diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2014-03-17 16:40:01 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2014-03-17 16:40:01 +0000 |
commit | be93d6a9c125d07dfc2cc9f217b29a90d316ae6f (patch) | |
tree | 75be1fb6801d6abf34de0e02baeb320b9f40e6b1 /sbin/fdisk | |
parent | a0b3facec3f0e32fe1487170e6557e99377ce373 (diff) |
Nuke pointless blank lines, defines, comments and casts. Eliminate
#include in *.h files in favour of listing them as required in the *.c
files. Fix error message to correctly state that 64 is the minimum
value for -l. Use errx() where errno is not relevant. Use 'continue'
rather than a label to go back to start of a loop.
No intentional functional change.
Diffstat (limited to 'sbin/fdisk')
-rw-r--r-- | sbin/fdisk/cmd.c | 22 | ||||
-rw-r--r-- | sbin/fdisk/cmd.h | 12 | ||||
-rw-r--r-- | sbin/fdisk/disk.c | 4 | ||||
-rw-r--r-- | sbin/fdisk/disk.h | 4 | ||||
-rw-r--r-- | sbin/fdisk/fdisk.c | 6 | ||||
-rw-r--r-- | sbin/fdisk/mbr.c | 8 | ||||
-rw-r--r-- | sbin/fdisk/mbr.h | 7 | ||||
-rw-r--r-- | sbin/fdisk/misc.c | 12 | ||||
-rw-r--r-- | sbin/fdisk/misc.h | 12 | ||||
-rw-r--r-- | sbin/fdisk/part.c | 5 | ||||
-rw-r--r-- | sbin/fdisk/part.h | 5 | ||||
-rw-r--r-- | sbin/fdisk/user.c | 8 | ||||
-rw-r--r-- | sbin/fdisk/user.h | 5 |
13 files changed, 40 insertions, 70 deletions
diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index 9c12742e258..0930053fbc0 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.67 2014/03/17 13:15:44 krw Exp $ */ +/* $OpenBSD: cmd.c,v 1.68 2014/03/17 16:40:00 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -34,6 +34,9 @@ #include <stdlib.h> #include <signal.h> +#include "disk.h" +#include "part.h" +#include "mbr.h" #include "user.h" #include "cmd.h" @@ -109,12 +112,12 @@ Xswap(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt, return (ret); } - pf = (int)strtonum(from, 0, 3, &errstr); + pf = strtonum(from, 0, 3, &errstr); if (errstr) { printf("partition number is %s: %s\n", errstr, from); return (ret); } - pt = (int)strtonum(to, 0, 3, &errstr); + pt = strtonum(to, 0, 3, &errstr); if (errstr) { printf("partition number is %s: %s\n", errstr, to); return (ret); @@ -142,7 +145,7 @@ Xedit(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt, int pn, num, ret; struct prt *pp; - pn = (int)strtonum(args, 0, 3, &errstr); + pn = strtonum(args, 0, 3, &errstr); if (errstr) { printf("partition number is %s: %s\n", errstr, args); return (CMD_CONT); @@ -206,7 +209,7 @@ Xsetpid(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt, ret = CMD_CONT; - pn = (int)strtonum(args, 0, 3, &errstr); + pn = strtonum(args, 0, 3, &errstr); if (errstr) { printf("partition number is %s: %s\n", errstr, args); return (ret); @@ -236,7 +239,7 @@ Xselect(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt, int off; int pn; - pn = (int)strtonum(args, 0, 3, &errstr); + pn = strtonum(args, 0, 3, &errstr); if (errstr) { printf("partition number is %s: %s\n", errstr, args); return (CMD_CONT); @@ -358,7 +361,6 @@ int Xupdate(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt, int offset) { - /* Update code */ memcpy(mbr->code, tt->code, sizeof(mbr->code)); mbr->signature = DOSMBR_SIGNATURE; @@ -377,7 +379,7 @@ Xflag(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt, flag = args; part = strsep(&flag, " \t"); - pn = (int)strtonum(part, 0, 3, &errstr); + pn = strtonum(part, 0, 3, &errstr); if (errstr) { printf("partition number is %s: %s.\n", errstr, part); return (CMD_CONT); @@ -424,13 +426,13 @@ Xmanual(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt, if (asprintf(&p, "gunzip -qc|%s", pager) != -1) { f = popen(p, "w"); if (f) { - (void) fwrite(manpage, manpage_sz, 1, f); + fwrite(manpage, manpage_sz, 1, f); pclose(f); } free(p); } - (void)signal(SIGPIPE, opipe); + signal(SIGPIPE, opipe); return (CMD_CONT); } diff --git a/sbin/fdisk/cmd.h b/sbin/fdisk/cmd.h index 62227efb9a6..6134f706887 100644 --- a/sbin/fdisk/cmd.h +++ b/sbin/fdisk/cmd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.h,v 1.11 2014/03/10 21:40:58 krw Exp $ */ +/* $OpenBSD: cmd.h,v 1.12 2014/03/17 16:40:00 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -28,30 +28,20 @@ #ifndef _CMD_H #define _CMD_H -/* Includes */ -#include "disk.h" -#include "mbr.h" - - -/* Constants (returned by cmd funs) */ #define CMD_EXIT 0x0000 #define CMD_SAVE 0x0001 #define CMD_CONT 0x0002 #define CMD_CLEAN 0x0003 #define CMD_DIRTY 0x0004 - -/* Data types */ struct cmd { char *cmd; int (*fcn)(char *, struct disk *, struct mbr *, struct mbr *, int); char *help; }; - extern struct cmd cmd_table[]; -/* Prototypes */ int Xreinit(char *, struct disk *, struct mbr *, struct mbr *, int); int Xdisk(char *, struct disk *, struct mbr *, struct mbr *, int); int Xmanual(char *, struct disk *, struct mbr *, struct mbr *, int); diff --git a/sbin/fdisk/disk.c b/sbin/fdisk/disk.c index 7b76c2e03ad..106d31b82ab 100644 --- a/sbin/fdisk/disk.c +++ b/sbin/fdisk/disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disk.c,v 1.39 2014/03/17 13:15:44 krw Exp $ */ +/* $OpenBSD: disk.c,v 1.40 2014/03/17 16:40:00 krw Exp $ */ /* * Copyright (c) 1997, 2001 Tobias Weingartner @@ -53,7 +53,7 @@ DISK_open(char *disk, int mode) if (fstat(fd, &st) == -1) err(1, "%s", disk); if (!S_ISCHR(st.st_mode) && !S_ISREG(st.st_mode)) - err(1, "%s is not a character device or a regular file", disk); + errx(1, "%s is not a character device or a regular file", disk); return (fd); } diff --git a/sbin/fdisk/disk.h b/sbin/fdisk/disk.h index c6cbf3549f7..f8fa3afcaa8 100644 --- a/sbin/fdisk/disk.h +++ b/sbin/fdisk/disk.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disk.h,v 1.15 2014/03/17 13:15:44 krw Exp $ */ +/* $OpenBSD: disk.h,v 1.16 2014/03/17 16:40:00 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -28,7 +28,6 @@ #ifndef _DISK_H #define _DISK_H -/* Data types */ struct disk { char *name; u_int32_t cylinders; @@ -37,7 +36,6 @@ struct disk { u_int32_t size; }; -/* Prototypes */ int DISK_open(char *, int); void DISK_getlabelgeometry(struct disk *); int DISK_printgeometry(struct disk *, char *); diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c index e1fe73c51da..45206f262f9 100644 --- a/sbin/fdisk/fdisk.c +++ b/sbin/fdisk/fdisk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdisk.c,v 1.61 2014/03/17 13:15:44 krw Exp $ */ +/* $OpenBSD: fdisk.c,v 1.62 2014/03/17 16:40:00 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -36,6 +36,8 @@ #include <stdint.h> #include "disk.h" +#include "part.h" +#include "mbr.h" #include "misc.h" #include "user.h" @@ -117,7 +119,7 @@ main(int argc, char *argv[]) case 'l': l_arg = strtonum(optarg, 64, UINT32_MAX, &errstr); if (errstr) - errx(1, "Block argument %s [1..%u].", errstr, + errx(1, "Block argument %s [64..%u].", errstr, UINT32_MAX); break; case 'y': diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c index dc5fea8667d..5ae0af92385 100644 --- a/sbin/fdisk/mbr.c +++ b/sbin/fdisk/mbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.c,v 1.37 2014/03/17 13:15:44 krw Exp $ */ +/* $OpenBSD: mbr.c,v 1.38 2014/03/17 16:40:00 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -41,10 +41,9 @@ #include <memory.h> #include "disk.h" +#include "part.h" #include "misc.h" #include "mbr.h" -#include "part.h" - void MBR_init(struct disk *disk, struct mbr *mbr) @@ -143,8 +142,7 @@ MBR_print(struct mbr *mbr, char *units) int i; /* Header */ - printf("Signature: 0x%X\n", - (int)mbr->signature); + printf("Signature: 0x%X\n", (int)mbr->signature); PRT_print(0, NULL, units); /* Entries */ diff --git a/sbin/fdisk/mbr.h b/sbin/fdisk/mbr.h index 58969b83fa6..776452c6411 100644 --- a/sbin/fdisk/mbr.h +++ b/sbin/fdisk/mbr.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.h,v 1.15 2014/03/09 22:25:06 krw Exp $ */ +/* $OpenBSD: mbr.h,v 1.16 2014/03/17 16:40:00 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -28,9 +28,6 @@ #ifndef _MBR_H #define _MBR_H -#include "part.h" - -/* MBR type */ struct mbr { off_t reloffset; off_t offset; @@ -39,7 +36,6 @@ struct mbr { unsigned short signature; }; -/* Prototypes */ void MBR_print_disk(char *); void MBR_print(struct mbr *, char *); void MBR_parse(struct disk *, struct dos_mbr *, off_t, off_t, struct mbr *); @@ -50,4 +46,3 @@ int MBR_write(int, off_t, struct dos_mbr *); void MBR_pcopy(struct disk *, struct mbr *); #endif /* _MBR_H */ - diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c index 9398f6dd9c4..b7703f4769c 100644 --- a/sbin/fdisk/misc.c +++ b/sbin/fdisk/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.38 2014/03/17 13:15:44 krw Exp $ */ +/* $OpenBSD: misc.c,v 1.39 2014/03/17 16:40:00 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -31,6 +31,7 @@ #include <string.h> #include <errno.h> +#include "disk.h" #include "misc.h" struct unit_type unit_types[] = { @@ -47,7 +48,7 @@ unit_lookup(char *units) { int i = 0; if (units == NULL) - return (UNIT_TYPE_DEFAULT); + return (SECTORS); while (unit_types[i].abbr != NULL) { if (strncasecmp(unit_types[i].abbr, units, 1) == 0) @@ -56,7 +57,7 @@ unit_lookup(char *units) } /* default */ if (unit_types[i].abbr == NULL) - return (UNIT_TYPE_DEFAULT); + return (SECTORS); return (i); } @@ -127,7 +128,7 @@ ask_pid(int dflt) { char lbuf[100], *cp; size_t lbuflen; - int num; + int num = -1; const int low = 0, high = 0xff; if (dflt < low) @@ -136,7 +137,6 @@ ask_pid(int dflt) dflt = high; do { -again: printf("Partition id ('0' to disable) [%X - %X]: [%X] ", low, high, dflt); printf("(? for help) "); @@ -149,7 +149,7 @@ again: if (lbuf[0] == '?') { PRT_printall(); - goto again; + continue; } /* Convert */ diff --git a/sbin/fdisk/misc.h b/sbin/fdisk/misc.h index e35f22d2d34..53f3bd7f9d3 100644 --- a/sbin/fdisk/misc.h +++ b/sbin/fdisk/misc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.h,v 1.20 2014/03/10 21:40:58 krw Exp $ */ +/* $OpenBSD: misc.h,v 1.21 2014/03/17 16:40:00 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -28,10 +28,6 @@ #ifndef _MISC_H #define _MISC_H -#include "cmd.h" - -/* typedefs */ - struct unit_type { char *abbr; int conversion; @@ -40,11 +36,6 @@ struct unit_type { extern struct unit_type unit_types[]; #define SECTORS 1 /* units are bytes/sectors/kbytes/mbytes/gbytes */ -/* Constants */ -#define ASK_HEX 0x01 -#define ASK_DEC 0x02 -#define UNIT_TYPE_DEFAULT 1 - /* Prototypes */ int unit_lookup(char *); int ask_cmd(char **, char **); @@ -58,4 +49,3 @@ void putlong(void *, u_int32_t); u_int32_t getuint(struct disk *, char *, u_int32_t, u_int32_t); #endif /* _MISC_H */ - diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c index 7e4b593d41e..369593091e4 100644 --- a/sbin/fdisk/part.c +++ b/sbin/fdisk/part.c @@ -1,4 +1,4 @@ -/* $OpenBSD: part.c,v 1.58 2014/03/17 13:15:44 krw Exp $ */ +/* $OpenBSD: part.c,v 1.59 2014/03/17 16:40:00 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -30,8 +30,9 @@ #include <stdio.h> #include <string.h> +#include "disk.h" #include "misc.h" -#include "mbr.h" +#include "part.h" int PRT_check_chs(struct prt *partn); diff --git a/sbin/fdisk/part.h b/sbin/fdisk/part.h index a26a0b992e4..feed812e2f9 100644 --- a/sbin/fdisk/part.h +++ b/sbin/fdisk/part.h @@ -1,4 +1,4 @@ -/* $OpenBSD: part.h,v 1.14 2014/03/07 21:56:13 krw Exp $ */ +/* $OpenBSD: part.h,v 1.15 2014/03/17 16:40:00 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -28,7 +28,6 @@ #ifndef _PART_H #define _PART_H -/* Partition type */ struct prt { u_int32_t shead, scyl, ssect; u_int32_t ehead, ecyl, esect; @@ -38,7 +37,6 @@ struct prt { unsigned char id; }; -/* Prototypes */ void PRT_printall(void); const char *PRT_ascii_id(int); void PRT_parse(struct disk *, void *, off_t, off_t, struct prt *); @@ -52,4 +50,3 @@ void PRT_fix_BN(struct disk *, struct prt *, int); void PRT_fix_CHS(struct disk *, struct prt *); #endif /* _PART_H */ - diff --git a/sbin/fdisk/user.c b/sbin/fdisk/user.c index ba52bd9c16d..561a18b609e 100644 --- a/sbin/fdisk/user.c +++ b/sbin/fdisk/user.c @@ -1,4 +1,4 @@ -/* $OpenBSD: user.c,v 1.32 2014/03/17 13:15:44 krw Exp $ */ +/* $OpenBSD: user.c,v 1.33 2014/03/17 16:40:00 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -31,12 +31,12 @@ #include <stdio.h> #include <string.h> -#include "user.h" #include "disk.h" -#include "misc.h" +#include "part.h" #include "mbr.h" +#include "misc.h" #include "cmd.h" - +#include "user.h" /* Our command table */ struct cmd cmd_table[] = { diff --git a/sbin/fdisk/user.h b/sbin/fdisk/user.h index 2726e4bb11f..79b993e2a77 100644 --- a/sbin/fdisk/user.h +++ b/sbin/fdisk/user.h @@ -1,4 +1,4 @@ -/* $OpenBSD: user.h,v 1.8 2014/03/07 21:56:13 krw Exp $ */ +/* $OpenBSD: user.h,v 1.9 2014/03/17 16:40:00 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -28,9 +28,6 @@ #ifndef _USER_H #define _USER_H -#include "disk.h" -#include "mbr.h" - /* Prototypes */ int USER_init(struct disk *, struct mbr *, int); int USER_modify(struct disk *, struct mbr *, off_t, off_t); |