Skip to content

Commit

Permalink
Refactor bootable check
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Mars <[email protected]>
  • Loading branch information
upils committed Jul 16, 2024
1 parent 1ddb7f8 commit 5b85d23
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions internal/statemachine/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,6 @@ func getStructureType(structure gadget.VolumeStructure, schema string) string {

// mbrPartitionFromStruct prepares a mbr.Partition object from a gadget.VolumeStructure
func mbrPartitionFromStruct(structure gadget.VolumeStructure, sectorSize uint64, structureType string) *mbr.Partition {
bootable := false
if structure.Role == gadget.SystemBoot || structure.Label == gadget.SystemBoot {
bootable = true
}
// mbr.Type is a byte. snapd has already verified that this string
// is exactly two chars, so we can safely parse those two chars to a byte
partitionType, _ := strconv.ParseUint(structureType, 16, 8) // nolint: errcheck
Expand All @@ -529,7 +525,7 @@ func mbrPartitionFromStruct(structure gadget.VolumeStructure, sectorSize uint64,
Start: uint32(math.Ceil(float64(*structure.Offset) / float64(sectorSize))),
Size: uint32(math.Ceil(float64(structure.Size) / float64(sectorSize))),
Type: mbr.Type(partitionType),
Bootable: bootable,
Bootable: isBootable(structure),
}
}

Expand All @@ -547,13 +543,18 @@ func gptPartitionFromStruct(structure gadget.VolumeStructure, sectorSize uint64,
Name: partitionName,
}

if structure.Role == gadget.SystemBoot || structure.Label == gadget.SystemBoot {
if isBootable(structure) {
partition.Attributes = gptBootableAttribute
}

return partition
}

// isBootable checks if the structure is bootable
func isBootable(structure gadget.VolumeStructure) bool {
return structure.Role == gadget.SystemBoot || structure.Label == gadget.SystemBoot
}

// copyDataToImage runs dd commands to copy the raw data to the final image with appropriate offsets
func (stateMachine *StateMachine) copyDataToImage(volumeName string, volume *gadget.Volume, diskImg *disk.Disk) error {
// Resolve gadget information to on disk volume
Expand Down

0 comments on commit 5b85d23

Please sign in to comment.