Commit cbeaa550 authored by Ka-Hing Cheung's avatar Ka-Hing Cheung

SetXattr support

parent d20c4665
......@@ -487,6 +487,35 @@ func convertInMessage(
return
}
}
case fusekernel.OpSetxattr:
type input fusekernel.SetxattrIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
if in == nil {
err = errors.New("Corrupt OpSetxattr")
return
}
payload := inMsg.ConsumeBytes(inMsg.Len())
// payload should be "name\x00value"
if len(payload) < 3 {
err = errors.New("Corrupt OpSetxattr")
return
}
i := bytes.IndexByte(payload, '\x00')
if i < 0 {
err = errors.New("Corrupt OpSetxattr")
return
}
name, value := payload[:i], payload[i+1:len(payload)]
fmt.Printf("Setting %v to %v\n", name, value)
o = &fuseops.SetXattrOp{
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
Name: string(name),
Data: value,
Flags: in.Flags,
}
default:
o = &unknownOp{
......@@ -726,6 +755,9 @@ func (c *Connection) kernelResponseForOp(
m.ShrinkTo(buffer.OutMessageHeaderSize + o.BytesRead)
}
case *fuseops.SetXattrOp:
// Empty response
case *initOp:
out := (*fusekernel.InitOut)(m.Grow(int(unsafe.Sizeof(fusekernel.InitOut{}))))
......
......@@ -95,6 +95,9 @@ func describeRequest(op interface{}) (s string) {
case *fuseops.GetXattrOp:
addComponent("name %s", typed.Name)
case *fuseops.SetXattrOp:
addComponent("name %s", typed.Name)
}
// Use just the name if there is no extra info.
......
......@@ -815,3 +815,18 @@ type ListXattrOp struct {
// big enough
BytesRead int
}
type SetXattrOp struct {
// The inode that we are changing
Inode InodeID
// The name of the extended attribute
Name string
// The data to for the extened attribute.
Data []byte
// If Flags is 0x1, and the attribute exists already, EEXIST should be returned.
// If Flags is 0x2, and the attribute does not exist, ENOATTR should be returned.
Flags uint32
}
......@@ -60,6 +60,7 @@ type FileSystem interface {
RemoveXattr(context.Context, *fuseops.RemoveXattrOp) error
GetXattr(context.Context, *fuseops.GetXattrOp) error
ListXattr(context.Context, *fuseops.ListXattrOp) error
SetXattr(context.Context, *fuseops.SetXattrOp) error
// Regard all inodes (including the root inode) as having their lookup counts
// decremented to zero, and clean up any resources associated with the file
......@@ -198,6 +199,9 @@ func (s *fileSystemServer) handleOp(
case *fuseops.ListXattrOp:
err = s.fs.ListXattr(ctx, typed)
case *fuseops.SetXattrOp:
err = s.fs.SetXattr(ctx, typed)
}
c.Reply(ctx, err)
......
......@@ -204,5 +204,12 @@ func (fs *NotImplementedFileSystem) ListXattr(
return
}
func (fs *NotImplementedFileSystem) SetXattr(
ctx context.Context,
op *fuseops.SetXattrOp) (err error) {
err = fuse.ENOSYS
return
}
func (fs *NotImplementedFileSystem) Destroy() {
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment