From: jsing Date: Sat, 28 Dec 2013 12:01:33 +0000 (+0000) Subject: Round the size of the bootstrap up to a multiple of the disk sector size. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=f7ad209ec75d011a2ac08abd31543ba37cea0e4e;p=openbsd 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. --- 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: