]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: gpt: loosen check fot pmbr size in lba
authorDavidlohr Bueso <davidlohr@hp.com>
Sun, 22 Sep 2013 03:45:16 +0000 (20:45 -0700)
committerKarel Zak <kzak@redhat.com>
Wed, 25 Sep 2013 09:13:43 +0000 (11:13 +0200)
While most disk partitioning tools out there create a pMBR's size in lba
to be the lesser of the whole disk or 2Tib, Microsoft apparently does not[1].
It always sets the entry to the maximum 32-bit limitation - even though a
drive may be smaller than that.

Loosen this check and only verify that the size is either the whole disk
or 0xFFFFFFFF.  No tool in its right mind would set it to any value
other than these.

[1] http://thestarman.pcministry.com/asm/mbr/GPT.htm#GPTPT

Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
libfdisk/src/gpt.c

index 155745d2602864b0cf6fbdbf4b1aee4eb00c8c07..d6817d4a3771fd1d70aca37fb8ee1f183e7825ae 100644 (file)
@@ -463,6 +463,7 @@ static int valid_pmbr(struct fdisk_context *cxt)
 {
        int i, part = 0, ret = 0; /* invalid by default */
        struct gpt_legacy_mbr *pmbr = NULL;
+       uint32_t sz_lba = 0;
 
        if (!cxt->firstsector)
                goto done;
@@ -503,12 +504,15 @@ check_hybrid:
        /*
         * Protective MBRs take up the lesser of the whole disk
         * or 2 TiB (32bit LBA), ignoring the rest of the disk.
+        * Some partitioning programs, nonetheless, choose to set
+        * the size to the maximum 32-bit limitation, disregarding
+        * the disk size.
         *
         * Hybrid MBRs do not necessarily comply with this.
         */
        if (ret == GPT_MBR_PROTECTIVE) {
-               if (le32_to_cpu(pmbr->partition_record[part].size_in_lba) !=
-                   min((uint32_t) cxt->total_sectors - 1, 0xFFFFFFFF))
+               sz_lba = le32_to_cpu(pmbr->partition_record[part].size_in_lba);
+               if (sz_lba != (uint32_t) cxt->total_sectors - 1 && sz_lba != 0xFFFFFFFF)
                        ret = 0;
        }
 done: