From 4312c28ef5bf3ab5ec2c001234fc71215118a88c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 3 Sep 2024 16:03:10 +0200 Subject: [PATCH] otk-gen-partition-table: add `start_offset` to allowed values This is needed for the `fedora-40-minimal_raw` image that sets this to "8 MB". --- cmd/otk-gen-partition-table/main.go | 18 +++++++++++++++--- cmd/otk-gen-partition-table/main_test.go | 21 ++++++++++++--------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/cmd/otk-gen-partition-table/main.go b/cmd/otk-gen-partition-table/main.go index 99f0d3c3b..553acd7e2 100644 --- a/cmd/otk-gen-partition-table/main.go +++ b/cmd/otk-gen-partition-table/main.go @@ -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"` @@ -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 { diff --git a/cmd/otk-gen-partition-table/main_test.go b/cmd/otk-gen-partition-table/main_test.go index 29de04908..d669981ef 100644 --- a/cmd/otk-gen-partition-table/main_test.go +++ b/cmd/otk-gen-partition-table/main_test.go @@ -26,7 +26,8 @@ var partInputsComplete = ` }, "bios": true, "type": "gpt", - "default_size": "10 GiB" + "default_size": "10 GiB", + "start_offset": "8 MB" }, "partitions": [ { @@ -63,6 +64,7 @@ var expectedInput = &genpart.Input{ }, Type: "gpt", DefaultSize: "10 GiB", + StartOffset: "8 MB", }, Partitions: []*genpart.InputPartition{ { @@ -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": [ { @@ -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, @@ -232,7 +235,7 @@ var expectedSimplePartOutput = `{ "PayloadType": "no-payload" }, { - "Start": 2097152, + "Start": 10097152, "Size": 2147483648, "Type": "C12A7328-F81F-11D2-BA4B-00A0C93EC93B", "Bootable": false, @@ -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", @@ -266,7 +269,7 @@ var expectedSimplePartOutput = `{ "PayloadType": "filesystem" }, { - "Start": 2149580800, + "Start": 2157580800, "Size": 2147483648, "Type": "", "Bootable": false, @@ -285,7 +288,7 @@ var expectedSimplePartOutput = `{ ], "SectorSize": 0, "ExtraPadding": 0, - "StartOffset": 0 + "StartOffset": 8000000 } }, "filename": "disk.img"