disk: change updatePartitionStartPointOffsets() to use entityPath()

Eventually partition.Payload will be an Entity, so we need to use
more generic functions that work on the interfaces.

Co-Authored-By: Christian Kellner <christian@kellner.me>
This commit is contained in:
Achilleas Koutsou 2022-02-09 12:28:35 +01:00 committed by Tom Gundersen
parent 491020f9b8
commit adfed6e0d7

View file

@ -313,9 +313,7 @@ func (pt *PartitionTable) ForEachEntity(cb EntityCallback) error {
// Will grow the root partition if there is any empty space.
// Returns the updated start point.
func (pt *PartitionTable) updatePartitionStartPointOffsets(size uint64) uint64 {
// always reserve one extra sector for the GPT header
header := pt.SectorsToBytes(1)
footer := uint64(0)
@ -324,7 +322,7 @@ func (pt *PartitionTable) updatePartitionStartPointOffsets(size uint64) uint64 {
// calculate the space we need for
parts := len(pt.Partitions)
// reserver a minimum of 128 partition entires
// reserve a minimum of 128 partition entires
if parts < 128 {
parts = 128
}
@ -338,10 +336,10 @@ func (pt *PartitionTable) updatePartitionStartPointOffsets(size uint64) uint64 {
size = pt.AlignUp(size)
var rootIdx = -1
for i := range pt.Partitions {
partition := &pt.Partitions[i]
if partition.Payload != nil && partition.Payload.Mountpoint == "/" {
rootIdx = i
for idx := range pt.Partitions {
partition := &pt.Partitions[idx]
if len(entityPath(partition, "/")) != 0 {
rootIdx = idx
continue
}
partition.Start = start
@ -349,6 +347,10 @@ func (pt *PartitionTable) updatePartitionStartPointOffsets(size uint64) uint64 {
start += partition.Size
}
if rootIdx < 0 {
panic("no root filesystem found; this is a programming error")
}
root := &pt.Partitions[rootIdx]
root.Start = start