Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 Dec 2015 10:35:07 +0000 (UTC)
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r292057 - in head/sys: boot/common geom/part
Message-ID:  <201512101035.tBAAZ7fj064953@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ae
Date: Thu Dec 10 10:35:07 2015
New Revision: 292057
URL: https://svnweb.freebsd.org/changeset/base/292057

Log:
  Make detection of GPT a bit more reliable.
  
  When we are detecting a partition table and didn't find PMBR, try to
  read backup GPT header from the last sector and if it is correct,
  assume that we have GPT.
  
  Reviewed by:	rpokala
  MFC after:	1 month
  Differential Revision:	https://reviews.freebsd.org/D4282

Modified:
  head/sys/boot/common/part.c
  head/sys/geom/part/g_part_gpt.c

Modified: head/sys/boot/common/part.c
==============================================================================
--- head/sys/boot/common/part.c	Thu Dec 10 07:45:58 2015	(r292056)
+++ head/sys/boot/common/part.c	Thu Dec 10 10:35:07 2015	(r292057)
@@ -301,12 +301,12 @@ ptable_gptread(struct ptable *table, voi
 			}
 		}
 	}
-	DEBUG("GPT detected");
 	if (pri == 0 && sec == 0) {
 		/* Both primary and backup tables are invalid. */
 		table->type = PTABLE_NONE;
 		goto out;
 	}
+	DEBUG("GPT detected");
 	size = MIN(hdr.hdr_entries * hdr.hdr_entsz,
 	    MAXTBLSZ * table->sectorsize);
 	for (i = 0; i < size / hdr.hdr_entsz; i++) {
@@ -635,6 +635,11 @@ ptable_open(void *dev, off_t sectors, ui
 	if (buf[DOSMAGICOFFSET] != 0x55 ||
 	    buf[DOSMAGICOFFSET + 1] != 0xaa) {
 		DEBUG("magic sequence not found");
+#if defined(LOADER_GPT_SUPPORT)
+		/* There is no PMBR, check that we have backup GPT */
+		table->type = PTABLE_GPT;
+		table = ptable_gptread(table, dev, dread);
+#endif
 		goto out;
 	}
 	/* Check that we have PMBR. Also do some validation. */

Modified: head/sys/geom/part/g_part_gpt.c
==============================================================================
--- head/sys/geom/part/g_part_gpt.c	Thu Dec 10 07:45:58 2015	(r292056)
+++ head/sys/geom/part/g_part_gpt.c	Thu Dec 10 10:35:07 2015	(r292057)
@@ -823,22 +823,23 @@ g_part_gpt_probe(struct g_part_table *ta
 		return (error);
 	res = le16dec(buf + DOSMAGICOFFSET);
 	pri = G_PART_PROBE_PRI_LOW;
-	for (index = 0; index < NDOSPART; index++) {
-		if (buf[DOSPARTOFF + DOSPARTSIZE * index + 4] == 0xee)
-			pri = G_PART_PROBE_PRI_HIGH;
-	}
-	g_free(buf);
-	if (res != DOSMAGIC) 
-		return (ENXIO);
+	if (res == DOSMAGIC) {
+		for (index = 0; index < NDOSPART; index++) {
+			if (buf[DOSPARTOFF + DOSPARTSIZE * index + 4] == 0xee)
+				pri = G_PART_PROBE_PRI_HIGH;
+		}
+		g_free(buf);
 
-	/* Check that there's a primary header. */
-	buf = g_read_data(cp, pp->sectorsize, pp->sectorsize, &error);
-	if (buf == NULL)
-		return (error);
-	res = memcmp(buf, GPT_HDR_SIG, 8);
-	g_free(buf);
-	if (res == 0)
-		return (pri);
+		/* Check that there's a primary header. */
+		buf = g_read_data(cp, pp->sectorsize, pp->sectorsize, &error);
+		if (buf == NULL)
+			return (error);
+		res = memcmp(buf, GPT_HDR_SIG, 8);
+		g_free(buf);
+		if (res == 0)
+			return (pri);
+	} else
+		g_free(buf);
 
 	/* No primary? Check that there's a secondary. */
 	buf = g_read_data(cp, pp->mediasize - pp->sectorsize, pp->sectorsize,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201512101035.tBAAZ7fj064953>