disk: implement Container interface for PartitionTable and Partition

A `PartitionTable` is a container for one or more instances of
`Partition`, which itself might contain a `Filesystem`.

Co-Authored-By: Christian Kellner <christian@kellner.me>
This commit is contained in:
Achilleas Koutsou 2022-02-07 19:50:58 +01:00 committed by Tom Gundersen
parent 51a396e3f1
commit 0e1c769598
2 changed files with 27 additions and 1 deletions

View file

@ -1,6 +1,10 @@
package disk
import osbuild "github.com/osbuild/osbuild-composer/internal/osbuild1"
import (
"fmt"
osbuild "github.com/osbuild/osbuild-composer/internal/osbuild1"
)
type Partition struct {
Start uint64 // Start of the partition in bytes
@ -44,3 +48,17 @@ func (p *Partition) QEMUPartition() osbuild.QEMUPartition {
Filesystem: fs,
}
}
func (pt *Partition) GetItemCount() uint {
if pt.Filesystem == nil {
return 0
}
return 1
}
func (p *Partition) GetChild(n uint) Entity {
if n != 0 {
panic(fmt.Sprintf("invalid child index for Partition: %d != 0", n))
}
return p.Filesystem
}

View file

@ -305,6 +305,14 @@ func (pt *PartitionTable) GenerateUUIDs(rng *rand.Rand) {
}
}
func (pt *PartitionTable) GetItemCount() uint {
return uint(len(pt.Partitions))
}
func (pt *PartitionTable) GetChild(n uint) Entity {
return &pt.Partitions[n]
}
// 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.