From 3181e6495b0a1670b593011e7c21a558949f44b5 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Mon, 16 Mar 2015 13:27:14 +1100 Subject: [PATCH] Be explicit about ownership info for memfs. --- samples/memfs/fs.go | 21 +++++++-------------- samples/memfs/memfs_test.go | 2 +- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/samples/memfs/fs.go b/samples/memfs/fs.go index 68489d4..a37784f 100644 --- a/samples/memfs/fs.go +++ b/samples/memfs/fs.go @@ -60,8 +60,11 @@ type memFS struct { freeInodes []fuse.InodeID // GUARDED_BY(mu) } -// Create a file system that stores data and metadata in memory. +// Create a file system that stores data and metadata in memory. The supplied +// UID/GID pair will own the root inode. func NewMemFS( + uid uint32, + gid uint32, clock timeutil.Clock) fuse.FileSystem { // Set up the basic struct. fs := &memFS{ @@ -69,10 +72,11 @@ func NewMemFS( inodes: make([]*inode, fuse.RootInodeID+1), } - // Set up the root inode. Its ownership information will later be modified in - // Init. + // Set up the root inode. rootAttrs := fuse.InodeAttributes{ Mode: 0700 | os.ModeDir, + Uid: uid, + Gid: gid, } fs.inodes[fuse.RootInodeID] = newInode(clock, rootAttrs) @@ -196,17 +200,6 @@ func (fs *memFS) Init( 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 } diff --git a/samples/memfs/memfs_test.go b/samples/memfs/memfs_test.go index 73cdda8..6b68f7e 100644 --- a/samples/memfs/memfs_test.go +++ b/samples/memfs/memfs_test.go @@ -111,7 +111,7 @@ func (t *MemFSTest) SetUp(ti *TestInfo) { } // Mount a file system. - fs := memfs.NewMemFS(&t.clock) + fs := memfs.NewMemFS(currentUid(), currentGid(), &t.clock) if t.mfs, err = fuse.Mount(mountPoint, fs); err != nil { panic("Mount: " + err.Error()) }