>From 33ca05ab37579d32a6488d500776cbc89eb7883d Mon Sep 17 00:00:00 2001 From: Roderick W. Smith Date: Tue, 28 Jun 2011 13:16:50 -0400 Subject: [PATCH] Added support for new Linux-specific GPT partition type code * NEWS: Added description of new Linux-specific partition type code and of the new msftres flag that can be used to override this type code, should it be necessary. * doc/parted.texi: Added description of the new msftres flag. * include/parted/disk.h: Added new PED_PARTITION_MSFT_DATA item to the _PedPartitionFlag enum. * libparted/disk.c: Added check for PED_PARTITION_MSFT_DATA, with return of "msftdata", to ped_partition_flag_get_name() * libparted/labels/gpt.c: Created #define for PARTITION_LINUX_DATA_GUID; added "int msftdata" to _GPTPartitionData struct; modified _parse_part_entry() to set the msftdata flag if and only if the PARTITION_BASIC_DATA_GUID type code is in use; modified gpt_partition_new() to use the PARTITION_LINUX_DATA_GUID type as the default type code; modified gpt_partition_set_system() to set the PARTITION_BASIC_DATA_GUID type code on partitions on which the msftdata flag is set and to set PARTITION_LINUX_DATA_GUID as the type by default; cleared the msftdata flag in most tests in gpt_partition_set_flag(); added test to gpt_partition_set_flag() for PED_PARTITION_MSFT_DATA, which sets msftdata and other flags appropriately; added test to gpt_partition_get_flag() for the PED_PARTITION_MSFT_DATA item that returns the status of the msftdata flag; added test for PED_PARTITION_MSFT_DATA item to gpt_partition_is_flag_available() function. --- NEWS | 18 +++++++++++++++++ doc/parted.texi | 14 +++++++++++++ include/parted/disk.h | 5 ++- libparted/disk.c | 2 + libparted/labels/gpt.c | 45 ++++++++++++++++++++++++++++++++++++++++++- tests/t0220-gpt-msftres.sh | 3 +- 6 files changed, 82 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index cb61ac1..23aad41 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,24 @@ GNU parted NEWS -*- outline -*- libparted: works with a two-component linux kernel version number like 3.0 +** Changes in behavior + + Added new Linux-specific partition GUID type code + (0FC63DAF-8483-4772-8E79-3D69D8477DE4) for Linux filesystem data on GPT + disks. This type code is now assigned as the default partition type code + for new partitions holding Linux filesystems. + + Added new "msftdata" flag to identify partitions holding NTFS or FAT + filesystems on GPT disks. This flag corresponds to a GPT type code of + EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 ("Microsoft Basic Data"). Since + Linux filesystem partitions formerly used this type code, this flag may + optionally be set on Linux partitions to make the partition table type + codes match former configurations in case the new Linux filesystem type + code causes problems with some utility. Note that this flag cannot be + removed from NTFS or FAT partitions within parted except by setting a + competing flag, such as "boot" (which sets the type code used by EFI + System partitions) or "msftres" (which sets the "Microsoft Reserved" type + code). * Noteworthy changes in release 3.0 (2011-05-30) [stable] diff --git a/doc/parted.texi b/doc/parted.texi index f6c64f5..eb82bd0 100644 --- a/doc/parted.texi +++ b/doc/parted.texi @@ -762,6 +762,20 @@ on a partition that partition must be bootable. For PC98 disk labels, all ext2 partitions must be bootable (this is enforced by Parted). address@hidden msftdata +(GPT) - This flag identifies partitions that contain Microsoft filesystems +(NTFS or FAT). It may optionally be set on Linux filesystems to mimic the +type of configuration created by parted 3.0 and earlier, in which a +separate Linux filesystem type code was not available on GPT disks. This +flag can only be removed within parted by replacing it with a competing +flag, such as boot or msftres. + address@hidden msftres +(GPT) - This flag identifies a "Microsoft Reserved" partition, which is +used by Windows on GPT disks. Note that this flag should not normally be +set on Windows filesystem partitions (those that contain NTFS or FAT +filesystems). + @item lba (MS-DOS) - this flag can be enabled to tell MS DOS, MS Windows 9x and MS Windows ME based operating systems to use Linear (LBA) mode. diff --git a/include/parted/disk.h b/include/parted/disk.h index dd461fb..e6ae021 100644 --- a/include/parted/disk.h +++ b/include/parted/disk.h @@ -70,10 +70,11 @@ enum _PedPartitionFlag { PED_PARTITION_BIOS_GRUB=12, PED_PARTITION_APPLE_TV_RECOVERY=13, PED_PARTITION_DIAG=14, - PED_PARTITION_LEGACY_BOOT=15 + PED_PARTITION_LEGACY_BOOT=15, + PED_PARTITION_MSFT_DATA=16 }; #define PED_PARTITION_FIRST_FLAG PED_PARTITION_BOOT -#define PED_PARTITION_LAST_FLAG PED_PARTITION_LEGACY_BOOT +#define PED_PARTITION_LAST_FLAG PED_PARTITION_MSFT_DATA enum _PedDiskTypeFeature { PED_DISK_TYPE_EXTENDED=1, /**< supports extended partitions */ diff --git a/libparted/disk.c b/libparted/disk.c index 1057aa8..9e597e0 100644 --- a/libparted/disk.c +++ b/libparted/disk.c @@ -2431,6 +2431,8 @@ ped_partition_flag_get_name (PedPartitionFlag flag) return N_("prep"); case PED_PARTITION_MSFT_RESERVED: return N_("msftres"); + case PED_PARTITION_MSFT_DATA: + return N_("msftdata"); case PED_PARTITION_APPLE_TV_RECOVERY: return N_("atvrecv"); case PED_PARTITION_DIAG: diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c index 8c9816f..1517c83 100644 --- a/libparted/labels/gpt.c +++ b/libparted/labels/gpt.c @@ -122,6 +122,10 @@ typedef struct ((efi_guid_t) { PED_CPU_TO_LE32 (0x0657fd6d), PED_CPU_TO_LE16 (0xa4ab), \ PED_CPU_TO_LE16 (0x43c4), 0x84, 0xe5, \ { 0x09, 0x33, 0xc8, 0x4b, 0x4f, 0x4f }}) +#define PARTITION_LINUX_DATA_GUID \ + ((efi_guid_t) { PED_CPU_TO_LE32 (0x0FC63DAF), PED_CPU_TO_LE16 (0x8483), \ + PED_CPU_TO_LE16 (0x4772), 0x8E, 0x79, \ + { 0x3D, 0x69, 0xD8, 0x47, 0x7D, 0xE4 }}) #define PARTITION_LVM_GUID \ ((efi_guid_t) { PED_CPU_TO_LE32 (0xe6d6d379), PED_CPU_TO_LE16 (0xf507), \ PED_CPU_TO_LE16 (0x44c2), 0xa2, 0x3c, \ @@ -279,6 +283,7 @@ typedef struct _GPTPartitionData int hp_service; int hidden; int msftres; + int msftdata; int atvrecv; int msftrecv; int legacy_boot; @@ -801,6 +806,7 @@ _parse_part_entry (PedDisk *disk, GuidPartitionEntry_t *pte) gpt_part_data->lvm = gpt_part_data->raid = gpt_part_data->boot = gpt_part_data->hp_service = gpt_part_data->hidden = gpt_part_data->msftres + = gpt_part_data->msftdata = gpt_part_data->msftrecv = gpt_part_data->legacy_boot = gpt_part_data->bios_grub = gpt_part_data->atvrecv = 0; @@ -822,6 +828,8 @@ _parse_part_entry (PedDisk *disk, GuidPartitionEntry_t *pte) gpt_part_data->hp_service = 1; else if (!guid_cmp (gpt_part_data->type, PARTITION_MSFT_RESERVED_GUID)) gpt_part_data->msftres = 1; + else if (!guid_cmp (gpt_part_data->type, PARTITION_BASIC_DATA_GUID)) + gpt_part_data->msftdata = 1; else if (!guid_cmp (gpt_part_data->type, PARTITION_MSFT_RECOVERY)) gpt_part_data->msftrecv = 1; else if (!guid_cmp (gpt_part_data->type, PARTITION_APPLE_TV_RECOVERY_GUID)) @@ -1319,7 +1327,7 @@ gpt_partition_new (const PedDisk *disk, if (!gpt_part_data) goto error_free_part; - gpt_part_data->type = PARTITION_BASIC_DATA_GUID; + gpt_part_data->type = PARTITION_LINUX_DATA_GUID; gpt_part_data->lvm = 0; gpt_part_data->raid = 0; gpt_part_data->boot = 0; @@ -1327,6 +1335,7 @@ gpt_partition_new (const PedDisk *disk, gpt_part_data->hp_service = 0; gpt_part_data->hidden = 0; gpt_part_data->msftres = 0; + gpt_part_data->msftdata = 0; gpt_part_data->msftrecv = 0; gpt_part_data->atvrecv = 0; gpt_part_data->legacy_boot = 0; @@ -1425,6 +1434,11 @@ gpt_partition_set_system (PedPartition *part, gpt_part_data->type = PARTITION_MSFT_RESERVED_GUID; return 1; } + if (gpt_part_data->msftdata) + { + gpt_part_data->type = PARTITION_BASIC_DATA_GUID; + return 1; + } if (gpt_part_data->msftrecv) { gpt_part_data->type = PARTITION_MSFT_RECOVERY; @@ -1456,7 +1470,7 @@ gpt_partition_set_system (PedPartition *part, } } - gpt_part_data->type = PARTITION_BASIC_DATA_GUID; + gpt_part_data->type = PARTITION_LINUX_DATA_GUID; return 1; } @@ -1534,6 +1548,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state) = gpt_part_data->bios_grub = gpt_part_data->hp_service = gpt_part_data->msftres + = gpt_part_data->msftdata = gpt_part_data->msftrecv = gpt_part_data->atvrecv = 0; return gpt_partition_set_system (part, part->fs_type); @@ -1545,6 +1560,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state) = gpt_part_data->boot = gpt_part_data->hp_service = gpt_part_data->msftres + = gpt_part_data->msftdata = gpt_part_data->msftrecv = gpt_part_data->atvrecv = 0; return gpt_partition_set_system (part, part->fs_type); @@ -1556,6 +1572,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state) = gpt_part_data->bios_grub = gpt_part_data->hp_service = gpt_part_data->msftres + = gpt_part_data->msftdata = gpt_part_data->msftrecv = gpt_part_data->atvrecv = 0; return gpt_partition_set_system (part, part->fs_type); @@ -1567,6 +1584,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state) = gpt_part_data->bios_grub = gpt_part_data->hp_service = gpt_part_data->msftres + = gpt_part_data->msftdata = gpt_part_data->msftrecv = gpt_part_data->atvrecv = 0; return gpt_partition_set_system (part, part->fs_type); @@ -1578,6 +1596,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state) = gpt_part_data->lvm = gpt_part_data->bios_grub = gpt_part_data->msftres + = gpt_part_data->msftdata = gpt_part_data->msftrecv = gpt_part_data->atvrecv = 0; return gpt_partition_set_system (part, part->fs_type); @@ -1589,8 +1608,25 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state) = gpt_part_data->lvm = gpt_part_data->bios_grub = gpt_part_data->hp_service + = gpt_part_data->msftdata + = gpt_part_data->msftrecv + = gpt_part_data->atvrecv = 0; + return gpt_partition_set_system (part, part->fs_type); + case PED_PARTITION_MSFT_DATA: + gpt_part_data->msftres = state; + if (state) { + gpt_part_data->boot + = gpt_part_data->raid + = gpt_part_data->lvm + = gpt_part_data->bios_grub + = gpt_part_data->hp_service + = gpt_part_data->msftres = gpt_part_data->msftrecv = gpt_part_data->atvrecv = 0; + gpt_part_data->msftdata = 1; + } else { + gpt_part_data->msftdata = 0; + } return gpt_partition_set_system (part, part->fs_type); case PED_PARTITION_DIAG: gpt_part_data->msftrecv = state; @@ -1600,6 +1636,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state) = gpt_part_data->lvm = gpt_part_data->bios_grub = gpt_part_data->hp_service + = gpt_part_data->msftdata = gpt_part_data->msftres = gpt_part_data->atvrecv = 0; return gpt_partition_set_system (part, part->fs_type); @@ -1612,6 +1649,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state) = gpt_part_data->bios_grub = gpt_part_data->hp_service = gpt_part_data->msftres + = gpt_part_data->msftdata = gpt_part_data->msftrecv = 0; return gpt_partition_set_system (part, part->fs_type); case PED_PARTITION_HIDDEN: @@ -1650,6 +1688,8 @@ gpt_partition_get_flag (const PedPartition *part, PedPartitionFlag flag) return gpt_part_data->hp_service; case PED_PARTITION_MSFT_RESERVED: return gpt_part_data->msftres; + case PED_PARTITION_MSFT_DATA: + return gpt_part_data->msftdata; case PED_PARTITION_DIAG: return gpt_part_data->msftrecv; case PED_PARTITION_APPLE_TV_RECOVERY: @@ -1679,6 +1719,7 @@ gpt_partition_is_flag_available (const PedPartition *part, case PED_PARTITION_BIOS_GRUB: case PED_PARTITION_HPSERVICE: case PED_PARTITION_MSFT_RESERVED: + case PED_PARTITION_MSFT_DATA: case PED_PARTITION_DIAG: case PED_PARTITION_APPLE_TV_RECOVERY: case PED_PARTITION_HIDDEN: diff --git a/tests/t0220-gpt-msftres.sh b/tests/t0220-gpt-msftres.sh index 1247ee0..8ff9515 100755 --- a/tests/t0220-gpt-msftres.sh +++ b/tests/t0220-gpt-msftres.sh @@ -56,7 +56,8 @@ printf "BYT;\n$dev:${n_sectors}s:file:$ss:$ss:gpt:;\n" > exp i=1 for type in $fs_types; do end=$(expr $start + $part_size - 1) - echo "$i:${start}s:${end}s:${part_size}s::$type:;" >> exp || fail=1 + case $type in fat*|NTFS) flag=msftdata;; *) flag=;; esac + echo "$i:${start}s:${end}s:${part_size}s::$type:$flag;" >> exp || fail=1 parted -s $dev mkpart primary $type ${start}s ${end}s > err 2>&1 || fail=1 compare err /dev/null || fail=1 parted -s $dev name $i $type > err 2>&1 || fail=1 -- 1.7.3.4