Add vfs.Dentry.Children().

PiperOrigin-RevId: 286660774
This commit is contained in:
Jamie Liu
2019-12-20 16:44:54 -08:00
committed by gVisor bot
parent 08c39e2587
commit 21a14e9532
+15 -3
View File
@@ -85,12 +85,12 @@ type Dentry struct {
// mounts is accessed using atomic memory operations.
mounts uint32
// mu synchronizes disowning and mounting over this Dentry.
mu sync.Mutex
// children are child Dentries.
children map[string]*Dentry
// mu synchronizes disowning and mounting over this Dentry.
mu sync.Mutex
// impl is the DentryImpl associated with this Dentry. impl is immutable.
// This should be the last field in Dentry.
impl DentryImpl
@@ -199,6 +199,18 @@ func (d *Dentry) HasChildren() bool {
return len(d.children) != 0
}
// Children returns a map containing all of d's children.
func (d *Dentry) Children() map[string]*Dentry {
if !d.HasChildren() {
return nil
}
m := make(map[string]*Dentry)
for name, child := range d.children {
m[name] = child
}
return m
}
// InsertChild makes child a child of d with the given name.
//
// InsertChild is a mutator of d and child.