add some casts, tweak some types and variable names.
#include <sys/ioctl.h>
#include <sys/stat.h>
+#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#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
/* 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,
*/
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];
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:
/* 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");
(nowrite ? "would write" : "writing"));
if (nowrite)
return;
- if (write(devfd, boot, bootsize) != bootsize)
+ if (write(devfd, boot, bootsize) != (ssize_t)bootsize)
err(1, "write");
}
-/* $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>
*
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. */
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;
/*
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";
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");
}
-/* $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>
*
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 *);
-/* $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>
*
{
struct bioc_inq bi;
struct bioc_vol bv;
- int rv, i;
+ int i;
/*
* Determine if the given device is a softraid volume.
/* 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. */
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) {