From e48f2377ec46f247d4db04cf8031702d0684c086 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sat, 5 Jun 2021 15:06:30 +0200 Subject: syscallcompat: drop obsolete wrappers These are now available cross-platform in the unix package. --- internal/fusefrontend/node.go | 4 ++-- internal/syscallcompat/eintr.go | 20 +++++++++++++++++++ internal/syscallcompat/sys_common.go | 33 ------------------------------- internal/syscallcompat/sys_common_test.go | 12 +++++++---- internal/syscallcompat/sys_darwin.go | 4 ++-- internal/syscallcompat/sys_linux.go | 4 ++-- 6 files changed, 34 insertions(+), 43 deletions(-) diff --git a/internal/fusefrontend/node.go b/internal/fusefrontend/node.go index 87effca..657a3bc 100644 --- a/internal/fusefrontend/node.go +++ b/internal/fusefrontend/node.go @@ -287,13 +287,13 @@ func (n *Node) Link(ctx context.Context, target fs.InodeEmbedder, name string, o return } // Create "gocryptfs.longfile." link - err = syscallcompat.Linkat(dirfd2, cName2, dirfd, cName, 0) + err = unix.Linkat(dirfd2, cName2, dirfd, cName, 0) if err != nil { nametransform.DeleteLongNameAt(dirfd, cName) } } else { // Create regular link - err = syscallcompat.Linkat(dirfd2, cName2, dirfd, cName, 0) + err = unix.Linkat(dirfd2, cName2, dirfd, cName, 0) } if err != nil { errno = fs.ToErrno(err) 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) -- cgit v1.2.3