summaryrefslogtreecommitdiffstats
path: root/usr.bin/mkimg
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2014-09-27 04:53:51 +0000
committermarcel <marcel@FreeBSD.org>2014-09-27 04:53:51 +0000
commitbf39d18edb9ad7a21a819c3dad15cc5d653191a2 (patch)
tree43df5d57128ba7a41d874b3eed549f539c02222e /usr.bin/mkimg
parent381edfd870a0fd662bd3a74207b9d97f55e1207f (diff)
downloadFreeBSD-src-bf39d18edb9ad7a21a819c3dad15cc5d653191a2.zip
FreeBSD-src-bf39d18edb9ad7a21a819c3dad15cc5d653191a2.tar.gz
Add 3 long options for getting information about mkimg itself:
--version print the version of mkimg and also whether it's 64- or 32-bit. --formats list the supported output formats separated by space. --schemes list the supported partitioning schemes separated by space. Inspired by a patch from: gjb@ MFC after: 1 week Relnotes: yes
Diffstat (limited to 'usr.bin/mkimg')
-rw-r--r--usr.bin/mkimg/Makefile2
-rw-r--r--usr.bin/mkimg/mkimg.c101
2 files changed, 90 insertions, 13 deletions
diff --git a/usr.bin/mkimg/Makefile b/usr.bin/mkimg/Makefile
index 1152ce3..a0bc579 100644
--- a/usr.bin/mkimg/Makefile
+++ b/usr.bin/mkimg/Makefile
@@ -6,6 +6,8 @@ PROG= mkimg
SRCS= format.c image.c mkimg.c scheme.c
MAN= mkimg.1
+MKIMG_VERSION=20140926
+CFLAGS+=-DMKIMG_VERSION=${MKIMG_VERSION}
CFLAGS+=-DSPARSE_WRITE
# List of formats to support
diff --git a/usr.bin/mkimg/mkimg.c b/usr.bin/mkimg/mkimg.c
index ab95d94..8c26c7e 100644
--- a/usr.bin/mkimg/mkimg.c
+++ b/usr.bin/mkimg/mkimg.c
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <err.h>
#include <fcntl.h>
+#include <getopt.h>
#include <libutil.h>
#include <limits.h>
#include <stdio.h>
@@ -48,6 +49,17 @@ __FBSDID("$FreeBSD$");
#include "mkimg.h"
#include "scheme.h"
+#define LONGOPT_FORMATS 0x01000001
+#define LONGOPT_SCHEMES 0x01000002
+#define LONGOPT_VERSION 0x01000003
+
+static struct option longopts[] = {
+ { "formats", no_argument, NULL, LONGOPT_FORMATS },
+ { "schemes", no_argument, NULL, LONGOPT_SCHEMES },
+ { "version", no_argument, NULL, LONGOPT_VERSION },
+ { NULL, 0, NULL, 0 }
+};
+
struct partlisthead partlist = STAILQ_HEAD_INITIALIZER(partlist);
u_int nparts = 0;
@@ -61,10 +73,69 @@ u_int secsz = 512;
u_int blksz = 0;
static void
-usage(const char *why)
+print_formats(int usage)
{
struct mkimg_format *f, **f_iter;
+ const char *sep;
+
+ if (usage) {
+ fprintf(stderr, "\n formats:\n");
+ SET_FOREACH(f_iter, formats) {
+ f = *f_iter;
+ fprintf(stderr, "\t%s\t- %s\n", f->name,
+ f->description);
+ }
+ } else {
+ sep = "";
+ SET_FOREACH(f_iter, formats) {
+ f = *f_iter;
+ printf("%s%s", sep, f->name);
+ sep = " ";
+ }
+ putchar('\n');
+ }
+}
+
+static void
+print_schemes(int usage)
+{
struct mkimg_scheme *s, **s_iter;
+ const char *sep;
+
+ if (usage) {
+ fprintf(stderr, "\n schemes:\n");
+ SET_FOREACH(s_iter, schemes) {
+ s = *s_iter;
+ fprintf(stderr, "\t%s\t- %s\n", s->name,
+ s->description);
+ }
+ } else {
+ sep = "";
+ SET_FOREACH(s_iter, schemes) {
+ s = *s_iter;
+ printf("%s%s", sep, s->name);
+ sep = " ";
+ }
+ putchar('\n');
+ }
+}
+
+static void
+print_version(void)
+{
+ u_int width;
+
+#ifdef __LP64__
+ width = 64;
+#else
+ width = 32;
+#endif
+ printf("mkimg %u (%u-bit)\n", MKIMG_VERSION, width);
+}
+
+static void
+usage(const char *why)
+{
warnx("error: %s", why);
fprintf(stderr, "\nusage: %s <options>\n", getprogname());
@@ -82,17 +153,8 @@ usage(const char *why)
fprintf(stderr, "\t-S <num>\t- logical sector size\n");
fprintf(stderr, "\t-T <num>\t- number of tracks to simulate\n");
- fprintf(stderr, "\n formats:\n");
- SET_FOREACH(f_iter, formats) {
- f = *f_iter;
- fprintf(stderr, "\t%s\t- %s\n", f->name, f->description);
- }
-
- fprintf(stderr, "\n schemes:\n");
- SET_FOREACH(s_iter, schemes) {
- s = *s_iter;
- fprintf(stderr, "\t%s\t- %s\n", s->name, s->description);
- }
+ print_formats(1);
+ print_schemes(1);
fprintf(stderr, "\n partition specification:\n");
fprintf(stderr, "\t<t>[/<l>]::<size>\t- empty partition of given "
@@ -366,7 +428,8 @@ main(int argc, char *argv[])
bcfd = -1;
outfd = 1; /* Write to stdout by default */
- while ((c = getopt(argc, argv, "b:f:o:p:s:vyH:P:S:T:")) != -1) {
+ while ((c = getopt_long(argc, argv, "b:f:o:p:s:vyH:P:S:T:",
+ longopts, NULL)) != -1) {
switch (c) {
case 'b': /* BOOT CODE */
if (bcfd != -1)
@@ -432,6 +495,18 @@ main(int argc, char *argv[])
if (error)
errc(EX_DATAERR, error, "track size");
break;
+ case LONGOPT_FORMATS:
+ print_formats(0);
+ exit(EX_OK);
+ /*NOTREACHED*/
+ case LONGOPT_SCHEMES:
+ print_schemes(0);
+ exit(EX_OK);
+ /*NOTREACHED*/
+ case LONGOPT_VERSION:
+ print_version();
+ exit(EX_OK);
+ /*NOTREACHED*/
default:
usage("unknown option");
}
OpenPOWER on IntegriCloud