Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/vnconfig Since now the kernel returns ENXIO again f...



details:   https://anonhg.NetBSD.org/src/rev/79b2dbc7cae5
branches:  trunk
changeset: 341515:79b2dbc7cae5
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Nov 09 17:39:20 2015 +0000

description:
Since now the kernel returns ENXIO again for devices exceeding the
number of devices configured in the kernel, use that instead of
scanning /dev.
XXX: pullup to 7 together with the kernel change.

diffstat:

 usr.sbin/vnconfig/vnconfig.c |  40 ++++++++++++----------------------------
 1 files changed, 12 insertions(+), 28 deletions(-)

diffs (97 lines):

diff -r fd796778ca29 -r 79b2dbc7cae5 usr.sbin/vnconfig/vnconfig.c
--- a/usr.sbin/vnconfig/vnconfig.c      Mon Nov 09 16:54:26 2015 +0000
+++ b/usr.sbin/vnconfig/vnconfig.c      Mon Nov 09 17:39:20 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vnconfig.c,v 1.42 2014/05/23 20:50:16 dholland Exp $   */
+/*     $NetBSD: vnconfig.c,v 1.43 2015/11/09 17:39:20 christos Exp $   */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -73,13 +73,11 @@
 #include <sys/buf.h>
 #include <sys/disklabel.h>
 #include <sys/disk.h>
-#include <sys/bitops.h>
 
 #include <dev/vndvar.h>
 
 #include <disktab.h>
 #include <err.h>
-#include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stddef.h>
@@ -100,7 +98,7 @@
 static int     compressed = 0;
 static char    *tabname;
 
-static void    show(int, int);
+static int     show(int, int);
 static int     config(char *, char *, char *, int);
 static int     getgeom(struct vndgeom *, char *);
 __dead static void     usage(void);
@@ -177,26 +175,8 @@
                if (argc)
                        show(v, -1);
                else {
-                       DIR *dirp;
-                       struct dirent *dp;
-                       __BITMAP_TYPE(, uint32_t, 65536) bm;
-
-                       __BITMAP_ZERO(&bm);
-
-                       if ((dirp = opendir(_PATH_DEV)) == NULL)
-                               err(1, "opendir: %s", _PATH_DEV);
-
-                       while ((dp = readdir(dirp)) != NULL) {
-                               if (strncmp(dp->d_name, "rvnd", 4) != 0)
-                                       continue;
-                               n = atoi(dp->d_name + 4);
-                               if (__BITMAP_ISSET(n, &bm))
-                                       continue;
-                               __BITMAP_SET(n, &bm);
-                               show(v, n);
-                       }
-
-                       closedir(dirp);
+                       for (n = 0; show(v, n); n++)
+                               continue;
                }
                close(v);
                rv = 0;
@@ -204,7 +184,7 @@
        return rv;
 }
 
-static void
+static int
 show(int v, int n)
 {
        struct vnd_user vnu;
@@ -213,12 +193,15 @@
        int i, nmount;
 
        vnu.vnu_unit = n;
-       if (ioctl(v, VNDIOCGET, &vnu) == -1)
-               err(1, "VNDIOCGET");
+       if (ioctl(v, VNDIOCGET, &vnu) == -1) {
+               if (errno != ENXIO)
+                       err(1, "VNDIOCGET");
+               return 0;
+       }
 
        if (vnu.vnu_ino == 0) {
                printf("vnd%d: not in use\n", vnu.vnu_unit);
-               return;
+               return 1;
        }
 
        printf("vnd%d: ", vnu.vnu_unit);
@@ -251,6 +234,7 @@
                    (unsigned long long)minor(vnu.vnu_dev));
 
        printf("inode %llu\n", (unsigned long long)vnu.vnu_ino);
+       return 1;
 }
 
 static int



Home | Main Index | Thread Index | Old Index