[parted/f17] - libparted: check PMBR before GPT partition table (#805272) - tests: add a test for the new behavio
Brian C. Lane
bcl at fedoraproject.org
Wed Mar 21 18:06:24 UTC 2012
commit 02f921c27d458101bc06073d13225cb126d12784
Author: Brian C. Lane <bcl at redhat.com>
Date: Tue Mar 20 17:38:02 2012 -0700
- libparted: check PMBR before GPT partition table (#805272)
- tests: add a test for the new behavior
...heck-PMBR-before-GPT-partition-table-8052.patch | 91 ++++++++++++++++++
...3.1-tests-add-t0301-overwrite-gpt-pmbr.sh.patch | 98 ++++++++++++++++++++
parted.spec | 8 ++-
3 files changed, 196 insertions(+), 1 deletions(-)
---
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" <bcl at redhat.com>
+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..0f786c2
--- /dev/null
+++ b/parted-3.1-tests-add-t0301-overwrite-gpt-pmbr.sh.patch
@@ -0,0 +1,98 @@
+From 6f8492c9c63e45861a076389b10a6e8d9090452a Mon Sep 17 00:00:00 2001
+From: "Brian C. Lane" <bcl at redhat.com>
+Date: Tue, 20 Mar 2012 17:17:10 -0700
+Subject: [PATCH] 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 | 5 ++++
+ tests/Makefile.am | 1 +
+ tests/t0301-overwrite-gpt-pmbr.sh | 45 +++++++++++++++++++++++++++++++++++++
+ 3 files changed, 51 insertions(+), 0 deletions(-)
+ create mode 100755 tests/t0301-overwrite-gpt-pmbr.sh
+
+diff --git a/NEWS b/NEWS
+index 2c1032d..ccfec62 100644
+--- a/NEWS
++++ b/NEWS
+@@ -1,5 +1,10 @@
+ GNU parted NEWS -*- outline -*-
+
++* Noteworthy changes in release 3.0-9 (Fedora)
++
++ libparted: Treat disks without a PMBR as msdos labeled disks
++ even if they have GPT partition tables.
++
+ * Noteworthy changes in release 3.0-8 (Fedora)
+
+ libparted: creating a new partition table on a device with an existing
+diff --git a/tests/Makefile.am b/tests/Makefile.am
+index cd74ff9..1d24ed8 100644
+--- a/tests/Makefile.am
++++ b/tests/Makefile.am
+@@ -20,6 +20,7 @@ TESTS = \
+ t0250-gpt.sh \
+ t0280-gpt-corrupt.sh \
+ t0300-dos-on-gpt.sh \
++ t0301-overwrite-gpt-pmbr.sh \
+ t0400-loop-clobber-infloop.sh \
+ t0500-dup-clobber.sh \
+ t0501-duplicate.sh \
+diff --git a/tests/t0301-overwrite-gpt-pmbr.sh b/tests/t0301-overwrite-gpt-pmbr.sh
+new file mode 100755
+index 0000000..04d9ea6
+--- /dev/null
++++ b/tests/t0301-overwrite-gpt-pmbr.sh
+@@ -0,0 +1,45 @@
++#!/bin/sh
++# Test creating a msdos partition over a GPT partition with
++# fdisk which doesn't remove the GPT partitions, only the PMBR
++
++# Copyright (C) 2009-2012 Free Software Foundation, Inc.
++
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++# GNU General Public License for more details.
++
++# You should have received a copy of the GNU General Public License
++# along with this program. If not, see <http://www.gnu.org/licenses/>.
++
++. "${srcdir=.}/init.sh"; path_prepend_ ../parted
++
++PARTED_SECTOR_SIZE=4096
++export PARTED_SECTOR_SIZE
++
++dev=loop-file
++# create a backing file large enough for a GPT partition table
++dd if=/dev/null of=$dev seek=4001 2> /dev/null || framework_failure
++
++# create a GPT partition table
++parted -s $dev mklabel gpt > out 2>&1 || fail=1
++# expect no output
++compare /dev/null out || fail=1
++
++# create a DOS partition table
++fdisk $dev > out 2>&1 <<EOF
++o
++w
++EOF
++
++# create a GPT partition table
++parted -s $dev mklabel gpt > out 2>&1 || fail=1
++# expect no output
++compare /dev/null out || fail=1
++
++Exit $fail
+--
+1.7.7.6
+
diff --git a/parted.spec b/parted.spec
index b4cd04e..b2da8d6 100644
--- a/parted.spec
+++ b/parted.spec
@@ -4,7 +4,7 @@
Summary: The GNU disk partition manipulation program
Name: parted
Version: 3.0
-Release: 8%{?dist}
+Release: 9%{?dist}
License: GPLv3+
Group: Applications/System
URL: http://www.gnu.org/software/parted
@@ -39,6 +39,8 @@ Patch18: parted-3.0-tests-add-test-for-GPT-PMBR-pmbr_boot-flag.patch
Patch19: parted-3.0-doc-update-parted-documentation.patch
Patch20: parted-3.0-libparted-copy-pmbr_boot-when-duplicating-GPT-disk.patch
Patch21: parted-3.1-libparted-avoid-unwarranted-failed-assertion-during-.patch
+Patch22: parted-3.1-libparted-check-PMBR-before-GPT-partition-table-8052.patch
+Patch23: parted-3.1-tests-add-t0301-overwrite-gpt-pmbr.sh.patch
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: e2fsprogs-devel
@@ -169,6 +171,10 @@ fi
%changelog
+* Tue Mar 20 2012 Brian C. Lane <bcl at redhat.com> 3.0-9
+- libparted: check PMBR before GPT partition table (#805272)
+- tests: add a test for the new behavior
+
* Wed Mar 14 2012 Brian C. Lane <bcl at redhat.com> 3.0-8
- libparted: avoid unwarranted failed assertion (#800235)
More information about the scm-commits
mailing list