Refactored newInode.
parent
bb1539e613
commit
5cf0f2b6bf
|
@ -58,7 +58,11 @@ func NewMemFS(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up the root inode.
|
// Set up the root inode.
|
||||||
fs.inodes[fuse.RootInodeID] = newInode(0777 | os.ModeDir)
|
rootAttrs := fuse.InodeAttributes{
|
||||||
|
Mode: 0777 | os.ModeDir,
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.inodes[fuse.RootInodeID] = newInode(rootAttrs)
|
||||||
|
|
||||||
// Set up invariant checking.
|
// Set up invariant checking.
|
||||||
fs.mu = syncutil.NewInvariantMutex(fs.checkInvariants)
|
fs.mu = syncutil.NewInvariantMutex(fs.checkInvariants)
|
||||||
|
@ -148,9 +152,9 @@ func (fs *memFS) getInodeForReadingOrDie(id fuse.InodeID) (inode *inode) {
|
||||||
// EXCLUSIVE_LOCKS_REQUIRED(fs.mu)
|
// EXCLUSIVE_LOCKS_REQUIRED(fs.mu)
|
||||||
// EXCLUSIVE_LOCK_FUNCTION(inode.mu)
|
// EXCLUSIVE_LOCK_FUNCTION(inode.mu)
|
||||||
func (fs *memFS) allocateInode(
|
func (fs *memFS) allocateInode(
|
||||||
mode os.FileMode) (id fuse.InodeID, inode *inode) {
|
attrs fuse.InodeAttributes) (id fuse.InodeID, inode *inode) {
|
||||||
// Create and lock the inode.
|
// Create and lock the inode.
|
||||||
inode = newInode(mode)
|
inode = newInode(attrs)
|
||||||
inode.mu.Lock()
|
inode.mu.Lock()
|
||||||
|
|
||||||
// Re-use a free ID if possible. Otherwise mint a new one.
|
// Re-use a free ID if possible. Otherwise mint a new one.
|
||||||
|
@ -238,7 +242,11 @@ func (fs *memFS) MkDir(
|
||||||
defer parent.mu.Unlock()
|
defer parent.mu.Unlock()
|
||||||
|
|
||||||
// Allocate a child.
|
// Allocate a child.
|
||||||
childID, child := fs.allocateInode(req.Mode)
|
childAttrs := fuse.InodeAttributes{
|
||||||
|
Mode: req.Mode,
|
||||||
|
}
|
||||||
|
|
||||||
|
childID, child := fs.allocateInode(childAttrs)
|
||||||
defer child.mu.Unlock()
|
defer child.mu.Unlock()
|
||||||
|
|
||||||
// Add an entry in the parent.
|
// Add an entry in the parent.
|
||||||
|
|
|
@ -59,12 +59,10 @@ type inode struct {
|
||||||
contents []byte // GUARDED_BY(mu)
|
contents []byte // GUARDED_BY(mu)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newInode(mode os.FileMode) (in *inode) {
|
func newInode(attrs fuse.InodeAttributes) (in *inode) {
|
||||||
in = &inode{
|
in = &inode{
|
||||||
dir: (mode&os.ModeDir != 0),
|
dir: (attrs.Mode&os.ModeDir != 0),
|
||||||
attributes: fuse.InodeAttributes{
|
attributes: attrs,
|
||||||
Mode: mode,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
in.mu = syncutil.NewInvariantMutex(in.checkInvariants)
|
in.mu = syncutil.NewInvariantMutex(in.checkInvariants)
|
||||||
|
|
Loading…
Reference in New Issue