From adfed6e0d7c2d8b9c26b3ef97a5b9218b8fa6f84 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Wed, 9 Feb 2022 12:28:35 +0100 Subject: [PATCH] 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 --- internal/disk/partition_table.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/disk/partition_table.go b/internal/disk/partition_table.go index 55fe8882a..8b6a2b6d3 100644 --- a/internal/disk/partition_table.go +++ b/internal/disk/partition_table.go @@ -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