Skip to content

Commit

Permalink
disk: add a fitTo() method to Partition that uses minSize()
Browse files Browse the repository at this point in the history
Add a new Partition method, fitTo(), which resizes a partition to either
fit the given size or the sum of its contents + metadata.  The content
sum and metadata is calculated using the new minSize() method for
VolumeContainers.
  • Loading branch information
achilleas-k authored and supakeen committed Jul 25, 2024
1 parent e392bf7 commit 344fc96
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/disk/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ func (p *Partition) GetChild(n uint) Entity {
return p.Payload
}

// fitTo resizes a partition to be either the given the size or the size of its
// payload if that is larger. The payload can be larger if it is a container
// with sized children.
func (p *Partition) fitTo(size uint64) {
payload, isVC := p.Payload.(VolumeContainer)
if isVC {
if payloadMinSize := payload.minSize(size); payloadMinSize > size {
size = payloadMinSize
}
}
p.Size = size
}

func (p *Partition) GetSize() uint64 {
return p.Size
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/disk/partition_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ func (pt *PartitionTable) relayout(size uint64) uint64 {
continue
}
partition.Start = start
partition.fitTo(partition.Size)
partition.Size = pt.AlignUp(partition.Size)
start += partition.Size
}
Expand All @@ -433,6 +434,7 @@ func (pt *PartitionTable) relayout(size uint64) uint64 {

root := &pt.Partitions[rootIdx]
root.Start = start
root.fitTo(root.Size)

// add the extra padding specified in the partition table
footer += pt.ExtraPadding
Expand Down

0 comments on commit 344fc96

Please sign in to comment.