Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Mar 2014 20:14:41 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r263831 - user/marcel/mkimg
Message-ID:  <201403272014.s2RKEfWt059548@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Thu Mar 27 20:14:40 2014
New Revision: 263831
URL: http://svnweb.freebsd.org/changeset/base/263831

Log:
  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

Modified:
  user/marcel/mkimg/mkimg.c
  user/marcel/mkimg/mkimg.h

Modified: user/marcel/mkimg/mkimg.c
==============================================================================
--- user/marcel/mkimg/mkimg.c	Thu Mar 27 20:13:53 2014	(r263830)
+++ user/marcel/mkimg/mkimg.c	Thu Mar 27 20:14:40 2014	(r263831)
@@ -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) {

Modified: user/marcel/mkimg/mkimg.h
==============================================================================
--- user/marcel/mkimg/mkimg.h	Thu Mar 27 20:13:53 2014	(r263830)
+++ user/marcel/mkimg/mkimg.h	Thu Mar 27 20:14:40 2014	(r263831)
@@ -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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201403272014.s2RKEfWt059548>