diff options
author | Robert Watson <rwatson@FreeBSD.org> | 2003-06-11 06:38:24 +0000 |
---|---|---|
committer | Robert Watson <rwatson@FreeBSD.org> | 2003-06-11 06:38:24 +0000 |
commit | f79c46d3f4669e243574e046e718c1edec91fe6c (patch) | |
tree | 13871376fc71754261a513a8ba381814ddf1acd3 | |
parent | 7ddc2528b7328729b8af37c8fc614cb37dafcecd (diff) | |
download | src-f79c46d3f4669e243574e046e718c1edec91fe6c.tar.gz src-f79c46d3f4669e243574e046e718c1edec91fe6c.zip |
Add "-n" argument, which causes mdconfig to simply print the unit
number X, rather than mdX, making it easier to script tests that
use md devices but don't want to make assumptions about any existing
md use (such as in diskless environments).
Notes
Notes:
svn path=/head/; revision=116194
-rw-r--r-- | sbin/mdconfig/mdconfig.8 | 5 | ||||
-rw-r--r-- | sbin/mdconfig/mdconfig.c | 16 |
2 files changed, 16 insertions, 5 deletions
diff --git a/sbin/mdconfig/mdconfig.8 b/sbin/mdconfig/mdconfig.8 index 50470155427d..a8a5a9ae9c20 100644 --- a/sbin/mdconfig/mdconfig.8 +++ b/sbin/mdconfig/mdconfig.8 @@ -51,6 +51,7 @@ .Nm .Fl a .Fl t Ar type +.Op Fl n .Oo .Fl o .Oo Cm no Oc Ns Ar option @@ -64,6 +65,7 @@ .Fl u Ar unit .Nm .Fl l +.Op Fl n .Op Fl u Ar unit .Sh DESCRIPTION The @@ -103,6 +105,9 @@ devices. If the .Fl u option is used in conjuction with this, the output is limited to information on the specified device. +.It Fl n +When printing md device names, print only the unit number without the +md prefix. .It Fl s Ar size Size of the memory disk. .Ar Size diff --git a/sbin/mdconfig/mdconfig.c b/sbin/mdconfig/mdconfig.c index 0269fe943d4f..263a94214f6f 100644 --- a/sbin/mdconfig/mdconfig.c +++ b/sbin/mdconfig/mdconfig.c @@ -33,13 +33,15 @@ struct md_ioctl mdio; enum {UNSET, ATTACH, DETACH, LIST} action = UNSET; +int nflag; + void usage() { fprintf(stderr, "usage:\n"); - fprintf(stderr, "\tmdconfig -a -t type [-o [no]option]... [ -f file] [-s size] [-S sectorsize] [-u unit]\n"); + fprintf(stderr, "\tmdconfig -a -t type [-n] [-o [no]option]... [ -f file] [-s size] [-S sectorsize] [-u unit]\n"); fprintf(stderr, "\tmdconfig -d -u unit\n"); - fprintf(stderr, "\tmdconfig -l [-u unit]\n"); + fprintf(stderr, "\tmdconfig -l [-n] [-u unit]\n"); fprintf(stderr, "\t\ttype = {malloc, preload, vnode, swap}\n"); fprintf(stderr, "\t\toption = {cluster, compress, reserve}\n"); fprintf(stderr, "\t\tsize = %%d (512 byte blocks), %%dk (kB), %%dm (MB) or %%dg (GB)\n"); @@ -54,7 +56,7 @@ main(int argc, char **argv) int cmdline = 0; for (;;) { - ch = getopt(argc, argv, "ab:df:lo:s:S:t:u:x:y:"); + ch = getopt(argc, argv, "ab:df:lno:s:S:t:u:x:y:"); if (ch == -1) break; switch (ch) { @@ -78,6 +80,9 @@ main(int argc, char **argv) mdio.md_options = MD_AUTOUNIT; cmdline = 3; break; + case 'n': + nflag = 1; + break; case 't': if (cmdline != 1) usage(); @@ -202,7 +207,7 @@ main(int argc, char **argv) if (i < 0) err(1, "ioctl(/dev/%s)", MDCTL_NAME); if (mdio.md_options & MD_AUTOUNIT) - printf("%s%d\n", MD_NAME, mdio.md_unit); + printf("%s%d\n", nflag ? "" : MD_NAME, mdio.md_unit); } else if (action == DETACH) { if (mdio.md_options & MD_AUTOUNIT) usage(); @@ -230,7 +235,8 @@ list(const int fd) if (ioctl(fd, MDIOCLIST, &mdio) < 0) err(1, "ioctl(/dev/%s)", MDCTL_NAME); for (unit = 0; unit < mdio.md_pad[0] && unit < MDNPAD - 1; unit++) { - printf("%smd%d", unit > 0 ? " " : "", mdio.md_pad[unit + 1]); + printf("%s%s%d", unit > 0 ? " " : "", + nflag ? "" : MD_NAME, mdio.md_pad[unit + 1]); } if (mdio.md_pad[0] - unit > 0) printf(" ... %d more", mdio.md_pad[0] - unit); |