Author: ae
Date: Sat Feb  4 05:09:47 2017
New Revision: 313185
URL: https://svnweb.freebsd.org/changeset/base/313185

Log:
  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.
  
  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     Sat Feb  4 02:15:49 2017        
(r313184)
+++ head/sys/geom/part/g_part_gpt.c     Sat Feb  4 05:09:47 2017        
(r313185)
@@ -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;
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to