svn commit: r237391 - stable/9/sys/geom/part

Andrey V. Elsukov ae at FreeBSD.org
Thu Jun 21 12:47:22 UTC 2012


Author: ae
Date: Thu Jun 21 12:47:21 2012
New Revision: 237391
URL: http://svn.freebsd.org/changeset/base/237391

Log:
  MFC r237057:
    Always reconstruct partition entries in the PMBR when Boot Camp is
    disabled. This helps to easily recover from situations when PMBR is
    damaged and contains no entries.

Modified:
  stable/9/sys/geom/part/g_part_gpt.c
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/geom/part/g_part_gpt.c
==============================================================================
--- stable/9/sys/geom/part/g_part_gpt.c	Thu Jun 21 12:26:12 2012	(r237390)
+++ stable/9/sys/geom/part/g_part_gpt.c	Thu Jun 21 12:47:21 2012	(r237391)
@@ -339,9 +339,6 @@ gpt_update_bootcamp(struct g_part_table 
 
  disable:
 	table->bootcamp = 0;
-	bzero(table->mbr + DOSPARTOFF, DOSPARTSIZE * NDOSPART);
-	gpt_write_mbr_entry(table->mbr, 0, 0xee, 1ull,
-	    MIN(table->lba[GPT_ELT_SECHDR], UINT32_MAX));
 }
 
 static struct gpt_hdr *
@@ -587,10 +584,6 @@ g_part_gpt_bootcode(struct g_part_table 
 	codesz = MIN(codesz, gpp->gpp_codesize);
 	if (codesz > 0)
 		bcopy(gpp->gpp_codeptr, table->mbr, codesz);
-
-	/* Mark the PMBR active since some BIOS require it. */
-	if (!table->bootcamp)
-		table->mbr[DOSPARTOFF] = 0x80;		/* status */
 	return (0);
 }
 
@@ -599,7 +592,6 @@ g_part_gpt_create(struct g_part_table *b
 {
 	struct g_provider *pp;
 	struct g_part_gpt_table *table;
-	quad_t last;
 	size_t tblsz;
 
 	/* We don't nest, which means that our depth should be 0. */
@@ -615,11 +607,6 @@ g_part_gpt_create(struct g_part_table *b
 	    pp->sectorsize)
 		return (ENOSPC);
 
-	last = (pp->mediasize / pp->sectorsize) - 1;
-
-	le16enc(table->mbr + DOSMAGICOFFSET, DOSMAGIC);
-	gpt_write_mbr_entry(table->mbr, 0, 0xee, 1, MIN(last, UINT32_MAX));
-
 	/* Allocate space for the header */
 	table->hdr = g_malloc(sizeof(struct gpt_hdr), M_WAITOK | M_ZERO);
 
@@ -1045,6 +1032,16 @@ g_part_gpt_write(struct g_part_table *ba
 	if (table->bootcamp)
 		gpt_update_bootcamp(basetable);
 
+	/* Update partition entries in the PMBR if Boot Camp disabled. */
+	if (!table->bootcamp) {
+		bzero(table->mbr + DOSPARTOFF, DOSPARTSIZE * NDOSPART);
+		gpt_write_mbr_entry(table->mbr, 0, 0xee, 1,
+		    MIN(pp->mediasize / pp->sectorsize - 1, UINT32_MAX));
+		/* Mark the PMBR active since some BIOS require it. */
+		table->mbr[DOSPARTOFF] = 0x80;
+	}
+	le16enc(table->mbr + DOSMAGICOFFSET, DOSMAGIC);
+
 	/* Write the PMBR */
 	buf = g_malloc(pp->sectorsize, M_WAITOK | M_ZERO);
 	bcopy(table->mbr, buf, MBRSIZE);


More information about the svn-src-stable-9 mailing list