v2api: move helpers from node.go to node_helpers.go
This commit is contained in:
parent
8afbbc86d1
commit
1867fdaef4
@ -3,7 +3,6 @@ package fusefrontend
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
@ -22,40 +21,6 @@ type Node struct {
|
||||
fs.Inode
|
||||
}
|
||||
|
||||
// Path returns the relative plaintext path of this node
|
||||
func (n *Node) Path() string {
|
||||
return n.Inode.Path(n.Root())
|
||||
}
|
||||
|
||||
// rootNode returns the Root Node of the filesystem.
|
||||
func (n *Node) rootNode() *RootNode {
|
||||
return n.Root().Operations().(*RootNode)
|
||||
}
|
||||
|
||||
// prepareAtSyscall returns a (dirfd, cName) pair that can be used
|
||||
// with the "___at" family of system calls (openat, fstatat, unlinkat...) to
|
||||
// access the backing encrypted directory.
|
||||
//
|
||||
// If you pass a `child` file name, the (dirfd, cName) pair will refer to
|
||||
// a child of this node.
|
||||
// If `child` is empty, the (dirfd, cName) pair refers to this node itself.
|
||||
func (n *Node) prepareAtSyscall(child string) (dirfd int, cName string, errno syscall.Errno) {
|
||||
p := n.Path()
|
||||
if child != "" {
|
||||
p = filepath.Join(p, child)
|
||||
}
|
||||
rn := n.rootNode()
|
||||
if rn.isFiltered(p) {
|
||||
errno = syscall.EPERM
|
||||
return
|
||||
}
|
||||
dirfd, cName, err := rn.openBackingDir(p)
|
||||
if err != nil {
|
||||
errno = fs.ToErrno(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Lookup - FUSE call for discovering a file.
|
||||
func (n *Node) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (ch *fs.Inode, errno syscall.Errno) {
|
||||
dirfd, cName, errno := n.prepareAtSyscall(name)
|
||||
@ -113,23 +78,6 @@ func (n *Node) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOut)
|
||||
return 0
|
||||
}
|
||||
|
||||
// newChild attaches a new child inode to n.
|
||||
// The passed-in `st` will be modified to get a unique inode number.
|
||||
func (n *Node) newChild(ctx context.Context, st *syscall.Stat_t, out *fuse.EntryOut) *fs.Inode {
|
||||
// Get unique inode number
|
||||
rn := n.rootNode()
|
||||
rn.inoMap.TranslateStat(st)
|
||||
out.Attr.FromStat(st)
|
||||
// Create child node
|
||||
id := fs.StableAttr{
|
||||
Mode: uint32(st.Mode),
|
||||
Gen: 1,
|
||||
Ino: st.Ino,
|
||||
}
|
||||
node := &Node{}
|
||||
return n.NewInode(ctx, node, id)
|
||||
}
|
||||
|
||||
// Create - FUSE call. Creates a new file.
|
||||
//
|
||||
// Symlink-safe through the use of Openat().
|
||||
|
@ -2,6 +2,7 @@ package fusefrontend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
|
||||
"github.com/hanwen/go-fuse/v2/fs"
|
||||
@ -63,3 +64,54 @@ func (n *Node) translateSize(dirfd int, cName string, out *fuse.Attr) {
|
||||
out.Size = uint64(len(target))
|
||||
}
|
||||
}
|
||||
|
||||
// Path returns the relative plaintext path of this node
|
||||
func (n *Node) Path() string {
|
||||
return n.Inode.Path(n.Root())
|
||||
}
|
||||
|
||||
// rootNode returns the Root Node of the filesystem.
|
||||
func (n *Node) rootNode() *RootNode {
|
||||
return n.Root().Operations().(*RootNode)
|
||||
}
|
||||
|
||||
// prepareAtSyscall returns a (dirfd, cName) pair that can be used
|
||||
// with the "___at" family of system calls (openat, fstatat, unlinkat...) to
|
||||
// access the backing encrypted directory.
|
||||
//
|
||||
// If you pass a `child` file name, the (dirfd, cName) pair will refer to
|
||||
// a child of this node.
|
||||
// If `child` is empty, the (dirfd, cName) pair refers to this node itself.
|
||||
func (n *Node) prepareAtSyscall(child string) (dirfd int, cName string, errno syscall.Errno) {
|
||||
p := n.Path()
|
||||
if child != "" {
|
||||
p = filepath.Join(p, child)
|
||||
}
|
||||
rn := n.rootNode()
|
||||
if rn.isFiltered(p) {
|
||||
errno = syscall.EPERM
|
||||
return
|
||||
}
|
||||
dirfd, cName, err := rn.openBackingDir(p)
|
||||
if err != nil {
|
||||
errno = fs.ToErrno(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// newChild attaches a new child inode to n.
|
||||
// The passed-in `st` will be modified to get a unique inode number.
|
||||
func (n *Node) newChild(ctx context.Context, st *syscall.Stat_t, out *fuse.EntryOut) *fs.Inode {
|
||||
// Get unique inode number
|
||||
rn := n.rootNode()
|
||||
rn.inoMap.TranslateStat(st)
|
||||
out.Attr.FromStat(st)
|
||||
// Create child node
|
||||
id := fs.StableAttr{
|
||||
Mode: uint32(st.Mode),
|
||||
Gen: 1,
|
||||
Ino: st.Ino,
|
||||
}
|
||||
node := &Node{}
|
||||
return n.NewInode(ctx, node, id)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user