The root inode ends with a lookup count of one, too.

geesefs-0-30-9
Aaron Jacobs 2015-03-31 09:53:39 +11:00
parent 8e04b7d848
commit ee2040958c
2 changed files with 13 additions and 2 deletions

View File

@ -241,7 +241,8 @@ func (o *SetInodeAttributesOp) Respond(err error) {
// revalidating. // revalidating.
// //
// In contrast to all other inodes, RootInodeID begins with an implicit // 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. // * (http://goo.gl/gWAheU) fuse_fill_super calls fuse_get_root_inode.
// //

View File

@ -35,7 +35,7 @@ import (
// The file system maintains reference counts for the inodes involved. It will // 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 // 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 // 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. // unmounting.
func NewFileSystem() (fs *ForgetFS) { func NewFileSystem() (fs *ForgetFS) {
// Set up the actual file system. // Set up the actual file system.
@ -179,6 +179,16 @@ func (fs *fsImpl) Check() {
defer fs.mu.Unlock() defer fs.mu.Unlock()
for k, v := range fs.inodes { 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 { if v.lookupCount != 0 {
panic(fmt.Sprintf("Inode %v has lookup count %v", k, v.lookupCount)) panic(fmt.Sprintf("Inode %v has lookup count %v", k, v.lookupCount))
} }