From 7e06d7bcbc39518d9984a07ab19116a9f050a176 Mon Sep 17 00:00:00 2001 From: Dima Dorfman Date: Thu, 22 Dec 2005 10:32:11 +0000 Subject: 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 --- sbin/mdconfig/mdconfig.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'sbin') diff --git a/sbin/mdconfig/mdconfig.c b/sbin/mdconfig/mdconfig.c index 03747aa13058..2064adf50f74 100644 --- a/sbin/mdconfig/mdconfig.c +++ b/sbin/mdconfig/mdconfig.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -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); -- cgit v1.2.3