summaryrefslogtreecommitdiffstats
path: root/sys/geom
diff options
context:
space:
mode:
authorae <ae@FreeBSD.org>2017-02-13 12:07:08 +0000
committerae <ae@FreeBSD.org>2017-02-13 12:07:08 +0000
commit7f640009ffe88e642c712ff3c88a8d57c1d26959 (patch)
treefbcd09e783767eff95e2d8b4cffbe26de263c5ba /sys/geom
parent4867abd4c8a4f8b3ce1788b290754f6599ebd71b (diff)
downloadFreeBSD-src-7f640009ffe88e642c712ff3c88a8d57c1d26959.zip
FreeBSD-src-7f640009ffe88e642c712ff3c88a8d57c1d26959.tar.gz
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.
Diffstat (limited to 'sys/geom')
-rw-r--r--sys/geom/part/g_part_gpt.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/sys/geom/part/g_part_gpt.c b/sys/geom/part/g_part_gpt.c
index f9017ab..45d6ef8 100644
--- a/sys/geom/part/g_part_gpt.c
+++ b/sys/geom/part/g_part_gpt.c
@@ -687,10 +687,11 @@ g_part_gpt_destroy(struct g_part_table *basetable, struct g_part_parms *gpp)
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;
OpenPOWER on IntegriCloud