parted/0009-libparted-Fix-handling-of-gpt-partition-types.patch
Brian C. Lane 7fc0182f62 - libparted: Fix handling of msdos partition types
- tests: Add a libparted test for ped_partition_set_system on msdos
- parted: Add display of GPT UUIDs in JSON output
- Add no_automount flag support
- increase xfs size to 300M
2022-12-14 10:13:44 -08:00

102 lines
3.2 KiB
Diff

From 8957382b98fd79bc06dad132ef28a0be8b46ea16 Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl@redhat.com>
Date: Mon, 8 Aug 2022 12:04:32 -0700
Subject: [PATCH 09/13] 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.
---
libparted/labels/gpt.c | 45 ++++++++++++++++++++++++++++++++++++++++--
1 file 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;
}
--
2.37.3