diff options
Diffstat (limited to 'internal/syscallcompat')
-rw-r--r-- | internal/syscallcompat/eintr.go | 20 | ||||
-rw-r--r-- | internal/syscallcompat/sys_common.go | 33 | ||||
-rw-r--r-- | internal/syscallcompat/sys_common_test.go | 12 | ||||
-rw-r--r-- | internal/syscallcompat/sys_darwin.go | 4 | ||||
-rw-r--r-- | internal/syscallcompat/sys_linux.go | 4 |
5 files changed, 32 insertions, 41 deletions
diff --git a/internal/syscallcompat/eintr.go b/internal/syscallcompat/eintr.go index f0a82f5..cdde806 100644 --- a/internal/syscallcompat/eintr.go +++ b/internal/syscallcompat/eintr.go @@ -2,6 +2,8 @@ package syscallcompat import ( "syscall" + + "golang.org/x/sys/unix" ) // retryEINTR executes operation `op` and retries if it gets EINTR. @@ -43,6 +45,24 @@ func Open(path string, mode int, perm uint32) (fd int, err error) { return fd, err } +// Renameat wraps the Renameat syscall. +// Retries on EINTR. +func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) { + err = retryEINTR(func() error { + return unix.Renameat(olddirfd, oldpath, newdirfd, newpath) + }) + return err +} + +// Unlinkat syscall. +// Retries on EINTR. +func Unlinkat(dirfd int, path string, flags int) (err error) { + err = retryEINTR(func() error { + return unix.Unlinkat(dirfd, path, flags) + }) + return err +} + // Flush is a helper for the FUSE command FLUSH. // Retries on EINTR. func Flush(fd int) error { diff --git a/internal/syscallcompat/sys_common.go b/internal/syscallcompat/sys_common.go index d7a9706..fc020bd 100644 --- a/internal/syscallcompat/sys_common.go +++ b/internal/syscallcompat/sys_common.go @@ -66,24 +66,6 @@ func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error) return fd, err } -// Renameat wraps the Renameat syscall. -// Retries on EINTR. -func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) { - err = retryEINTR(func() error { - return unix.Renameat(olddirfd, oldpath, newdirfd, newpath) - }) - return err -} - -// Unlinkat syscall. -// Retries on EINTR. -func Unlinkat(dirfd int, path string, flags int) (err error) { - err = retryEINTR(func() error { - return unix.Unlinkat(dirfd, path, flags) - }) - return err -} - // Fchownat syscall. func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { // Why would we ever want to call this without AT_SYMLINK_NOFOLLOW? @@ -94,21 +76,6 @@ func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { return unix.Fchownat(dirfd, path, uid, gid, flags) } -// Linkat exists both in Linux and in MacOS 10.10+. -func Linkat(olddirfd int, oldpath string, newdirfd int, newpath string, flags int) (err error) { - return unix.Linkat(olddirfd, oldpath, newdirfd, newpath, flags) -} - -// Symlinkat syscall. -func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) { - return unix.Symlinkat(oldpath, newdirfd, newpath) -} - -// Mkdirat syscall. -func Mkdirat(dirfd int, path string, mode uint32) (err error) { - return unix.Mkdirat(dirfd, path, mode) -} - // Fstatat syscall. // Retries on EINTR. func Fstatat(dirfd int, path string, stat *unix.Stat_t, flags int) (err error) { diff --git a/internal/syscallcompat/sys_common_test.go b/internal/syscallcompat/sys_common_test.go index c5f05a9..7141b92 100644 --- a/internal/syscallcompat/sys_common_test.go +++ b/internal/syscallcompat/sys_common_test.go @@ -230,8 +230,10 @@ func symlinkCheckMode(t *testing.T, st syscall.Stat_t) { } } +// We used to have our own wrapper for Symlinkat. The wrapper is gone but the test +// is still useful. func TestSymlinkat(t *testing.T) { - err := Symlinkat("/foo/bar/baz", tmpDirFd, "symlink1") + err := unix.Symlinkat("/foo/bar/baz", tmpDirFd, "symlink1") if err != nil { t.Fatal(err) } @@ -242,7 +244,7 @@ func TestSymlinkat(t *testing.T) { } symlinkCheckMode(t, st) // Test with absolute path - err = Symlinkat("/foo/bar/baz", -1, tmpDir+"/symlink2") + err = unix.Symlinkat("/foo/bar/baz", -1, tmpDir+"/symlink2") if err != nil { t.Fatal(err) } @@ -253,8 +255,10 @@ func TestSymlinkat(t *testing.T) { symlinkCheckMode(t, st) } +// We used to have our own wrapper for Mkdirat. The wrapper is gone but the test +// is still useful. func TestMkdirat(t *testing.T) { - err := Mkdirat(tmpDirFd, "mkdirat", 0700) + err := unix.Mkdirat(tmpDirFd, "mkdirat", 0700) if err != nil { t.Fatal(err) } @@ -266,7 +270,7 @@ func TestMkdirat(t *testing.T) { t.Fatalf("mkdirat did not create a directory") } // Test with absolute path - err = Mkdirat(-1, tmpDir+"/mkdirat2", 0700) + err = unix.Mkdirat(-1, tmpDir+"/mkdirat2", 0700) if err != nil { t.Fatal(err) } diff --git a/internal/syscallcompat/sys_darwin.go b/internal/syscallcompat/sys_darwin.go index b5f7d49..075563f 100644 --- a/internal/syscallcompat/sys_darwin.go +++ b/internal/syscallcompat/sys_darwin.go @@ -131,7 +131,7 @@ func SymlinkatUser(oldpath string, newdirfd int, newpath string, context *fuse.C defer pthread_setugid_np(KAUTH_UID_NONE, KAUTH_GID_NONE) } - return Symlinkat(oldpath, newdirfd, newpath) + return unix.Symlinkat(oldpath, newdirfd, newpath) } func MkdiratUser(dirfd int, path string, mode uint32, context *fuse.Context) (err error) { @@ -146,7 +146,7 @@ func MkdiratUser(dirfd int, path string, mode uint32, context *fuse.Context) (er defer pthread_setugid_np(KAUTH_UID_NONE, KAUTH_GID_NONE) } - return Mkdirat(dirfd, path, mode) + return unix.Mkdirat(dirfd, path, mode) } type attrList struct { diff --git a/internal/syscallcompat/sys_linux.go b/internal/syscallcompat/sys_linux.go index 45c18d2..9672be7 100644 --- a/internal/syscallcompat/sys_linux.go +++ b/internal/syscallcompat/sys_linux.go @@ -204,7 +204,7 @@ func FchmodatNofollow(dirfd int, path string, mode uint32) (err error) { // See OpenatUser() for how this works. func SymlinkatUser(oldpath string, newdirfd int, newpath string, context *fuse.Context) (err error) { f := func() (int, error) { - err := Symlinkat(oldpath, newdirfd, newpath) + err := unix.Symlinkat(oldpath, newdirfd, newpath) return -1, err } _, err = asUser(f, context) @@ -217,7 +217,7 @@ func SymlinkatUser(oldpath string, newdirfd int, newpath string, context *fuse.C // See OpenatUser() for how this works. func MkdiratUser(dirfd int, path string, mode uint32, context *fuse.Context) (err error) { f := func() (int, error) { - err := Mkdirat(dirfd, path, mode) + err := unix.Mkdirat(dirfd, path, mode) return -1, err } _, err = asUser(f, context) |