summaryrefslogtreecommitdiff
path: root/sbin/fdisk
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2021-10-29 18:38:20 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2021-10-29 18:38:20 +0000
commit388a767ec2a1bd1f067c77815ff306a2b3d83214 (patch)
treedc8fdfc2537d3c2ac5c66aed9f0746642734e6aa /sbin/fdisk
parentbda7220cf231a28b8aa34fd21ddc31996b348b6e (diff)
Tweak code to make it clear that MBR_init() uses just the boot code and
partition 0 information from the default MBR. loongson and macppc provide partition 0 information but no boot code. amd64, i386, landisk provide boot code but no partition 0 information. Other arch's get by w/o a default MBR (a.k.a. /usr/mdec/mbr). No functional change.
Diffstat (limited to 'sbin/fdisk')
-rw-r--r--sbin/fdisk/mbr.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c
index b14863d6e01..3793e6a4d75 100644
--- a/sbin/fdisk/mbr.c
+++ b/sbin/fdisk/mbr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbr.c,v 1.101 2021/09/26 13:13:16 krw Exp $ */
+/* $OpenBSD: mbr.c,v 1.102 2021/10/29 18:38:19 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -41,6 +41,7 @@ void dos_mbr_to_mbr(const struct dos_mbr *, const uint64_t,
void
MBR_init(struct mbr *mbr)
{
+ struct dos_partition dp;
uint64_t adj;
daddr_t daddr;
@@ -56,19 +57,13 @@ MBR_init(struct mbr *mbr)
return;
}
- dos_mbr_to_mbr(&default_dmbr, 0, 0, mbr);
+ memset(mbr, 0, sizeof(*mbr));
+ memcpy(mbr->mbr_code, default_dmbr.dmbr_boot, sizeof(mbr->mbr_code));
+ memcpy(&dp, &default_dmbr.dmbr_parts[0], sizeof(dp));
+ PRT_parse(&dp, 0, 0, &mbr->mbr_prt[0]);
- /*
- * XXX Do *NOT* zap all MBR parts! Some archs still read default mbr
- * from disk! Just mark them inactive until -b goodness spreads
- * further.
- */
-
- mbr->mbr_prt[0].prt_flag = 0;
- mbr->mbr_prt[1].prt_flag = 0;
- mbr->mbr_prt[2].prt_flag = 0;
-
- mbr->mbr_prt[3].prt_flag = DOSACTIVE;
+ if (mbr->mbr_prt[0].prt_flag != DOSACTIVE)
+ mbr->mbr_prt[3].prt_flag = DOSACTIVE;
mbr->mbr_signature = DOSMBR_SIGNATURE;
/* Use whole disk. Reserve first track, or first cyl, if possible. */