svn commit: r237292 - user/ae/bootcode/sys/boot/common

Andrey V. Elsukov ae at FreeBSD.org
Wed Jun 20 07:56:39 UTC 2012


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);


More information about the svn-src-user mailing list