From 3220ebed14aaea7b477b113f72b9978d855c8d59 Mon Sep 17 00:00:00 2001 From: krw Date: Sat, 11 Dec 2021 20:09:28 +0000 Subject: [PATCH] Start the default OpenBSD partition either immediately following any boot partition specified via '-b' or /usr/mdec/mbr; at the power of 2 block after the first track; or immediately following the MBR if there is only one track. Mark any non-EFISYS boot partition created by -b as DOSACTIVE. Suggested by kettenis@, better than a separate new option. Brings -b behaviour into line with many uses of -e to create boot partitions, allowing for the eventual elimination of said -e uses in the creation of the various boot media and in the install scripts. --- sbin/fdisk/fdisk.c | 4 +++- sbin/fdisk/mbr.c | 26 +++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c index 854966a9233..4c50e1fbdf0 100644 --- a/sbin/fdisk/fdisk.c +++ b/sbin/fdisk/fdisk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdisk.c,v 1.140 2021/10/19 19:38:10 krw Exp $ */ +/* $OpenBSD: fdisk.c,v 1.141 2021/12/11 20:09:28 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -79,6 +79,8 @@ main(int argc, char *argv[]) break; case 'b': parse_bootprt(optarg); + if (disk.dk_bootprt.prt_id != DOSPTYP_EFISYS) + disk.dk_bootprt.prt_flag = DOSACTIVE; break; case 'c': disk.dk_cylinders = strtonum(optarg, 1, 262144, &errstr); diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c index d25b0897bb7..ad11fa130c4 100644 --- a/sbin/fdisk/mbr.c +++ b/sbin/fdisk/mbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.c,v 1.113 2021/12/07 14:58:32 krw Exp $ */ +/* $OpenBSD: mbr.c,v 1.114 2021/12/11 20:09:28 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -67,18 +67,22 @@ MBR_init(struct mbr *mbr) PRT_parse(&dp, 0, 0, &bootprt); } - if (bootprt.prt_ns > 0) + if (bootprt.prt_ns > 0) { + /* Start OpenBSD partition immediately after bootprt. */ obsdprt.prt_bs = bootprt.prt_bs + bootprt.prt_ns; - else if (disk.dk_heads > 1 || disk.dk_cylinders > 1) - obsdprt.prt_bs = disk.dk_sectors; - else + } else if (disk.dk_heads > 1 || disk.dk_cylinders > 1) { + /* + * Start OpenBSD partition on power of 2 block number + * after the first track. + */ + daddr = 1; + while (daddr < DL_SECTOBLK(&dl, disk.dk_sectors)) + daddr *= 2; + obsdprt.prt_bs = DL_BLKTOSEC(&dl, daddr); + } else { + /* Start OpenBSD partition immediately after MBR. */ obsdprt.prt_bs = 1; - - /* Start OpenBSD MBR partition on a power of 2 block number. */ - daddr = 1; - while (daddr < DL_SECTOBLK(&dl, obsdprt.prt_bs)) - daddr *= 2; - obsdprt.prt_bs = DL_BLKTOSEC(&dl, daddr); + } if (obsdprt.prt_bs >= disk.dk_size) { memset(&obsdprt, 0, sizeof(obsdprt)); -- 2.20.1