diff options
author | marcel <marcel@FreeBSD.org> | 2014-03-27 20:14:40 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 2014-03-27 20:14:40 +0000 |
commit | 6084642f6d5685bfa794ae063e8b924555e68559 (patch) | |
tree | cd8211f2f058f3a31ba00e415d3e3c282ce8cbf5 | |
parent | e7f6c0c88bf1d79cb1c51a125f162d00f3be96dd (diff) | |
download | FreeBSD-src-6084642f6d5685bfa794ae063e8b924555e68559.zip FreeBSD-src-6084642f6d5685bfa794ae063e8b924555e68559.tar.gz |
1. Add -v option to increase vebosity levels
2. Fix copy-paste bug -- acrually check secsz for being a power of 2
3. Check secsz and blksz parameters
4. Print the sector and block size when -v is given
-rw-r--r-- | mkimg.c | 36 | ||||
-rw-r--r-- | mkimg.h | 2 |
2 files changed, 31 insertions, 7 deletions
@@ -50,11 +50,13 @@ __FBSDID("$FreeBSD$"); struct partlisthead partlist = STAILQ_HEAD_INITIALIZER(partlist); u_int nparts = 0; +u_int verbose; + u_int ncyls = 0; u_int nheads = 1; u_int nsecs = 1; u_int secsz = 512; -u_int blksz = 512; +u_int blksz = 0; static int bcfd = -1; static int outfd = 0; @@ -270,10 +272,6 @@ mkimg(int bfd) off_t bytesize; int error, fd; - if (nparts > scheme_max_parts()) - errc(EX_DATAERR, ENOSPC, "only %d partitions are supported", - scheme_max_parts()); - error = scheme_bootcode(bfd); if (error) errc(EX_DATAERR, error, "boot code"); @@ -325,7 +323,7 @@ main(int argc, char *argv[]) { int c, error; - while ((c = getopt(argc, argv, "b:o:p:s:zH:P:S:T:")) != -1) { + while ((c = getopt(argc, argv, "b:o:p:s:vzH:P:S:T:")) != -1) { switch (c) { case 'b': /* BOOT CODE */ if (bcfd != -1) @@ -354,6 +352,9 @@ main(int argc, char *argv[]) if (error) errc(EX_DATAERR, error, "scheme"); break; + case 'v': + verbose++; + break; case 'z': /* SPARSE OUTPUT */ break; case 'H': /* GEOMETRY: HEADS */ @@ -370,7 +371,7 @@ main(int argc, char *argv[]) break; case 'S': /* GEOMETRY: LOGICAL SECTOR SIZE */ error = parse_number(&secsz, 512, INT_MAX + 1, optarg); - if (error == 0 && !pwr_of_two(blksz)) + if (error == 0 && !pwr_of_two(secsz)) error = EINVAL; if (error) errc(EX_DATAERR, error, "logical sector size"); @@ -384,6 +385,7 @@ main(int argc, char *argv[]) usage("unknown option"); } } + if (argc > optind) usage("trailing arguments"); if (scheme_selected() == NULL) @@ -391,6 +393,21 @@ main(int argc, char *argv[]) if (nparts == 0) usage("no partitions"); + if (secsz > blksz) { + if (blksz != 0) + errx(EX_DATAERR, "the physical block size cannot " + "be smaller than the sector size"); + blksz = secsz; + } + + if (secsz > scheme_max_secsz()) + errx(EX_DATAERR, "maximum sector size supported is %u; " + "size specified is %u", scheme_max_secsz(), secsz); + + if (nparts > scheme_max_parts()) + errx(EX_DATAERR, "%d partitions supported; %d given", + scheme_max_parts(), nparts); + if (outfd == 0) { if (atexit(cleanup) == -1) err(EX_OSERR, "cannot register cleanup function"); @@ -401,6 +418,11 @@ main(int argc, char *argv[]) } else tmpfd = outfd; + if (verbose) { + printf("Logical sector size: %u\n", secsz); + printf("Physical block size: %u\n", blksz); + } + mkimg(bcfd); if (tmpfd != outfd) { @@ -52,6 +52,8 @@ struct part { extern STAILQ_HEAD(partlisthead, part) partlist; extern u_int nparts; +extern u_int verbose; + extern u_int ncyls; extern u_int nheads; extern u_int nsecs; |