summaryrefslogtreecommitdiff
path: root/sbin/fdisk/fdisk.c
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2021-08-07 17:48:32 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2021-08-07 17:48:32 +0000
commit8d70cdc1abc78de8ddb66d7561652759482b54d2 (patch)
tree46df617e61501a44136de8c128f0a3f073dce1e6 /sbin/fdisk/fdisk.c
parentfe3cd0c74999a830fb18cbf7ffc3923ab4467ec7 (diff)
style(9) says sort getopt() options and the following switch {}
cases. Make it so. In passing nuke a single use 'error' variable and move an *errstr declaration nearer to its friends. No intentional functional change.
Diffstat (limited to 'sbin/fdisk/fdisk.c')
-rw-r--r--sbin/fdisk/fdisk.c58
1 files changed, 28 insertions, 30 deletions
diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c
index aa1c4f4ad01..816f8f49857 100644
--- a/sbin/fdisk/fdisk.c
+++ b/sbin/fdisk/fdisk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdisk.c,v 1.132 2021/08/07 13:33:12 krw Exp $ */
+/* $OpenBSD: fdisk.c,v 1.133 2021/08/07 17:48:31 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -72,26 +72,26 @@ main(int argc, char *argv[])
#else
const char *mbrfile = NULL;
#endif
- int ch, error;
+ const char *errstr;
+ int ch;
int e_flag = 0, init = 0;
int verbosity = TERSE;
int oflags = O_RDONLY;
- while ((ch = getopt(argc, argv, "Aieguvf:c:h:s:l:b:y")) != -1) {
- const char *errstr;
-
+ while ((ch = getopt(argc, argv, "Ab:c:ef:gh:il:s:uvy")) != -1) {
switch(ch) {
case 'A':
init = INIT_GPTPARTITIONS;
break;
- case 'i':
- init = INIT_MBR;
- break;
- case 'g':
- init = INIT_GPT;
+ case 'b':
+ parse_bootprt(optarg);
break;
- case 'u':
- init = INIT_MBRBOOTCODE;
+ case 'c':
+ disk.dk_cylinders = strtonum(optarg, 1, 262144, &errstr);
+ if (errstr)
+ errx(1, "Cylinder argument %s [1..262144].",
+ errstr);
+ disk.dk_size = 0;
break;
case 'e':
e_flag = 1;
@@ -99,12 +99,8 @@ main(int argc, char *argv[])
case 'f':
mbrfile = optarg;
break;
- case 'c':
- disk.dk_cylinders = strtonum(optarg, 1, 262144, &errstr);
- if (errstr)
- errx(1, "Cylinder argument %s [1..262144].",
- errstr);
- disk.dk_size = 0;
+ case 'g':
+ init = INIT_GPT;
break;
case 'h':
disk.dk_heads = strtonum(optarg, 1, 256, &errstr);
@@ -112,14 +108,8 @@ main(int argc, char *argv[])
errx(1, "Head argument %s [1..256].", errstr);
disk.dk_size = 0;
break;
- case 's':
- disk.dk_sectors = strtonum(optarg, 1, 63, &errstr);
- if (errstr)
- errx(1, "Sector argument %s [1..63].", errstr);
- disk.dk_size = 0;
- break;
- case 'b':
- parse_bootprt(optarg);
+ case 'i':
+ init = INIT_MBR;
break;
case 'l':
disk.dk_size = strtonum(optarg, BLOCKALIGNMENT, UINT32_MAX, &errstr);
@@ -128,12 +118,21 @@ main(int argc, char *argv[])
BLOCKALIGNMENT, UINT32_MAX);
disk.dk_cylinders = disk.dk_heads = disk.dk_sectors = 0;
break;
- case 'y':
- y_flag = 1;
+ case 's':
+ disk.dk_sectors = strtonum(optarg, 1, 63, &errstr);
+ if (errstr)
+ errx(1, "Sector argument %s [1..63].", errstr);
+ disk.dk_size = 0;
+ break;
+ case 'u':
+ init = INIT_MBRBOOTCODE;
break;
case 'v':
verbosity = VERBOSE;
break;
+ case 'y':
+ y_flag = 1;
+ break;
default:
usage();
}
@@ -185,8 +184,7 @@ main(int argc, char *argv[])
MBR_write(&mbr);
break;
case INIT_MBRBOOTCODE:
- error = MBR_read(0, 0, &mbr);
- if (error)
+ if (MBR_read(0, 0, &mbr))
errx(1, "Can't read MBR!");
memcpy(mbr.mbr_code, default_dmbr.dmbr_boot,
sizeof(mbr.mbr_code));