summaryrefslogtreecommitdiff
path: root/internal/syscallcompat
diff options
context:
space:
mode:
Diffstat (limited to 'internal/syscallcompat')
-rw-r--r--internal/syscallcompat/sys_darwin.go17
-rw-r--r--internal/syscallcompat/sys_linux.go21
2 files changed, 38 insertions, 0 deletions
diff --git a/internal/syscallcompat/sys_darwin.go b/internal/syscallcompat/sys_darwin.go
index 5504860..4068e1a 100644
--- a/internal/syscallcompat/sys_darwin.go
+++ b/internal/syscallcompat/sys_darwin.go
@@ -148,3 +148,20 @@ func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) {
defer syscall.Fchdir(cwd)
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)
+}
diff --git a/internal/syscallcompat/sys_linux.go b/internal/syscallcompat/sys_linux.go
index 8a64a81..277015e 100644
--- a/internal/syscallcompat/sys_linux.go
+++ b/internal/syscallcompat/sys_linux.go
@@ -4,6 +4,7 @@ package syscallcompat
import (
"sync"
"syscall"
+ "unsafe"
"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) {
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
+}