disk: move Partition and methods to separate file

Split up disk.go into smaller more manageable pieces: finish
by moving `Partition` to its own file.

Co-Authored-By: Christian Kellner <christian@kellner.me>
This commit is contained in:
Achilleas Koutsou 2022-02-07 19:08:14 +01:00 committed by Tom Gundersen
parent 53795c3dad
commit 22b8b671a8
2 changed files with 42 additions and 40 deletions

View file

@ -9,7 +9,6 @@ import (
"io"
"github.com/google/uuid"
osbuild "github.com/osbuild/osbuild-composer/internal/osbuild1"
)
const (
@ -34,45 +33,6 @@ type FSTabOptions struct {
PassNo uint64
}
type Partition struct {
Start uint64 // Start of the partition in bytes
Size uint64 // Size of the partition in bytes
Type string // Partition type, e.g. 0x83 for MBR or a UUID for gpt
Bootable bool // `Legacy BIOS bootable` (GPT) or `active` (DOS) flag
// ID of the partition, dos doesn't use traditional UUIDs, therefore this
// is just a string.
UUID string
// If nil, the partition is raw; It doesn't contain a filesystem.
Filesystem *Filesystem
}
// 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
if p.Filesystem != nil {
f := p.Filesystem.QEMUFilesystem()
fs = &f
}
return osbuild.QEMUPartition{
Start: p.Start,
Size: p.Size,
Type: p.Type,
Bootable: p.Bootable,
UUID: p.UUID,
Filesystem: fs,
}
}
// uuid generator helpers
// GeneratesnewRandomUUIDFromReader generates a new random UUID (version

View file

@ -0,0 +1,42 @@
package disk
import osbuild "github.com/osbuild/osbuild-composer/internal/osbuild1"
type Partition struct {
Start uint64 // Start of the partition in bytes
Size uint64 // Size of the partition in bytes
Type string // Partition type, e.g. 0x83 for MBR or a UUID for gpt
Bootable bool // `Legacy BIOS bootable` (GPT) or `active` (DOS) flag
// ID of the partition, dos doesn't use traditional UUIDs, therefore this
// is just a string.
UUID string
// If nil, the partition is raw; It doesn't contain a filesystem.
Filesystem *Filesystem
}
// 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
if p.Filesystem != nil {
f := p.Filesystem.QEMUFilesystem()
fs = &f
}
return osbuild.QEMUPartition{
Start: p.Start,
Size: p.Size,
Type: p.Type,
Bootable: p.Bootable,
UUID: p.UUID,
Filesystem: fs,
}
}