diff options
Diffstat (limited to 'internal/fusefrontend_reverse')
-rw-r--r-- | internal/fusefrontend_reverse/node.go | 4 | ||||
-rw-r--r-- | internal/fusefrontend_reverse/node_helpers.go | 3 | ||||
-rw-r--r-- | internal/fusefrontend_reverse/root_node.go | 21 | ||||
-rw-r--r-- | internal/fusefrontend_reverse/virtualconf.go | 9 | ||||
-rw-r--r-- | internal/fusefrontend_reverse/virtualnode.go | 4 |
5 files changed, 34 insertions, 7 deletions
diff --git a/internal/fusefrontend_reverse/node.go b/internal/fusefrontend_reverse/node.go index 22ad975..30654e0 100644 --- a/internal/fusefrontend_reverse/node.go +++ b/internal/fusefrontend_reverse/node.go @@ -69,6 +69,10 @@ func (n *Node) Lookup(ctx context.Context, cName string, out *fuse.EntryOut) (ch n.translateSize(d.dirfd, cName, d.pName, &out.Attr) } + if rn.args.ForceOwner != nil { + out.Owner = *rn.args.ForceOwner + } + // Usually we always create a new Node ID by always incrementing the generation // number. // diff --git a/internal/fusefrontend_reverse/node_helpers.go b/internal/fusefrontend_reverse/node_helpers.go index 6bba097..30361bc 100644 --- a/internal/fusefrontend_reverse/node_helpers.go +++ b/internal/fusefrontend_reverse/node_helpers.go @@ -201,6 +201,9 @@ func (n *Node) lookupConf(ctx context.Context, out *fuse.EntryOut) (ch *fs.Inode // Get unique inode number rn.inoMap.TranslateStat(&st) out.Attr.FromStat(&st) + if rn.args.ForceOwner != nil { + out.Owner = *rn.args.ForceOwner + } // Create child node id := rn.uniqueStableAttr(uint32(st.Mode), st.Ino) node := &VirtualConfNode{path: p} diff --git a/internal/fusefrontend_reverse/root_node.go b/internal/fusefrontend_reverse/root_node.go index 1a68ffd..cb04151 100644 --- a/internal/fusefrontend_reverse/root_node.go +++ b/internal/fusefrontend_reverse/root_node.go @@ -8,20 +8,18 @@ import ( "sync/atomic" "syscall" - "github.com/rfjakob/gocryptfs/v2/internal/exitcodes" - - "github.com/rfjakob/gocryptfs/v2/internal/tlog" - "golang.org/x/sys/unix" "github.com/hanwen/go-fuse/v2/fs" "github.com/hanwen/go-fuse/v2/fuse" "github.com/rfjakob/gocryptfs/v2/internal/contentenc" + "github.com/rfjakob/gocryptfs/v2/internal/exitcodes" "github.com/rfjakob/gocryptfs/v2/internal/fusefrontend" "github.com/rfjakob/gocryptfs/v2/internal/inomap" "github.com/rfjakob/gocryptfs/v2/internal/nametransform" "github.com/rfjakob/gocryptfs/v2/internal/syscallcompat" + "github.com/rfjakob/gocryptfs/v2/internal/tlog" "github.com/sabhiram/go-gitignore" ) @@ -53,6 +51,8 @@ type RootNode struct { // bizarre problems when inode numbers are reused behind our back, // like this one: https://github.com/rfjakob/gocryptfs/issues/802 gen uint64 + // rootIno is the inode number that we report for the root node on mount + rootIno uint64 } // NewRootNode returns an encrypted FUSE overlay filesystem. @@ -61,9 +61,10 @@ type RootNode struct { func NewRootNode(args fusefrontend.Args, c *contentenc.ContentEnc, n *nametransform.NameTransform) *RootNode { var rootDev uint64 var st syscall.Stat_t + var statErr error var shortNameMax int - if err := syscall.Stat(args.Cipherdir, &st); err != nil { - tlog.Warn.Printf("Could not stat backing directory %q: %v", args.Cipherdir, err) + if statErr = syscall.Stat(args.Cipherdir, &st); statErr != nil { + tlog.Warn.Printf("Could not stat backing directory %q: %v", args.Cipherdir, statErr) if args.OneFileSystem { tlog.Fatal.Printf("This is a fatal error in combination with -one-file-system") os.Exit(exitcodes.CipherDir) @@ -83,6 +84,10 @@ func NewRootNode(args fusefrontend.Args, c *contentenc.ContentEnc, n *nametransf rootDev: rootDev, shortNameMax: shortNameMax, } + if statErr == nil { + rn.inoMap.TranslateStat(&st) + rn.rootIno = st.Ino + } if len(args.Exclude) > 0 || len(args.ExcludeWildcard) > 0 || len(args.ExcludeFrom) > 0 { rn.excluder = prepareExcluder(args) } @@ -173,3 +178,7 @@ func (rn *RootNode) uniqueStableAttr(mode uint32, ino uint64) fs.StableAttr { Gen: atomic.AddUint64(&rn.gen, 1), } } + +func (rn *RootNode) RootIno() uint64 { + return rn.rootIno +} diff --git a/internal/fusefrontend_reverse/virtualconf.go b/internal/fusefrontend_reverse/virtualconf.go index 3643fad..ea358dd 100644 --- a/internal/fusefrontend_reverse/virtualconf.go +++ b/internal/fusefrontend_reverse/virtualconf.go @@ -18,6 +18,11 @@ type VirtualConfNode struct { path string } +// rootNode returns the Root Node of the filesystem. +func (n *VirtualConfNode) rootNode() *RootNode { + return n.Root().Operations().(*RootNode) +} + func (n *VirtualConfNode) Open(ctx context.Context, flags uint32) (fh fs.FileHandle, fuseFlags uint32, errno syscall.Errno) { fd, err := syscall.Open(n.path, syscall.O_RDONLY, 0) if err != nil { @@ -35,6 +40,10 @@ func (n *VirtualConfNode) Getattr(ctx context.Context, fh fs.FileHandle, out *fu return fs.ToErrno(err) } out.FromStat(&st) + rn := n.rootNode() + if rn.args.ForceOwner != nil { + out.Owner = *rn.args.ForceOwner + } return 0 } diff --git a/internal/fusefrontend_reverse/virtualnode.go b/internal/fusefrontend_reverse/virtualnode.go index 922cfa7..732564a 100644 --- a/internal/fusefrontend_reverse/virtualnode.go +++ b/internal/fusefrontend_reverse/virtualnode.go @@ -100,7 +100,9 @@ func (n *Node) newVirtualMemNode(content []byte, parentStat *syscall.Stat_t, ino st.Nlink = 1 var a fuse.Attr a.FromStat(st) - + if rn.args.ForceOwner != nil { + a.Owner = *rn.args.ForceOwner + } vf = &VirtualMemNode{content: content, attr: a} return } |