diff options
author | Pedro Martelletto <pedro@cvs.openbsd.org> | 2004-06-20 18:04:55 +0000 |
---|---|---|
committer | Pedro Martelletto <pedro@cvs.openbsd.org> | 2004-06-20 18:04:55 +0000 |
commit | 873ad064c822ac7fef1a1fb072d59a9879caff11 (patch) | |
tree | 0c107fed911771aa6f16b5ab57d26f7611759130 /usr.sbin | |
parent | eeba73d47cf7d6e74006ac0a29476841e78afee2 (diff) |
make vnconfig use the new VNDIOCGET ioctl to retrieve information about
the status of vnode disks, ok millert@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/vnconfig/vnconfig.c | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/usr.sbin/vnconfig/vnconfig.c b/usr.sbin/vnconfig/vnconfig.c index 2e1d8caf10a..6fada1a6645 100644 --- a/usr.sbin/vnconfig/vnconfig.c +++ b/usr.sbin/vnconfig/vnconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vnconfig.c,v 1.12 2003/06/24 23:26:58 millert Exp $ */ +/* $OpenBSD: vnconfig.c,v 1.13 2004/06/20 18:04:54 pedro Exp $ */ /* * Copyright (c) 1993 University of Utah. * Copyright (c) 1990, 1993 @@ -40,6 +40,7 @@ #include <sys/param.h> #include <sys/ioctl.h> #include <sys/mount.h> +#include <sys/stat.h> #include <dev/vndioctl.h> @@ -53,13 +54,17 @@ #include <unistd.h> #include <util.h> +#define DEFAULT_VND "vnd0" + #define VND_CONFIG 1 #define VND_UNCONFIG 2 +#define VND_GET 3 int verbose = 0; __dead void usage(void); int config(char *, char *, int, char *); +int getinfo(const char *); int main(int argc, char **argv) @@ -67,11 +72,14 @@ main(int argc, char **argv) int ch, rv, action = VND_CONFIG; char *key = NULL; - while ((ch = getopt(argc, argv, "cuvk")) != -1) { + while ((ch = getopt(argc, argv, "cluvk")) != -1) { switch (ch) { case 'c': action = VND_CONFIG; break; + case 'l': + action = VND_GET; + break; case 'u': action = VND_UNCONFIG; break; @@ -86,6 +94,7 @@ main(int argc, char **argv) /* NOTREACHED */ } } + argc -= optind; argv += optind; @@ -93,12 +102,56 @@ main(int argc, char **argv) rv = config(argv[0], argv[1], action, key); else if (action == VND_UNCONFIG && argc == 1) rv = config(argv[0], NULL, action, key); + else if (action == VND_GET) + rv = getinfo(argc ? argv[0] : NULL); else usage(); + exit(rv); } int +getinfo(const char *vname) +{ + int vd, print_all = 0; + struct vnd_user vnu; + + if (vname == NULL) { + vname = DEFAULT_VND; + print_all = 1; + } + + vd = opendev(vname, O_RDONLY, OPENDEV_PART, NULL); + if (vd < 0) + err(1, "open: %s", vname); + + vnu.vnu_unit = -1; + +query: + if (ioctl(vd, VNDIOCGET, &vnu) == -1) { + close(vd); + return (!(errno == ENXIO && print_all)); + } + + fprintf(stdout, "vnd%d: ", vnu.vnu_unit); + + if (!vnu.vnu_ino) + fprintf(stdout, "not in use\n"); + else + fprintf(stdout, "covering %s on %s, inode %d\n", vnu.vnu_file, + devname(vnu.vnu_dev, S_IFBLK), vnu.vnu_ino); + + if (print_all) { + vnu.vnu_unit++; + goto query; + } + + close(vd); + + return (0); +} + +int config(char *dev, char *file, int action, char *key) { struct vnd_ioctl vndio; |