summaryrefslogtreecommitdiff
path: root/sbin/fdisk
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2022-07-26 14:30:38 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2022-07-26 14:30:38 +0000
commit59478e0b2f531e97853e9e7e1cd85a60e1a07a30 (patch)
tree6d9f854eac4e571e3764f2de4dc23ab929a08fc2 /sbin/fdisk
parent832416761d223ca851f94bb5f0925ccd25f294a9 (diff)
Allow editing of an MBR of all zeros.
Fallout from regress failure spotted by anton@.
Diffstat (limited to 'sbin/fdisk')
-rw-r--r--sbin/fdisk/mbr.c13
-rw-r--r--sbin/fdisk/mbr.h3
2 files changed, 13 insertions, 3 deletions
diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c
index 2ef6783110f..6e6b6c58caf 100644
--- a/sbin/fdisk/mbr.c
+++ b/sbin/fdisk/mbr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbr.c,v 1.120 2022/07/25 17:45:16 krw Exp $ */
+/* $OpenBSD: mbr.c,v 1.121 2022/07/26 14:30:37 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -105,7 +105,13 @@ dos_mbr_to_mbr(const struct dos_mbr *dmbr, const uint64_t lba_self,
const uint64_t lba_firstembr, struct mbr *mbr)
{
struct dos_partition dos_parts[NDOSPART];
- int i;
+ uint8_t *p;
+ unsigned int i;
+
+ p = (uint8_t *)dmbr;
+ mbr->mbr_dmbrzeros = 0;
+ for (i = 0; i < sizeof(struct dos_mbr) && *p == 0; i++, p++)
+ mbr->mbr_dmbrzeros++;
memcpy(mbr->mbr_code, dmbr->dmbr_boot, sizeof(mbr->mbr_code));
mbr->mbr_lba_self = lba_self;
@@ -188,6 +194,9 @@ MBR_valid_prt(const struct mbr *mbr)
unsigned int i, nprt;
unsigned char id;
+ if (mbr->mbr_dmbrzeros == sizeof(struct dos_mbr))
+ return 1; /* All zeros struct dos_mbr is editable. */
+
nprt = 0;
for (i = 0; i < NDOSPART; i++) {
bs = mbr->mbr_prt[i].prt_bs;
diff --git a/sbin/fdisk/mbr.h b/sbin/fdisk/mbr.h
index 0c56a3db4e0..3aee1dabdb5 100644
--- a/sbin/fdisk/mbr.h
+++ b/sbin/fdisk/mbr.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbr.h,v 1.43 2022/07/25 17:45:16 krw Exp $ */
+/* $OpenBSD: mbr.h,v 1.44 2022/07/26 14:30:37 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -22,6 +22,7 @@ struct mbr {
unsigned char mbr_code[DOSPARTOFF];
struct prt mbr_prt[NDOSPART];
uint16_t mbr_signature;
+ unsigned int mbr_dmbrzeros;
};
extern struct dos_mbr default_dmbr;