[Parted-commits] GNU Parted Official Repository: Changes to 'master'

Jim Meyering meyering at alioth.debian.org
Mon Mar 26 17:22:50 UTC 2012


 NEWS                              |    5 ++++
 libparted/labels/gpt.c            |   47 +++++++++++---------------------------
 tests/Makefile.am                 |    1 
 tests/t0301-overwrite-gpt-pmbr.sh |   44 +++++++++++++++++++++++++++++++++++
 4 files changed, 64 insertions(+), 33 deletions(-)

New commits:
commit 5021bbdc6ee892890c2c6fede806b9ad6a6a9378
Author: Brian C. Lane <bcl at redhat.com>
Date:   Tue Mar 20 17:25:23 2012 -0700

    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/overwrite-gpt-pmbr.sh: New test.
    * tests/Makefile.am (TESTS): Add it.

diff --git a/NEWS b/NEWS
index 3bef20e..3969c44 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,11 @@ GNU parted NEWS                                    -*- outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** Bug Fixes
+
+  libparted: treat a disk with no pMBR as an msdos-labeled disk
+  even when it has valid GPT headers.
+
 
 * Noteworthy changes in release 3.1 (2012-03-02) [stable]
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1b37fd9..1264812 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -28,6 +28,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..e7edb66
--- /dev/null
+++ b/tests/t0301-overwrite-gpt-pmbr.sh
@@ -0,0 +1,44 @@
+#!/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
+
+ss=$sector_size_
+dev=loop-file
+
+# Create a GPT partition table.
+dd if=/dev/null of=$dev bs=$ss seek=80 2> /dev/null || framework_failure
+parted -s $dev mklabel gpt > out 2>&1 || framework_failure_
+compare /dev/null out || framework_failure_
+
+# Create an MSDOS partition table in another file.
+dd if=/dev/null of=m bs=$ss seek=80 2> /dev/null || framework_failure
+parted -s m mklabel msdos > out 2>&1 || framework_failure_
+compare /dev/null out || framework_failure_
+
+# Transplant the MSDOS MBR into the GPT-formatted image.
+dd if=m of=$dev bs=$ss count=1 conv=notrunc || framework_failure_
+
+# Now, try to create a GPT partition table in $dev.
+# Before, parted would prompt, asking about the apparent inconsistency.
+parted -s $dev mklabel gpt > out 2>&1 || fail=1
+# expect no output
+compare /dev/null out || fail=1
+
+Exit $fail

commit b55724f291fa405f652fbbc5cae6e36cc8a2d200
Author: Brian C. Lane <bcl at redhat.com>
Date:   Tue Mar 20 17:25:22 2012 -0700

    libparted: check PMBR before GPT partition table
    
    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 invalid
    PMBR, but would not allow the disk to be used as an msdos disk. This
    change causes parted to recognize the msdos partition table.
    
    * libparted/labels/gpt.c (gpt_probe): Move _pmbr_is_valid test.
    Reported by Chris Murphy in http://bugzilla.redhat.com/805272

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 84bdc12..91ad71a 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -457,7 +457,6 @@ _pmbr_is_valid (const LegacyMBR_t *mbr)
 static int
 gpt_probe (const PedDevice *dev)
 {
-  GuidPartitionTableHeader_t *gpt = NULL;
   int gpt_sig_found = 0;
 
   PED_ASSERT (dev != NULL);
@@ -465,47 +464,29 @@ 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 (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))
     {
-      gpt = pth_new_from_raw (dev, pth_raw);
+      GuidPartitionTableHeader_t *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 *



More information about the Parted-commits mailing list