diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2021-06-22 14:01:59 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2021-06-22 14:01:59 +0000 |
commit | cf94924a1e151d44f1d9da293ffeea3724f6902d (patch) | |
tree | 63c3dff45718cd7934a12845c2f4ca5e9d7e9c4c /sbin | |
parent | 58639d1ec9e15147eb7157c53893506e1fc8cb23 (diff) |
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@.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/fdisk/fdisk.8 | 19 | ||||
-rw-r--r-- | 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 <sys/types.h> +#include <sys/param.h> /* DEV_BSIZE */ #include <sys/disklabel.h> #include <err.h> @@ -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) |