disk: use new alignment helper to align partitions

Align partitions during their re-layout. Specifically, we align the
first partition which removes the need for the hard coded magic
number of 2048, which represents the proper alignment for a grain
size of 1MB given a sector size of 512 (our setup).

NB: Since all our partitions should sizes that are themselves
aligned, i.e. evenly dividable by the default grain (1MB) this
will not actually change any manifest.
This commit is contained in:
Christian Kellner 2021-12-20 19:27:06 +01:00 committed by Tom Gundersen
parent 930633c249
commit 1dbd2bc364
2 changed files with 10 additions and 5 deletions

View file

@ -46,9 +46,8 @@ func CreatePartitionTable(
}
}
// start point for all of the arches is
// 2048 sectors.
table.updatePartitionStartPointOffsets(2048, imageSize)
// Calculate partition table offsets and sizes
table.updatePartitionStartPointOffsets(imageSize)
// Generate new UUIDs for filesystems and partitions
table.GenerateUUIDs(rng)

View file

@ -330,7 +330,12 @@ func (pt *PartitionTable) GenerateUUIDs(rng *rand.Rand) {
// value in `size` or to the sum of all partitions if that is lager.
// Will grow the root partition if there is any empty space.
// Returns the updated start point.
func (pt *PartitionTable) updatePartitionStartPointOffsets(start, size uint64) uint64 {
func (pt *PartitionTable) updatePartitionStartPointOffsets(size uint64) uint64 {
// initial alignment
start := pt.AlignUp(0)
size = pt.SectorsToBytes(pt.AlignUp(pt.BytesToSectors(size) - 1))
var rootIdx = -1
for i := range pt.Partitions {
partition := &pt.Partitions[i]
@ -339,6 +344,7 @@ func (pt *PartitionTable) updatePartitionStartPointOffsets(start, size uint64) u
continue
}
partition.Start = start
partition.Size = pt.AlignUp(partition.Size - 1)
start += partition.Size
}
@ -354,7 +360,7 @@ func (pt *PartitionTable) updatePartitionStartPointOffsets(start, size uint64) u
// If the sum of all partitions is bigger then the specified size,
// we use that instead. Grow the partition table size if needed.
end := root.Start + padding + root.Size
end := pt.AlignUp(root.Start + padding + root.Size - 1)
if endBytes := pt.SectorsToBytes(end); endBytes > size {
size = endBytes
}