From ee2040958cbea36023c05a0ffbb18757638573be Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Tue, 31 Mar 2015 09:53:39 +1100 Subject: [PATCH] The root inode ends with a lookup count of one, too. --- fuseops/ops.go | 3 ++- samples/forgetfs/forget_fs.go | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/fuseops/ops.go b/fuseops/ops.go index 20664f5..7d43b73 100644 --- a/fuseops/ops.go +++ b/fuseops/ops.go @@ -241,7 +241,8 @@ func (o *SetInodeAttributesOp) Respond(err error) { // revalidating. // // In contrast to all other inodes, RootInodeID begins with an implicit -// reference count of one, without a corresponding op to increase it: +// reference count of one, without a corresponding op to increase it. It also +// is never decremented to zero. Code walk: // // * (http://goo.gl/gWAheU) fuse_fill_super calls fuse_get_root_inode. // diff --git a/samples/forgetfs/forget_fs.go b/samples/forgetfs/forget_fs.go index 4256881..ab9692f 100644 --- a/samples/forgetfs/forget_fs.go +++ b/samples/forgetfs/forget_fs.go @@ -35,7 +35,7 @@ import ( // The file system maintains reference counts for the inodes involved. It will // panic if a reference count becomes negative or if an inode ID is re-used // after we expect it to be dead. Its Check method may be used to check that -// there are no inodes with non-zero reference counts remaining, after +// there are no inodes with unexpected reference counts remaining, after // unmounting. func NewFileSystem() (fs *ForgetFS) { // Set up the actual file system. @@ -179,6 +179,16 @@ func (fs *fsImpl) Check() { defer fs.mu.Unlock() for k, v := range fs.inodes { + // Special case: the root inode should have an implicit lookup count of 1. + if k == fuseops.RootInodeID { + if v.lookupCount != 1 { + panic(fmt.Sprintf("Root has lookup count %v", v.lookupCount)) + } + + continue + } + + // Check other inodes. if v.lookupCount != 0 { panic(fmt.Sprintf("Inode %v has lookup count %v", k, v.lookupCount)) }