fusefronted: replace last rn.openBackingDir() calls

Use the n.prepareAtSyscall() wrapper instead. Prepares
for adding caching into n.prepareAtSyscall().
This commit is contained in:
Jakob Unterwurzacher 2021-04-03 11:19:04 +02:00
parent beab7004f2
commit 6b28c0be2c
1 changed files with 13 additions and 19 deletions

View File

@ -66,25 +66,21 @@ func (n *Node) mkdirWithIv(dirfd int, cName string, mode uint32, caller *fuse.Ca
// //
// Symlink-safe through use of Mkdirat(). // Symlink-safe through use of Mkdirat().
func (n *Node) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) { func (n *Node) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) {
rn := n.rootNode() dirfd, cName, errno := n.prepareAtSyscall(name)
newPath := filepath.Join(n.Path(), name) if errno != 0 {
if rn.isFiltered(newPath) { return nil, errno
return nil, syscall.EPERM
}
dirfd, cName, err := rn.openBackingDir(newPath)
if err != nil {
return nil, fs.ToErrno(err)
} }
defer syscall.Close(dirfd) defer syscall.Close(dirfd)
rn := n.rootNode()
var caller *fuse.Caller var caller *fuse.Caller
if rn.args.PreserveOwner { if rn.args.PreserveOwner {
caller, _ = fuse.FromContext(ctx) caller, _ = fuse.FromContext(ctx)
} }
var st syscall.Stat_t var st syscall.Stat_t
if rn.args.PlaintextNames { if rn.args.PlaintextNames {
err = syscallcompat.MkdiratUser(dirfd, cName, mode, caller) err := syscallcompat.MkdiratUser(dirfd, cName, mode, caller)
if err != nil { if err != nil {
return nil, fs.ToErrno(err) return nil, fs.ToErrno(err)
} }
@ -104,7 +100,7 @@ func (n *Node) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.En
// Handle long file name // Handle long file name
if nametransform.IsLongContent(cName) { if nametransform.IsLongContent(cName) {
// Create ".name" // Create ".name"
err = rn.nameTransform.WriteLongNameAt(dirfd, cName, newPath) err := rn.nameTransform.WriteLongNameAt(dirfd, cName, name)
if err != nil { if err != nil {
return nil, fs.ToErrno(err) return nil, fs.ToErrno(err)
} }
@ -116,7 +112,7 @@ func (n *Node) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.En
return nil, fs.ToErrno(err) return nil, fs.ToErrno(err)
} }
} else { } else {
err = rn.mkdirWithIv(dirfd, cName, mode, caller) err := rn.mkdirWithIv(dirfd, cName, mode, caller)
if err != nil { if err != nil {
return nil, fs.ToErrno(err) return nil, fs.ToErrno(err)
} }
@ -158,12 +154,9 @@ func (n *Node) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.En
// This function is symlink-safe through use of openBackingDir() and // This function is symlink-safe through use of openBackingDir() and
// ReadDirIVAt(). // ReadDirIVAt().
func (n *Node) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) { func (n *Node) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
rn := n.rootNode() parentDirFd, cDirName, errno := n.prepareAtSyscall("")
p := n.Path() if errno != 0 {
dirName := filepath.Base(p) return nil, errno
parentDirFd, cDirName, err := rn.openBackingDir(p)
if err != nil {
return nil, fs.ToErrno(err)
} }
defer syscall.Close(parentDirFd) defer syscall.Close(parentDirFd)
@ -180,6 +173,7 @@ func (n *Node) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
} }
// Get DirIV (stays nil if PlaintextNames is used) // Get DirIV (stays nil if PlaintextNames is used)
var cachedIV []byte var cachedIV []byte
rn := n.rootNode()
if !rn.args.PlaintextNames { if !rn.args.PlaintextNames {
// Read the DirIV from disk // Read the DirIV from disk
cachedIV, err = nametransform.ReadDirIVAt(fd) cachedIV, err = nametransform.ReadDirIVAt(fd)
@ -193,7 +187,7 @@ func (n *Node) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
// Filter and decrypt filenames // Filter and decrypt filenames
for i := range cipherEntries { for i := range cipherEntries {
cName := cipherEntries[i].Name cName := cipherEntries[i].Name
if dirName == "." && cName == configfile.ConfDefaultName { if n.IsRoot() && cName == configfile.ConfDefaultName {
// silently ignore "gocryptfs.conf" in the top level dir // silently ignore "gocryptfs.conf" in the top level dir
continue continue
} }