summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian C. Lane <bcl@redhat.com>2022-08-08 12:04:32 -0700
committerBrian C. Lane <bcl@redhat.com>2022-08-15 11:35:51 -0700
commit8957382b98fd79bc06dad132ef28a0be8b46ea16 (patch)
treef87651c40ca63a46ee05b8f00399ccbdbc30bfbd
parentaa690ee275db86d1edb2468bcf31c3d7cf81228e (diff)
downloadparted-8957382b98fd79bc06dad132ef28a0be8b46ea16.tar.gz
libparted: Fix handling of gpt partition types
This restores the previous behavior by testing the GUID against the list of known types and skipping the filesystem GUID reset. Now the sequence of: ped_partition_new(...) ped_partition_set_flag(part, PED_PARTITION_BIOS_GRUB, 1); ped_partition_set_system(part, ped_file_system_type_get("ext4")); Will keep the GUID set to PED_PARTITION_BIOS_GRUB, which is how it used to behave.
-rw-r--r--libparted/labels/gpt.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 0e9e060..8e6a37d 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -196,6 +196,24 @@ static const struct flag_uuid_mapping_t flag_uuid_mapping[] =
{ PED_PARTITION_SWAP, PARTITION_SWAP_GUID },
};
+static const efi_guid_t skip_set_system_guids[] =
+{
+ PARTITION_LVM_GUID,
+ PARTITION_SWAP_GUID,
+ PARTITION_RAID_GUID,
+ PARTITION_PREP_GUID,
+ PARTITION_SYSTEM_GUID,
+ PARTITION_BIOS_GRUB_GUID,
+ PARTITION_HPSERVICE_GUID,
+ PARTITION_MSFT_RESERVED_GUID,
+ PARTITION_BASIC_DATA_GUID,
+ PARTITION_MSFT_RECOVERY,
+ PARTITION_APPLE_TV_RECOVERY_GUID,
+ PARTITION_IRST_GUID,
+ PARTITION_CHROMEOS_KERNEL_GUID,
+ PARTITION_BLS_BOOT_GUID,
+};
+
static const struct flag_uuid_mapping_t* _GL_ATTRIBUTE_CONST
gpt_find_flag_uuid_mapping (PedPartitionFlag flag)
{
@@ -1421,6 +1439,21 @@ gpt_partition_destroy (PedPartition *part)
_ped_partition_free (part);
}
+/* is_skip_guid checks the guid against the list of guids that should not be
+ * overridden by set_system. It returns a 1 if it is in the list.
+*/
+static bool
+is_skip_guid(efi_guid_t guid) {
+ int n = sizeof(skip_set_system_guids) / sizeof(skip_set_system_guids[0]);
+ for (int i = 0; i < n; ++i) {
+ if (guid_cmp(guid, skip_set_system_guids[i]) == 0) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
static int
gpt_partition_set_system (PedPartition *part,
const PedFileSystemType *fs_type)
@@ -1431,6 +1464,11 @@ gpt_partition_set_system (PedPartition *part,
part->fs_type = fs_type;
+ // Is this a GUID that should skip fs_type checking?
+ if (is_skip_guid(gpt_part_data->type)) {
+ return 1;
+ }
+
if (fs_type)
{
if (strncmp (fs_type->name, "fat", 3) == 0
@@ -1563,10 +1601,13 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
const struct flag_uuid_mapping_t* p = gpt_find_flag_uuid_mapping (flag);
if (p)
{
- if (state)
+ if (state) {
gpt_part_data->type = p->type_uuid;
- else if (guid_cmp (gpt_part_data->type, p->type_uuid) == 0)
+ } else if (guid_cmp (gpt_part_data->type, p->type_uuid) == 0) {
+ // Clear the GUID so that fs_type will be used to return it to the default
+ gpt_part_data->type = PARTITION_LINUX_DATA_GUID;
return gpt_partition_set_system (part, part->fs_type);
+ }
return 1;
}