From cf3eb1bb806b198cb07b00c16d328f3557230798 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Sun, 30 Apr 2017 20:55:36 -0700 Subject: [PATCH] fsop: simplify Getxattr signature --- examples/memfs/memfs.go | 15 ++++++--------- fuse/fsop.go | 6 +++--- fuse/host.go | 24 +++++++++--------------- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/examples/memfs/memfs.go b/examples/memfs/memfs.go index a63c787..a9d4d2b 100644 --- a/examples/memfs/memfs.go +++ b/examples/memfs/memfs.go @@ -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) { diff --git a/fuse/fsop.go b/fuse/fsop.go index 864662f..229ccf3 100644 --- a/fuse/fsop.go +++ b/fuse/fsop.go @@ -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 @@ -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. diff --git a/fuse/host.go b/fuse/host.go index 602f2d7..26fdace 100644 --- a/fuse/host.go +++ b/fuse/host.go @@ -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