diff options
author | Andrey V. Elsukov <ae@FreeBSD.org> | 2017-02-04 05:09:47 +0000 |
---|---|---|
committer | Andrey V. Elsukov <ae@FreeBSD.org> | 2017-02-04 05:09:47 +0000 |
commit | 9ef60043520706ebe7d00161dde5237823f799c2 (patch) | |
tree | 38e632d98624f7e6ff316962d83d99627dde3fd2 /sys/geom | |
parent | e29722703885d1a1848ce96516db519f4789a709 (diff) | |
download | src-9ef60043520706ebe7d00161dde5237823f799c2.tar.gz src-9ef60043520706ebe7d00161dde5237823f799c2.zip |
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
Notes
Notes:
svn path=/head/; revision=313185
Diffstat (limited to 'sys/geom')
-rw-r--r-- | sys/geom/part/g_part_gpt.c | 7 |
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 f9017abe2bd6..45d6ef859560 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; |