diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2013-12-28 12:01:34 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2013-12-28 12:01:34 +0000 |
commit | 4896a5b631db177aa585a64a097a6362471be99d (patch) | |
tree | 6a1eda242745bb36fcd0747884673caa2711578a | |
parent | 8b474ec3880292d099de348c646bc4f5fda091a8 (diff) |
Round the size of the bootstrap up to a multiple of the disk sector size.
Some bootstraps are already built this way, however others are not.
-rw-r--r-- | usr.sbin/installboot/bootstrap.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/usr.sbin/installboot/bootstrap.c b/usr.sbin/installboot/bootstrap.c index 425d1cfd2de..7e4f35b773d 100644 --- a/usr.sbin/installboot/bootstrap.c +++ b/usr.sbin/installboot/bootstrap.c @@ -37,7 +37,7 @@ bootstrap(int devfd, char *dev, char *bootfile) struct partition *pp; char *boot, *p, part; size_t bootsize; - size_t bootend; + size_t bootsec; struct stat sb; int fd, i; @@ -62,16 +62,18 @@ bootstrap(int devfd, char *dev, char *bootfile) err(1, "open %s", bootfile); if (fstat(fd, &sb) != 0) err(1, "fstat %s", bootfile); - bootsize = sb.st_size; - bootend = howmany(bootsize, dl.d_secsize); + bootsec = howmany((ssize_t)sb.st_size, dl.d_secsize); + bootsize = bootsec * dl.d_secsize; + if (verbose) + fprintf(stderr, "bootstrap is %zu bytes " + "(%zu sectors @ %u bytes = %zu bytes)\n", + (ssize_t)sb.st_size, bootsec, dl.d_secsize, bootsize); boot = malloc(bootsize); if (boot == NULL) err(1, "malloc"); - if (read(fd, boot, bootsize) != (ssize_t)bootsize) + memset(boot, 0, bootsize); + if (read(fd, boot, bootsize) != (ssize_t)sb.st_size) err(1, "read"); - if (verbose) - fprintf(stderr, "bootstrap is %zu bytes (%zu sectors)\n", - bootsize, bootend); close(fd); /* @@ -81,7 +83,7 @@ bootstrap(int devfd, char *dev, char *bootfile) */ if (verbose) fprintf(stderr, "ensuring used partitions do not overlap " - "with bootstrap sectors 0-%zu\n", bootend); + "with bootstrap sectors 0-%zu\n", bootsec); for (i = 0; i < dl.d_npartitions; i++) { part = 'a' + i; pp = &dl.d_partitions[i]; @@ -89,7 +91,7 @@ bootstrap(int devfd, char *dev, char *bootfile) continue; if (DL_GETPSIZE(pp) == 0) continue; - if ((u_int64_t)bootend <= DL_GETPOFFSET(pp)) + if ((u_int64_t)bootsec <= DL_GETPOFFSET(pp)) continue; switch (pp->p_fstype) { case FS_BOOT: |