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

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