[parted-devel] [PATCH 1/3] Preserve first 446 bytes of the pmbr in gpt.

Joel Granados Moreno jgranado at redhat.com
Tue Jun 9 11:05:40 UTC 2009


* libparted/label/gpt.c (_write_pmbr) : Make sure we read the first 446
  bytes of the device when we are creating the pmbr.
---
 libparted/labels/gpt.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 11eab61..d828e65 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -959,7 +959,18 @@ _write_pmbr (PedDevice * dev)
 	size_t buf_len = pth_get_size (dev);
 	LegacyMBR_t *pmbr = ped_malloc (buf_len);
 
-	memset(pmbr, 0, buf_len);
+	/* The UEFI spec is not clear about what to do with the following
+	 * elements of the Protective MBR (pmbr): BootCode (0-440B),
+	 * UniqueMBRSignature (440B-444B) and Unknown (444B-446B).
+	 * With this in mind, we try not to modify these elements.
+	 */
+	if(ped_device_read(dev, pmbr, 0, GPT_PMBR_SECTORS) < GPT_PMBR_SECTORS)
+		memset(pmbr, 0, buf_len);
+
+	/* Make sure we zero out all the legacy partitions.
+	 * There are 4 PartitionRecords.  */
+	memset(&(pmbr->PartitionRecord), 0, sizeof(PartitionRecord_t) * 4);
+
 	pmbr->Signature = PED_CPU_TO_LE16(MSDOS_MBR_SIGNATURE);
 	pmbr->PartitionRecord[0].OSType      = EFI_PMBR_OSTYPE_EFI;
 	pmbr->PartitionRecord[0].StartSector = 1;
-- 
1.6.0.6




More information about the parted-devel mailing list