Module Name: src
Committed By: martin
Date: Thu Apr 4 14:03:40 UTC 2019
Modified Files:
src/sbin/gpt: destroy.c
Log Message:
PR bin/54088: make "destroy" remove the protective MBR too.
We could make this optional if someone comes up with a good reason
to leave it intact.
To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sbin/gpt/destroy.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sbin/gpt/destroy.c
diff -u src/sbin/gpt/destroy.c:1.11 src/sbin/gpt/destroy.c:1.12
--- src/sbin/gpt/destroy.c:1.11 Thu Apr 4 13:58:20 2019
+++ src/sbin/gpt/destroy.c Thu Apr 4 14:03:40 2019
@@ -33,7 +33,7 @@
__FBSDID("$FreeBSD: src/sbin/gpt/destroy.c,v 1.6 2005/08/31 01:47:19 marcel Exp $");
#endif
#ifdef __RCSID
-__RCSID("$NetBSD: destroy.c,v 1.11 2019/04/04 13:58:20 martin Exp $");
+__RCSID("$NetBSD: destroy.c,v 1.12 2019/04/04 14:03:40 martin Exp $");
#endif
#include <sys/types.h>
@@ -68,10 +68,11 @@ struct gpt_cmd c_destroy = {
static int
destroy(gpt_t gpt, int force, int recoverable)
{
- map_t pri_hdr, sec_hdr;
+ map_t pri_hdr, sec_hdr, pmbr;
pri_hdr = map_find(gpt, MAP_TYPE_PRI_GPT_HDR);
sec_hdr = map_find(gpt, MAP_TYPE_SEC_GPT_HDR);
+ pmbr = map_find(gpt, MAP_TYPE_PMBR);
if (pri_hdr == NULL && sec_hdr == NULL) {
gpt_warnx(gpt, "Device doesn't contain a GPT");
@@ -99,6 +100,14 @@ destroy(gpt_t gpt, int force, int recove
}
}
+ if (!recoverable && pmbr != NULL) {
+ memset(pmbr->map_data, 0, gpt->secsz);
+ if (gpt_write(gpt, pmbr) == -1) {
+ gpt_warnx(gpt, "Error deleting PMBR");
+ return -1;
+ }
+ }
+
return 0;
}