Blame SOURCES/0003-libparted-add-swap-flag-for-DASD-label.patch

ceb987
From 29ffc6a1f285f48ac0b9efa7299373e486c486e8 Mon Sep 17 00:00:00 2001
ceb987
From: Arvin Schnell <aschnell@suse.com>
ceb987
Date: Fri, 8 Oct 2021 10:06:24 +0000
ceb987
Subject: [PATCH 3/5] libparted: add swap flag for DASD label
ceb987
ceb987
Support the swap flag and fix reading flags from disk. Also
ceb987
cleanup code by dropping the 2 flags "raid" and "lvm" from
ceb987
DasdPartitionData and instead use "system" directly.
ceb987
ceb987
Signed-off-by: Brian C. Lane <bcl@redhat.com>
ceb987
---
ceb987
 include/parted/fdasd.in.h |   2 -
ceb987
 libparted/labels/dasd.c   | 118 ++++++++++++++++----------------------
ceb987
 2 files changed, 50 insertions(+), 70 deletions(-)
ceb987
ceb987
diff --git a/include/parted/fdasd.in.h b/include/parted/fdasd.in.h
ceb987
index 9e5d7d1..e3ba183 100644
ceb987
--- a/include/parted/fdasd.in.h
ceb987
+++ b/include/parted/fdasd.in.h
ceb987
@@ -28,10 +28,8 @@
ceb987
 
ceb987
 #define PARTITION_LINUX_SWAP    0x82
ceb987
 #define PARTITION_LINUX         0x83
ceb987
-#define PARTITION_LINUX_EXT     0x85
ceb987
 #define PARTITION_LINUX_LVM     0x8e
ceb987
 #define PARTITION_LINUX_RAID    0xfd
ceb987
-#define PARTITION_LINUX_LVM_OLD 0xfe
ceb987
 
ceb987
 #define PART_TYPE_NATIVE "NATIVE"
ceb987
 #define PART_TYPE_SWAP   "SWAP  "
ceb987
diff --git a/libparted/labels/dasd.c b/libparted/labels/dasd.c
ceb987
index 0c00c4f..27baad0 100644
ceb987
--- a/libparted/labels/dasd.c
ceb987
+++ b/libparted/labels/dasd.c
ceb987
@@ -53,10 +53,8 @@
ceb987
 
ceb987
 #define PARTITION_LINUX_SWAP 0x82
ceb987
 #define PARTITION_LINUX 0x83
ceb987
-#define PARTITION_LINUX_EXT 0x85
ceb987
 #define PARTITION_LINUX_LVM 0x8e
ceb987
 #define PARTITION_LINUX_RAID 0xfd
ceb987
-#define PARTITION_LINUX_LVM_OLD 0xfe
ceb987
 
ceb987
 extern void ped_disk_dasd_init ();
ceb987
 extern void ped_disk_dasd_done ();
ceb987
@@ -66,8 +64,6 @@ extern void ped_disk_dasd_done ();
ceb987
 typedef struct {
ceb987
 	int type;
ceb987
 	int system;
ceb987
-	int	raid;
ceb987
-	int	lvm;
ceb987
 } DasdPartitionData;
ceb987
 
ceb987
 typedef struct {
ceb987
@@ -134,6 +130,31 @@ static PedDiskType dasd_disk_type = {
ceb987
 	features: 0
ceb987
 };
ceb987
 
ceb987
+struct flag_id_mapping_t
ceb987
+{
ceb987
+	enum _PedPartitionFlag flag;
ceb987
+	int type_id;
ceb987
+};
ceb987
+
ceb987
+static const struct flag_id_mapping_t flag_id_mapping[] =
ceb987
+{
ceb987
+	{ PED_PARTITION_LVM,	PARTITION_LINUX_LVM },
ceb987
+	{ PED_PARTITION_RAID,	PARTITION_LINUX_RAID },
ceb987
+	{ PED_PARTITION_SWAP,	PARTITION_LINUX_SWAP },
ceb987
+};
ceb987
+
ceb987
+static const struct flag_id_mapping_t* _GL_ATTRIBUTE_CONST
ceb987
+dasd_find_flag_id_mapping (PedPartitionFlag flag)
ceb987
+{
ceb987
+	int n = sizeof(flag_id_mapping) / sizeof(flag_id_mapping[0]);
ceb987
+
ceb987
+	for (int i = 0; i < n; ++i)
ceb987
+		if (flag_id_mapping[i].flag == flag)
ceb987
+			return &flag_id_mapping[i];
ceb987
+
ceb987
+	return NULL;
ceb987
+}
ceb987
+
ceb987
 static PedDisk*
ceb987
 dasd_alloc (const PedDevice* dev)
ceb987
 {
ceb987
@@ -310,8 +331,6 @@ dasd_read (PedDisk* disk)
ceb987
 		part->num = 1;
ceb987
 		part->fs_type = ped_file_system_probe (&part->geom);
ceb987
 		dasd_data = part->disk_specific;
ceb987
-		dasd_data->raid = 0;
ceb987
-		dasd_data->lvm = 0;
ceb987
 		dasd_data->type = 0;
ceb987
 
ceb987
 		if (!ped_disk_add_partition (disk, part, NULL))
ceb987
@@ -394,8 +413,6 @@ dasd_read (PedDisk* disk)
ceb987
 		part->num = 1;
ceb987
 		part->fs_type = ped_file_system_probe (&part->geom);
ceb987
 		dasd_data = part->disk_specific;
ceb987
-		dasd_data->raid = 0;
ceb987
-		dasd_data->lvm = 0;
ceb987
 		dasd_data->type = 0;
ceb987
 
ceb987
 		if (!ped_disk_add_partition (disk, part, NULL))
ceb987
@@ -452,25 +469,12 @@ dasd_read (PedDisk* disk)
ceb987
 
ceb987
 		dasd_data = part->disk_specific;
ceb987
 
ceb987
-		if ((strncmp(PART_TYPE_RAID, str, 6) == 0) &&
ceb987
-		    (ped_file_system_probe(&part->geom) == NULL))
ceb987
-			ped_partition_set_flag(part, PED_PARTITION_RAID, 1);
ceb987
-		else
ceb987
-			ped_partition_set_flag(part, PED_PARTITION_RAID, 0);
ceb987
-
ceb987
-		if ((strncmp(PART_TYPE_LVM, str, 6) == 0) &&
ceb987
-		    (ped_file_system_probe(&part->geom) == NULL))
ceb987
-			ped_partition_set_flag(part, PED_PARTITION_LVM, 1);
ceb987
-		else
ceb987
-			ped_partition_set_flag(part, PED_PARTITION_LVM, 0);
ceb987
-
ceb987
-		if (strncmp(PART_TYPE_SWAP, str, 6) == 0) {
ceb987
-			fs = ped_file_system_probe(&part->geom);
ceb987
-			if (fs && is_linux_swap(fs->name)) {
ceb987
-				dasd_data->system = PARTITION_LINUX_SWAP;
ceb987
-				PDEBUG;
ceb987
-			}
ceb987
-		}
ceb987
+		if (strncmp(PART_TYPE_RAID, str, 6) == 0)
ceb987
+			dasd_data->system = PARTITION_LINUX_RAID;
ceb987
+		else if (strncmp(PART_TYPE_LVM, str, 6) == 0)
ceb987
+			dasd_data->system = PARTITION_LINUX_LVM;
ceb987
+		else if (strncmp(PART_TYPE_SWAP, str, 6) == 0)
ceb987
+			dasd_data->system = PARTITION_LINUX_SWAP;
ceb987
 
ceb987
 		vtoc_ebcdic_enc(p->f1->DS1DSNAM, p->f1->DS1DSNAM, 44);
ceb987
 
ceb987
@@ -747,20 +751,17 @@ dasd_partition_set_flag (PedPartition* part, PedPartitionFlag flag, int state)
ceb987
 	PED_ASSERT(part->disk_specific != NULL);
ceb987
 	dasd_data = part->disk_specific;
ceb987
 
ceb987
-	switch (flag) {
ceb987
-		case PED_PARTITION_RAID:
ceb987
-			if (state)
ceb987
-				dasd_data->lvm = 0;
ceb987
-			dasd_data->raid = state;
ceb987
-			return ped_partition_set_system(part, part->fs_type);
ceb987
-		case PED_PARTITION_LVM:
ceb987
-			if (state)
ceb987
-				dasd_data->raid = 0;
ceb987
-			dasd_data->lvm = state;
ceb987
-			return ped_partition_set_system(part, part->fs_type);
ceb987
-		default:
ceb987
-			return 0;
ceb987
+	const struct flag_id_mapping_t* p = dasd_find_flag_id_mapping (flag);
ceb987
+	if (p)
ceb987
+	{
ceb987
+		if (state)
ceb987
+			dasd_data->system = p->type_id;
ceb987
+		else if (dasd_data->system == p->type_id)
ceb987
+			return dasd_partition_set_system (part, part->fs_type);
ceb987
+		return 1;
ceb987
 	}
ceb987
+
ceb987
+	return 0;
ceb987
 }
ceb987
 
ceb987
 static int
ceb987
@@ -772,14 +773,11 @@ dasd_partition_get_flag (const PedPartition* part, PedPartitionFlag flag)
ceb987
 	PED_ASSERT (part->disk_specific != NULL);
ceb987
 	dasd_data = part->disk_specific;
ceb987
 
ceb987
-	switch (flag) {
ceb987
-		case PED_PARTITION_RAID:
ceb987
-			return dasd_data->raid;
ceb987
-		case PED_PARTITION_LVM:
ceb987
-			return dasd_data->lvm;
ceb987
-		default:
ceb987
-			return 0;
ceb987
-	}
ceb987
+	const struct flag_id_mapping_t* p = dasd_find_flag_id_mapping (flag);
ceb987
+	if (p)
ceb987
+		return dasd_data->system == p->type_id;
ceb987
+
ceb987
+	return 0;
ceb987
 }
ceb987
 
ceb987
 /*
ceb987
@@ -800,14 +798,10 @@ dasd_partition_is_flag_available (const PedPartition* part,
ceb987
 	if (disk_specific->format_type == 1)
ceb987
 		return 0;
ceb987
 
ceb987
-	switch (flag) {
ceb987
-		case PED_PARTITION_RAID:
ceb987
-			return 1;
ceb987
-		case PED_PARTITION_LVM:
ceb987
-			return 1;
ceb987
-		default:
ceb987
-			return 0;
ceb987
-	}
ceb987
+	if (dasd_find_flag_id_mapping (flag))
ceb987
+		return 1;
ceb987
+
ceb987
+	return 0;
ceb987
 }
ceb987
 
ceb987
 
ceb987
@@ -938,18 +932,6 @@ dasd_partition_set_system (PedPartition* part,
ceb987
 
ceb987
 	part->fs_type = fs_type;
ceb987
 
ceb987
-	if (dasd_data->lvm) {
ceb987
-		dasd_data->system = PARTITION_LINUX_LVM;
ceb987
-        PDEBUG;
ceb987
-		return 1;
ceb987
-	}
ceb987
-
ceb987
-	if (dasd_data->raid) {
ceb987
-		dasd_data->system = PARTITION_LINUX_RAID;
ceb987
-        PDEBUG;
ceb987
-		return 1;
ceb987
-	}
ceb987
-
ceb987
 	if (!fs_type) {
ceb987
 		dasd_data->system = PARTITION_LINUX;
ceb987
         PDEBUG;
ceb987
-- 
ceb987
2.35.3
ceb987