Hi guys,
Below is a revised patch (should be unmangled this time) that adds an -f
option to print the first unused vnd_dev, fixed style nits and unbroken
getopt. hat tip to Theo Buehler for pointers:
Index: sbin/mount_vnd/mount_vnd.8
===================================================================
RCS file: /cvs/src/sbin/mount_vnd/mount_vnd.8,v
retrieving revision 1.21
diff -u -p -r1.21 mount_vnd.8
--- sbin/mount_vnd/mount_vnd.8 30 May 2014 16:53:02 -0000 1.21
+++ sbin/mount_vnd/mount_vnd.8 3 May 2017 01:50:13 -0000
@@ -164,6 +164,10 @@ List the vnd devices and indicate which
If a specific
.Ar vnd_dev
is given, then only that one will be described.
+.It Fl f
+.Nm vnconfig
+only.
+Print the first unused vnode device to stdout.
.It Fl o Ar options
.Nm mount_vnd
only.
Index: sbin/mount_vnd/mount_vnd.c
===================================================================
RCS file: /cvs/src/sbin/mount_vnd/mount_vnd.c,v
retrieving revision 1.20
diff -u -p -r1.20 mount_vnd.c
--- sbin/mount_vnd/mount_vnd.c 24 Jan 2016 06:32:33 -0000 1.20
+++ sbin/mount_vnd/mount_vnd.c 3 May 2017 01:50:13 -0000
@@ -62,6 +62,7 @@
#define VND_CONFIG 1
#define VND_UNCONFIG 2
#define VND_GET 3
+#define VND_FIND 4
int verbose = 0;
int run_mount_vnd = 0;
@@ -70,12 +71,13 @@ __dead void usage(void);
int config(char *, char *, int, struct disklabel *, char *,
size_t);
int getinfo(const char *);
+int findfirst(void);
char *get_pkcs_key(char *, char *);
int
main(int argc, char **argv)
{
- int ch, rv, action, opt_c, opt_k, opt_K, opt_l, opt_u;
+ int ch, rv, action, opt_c, opt_f, opt_k, opt_K, opt_l, opt_u;
char *key, *mntopts, *rounds, *saltopt;
size_t keylen = 0;
extern char *__progname;
@@ -84,15 +86,18 @@ main(int argc, char **argv)
if (strcasecmp(__progname, "mount_vnd") == 0)
run_mount_vnd = 1;
- opt_c = opt_k = opt_K = opt_l = opt_u = 0;
+ opt_c = opt_f = opt_k = opt_K = opt_l = opt_u = 0;
key = mntopts = rounds = saltopt = NULL;
action = VND_CONFIG;
- while ((ch = getopt(argc, argv, "ckK:lo:S:t:uv")) != -1) {
+ while ((ch = getopt(argc, argv, "cfkK:lo:S:t:uv")) != -1) {
switch (ch) {
case 'c':
opt_c = 1;
break;
+ case 'f':
+ opt_f = 1;
+ break;
case 'k':
opt_k = 1;
break;
@@ -128,10 +133,12 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
- if (opt_c + opt_l + opt_u > 1)
- errx(1, "-c, -l and -u are mutually exclusive options");
+ if (opt_c + opt_f + opt_l + opt_u > 1)
+ errx(1, "-c, -f, -l and -u are mutually exclusive options");
- if (opt_l)
+ if (opt_f)
+ action = VND_FIND;
+ else if (opt_l)
action = VND_GET;
else if (opt_u)
action = VND_UNCONFIG;
@@ -173,6 +180,8 @@ main(int argc, char **argv)
rv = config(argv[0], NULL, action, NULL, NULL, 0);
else if (action == VND_GET)
rv = getinfo(argc ? argv[0] : NULL);
+ else if (action == VND_FIND)
+ rv = findfirst();
else
usage();
@@ -293,6 +302,34 @@ query:
}
int
+findfirst(void)
+{
+ char *vname = DEFAULT_VND;
+ int vd;
+ struct vnd_user vnu;
+
+ vd = opendev((char *)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)
+ err(1, "ioctl: %s", vname);
+
+ if (!vnu.vnu_ino)
+ fprintf(stdout, "vnd%d\n", vnu.vnu_unit);
+ else {
+ vnu.vnu_unit++;
+ goto query;
+ }
+
+ close(vd);
+ return (0);
+}
+
+int
config(char *dev, char *file, int action, struct disklabel *dp, char *key,
size_t keylen)
{
@@ -354,7 +391,7 @@ usage(void)
"\t\t image vnd_dev\n");
else
(void)fprintf(stderr,
- "usage: %s [-ckluv] [-K rounds] [-S saltfile] "
+ "usage: %s [-cfkluv] [-K rounds] [-S saltfile] "
"[-t disktype] vnd_dev image\n", __progname);
exit(1);