From 353d349312a36f8bb827ee6a727784a17394caa2 Mon Sep 17 00:00:00 2001 From: krw Date: Tue, 22 Jun 2021 14:01:58 +0000 Subject: [PATCH] The values for blocks and offset in -b should be treated as 512-byte block counts. Tweak man page accordingly. Requested by deraadt@ and kettenis@. --- sbin/fdisk/fdisk.8 | 19 +++++++++++++------ sbin/fdisk/fdisk.c | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/sbin/fdisk/fdisk.8 b/sbin/fdisk/fdisk.8 index 94afcd3e923..fe711970480 100644 --- a/sbin/fdisk/fdisk.8 +++ b/sbin/fdisk/fdisk.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: fdisk.8,v 1.101 2021/06/21 02:05:30 krw Exp $ +.\" $OpenBSD: fdisk.8,v 1.102 2021/06/22 14:01:58 krw Exp $ .\" .\" .\" Copyright (c) 1997 Tobias Weingartner @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 21 2021 $ +.Dd $Mdocdate: June 22 2021 $ .Dt FDISK 8 .Os .Sh NAME @@ -69,10 +69,18 @@ all existing partitions except the boot partitions and .Sq HiFive BBL . .It Fl b Ar blocks Ns Op @ Ns Ar offset Ns Op : Ns Ar type -A special boot partition of the specified size, offset and type will be written to disk. +Configures a special boot partition of the specified number of blocks, offset +and type. +.Ar offset +defaults to the first available block, and +.Ar type +defaults to +.Sq EF . +.Pp The .Ox -partition will follow the boot partition and use the remaining space on the disk. +partition will follow the boot partition and use the remaining +available space. .Pp Can only be used when initializing a disk with .Fl i Op Fl g @@ -81,8 +89,7 @@ or If a GPT is being initialized only the .Ar blocks -value will be used, with the boot partition being placed at the first available LBA and -given the type EFI SYS. +value is used. .It Xo .Fl c Ar cylinders .Fl h Ar heads diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c index 12c042f18a5..d6fee5a5976 100644 --- a/sbin/fdisk/fdisk.c +++ b/sbin/fdisk/fdisk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdisk.c,v 1.110 2021/06/21 02:05:30 krw Exp $ */ +/* $OpenBSD: fdisk.c,v 1.111 2021/06/22 14:01:58 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -16,7 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include +#include /* DEV_BSIZE */ #include #include @@ -62,6 +62,7 @@ main(int argc, char *argv[]) { ssize_t len; int ch, fd, efi, error; + unsigned int bps; int e_flag = 0, g_flag = 0, i_flag = 0, u_flag = 0; int verbosity = TERSE; int c_arg = 0, h_arg = 0, s_arg = 0; @@ -155,6 +156,15 @@ main(int argc, char *argv[]) disk.name = argv[0]; DISK_open(A_flag || i_flag || u_flag || e_flag); + bps = DL_BLKSPERSEC(&dl); + if (b_sectors > 0) { + if (b_sectors % bps != 0) + b_sectors += bps - b_sectors % bps; + if (b_offset % bps != 0) + b_offset += bps - b_offset % bps; + b_sectors = DL_BLKTOSEC(&dl, b_sectors); + b_offset = DL_BLKTOSEC(&dl, b_offset); + } /* "proc exec" for man page display */ if (pledge("stdio rpath wpath disklabel proc exec", NULL) == -1) -- 2.20.1