summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2014-10-08 22:06:38 +0000
committermarcel <marcel@FreeBSD.org>2014-10-08 22:06:38 +0000
commit27db89ec695f2599ec2afd7010338235b49ea485 (patch)
tree4a5c3caf18e74c5aa5a5c8b7c5d6ab76e0f5a656
parent951d95ff86579b104209f34d7a07ff6d997657f4 (diff)
downloadFreeBSD-src-27db89ec695f2599ec2afd7010338235b49ea485.zip
FreeBSD-src-27db89ec695f2599ec2afd7010338235b49ea485.tar.gz
MFC 272198, 272217:
Add 3 long options (--version, --formats & --schemes) for getting information about mkimg itself. Requested by: gjb Relnotes: yes
-rw-r--r--usr.bin/mkimg/Makefile2
-rw-r--r--usr.bin/mkimg/mkimg.130
-rw-r--r--usr.bin/mkimg/mkimg.c115
3 files changed, 127 insertions, 20 deletions
diff --git a/usr.bin/mkimg/Makefile b/usr.bin/mkimg/Makefile
index 4e64aaa..bc7baed 100644
--- a/usr.bin/mkimg/Makefile
+++ b/usr.bin/mkimg/Makefile
@@ -4,6 +4,8 @@ PROG= mkimg
SRCS= format.c image.c mkimg.c scheme.c
MAN= mkimg.1
+MKIMG_VERSION=20140927
+CFLAGS+=-DMKIMG_VERSION=${MKIMG_VERSION}
CFLAGS+=-DSPARSE_WRITE
# List of formats to support
diff --git a/usr.bin/mkimg/mkimg.1 b/usr.bin/mkimg/mkimg.1
index db492ed..bfe05c0 100644
--- a/usr.bin/mkimg/mkimg.1
+++ b/usr.bin/mkimg/mkimg.1
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd September 12, 2014
+.Dd September 27, 2014
.Dt MKIMG 1
.Os
.Sh NAME
@@ -44,6 +44,8 @@
.Fl s Ar scheme
.Fl p Ar partition
.Op Fl p Ar partition ...
+.Nm
+.Ar --formats | --schemes | --version
.Sh DESCRIPTION
The
.Nm
@@ -122,10 +124,32 @@ utility will generate predictable values for Universally Unique Identifiers
.Nm
utility will create images that are identical.
.Pp
-For a complete list of supported partitioning schemes or supported output
-format, or for a detailed description of how to specify partitions, run the
+A set of long options exist to query about the
+.Nm
+utilty itself.
+Options in this set should be given by themselves because the
+.Nm
+utility exits immediately after providing the requested information.
+The version of the
+.Nm
+utility is printed when the
+.Ar --version
+option is given.
+The list of supported output formats is printed when the
+.Ar --formats
+option is given and the list of supported partitioning schemes is printed
+when the
+.Ar --schemes
+option is given.
+Both the format and scheme lists a space-separated lists for easy handling
+in scripts.
+.Pp
+For a more descriptive list of supported partitioning schemes or supported
+output format, or for a detailed description of how to specify partitions,
+run the
.Nm
utility without any arguments.
+This will print a usage message with all the necessary details.
.Sh ENVIRONMENT
.Bl -tag -width "TMPDIR" -compact
.It Ev TMPDIR
diff --git a/usr.bin/mkimg/mkimg.c b/usr.bin/mkimg/mkimg.c
index ab95d94..d054423 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,15 +73,79 @@ 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, " 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, " 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());
+ fputc('\n', stderr);
+ fprintf(stderr, "usage: %s <options>\n", getprogname());
fprintf(stderr, " options:\n");
+ fprintf(stderr, "\t--formats\t- list image formats\n");
+ fprintf(stderr, "\t--schemes\t- list partition schemes\n");
+ fprintf(stderr, "\t--version\t- show version information\n");
+ fputc('\n', stderr);
fprintf(stderr, "\t-b <file>\t- file containing boot code\n");
fprintf(stderr, "\t-f <format>\n");
fprintf(stderr, "\t-o <file>\t- file to write image into\n");
@@ -81,20 +157,12 @@ usage(const char *why)
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, "\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);
- }
-
- fprintf(stderr, "\n partition specification:\n");
+ fputc('\n', stderr);
+ print_formats(1);
+ fputc('\n', stderr);
+ print_schemes(1);
+ fputc('\n', stderr);
+ fprintf(stderr, " partition specification:\n");
fprintf(stderr, "\t<t>[/<l>]::<size>\t- empty partition of given "
"size\n");
fprintf(stderr, "\t<t>[/<l>]:=<file>\t- partition content and size "
@@ -366,7 +434,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 +501,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