From 51e87b09ccac9830737454fd8b4ef1a655451454 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Fri, 11 Mar 2011 17:25:06 -0800 Subject: [PATCH] Add upstream patched for legacy_boot and PED_ASSERT - Add support for legacy_boot flag for GPT partitions (680562) - Remove PED_ASSERT for dos geometry calculations (585468) --- ...2.3-Add-GPT-partition-attribute-bits.patch | 37 ++++ ...-legacy_boot-flag-for-GPT-parititons.patch | 159 ++++++++++++++++++ ...ED_ASSERT-from-dos-geometry-checking.patch | 82 +++++++++ parted.spec | 9 +- 4 files changed, 286 insertions(+), 1 deletion(-) create mode 100644 parted-2.3-Add-GPT-partition-attribute-bits.patch create mode 100644 parted-2.3-Add-legacy_boot-flag-for-GPT-parititons.patch create mode 100644 parted-2.3-Remove-PED_ASSERT-from-dos-geometry-checking.patch diff --git a/parted-2.3-Add-GPT-partition-attribute-bits.patch b/parted-2.3-Add-GPT-partition-attribute-bits.patch new file mode 100644 index 0000000..07f8d0c --- /dev/null +++ b/parted-2.3-Add-GPT-partition-attribute-bits.patch @@ -0,0 +1,37 @@ +From e60879e2b781980842f940c39993cccc30cfc67b Mon Sep 17 00:00:00 2001 +From: Brian C. Lane +Date: Thu, 24 Feb 2011 17:02:45 -0800 +Subject: [PATCH 1/2] Add GPT partition attribute bits + +Add NoBlockIOProtocol and LegacyBIOSBootable flags to the GPT partition +Attributes entry. +--- + libparted/labels/gpt.c | 8 ++++++-- + 1 files changed, 6 insertions(+), 2 deletions(-) + +diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c +index b9ed5c3..0396ad7 100644 +--- a/libparted/labels/gpt.c ++++ b/libparted/labels/gpt.c +@@ -163,12 +163,16 @@ struct __attribute__ ((packed)) _GuidPartitionEntryAttributes_t + { + #ifdef __GNUC__ /* XXX narrow this down to !TinyCC */ + uint64_t RequiredToFunction:1; +- uint64_t Reserved:47; ++ uint64_t NoBlockIOProtocol:1; ++ uint64_t LegacyBIOSBootable:1; ++ uint64_t Reserved:45; + uint64_t GuidSpecific:16; + #else + # warning "Using crippled partition entry type" + uint32_t RequiredToFunction:1; +- uint32_t Reserved:32; ++ uint32_t NoBlockIOProtocol:1; ++ uint32_t LegacyBIOSBootable:1; ++ uint32_t Reserved:30; + uint32_t LOST:5; + uint32_t GuidSpecific:16; + #endif +-- +1.7.4 + diff --git a/parted-2.3-Add-legacy_boot-flag-for-GPT-parititons.patch b/parted-2.3-Add-legacy_boot-flag-for-GPT-parititons.patch new file mode 100644 index 0000000..490e5b8 --- /dev/null +++ b/parted-2.3-Add-legacy_boot-flag-for-GPT-parititons.patch @@ -0,0 +1,159 @@ +From df743ae96161bcd260937424c61e24b36ef18fe1 Mon Sep 17 00:00:00 2001 +From: Brian C. Lane +Date: Fri, 25 Feb 2011 10:56:32 -0800 +Subject: [PATCH 2/2] Add legacy_boot flag for GPT parititons + +Add support for the Legacy BIOS Bootable flag in the GPT +Attribute field. This is used by software like syslinux to +determine which partition to boot when in BIOS mode. + +See Page 105, Table 19 Bit 2 of the UEFI Spec 2.3 book. + +* doc/C/parted.8: document legacy_boot +* doc/parted.texi: document legacy_boot +* include/parted/disk.h: Add PED_PARTITION_LEGACY_BOOT flag +* libparted/disk.c (ped_partition_flag_get_name): Add legacy_boot flag +* libparted/labels/gpt.c (_parse_part_entry, + _partition_generate_part_entry, gpt_partition_new, + gpt_partition_set_flag, gpt_partition_get_flag, + gpt_partition_is_flag_available): Add legacy_boot flag support +--- + doc/C/parted.8 | 2 +- + doc/parted.texi | 4 ++++ + include/parted/disk.h | 5 +++-- + libparted/disk.c | 2 ++ + libparted/labels/gpt.c | 13 +++++++++++++ + 5 files changed, 23 insertions(+), 3 deletions(-) + +diff --git a/doc/C/parted.8 b/doc/C/parted.8 +index 2a8992e..f4b940c 100644 +--- a/doc/C/parted.8 ++++ b/doc/C/parted.8 +@@ -132,7 +132,7 @@ or an LVM logical volume if necessary. + .B set \fIpartition\fP \fIflag\fP \fIstate\fP + Change the state of the \fIflag\fP on \fIpartition\fP to \fIstate\fP. + Supported flags are: "boot", "root", "swap", "hidden", "raid", "lvm", "lba", +-and "palo". ++"legacy_boot" and "palo". + \fIstate\fP should be either "on" or "off". + .TP + .B unit \fIunit\fP +diff --git a/doc/parted.texi b/doc/parted.texi +index 1111efd..1a57c07 100644 +--- a/doc/parted.texi ++++ b/doc/parted.texi +@@ -1049,6 +1049,10 @@ depending on what disk label you are using: + (GPT) - Enable this to record that the selected partition is a + GRUB BIOS partition. + ++@item legacy_boot ++(GPT) - this flag is used to tell special purpose software that the GPT ++partition may be bootable. ++ + @item boot + (Mac, MS-DOS, PC98) - should be enabled if you want to boot off the + partition. The semantics vary between disk labels. For MS-DOS disk +diff --git a/include/parted/disk.h b/include/parted/disk.h +index 3a1450c..dd461fb 100644 +--- a/include/parted/disk.h ++++ b/include/parted/disk.h +@@ -69,10 +69,11 @@ enum _PedPartitionFlag { + PED_PARTITION_MSFT_RESERVED=11, + PED_PARTITION_BIOS_GRUB=12, + PED_PARTITION_APPLE_TV_RECOVERY=13, +- PED_PARTITION_DIAG=14 ++ PED_PARTITION_DIAG=14, ++ PED_PARTITION_LEGACY_BOOT=15 + }; + #define PED_PARTITION_FIRST_FLAG PED_PARTITION_BOOT +-#define PED_PARTITION_LAST_FLAG PED_PARTITION_DIAG ++#define PED_PARTITION_LAST_FLAG PED_PARTITION_LEGACY_BOOT + + enum _PedDiskTypeFeature { + PED_DISK_TYPE_EXTENDED=1, /**< supports extended partitions */ +diff --git a/libparted/disk.c b/libparted/disk.c +index 376571e..f6f795f 100644 +--- a/libparted/disk.c ++++ b/libparted/disk.c +@@ -2442,6 +2442,8 @@ ped_partition_flag_get_name (PedPartitionFlag flag) + return N_("atvrecv"); + case PED_PARTITION_DIAG: + return N_("diag"); ++ case PED_PARTITION_LEGACY_BOOT: ++ return N_("legacy_boot"); + + default: + ped_exception_throw ( +diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c +index 0396ad7..31d41bb 100644 +--- a/libparted/labels/gpt.c ++++ b/libparted/labels/gpt.c +@@ -278,6 +278,7 @@ typedef struct _GPTPartitionData + int msftres; + int atvrecv; + int msftrecv; ++ int legacy_boot; + } GPTPartitionData; + + static PedDiskType gpt_disk_type; +@@ -783,10 +784,13 @@ _parse_part_entry (PedDisk *disk, GuidPartitionEntry_t *pte) + = gpt_part_data->boot = gpt_part_data->hp_service + = gpt_part_data->hidden = gpt_part_data->msftres + = gpt_part_data->msftrecv ++ = gpt_part_data->legacy_boot + = gpt_part_data->bios_grub = gpt_part_data->atvrecv = 0; + + if (pte->Attributes.RequiredToFunction & 0x1) + gpt_part_data->hidden = 1; ++ if (pte->Attributes.LegacyBIOSBootable & 0x1) ++ gpt_part_data->legacy_boot = 1; + + if (!guid_cmp (gpt_part_data->type, PARTITION_SYSTEM_GUID)) + gpt_part_data->boot = 1; +@@ -1163,6 +1167,8 @@ _partition_generate_part_entry (PedPartition *part, GuidPartitionEntry_t *pte) + + if (gpt_part_data->hidden) + pte->Attributes.RequiredToFunction = 1; ++ if (gpt_part_data->legacy_boot) ++ pte->Attributes.LegacyBIOSBootable= 1; + + for (i = 0; i < 72 / sizeof (efi_char16_t); i++) + pte->PartitionName[i] +@@ -1305,6 +1311,7 @@ gpt_partition_new (const PedDisk *disk, + gpt_part_data->msftres = 0; + gpt_part_data->msftrecv = 0; + gpt_part_data->atvrecv = 0; ++ gpt_part_data->legacy_boot = 0; + uuid_generate ((unsigned char *) &gpt_part_data->uuid); + swap_uuid_and_efi_guid ((unsigned char *) (&gpt_part_data->uuid)); + memset (gpt_part_data->name, 0, sizeof gpt_part_data->name); +@@ -1592,6 +1599,9 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state) + case PED_PARTITION_HIDDEN: + gpt_part_data->hidden = state; + return 1; ++ case PED_PARTITION_LEGACY_BOOT: ++ gpt_part_data->legacy_boot = state; ++ return 1; + case PED_PARTITION_SWAP: + case PED_PARTITION_ROOT: + case PED_PARTITION_LBA: +@@ -1628,6 +1638,8 @@ gpt_partition_get_flag (const PedPartition *part, PedPartitionFlag flag) + return gpt_part_data->atvrecv; + case PED_PARTITION_HIDDEN: + return gpt_part_data->hidden; ++ case PED_PARTITION_LEGACY_BOOT: ++ return gpt_part_data->legacy_boot; + case PED_PARTITION_SWAP: + case PED_PARTITION_LBA: + case PED_PARTITION_ROOT: +@@ -1652,6 +1664,7 @@ gpt_partition_is_flag_available (const PedPartition *part, + case PED_PARTITION_DIAG: + case PED_PARTITION_APPLE_TV_RECOVERY: + case PED_PARTITION_HIDDEN: ++ case PED_PARTITION_LEGACY_BOOT: + return 1; + case PED_PARTITION_SWAP: + case PED_PARTITION_ROOT: +-- +1.7.4 + diff --git a/parted-2.3-Remove-PED_ASSERT-from-dos-geometry-checking.patch b/parted-2.3-Remove-PED_ASSERT-from-dos-geometry-checking.patch new file mode 100644 index 0000000..125a275 --- /dev/null +++ b/parted-2.3-Remove-PED_ASSERT-from-dos-geometry-checking.patch @@ -0,0 +1,82 @@ +From 244b1b25a12198efb076e8c65be77b5750776583 Mon Sep 17 00:00:00 2001 +From: Brian C. Lane +Date: Wed, 2 Mar 2011 14:36:32 -0800 +Subject: [PATCH 1/2] Remove PED_ASSERT from dos geometry checking + +The CHS geometry values are calculated based on the existing partition +information. The values can't always be calculated, and the partition +may be corrupt so instead of throwing an assertion just return 0 and +carry on. + +I left the logic for the PED_ASSERT checks the same so that it is clear +that the logic has not changed, it just returns 0 now. + +* libparted/labels/dos.c (probe_partition_for_geom): remove PED_ASSERT +--- + libparted/labels/dos.c | 30 ++++++++++++++++++++---------- + 1 files changed, 20 insertions(+), 10 deletions(-) + +diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c +index b657c34..ba80896 100644 +--- a/libparted/labels/dos.c ++++ b/libparted/labels/dos.c +@@ -720,8 +720,10 @@ probe_partition_for_geom (const PedPartition* part, PedCHSGeometry* bios_geom) + if (cyl_size * denum != a_*H - A_*h) + return 0; + +- PED_ASSERT (cyl_size > 0, return 0); +- PED_ASSERT (cyl_size <= 255 * 63, return 0); ++ if (!(cyl_size > 0)) ++ return 0; ++ if (!(cyl_size <= 255 * 63)) ++ return 0; + + if (h > 0) + head_size = ( a_ - c * cyl_size ) / h; +@@ -732,18 +734,24 @@ probe_partition_for_geom (const PedPartition* part, PedCHSGeometry* bios_geom) + PED_ASSERT (0, return 0); + } + +- PED_ASSERT (head_size > 0, return 0); +- PED_ASSERT (head_size <= 63, return 0); ++ if (!(head_size > 0)) ++ return 0; ++ if (!(head_size <= 63)) ++ return 0; + + cylinders = part->disk->dev->length / cyl_size; + heads = cyl_size / head_size; + sectors = head_size; + +- PED_ASSERT (heads > 0, return 0); +- PED_ASSERT (heads < 256, return 0); ++ if (!(heads > 0)) ++ return 0; ++ if (!(heads < 256)) ++ return 0; + +- PED_ASSERT (sectors > 0, return 0); +- PED_ASSERT (sectors <= 63, return 0); ++ if (!(sectors > 0)) ++ return 0; ++ if (!(sectors <= 63)) ++ return 0; + + /* Some broken OEM partitioning program(s) seem to have an out-by-one + * error on the end of partitions. We should offer to fix the +@@ -752,8 +760,10 @@ probe_partition_for_geom (const PedPartition* part, PedCHSGeometry* bios_geom) + if (((C + 1) * heads + H) * sectors + S == A) + C++; + +- PED_ASSERT ((c * heads + h) * sectors + s == a, return 0); +- PED_ASSERT ((C * heads + H) * sectors + S == A, return 0); ++ if (!((c * heads + h) * sectors + s == a)) ++ return 0; ++ if (!((C * heads + H) * sectors + S == A)) ++ return 0; + + bios_geom->cylinders = cylinders; + bios_geom->heads = heads; +-- +1.7.4 + diff --git a/parted.spec b/parted.spec index 342d653..13ef727 100644 --- a/parted.spec +++ b/parted.spec @@ -4,7 +4,7 @@ Summary: The GNU disk partition manipulation program Name: parted Version: 2.3 -Release: 7%{?dist} +Release: 8%{?dist} License: GPLv3+ Group: Applications/System URL: http://www.gnu.org/software/parted @@ -24,6 +24,9 @@ Patch2: parted-2.3-mac-logical-sector-size.patch Patch3: parted-2.3-Document-align-check-642476.patch # Default to 1MiB partition alignment Patch4: parted-2.3-default-to-1MiB-alignment-when-possible.patch +Patch5: parted-2.3-Add-GPT-partition-attribute-bits.patch +Patch6: parted-2.3-Add-legacy_boot-flag-for-GPT-parititons.patch +Patch7: parted-2.3-Remove-PED_ASSERT-from-dos-geometry-checking.patch Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRequires: e2fsprogs-devel @@ -149,6 +152,10 @@ fi %changelog +* Fri Mar 11 2011 Brian C. Lane - 2.3-8 +- Add support for legacy_boot flag for GPT partitions (680562) +- Remove PED_ASSERT for dos geometry calculations (585468) + * Wed Feb 09 2011 Brian C. Lane - 2.3-7 - Tell GCC to stop treating unused variable warnings as errors