v2api: remove OpenatUserCtx, MknodatUserCtx helpers

Instead, use the new toFuseCtx() function introduced
in an earlier commit.
This commit is contained in:
Jakob Unterwurzacher 2020-07-11 19:44:45 +02:00
parent 250dbc6436
commit 84344834c4
3 changed files with 26 additions and 33 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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 {