From a5d0c033cb149195b5769eade257b7d63183af46 Mon Sep 17 00:00:00 2001 From: deraadt Date: Tue, 9 Nov 2021 01:50:11 +0000 Subject: [PATCH] no, that breaks architectures --- sbin/fdisk/mbr.c | 85 ++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 46 deletions(-) diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c index f96b34d9348..5a393b3e15b 100644 --- a/sbin/fdisk/mbr.c +++ b/sbin/fdisk/mbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.c,v 1.103 2021/11/08 22:47:47 krw Exp $ */ +/* $OpenBSD: mbr.c,v 1.104 2021/11/09 01:50:11 deraadt Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -42,7 +42,6 @@ void MBR_init(struct mbr *mbr) { struct dos_partition dp; - struct prt bootprt, obsdprt; uint64_t adj; daddr_t daddr; @@ -58,76 +57,70 @@ MBR_init(struct mbr *mbr) return; } - memset(&obsdprt, 0, sizeof(obsdprt)); - memset(&bootprt, 0, sizeof(bootprt)); - + 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, &bootprt); + PRT_parse(&dp, 0, 0, &mbr->mbr_prt[0]); - if (bootprt.prt_flag != DOSACTIVE) - obsdprt.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. */ - obsdprt.prt_id = DOSPTYP_OPENBSD; + mbr->mbr_prt[3].prt_id = DOSPTYP_OPENBSD; if (disk.dk_heads > 1) - obsdprt.prt_shead = 1; + mbr->mbr_prt[3].prt_shead = 1; else - obsdprt.prt_shead = 0; + mbr->mbr_prt[3].prt_shead = 0; if (disk.dk_heads < 2 && disk.dk_cylinders > 1) - obsdprt.prt_scyl = 1; + mbr->mbr_prt[3].prt_scyl = 1; else - obsdprt.prt_scyl = 0; - obsdprt.prt_ssect = 1; + mbr->mbr_prt[3].prt_scyl = 0; + mbr->mbr_prt[3].prt_ssect = 1; /* Go right to the end */ - obsdprt.prt_ecyl = disk.dk_cylinders - 1; - obsdprt.prt_ehead = disk.dk_heads - 1; - obsdprt.prt_esect = disk.dk_sectors; + mbr->mbr_prt[3].prt_ecyl = disk.dk_cylinders - 1; + mbr->mbr_prt[3].prt_ehead = disk.dk_heads - 1; + mbr->mbr_prt[3].prt_esect = disk.dk_sectors; /* Fix up start/length fields */ - PRT_fix_BN(&obsdprt, 3); + PRT_fix_BN(&mbr->mbr_prt[3], 3); #if defined(__powerpc__) || defined(__mips__) /* Now fix up for the MS-DOS boot partition on PowerPC/MIPS. */ - bootprt.prt_flag = DOSACTIVE; /* Boot from dos part */ - bootprt.prt_flag = 0; - obsdprt.prt_ns += obsdprt.prt_bs; - obsdprt.prt_bs = bootprt.prt_bs + bootptr.prt_ns; - obsdprt.prt_ns -= obsdprt.prt_bs; - PRT_fix_CHS(&obsdprt); - if ((obsdprt.prt_shead != 1) || (obsdprt.prt_ssect != 1)) { + mbr->mbr_prt[0].prt_flag = DOSACTIVE; /* Boot from dos part */ + mbr->mbr_prt[3].prt_flag = 0; + mbr->mbr_prt[3].prt_ns += mbr->mbr_prt[3].prt_bs; + mbr->mbr_prt[3].prt_bs = mbr->mbr_prt[0].prt_bs + mbr->mbr_prt[0].prt_ns; + mbr->mbr_prt[3].prt_ns -= mbr->mbr_prt[3].prt_bs; + PRT_fix_CHS(&mbr->mbr_prt[3]); + if ((mbr->mbr_prt[3].prt_shead != 1) || (mbr->mbr_prt[3].prt_ssect != 1)) { /* align the partition on a cylinder boundary */ - obsdprt.prt_shead = 0; - obsdprt.prt_ssect = 1; - obsdprt.prt_scyl += 1; + mbr->mbr_prt[3].prt_shead = 0; + mbr->mbr_prt[3].prt_ssect = 1; + mbr->mbr_prt[3].prt_scyl += 1; } /* Fix up start/length fields */ - PRT_fix_BN(&obsdprt, 3); + PRT_fix_BN(&mbr->mbr_prt[3], 3); #else if (disk.dk_bootprt.prt_ns > 0) { - bootprt = disk.dk_bootprt; - PRT_fix_CHS(&bootprt); - obsdprt.prt_ns += obsdprt.prt_bs; - obsdprt.prt_bs = bootprt.prt_bs + bootprt.prt_ns; - obsdprt.prt_ns -= obsdprt.prt_bs; - PRT_fix_CHS(&obsdprt); + mbr->mbr_prt[0] = disk.dk_bootprt; + PRT_fix_CHS(&mbr->mbr_prt[0]); + mbr->mbr_prt[3].prt_ns += mbr->mbr_prt[3].prt_bs; + mbr->mbr_prt[3].prt_bs = mbr->mbr_prt[0].prt_bs + mbr->mbr_prt[0].prt_ns; + mbr->mbr_prt[3].prt_ns -= mbr->mbr_prt[3].prt_bs; + PRT_fix_CHS(&mbr->mbr_prt[3]); } #endif /* Start OpenBSD MBR partition on a power of 2 block number. */ daddr = 1; - while (daddr < DL_SECTOBLK(&dl, obsdprt.prt_bs)) + while (daddr < DL_SECTOBLK(&dl, mbr->mbr_prt[3].prt_bs)) daddr *= 2; - adj = DL_BLKTOSEC(&dl, daddr) - obsdprt.prt_bs; - obsdprt.prt_bs += adj; - obsdprt.prt_ns -= adj; - PRT_fix_CHS(&obsdprt); - - memset(mbr, 0, sizeof(*mbr)); - memcpy(mbr->mbr_code, default_dmbr.dmbr_boot, sizeof(mbr->mbr_code)); - mbr->mbr_prt[0] = bootprt; - mbr->mbr_prt[3] = obsdprt; - mbr->mbr_signature = DOSMBR_SIGNATURE; + adj = DL_BLKTOSEC(&dl, daddr) - mbr->mbr_prt[3].prt_bs; + mbr->mbr_prt[3].prt_bs += adj; + mbr->mbr_prt[3].prt_ns -= adj; + PRT_fix_CHS(&mbr->mbr_prt[3]); } void -- 2.20.1