Added memfs support for nlink.

geesefs-0-30-9
Aaron Jacobs 2015-03-18 14:13:37 +11:00
parent 7e8f3266ef
commit 7120eb1f3d
2 changed files with 7 additions and 19 deletions

View File

@ -305,9 +305,10 @@ func (fs *memFS) MkDir(
// Set up attributes from the child, using the credentials of the calling // Set up attributes from the child, using the credentials of the calling
// process as owner (matching inode_init_owner, cf. http://goo.gl/5qavg8). // process as owner (matching inode_init_owner, cf. http://goo.gl/5qavg8).
childAttrs := fuse.InodeAttributes{ childAttrs := fuse.InodeAttributes{
Mode: req.Mode, Nlink: 1,
Uid: req.Header.Uid, Mode: req.Mode,
Gid: req.Header.Gid, Uid: req.Header.Uid,
Gid: req.Header.Gid,
} }
// Allocate a child. // Allocate a child.
@ -345,6 +346,7 @@ func (fs *memFS) CreateFile(
// process as owner (matching inode_init_owner, cf. http://goo.gl/5qavg8). // process as owner (matching inode_init_owner, cf. http://goo.gl/5qavg8).
now := fs.clock.Now() now := fs.clock.Now()
childAttrs := fuse.InodeAttributes{ childAttrs := fuse.InodeAttributes{
Nlink: 1,
Mode: req.Mode, Mode: req.Mode,
Atime: now, Atime: now,
Mtime: now, Mtime: now,
@ -408,7 +410,7 @@ func (fs *memFS) RmDir(
parent.RemoveChild(req.Name) parent.RemoveChild(req.Name)
// Mark the child as unlinked. // Mark the child as unlinked.
child.linkCount-- child.attributes.Nlink--
return return
} }
@ -440,7 +442,7 @@ func (fs *memFS) Unlink(
parent.RemoveChild(req.Name) parent.RemoveChild(req.Name)
// Mark the child as unlinked. // Mark the child as unlinked.
child.linkCount-- child.attributes.Nlink--
return return
} }

View File

@ -47,13 +47,6 @@ type inode struct {
mu syncutil.InvariantMutex 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. // The current attributes of this inode.
// //
// INVARIANT: No non-permission mode bits are set besides os.ModeDir // 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 // Create a new inode with the supplied attributes, which need not contain
// time-related information (the inode object will take care of that). // time-related information (the inode object will take care of that).
// Initially the link count is one.
func newInode( func newInode(
clock timeutil.Clock, clock timeutil.Clock,
attrs fuse.InodeAttributes) (in *inode) { attrs fuse.InodeAttributes) (in *inode) {
@ -99,7 +91,6 @@ func newInode(
// Create the object. // Create the object.
in = &inode{ in = &inode{
clock: clock, clock: clock,
linkCount: 1,
dir: (attrs.Mode&os.ModeDir != 0), dir: (attrs.Mode&os.ModeDir != 0),
attributes: attrs, attributes: attrs,
} }
@ -109,11 +100,6 @@ func newInode(
} }
func (inode *inode) checkInvariants() { 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. // No non-permission mode bits should be set besides os.ModeDir.
if inode.attributes.Mode & ^(os.ModePerm|os.ModeDir) != 0 { if inode.attributes.Mode & ^(os.ModePerm|os.ModeDir) != 0 {
panic(fmt.Sprintf("Unexpected mode: %v", inode.attributes.Mode)) panic(fmt.Sprintf("Unexpected mode: %v", inode.attributes.Mode))