disk: new method for finding Mountable entities with a given mountpoint

This commit is contained in:
Achilleas Koutsou 2022-02-09 17:54:56 +01:00 committed by Tom Gundersen
parent 6fc993d03c
commit 3f38602896

View file

@ -428,3 +428,15 @@ func forEachMountable(c Container, path []Entity, cb MountableCallback) error {
func (pt *PartitionTable) ForEachMountable(cb MountableCallback) error {
return forEachMountable(pt, []Entity{pt}, cb)
}
// FindMountable returns the Mountable entity with the given mountpoint in the
// PartitionTable. Returns nil if no Entity has the target as a Mountpoint.
func (pt *PartitionTable) FindMountable(mountpoint string) Mountable {
path := entityPath(pt, mountpoint)
if len(path) == 0 {
return nil
}
// first path element is guaranteed to be Mountable
return path[0].(Mountable)
}