aboutsummaryrefslogtreecommitdiff
path: root/sbin/mdconfig
diff options
context:
space:
mode:
authorDima Dorfman <dd@FreeBSD.org>2005-12-22 10:32:11 +0000
committerDima Dorfman <dd@FreeBSD.org>2005-12-22 10:32:11 +0000
commit7e06d7bcbc39518d9984a07ab19116a9f050a176 (patch)
tree4a0c42e2f5a77dfe8280748654f472ea6fe00d50 /sbin/mdconfig
parent0014abfcc412e5ed4440bb2577345b8c5a67e9dd (diff)
downloadsrc-7e06d7bcbc39518d9984a07ab19116a9f050a176.tar.gz
src-7e06d7bcbc39518d9984a07ab19116a9f050a176.zip
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
Notes
Notes: svn path=/head/; revision=153636
Diffstat (limited to 'sbin/mdconfig')
-rw-r--r--sbin/mdconfig/mdconfig.c16
1 files changed, 13 insertions, 3 deletions
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 <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);