svn commit: r263709 - user/marcel/mkimg
Marcel Moolenaar
marcel at FreeBSD.org
Tue Mar 25 04:45:56 UTC 2014
Author: marcel
Date: Tue Mar 25 04:45:55 2014
New Revision: 263709
URL: http://svnweb.freebsd.org/changeset/base/263709
Log:
First batch of media control:
1. Change -h to -H and change -t to -T. Use -H to specify the number of
heads and -T to specify the track size (number of sectors per track).
2. Add -S and -P. Use -S to specify the logical sector size and -P to
specify the physical sector size.
Default to 512 for both the logical and physical sector size.
Set nheads and nsecs to 1 by default.
Modified:
user/marcel/mkimg/mkimg.c
user/marcel/mkimg/mkimg.h
Modified: user/marcel/mkimg/mkimg.c
==============================================================================
--- user/marcel/mkimg/mkimg.c Tue Mar 25 04:40:41 2014 (r263708)
+++ user/marcel/mkimg/mkimg.c Tue Mar 25 04:45:55 2014 (r263709)
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <fcntl.h>
#include <libutil.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -49,7 +50,11 @@ __FBSDID("$FreeBSD$");
struct partlisthead partlist = STAILQ_HEAD_INITIALIZER(partlist);
u_int nparts = 0;
+u_int ncyls = 0;
+u_int nheads = 1;
+u_int nsecs = 1;
u_int secsz = 512;
+u_int blksz = 512;
static int bcfd = -1;
static int outfd = 0;
@@ -76,11 +81,13 @@ usage(const char *why)
fprintf(stderr, " options:\n");
fprintf(stderr, "\t-b <file>\t- file containing boot code\n");
- fprintf(stderr, "\t-h <num>\t- number of heads to simulate\n");
fprintf(stderr, "\t-o <file>\t- file to write image into\n");
fprintf(stderr, "\t-p <partition>\n");
fprintf(stderr, "\t-s <scheme>\n");
- fprintf(stderr, "\t-t <num>\t- number of tracks to simulate\n");
+ fprintf(stderr, "\t-H <num>\t- number of heads to simulate\n");
+ fprintf(stderr, "\t-P <num>\t- physical sector size\n");
+ fprintf(stderr, "\t-S <num>\t- logical sector size\n");
+ fprintf(stderr, "\t-T <num>\t- number of tracks to simulate\n");
fprintf(stderr, "\t-z\t\t- write a sparse file\n");
fprintf(stderr, " schemes:\n");
@@ -104,6 +111,26 @@ usage(const char *why)
exit(EX_USAGE);
}
+static int
+parse_number(u_int *valp, u_int min, u_int max, const char *arg)
+{
+ uint64_t val;
+
+ if (expand_number(arg, &val) == -1)
+ return (errno);
+ if (val > UINT_MAX || val < (uint64_t)min || val > (uint64_t)max)
+ return (EINVAL);
+ *valp = (u_int)val;
+ return (0);
+}
+
+static int
+pwr_of_two(u_int nr)
+{
+
+ return (((nr & (nr - 1)) == 0) ? 1 : 0);
+}
+
/*
* A partition specification has the following format:
* <type> ':' <kind> <contents>
@@ -298,7 +325,7 @@ main(int argc, char *argv[])
{
int c, error;
- while ((c = getopt(argc, argv, "b:h:o:p:s:t:z")) != -1) {
+ while ((c = getopt(argc, argv, "b:o:p:s:zH:P:S:T:")) != -1) {
switch (c) {
case 'b': /* BOOT CODE */
if (bcfd != -1)
@@ -307,8 +334,6 @@ main(int argc, char *argv[])
if (bcfd == -1)
err(EX_UNAVAILABLE, "%s", optarg);
break;
- case 'h': /* GEOMETRY: HEADS */
- break;
case 'o': /* OUTPUT FILE */
if (outfd != 0)
usage("multiple output files given");
@@ -329,10 +354,32 @@ main(int argc, char *argv[])
if (error)
errc(EX_DATAERR, error, "scheme");
break;
- case 't': /* GEOMETRY: TRACK SIZE */
- break;
case 'z': /* SPARSE OUTPUT */
break;
+ case 'H': /* GEOMETRY: HEADS */
+ error = parse_number(&nheads, 1, 255, optarg);
+ if (error)
+ errc(EX_DATAERR, error, "number of heads");
+ break;
+ case 'P': /* GEOMETRY: PHYSICAL SECTOR SIZE */
+ error = parse_number(&blksz, 512, INT_MAX + 1, optarg);
+ if (error == 0 && !pwr_of_two(blksz))
+ error = EINVAL;
+ if (error)
+ errc(EX_DATAERR, error, "physical sector size");
+ break;
+ case 'S': /* GEOMETRY: LOGICAL SECTOR SIZE */
+ error = parse_number(&secsz, 512, INT_MAX + 1, optarg);
+ if (error == 0 && !pwr_of_two(blksz))
+ error = EINVAL;
+ if (error)
+ errc(EX_DATAERR, error, "logical sector size");
+ break;
+ case 'T': /* GEOMETRY: TRACK SIZE */
+ error = parse_number(&nsecs, 1, 63, optarg);
+ if (error)
+ errc(EX_DATAERR, error, "track size");
+ break;
default:
usage("unknown option");
}
Modified: user/marcel/mkimg/mkimg.h
==============================================================================
--- user/marcel/mkimg/mkimg.h Tue Mar 25 04:40:41 2014 (r263708)
+++ user/marcel/mkimg/mkimg.h Tue Mar 25 04:45:55 2014 (r263709)
@@ -52,7 +52,11 @@ struct part {
extern STAILQ_HEAD(partlisthead, part) partlist;
extern u_int nparts;
-extern u_int secsz;
+extern u_int ncyls;
+extern u_int nheads;
+extern u_int nsecs;
+extern u_int secsz; /* Logical block size. */
+extern u_int blksz; /* Physical block size. */
int mkimg_seek(int fd, lba_t blk);
More information about the svn-src-user
mailing list