summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2015-03-14 18:32:30 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2015-03-14 18:32:30 +0000
commitfe1a28b2e75484938361b2bea63dabcd0c2f224d (patch)
tree6939ee0162bde62a536059a801d71afd6f5b78d5 /sbin
parenta65d0760b340749cc44566a7c47fb6fe237d0273 (diff)
Whitespace & KNF tweaks. Change functions whose return values are
not checked to void. Use continue inside a do loop instead of a goto to the top. Move a #define/#undef more local to use. Eliminate some lint. General cleanup of things noticed preparing the big churn. No intentional functional change.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/fdisk/cmd.c25
-rw-r--r--sbin/fdisk/disk.c5
-rw-r--r--sbin/fdisk/fdisk.c7
-rw-r--r--sbin/fdisk/mbr.c8
-rw-r--r--sbin/fdisk/misc.c3
-rw-r--r--sbin/fdisk/part.c7
-rw-r--r--sbin/fdisk/user.c25
-rw-r--r--sbin/fdisk/user.h8
8 files changed, 43 insertions, 45 deletions
diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c
index af96485ccce..23739451b6d 100644
--- a/sbin/fdisk/cmd.c
+++ b/sbin/fdisk/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.74 2015/03/14 15:21:53 krw Exp $ */
+/* $OpenBSD: cmd.c,v 1.75 2015/03/14 18:32:29 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -148,11 +148,6 @@ Xedit(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
/* Edit partition type */
ret = Xsetpid(args, disk, mbr, tt, offset);
-#define EDIT(p, v, n, m) \
- if ((num = ask_num(p, v, n, m)) != v) \
- ret = CMD_DIRTY; \
- v = num;
-
/* Unused, so just zero out */
if (pp->id == DOSPTYP_UNUSED) {
memset(pp, 0, sizeof(*pp));
@@ -170,12 +165,17 @@ Xedit(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
maxsect = disk->sectors;
/* Get data */
+#define EDIT(p, v, n, m) \
+ if ((num = ask_num(p, v, n, m)) != v) \
+ ret = CMD_DIRTY; \
+ v = num;
EDIT("BIOS Starting cylinder", pp->scyl, 0, maxcyl);
EDIT("BIOS Starting head", pp->shead, 0, maxhead);
EDIT("BIOS Starting sector", pp->ssect, 1, maxsect);
EDIT("BIOS Ending cylinder", pp->ecyl, 0, maxcyl);
EDIT("BIOS Ending head", pp->ehead, 0, maxhead);
EDIT("BIOS Ending sector", pp->esect, 1, maxsect);
+#undef EDIT
/* Fix up off/size values */
PRT_fix_BN(disk, pp, pn);
/* Fix up CHS values for LBA */
@@ -188,7 +188,7 @@ Xedit(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
/* Fix up CHS values */
PRT_fix_CHS(disk, pp);
}
-#undef EDIT
+
return (ret);
}
@@ -217,6 +217,7 @@ Xsetpid(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
return (CMD_CONT);
pp->id = num;
+
return (CMD_DIRTY);
}
@@ -257,6 +258,7 @@ Xselect(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
/* Recursion is beautiful! */
USER_edit(disk, tt, off, firstoff);
+
return (CMD_CONT);
}
@@ -316,8 +318,6 @@ int
Xquit(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
int offset)
{
-
- /* Nothing to do here */
return (CMD_SAVE);
}
@@ -326,17 +326,12 @@ Xabort(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
int offset)
{
exit(0);
-
- /* NOTREACHED */
- return (CMD_CONT);
}
int
Xexit(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
int offset)
{
-
- /* Nothing to do here */
return (CMD_EXIT);
}
@@ -400,6 +395,7 @@ Xflag(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
mbr->part[pn].flag = val;
printf("Partition %d flag value set to 0x%x.\n", pn, val);
}
+
return (CMD_DIRTY);
}
@@ -427,5 +423,6 @@ Xmanual(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
}
signal(SIGPIPE, opipe);
+
return (CMD_CONT);
}
diff --git a/sbin/fdisk/disk.c b/sbin/fdisk/disk.c
index 59dd29f1585..8f9fe533ed9 100644
--- a/sbin/fdisk/disk.c
+++ b/sbin/fdisk/disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disk.c,v 1.43 2015/03/14 15:21:53 krw Exp $ */
+/* $OpenBSD: disk.c,v 1.44 2015/03/14 18:32:29 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -37,8 +37,8 @@ struct disklabel dl;
int
DISK_open(char *disk, int mode)
{
- int fd;
struct stat st;
+ int fd;
fd = opendev(disk, mode, OPENDEV_PART, NULL);
if (fd == -1)
@@ -47,6 +47,7 @@ DISK_open(char *disk, int mode)
err(1, "%s", disk);
if (!S_ISCHR(st.st_mode) && !S_ISREG(st.st_mode))
errx(1, "%s is not a character device or a regular file", disk);
+
return (fd);
}
diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c
index 295c9ec22e0..7143223f638 100644
--- a/sbin/fdisk/fdisk.c
+++ b/sbin/fdisk/fdisk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdisk.c,v 1.66 2015/03/14 15:21:53 krw Exp $ */
+/* $OpenBSD: fdisk.c,v 1.67 2015/03/14 18:32:29 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -170,7 +170,7 @@ main(int argc, char *argv[])
/* Print out current MBRs on disk */
if ((i_flag + u_flag + e_flag) == 0)
- exit(USER_print_disk(&disk));
+ USER_print_disk(&disk);
/* Parse mbr template, to pass on later */
if (mbrfile != NULL && (fd = open(mbrfile, O_RDONLY)) == -1) {
@@ -190,8 +190,7 @@ main(int argc, char *argv[])
/* Now do what we are supposed to */
if (i_flag || u_flag)
- if (USER_init(&disk, &mbr, u_flag) == -1)
- err(1, "error initializing MBR");
+ USER_init(&disk, &mbr, u_flag);
if (e_flag)
USER_edit(&disk, &mbr, 0, 0);
diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c
index 91b287707af..eb4dedd3544 100644
--- a/sbin/fdisk/mbr.c
+++ b/sbin/fdisk/mbr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbr.c,v 1.45 2015/03/14 16:58:00 krw Exp $ */
+/* $OpenBSD: mbr.c,v 1.46 2015/03/14 18:32:29 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -211,9 +211,9 @@ MBR_write(int fd, off_t where, struct dos_mbr *dos_mbr)
void
MBR_pcopy(struct disk *disk, struct mbr *mbr)
{
- int i, fd, error;
- struct dos_mbr dos_mbr;
struct dos_partition dos_parts[NDOSPART];
+ struct dos_mbr dos_mbr;
+ int i, fd, error;
fd = DISK_open(disk->name, O_RDONLY);
error = MBR_read(fd, 0, &dos_mbr);
@@ -234,8 +234,8 @@ MBR_pcopy(struct disk *disk, struct mbr *mbr)
char *
MBR_readsector(int fd, off_t where)
{
- char *secbuf;
const int secsize = unit_types[SECTORS].conversion;
+ char *secbuf;
ssize_t len;
off_t off;
diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c
index 99befe0b8ff..7512bbdcc82 100644
--- a/sbin/fdisk/misc.c
+++ b/sbin/fdisk/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.43 2015/03/14 15:21:53 krw Exp $ */
+/* $OpenBSD: misc.c,v 1.44 2015/03/14 18:32:29 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -42,6 +42,7 @@ int
unit_lookup(char *units)
{
int i = 0;
+
if (units == NULL)
return (SECTORS);
diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c
index ab2ffe299fe..dae423cf997 100644
--- a/sbin/fdisk/part.c
+++ b/sbin/fdisk/part.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: part.c,v 1.67 2015/03/14 15:21:53 krw Exp $ */
+/* $OpenBSD: part.c,v 1.68 2015/03/14 18:32:29 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -211,9 +211,9 @@ PRT_check_chs(struct prt *partn)
(partn->esect >63) ||
(partn->ecyl > 1023) )
{
- return 0;
+ return (0);
}
- return 1;
+ return (1);
}
void
@@ -274,6 +274,7 @@ PRT_print(int num, struct prt *partn, char *units)
{
double size;
int i;
+
i = unit_lookup(units);
if (partn == NULL) {
diff --git a/sbin/fdisk/user.c b/sbin/fdisk/user.c
index db3fbe5cf8d..b421a57d1ac 100644
--- a/sbin/fdisk/user.c
+++ b/sbin/fdisk/user.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: user.c,v 1.37 2015/03/14 15:21:53 krw Exp $ */
+/* $OpenBSD: user.c,v 1.38 2015/03/14 18:32:29 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -19,6 +19,7 @@
#include <sys/types.h>
#include <sys/fcntl.h>
#include <sys/disklabel.h>
+#include <err.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
@@ -50,7 +51,7 @@ struct cmd cmd_table[] = {
{NULL, NULL, NULL}
};
-int
+void
USER_init(struct disk *disk, struct mbr *tt, int preserve)
{
char *query;
@@ -64,14 +65,12 @@ USER_init(struct disk *disk, struct mbr *tt, int preserve)
}
if (ask_yn(query))
- Xwrite(NULL, disk, tt, NULL, 0);
-
- return (0);
+ Xwrite(NULL, disk, tt, NULL, 0);
}
int modified;
-int
+void
USER_edit(struct disk *disk, struct mbr *tt, off_t offset, off_t reloff)
{
static int editlevel;
@@ -96,14 +95,14 @@ USER_edit(struct disk *disk, struct mbr *tt, off_t offset, off_t reloff)
printf("Enter 'help' for information\n");
/* Edit cycle */
- do {
again:
+ do {
printf("fdisk:%c%d> ", (modified)?'*':' ', editlevel);
fflush(stdout);
ask_cmd(&cmd, &args);
if (cmd[0] == '\0')
- goto again;
+ continue;
for (i = 0; cmd_table[i].cmd != NULL; i++)
if (strstr(cmd_table[i].cmd, cmd) == cmd_table[i].cmd)
break;
@@ -135,7 +134,7 @@ again:
/* Write out MBR */
if (modified) {
if (st == CMD_SAVE) {
- if (Xwrite(NULL, disk, &mbr, NULL, offset) == CMD_CONT)
+ if (Xwrite(NULL, disk, &mbr, NULL, offset) == CMD_CONT)
goto again;
close(fd);
} else
@@ -145,11 +144,9 @@ again:
done:
/* One level less */
editlevel -= 1;
-
- return (0);
}
-int
+void
USER_print_disk(struct disk *disk)
{
off_t offset, firstoff;
@@ -181,5 +178,7 @@ USER_print_disk(struct disk *disk)
}
} while (offset);
- return (close(fd));
+ error = close(fd);
+ if (error == -1)
+ err(1, "Unable to close disk");
}
diff --git a/sbin/fdisk/user.h b/sbin/fdisk/user.h
index e3567fe6ebb..d16f9b4d2ee 100644
--- a/sbin/fdisk/user.h
+++ b/sbin/fdisk/user.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: user.h,v 1.12 2015/03/14 15:21:53 krw Exp $ */
+/* $OpenBSD: user.h,v 1.13 2015/03/14 18:32:29 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -20,8 +20,8 @@
#define _USER_H
/* Prototypes */
-int USER_init(struct disk *, struct mbr *, int);
-int USER_edit(struct disk *, struct mbr *, off_t, off_t);
-int USER_print_disk(struct disk *);
+void USER_init(struct disk *, struct mbr *, int);
+void USER_edit(struct disk *, struct mbr *, off_t, off_t);
+void USER_print_disk(struct disk *);
#endif /* _USER_H */