Commit 621df57d authored by Aaron Jacobs's avatar Aaron Jacobs

Refactored inode.LookUpChild.

parent 57cb4ccd
......@@ -116,22 +116,18 @@ func (inode *inode) checkInvariants() {
}
}
////////////////////////////////////////////////////////////////////////
// Public methods
////////////////////////////////////////////////////////////////////////
// Find an entry for the given child name and return its inode ID.
// Return the index of the child within inode.entries, if it exists.
//
// REQUIRES: inode.dir
// SHARED_LOCKS_REQUIRED(inode.mu)
func (inode *inode) LookUpChild(name string) (id fuse.InodeID, ok bool) {
func (inode *inode) findChild(name string) (i int, ok bool) {
if !inode.dir {
panic("LookUpChild called on non-directory.")
panic("findChild called on non-directory.")
}
for _, e := range inode.entries {
var e fuseutil.Dirent
for i, e = range inode.entries {
if e.Name == name {
id = e.Inode
ok = true
return
}
......@@ -140,6 +136,23 @@ func (inode *inode) LookUpChild(name string) (id fuse.InodeID, ok bool) {
return
}
////////////////////////////////////////////////////////////////////////
// Public methods
////////////////////////////////////////////////////////////////////////
// Find an entry for the given child name and return its inode ID.
//
// REQUIRES: inode.dir
// SHARED_LOCKS_REQUIRED(inode.mu)
func (inode *inode) LookUpChild(name string) (id fuse.InodeID, ok bool) {
index, ok := inode.findChild(name)
if ok {
id = inode.entries[index].Inode
}
return
}
// Add an entry for a child.
//
// REQUIRES: inode.dir
......@@ -167,7 +180,7 @@ func (inode *inode) RemoveChild(name string)
// Serve a ReadDir request.
//
// REQUIRED: inode.dir
// REQUIRES: inode.dir
// SHARED_LOCKS_REQUIRED(inode.mu)
func (inode *inode) ReadDir(offset int, size int) (data []byte, err error) {
if !inode.dir {
......
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