Commit d0a8174e authored by Aaron Jacobs's avatar Aaron Jacobs

fsImpl.LookUpInode.

parent 541223bb
......@@ -136,6 +136,10 @@ type inode struct {
lookupCount int
}
////////////////////////////////////////////////////////////////////////
// Helpers
////////////////////////////////////////////////////////////////////////
// LOCKS_REQUIRED(fs.mu)
func (fs *fsImpl) checkInvariants() {
// INVARIANT: For each v in inodes, v.lookupCount >= 0
......@@ -165,6 +169,26 @@ func (fs *fsImpl) Check() {
}
}
// Look up the inode and verify it hasn't been forgotten.
//
// LOCKS_REQUIRED(fs.mu)
func (fs *fsImpl) findInodeByID(id fuseops.InodeID) (in *inode) {
in = fs.inodes[id]
if in == nil {
panic(fmt.Sprintf("Unknown inode: %v", id))
}
if in.lookupCount <= 0 {
panic(fmt.Sprintf("Forgotten inode: %v", id))
}
return
}
////////////////////////////////////////////////////////////////////////
// FileSystem methods
////////////////////////////////////////////////////////////////////////
func (fs *fsImpl) Init(
op *fuseops.InitOp) {
var err error
......@@ -173,24 +197,57 @@ func (fs *fsImpl) Init(
return
}
func (fs *fsImpl) GetInodeAttributes(
op *fuseops.GetInodeAttributesOp) {
func (fs *fsImpl) LookUpInode(
op *fuseops.LookUpInodeOp) {
var err error
defer fuseutil.RespondToOp(op, &err)
fs.mu.Lock()
defer fs.mu.Unlock()
// Find the inode, verifying that it has not been forgotten.
in := fs.inodes[op.Inode]
if in == nil {
panic(fmt.Sprintf("Unknown inode: %v", op.Inode))
// Make sure the parent exists and has not been forgotten.
_ = fs.findInodeByID(op.Parent)
// Handle the names we support.
var childID fuseops.InodeID
switch {
case op.Parent == cannedID_Root && op.Name == "foo":
childID = cannedID_Foo
case op.Parent == cannedID_Root && op.Name == "bar":
childID = cannedID_Bar
default:
err = fuse.ENOENT
return
}
if in.lookupCount <= 0 {
panic(fmt.Sprintf("Forgotten inode: %v", op.Inode))
// Find the child.
child := fs.findInodeByID(childID)
// Increment the child's lookup count.
child.lookupCount++
// Return an appropriate entry.
op.Entry = fuseops.ChildInodeEntry{
Child: childID,
Attributes: child.attributes,
}
return
}
func (fs *fsImpl) GetInodeAttributes(
op *fuseops.GetInodeAttributesOp) {
var err error
defer fuseutil.RespondToOp(op, &err)
fs.mu.Lock()
defer fs.mu.Unlock()
// Find the inode, verifying that it has not been forgotten.
in := fs.findInodeByID(op.Inode)
// Return appropriate attributes.
op.Attributes = in.attributes
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment