From owner-svn-src-stable-11@freebsd.org Mon Feb 13 12:07:09 2017 Return-Path: Delivered-To: svn-src-stable-11@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 CE560CDCD88; Mon, 13 Feb 2017 12:07:09 +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 9DA26DD5; Mon, 13 Feb 2017 12:07:09 +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 v1DC78uI024511; Mon, 13 Feb 2017 12:07:08 GMT (envelope-from ae@FreeBSD.org) Received: (from ae@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v1DC78Ii024510; Mon, 13 Feb 2017 12:07:08 GMT (envelope-from ae@FreeBSD.org) Message-Id: <201702131207.v1DC78Ii024510@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ae set sender to ae@FreeBSD.org using -f From: "Andrey V. Elsukov" Date: Mon, 13 Feb 2017 12:07:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r313698 - stable/11/sys/geom/part X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Feb 2017 12:07:09 -0000 Author: ae Date: Mon Feb 13 12:07:08 2017 New Revision: 313698 URL: https://svnweb.freebsd.org/changeset/base/313698 Log: MFC r313185: Check that primary GPT header is valid before wiping partitioning. This allows safely destroy corrupted GPT when primary header was rewritten by some data, that do not want to destroy. Modified: stable/11/sys/geom/part/g_part_gpt.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/geom/part/g_part_gpt.c ============================================================================== --- stable/11/sys/geom/part/g_part_gpt.c Mon Feb 13 11:37:52 2017 (r313697) +++ stable/11/sys/geom/part/g_part_gpt.c Mon Feb 13 12:07:08 2017 (r313698) @@ -687,10 +687,11 @@ g_part_gpt_destroy(struct g_part_table * table->hdr = NULL; /* - * Wipe the first 2 sectors to clear the partitioning. Wipe the last - * sector only if it has valid secondary header. + * Wipe the first 2 sectors and last one to clear the partitioning. + * Wipe sectors only if they have valid metadata. */ - basetable->gpt_smhead |= 3; + if (table->state[GPT_ELT_PRIHDR] == GPT_STATE_OK) + basetable->gpt_smhead |= 3; if (table->state[GPT_ELT_SECHDR] == GPT_STATE_OK && table->lba[GPT_ELT_SECHDR] == pp->mediasize / pp->sectorsize - 1) basetable->gpt_smtail |= 1;