Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Jun 2012 07:56:39 +0000 (UTC)
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r237292 - user/ae/bootcode/sys/boot/common
Message-ID:  <201206200756.q5K7ud7j027515@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ae
Date: Wed Jun 20 07:56:38 2012
New Revision: 237292
URL: http://svn.freebsd.org/changeset/base/237292

Log:
  When primary GPT header is damaged and we are trying to find backup
  GPT header at the last LBA, check for GEOM metadata and skip them if
  found. This allows use GPT atop of the some GEOM providers and boot
  from.
  
  Submitted by:	hrs

Modified:
  user/ae/bootcode/sys/boot/common/gpt.c

Modified: user/ae/bootcode/sys/boot/common/gpt.c
==============================================================================
--- user/ae/bootcode/sys/boot/common/gpt.c	Wed Jun 20 07:38:52 2012	(r237291)
+++ user/ae/bootcode/sys/boot/common/gpt.c	Wed Jun 20 07:56:38 2012	(r237292)
@@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
 #include "gpt.h"
 
 #define	MAXTBLENTS	128
+#define	GEOM_MAGIC	"GEOM::"
 
 static struct gpt_hdr hdr_primary, hdr_backup, *gpthdr;
 static uint64_t hdr_primary_lba, hdr_backup_lba;
@@ -345,8 +346,18 @@ gptread(const uuid_t *uuid, struct dsk *
 		altlba = hdr_primary.hdr_lba_alt;
 	} else {
 		altlba = drvsize(dskp);
-		if (altlba > 0)
-			altlba--;
+		if (altlba > 0) {
+			do {
+				altlba--;
+				/*
+				 * Check GEOM metadata and decrement
+				 * the altlba if found.
+				 */
+				if (drvread(dskp, secbuf, altlba, 1) != 0)
+					break;
+			} while (memcmp(secbuf, GEOM_MAGIC,
+			    sizeof(GEOM_MAGIC) - 1) == 0);
+		}
 	}
 	if (altlba == 0)
 		printf("%s: unable to locate backup GPT header\n", BOOTPROG);



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