aboutsummaryrefslogtreecommitdiff
path: root/internal/syscallcompat/sys_common.go
diff options
context:
space:
mode:
authorSebastian Lackner2019-01-14 02:32:28 +0100
committerrfjakob2019-01-14 21:27:28 +0100
commitda557702d713e38a8c6c4c28275724c70988f919 (patch)
tree615a8c9487b52c18d74bed29defd03d03c933743 /internal/syscallcompat/sys_common.go
parentd7be76685128cb2cdca01becd856ea57cc18ef34 (diff)
syscallcompat: Drop Openat emulation on macOS.
Diffstat (limited to 'internal/syscallcompat/sys_common.go')
-rw-r--r--internal/syscallcompat/sys_common.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/syscallcompat/sys_common.go b/internal/syscallcompat/sys_common.go
index a1aa66d..a5b2c05 100644
--- a/internal/syscallcompat/sys_common.go
+++ b/internal/syscallcompat/sys_common.go
@@ -5,6 +5,8 @@ import (
"syscall"
"golang.org/x/sys/unix"
+
+ "github.com/rfjakob/gocryptfs/internal/tlog"
)
// PATH_MAX is the maximum allowed path length on Linux.
@@ -42,6 +44,24 @@ func Faccessat(dirfd int, path string, mode uint32) error {
return unix.Faccessat(dirfd, path, mode, 0)
}
+// Openat wraps the Openat syscall.
+func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error) {
+ if flags&syscall.O_CREAT != 0 {
+ // O_CREAT should be used with O_EXCL. O_NOFOLLOW has no effect with O_EXCL.
+ if flags&syscall.O_EXCL == 0 {
+ tlog.Warn.Printf("Openat: O_CREAT without O_EXCL: flags = %#x", flags)
+ flags |= syscall.O_EXCL
+ }
+ } else {
+ // If O_CREAT is not used, we should use O_NOFOLLOW
+ if flags&syscall.O_NOFOLLOW == 0 {
+ tlog.Warn.Printf("Openat: O_NOFOLLOW missing: flags = %#x", flags)
+ flags |= syscall.O_NOFOLLOW
+ }
+ }
+ return unix.Openat(dirfd, path, flags, mode)
+}
+
// Linkat exists both in Linux and in MacOS 10.10+.
func Linkat(olddirfd int, oldpath string, newdirfd int, newpath string, flags int) (err error) {
return unix.Linkat(olddirfd, oldpath, newdirfd, newpath, flags)