disk: implement Sizeable interface for PartitionTable and Partition
In our model a partition table has a size to represent the disk size. Also each individual partition has a size, so they both implement the Sizeable interface. Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
This commit is contained in:
parent
0e1c769598
commit
4c34b5e2a8
2 changed files with 26 additions and 10 deletions
|
|
@ -22,16 +22,6 @@ func (p *Partition) IsContainer() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// Ensure the partition has at least the given size. Will do nothing
|
||||
// if the partition is already larger. Returns if the size changed.
|
||||
func (p *Partition) EnsureSize(s uint64) bool {
|
||||
if s > p.Size {
|
||||
p.Size = s
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Converts Partition to osbuild.QEMUPartition that encodes the same partition.
|
||||
func (p *Partition) QEMUPartition() osbuild.QEMUPartition {
|
||||
var fs *osbuild.QEMUFilesystem
|
||||
|
|
@ -62,3 +52,17 @@ func (p *Partition) GetChild(n uint) Entity {
|
|||
}
|
||||
return p.Filesystem
|
||||
}
|
||||
|
||||
func (p *Partition) GetSize() uint64 {
|
||||
return p.Size
|
||||
}
|
||||
|
||||
// Ensure the partition has at least the given size. Will do nothing
|
||||
// if the partition is already larger. Returns if the size changed.
|
||||
func (p *Partition) EnsureSize(s uint64) bool {
|
||||
if s > p.Size {
|
||||
p.Size = s
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -313,6 +313,18 @@ func (pt *PartitionTable) GetChild(n uint) Entity {
|
|||
return &pt.Partitions[n]
|
||||
}
|
||||
|
||||
func (pt *PartitionTable) GetSize() uint64 {
|
||||
return pt.Size
|
||||
}
|
||||
|
||||
func (pt *PartitionTable) EnsureSize(s uint64) bool {
|
||||
if s > pt.Size {
|
||||
pt.Size = s
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Dynamically calculate and update the start point for each of the existing
|
||||
// partitions. Adjusts the overall size of image to either the supplied
|
||||
// value in `size` or to the sum of all partitions if that is lager.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue