Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 13 Feb 2017 12:07:08 +0000 (UTC)
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
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
Message-ID:  <201702131207.v1DC78Ii024510@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201702131207.v1DC78Ii024510>