From b68de8941f7be489a320b9d91ec61852d74f4f9d Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Thu, 21 Dec 2017 19:19:43 +0000 Subject: When -v is specified with -p dev, print the same verbose output as when listing the whole tree. The list, however, is from the requested device to the root (so it backwards from the normal tree). Sponsored by: Netflix --- usr.sbin/devinfo/devinfo.8 | 3 ++- usr.sbin/devinfo/devinfo.c | 64 ++++++++++++++++++++++++++++------------------ 2 files changed, 41 insertions(+), 26 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/devinfo/devinfo.8 b/usr.sbin/devinfo/devinfo.8 index 7b264d903d59..72fd73dba82c 100644 --- a/usr.sbin/devinfo/devinfo.8 +++ b/usr.sbin/devinfo/devinfo.8 @@ -39,7 +39,7 @@ .Nm .Fl u .Nm -.Fl p Ar dev +.Fl p Ar dev Op Fl v .Sh DESCRIPTION The .Nm @@ -64,6 +64,7 @@ the IRQ consumers together. Display all devices in the driver tree, not just those that are attached or busy. Without this flag, only those devices that have attached are reported. +This flag also displays verbose information about each device. .It Fl p Ar dev Display the path of .Ar dev diff --git a/usr.sbin/devinfo/devinfo.c b/usr.sbin/devinfo/devinfo.c index 5bc97fe8acef..c4ec2eeccfd0 100644 --- a/usr.sbin/devinfo/devinfo.c +++ b/usr.sbin/devinfo/devinfo.c @@ -131,6 +131,22 @@ print_device_rman_resources(struct devinfo_rman *rman, void *arg) return(0); } +static void +print_dev(struct devinfo_dev *dev) +{ + + printf("%s", dev->dd_name[0] ? dev->dd_name : "unknown"); + if (vflag && *dev->dd_pnpinfo) + printf(" pnpinfo %s", dev->dd_pnpinfo); + if (vflag && *dev->dd_location) + printf(" at %s", dev->dd_location); + if (!(dev->dd_flags & DF_ENABLED)) + printf(" (disabled)"); + else if (dev->dd_flags & DF_SUSPENDED) + printf(" (suspended)"); +} + + /* * Print information about a device. */ @@ -144,15 +160,7 @@ print_device(struct devinfo_dev *dev, void *arg) indent = (int)(intptr_t)arg; for (i = 0; i < indent; i++) printf(" "); - printf("%s", dev->dd_name[0] ? dev->dd_name : "unknown"); - if (vflag && *dev->dd_pnpinfo) - printf(" pnpinfo %s", dev->dd_pnpinfo); - if (vflag && *dev->dd_location) - printf(" at %s", dev->dd_location); - if (!(dev->dd_flags & DF_ENABLED)) - printf(" (disabled)"); - else if (dev->dd_flags & DF_SUSPENDED) - printf(" (suspended)"); + print_dev(dev); printf("\n"); if (rflag) { ia.indent = indent + 4; @@ -197,17 +205,6 @@ print_rman(struct devinfo_rman *rman, void *arg __unused) return(0); } -static void __dead2 -usage(void) -{ - fprintf(stderr, "%s\n%s\n%s\n", - "usage: devinfo [-rv]", - " devinfo -u", - " devifno -p dev"); - exit(1); -} - - static int print_path(struct devinfo_dev *dev, void *xname) { @@ -215,22 +212,38 @@ print_path(struct devinfo_dev *dev, void *xname) int rv; if (strcmp(dev->dd_name, name) == 0) { - printf("%s", dev->dd_name); + print_dev(dev); + if (vflag) + printf("\n"); return (1); } rv = devinfo_foreach_device_child(dev, print_path, xname); - if (rv == 1) - printf(" %s", dev->dd_name[0] ? dev->dd_name : "unknown"); + if (rv == 1) { + printf(" "); + print_dev(dev); + if (vflag) + printf("\n"); + } return (rv); } +static void __dead2 +usage(void) +{ + fprintf(stderr, "%s\n%s\n%s\n", + "usage: devinfo [-rv]", + " devinfo -u", + " devifno -p dev [-v]"); + exit(1); +} + int main(int argc, char *argv[]) { struct devinfo_dev *root; int c, uflag; - char *path; + char *path = NULL; uflag = 0; while ((c = getopt(argc, argv, "p:ruv")) != -1) { @@ -264,7 +277,8 @@ main(int argc, char *argv[]) if (path) { if (devinfo_foreach_device_child(root, print_path, (void *)path) == 0) errx(1, "%s: Not found", path); - printf("\n"); + if (!vflag) + printf("\n"); } else if (uflag) { /* print resource usage? */ devinfo_foreach_rman(print_rman, NULL); -- cgit v1.2.3