I think this is a big improvement already, OK with me. It could do with a quick manpage mention, I think this is enough.
Index: usbdevs.8 =================================================================== RCS file: /cvs/src/usr.sbin/usbdevs/usbdevs.8,v retrieving revision 1.9 diff -u -p -r1.9 usbdevs.8 --- usbdevs.8 26 Jun 2008 05:42:21 -0000 1.9 +++ usbdevs.8 28 Jun 2018 11:50:16 -0000 @@ -55,6 +55,7 @@ Show the device drivers associated with Only print information for the given USB controller. .It Fl v Be verbose. +Multiple -v options increase the verbosity. .El .Sh FILES .Bl -tag -width Pa On 2018/06/28 13:31, Martin Pieuchot wrote: > My recent work to force USB devices to attach as ugen(4) [0] and Ilya's > work to enable/disable USB devices [1] have a lot in common. Now I'd > argue that we don't want new userland tool for these functionalities. > IMHO we should improve usbdevs(8). > > Sadly usbdevs(8) output is hard to read. So here's a first diff to > improve that. > > With the diff below '-v' can be specified multiple time and the 'port' > status of hub are only printed if verbose is > 1. That's similar to > pcidump(8)'s -xxx :) > > Like in pcidump(8) the USB "Controller" or bus, will now be displayed > unconditionally. This matters now that most computer have multiple > controllers and it is coherent with pcidump(8). > > This is just a first step :) > > Ok? > > [0] https://marc.info/?l=openbsd-tech&m=152457124405318&w=2 > [1] https://marc.info/?l=openbsd-tech&m=152996290828464&w=2 > > > Index: usbdevs.c > =================================================================== > RCS file: /cvs/src/usr.sbin/usbdevs/usbdevs.c,v > retrieving revision 1.25 > diff -u -p -r1.25 usbdevs.c > --- usbdevs.c 22 Dec 2015 08:36:40 -0000 1.25 > +++ usbdevs.c 28 Jun 2018 11:21:33 -0000 > @@ -30,15 +30,17 @@ > * POSSIBILITY OF SUCH DAMAGE. > */ > > +#include <sys/types.h> > +#include <dev/usb/usb.h> > + > +#include <err.h> > +#include <errno.h> > +#include <fcntl.h> > +#include <limits.h> > #include <stdio.h> > #include <stdlib.h> > #include <string.h> > -#include <sys/types.h> > -#include <fcntl.h> > #include <unistd.h> > -#include <err.h> > -#include <errno.h> > -#include <dev/usb/usb.h> > > #ifndef nitems > #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) > @@ -131,7 +133,7 @@ usbdev(int f, int a, int rec) > int s = di.udi_ports[p]; > > if (s >= USB_MAX_DEVICES) { > - if (verbose) { > + if (verbose > 1) { > printf("%*sport %d %s\n", indent+1, "", p+1, > s == USB_PORT_ENABLED ? "enabled" : > s == USB_PORT_SUSPENDED ? "suspended" : > @@ -143,7 +145,7 @@ usbdev(int f, int a, int rec) > } > indent++; > printf("%*s", indent, ""); > - if (verbose) > + if (verbose > 1) > printf("port %d ", p+1); > if (s == 0) > printf("addr 0 should never happen!\n"); > @@ -167,7 +169,7 @@ usbdump(int f) > void > dumpone(char *name, int f, int addr) > { > - if (verbose) > + if (!addr) > printf("Controller %s:\n", name); > indent = 0; > memset(done, 0, sizeof done); > @@ -201,7 +203,7 @@ main(int argc, char **argv) > dev = optarg; > break; > case 'v': > - verbose = 1; > + verbose++; > break; > default: > usage(); > @@ -210,6 +212,9 @@ main(int argc, char **argv) > argc -= optind; > argv += optind; > > + if (argc != 0) > + usage(); > + > if (dev == 0) { > for (ncont = 0, i = 0; i < 10; i++) { > snprintf(buf, sizeof buf, "%s%d", USBDEV, i); > @@ -229,10 +234,12 @@ main(int argc, char **argv) > __progname); > } else { > f = open(dev, O_RDONLY); > - if (f >= 0) > + if (f >= 0) { > dumpone(dev, f, addr); > - else > + close(f); > + } else > err(1, "%s", dev); > } > - exit(0); > + > + return 0; > } >
