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