Commit 420b298b authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fuse/pathfs: remove obsolete copies of syscall code

parent e028a29e
...@@ -13,13 +13,12 @@ import ( ...@@ -13,13 +13,12 @@ import (
) )
func (fs *loopbackFileSystem) ListXAttr(name string, context *fuse.Context) ([]string, fuse.Status) { func (fs *loopbackFileSystem) ListXAttr(name string, context *fuse.Context) ([]string, fuse.Status) {
data, err := listXAttr(fs.GetPath(name)) attrs, err := listXAttr(fs.GetPath(name))
return attrs, fuse.ToStatus(err)
return data, fuse.ToStatus(err)
} }
func (fs *loopbackFileSystem) RemoveXAttr(name string, attr string, context *fuse.Context) fuse.Status { func (fs *loopbackFileSystem) RemoveXAttr(name string, attr string, context *fuse.Context) fuse.Status {
err := sysRemovexattr(fs.GetPath(name), attr) err := syscall.Removexattr(fs.GetPath(name), attr)
return fuse.ToStatus(err) return fuse.ToStatus(err)
} }
...@@ -28,10 +27,22 @@ func (fs *loopbackFileSystem) String() string { ...@@ -28,10 +27,22 @@ func (fs *loopbackFileSystem) String() string {
} }
func (fs *loopbackFileSystem) GetXAttr(name string, attr string, context *fuse.Context) ([]byte, fuse.Status) { func (fs *loopbackFileSystem) GetXAttr(name string, attr string, context *fuse.Context) ([]byte, fuse.Status) {
data := make([]byte, 1024)
data, err := getXAttr(fs.GetPath(name), attr, data)
return data, fuse.ToStatus(err) bufsz := 1024
for {
data := make([]byte, bufsz)
sz, err := syscall.Getxattr(fs.GetPath(name), attr, data)
if err == nil {
return data[:sz], fuse.OK
}
if err == syscall.ERANGE {
bufsz = sz
continue
}
return nil, fuse.ToStatus(err)
}
} }
func (fs *loopbackFileSystem) SetXAttr(name string, attr string, data []byte, flags int, context *fuse.Context) fuse.Status { func (fs *loopbackFileSystem) SetXAttr(name string, attr string, data []byte, flags int, context *fuse.Context) fuse.Status {
......
...@@ -13,10 +13,10 @@ import ( ...@@ -13,10 +13,10 @@ import (
var _zero uintptr var _zero uintptr
func getXAttr(path string, attr string, dest []byte) (value []byte, err error) { func getXAttr(path string, attr string, dest []byte) (value []byte, err error) {
sz, err := sysGetxattr(path, attr, dest) sz, err := syscall.Getxattr(path, attr, dest)
for sz > cap(dest) && err == nil { for sz > cap(dest) && err == nil {
dest = make([]byte, sz) dest = make([]byte, sz)
sz, err = sysGetxattr(path, attr, dest) sz, err = syscall.Getxattr(path, attr, dest)
} }
if err != nil { if err != nil {
...@@ -28,14 +28,14 @@ func getXAttr(path string, attr string, dest []byte) (value []byte, err error) { ...@@ -28,14 +28,14 @@ func getXAttr(path string, attr string, dest []byte) (value []byte, err error) {
func listXAttr(path string) (attributes []string, err error) { func listXAttr(path string) (attributes []string, err error) {
dest := make([]byte, 0) dest := make([]byte, 0)
sz, err := sysListxattr(path, dest) sz, err := syscall.Listxattr(path, dest)
if err != nil { if err != nil {
return nil, err return nil, err
} }
for sz > cap(dest) && err == nil { for sz > cap(dest) && err == nil {
dest = make([]byte, sz) dest = make([]byte, sz)
sz, err = sysListxattr(path, dest) sz, err = syscall.Listxattr(path, dest)
} }
if sz == 0 { if sz == 0 {
...@@ -52,75 +52,6 @@ func listXAttr(path string) (attributes []string, err error) { ...@@ -52,75 +52,6 @@ func listXAttr(path string) (attributes []string, err error) {
return attributes, err return attributes, err
} }
// Below is cut & paste from std lib syscall, so gccgo 4.8.1 can
// compile this too.
func sysGetxattr(path string, attr string, dest []byte) (sz int, err error) {
var _p0 *byte
_p0, err = syscall.BytePtrFromString(path)
if err != nil {
return
}
var _p1 *byte
_p1, err = syscall.BytePtrFromString(attr)
if err != nil {
return
}
var _p2 unsafe.Pointer
if len(dest) > 0 {
_p2 = unsafe.Pointer(&dest[0])
} else {
_p2 = unsafe.Pointer(&_zero)
}
r0, _, e1 := syscall.Syscall6(syscall.SYS_GETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(dest)), 0, 0)
sz = int(r0)
if e1 != 0 {
err = e1
}
return
}
func sysRemovexattr(path string, attr string) (err error) {
var _p0 *byte
_p0, err = syscall.BytePtrFromString(path)
if err != nil {
return
}
var _p1 *byte
_p1, err = syscall.BytePtrFromString(attr)
if err != nil {
return
}
_, _, e1 := syscall.Syscall(syscall.SYS_REMOVEXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0)
if e1 != 0 {
err = e1
}
return
}
func sysListxattr(path string, dest []byte) (sz int, err error) {
var _p0 *byte
_p0, err = syscall.BytePtrFromString(path)
if err != nil {
return
}
var _p1 unsafe.Pointer
if len(dest) > 0 {
_p1 = unsafe.Pointer(&dest[0])
} else {
_p1 = unsafe.Pointer(&_zero)
}
r0, _, e1 := syscall.Syscall(syscall.SYS_LISTXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(dest)))
sz = int(r0)
if e1 != 0 {
err = e1
}
return
}
func sysSetxattr(path string, attr string, val []byte, flag int) error {
return syscall.Setxattr(path, attr, val, flag)
}
const _AT_SYMLINK_NOFOLLOW = 0x100 const _AT_SYMLINK_NOFOLLOW = 0x100
// Linux kernel syscall utimensat(2) // Linux kernel syscall utimensat(2)
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"bytes" "bytes"
"os" "os"
"path/filepath" "path/filepath"
"syscall"
"testing" "testing"
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
...@@ -99,11 +100,6 @@ func (fs *XAttrTestFs) RemoveXAttr(name string, attr string, context *fuse.Conte ...@@ -99,11 +100,6 @@ func (fs *XAttrTestFs) RemoveXAttr(name string, attr string, context *fuse.Conte
return fuse.OK return fuse.OK
} }
func readXAttr(p, a string) (val []byte, err error) {
val = make([]byte, 1024)
return getXAttr(p, a, val)
}
func xattrTestCase(t *testing.T, nm string, m map[string][]byte) (mountPoint string, cleanup func()) { func xattrTestCase(t *testing.T, nm string, m map[string][]byte) (mountPoint string, cleanup func()) {
xfs := NewXAttrFs(nm, m) xfs := NewXAttrFs(nm, m)
mountPoint = testutil.TempDir() mountPoint = testutil.TempDir()
...@@ -138,6 +134,11 @@ func TestXAttrNoAttrs(t *testing.T) { ...@@ -138,6 +134,11 @@ func TestXAttrNoAttrs(t *testing.T) {
} }
} }
func readXAttr(p, a string) (val []byte, err error) {
val = make([]byte, 1024)
return getXAttr(p, a, val)
}
func TestXAttrNoExist(t *testing.T) { func TestXAttrNoExist(t *testing.T) {
nm := xattrFilename nm := xattrFilename
mountPoint, clean := xattrTestCase(t, nm, xattrGolden) mountPoint, clean := xattrTestCase(t, nm, xattrGolden)
...@@ -185,8 +186,7 @@ func TestXAttrRead(t *testing.T) { ...@@ -185,8 +186,7 @@ func TestXAttrRead(t *testing.T) {
} }
} }
err = sysSetxattr(mounted, "third", []byte("value"), 0) if err = syscall.Setxattr(mounted, "third", []byte("value"), 0); err != nil {
if err != nil {
t.Error("Setxattr error", err) t.Error("Setxattr error", err)
} }
val, err := readXAttr(mounted, "third") val, err := readXAttr(mounted, "third")
...@@ -194,7 +194,9 @@ func TestXAttrRead(t *testing.T) { ...@@ -194,7 +194,9 @@ func TestXAttrRead(t *testing.T) {
t.Error("Read back set xattr:", err, string(val)) t.Error("Read back set xattr:", err, string(val))
} }
sysRemovexattr(mounted, "third") if err := syscall.Removexattr(mounted, "third"); err != nil {
t.Errorf("Removexattr: %v", err)
}
val, err = readXAttr(mounted, "third") val, err = readXAttr(mounted, "third")
if fuse.ToStatus(err) != fuse.ENOATTR { if fuse.ToStatus(err) != fuse.ENOATTR {
t.Error("Data not removed?", err, val) t.Error("Data not removed?", err, val)
......
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