summaryrefslogtreecommitdiff
path: root/internal/syscallcompat/sys_darwin.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/syscallcompat/sys_darwin.go')
-rw-r--r--internal/syscallcompat/sys_darwin.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/internal/syscallcompat/sys_darwin.go b/internal/syscallcompat/sys_darwin.go
index d437170..81e1b15 100644
--- a/internal/syscallcompat/sys_darwin.go
+++ b/internal/syscallcompat/sys_darwin.go
@@ -1,5 +1,11 @@
package syscallcompat
+import (
+ "os"
+ "sync"
+ "syscall"
+)
+
// prealloc - preallocate space without changing the file size. This prevents
// us from running out of space in the middle of an operation.
func Prealloc(fd int, off int64, len int64) (err error) {
@@ -10,3 +16,30 @@ func Prealloc(fd int, off int64, len int64) (err error) {
// See https://github.com/rfjakob/gocryptfs/issues/18 if you want to help.
return nil
}
+
+var openatLock sync.Mutex
+
+// Poor man's Openat:
+// 1) fchdir to the dirfd
+// 2) open the file
+// 3) chdir back.
+func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error) {
+ openatLock.Lock()
+ defer openatLock.Unlock()
+
+ oldWd, err := os.Getwd()
+ if err != nil {
+ return -1, err
+ }
+ err = syscall.Fchdir(dirfd)
+ if err != nil {
+ return -1, err
+ }
+ defer os.Chdir(oldWd)
+
+ return syscall.Open(path, flags, mode)
+}
+
+func Fallocate(fd int, mode uint32, off int64, len int64) (err error) {
+ return syscall.EOPNOTSUPP
+}