Teach bioctl(8) to resolve disks via duid. The realpath provided by opendev()
cannot be used since bioctl internally uses the volume name (e.g. "sd0")
rather than the full path to the device node. Mapping a duid to a volume
name with an extra BIOCVOL call is not pretty but works.

Index: bioctl.c
===================================================================
RCS file: /cvs/src/sbin/bioctl/bioctl.c,v
retrieving revision 1.109
diff -u -p -r1.109 bioctl.c
--- bioctl.c    22 Jan 2012 11:00:39 -0000      1.109
+++ bioctl.c    22 Apr 2012 22:57:11 -0000
@@ -95,7 +95,7 @@ main(int argc, char *argv[])
        extern char             *optarg;
        u_int64_t               func = 0;
        char                    *devicename = NULL;
-       char                    *realname = NULL, *al_arg = NULL;
+       char                    *al_arg = NULL;
        char                    *bl_arg = NULL, *dev_list = NULL;
        char                    *key_disk = NULL;
        const char              *errstr;
@@ -103,6 +103,7 @@ main(int argc, char *argv[])
        int                     ss_func = 0;
        u_int16_t               cr_level = 0;
        int                     biodev = 0;
+       struct bioc_vol         bv;
 
        if (argc < 2)
                usage();
@@ -210,7 +211,7 @@ main(int argc, char *argv[])
        if (devicename == NULL)
                errx(1, "need device");
 
-       devh = opendev(devicename, O_RDWR, OPENDEV_PART, &realname);
+       devh = opendev(devicename, O_RDWR, OPENDEV_PART, NULL);
        if (devh == -1) {
                devh = open("/dev/bio", O_RDWR);
                if (devh == -1)
@@ -225,6 +226,10 @@ main(int argc, char *argv[])
 
                biodev = 1;
                devicename = NULL;
+       } else if (isduid(devicename, OPENDEV_PART)) {
+               if (ioctl(devh, BIOCVOL, &bv))
+                       err(1, "BIOCVOL");
+               devicename = bv.bv_dev;
        }
 
        if (diskinq) {

Reply via email to