You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
3.2 KiB
110 lines
3.2 KiB
From d37d5e7a9470bb5bf8446f79f8e9c508366e06b6 Mon Sep 17 00:00:00 2001
|
|
From: "Brian C. Lane" <bcl@redhat.com>
|
|
Date: Mon, 8 Aug 2022 15:02:30 -0700
|
|
Subject: [PATCH 8/9] libparted: Fix handling of msdos partition types
|
|
|
|
This restores the previous behavior by testing the partition type
|
|
against the list of known types and skipping the filesystem type reset.
|
|
Now the sequence of:
|
|
|
|
ped_partition_new(...)
|
|
ped_partition_set_flag(part, PED_PARTITION_BLS_BOOT, 1);
|
|
ped_partition_set_system(part, ped_file_system_type_get("ext4"));
|
|
|
|
Will keep the type set to PED_PARTITION_BLS_BOOT, which is how it used
|
|
to behave.
|
|
---
|
|
libparted/labels/dos.c | 54 +++++++++++++++++++++++++++++++++++-------
|
|
1 file changed, 46 insertions(+), 8 deletions(-)
|
|
|
|
diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
|
|
index bd7465d..4359276 100644
|
|
--- a/libparted/labels/dos.c
|
|
+++ b/libparted/labels/dos.c
|
|
@@ -121,6 +121,22 @@ static const struct flag_id_mapping_t flag_id_mapping[] =
|
|
{ PED_PARTITION_SWAP, PARTITION_LINUX_SWAP },
|
|
};
|
|
|
|
+static const unsigned char skip_set_system_types[] =
|
|
+{
|
|
+ PARTITION_EXT_LBA,
|
|
+ PARTITION_DOS_EXT,
|
|
+ PARTITION_COMPAQ_DIAG,
|
|
+ PARTITION_MSFT_RECOVERY,
|
|
+ PARTITION_LINUX_LVM,
|
|
+ PARTITION_LINUX_SWAP,
|
|
+ PARTITION_LINUX_RAID,
|
|
+ PARTITION_PALO,
|
|
+ PARTITION_PREP,
|
|
+ PARTITION_IRST,
|
|
+ PARTITION_ESP,
|
|
+ PARTITION_BLS_BOOT
|
|
+};
|
|
+
|
|
static const struct flag_id_mapping_t* _GL_ATTRIBUTE_CONST
|
|
dos_find_flag_id_mapping (PedPartitionFlag flag)
|
|
{
|
|
@@ -1540,6 +1556,21 @@ msdos_partition_destroy (PedPartition* part)
|
|
free (part);
|
|
}
|
|
|
|
+/* is_skip_type checks the type against the list of types that should not be
|
|
+ * overridden by set_system. It returns a 1 if it is in the list.
|
|
+*/
|
|
+static bool
|
|
+is_skip_type(unsigned char type_id) {
|
|
+ int n = sizeof(skip_set_system_types) / sizeof(skip_set_system_types[0]);
|
|
+ for (int i = 0; i < n; ++i) {
|
|
+ if (type_id == skip_set_system_types[i]) {
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return false;
|
|
+}
|
|
+
|
|
static int
|
|
msdos_partition_set_system (PedPartition* part,
|
|
const PedFileSystemType* fs_type)
|
|
@@ -1548,6 +1579,11 @@ msdos_partition_set_system (PedPartition* part,
|
|
|
|
part->fs_type = fs_type;
|
|
|
|
+ // Is this a type that should skip fs_type checking?
|
|
+ if (is_skip_type(dos_data->system)) {
|
|
+ return 1;
|
|
+ }
|
|
+
|
|
if (part->type & PED_PARTITION_EXTENDED) {
|
|
dos_data->system = PARTITION_EXT_LBA;
|
|
return 1;
|
|
@@ -1590,15 +1626,17 @@ msdos_partition_set_flag (PedPartition* part,
|
|
const struct flag_id_mapping_t* p = dos_find_flag_id_mapping (flag);
|
|
if (p)
|
|
{
|
|
- if (part->type & PED_PARTITION_EXTENDED)
|
|
- return 0;
|
|
-
|
|
- if (state)
|
|
- dos_data->system = p->type_id;
|
|
- else if (dos_data->system == p->type_id || dos_data->system == p->alt_type_id)
|
|
- return ped_partition_set_system (part, part->fs_type);
|
|
+ if (part->type & PED_PARTITION_EXTENDED)
|
|
+ return 0;
|
|
|
|
- return 1;
|
|
+ if (state) {
|
|
+ dos_data->system = p->type_id;
|
|
+ } else if (dos_data->system == p->type_id || dos_data->system == p->alt_type_id) {
|
|
+ // Clear the type so that fs_type will be used to return it to the default
|
|
+ dos_data->system = PARTITION_LINUX;
|
|
+ return ped_partition_set_system (part, part->fs_type);
|
|
+ }
|
|
+ return 1;
|
|
}
|
|
|
|
switch (flag) {
|
|
--
|
|
2.37.1
|
|
|