From 057b61aa1ca4ab4f1234f96ca5b7b913d408beda Mon Sep 17 00:00:00 2001 From: rwatson Date: Wed, 11 Jun 2003 06:38:24 +0000 Subject: 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). --- sbin/mdconfig/mdconfig.8 | 5 +++++ sbin/mdconfig/mdconfig.c | 16 +++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'sbin') diff --git a/sbin/mdconfig/mdconfig.8 b/sbin/mdconfig/mdconfig.8 index 5047015..a8a5a9a 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 0269fe9..263a942 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); -- cgit v1.1