Blame SOURCES/0006-libparted-Fix-handling-of-gpt-partition-types.patch

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