public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Davidlohr Bueso <davidlohr@hp.com>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org, Davidlohr Bueso <davidlohr@hp.com>
Subject: [PATCH 2/3] libfdisk: gpt: do not assume first pt record is always pmbr
Date: Sat, 21 Sep 2013 20:45:15 -0700	[thread overview]
Message-ID: <1379821516-2540-2-git-send-email-davidlohr@hp.com> (raw)
In-Reply-To: <1379821516-2540-1-git-send-email-davidlohr@hp.com>

The 0xEE (GPT protective) partition does not always have to be
the first element in the array of MBR partition records.

Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
---
 libfdisk/src/gpt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c
index 2a6284a..bb9e9a7 100644
--- a/libfdisk/src/gpt.c
+++ b/libfdisk/src/gpt.c
@@ -475,7 +475,7 @@ static int gpt_mknew_header(struct fdisk_context *cxt,
  */
 static int valid_pmbr(struct fdisk_context *cxt)
 {
-	int i, ret = 0; /* invalid by default */
+	int i, part = 0, ret = 0; /* invalid by default */
 	struct gpt_legacy_mbr *pmbr = NULL;
 
 	if (!cxt->firstsector)
@@ -494,6 +494,7 @@ static int valid_pmbr(struct fdisk_context *cxt)
 	/* 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) {
+			part = i;
 			/*
 			 * Ok, we at least know that there's a protective MBR,
 			 * now check if there are other partition types for
@@ -520,7 +521,7 @@ check_hybrid:
 	 * Hybrid MBRs do not necessarily comply with this.
 	 */
 	if (ret == GPT_MBR_PROTECTIVE) {
-		if (le32_to_cpu(pmbr->partition_record[0].size_in_lba) !=
+		if (le32_to_cpu(pmbr->partition_record[part].size_in_lba) !=
 		    min((uint32_t) cxt->total_sectors - 1, 0xFFFFFFFF))
 			ret = 0;
 	}
-- 
1.7.11.7

  reply	other threads:[~2013-09-22  3:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-22  3:45 [PATCH 1/3] libfdisk: gpt: avoid unnecessary pmbr check Davidlohr Bueso
2013-09-22  3:45 ` Davidlohr Bueso [this message]
2013-09-25  9:26   ` [PATCH 2/3] libfdisk: gpt: do not assume first pt record is always pmbr Karel Zak
2013-09-22  3:45 ` [PATCH 3/3] libfdisk: gpt: loosen check fot pmbr size in lba Davidlohr Bueso
2013-09-25  9:27   ` Karel Zak
2013-09-25  9:25 ` [PATCH 1/3] libfdisk: gpt: avoid unnecessary pmbr check Karel Zak

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=1379821516-2540-2-git-send-email-davidlohr@hp.com \
    --to=davidlohr@hp.com \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    /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