From 7120eb1f3d94e34d1e4698bb2eaad1561a7b2eb7 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Wed, 18 Mar 2015 14:13:37 +1100 Subject: [PATCH] Added memfs support for nlink. --- samples/memfs/fs.go | 12 +++++++----- samples/memfs/inode.go | 14 -------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/samples/memfs/fs.go b/samples/memfs/fs.go index b260cb4..ac77f9f 100644 --- a/samples/memfs/fs.go +++ b/samples/memfs/fs.go @@ -305,9 +305,10 @@ func (fs *memFS) MkDir( // Set up attributes from the child, using the credentials of the calling // process as owner (matching inode_init_owner, cf. http://goo.gl/5qavg8). childAttrs := fuse.InodeAttributes{ - Mode: req.Mode, - Uid: req.Header.Uid, - Gid: req.Header.Gid, + Nlink: 1, + Mode: req.Mode, + Uid: req.Header.Uid, + Gid: req.Header.Gid, } // Allocate a child. @@ -345,6 +346,7 @@ func (fs *memFS) CreateFile( // process as owner (matching inode_init_owner, cf. http://goo.gl/5qavg8). now := fs.clock.Now() childAttrs := fuse.InodeAttributes{ + Nlink: 1, Mode: req.Mode, Atime: now, Mtime: now, @@ -408,7 +410,7 @@ func (fs *memFS) RmDir( parent.RemoveChild(req.Name) // Mark the child as unlinked. - child.linkCount-- + child.attributes.Nlink-- return } @@ -440,7 +442,7 @@ func (fs *memFS) Unlink( parent.RemoveChild(req.Name) // Mark the child as unlinked. - child.linkCount-- + child.attributes.Nlink-- return } diff --git a/samples/memfs/inode.go b/samples/memfs/inode.go index 58cbbdc..3ff4175 100644 --- a/samples/memfs/inode.go +++ b/samples/memfs/inode.go @@ -47,13 +47,6 @@ type inode struct { mu syncutil.InvariantMutex - // The number of times this inode is linked into a parent directory. This may - // be zero if the inode has been unlinked but not yet forgotten, because some - // process still has an open file handle. - // - // INVARIANT: linkCount >= 0 - linkCount int // GUARDED_BY(mu) - // The current attributes of this inode. // // INVARIANT: No non-permission mode bits are set besides os.ModeDir @@ -87,7 +80,6 @@ type inode struct { // Create a new inode with the supplied attributes, which need not contain // time-related information (the inode object will take care of that). -// Initially the link count is one. func newInode( clock timeutil.Clock, attrs fuse.InodeAttributes) (in *inode) { @@ -99,7 +91,6 @@ func newInode( // Create the object. in = &inode{ clock: clock, - linkCount: 1, dir: (attrs.Mode&os.ModeDir != 0), attributes: attrs, } @@ -109,11 +100,6 @@ func newInode( } func (inode *inode) checkInvariants() { - // Check the link count. - if inode.linkCount < 0 { - panic(fmt.Sprintf("Negative link count: %v", inode.linkCount)) - } - // No non-permission mode bits should be set besides os.ModeDir. if inode.attributes.Mode & ^(os.ModePerm|os.ModeDir) != 0 { panic(fmt.Sprintf("Unexpected mode: %v", inode.attributes.Mode))