summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/fusefrontend/node.go10
-rw-r--r--internal/fusefrontend/node_helpers.go20
-rw-r--r--internal/syscallcompat/sys_linux.go29
3 files changed, 26 insertions, 33 deletions
diff --git a/internal/fusefrontend/node.go b/internal/fusefrontend/node.go
index aa9bd51..5b42ddc 100644
--- a/internal/fusefrontend/node.go
+++ b/internal/fusefrontend/node.go
@@ -138,6 +138,7 @@ func (n *Node) Create(ctx context.Context, name string, flags uint32, mode uint3
}
newFlags := rn.mangleOpenFlags(flags)
// Handle long file name
+ ctx2 := toFuseCtx(ctx)
if !rn.args.PlaintextNames && nametransform.IsLongContent(cName) {
// Create ".name"
err = rn.nameTransform.WriteLongNameAt(dirfd, cName, name)
@@ -145,13 +146,13 @@ func (n *Node) Create(ctx context.Context, name string, flags uint32, mode uint3
return nil, nil, 0, fs.ToErrno(err)
}
// Create content
- fd, err = syscallcompat.OpenatUserCtx(dirfd, cName, newFlags|syscall.O_CREAT|syscall.O_EXCL, mode, ctx)
+ fd, err = syscallcompat.OpenatUser(dirfd, cName, newFlags|syscall.O_CREAT|syscall.O_EXCL, mode, ctx2)
if err != nil {
nametransform.DeleteLongNameAt(dirfd, cName)
}
} else {
// Create content, normal (short) file name
- fd, err = syscallcompat.OpenatUserCtx(dirfd, cName, newFlags|syscall.O_CREAT|syscall.O_EXCL, mode, ctx)
+ fd, err = syscallcompat.OpenatUser(dirfd, cName, newFlags|syscall.O_CREAT|syscall.O_EXCL, mode, ctx2)
}
if err != nil {
// xfstests generic/488 triggers this
@@ -322,6 +323,7 @@ func (n *Node) Mknod(ctx context.Context, name string, mode, rdev uint32, out *f
// Create ".name" file to store long file name (except in PlaintextNames mode)
var err error
+ ctx2 := toFuseCtx(ctx)
if !rn.args.PlaintextNames && nametransform.IsLongContent(cName) {
err := rn.nameTransform.WriteLongNameAt(dirfd, cName, name)
if err != nil {
@@ -329,13 +331,13 @@ func (n *Node) Mknod(ctx context.Context, name string, mode, rdev uint32, out *f
return
}
// Create "gocryptfs.longfile." device node
- err = syscallcompat.MknodatUserCtx(dirfd, cName, mode, int(rdev), ctx)
+ err = syscallcompat.MknodatUser(dirfd, cName, mode, int(rdev), ctx2)
if err != nil {
nametransform.DeleteLongNameAt(dirfd, cName)
}
} else {
// Create regular device node
- err = syscallcompat.MknodatUserCtx(dirfd, cName, mode, int(rdev), ctx)
+ err = syscallcompat.MknodatUser(dirfd, cName, mode, int(rdev), ctx2)
}
if err != nil {
errno = fs.ToErrno(err)
diff --git a/internal/fusefrontend/node_helpers.go b/internal/fusefrontend/node_helpers.go
new file mode 100644
index 0000000..1eb6d4a
--- /dev/null
+++ b/internal/fusefrontend/node_helpers.go
@@ -0,0 +1,20 @@
+package fusefrontend
+
+import (
+ "context"
+
+ "github.com/hanwen/go-fuse/v2/fuse"
+)
+
+// toFuseCtx tries to extract a fuse.Context from a generic context.Context.
+func toFuseCtx(ctx context.Context) (ctx2 *fuse.Context) {
+ if ctx == nil {
+ return nil
+ }
+ if caller, ok := fuse.FromContext(ctx); ok {
+ ctx2 = &fuse.Context{
+ Caller: *caller,
+ }
+ }
+ return ctx2
+}
diff --git a/internal/syscallcompat/sys_linux.go b/internal/syscallcompat/sys_linux.go
index 5a23084..42e9da6 100644
--- a/internal/syscallcompat/sys_linux.go
+++ b/internal/syscallcompat/sys_linux.go
@@ -2,7 +2,6 @@
package syscallcompat
import (
- "context"
"fmt"
"io/ioutil"
"runtime"
@@ -89,20 +88,6 @@ func getSupplementaryGroups(pid uint32) (gids []int) {
return nil
}
-// OpenatUserCtx is a tries to extract a fuse.Context from the generic ctx and
-// calls OpenatUser.
-func OpenatUserCtx(dirfd int, path string, flags int, mode uint32, ctx context.Context) (fd int, err error) {
- var ctx2 *fuse.Context
- if ctx != nil {
- if caller, ok := fuse.FromContext(ctx); ok {
- ctx2 = &fuse.Context{
- Caller: *caller,
- }
- }
- }
- return OpenatUser(dirfd, path, flags, mode, ctx2)
-}
-
// OpenatUser runs the Openat syscall in the context of a different user.
func OpenatUser(dirfd int, path string, flags int, mode uint32, context *fuse.Context) (fd int, err error) {
if context != nil {
@@ -136,20 +121,6 @@ func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) {
return syscall.Mknodat(dirfd, path, mode, dev)
}
-// MknodatUserCtx is a tries to extract a fuse.Context from the generic ctx and
-// calls OpenatUser.
-func MknodatUserCtx(dirfd int, path string, mode uint32, dev int, ctx context.Context) (err error) {
- var ctx2 *fuse.Context
- if ctx != nil {
- if caller, ok := fuse.FromContext(ctx); ok {
- ctx2 = &fuse.Context{
- Caller: *caller,
- }
- }
- }
- return MknodatUser(dirfd, path, mode, dev, ctx2)
-}
-
// MknodatUser runs the Mknodat syscall in the context of a different user.
func MknodatUser(dirfd int, path string, mode uint32, dev int, context *fuse.Context) (err error) {
if context != nil {