diff --git a/parted-3.1-libparted-check-PMBR-before-GPT-partition-table-8052.patch b/parted-3.1-libparted-check-PMBR-before-GPT-partition-table-8052.patch new file mode 100644 index 0000000..11687b3 --- /dev/null +++ b/parted-3.1-libparted-check-PMBR-before-GPT-partition-table-8052.patch @@ -0,0 +1,91 @@ +From 9343e79fee796a142a4bd12674aa3fdb56526eb6 Mon Sep 17 00:00:00 2001 +From: "Brian C. Lane" +Date: Tue, 20 Mar 2012 16:08:25 -0700 +Subject: [PATCH 1/2] libparted: check PMBR before GPT partition table + (#805272) + +The UEFI spec requires that a valid GPT disk label have a PMBR +partition. This moves the PMBR check to before the GPT check, +exiting gpt_probe with a 0 if the PMBR is not valid. + +The previous behavior would cause problems in the following situation: + 1. format a disk as GPT + 2. re-format it as MSDOS using tools that don't understand GPT + +Subsequent operations with parted would then complain about the invlid +PMBR, but would not allow the disk to be used as a msdos disk. This +change causes parted to tread the disk as a msdos disk. + +* libparted/labels/gpt.c (gpt_probe): Move _pmbr_is_valid test +--- + libparted/labels/gpt.c | 44 +++++++++++++------------------------------- + 1 files changed, 13 insertions(+), 31 deletions(-) + +diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c +index 84bdc12..e57b3a2 100644 +--- a/libparted/labels/gpt.c ++++ b/libparted/labels/gpt.c +@@ -465,6 +465,17 @@ gpt_probe (const PedDevice *dev) + if (dev->length <= 1) + return 0; + ++ void *label; ++ if (!ptt_read_sector (dev, 0, &label)) ++ return 0; ++ ++ if (!_pmbr_is_valid ((const LegacyMBR_t *) label)) ++ { ++ free (label); ++ return 0; ++ } ++ free (label); ++ + void *pth_raw = ped_malloc (pth_get_size (dev)); + if (ped_device_read (dev, pth_raw, 1, GPT_HEADER_SECTORS) + || ped_device_read (dev, pth_raw, dev->length - 1, GPT_HEADER_SECTORS)) +@@ -472,40 +483,11 @@ gpt_probe (const PedDevice *dev) + gpt = pth_new_from_raw (dev, pth_raw); + if (gpt->Signature == PED_CPU_TO_LE64 (GPT_HEADER_SIGNATURE)) + gpt_sig_found = 1; ++ pth_free (gpt); + } +- + free (pth_raw); + +- pth_free (gpt); +- +- if (!gpt_sig_found) +- return 0; +- +- void *label; +- if (!ptt_read_sector (dev, 0, &label)) +- return 0; +- +- int ok = 1; +- if (!_pmbr_is_valid ((const LegacyMBR_t *) label)) +- { +- int ex_status = ped_exception_throw +- (PED_EXCEPTION_WARNING, +- PED_EXCEPTION_YES_NO, +- _("%s contains GPT signatures, indicating that it has " +- "a GPT table. However, it does not have a valid " +- "fake msdos partition table, as it should. Perhaps " +- "it was corrupted -- possibly by a program that " +- "doesn't understand GPT partition tables. Or " +- "perhaps you deleted the GPT table, and are now " +- "using an msdos partition table. Is this a GPT " +- "partition table?"), +- dev->path); +- if (ex_status == PED_EXCEPTION_NO) +- ok = 0; +- } +- +- free (label); +- return ok; ++ return gpt_sig_found; + } + + static PedDisk * +-- +1.7.7.6 + diff --git a/parted-3.1-tests-add-t0301-overwrite-gpt-pmbr.sh.patch b/parted-3.1-tests-add-t0301-overwrite-gpt-pmbr.sh.patch new file mode 100644 index 0000000..99b6602 --- /dev/null +++ b/parted-3.1-tests-add-t0301-overwrite-gpt-pmbr.sh.patch @@ -0,0 +1,34 @@ +From 98f1556d8a134f54d62ebdac27e9d16aa7884983 Mon Sep 17 00:00:00 2001 +From: "Brian C. Lane" +Date: Tue, 20 Mar 2012 17:17:10 -0700 +Subject: [PATCH 2/2] tests: add t0301-overwrite-gpt-pmbr.sh + +Make sure parted checks the PMBR before the GPT partition table. + +* NEWS: Update with new GPT behavior +* tests/Makefile.am: Add new test +* tests/overwrite-gpt-pmbr.sh: new test +--- + NEWS | 7 +++++++ + 1 files changed, 7 insertions(+), 0 deletions(-) + +diff --git a/NEWS b/NEWS +index fe0fcdd..b0a0657 100644 +--- a/NEWS ++++ b/NEWS +@@ -1,5 +1,12 @@ + GNU parted NEWS -*- outline -*- + ++* Noteworthy changes in release 3.1-2 (2012-03-21) [Fedora] ++ ++** Bug Fixes ++ ++ libparted: Treat disks without a PMBR as msdos labeled disks ++ even if they have GPT partition tables. ++ + * Noteworthy changes in release 3.1 (2012-03-02) [stable] + + ** New features +-- +1.7.7.6 + diff --git a/parted.spec b/parted.spec index d1a3ecb..953d3b1 100644 --- a/parted.spec +++ b/parted.spec @@ -4,7 +4,7 @@ Summary: The GNU disk partition manipulation program Name: parted Version: 3.1 -Release: 1%{?dist} +Release: 2%{?dist} License: GPLv3+ Group: Applications/System URL: http://www.gnu.org/software/parted @@ -14,6 +14,8 @@ Source1: ftp://ftp.gnu.org/gnu/%{name}/%{name}-%{version}.tar.xz.sig Source2: pubkey.jim.meyering Patch0: parted-3.0-libparted-copy-pmbr_boot-when-duplicating-GPT-disk.patch +Patch1: parted-3.1-libparted-check-PMBR-before-GPT-partition-table-8052.patch +Patch2: parted-3.1-tests-add-t0301-overwrite-gpt-pmbr.sh.patch Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRequires: e2fsprogs-devel @@ -145,6 +147,10 @@ fi %changelog +* Wed Mar 21 2012 Brian C. Lane 3.1-2 +- libparted: check PMBR before GPT partition table (#805272) +- tests: add a test for the new behavior + * Tue Mar 13 2012 Brian C. Lane 3.1-1 - Rebase to upstream parted v3.1 - removed merged patches