syscallcompat: Drop Mkdirat emulation on macOS.
This commit is contained in:
parent
7b0d56fe98
commit
4134ff7570
@ -30,26 +30,6 @@ func emulateMknodat(dirfd int, path string, mode uint32, dev int) error {
|
|||||||
return syscall.Mknod(path, mode, dev)
|
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
|
// emulateFstatat emulates the syscall for platforms that don't have it
|
||||||
// in the kernel (darwin).
|
// in the kernel (darwin).
|
||||||
func emulateFstatat(dirfd int, path string, stat *unix.Stat_t, flags int) (err error) {
|
func emulateFstatat(dirfd int, path string, stat *unix.Stat_t, flags int) (err error) {
|
||||||
|
@ -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) {
|
func TestEmulateFstatat(t *testing.T) {
|
||||||
var st unix.Stat_t
|
var st unix.Stat_t
|
||||||
// stat a normal file (size 3)
|
// stat a normal file (size 3)
|
||||||
|
@ -92,6 +92,11 @@ func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) {
|
|||||||
return unix.Symlinkat(oldpath, newdirfd, newpath)
|
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
|
const XATTR_SIZE_MAX = 65536
|
||||||
|
|
||||||
// Make the buffer 1kB bigger so we can detect overflows
|
// Make the buffer 1kB bigger so we can detect overflows
|
||||||
|
@ -247,3 +247,29 @@ func TestSymlinkat(t *testing.T) {
|
|||||||
}
|
}
|
||||||
symlinkCheckMode(t, st)
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -117,10 +117,6 @@ func SymlinkatUser(oldpath string, newdirfd int, newpath string, context *fuse.C
|
|||||||
return Symlinkat(oldpath, newdirfd, newpath)
|
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) {
|
func MkdiratUser(dirfd int, path string, mode uint32, context *fuse.Context) (err error) {
|
||||||
if context != nil {
|
if context != nil {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
|
@ -176,11 +176,6 @@ func SymlinkatUser(oldpath string, newdirfd int, newpath string, context *fuse.C
|
|||||||
return Symlinkat(oldpath, newdirfd, newpath)
|
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.
|
// 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) {
|
func MkdiratUser(dirfd int, path string, mode uint32, context *fuse.Context) (err error) {
|
||||||
if context != nil {
|
if context != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user