Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/gpt PR bin/54088: make "destroy" remove the protective ...



details:   https://anonhg.NetBSD.org/src/rev/cb57243666b6
branches:  trunk
changeset: 840365:cb57243666b6
user:      martin <martin%NetBSD.org@localhost>
date:      Thu Apr 04 14:03:40 2019 +0000

description:
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.

diffstat:

 sbin/gpt/destroy.c |  13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diffs (40 lines):

diff -r eea74f95ab78 -r cb57243666b6 sbin/gpt/destroy.c
--- a/sbin/gpt/destroy.c        Thu Apr 04 13:58:20 2019 +0000
+++ b/sbin/gpt/destroy.c        Thu Apr 04 14:03:40 2019 +0000
@@ -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 @@
 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 @@
                }
        }
 
+       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;
 }
 



Home | Main Index | Thread Index | Old Index