From 388a767ec2a1bd1f067c77815ff306a2b3d83214 Mon Sep 17 00:00:00 2001 From: Kenneth R Westerback Date: Fri, 29 Oct 2021 18:38:20 +0000 Subject: 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. --- sbin/fdisk/mbr.c | 21 ++++++++------------- 1 file 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. */ -- cgit v1.2.3