syscallcompat: drop obsolete wrappers

These are now available cross-platform in the unix
package.
This commit is contained in:
Jakob Unterwurzacher 2021-06-05 15:06:30 +02:00
parent c0e7530216
commit e48f2377ec
6 changed files with 34 additions and 43 deletions

View File

@ -287,13 +287,13 @@ func (n *Node) Link(ctx context.Context, target fs.InodeEmbedder, name string, o
return return
} }
// Create "gocryptfs.longfile." link // Create "gocryptfs.longfile." link
err = syscallcompat.Linkat(dirfd2, cName2, dirfd, cName, 0) err = unix.Linkat(dirfd2, cName2, dirfd, cName, 0)
if err != nil { if err != nil {
nametransform.DeleteLongNameAt(dirfd, cName) nametransform.DeleteLongNameAt(dirfd, cName)
} }
} else { } else {
// Create regular link // Create regular link
err = syscallcompat.Linkat(dirfd2, cName2, dirfd, cName, 0) err = unix.Linkat(dirfd2, cName2, dirfd, cName, 0)
} }
if err != nil { if err != nil {
errno = fs.ToErrno(err) errno = fs.ToErrno(err)

View File

@ -2,6 +2,8 @@ package syscallcompat
import ( import (
"syscall" "syscall"
"golang.org/x/sys/unix"
) )
// retryEINTR executes operation `op` and retries if it gets EINTR. // 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 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. // Flush is a helper for the FUSE command FLUSH.
// Retries on EINTR. // Retries on EINTR.
func Flush(fd int) error { func Flush(fd int) error {

View File

@ -66,24 +66,6 @@ func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error)
return fd, err 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. // Fchownat syscall.
func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { 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? // 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) 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. // Fstatat syscall.
// Retries on EINTR. // Retries on EINTR.
func Fstatat(dirfd int, path string, stat *unix.Stat_t, flags int) (err error) { func Fstatat(dirfd int, path string, stat *unix.Stat_t, flags int) (err error) {

View File

@ -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) { func TestSymlinkat(t *testing.T) {
err := Symlinkat("/foo/bar/baz", tmpDirFd, "symlink1") err := unix.Symlinkat("/foo/bar/baz", tmpDirFd, "symlink1")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -242,7 +244,7 @@ func TestSymlinkat(t *testing.T) {
} }
symlinkCheckMode(t, st) symlinkCheckMode(t, st)
// Test with absolute path // Test with absolute path
err = Symlinkat("/foo/bar/baz", -1, tmpDir+"/symlink2") err = unix.Symlinkat("/foo/bar/baz", -1, tmpDir+"/symlink2")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -253,8 +255,10 @@ func TestSymlinkat(t *testing.T) {
symlinkCheckMode(t, st) 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) { func TestMkdirat(t *testing.T) {
err := Mkdirat(tmpDirFd, "mkdirat", 0700) err := unix.Mkdirat(tmpDirFd, "mkdirat", 0700)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -266,7 +270,7 @@ func TestMkdirat(t *testing.T) {
t.Fatalf("mkdirat did not create a directory") t.Fatalf("mkdirat did not create a directory")
} }
// Test with absolute path // Test with absolute path
err = Mkdirat(-1, tmpDir+"/mkdirat2", 0700) err = unix.Mkdirat(-1, tmpDir+"/mkdirat2", 0700)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -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) 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) { 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) defer pthread_setugid_np(KAUTH_UID_NONE, KAUTH_GID_NONE)
} }
return Mkdirat(dirfd, path, mode) return unix.Mkdirat(dirfd, path, mode)
} }
type attrList struct { type attrList struct {

View File

@ -204,7 +204,7 @@ func FchmodatNofollow(dirfd int, path string, mode uint32) (err error) {
// See OpenatUser() for how this works. // See OpenatUser() for how this works.
func SymlinkatUser(oldpath string, newdirfd int, newpath string, context *fuse.Context) (err error) { func SymlinkatUser(oldpath string, newdirfd int, newpath string, context *fuse.Context) (err error) {
f := func() (int, error) { f := func() (int, error) {
err := Symlinkat(oldpath, newdirfd, newpath) err := unix.Symlinkat(oldpath, newdirfd, newpath)
return -1, err return -1, err
} }
_, err = asUser(f, context) _, 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. // See OpenatUser() for how this works.
func MkdiratUser(dirfd int, path string, mode uint32, context *fuse.Context) (err error) { func MkdiratUser(dirfd int, path string, mode uint32, context *fuse.Context) (err error) {
f := func() (int, error) { f := func() (int, error) {
err := Mkdirat(dirfd, path, mode) err := unix.Mkdirat(dirfd, path, mode)
return -1, err return -1, err
} }
_, err = asUser(f, context) _, err = asUser(f, context)