Blame SOURCES/parted-3.1-libparted-check-PMBR-before-GPT-partition-table-8052.patch

fc4a62
From 9343e79fee796a142a4bd12674aa3fdb56526eb6 Mon Sep 17 00:00:00 2001
fc4a62
From: "Brian C. Lane" <bcl@redhat.com>
fc4a62
Date: Tue, 20 Mar 2012 16:08:25 -0700
fc4a62
Subject: [PATCH 1/2] libparted: check PMBR before GPT partition table
fc4a62
 (#805272)
fc4a62
fc4a62
The UEFI spec requires that a valid GPT disk label have a PMBR
fc4a62
partition. This moves the PMBR check to before the GPT check,
fc4a62
exiting gpt_probe with a 0 if the PMBR is not valid.
fc4a62
fc4a62
The previous behavior would cause problems in the following situation:
fc4a62
 1. format a disk as GPT
fc4a62
 2. re-format it as MSDOS using tools that don't understand GPT
fc4a62
fc4a62
Subsequent operations with parted would then complain about the invlid
fc4a62
PMBR, but would not allow the disk to be used as a msdos disk. This
fc4a62
change causes parted to tread the disk as a msdos disk.
fc4a62
fc4a62
* libparted/labels/gpt.c (gpt_probe): Move _pmbr_is_valid test
fc4a62
---
fc4a62
 libparted/labels/gpt.c |   44 +++++++++++++-------------------------------
fc4a62
 1 files changed, 13 insertions(+), 31 deletions(-)
fc4a62
fc4a62
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
fc4a62
index 84bdc12..e57b3a2 100644
fc4a62
--- a/libparted/labels/gpt.c
fc4a62
+++ b/libparted/labels/gpt.c
fc4a62
@@ -465,6 +465,17 @@ gpt_probe (const PedDevice *dev)
fc4a62
   if (dev->length <= 1)
fc4a62
     return 0;
fc4a62
 
fc4a62
+  void *label;
fc4a62
+  if (!ptt_read_sector (dev, 0, &label))
fc4a62
+    return 0;
fc4a62
+
fc4a62
+  if (!_pmbr_is_valid ((const LegacyMBR_t *) label))
fc4a62
+    {
fc4a62
+        free (label);
fc4a62
+        return 0;
fc4a62
+    }
fc4a62
+  free (label);
fc4a62
+
fc4a62
   void *pth_raw = ped_malloc (pth_get_size (dev));
fc4a62
   if (ped_device_read (dev, pth_raw, 1, GPT_HEADER_SECTORS)
fc4a62
       || ped_device_read (dev, pth_raw, dev->length - 1, GPT_HEADER_SECTORS))
fc4a62
@@ -472,40 +483,11 @@ gpt_probe (const PedDevice *dev)
fc4a62
       gpt = pth_new_from_raw (dev, pth_raw);
fc4a62
       if (gpt->Signature == PED_CPU_TO_LE64 (GPT_HEADER_SIGNATURE))
fc4a62
         gpt_sig_found = 1;
fc4a62
+      pth_free (gpt);
fc4a62
     }
fc4a62
-
fc4a62
   free (pth_raw);
fc4a62
 
fc4a62
-  pth_free (gpt);
fc4a62
-
fc4a62
-  if (!gpt_sig_found)
fc4a62
-    return 0;
fc4a62
-
fc4a62
-  void *label;
fc4a62
-  if (!ptt_read_sector (dev, 0, &label))
fc4a62
-    return 0;
fc4a62
-
fc4a62
-  int ok = 1;
fc4a62
-  if (!_pmbr_is_valid ((const LegacyMBR_t *) label))
fc4a62
-    {
fc4a62
-      int ex_status = ped_exception_throw
fc4a62
-        (PED_EXCEPTION_WARNING,
fc4a62
-         PED_EXCEPTION_YES_NO,
fc4a62
-         _("%s contains GPT signatures, indicating that it has "
fc4a62
-           "a GPT table.  However, it does not have a valid "
fc4a62
-           "fake msdos partition table, as it should.  Perhaps "
fc4a62
-           "it was corrupted -- possibly by a program that "
fc4a62
-           "doesn't understand GPT partition tables.  Or "
fc4a62
-           "perhaps you deleted the GPT table, and are now "
fc4a62
-           "using an msdos partition table.  Is this a GPT "
fc4a62
-           "partition table?"),
fc4a62
-         dev->path);
fc4a62
-      if (ex_status == PED_EXCEPTION_NO)
fc4a62
-        ok = 0;
fc4a62
-    }
fc4a62
-
fc4a62
-  free (label);
fc4a62
-  return ok;
fc4a62
+  return gpt_sig_found;
fc4a62
 }
fc4a62
 
fc4a62
 static PedDisk *
fc4a62
-- 
fc4a62
1.7.7.6
fc4a62