]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (gpt) fix check for beginning of protective partition
authorMichael Marineau <michael.marineau@coreos.com>
Sat, 2 May 2015 04:44:33 +0000 (21:44 -0700)
committerKarel Zak <kzak@redhat.com>
Tue, 5 May 2015 10:28:52 +0000 (12:28 +0200)
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 <michael.marineau@coreos.com>
libfdisk/src/gpt.c

index a7766da60478c9f4bb5dc9c7a13ea62b79f25c98..989fd752c52647f85dce59bce5aca8abead38ca6 100644 (file)
@@ -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))