disk: new PartitionTable method ForEachMountable()
Calls a given function on each Mountable in a PartitionTable. Co-Authored-By: Christian Kellner <christian@kellner.me>
This commit is contained in:
parent
46a0ad77f9
commit
05a2f97549
1 changed files with 26 additions and 0 deletions
|
|
@ -401,3 +401,29 @@ func (pt *PartitionTable) updatePartitionStartPointOffsets(size uint64) uint64 {
|
|||
|
||||
return start
|
||||
}
|
||||
|
||||
type MountableCallback func(mnt Mountable, path []Entity) error
|
||||
|
||||
func forEachMountable(c Container, path []Entity, cb MountableCallback) error {
|
||||
for idx := uint(0); idx < c.GetItemCount(); idx++ {
|
||||
child := c.GetChild(idx)
|
||||
childPath := append(path, child)
|
||||
var err error
|
||||
switch ent := child.(type) {
|
||||
case Mountable:
|
||||
err = cb(ent, childPath)
|
||||
case Container:
|
||||
err = forEachMountable(ent, childPath, cb)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ForEachMountable runs the provided callback function on each Mountable in
|
||||
// the PartitionTable.
|
||||
func (pt *PartitionTable) ForEachMountable(cb MountableCallback) error {
|
||||
return forEachMountable(pt, []Entity{pt}, cb)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue