Refactored inode.LookUpChild.
parent
57cb4ccda3
commit
621df57d80
|
@ -116,6 +116,26 @@ func (inode *inode) checkInvariants() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the index of the child within inode.entries, if it exists.
|
||||||
|
//
|
||||||
|
// REQUIRES: inode.dir
|
||||||
|
// SHARED_LOCKS_REQUIRED(inode.mu)
|
||||||
|
func (inode *inode) findChild(name string) (i int, ok bool) {
|
||||||
|
if !inode.dir {
|
||||||
|
panic("findChild called on non-directory.")
|
||||||
|
}
|
||||||
|
|
||||||
|
var e fuseutil.Dirent
|
||||||
|
for i, e = range inode.entries {
|
||||||
|
if e.Name == name {
|
||||||
|
ok = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Public methods
|
// Public methods
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -125,16 +145,9 @@ func (inode *inode) checkInvariants() {
|
||||||
// REQUIRES: inode.dir
|
// REQUIRES: inode.dir
|
||||||
// SHARED_LOCKS_REQUIRED(inode.mu)
|
// SHARED_LOCKS_REQUIRED(inode.mu)
|
||||||
func (inode *inode) LookUpChild(name string) (id fuse.InodeID, ok bool) {
|
func (inode *inode) LookUpChild(name string) (id fuse.InodeID, ok bool) {
|
||||||
if !inode.dir {
|
index, ok := inode.findChild(name)
|
||||||
panic("LookUpChild called on non-directory.")
|
if ok {
|
||||||
}
|
id = inode.entries[index].Inode
|
||||||
|
|
||||||
for _, e := range inode.entries {
|
|
||||||
if e.Name == name {
|
|
||||||
id = e.Inode
|
|
||||||
ok = true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -167,7 +180,7 @@ func (inode *inode) RemoveChild(name string)
|
||||||
|
|
||||||
// Serve a ReadDir request.
|
// Serve a ReadDir request.
|
||||||
//
|
//
|
||||||
// REQUIRED: inode.dir
|
// REQUIRES: inode.dir
|
||||||
// SHARED_LOCKS_REQUIRED(inode.mu)
|
// SHARED_LOCKS_REQUIRED(inode.mu)
|
||||||
func (inode *inode) ReadDir(offset int, size int) (data []byte, err error) {
|
func (inode *inode) ReadDir(offset int, size int) (data []byte, err error) {
|
||||||
if !inode.dir {
|
if !inode.dir {
|
||||||
|
|
Loading…
Reference in New Issue