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
// 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
}

View File

@ -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))