diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2021-11-14 17:28:30 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2021-11-14 17:28:30 +0000 |
commit | a92a5b3c53440722e9a89c6d99b83599768f80f0 (patch) | |
tree | a4c270de52bb08ce51fc99b54a4fd7df01294121 | |
parent | a7af4542d4c7bb5c0dfb4fec7b5201cc237989f9 (diff) |
Calculate initial OpenBSD partition start/size using LBA values
instead of CHS values. Shorter, easier to follow.
No intentional functional change.
-rw-r--r-- | sbin/fdisk/mbr.c | 52 |
1 files changed, 17 insertions, 35 deletions
diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c index c04a7c91188..ae3b4c060d8 100644 --- a/sbin/fdisk/mbr.c +++ b/sbin/fdisk/mbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.c,v 1.106 2021/11/10 13:01:08 krw Exp $ */ +/* $OpenBSD: mbr.c,v 1.107 2021/11/14 17:28:29 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -45,6 +45,7 @@ MBR_init(struct mbr *mbr) struct prt bootprt, obsdprt; uint64_t adj; daddr_t daddr; + uint32_t spc; memset(&gmbr, 0, sizeof(gmbr)); memset(&gh, 0, sizeof(gh)); @@ -67,50 +68,26 @@ MBR_init(struct mbr *mbr) if (bootprt.prt_flag != DOSACTIVE) obsdprt.prt_flag = DOSACTIVE; - /* Use whole disk. Reserve first track, or first cyl, if possible. */ + /* Reserve first track, or first cyl, if possible. */ obsdprt.prt_id = DOSPTYP_OPENBSD; - if (disk.dk_heads > 1) - obsdprt.prt_shead = 1; + if (disk.dk_heads > 1 || disk.dk_cylinders > 1) + obsdprt.prt_bs = disk.dk_sectors; else - obsdprt.prt_shead = 0; - if (disk.dk_heads < 2 && disk.dk_cylinders > 1) - obsdprt.prt_scyl = 1; - else - obsdprt.prt_scyl = 0; - obsdprt.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; - - /* Fix up start/length fields */ - PRT_fix_BN(&obsdprt, 3); + obsdprt.prt_bs = 1; #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 */ obsdprt.prt_flag = 0; - 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); - if ((obsdprt.prt_shead != 1) || (obsdprt.prt_ssect != 1)) { - /* align the partition on a cylinder boundary */ - obsdprt.prt_shead = 0; - obsdprt.prt_ssect = 1; - obsdprt.prt_scyl += 1; - } - /* Fix up start/length fields */ - PRT_fix_BN(&obsdprt, 3); + if (bootprt.prt_ns > 0) + obsdprt.prt_bs = bootprt.prt_bs + bootprt.prt_ns; + spc = disk.dk_heads * disk.dk_sectors; + if (obsdprt.prt_bs % spc != 0) + obsdprt.prt_bs += spc - (obsdprt.prt_bs % spc); #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); } #endif @@ -120,7 +97,12 @@ MBR_init(struct mbr *mbr) daddr *= 2; adj = DL_BLKTOSEC(&dl, daddr) - obsdprt.prt_bs; obsdprt.prt_bs += adj; - obsdprt.prt_ns -= adj; + + /* Use all space up to end of last complete cylinder. */ + obsdprt.prt_ns = disk.dk_cylinders * disk.dk_heads * disk.dk_sectors; + obsdprt.prt_ns -= obsdprt.prt_bs; + + PRT_fix_CHS(&bootprt); PRT_fix_CHS(&obsdprt); memset(mbr, 0, sizeof(*mbr)); |