aboutsummaryrefslogtreecommitdiff
path: root/internal/syscallcompat/sys_darwin.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-07-03 19:14:12 +0200
committerJakob Unterwurzacher2016-07-03 19:18:34 +0200
commit9b725c15cf50cfb85ec6ec88c47843092775dedc (patch)
tree3fd5f651428e48cdd8485389c81de467d9e5d9a0 /internal/syscallcompat/sys_darwin.go
parentc9a472c12ff08a6481c086c791f3005e81dbbcf1 (diff)
syscallcompat: OSX: add Fallocate and Openat wrappers
...and convert all calls to syscall.{Fallocate,Openat} to syscallcompat . Both syscalls are not available on OSX. We emulate Openat and just return EOPNOTSUPP for Fallocate.
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
+}