From 2cf18ad9a51500e4ec35e95b4d1957c1c903e16d Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Tue, 3 Mar 2015 09:33:33 +1100 Subject: [PATCH] Fixed some build errors. --- samples/memfs/fs.go | 30 ++++++++++++++++++++++++++---- samples/memfs/inode.go | 9 +++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/samples/memfs/fs.go b/samples/memfs/fs.go index c1a373f..beacbf2 100644 --- a/samples/memfs/fs.go +++ b/samples/memfs/fs.go @@ -112,8 +112,23 @@ func (fs *memFS) Init( return } -// Find the supplied inode and return it with its lock held for reading. Panic -// if it doesn't exist. +// Find the given inode and return it with its lock held. Panic if it doesn't +// exist. +// +// SHARED_LOCKS_REQUIRED(fs.mu) +// EXCLUSIVE_LOCK_FUNCTION(inode.mu) +func (fs *memFS) getInodeForModifyingOrDie(id fuse.InodeID) (inode *inode) { + inode = fs.inodes[id] + if inode == nil { + panic(fmt.Sprintf("Unknown inode: %v", id)) + } + + inode.mu.Lock() + return +} + +// Find the given inode and return it with its lock held for reading. Panic if +// it doesn't exist. // // SHARED_LOCKS_REQUIRED(fs.mu) // SHARED_LOCK_FUNCTION(inode.mu) @@ -127,6 +142,13 @@ func (fs *memFS) getInodeForReadingOrDie(id fuse.InodeID) (inode *inode) { return } +// Allocate a new inode, assigning it an ID that is not in use. Return it with +// its lock held. +// +// EXCLUSIVE_LOCKS_REQUIRED(fs.mu) +// EXCLUSIVE_LOCK_FUNCTION(inode.mu) +func (fs *memFS) allocateInode(mode os.FileMode) (id fuse.InodeID, inode *inode) + func (fs *memFS) LookUpInode( ctx context.Context, req *fuse.LookUpInodeRequest) (resp *fuse.LookUpInodeResponse, err error) { @@ -193,7 +215,7 @@ func (fs *memFS) MkDir( defer fs.mu.Unlock() // Grab the parent, which we will update shortly. - parent := fs.getInodeForModifying(req.Parent) + parent := fs.getInodeForModifyingOrDie(req.Parent) defer parent.mu.Unlock() // Allocate a child. @@ -201,7 +223,7 @@ func (fs *memFS) MkDir( defer child.mu.Unlock() // Add an entry in the parent. - parent.AddEntry(childID, req.Name, fuseutil.DT_Directory) + parent.AddChild(childID, req.Name, fuseutil.DT_Directory) // Fill in the response. resp.Entry.Attributes = child.attributes diff --git a/samples/memfs/inode.go b/samples/memfs/inode.go index b87d6e5..76270a2 100644 --- a/samples/memfs/inode.go +++ b/samples/memfs/inode.go @@ -134,6 +134,15 @@ func (inode *inode) LookUpChild(name string) (id fuse.InodeID, ok bool) { return } +// Add an entry for a child. +// +// REQUIRES: inode.dir +// EXCLUSIVE_LOCKS_REQUIRED(inode.mu) +func (inode *inode) AddChild( + id fuse.InodeID, + name string, + dt fuseutil.DirentType) + // Serve a ReadDir request. // // REQUIRED: inode.dir