syscallcompat: Drop Mkdirat emulation on macOS.

This commit is contained in:
Sebastian Lackner 2019-01-14 02:56:06 +01:00 committed by rfjakob
parent 7b0d56fe98
commit 4134ff7570
6 changed files with 31 additions and 55 deletions

View File

@ -30,26 +30,6 @@ func emulateMknodat(dirfd int, path string, mode uint32, dev int) error {
return syscall.Mknod(path, mode, dev)
}
// emulateMkdirat emulates the syscall for platforms that don't have it
// in the kernel (darwin).
func emulateMkdirat(dirfd int, path string, mode uint32) (err error) {
if !filepath.IsAbs(path) {
chdirMutex.Lock()
defer chdirMutex.Unlock()
cwd, err := syscall.Open(".", syscall.O_RDONLY, 0)
if err != nil {
return err
}
defer syscall.Close(cwd)
err = syscall.Fchdir(dirfd)
if err != nil {
return err
}
defer syscall.Fchdir(cwd)
}
return syscall.Mkdir(path, mode)
}
// emulateFstatat emulates the syscall for platforms that don't have it
// in the kernel (darwin).
func emulateFstatat(dirfd int, path string, stat *unix.Stat_t, flags int) (err error) {

View File

@ -27,32 +27,6 @@ func TestEmulateMknodat(t *testing.T) {
}
}
func TestEmulateMkdirat(t *testing.T) {
err := emulateMkdirat(tmpDirFd, "mkdirat", 0700)
if err != nil {
t.Fatal(err)
}
fi, err := os.Stat(tmpDir + "/mkdirat")
if err != nil {
t.Fatal(err)
}
if !fi.IsDir() {
t.Fatalf("mkdirat did not create a directory")
}
// Test with absolute path
err = emulateMkdirat(-1, tmpDir+"/mkdirat2", 0700)
if err != nil {
t.Fatal(err)
}
fi, err = os.Stat(tmpDir + "/mkdirat2")
if err != nil {
t.Fatal(err)
}
if !fi.IsDir() {
t.Fatalf("mkdirat did not create a directory")
}
}
func TestEmulateFstatat(t *testing.T) {
var st unix.Stat_t
// stat a normal file (size 3)

View File

@ -92,6 +92,11 @@ 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)
}
const XATTR_SIZE_MAX = 65536
// Make the buffer 1kB bigger so we can detect overflows

View File

@ -247,3 +247,29 @@ func TestSymlinkat(t *testing.T) {
}
symlinkCheckMode(t, st)
}
func TestMkdirat(t *testing.T) {
err := Mkdirat(tmpDirFd, "mkdirat", 0700)
if err != nil {
t.Fatal(err)
}
fi, err := os.Stat(tmpDir + "/mkdirat")
if err != nil {
t.Fatal(err)
}
if !fi.IsDir() {
t.Fatalf("mkdirat did not create a directory")
}
// Test with absolute path
err = Mkdirat(-1, tmpDir+"/mkdirat2", 0700)
if err != nil {
t.Fatal(err)
}
fi, err = os.Stat(tmpDir + "/mkdirat2")
if err != nil {
t.Fatal(err)
}
if !fi.IsDir() {
t.Fatalf("mkdirat did not create a directory")
}
}

View File

@ -117,10 +117,6 @@ func SymlinkatUser(oldpath string, newdirfd int, newpath string, context *fuse.C
return Symlinkat(oldpath, newdirfd, newpath)
}
func Mkdirat(dirfd int, path string, mode uint32) (err error) {
return emulateMkdirat(dirfd, path, mode)
}
func MkdiratUser(dirfd int, path string, mode uint32, context *fuse.Context) (err error) {
if context != nil {
runtime.LockOSThread()

View File

@ -176,11 +176,6 @@ func SymlinkatUser(oldpath string, newdirfd int, newpath string, context *fuse.C
return Symlinkat(oldpath, newdirfd, newpath)
}
// Mkdirat syscall.
func Mkdirat(dirfd int, path string, mode uint32) (err error) {
return syscall.Mkdirat(dirfd, path, mode)
}
// MkdiratUser runs the Mkdirat syscall in the context of a different user.
func MkdiratUser(dirfd int, path string, mode uint32, context *fuse.Context) (err error) {
if context != nil {