Skip to content

Commit

Permalink
syscallcompat: refactor MkdiratUser to take fuse.Context
Browse files Browse the repository at this point in the history
Let's have MkdiratUser take fuse.Context like everybody
else.
  • Loading branch information
rfjakob committed May 22, 2021
1 parent cb4f9f9 commit e1853e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
14 changes: 7 additions & 7 deletions internal/fusefrontend/node_dir_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ func haveDsstore(entries []fuse.DirEntry) bool {
// mkdirWithIv - create a new directory and corresponding diriv file. dirfd
// should be a handle to the parent directory, cName is the name of the new
// directory and mode specifies the access permissions to use.
func (n *Node) mkdirWithIv(dirfd int, cName string, mode uint32, caller *fuse.Caller) error {
func (n *Node) mkdirWithIv(dirfd int, cName string, mode uint32, context *fuse.Context) error {
rn := n.rootNode()
// Between the creation of the directory and the creation of gocryptfs.diriv
// the directory is inconsistent. Take the lock to prevent other readers
// from seeing it.
rn.dirIVLock.Lock()
defer rn.dirIVLock.Unlock()
err := syscallcompat.MkdiratUser(dirfd, cName, mode, caller)
err := syscallcompat.MkdiratUser(dirfd, cName, mode, context)
if err != nil {
return err
}
Expand Down Expand Up @@ -73,14 +73,14 @@ func (n *Node) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.En
defer syscall.Close(dirfd)

rn := n.rootNode()
var caller *fuse.Caller
var context *fuse.Context
if rn.args.PreserveOwner {
caller, _ = fuse.FromContext(ctx)
context = toFuseCtx(ctx)
}

var st syscall.Stat_t
if rn.args.PlaintextNames {
err := syscallcompat.MkdiratUser(dirfd, cName, mode, caller)
err := syscallcompat.MkdiratUser(dirfd, cName, mode, context)
if err != nil {
return nil, fs.ToErrno(err)
}
Expand All @@ -106,13 +106,13 @@ func (n *Node) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.En
}

// Create directory
err = rn.mkdirWithIv(dirfd, cName, mode, caller)
err = rn.mkdirWithIv(dirfd, cName, mode, context)
if err != nil {
nametransform.DeleteLongNameAt(dirfd, cName)
return nil, fs.ToErrno(err)
}
} else {
err := rn.mkdirWithIv(dirfd, cName, mode, caller)
err := rn.mkdirWithIv(dirfd, cName, mode, context)
if err != nil {
return nil, fs.ToErrno(err)
}
Expand Down
9 changes: 1 addition & 8 deletions internal/syscallcompat/sys_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,11 @@ func SymlinkatUser(oldpath string, newdirfd int, newpath string, context *fuse.C
// MkdiratUser runs the Mkdirat syscall in the context of a different user.
//
// See OpenatUser() for how this works.
func MkdiratUser(dirfd int, path string, mode uint32, caller *fuse.Caller) (err error) {
func MkdiratUser(dirfd int, path string, mode uint32, context *fuse.Context) (err error) {
f := func() (int, error) {
err := Mkdirat(dirfd, path, mode)
return -1, err
}
// TODO: refactor MkdiratUser to take context instead of caller
var context *fuse.Context
if caller != nil {
context = &fuse.Context{
Caller: *caller,
}
}
_, err = asUser(f, context)
return err
}
Expand Down

0 comments on commit e1853e1

Please sign in to comment.