summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsing <jsing@openbsd.org>2013-12-28 11:26:57 +0000
committerjsing <jsing@openbsd.org>2013-12-28 11:26:57 +0000
commit808c65001a8f417e47b5d11110894acfa47f0f8a (patch)
treeadc1ef26254f6709484ba7afbd55841a56d3b7a0
parentTweak makefiles so that we pull in source files based on defines. (diff)
downloadwireguard-openbsd-808c65001a8f417e47b5d11110894acfa47f0f8a.tar.xz
wireguard-openbsd-808c65001a8f417e47b5d11110894acfa47f0f8a.zip
Various code clean ups - add a missing header, add a missing prototype,
add some casts, tweak some types and variable names.
-rw-r--r--usr.sbin/installboot/bootstrap.c31
-rw-r--r--usr.sbin/installboot/i386/i386_softraid.c12
-rw-r--r--usr.sbin/installboot/installboot.h6
-rw-r--r--usr.sbin/installboot/softraid.c10
4 files changed, 30 insertions, 29 deletions
diff --git a/usr.sbin/installboot/bootstrap.c b/usr.sbin/installboot/bootstrap.c
index 76782ef1207..425d1cfd2de 100644
--- a/usr.sbin/installboot/bootstrap.c
+++ b/usr.sbin/installboot/bootstrap.c
@@ -20,6 +20,7 @@
#include <sys/ioctl.h>
#include <sys/stat.h>
+#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
@@ -28,17 +29,17 @@
#include "installboot.h"
-int
+void
bootstrap(int devfd, char *dev, char *bootfile)
{
struct disklabel dl;
struct disklabel *lp;
struct partition *pp;
char *boot, *p, part;
- u_int64_t bootend;
+ size_t bootsize;
+ size_t bootend;
struct stat sb;
- int bootsize;
- int bf, i;
+ int fd, i;
/*
* Install bootstrap code onto the given disk, preserving the
@@ -56,22 +57,22 @@ bootstrap(int devfd, char *dev, char *bootfile)
/* Read bootstrap file. */
if (verbose)
fprintf(stderr, "reading bootstrap from %s\n", bootfile);
- bf = open(bootfile, O_RDONLY);
- if (bf < 0)
+ fd = open(bootfile, O_RDONLY);
+ if (fd < 0)
err(1, "open %s", bootfile);
- if (fstat(bf, &sb) != 0)
+ if (fstat(fd, &sb) != 0)
err(1, "fstat %s", bootfile);
bootsize = sb.st_size;
- bootend = howmany((u_int64_t)bootsize, dl.d_secsize);
+ bootend = howmany(bootsize, dl.d_secsize);
boot = malloc(bootsize);
if (boot == NULL)
err(1, "malloc");
- if (read(bf, boot, bootsize) != bootsize)
+ if (read(fd, boot, bootsize) != (ssize_t)bootsize)
err(1, "read");
if (verbose)
- fprintf(stderr, "bootstrap is %lld bytes (%llu sectors)\n",
+ fprintf(stderr, "bootstrap is %zu bytes (%zu sectors)\n",
bootsize, bootend);
- close(bf);
+ close(fd);
/*
* Check that the bootstrap will fit - partitions must not overlap,
@@ -80,7 +81,7 @@ bootstrap(int devfd, char *dev, char *bootfile)
*/
if (verbose)
fprintf(stderr, "ensuring used partitions do not overlap "
- "with bootstrap sectors 0-%lld\n", bootend);
+ "with bootstrap sectors 0-%zu\n", bootend);
for (i = 0; i < dl.d_npartitions; i++) {
part = 'a' + i;
pp = &dl.d_partitions[i];
@@ -88,7 +89,7 @@ bootstrap(int devfd, char *dev, char *bootfile)
continue;
if (DL_GETPSIZE(pp) == 0)
continue;
- if (bootend <= DL_GETPOFFSET(pp))
+ if ((u_int64_t)bootend <= DL_GETPOFFSET(pp))
continue;
switch (pp->p_fstype) {
case FS_BOOT:
@@ -105,7 +106,7 @@ bootstrap(int devfd, char *dev, char *bootfile)
/* Make sure the bootstrap has left space for the disklabel. */
lp = (struct disklabel *)(boot + (LABELSECTOR * dl.d_secsize) +
LABELOFFSET);
- for (i = 0, p = (char *)lp; i < sizeof(*lp); i++)
+ for (i = 0, p = (char *)lp; i < (int)sizeof(*lp); i++)
if (p[i] != 0)
errx(1, "bootstrap has data in disklabel area");
@@ -120,6 +121,6 @@ bootstrap(int devfd, char *dev, char *bootfile)
(nowrite ? "would write" : "writing"));
if (nowrite)
return;
- if (write(devfd, boot, bootsize) != bootsize)
+ if (write(devfd, boot, bootsize) != (ssize_t)bootsize)
err(1, "write");
}
diff --git a/usr.sbin/installboot/i386/i386_softraid.c b/usr.sbin/installboot/i386/i386_softraid.c
index 75756dc0216..98f5209490d 100644
--- a/usr.sbin/installboot/i386/i386_softraid.c
+++ b/usr.sbin/installboot/i386/i386_softraid.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: i386_softraid.c,v 1.1 2013/12/27 13:52:40 jsing Exp $ */
+/* $OpenBSD: i386_softraid.c,v 1.2 2013/12/28 11:26:57 jsing Exp $ */
/*
* Copyright (c) 2012 Joel Sing <jsing@openbsd.org>
*
@@ -49,14 +49,12 @@ sr_install_bootblk(int devfd, int vol, int disk)
char *dev;
char part;
int diskfd;
- int rv;
/* Get device name for this disk/chunk. */
memset(&bd, 0, sizeof(bd));
bd.bd_volid = vol;
bd.bd_diskid = disk;
- rv = ioctl(devfd, BIOCDISK, &bd);
- if (rv == -1)
+ if (ioctl(devfd, BIOCDISK, &bd) == -1)
err(1, "BIOCDISK");
/* Check disk status. */
@@ -116,7 +114,7 @@ sr_install_bootldr(int devfd, char *dev)
uint16_t bsize = SR_FS_BLOCKSIZE;
uint16_t nblocks;
uint8_t bshift = 5; /* fragsize == blocksize */
- int fd, i, rv;
+ int fd, i;
u_char *p;
/*
@@ -162,6 +160,7 @@ sr_install_bootldr(int devfd, char *dev)
inodedbl = ((u_char*)&ino_p->di_db[0] -
&p[bootsize - SR_FS_BLOCKSIZE]) + INODEOFF;
+ memset(&bb, 0, sizeof(bb));
bb.bb_bootldr = p;
bb.bb_bootldr_size = bootsize;
bb.bb_bootblk = "XXX";
@@ -171,8 +170,7 @@ sr_install_bootldr(int devfd, char *dev)
if (verbose)
fprintf(stderr, "%s: installing boot loader on "
"softraid volume\n", dev);
- rv = ioctl(devfd, BIOCINSTALLBOOT, &bb);
- if (rv != 0)
+ if (ioctl(devfd, BIOCINSTALLBOOT, &bb) == -1)
errx(1, "softraid installboot failed");
}
diff --git a/usr.sbin/installboot/installboot.h b/usr.sbin/installboot/installboot.h
index ec0f56d3555..1b0a79efe48 100644
--- a/usr.sbin/installboot/installboot.h
+++ b/usr.sbin/installboot/installboot.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: installboot.h,v 1.1 2013/12/27 13:52:40 jsing Exp $ */
+/* $OpenBSD: installboot.h,v 1.2 2013/12/28 11:26:57 jsing Exp $ */
/*
* Copyright (c) 2012, 2013 Joel Sing <jsing@openbsd.org>
*
@@ -22,6 +22,10 @@ extern int verbose;
extern char *stage1;
extern char *stage2;
+#ifdef BOOTSTRAP
+void bootstrap(int, char *, char *);
+#endif
+
void md_init(void);
void md_loadboot(void);
void md_installboot(int, char *);
diff --git a/usr.sbin/installboot/softraid.c b/usr.sbin/installboot/softraid.c
index e155cbd1c04..41e755e2bc0 100644
--- a/usr.sbin/installboot/softraid.c
+++ b/usr.sbin/installboot/softraid.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraid.c,v 1.1 2013/12/27 13:52:40 jsing Exp $ */
+/* $OpenBSD: softraid.c,v 1.2 2013/12/28 11:26:57 jsing Exp $ */
/*
* Copyright (c) 2012 Joel Sing <jsing@openbsd.org>
*
@@ -53,7 +53,7 @@ sr_volume(int devfd, char *dev, int *vol, int *disks)
{
struct bioc_inq bi;
struct bioc_vol bv;
- int rv, i;
+ int i;
/*
* Determine if the given device is a softraid volume.
@@ -61,8 +61,7 @@ sr_volume(int devfd, char *dev, int *vol, int *disks)
/* Get volume information. */
memset(&bi, 0, sizeof(bi));
- rv = ioctl(devfd, BIOCINQ, &bi);
- if (rv == -1)
+ if (ioctl(devfd, BIOCINQ, &bi) == -1)
return 0;
/* XXX - softraid volumes will always have a "softraid0" controller. */
@@ -78,8 +77,7 @@ sr_volume(int devfd, char *dev, int *vol, int *disks)
for (i = 0; i < bi.bi_novol; i++) {
memset(&bv, 0, sizeof(bv));
bv.bv_volid = i;
- rv = ioctl(devfd, BIOCVOL, &bv);
- if (rv == -1)
+ if (ioctl(devfd, BIOCVOL, &bv) == -1)
err(1, "BIOCVOL");
if (strncmp(dev, bv.bv_dev, sizeof(bv.bv_dev)) == 0) {