diff options
author | dd <dd@FreeBSD.org> | 2005-12-22 10:32:11 +0000 |
---|---|---|
committer | dd <dd@FreeBSD.org> | 2005-12-22 10:32:11 +0000 |
commit | 5ebe38d66780d5030bfbca6a38a7a71e9dc0f8a6 (patch) | |
tree | 4a0c42e2f5a77dfe8280748654f472ea6fe00d50 /sbin | |
parent | 546c2347deff7757b4ad366b80d9943ac1418adc (diff) | |
download | FreeBSD-src-5ebe38d66780d5030bfbca6a38a7a71e9dc0f8a6.zip FreeBSD-src-5ebe38d66780d5030bfbca6a38a7a71e9dc0f8a6.tar.gz |
Sort the list results by the unit number. The list returned by the
kernel is in the order the devices were made, which is not useful to
the user. Also, remove the "%d more" test since the kernel does not
return the complete count in md_pad[0] (maybe it should?).
Submitted by: Wojciech A. Koszek
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/mdconfig/mdconfig.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/sbin/mdconfig/mdconfig.c b/sbin/mdconfig/mdconfig.c index 03747aa..2064adf 100644 --- a/sbin/mdconfig/mdconfig.c +++ b/sbin/mdconfig/mdconfig.c @@ -19,6 +19,7 @@ #include <libutil.h> #include <string.h> #include <err.h> +#include <assert.h> #include <sys/ioctl.h> #include <sys/param.h> @@ -269,19 +270,28 @@ main(int argc, char **argv) return (0); } +static int +mdunitcmp(const void *a, const void *b) +{ + return (*(int *)a - *(int *)b); +} + int list(const int fd) { int unit; + int mdcount; 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++) { + mdcount = mdio.md_pad[0]; + assert(mdcount < MDNPAD - 1); + if (mdcount > 0) + qsort(&mdio.md_pad[1], mdcount, sizeof(mdio.md_pad[0]), mdunitcmp); + for (unit = 0; unit < mdcount; unit++) { 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); if (unit > 0) printf("\n"); return (0); |