From 0b5140a3400e41b91c5279ab9432cff86bcb2a86 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Mon, 19 Apr 2010 13:45:45 +0200 Subject: [PATCH parted 1/2] dos: Add a partition flag for diagnostics / recovery partitions msdos partition tables can contain diagnostics partitions (often used now a days as system recovery partitions). For some users of libparted (ie anaconda) it is usefull to know if a dos partition is a regular partition or a diagnostic partition (see rh bug 534066). * include/parted/disk.h(_PedPartitionFlag): Add PED_PARTITION_DIAG * libparted/disk.c(ped_partition_flag_get_name): Add PED_PARTITION_DIAG * libparted/labels/dos.c: Add support for PED_PARTITION_DIAG flag --- include/parted/disk.h | 5 +++-- libparted/disk.c | 2 ++ libparted/labels/dos.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/include/parted/disk.h b/include/parted/disk.h index dea4d19..f11e393 100644 --- a/include/parted/disk.h +++ b/include/parted/disk.h @@ -68,10 +68,11 @@ enum _PedPartitionFlag { PED_PARTITION_PREP=10, PED_PARTITION_MSFT_RESERVED=11, PED_PARTITION_BIOS_GRUB=12, - PED_PARTITION_APPLE_TV_RECOVERY=13 + PED_PARTITION_APPLE_TV_RECOVERY=13, + PED_PARTITION_DIAG=14 }; #define PED_PARTITION_FIRST_FLAG PED_PARTITION_BOOT -#define PED_PARTITION_LAST_FLAG PED_PARTITION_APPLE_TV_RECOVERY +#define PED_PARTITION_LAST_FLAG PED_PARTITION_DIAG enum _PedDiskTypeFeature { PED_DISK_TYPE_EXTENDED=1, /**< supports extended partitions */ diff --git a/libparted/disk.c b/libparted/disk.c index f4c0d74..7a60a09 100644 --- a/libparted/disk.c +++ b/libparted/disk.c @@ -2441,6 +2441,8 @@ ped_partition_flag_get_name (PedPartitionFlag flag) return N_("msftres"); case PED_PARTITION_APPLE_TV_RECOVERY: return N_("atvrecv"); + case PED_PARTITION_DIAG: + return N_("diag"); default: ped_exception_throw ( diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c index 6fb4aef..17209da 100644 --- a/libparted/labels/dos.c +++ b/libparted/labels/dos.c @@ -157,6 +157,7 @@ typedef struct { int lba; int palo; int prep; + int diag; OrigState* orig; /* used for CHS stuff */ } DosPartitionData; @@ -835,6 +836,8 @@ raw_part_parse (const PedDisk* disk, const DosRawPartition* raw_part, dos_data->lba = raw_part_is_lba (raw_part); dos_data->palo = raw_part->type == PARTITION_PALO; dos_data->prep = raw_part->type == PARTITION_PREP; + dos_data->diag = raw_part->type == PARTITION_COMPAQ_DIAG || + raw_part->type == PARTITION_DELL_DIAG; dos_data->orig = ped_malloc (sizeof (OrigState)); if (!dos_data->orig) { ped_partition_destroy (part); @@ -1236,6 +1239,7 @@ msdos_partition_new (const PedDisk* disk, PedPartitionType part_type, dos_data->lba = 0; dos_data->palo = 0; dos_data->prep = 0; + dos_data->diag = 0; } else { part->disk_specific = NULL; } @@ -1270,6 +1274,7 @@ msdos_partition_duplicate (const PedPartition* part) new_dos_data->lba = old_dos_data->lba; new_dos_data->palo = old_dos_data->palo; new_dos_data->prep = old_dos_data->prep; + new_dos_data->diag = old_dos_data->diag; if (old_dos_data->orig) { new_dos_data->orig = ped_malloc (sizeof (OrigState)); @@ -1317,6 +1322,7 @@ msdos_partition_set_system (PedPartition* part, dos_data->lvm = 0; dos_data->palo = 0; dos_data->prep = 0; + dos_data->diag = 0; if (dos_data->lba) dos_data->system = PARTITION_EXT_LBA; else @@ -1340,6 +1346,14 @@ msdos_partition_set_system (PedPartition* part, dos_data->system = PARTITION_PREP; return 1; } + if (dos_data->diag) { + /* Don't change the system if it already is a diag type, + otherwise use Compaq as almost all vendors use that. */ + if (dos_data->system != PARTITION_COMPAQ_DIAG && + dos_data->system != PARTITION_DELL_DIAG) + dos_data->system = PARTITION_COMPAQ_DIAG; + return 1; + } if (!fs_type) dos_data->system = PARTITION_LINUX; @@ -1415,6 +1429,7 @@ msdos_partition_set_flag (PedPartition* part, dos_data->lvm = 0; dos_data->palo = 0; dos_data->prep = 0; + dos_data->diag = 0; } dos_data->raid = state; return ped_partition_set_system (part, part->fs_type); @@ -1425,6 +1440,7 @@ msdos_partition_set_flag (PedPartition* part, dos_data->raid = 0; dos_data->palo = 0; dos_data->prep = 0; + dos_data->diag = 0; } dos_data->lvm = state; return ped_partition_set_system (part, part->fs_type); @@ -1438,6 +1454,7 @@ msdos_partition_set_flag (PedPartition* part, dos_data->hidden = 0; dos_data->raid = 0; dos_data->lvm = 0; + dos_data->diag = 0; } dos_data->palo = state; return ped_partition_set_system (part, part->fs_type); @@ -1447,10 +1464,22 @@ msdos_partition_set_flag (PedPartition* part, dos_data->hidden = 0; dos_data->raid = 0; dos_data->lvm = 0; + dos_data->diag = 0; } dos_data->prep = state; return ped_partition_set_system (part, part->fs_type); + case PED_PARTITION_DIAG: + if (state) { + dos_data->hidden = 0; + dos_data->raid = 0; + dos_data->lvm = 0; + dos_data->palo = 0; + dos_data->prep = 0; + } + dos_data->diag = state; + return ped_partition_set_system (part, part->fs_type); + default: return 0; } @@ -1490,6 +1519,9 @@ msdos_partition_get_flag (const PedPartition* part, PedPartitionFlag flag) case PED_PARTITION_PREP: return dos_data->prep; + case PED_PARTITION_DIAG: + return dos_data->diag; + default: return 0; } @@ -1512,6 +1544,7 @@ msdos_partition_is_flag_available (const PedPartition* part, case PED_PARTITION_LBA: case PED_PARTITION_PALO: case PED_PARTITION_PREP: + case PED_PARTITION_DIAG: return 1; default: -- 1.7.0.1 From f6def89ad61f2c13d344763137e551adf6a23526 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Mon, 19 Apr 2010 13:51:27 +0200 Subject: [PATCH parted 2/2] dos: Fix prep / palo flag handling Setting the prep flag was not clearing the palo flag and vica versa * libparted/labels/dos.c(msdos_partition_set_flag): Fix prep / palo flag handling. --- libparted/labels/dos.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c index 17209da..c0190a1 100644 --- a/libparted/labels/dos.c +++ b/libparted/labels/dos.c @@ -1454,6 +1454,7 @@ msdos_partition_set_flag (PedPartition* part, dos_data->hidden = 0; dos_data->raid = 0; dos_data->lvm = 0; + dos_data->prep = 0; dos_data->diag = 0; } dos_data->palo = state; @@ -1464,6 +1465,7 @@ msdos_partition_set_flag (PedPartition* part, dos_data->hidden = 0; dos_data->raid = 0; dos_data->lvm = 0; + dos_data->palo = 0; dos_data->diag = 0; } dos_data->prep = state; -- 1.7.0.1