[parted-devel] [PATCH 1/1] add swap flag for DASD label
Arvin Schnell
aschnell at suse.com
Fri Oct 8 11:06:24 BST 2021
Support the swap flag and fix reading flags from disk. Also
cleanup code by dropping the 2 flags "raid" and "lvm" from
DasdPartitionData and instead use "system" directly.
---
include/parted/fdasd.in.h | 2 -
libparted/labels/dasd.c | 118 ++++++++++++++++----------------------
2 files changed, 50 insertions(+), 70 deletions(-)
diff --git a/include/parted/fdasd.in.h b/include/parted/fdasd.in.h
index 9e5d7d1..e3ba183 100644
--- a/include/parted/fdasd.in.h
+++ b/include/parted/fdasd.in.h
@@ -28,10 +28,8 @@
#define PARTITION_LINUX_SWAP 0x82
#define PARTITION_LINUX 0x83
-#define PARTITION_LINUX_EXT 0x85
#define PARTITION_LINUX_LVM 0x8e
#define PARTITION_LINUX_RAID 0xfd
-#define PARTITION_LINUX_LVM_OLD 0xfe
#define PART_TYPE_NATIVE "NATIVE"
#define PART_TYPE_SWAP "SWAP "
diff --git a/libparted/labels/dasd.c b/libparted/labels/dasd.c
index 6b0b10d..3ad5322 100644
--- a/libparted/labels/dasd.c
+++ b/libparted/labels/dasd.c
@@ -53,10 +53,8 @@
#define PARTITION_LINUX_SWAP 0x82
#define PARTITION_LINUX 0x83
-#define PARTITION_LINUX_EXT 0x85
#define PARTITION_LINUX_LVM 0x8e
#define PARTITION_LINUX_RAID 0xfd
-#define PARTITION_LINUX_LVM_OLD 0xfe
extern void ped_disk_dasd_init ();
extern void ped_disk_dasd_done ();
@@ -66,8 +64,6 @@ extern void ped_disk_dasd_done ();
typedef struct {
int type;
int system;
- int raid;
- int lvm;
} DasdPartitionData;
typedef struct {
@@ -130,6 +126,31 @@ static PedDiskType dasd_disk_type = {
features: 0
};
+struct flag_id_mapping_t
+{
+ enum _PedPartitionFlag flag;
+ int type_id;
+};
+
+static const struct flag_id_mapping_t flag_id_mapping[] =
+{
+ { PED_PARTITION_LVM, PARTITION_LINUX_LVM },
+ { PED_PARTITION_RAID, PARTITION_LINUX_RAID },
+ { PED_PARTITION_SWAP, PARTITION_LINUX_SWAP },
+};
+
+static const struct flag_id_mapping_t* _GL_ATTRIBUTE_CONST
+dasd_find_flag_id_mapping (PedPartitionFlag flag)
+{
+ int n = sizeof(flag_id_mapping) / sizeof(flag_id_mapping[0]);
+
+ for (int i = 0; i < n; ++i)
+ if (flag_id_mapping[i].flag == flag)
+ return &flag_id_mapping[i];
+
+ return NULL;
+}
+
static PedDisk*
dasd_alloc (const PedDevice* dev)
{
@@ -306,8 +327,6 @@ dasd_read (PedDisk* disk)
part->num = 1;
part->fs_type = ped_file_system_probe (&part->geom);
dasd_data = part->disk_specific;
- dasd_data->raid = 0;
- dasd_data->lvm = 0;
dasd_data->type = 0;
if (!ped_disk_add_partition (disk, part, NULL))
@@ -390,8 +409,6 @@ dasd_read (PedDisk* disk)
part->num = 1;
part->fs_type = ped_file_system_probe (&part->geom);
dasd_data = part->disk_specific;
- dasd_data->raid = 0;
- dasd_data->lvm = 0;
dasd_data->type = 0;
if (!ped_disk_add_partition (disk, part, NULL))
@@ -448,25 +465,12 @@ dasd_read (PedDisk* disk)
dasd_data = part->disk_specific;
- if ((strncmp(PART_TYPE_RAID, str, 6) == 0) &&
- (ped_file_system_probe(&part->geom) == NULL))
- ped_partition_set_flag(part, PED_PARTITION_RAID, 1);
- else
- ped_partition_set_flag(part, PED_PARTITION_RAID, 0);
-
- if ((strncmp(PART_TYPE_LVM, str, 6) == 0) &&
- (ped_file_system_probe(&part->geom) == NULL))
- ped_partition_set_flag(part, PED_PARTITION_LVM, 1);
- else
- ped_partition_set_flag(part, PED_PARTITION_LVM, 0);
-
- if (strncmp(PART_TYPE_SWAP, str, 6) == 0) {
- fs = ped_file_system_probe(&part->geom);
- if (fs && is_linux_swap(fs->name)) {
- dasd_data->system = PARTITION_LINUX_SWAP;
- PDEBUG;
- }
- }
+ if (strncmp(PART_TYPE_RAID, str, 6) == 0)
+ dasd_data->system = PARTITION_LINUX_RAID;
+ else if (strncmp(PART_TYPE_LVM, str, 6) == 0)
+ dasd_data->system = PARTITION_LINUX_LVM;
+ else if (strncmp(PART_TYPE_SWAP, str, 6) == 0)
+ dasd_data->system = PARTITION_LINUX_SWAP;
vtoc_ebcdic_enc(p->f1->DS1DSNAM, p->f1->DS1DSNAM, 44);
@@ -743,20 +747,17 @@ dasd_partition_set_flag (PedPartition* part, PedPartitionFlag flag, int state)
PED_ASSERT(part->disk_specific != NULL);
dasd_data = part->disk_specific;
- switch (flag) {
- case PED_PARTITION_RAID:
- if (state)
- dasd_data->lvm = 0;
- dasd_data->raid = state;
- return ped_partition_set_system(part, part->fs_type);
- case PED_PARTITION_LVM:
- if (state)
- dasd_data->raid = 0;
- dasd_data->lvm = state;
- return ped_partition_set_system(part, part->fs_type);
- default:
- return 0;
+ const struct flag_id_mapping_t* p = dasd_find_flag_id_mapping (flag);
+ if (p)
+ {
+ if (state)
+ dasd_data->system = p->type_id;
+ else if (dasd_data->system == p->type_id)
+ return dasd_partition_set_system (part, part->fs_type);
+ return 1;
}
+
+ return 0;
}
static int
@@ -768,14 +769,11 @@ dasd_partition_get_flag (const PedPartition* part, PedPartitionFlag flag)
PED_ASSERT (part->disk_specific != NULL);
dasd_data = part->disk_specific;
- switch (flag) {
- case PED_PARTITION_RAID:
- return dasd_data->raid;
- case PED_PARTITION_LVM:
- return dasd_data->lvm;
- default:
- return 0;
- }
+ const struct flag_id_mapping_t* p = dasd_find_flag_id_mapping (flag);
+ if (p)
+ return dasd_data->system == p->type_id;
+
+ return 0;
}
/*
@@ -796,14 +794,10 @@ dasd_partition_is_flag_available (const PedPartition* part,
if (disk_specific->format_type == 1)
return 0;
- switch (flag) {
- case PED_PARTITION_RAID:
- return 1;
- case PED_PARTITION_LVM:
- return 1;
- default:
- return 0;
- }
+ if (dasd_find_flag_id_mapping (flag))
+ return 1;
+
+ return 0;
}
@@ -934,18 +928,6 @@ dasd_partition_set_system (PedPartition* part,
part->fs_type = fs_type;
- if (dasd_data->lvm) {
- dasd_data->system = PARTITION_LINUX_LVM;
- PDEBUG;
- return 1;
- }
-
- if (dasd_data->raid) {
- dasd_data->system = PARTITION_LINUX_RAID;
- PDEBUG;
- return 1;
- }
-
if (!fs_type) {
dasd_data->system = PARTITION_LINUX;
PDEBUG;
--
2.26.2
More information about the parted-devel
mailing list