From: krw Date: Fri, 25 Jun 2021 19:24:53 +0000 (+0000) Subject: Replace instances of the magic number '64' with a nice #define X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=893a24550ad4ecb456969a768fd26f434cc314bf;p=openbsd Replace instances of the magic number '64' with a nice #define BLOCKALIGNMENT. This will make it more obvious where this 512-byte block count could/should be converted to a disk sector count. No functional change. --- diff --git a/sbin/fdisk/disk.h b/sbin/fdisk/disk.h index 4f549e4bd3b..416aa6af8bb 100644 --- a/sbin/fdisk/disk.h +++ b/sbin/fdisk/disk.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disk.h,v 1.22 2021/05/07 22:15:13 krw Exp $ */ +/* $OpenBSD: disk.h,v 1.23 2021/06/25 19:24:53 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -28,6 +28,9 @@ struct disk { uint32_t size; }; +/* Align partition starts/sizes on 32K-byte boundaries. */ +#define BLOCKALIGNMENT 64 + void DISK_open(int); int DISK_printgeometry(char *); char *DISK_readsector(off_t); diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c index c76ae1f366a..b1f3870a964 100644 --- a/sbin/fdisk/fdisk.c +++ b/sbin/fdisk/fdisk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdisk.c,v 1.112 2021/06/23 13:07:13 krw Exp $ */ +/* $OpenBSD: fdisk.c,v 1.113 2021/06/25 19:24:53 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -124,13 +124,13 @@ main(int argc, char *argv[]) parse_b(optarg, &b_sectors, &b_offset, &b_type); break; case 'l': - l_arg = strtonum(optarg, 64, UINT32_MAX, &errstr); + l_arg = strtonum(optarg, BLOCKALIGNMENT, UINT32_MAX, &errstr); if (errstr) - errx(1, "Block argument %s [64..%u].", errstr, - UINT32_MAX); - disk.cylinders = l_arg / 64; + errx(1, "Block argument %s [%u..%u].", errstr, + BLOCKALIGNMENT, UINT32_MAX); + disk.cylinders = l_arg / BLOCKALIGNMENT; disk.heads = 1; - disk.sectors = 64; + disk.sectors = BLOCKALIGNMENT; disk.size = l_arg; break; case 'y': @@ -169,9 +169,9 @@ main(int argc, char *argv[]) if (l_arg % bps != 0) l_arg += bps - l_arg % bps; l_arg = DL_BLKTOSEC(&dl, l_arg); - disk.cylinders = l_arg / 64; + disk.cylinders = l_arg / BLOCKALIGNMENT; disk.heads = 1; - disk.sectors = 64; + disk.sectors = BLOCKALIGNMENT; disk.size = l_arg; } diff --git a/sbin/fdisk/gpt.c b/sbin/fdisk/gpt.c index a446ef437e6..83e5201f58d 100644 --- a/sbin/fdisk/gpt.c +++ b/sbin/fdisk/gpt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gpt.c,v 1.32 2021/06/21 02:05:30 krw Exp $ */ +/* $OpenBSD: gpt.c,v 1.33 2021/06/25 19:24:53 krw Exp $ */ /* * Copyright (c) 2015 Markus Muller * Copyright (c) 2015 Kenneth R Westerback @@ -334,8 +334,8 @@ add_partition(const uint8_t *beuuid, const char *name, uint64_t sectors) if (rslt == -1) goto done; - if (start % 64) - start += (64 - start % 64); + if (start % BLOCKALIGNMENT) + start += (BLOCKALIGNMENT - start % BLOCKALIGNMENT); if (start >= end) goto done; @@ -386,9 +386,8 @@ init_gh(void) needed = sizeof(gp) / secsize + 2; - /* Start usable LBA area on 64 sector boundary. */ - if (needed % 64) - needed += (64 - (needed % 64)); + if (needed % BLOCKALIGNMENT) + needed += (needed - (needed % BLOCKALIGNMENT)); gh.gh_sig = htole64(GPTSIGNATURE); gh.gh_rev = htole32(GPTREVISION); diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c index 8885d4659e5..56a80686e5c 100644 --- a/sbin/fdisk/misc.c +++ b/sbin/fdisk/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.68 2021/06/20 18:44:19 krw Exp $ */ +/* $OpenBSD: misc.c,v 1.69 2021/06/25 19:24:53 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -411,11 +411,11 @@ parse_b(const char *arg, uint32_t *blocks, uint32_t *offset, uint8_t *type) uint32_t blockcount, blockoffset; uint8_t partitiontype; - blockoffset = 64; + blockoffset = BLOCKALIGNMENT; partitiontype = DOSPTYP_EFISYS; ptype = NULL; - /* First number: # of sectors in boot partition. */ + /* First number: # of 512-byte blocks in boot partition. */ poffset = strchr(arg, '@'); if (poffset != NULL) *poffset++ = '\0'; @@ -425,18 +425,19 @@ parse_b(const char *arg, uint32_t *blocks, uint32_t *offset, uint8_t *type) *ptype++ = '\0'; } - blockcount = strtonum(arg, 64, UINT32_MAX, &errstr); + blockcount = strtonum(arg, BLOCKALIGNMENT, UINT32_MAX, &errstr); if (errstr) - errx(1, "Block argument %s [64..%u].", - errstr, UINT32_MAX); + errx(1, "Block argument %s [%u..%u].", errstr, BLOCKALIGNMENT, + UINT32_MAX); if (poffset == NULL) goto done; - blockoffset = strtonum(poffset, 64, UINT32_MAX, &errstr); + /* Second number: # of 512-byte blocks to offset partition start. */ + blockoffset = strtonum(poffset, BLOCKALIGNMENT, UINT32_MAX, &errstr); if (errstr) - errx(1, "Block offset argument %s " - "[64..%u].", errstr, UINT32_MAX); + errx(1, "Block offset argument %s [%u..%u].", errstr, + BLOCKALIGNMENT, UINT32_MAX); if (ptype == NULL) goto done;