From: Davidlohr Bueso <davidlohr@hp.com>
To: Andrew Morton <akpm@linux-foundation.org>, Jens Axboe <axboe@kernel.dk>
Cc: Matt Domsch <Matt_Domsch@dell.com>, Jim Hull <jim.hull@hp.com>,
Karel Zak <kzak@redhat.com>, Peter Jones <pjones@redhat.com>,
Chegu Vinod <chegu_vinod@hp.com>,
Aswin Chandramouleeswaran <aswin@hp.com>,
linux-kernel@vger.kernel.org, Davidlohr Bueso <davidlohr@hp.com>
Subject: [PATCH 5/8] partitions/efi: account for pmbr size in lba
Date: Mon, 5 Aug 2013 22:21:13 -0700 [thread overview]
Message-ID: <1375766476-4204-6-git-send-email-davidlohr@hp.com> (raw)
In-Reply-To: <1375766476-4204-1-git-send-email-davidlohr@hp.com>
The partition that has the 0xEE (GPT protective), must
have the size in lba field set to the lesser of the size
of the disk minus one or 0xFFFFFFFF for larger disks.
Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
---
block/partitions/efi.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/block/partitions/efi.c b/block/partitions/efi.c
index 4bf8165..ab6cd08 100644
--- a/block/partitions/efi.c
+++ b/block/partitions/efi.c
@@ -166,6 +166,7 @@ invalid:
/**
* is_pmbr_valid(): test Protective MBR for validity
* @mbr: pointer to a legacy mbr structure
+ * @total_sectors: amount of sectors in the device
*
* Description: Checks for a valid protective or hybrid
* master boot record (MBR). The validity of a pMBR depends
@@ -180,9 +181,9 @@ invalid:
* Returns 0 upon invalid MBR, or GPT_MBR_PROTECTIVE or
* GPT_MBR_HYBRID depending on the device layout.
*/
-static int is_pmbr_valid(legacy_mbr *mbr)
+static int is_pmbr_valid(legacy_mbr *mbr, sector_t total_sectors)
{
- int i, ret = 0; /* invalid by default */
+ int i, part = 0, ret = 0; /* invalid by default */
if (!mbr || le16_to_cpu(mbr->signature) != MSDOS_MBR_SIGNATURE)
goto done;
@@ -190,6 +191,7 @@ static int is_pmbr_valid(legacy_mbr *mbr)
for (i = 0; i < 4; i++) {
ret = pmbr_part_valid(&mbr->partition_record[i]);
if (ret == GPT_MBR_PROTECTIVE) {
+ part = i;
/*
* Ok, we at least know that there's a protective MBR,
* now check if there are other partition types for
@@ -206,6 +208,18 @@ check_hybrid:
if ((mbr->partition_record[i].os_type != EFI_PMBR_OSTYPE_EFI_GPT) &&
(mbr->partition_record[i].os_type != 0x00))
ret = GPT_MBR_HYBRID;
+
+ /*
+ * Protective MBRs take up the lesser of the whole disk
+ * or 2 TiB (32bit LBA), ignoring the rest of the disk.
+ *
+ * Hybrid MBRs do not necessarily comply with this.
+ */
+ if (ret == GPT_MBR_PROTECTIVE) {
+ if (le32_to_cpu(mbr->partition_record[part].size_in_lba) !=
+ min((uint32_t) total_sectors - 1, 0xFFFFFFFF))
+ ret = 0;
+ }
done:
return ret;
}
@@ -567,6 +581,7 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
gpt_header *pgpt = NULL, *agpt = NULL;
gpt_entry *pptes = NULL, *aptes = NULL;
legacy_mbr *legacymbr;
+ sector_t total_sectors = i_size_read(state->bdev->bd_inode) >> 9;
u64 lastlba;
if (!ptes)
@@ -580,7 +595,7 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
goto fail;
read_lba(state, 0, (u8 *) legacymbr, sizeof (*legacymbr));
- good_pmbr = is_pmbr_valid(legacymbr);
+ good_pmbr = is_pmbr_valid(legacymbr, total_sectors);
kfree(legacymbr);
if (!good_pmbr)
--
1.7.11.7
next prev parent reply other threads:[~2013-08-06 5:21 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-06 5:21 [PATCH 0/8] partitions/efi: detect hybrid mbrs Davidlohr Bueso
2013-08-06 5:21 ` [PATCH 1/8] partitions/efi: use lba-aware partition records Davidlohr Bueso
2013-09-02 10:10 ` Karel Zak
2013-09-03 5:01 ` Davidlohr Bueso
2013-08-06 5:21 ` [PATCH 2/8] partitions/efi: check pmbr record's starting lba Davidlohr Bueso
2013-08-06 5:21 ` [PATCH 3/8] partitions/efi: do not require gpt partition to begin at sector 1 Davidlohr Bueso
2013-08-06 5:21 ` [PATCH 4/8] partitions/efi: detect hybrid MBRs Davidlohr Bueso
2013-08-06 5:21 ` Davidlohr Bueso [this message]
2013-08-06 5:21 ` [PATCH 6/8] partitions/efi: compare first and last usable LBAs Davidlohr Bueso
2013-08-06 5:21 ` [PATCH 7/8] partitions/efi: delete annoying emacs style comments Davidlohr Bueso
2013-08-06 5:21 ` [PATCH 8/8] partitions/efi: some style cleanups Davidlohr Bueso
2013-08-06 21:16 ` [PATCH 0/8] partitions/efi: detect hybrid mbrs Andrew Morton
2013-08-06 22:39 ` Davidlohr Bueso
2013-08-15 16:59 ` Davidlohr Bueso
2013-08-15 19:29 ` Andrew Morton
2013-08-16 1:37 ` Davidlohr Bueso
2013-09-02 10:33 ` Karel Zak
2013-09-03 12:33 ` Matt Fleming
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1375766476-4204-6-git-send-email-davidlohr@hp.com \
--to=davidlohr@hp.com \
--cc=Matt_Domsch@dell.com \
--cc=akpm@linux-foundation.org \
--cc=aswin@hp.com \
--cc=axboe@kernel.dk \
--cc=chegu_vinod@hp.com \
--cc=jim.hull@hp.com \
--cc=kzak@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pjones@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®