diff --git a/samples/memfs/fs.go b/samples/memfs/fs.go index 30a33e7..23923f1 100644 --- a/samples/memfs/fs.go +++ b/samples/memfs/fs.go @@ -57,9 +57,10 @@ func NewMemFS( inodes: make([]*inode, fuse.RootInodeID+1), } - // Set up the root inode. + // Set up the root inode. Its ownership information will later be modified in + // Init. rootAttrs := fuse.InodeAttributes{ - Mode: 0777 | os.ModeDir, + Mode: 0700 | os.ModeDir, } fs.inodes[fuse.RootInodeID] = newInode(rootAttrs) @@ -70,6 +71,10 @@ func NewMemFS( return fs } +//////////////////////////////////////////////////////////////////////// +// Helpers +//////////////////////////////////////////////////////////////////////// + func (fs *memFS) checkInvariants() { // Check reserved inodes. for i := 0; i < fuse.RootInodeID; i++ { @@ -109,13 +114,6 @@ func (fs *memFS) checkInvariants() { } } -func (fs *memFS) Init( - ctx context.Context, - req *fuse.InitRequest) (resp *fuse.InitResponse, err error) { - resp = &fuse.InitResponse{} - return -} - // Find the given inode and return it with its lock held. Panic if it doesn't // exist. // @@ -171,6 +169,29 @@ func (fs *memFS) allocateInode( return } +//////////////////////////////////////////////////////////////////////// +// FileSystem methods +//////////////////////////////////////////////////////////////////////// + +func (fs *memFS) Init( + ctx context.Context, + req *fuse.InitRequest) (resp *fuse.InitResponse, err error) { + resp = &fuse.InitResponse{} + + fs.mu.RLock() + defer fs.mu.RUnlock() + + // Update the root inode's ownership information to match the credentials of + // the mounting process. + root := fs.getInodeForModifyingOrDie(fuse.RootInodeID) + defer root.mu.Unlock() + + root.attributes.Uid = req.Header.Uid + root.attributes.Gid = req.Header.Gid + + return +} + func (fs *memFS) LookUpInode( ctx context.Context, req *fuse.LookUpInodeRequest) (resp *fuse.LookUpInodeResponse, err error) { diff --git a/samples/memfs/inode.go b/samples/memfs/inode.go index a22bdc7..f17306e 100644 --- a/samples/memfs/inode.go +++ b/samples/memfs/inode.go @@ -59,6 +59,10 @@ type inode struct { contents []byte // GUARDED_BY(mu) } +//////////////////////////////////////////////////////////////////////// +// Helpers +//////////////////////////////////////////////////////////////////////// + func newInode(attrs fuse.InodeAttributes) (in *inode) { in = &inode{ dir: (attrs.Mode&os.ModeDir != 0), @@ -112,6 +116,10 @@ func (inode *inode) checkInvariants() { } } +//////////////////////////////////////////////////////////////////////// +// Public methods +//////////////////////////////////////////////////////////////////////// + // Find an entry for the given child name and return its inode ID. // // REQUIRES: inode.dir