diff options
-rw-r--r-- | sbin/fdisk/fdisk.8 | 21 | ||||
-rw-r--r-- | sbin/fdisk/fdisk.c | 14 | ||||
-rw-r--r-- | sbin/fdisk/gpt.c | 8 | ||||
-rw-r--r-- | sbin/fdisk/mbr.c | 19 | ||||
-rw-r--r-- | sbin/fdisk/misc.c | 52 | ||||
-rw-r--r-- | sbin/fdisk/misc.h | 3 |
6 files changed, 88 insertions, 29 deletions
diff --git a/sbin/fdisk/fdisk.8 b/sbin/fdisk/fdisk.8 index fb083588556..9e4a88aed0d 100644 --- a/sbin/fdisk/fdisk.8 +++ b/sbin/fdisk/fdisk.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: fdisk.8,v 1.97 2021/06/16 15:40:47 krw Exp $ +.\" $OpenBSD: fdisk.8,v 1.98 2021/06/20 18:44:19 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 16 2021 $ +.Dd $Mdocdate: June 20 2021 $ .Dt FDISK 8 .Os .Sh NAME @@ -25,7 +25,7 @@ .Nm fdisk .Op Fl egvy .Op Fl i | u -.Op Fl b Ar blocks +.Op Fl b Ar blocks Op @ Ns Ar offset Ns Op : Ns Ar type .Oo .Fl c Ar cylinders .Fl h Ar heads @@ -58,11 +58,20 @@ at install time. .Pp The options are as follows: .Bl -tag -width Ds -.It Fl b Ar blocks -A special boot partition of the specified size will be written to disk -on architectures that need one. +.It Fl b Ar blocks 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. +The +.Ox +partition will follow the boot partition and use the remaining space on the disk. +.Pp Only valid with .Fl i . +If +.Fl g +is specified 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. .It Xo .Fl c Ar cylinders .Fl h Ar heads diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c index 94d449ca6f8..27d9cc1e933 100644 --- a/sbin/fdisk/fdisk.c +++ b/sbin/fdisk/fdisk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdisk.c,v 1.108 2021/06/14 17:34:06 krw Exp $ */ +/* $OpenBSD: fdisk.c,v 1.109 2021/06/20 18:44:19 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -41,8 +41,9 @@ static unsigned char builtin_mbr[] = { #include "mbrcode.h" }; -uint32_t b_arg; -int y_flag; +uint32_t b_sectors, b_offset; +uint8_t b_type; +int y_flag; static void usage(void) @@ -127,10 +128,7 @@ main(int argc, char *argv[]) g_flag = 1; break; case 'b': - b_arg = strtonum(optarg, 64, UINT32_MAX, &errstr); - if (errstr) - errx(1, "Block argument %s [64..%u].", errstr, - UINT32_MAX); + parse_b(optarg, &b_sectors, &b_offset, &b_type); break; case 'l': l_arg = strtonum(optarg, 64, UINT32_MAX, &errstr); @@ -157,7 +155,7 @@ main(int argc, char *argv[]) /* Argument checking */ if (argc != 1 || (i_flag && u_flag) || - (i_flag == 0 && (b_arg || g_flag)) || + (i_flag == 0 && (b_sectors || g_flag)) || ((c_arg | h_arg | s_arg) && !(c_arg && h_arg && s_arg)) || ((c_arg | h_arg | s_arg) && l_arg)) usage(); diff --git a/sbin/fdisk/gpt.c b/sbin/fdisk/gpt.c index b54e27f7d08..79c9df07ae5 100644 --- a/sbin/fdisk/gpt.c +++ b/sbin/fdisk/gpt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gpt.c,v 1.30 2021/06/16 15:40:47 krw Exp $ */ +/* $OpenBSD: gpt.c,v 1.31 2021/06/20 18:44:19 krw Exp $ */ /* * Copyright (c) 2015 Markus Muller <mmu@grummel.net> * Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org> @@ -416,7 +416,7 @@ init_gh(void) int init_gp(void) { - extern uint32_t b_arg; + extern uint32_t b_sectors; const uint8_t gpt_uuid_efi_system[] = GPT_UUID_EFI_SYSTEM; const uint8_t gpt_uuid_openbsd[] = GPT_UUID_OPENBSD; struct gpt_partition oldgp[NGPTPARTITIONS]; @@ -426,9 +426,9 @@ init_gp(void) memset(&gp, 0, sizeof(gp)); rslt = 0; - if (b_arg > 0) { + if (b_sectors > 0) { rslt = add_partition(gpt_uuid_efi_system, "EFI System Area", - b_arg); + b_sectors); } if (rslt == 0) rslt = add_partition(gpt_uuid_openbsd, "OpenBSD Area", 0); diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c index 27fe2e4eff1..9a0ec6cd55d 100644 --- a/sbin/fdisk/mbr.c +++ b/sbin/fdisk/mbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.c,v 1.76 2021/06/16 15:40:47 krw Exp $ */ +/* $OpenBSD: mbr.c,v 1.77 2021/06/20 18:44:19 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -77,7 +77,8 @@ MBR_init_GPT(struct mbr *mbr) void MBR_init(struct mbr *mbr) { - extern uint32_t b_arg; + extern uint32_t b_sectors, b_offset; + extern uint8_t b_type; uint64_t adj; daddr_t daddr; @@ -132,14 +133,14 @@ MBR_init(struct mbr *mbr) } /* Fix up start/length fields */ PRT_fix_BN(&mbr->part[3], 3); -#endif -#if defined(__i386__) || defined(__amd64__) - if (b_arg > 0) { - /* Add an EFI system partition on i386/amd64. */ - mbr->part[0].id = DOSPTYP_EFISYS; - mbr->part[0].bs = 64; - mbr->part[0].ns = b_arg; +#else + if (b_sectors > 0) { + mbr->part[0].flag = DOSACTIVE; + mbr->part[0].id = b_type; + mbr->part[0].bs = b_offset; + mbr->part[0].ns = b_sectors; PRT_fix_CHS(&mbr->part[0]); + mbr->part[3].flag = 0; mbr->part[3].ns += mbr->part[3].bs; mbr->part[3].bs = mbr->part[0].bs + mbr->part[0].ns; mbr->part[3].ns -= mbr->part[3].bs; diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c index 2571b87bd7d..8885d4659e5 100644 --- a/sbin/fdisk/misc.c +++ b/sbin/fdisk/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.67 2021/06/13 14:14:56 krw Exp $ */ +/* $OpenBSD: misc.c,v 1.68 2021/06/20 18:44:19 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -22,6 +22,7 @@ #include <ctype.h> #include <err.h> #include <errno.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -401,3 +402,52 @@ string_to_utf16le(const char *ch) return (utf); } + +void +parse_b(const char *arg, uint32_t *blocks, uint32_t *offset, uint8_t *type) +{ + const char *errstr; + char *poffset, *ptype; + uint32_t blockcount, blockoffset; + uint8_t partitiontype; + + blockoffset = 64; + partitiontype = DOSPTYP_EFISYS; + ptype = NULL; + + /* First number: # of sectors in boot partition. */ + poffset = strchr(arg, '@'); + if (poffset != NULL) + *poffset++ = '\0'; + if (poffset != NULL) { + ptype = strchr(poffset, ':'); + if (ptype != NULL) + *ptype++ = '\0'; + } + + blockcount = strtonum(arg, 64, UINT32_MAX, &errstr); + if (errstr) + errx(1, "Block argument %s [64..%u].", + errstr, UINT32_MAX); + + if (poffset == NULL) + goto done; + + blockoffset = strtonum(poffset, 64, UINT32_MAX, &errstr); + if (errstr) + errx(1, "Block offset argument %s " + "[64..%u].", errstr, UINT32_MAX); + + if (ptype == NULL) + goto done; + + if (strlen(ptype) != 2 || !(isxdigit(*ptype) && isxdigit(*(ptype + 1)))) + errx(1, "Block type is not 2 digit hex value"); + + partitiontype = strtol(ptype, NULL, 16); + + done: + *blocks = blockcount; + *offset = blockoffset; + *type = partitiontype; +} diff --git a/sbin/fdisk/misc.h b/sbin/fdisk/misc.h index 3f3713fbf62..8a2c15be934 100644 --- a/sbin/fdisk/misc.h +++ b/sbin/fdisk/misc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.h,v 1.35 2021/06/10 15:21:19 krw Exp $ */ +/* $OpenBSD: misc.h,v 1.36 2021/06/20 18:44:19 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -39,5 +39,6 @@ uint64_t getuint64(char *, uint64_t, uint64_t, uint64_t); uint32_t crc32(const u_char *, const uint32_t); char *utf16le_to_string(const uint16_t *); uint16_t *string_to_utf16le(const char *); +void parse_b(const char *, uint32_t *, uint32_t *, uint8_t *); #endif /* _MISC_H */ |