From c6bf5c094d90a8a67317ac0fe5b685e7c2b54199 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Fri, 1 May 2015 21:44:33 -0700 Subject: [PATCH] libfdisk: (gpt) fix check for beginning of protective partition Search for the protective partition before attempting to validate that it covers the GPT header. Some hybrid MBRs list partitions out of order. For example, CoreOS images ship with a hybrid MBR that lists the boot partition first and the protective partition second in order to maintain compatibility with old versions of Xen's PV-GRUB. Signed-off-by: Michael Marineau --- libfdisk/src/gpt.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c index a7766da604..989fd752c5 100644 --- a/libfdisk/src/gpt.c +++ b/libfdisk/src/gpt.c @@ -678,11 +678,6 @@ static int valid_pmbr(struct fdisk_context *cxt) if (le16_to_cpu(pmbr->signature) != MSDOS_MBR_SIGNATURE) goto done; - /* LBA of the GPT partition header */ - if (pmbr->partition_record[0].starting_lba != - cpu_to_le32(GPT_PRIMARY_PARTITION_TABLE_LBA)) - goto done; - /* seems like a valid MBR was found, check DOS primary partitions */ for (i = 0; i < 4; i++) { if (pmbr->partition_record[i].os_type == EFI_PMBR_OSTYPE) { @@ -693,13 +688,18 @@ static int valid_pmbr(struct fdisk_context *cxt) */ part = i; ret = GPT_MBR_PROTECTIVE; - goto check_hybrid; + break; } } if (ret != GPT_MBR_PROTECTIVE) goto done; -check_hybrid: + + /* LBA of the GPT partition header */ + if (pmbr->partition_record[part].starting_lba != + cpu_to_le32(GPT_PRIMARY_PARTITION_TABLE_LBA)) + goto done; + for (i = 0 ; i < 4; i++) { if ((pmbr->partition_record[i].os_type != EFI_PMBR_OSTYPE) && (pmbr->partition_record[i].os_type != 0x00)) -- 2.47.3