From owner-svn-src-all@FreeBSD.ORG Thu Jun 14 11:17:55 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 861DC1065670; Thu, 14 Jun 2012 11:17:55 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [69.147.83.44]) by mx1.freebsd.org (Postfix) with ESMTP id 596868FC0A; Thu, 14 Jun 2012 11:17:55 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q5EBHtIY090747; Thu, 14 Jun 2012 11:17:55 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q5EBHtD7090745; Thu, 14 Jun 2012 11:17:55 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201206141117.q5EBHtD7090745@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Thu, 14 Jun 2012 11:17:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r237057 - head/sys/geom/part X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Jun 2012 11:17:55 -0000 Author: ae Date: Thu Jun 14 11:17:54 2012 New Revision: 237057 URL: http://svn.freebsd.org/changeset/base/237057 Log: 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. MFC after: 1 week Modified: head/sys/geom/part/g_part_gpt.c Modified: head/sys/geom/part/g_part_gpt.c ============================================================================== --- head/sys/geom/part/g_part_gpt.c Thu Jun 14 10:48:41 2012 (r237056) +++ head/sys/geom/part/g_part_gpt.c Thu Jun 14 11:17:54 2012 (r237057) @@ -341,9 +341,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 * @@ -589,10 +586,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); } @@ -601,7 +594,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. */ @@ -617,11 +609,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); @@ -1047,6 +1034,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);