/* * Read information about /boot's inode and filesystem parameters, then * put biosboot (partition boot record) on the target drive with these * parameters patched in. */ int main(int argc, char *argv[]) { int vol = -1, ndisks = 0, disk; int c; int devfd; struct disklabel dl; while ((c = getopt(argc, argv, "vn")) != -1) { switch (c) { case 'n': /* Do not actually write the bootblock to disk. */ nowrite = 1; break; case 'v': /* Give more information. */ verbose = 1; break; default: usage(); } } if (argc - optind < 3) usage(); boot = argv[optind]; proto = argv[optind + 1]; realdev = dev = argv[optind + 2]; /* Open raw disk device. */ if ((devfd = opendev(dev, (nowrite? O_RDONLY:O_RDWR), OPENDEV_PART, &realdev)) < 0) err(1, "open: %s", realdev); if (verbose) fprintf(stderr, "boot: %s proto: %s device: %s\n", boot, proto, realdev); /* Load proto blocks into core. */ if ((protostore = loadproto(proto, &protosize)) == NULL) exit(1); /* XXX - Paranoia: Make sure size is aligned! */ if (protosize & (DEV_BSIZE - 1)) errx(1, "proto %s bad size=%ld", proto, protosize); if (protosize > SBSIZE - DEV_BSIZE) errx(1, "proto bootblocks too big"); if (sr_volume(devfd, &vol, &ndisks)) { /* Install boot loader into softraid volume. */ sr_installboot(devfd); /* Install biosboot on each disk that is part of this volume. */ for (disk = 0; disk < ndisks; disk++) sr_installpbr(devfd, vol, disk); } else { /* Get and check disklabel. */ if (ioctl(devfd, DIOCGDINFO, &dl) != 0) err(1, "disklabel: %s", realdev); if (dl.d_magic != DISKMAGIC) err(1, "bad disklabel magic=0x%08x", dl.d_magic); /* Warn on unknown disklabel types. */ if (dl.d_type == 0) warnx("disklabel type unknown"); /* Get bootstrap parameters to patch into proto. */ if (getbootparams(boot, devfd, &dl) != 0) exit(1); /* Write boot blocks to device. */ write_bootblocks(devfd, &dl); } (void)close(devfd); return 0; }
int main(int argc, char *argv[]) { char *blkfile, *realdev; int vol = -1, ndisks = 0, disk; int c, devfd, blkfd; struct stat sb; while ((c = getopt(argc, argv, "nv")) != -1) { switch (c) { case 'n': /* Do not actually write the bootblock to disk. */ nowrite = 1; break; case 'v': /* Chat */ verbose = 1; break; default: usage(); } } if (argc - optind < 2) usage(); blkfile = argv[optind++]; dev = argv[optind]; if (verbose) printf("bootblk: %s\n", blkfile); if ((blkfd = open(blkfile, O_RDONLY)) < 0) err(1, "open: %s", blkfile); if (fstat(blkfd, &sb) == -1) err(1, "fstat: %s", blkfile); if (sb.st_size == 0) errx(1, "%s is empty", blkfile); blksize = howmany(sb.st_size, DEV_BSIZE) * DEV_BSIZE; if (blksize > SBSIZE - DEV_BSIZE) errx(1, "boot blocks too big"); if ((blkstore = malloc(blksize)) == NULL) err(1, "malloc: %s", blkfile); bzero(blkstore, blksize); if (read(blkfd, blkstore, sb.st_size) != sb.st_size) err(1, "read: %s", blkfile); if ((devfd = opendev(dev, (nowrite ? O_RDONLY : O_RDWR), OPENDEV_PART, &realdev)) < 0) err(1, "open: %s", realdev); if (verbose) printf("device: %s\n", realdev); if (sr_volume(devfd, &vol, &ndisks)) { /* Install boot loader in softraid volume. */ sr_installboot(devfd); /* Install bootblk on each disk that is part of this volume. */ for (disk = 0; disk < ndisks; disk++) sr_install_bootblk(devfd, vol, disk); } else { /* Write boot blocks to device. */ write_bootblk(devfd); } close(devfd); }