fusefrontend: Use the Symlinkat syscall for longname handling

This commit is contained in:
Sebastian Lackner 2017-11-28 00:54:38 +01:00 committed by rfjakob
parent 295c4c2b85
commit 5a56810603
3 changed files with 39 additions and 2 deletions

View File

@ -448,8 +448,7 @@ func (fs *FS) Symlink(target string, linkName string, context *fuse.Context) (co
return fuse.ToStatus(err) return fuse.ToStatus(err)
} }
// Create "gocryptfs.longfile." symlink // Create "gocryptfs.longfile." symlink
// TODO use syscall.Symlinkat once it is available in Go err = syscallcompat.Symlinkat(cTarget, int(dirfd.Fd()), cName)
err = syscall.Symlink(cTarget, cPath)
if err != nil { if err != nil {
nametransform.DeleteLongName(dirfd, cName) nametransform.DeleteLongName(dirfd, cName)
} }

View File

@ -148,3 +148,20 @@ func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) {
defer syscall.Fchdir(cwd) defer syscall.Fchdir(cwd)
return syscall.Lchown(path, uid, gid) return syscall.Lchown(path, uid, gid)
} }
// Poor man's Symlinkat.
func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) {
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(newdirfd)
if err != nil {
return err
}
defer syscall.Fchdir(cwd)
return syscall.Symlink(oldpath, newpath)
}

View File

@ -4,6 +4,7 @@ package syscallcompat
import ( import (
"sync" "sync"
"syscall" "syscall"
"unsafe"
"github.com/rfjakob/gocryptfs/internal/tlog" "github.com/rfjakob/gocryptfs/internal/tlog"
) )
@ -73,3 +74,23 @@ func Dup3(oldfd int, newfd int, flags int) (err error) {
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) {
return syscall.Fchownat(dirfd, path, uid, gid, flags) return syscall.Fchownat(dirfd, path, uid, gid, flags)
} }
// Symlinkat syscall. Unfortunately this function is not exported directly, so
// manually call it by using the corresponding syscall number.
func Symlinkat(oldpath string, newdirfd int, newpath string) (err error) {
var _p0 *byte
_p0, err = syscall.BytePtrFromString(oldpath)
if err != nil {
return
}
var _p1 *byte
_p1, err = syscall.BytePtrFromString(newpath)
if err != nil {
return
}
_, _, e1 := syscall.Syscall(syscall.SYS_SYMLINKAT, uintptr(unsafe.Pointer(_p0)), uintptr(newdirfd), uintptr(unsafe.Pointer(_p1)))
if e1 != 0 {
err = e1
}
return
}