From owner-svn-src-all@freebsd.org Sun Jan 10 13:53:58 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 77A97A69CC0; Sun, 10 Jan 2016 13:53:58 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5212712F3; Sun, 10 Jan 2016 13:53:58 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u0ADrv0Q023463; Sun, 10 Jan 2016 13:53:57 GMT (envelope-from ae@FreeBSD.org) Received: (from ae@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u0ADrvsl023460; Sun, 10 Jan 2016 13:53:57 GMT (envelope-from ae@FreeBSD.org) Message-Id: <201601101353.u0ADrvsl023460@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ae set sender to ae@FreeBSD.org using -f From: "Andrey V. Elsukov" Date: Sun, 10 Jan 2016 13:53:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r293634 - in stable/10: sbin/geom/class/part sys/boot/common sys/geom/part X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 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: Sun, 10 Jan 2016 13:53:58 -0000 Author: ae Date: Sun Jan 10 13:53:57 2016 New Revision: 293634 URL: https://svnweb.freebsd.org/changeset/base/293634 Log: MFC r292057: 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. Differential Revision: https://reviews.freebsd.org/D4282 MFC r292058: Remove a note about damaged PMBR. Now GPT will be detected automatically with such corruption. Relnotes: yes Modified: stable/10/sbin/geom/class/part/gpart.8 stable/10/sys/boot/common/part.c stable/10/sys/geom/part/g_part_gpt.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sbin/geom/class/part/gpart.8 ============================================================================== --- stable/10/sbin/geom/class/part/gpart.8 Sun Jan 10 13:40:29 2016 (r293633) +++ stable/10/sbin/geom/class/part/gpart.8 Sun Jan 10 13:53:57 2016 (r293634) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 14, 2015 +.Dd December 10, 2015 .Dt GPART 8 .Os .Sh NAME @@ -1107,15 +1107,6 @@ and .Cm recover are the only operations allowed on corrupt tables. .Pp -If the first sector of a provider is corrupt, the kernel can not detect GPT -even if the partition table itself is not corrupt. -The protective MBR can be rewritten using the -.Xr dd 1 -command, to restore the ability to detect the GPT. -The copy of the protective MBR is usually located in the -.Pa /boot/pmbr -file. -.Pp If one GPT header appears to be corrupt but the other copy remains intact, the kernel will log the following: .Bd -literal -offset indent @@ -1330,7 +1321,6 @@ and /sbin/gpart backup ada0 | /sbin/gpart restore -F ada1 ada2 .Ed .Sh SEE ALSO -.Xr dd 1 , .Xr geom 4 , .Xr boot0cfg 8 , .Xr geom 8 , Modified: stable/10/sys/boot/common/part.c ============================================================================== --- stable/10/sys/boot/common/part.c Sun Jan 10 13:40:29 2016 (r293633) +++ stable/10/sys/boot/common/part.c Sun Jan 10 13:53:57 2016 (r293634) @@ -306,6 +306,7 @@ ptable_gptread(struct ptable *table, voi 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++) { @@ -631,6 +632,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: stable/10/sys/geom/part/g_part_gpt.c ============================================================================== --- stable/10/sys/geom/part/g_part_gpt.c Sun Jan 10 13:40:29 2016 (r293633) +++ stable/10/sys/geom/part/g_part_gpt.c Sun Jan 10 13:53:57 2016 (r293634) @@ -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,