Skip to content

Commit

Permalink
fsop: simplify Getxattr signature
Browse files Browse the repository at this point in the history
  • Loading branch information
billziss-gh committed May 1, 2017
1 parent 4079a85 commit cf3eb1b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
15 changes: 6 additions & 9 deletions examples/memfs/memfs.go
Expand Up @@ -371,24 +371,21 @@ func (self *Memfs) Setxattr(path string, name string, value []byte, flags int) (
return 0
}

func (self *Memfs) Getxattr(path string, name string, fill func(value []byte) bool) (errc int) {
defer trace(path, name, fill)(&errc)
func (self *Memfs) Getxattr(path string, name string) (errc int, xatr []byte) {
defer trace(path, name)(&errc, &xatr)
defer self.synchronize()()
_, _, node := self.lookupNode(path, nil)
if nil == node {
return -fuse.ENOENT
return -fuse.ENOENT, nil
}
if "com.apple.ResourceFork" == name {
return -fuse.ENOTSUP
return -fuse.ENOTSUP, nil
}
xatr, ok := node.xatr[name]
if !ok {
return -fuse.ENOATTR
return -fuse.ENOATTR, nil
}
if !fill(xatr) {
return -fuse.ERANGE
}
return 0
return 0, xatr
}

func (self *Memfs) Removexattr(path string, name string) (errc int) {
Expand Down
6 changes: 3 additions & 3 deletions fuse/fsop.go
Expand Up @@ -477,7 +477,7 @@ type FileSystemInterface interface {
Setxattr(path string, name string, value []byte, flags int) int

// Getxattr gets extended attributes.
Getxattr(path string, name string, fill func(value []byte) bool) int
Getxattr(path string, name string) (int, []byte)

// Removexattr removes extended attributes.
Removexattr(path string, name string) int
Expand Down Expand Up @@ -687,8 +687,8 @@ func (*FileSystemBase) Setxattr(path string, name string, value []byte, flags in

// Getxattr gets extended attributes.
// The FileSystemBase implementation returns -ENOSYS.
func (*FileSystemBase) Getxattr(path string, name string, fill func(value []byte) bool) int {
return -ENOSYS
func (*FileSystemBase) Getxattr(path string, name string) (int, []byte) {
return -ENOSYS, nil
}

// Removexattr removes extended attributes.
Expand Down
24 changes: 9 additions & 15 deletions fuse/host.go
Expand Up @@ -708,24 +708,18 @@ func hostGetxattr(path0 *C.char, name0 *C.char, buff0 *C.char, size0 C.size_t) (
fsop := getInterfaceForHandle(C.fuse_get_context().private_data).(FileSystemInterface)
path := C.GoString(path0)
name := C.GoString(name0)
buff := (*[1 << 30]byte)(unsafe.Pointer(buff0))
size := int(size0)
nbyt := 0
fill := func(value []byte) bool {
nbyt = len(value)
if 0 != size {
if nbyt > size {
return false
}
copy(buff[:size], value)
}
return true
}
errc := fsop.Getxattr(path, name, fill)
errc, rslt := fsop.Getxattr(path, name)
if 0 != errc {
return C.int(errc)
}
return C.int(nbyt)
if 0 != size0 {
if len(rslt) > int(size0) {
return -C.int(ERANGE)
}
buff := (*[1 << 30]byte)(unsafe.Pointer(buff0))
copy(buff[:size0], rslt)
}
return C.int(len(rslt))
}

//export hostListxattr
Expand Down

0 comments on commit cf3eb1b

Please sign in to comment.