Skip to content

Commit

Permalink
otk-gen-partition-table: add start_offset to allowed values
Browse files Browse the repository at this point in the history
This is needed for the `fedora-40-minimal_raw` image that sets
this to "8 MB".
  • Loading branch information
mvo5 authored and supakeen committed Sep 3, 2024
1 parent 3ee4b46 commit 4312c28
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
18 changes: 15 additions & 3 deletions cmd/otk-gen-partition-table/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type InputProperties struct {
Type otkdisk.PartType `json:"type"`
DefaultSize string `json:"default_size"`
UUID string `json:"uuid"`
StartOffset string `json:"start_offset"`
Create InputCreate `json:"create"`

SectorSize uint64 `json:"sector_size"`
Expand Down Expand Up @@ -110,14 +111,25 @@ func validateInput(input *Input) error {
}

func makePartitionTableFromOtkInput(input *Input) (*disk.PartitionTable, error) {
var err error

if err := validateInput(input); err != nil {
return nil, fmt.Errorf("cannot validate inputs: %w", err)
}

var startOffset uint64
if input.Properties.StartOffset != "" {
startOffset, err = common.DataSizeToUint64(input.Properties.StartOffset)
if err != nil {
return nil, err
}
}

pt := &disk.PartitionTable{
UUID: input.Properties.UUID,
Type: string(input.Properties.Type),
SectorSize: input.Properties.SectorSize,
UUID: input.Properties.UUID,
Type: string(input.Properties.Type),
SectorSize: input.Properties.SectorSize,
StartOffset: startOffset,
}
if input.Properties.Create.BIOSBootPartition {
if len(pt.Partitions) > 0 {
Expand Down
21 changes: 12 additions & 9 deletions cmd/otk-gen-partition-table/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ var partInputsComplete = `
},
"bios": true,
"type": "gpt",
"default_size": "10 GiB"
"default_size": "10 GiB",
"start_offset": "8 MB"
},
"partitions": [
{
Expand Down Expand Up @@ -63,6 +64,7 @@ var expectedInput = &genpart.Input{
},
Type: "gpt",
DefaultSize: "10 GiB",
StartOffset: "8 MB",
},
Partitions: []*genpart.InputPartition{
{
Expand Down Expand Up @@ -184,7 +186,8 @@ var partInputsSimple = `
"esp_partition_size": "2 GiB"
},
"type": "gpt",
"default_size": "10 GiB"
"default_size": "10 GiB",
"start_offset": "8 MB"
},
"partitions": [
{
Expand Down Expand Up @@ -218,12 +221,12 @@ var expectedSimplePartOutput = `{
},
"internal": {
"partition-table": {
"Size": 11814305792,
"Size": 11821645824,
"UUID": "dbd21911-1c4e-4107-8a9f-14fe6e751358",
"Type": "gpt",
"Partitions": [
{
"Start": 1048576,
"Start": 9048576,
"Size": 1048576,
"Type": "21686148-6449-6E6F-744E-656564454649",
"Bootable": true,
Expand All @@ -232,7 +235,7 @@ var expectedSimplePartOutput = `{
"PayloadType": "no-payload"
},
{
"Start": 2097152,
"Start": 10097152,
"Size": 2147483648,
"Type": "C12A7328-F81F-11D2-BA4B-00A0C93EC93B",
"Bootable": false,
Expand All @@ -249,8 +252,8 @@ var expectedSimplePartOutput = `{
"PayloadType": "filesystem"
},
{
"Start": 4297064448,
"Size": 7517224448,
"Start": 4305064448,
"Size": 7516564480,
"Type": "",
"Bootable": false,
"UUID": "ed130be6-c822-49af-83bb-4ea648bb2264",
Expand All @@ -266,7 +269,7 @@ var expectedSimplePartOutput = `{
"PayloadType": "filesystem"
},
{
"Start": 2149580800,
"Start": 2157580800,
"Size": 2147483648,
"Type": "",
"Bootable": false,
Expand All @@ -285,7 +288,7 @@ var expectedSimplePartOutput = `{
],
"SectorSize": 0,
"ExtraPadding": 0,
"StartOffset": 0
"StartOffset": 8000000
}
},
"filename": "disk.img"
Expand Down

0 comments on commit 4312c28

Please sign in to comment.