Implement "-p dev" to print the path to the given device back to the
nexus. With redirection, could also be used to test if the device exists in the device tree. Sponsored by: Netflix
This commit is contained in:
parent
9e33a61693
commit
3386009737
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=327066
@ -38,6 +38,8 @@
|
|||||||
.Op Fl rv
|
.Op Fl rv
|
||||||
.Nm
|
.Nm
|
||||||
.Fl u
|
.Fl u
|
||||||
|
.Nm
|
||||||
|
.Fl p dev
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Nm
|
.Nm
|
||||||
@ -62,6 +64,8 @@ the IRQ consumers together.
|
|||||||
Display all devices in the driver tree, not just those that are attached or
|
Display all devices in the driver tree, not just those that are attached or
|
||||||
busy.
|
busy.
|
||||||
Without this flag, only those devices that have attached are reported.
|
Without this flag, only those devices that have attached are reported.
|
||||||
|
.It Fl p dev
|
||||||
|
Display the path of dev back to the root of the device tree.
|
||||||
.El
|
.El
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr systat 1 ,
|
.Xr systat 1 ,
|
||||||
|
@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "devinfo.h"
|
#include "devinfo.h"
|
||||||
|
|
||||||
@ -196,15 +197,47 @@ print_rman(struct devinfo_rman *rman, void *arg __unused)
|
|||||||
return(0);
|
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)
|
||||||
|
{
|
||||||
|
const char *name = xname;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
if (strcmp(dev->dd_name, name) == 0) {
|
||||||
|
printf("%s", dev->dd_name);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
rv = devinfo_foreach_device_child(dev, print_path, xname);
|
||||||
|
if (rv == 1)
|
||||||
|
printf(" %s", dev->dd_name[0] ? dev->dd_name : "unknown");
|
||||||
|
return (rv);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct devinfo_dev *root;
|
struct devinfo_dev *root;
|
||||||
int c, uflag;
|
int c, uflag;
|
||||||
|
char *path;
|
||||||
|
|
||||||
uflag = 0;
|
uflag = 0;
|
||||||
while ((c = getopt(argc, argv, "ruv")) != -1) {
|
while ((c = getopt(argc, argv, "p:ruv")) != -1) {
|
||||||
switch(c) {
|
switch(c) {
|
||||||
|
case 'p':
|
||||||
|
path = optarg;
|
||||||
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
rflag++;
|
rflag++;
|
||||||
break;
|
break;
|
||||||
@ -215,21 +248,25 @@ main(int argc, char *argv[])
|
|||||||
vflag++;
|
vflag++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "%s\n%s\n",
|
usage();
|
||||||
"usage: devinfo [-rv]",
|
|
||||||
" devinfo -u");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (path && (rflag || uflag))
|
||||||
|
usage();
|
||||||
|
|
||||||
if (devinfo_init())
|
if (devinfo_init())
|
||||||
err(1, "devinfo_init");
|
err(1, "devinfo_init");
|
||||||
|
|
||||||
if ((root = devinfo_handle_to_device(DEVINFO_ROOT_DEVICE)) == NULL)
|
if ((root = devinfo_handle_to_device(DEVINFO_ROOT_DEVICE)) == NULL)
|
||||||
errx(1, "can't find root device");
|
errx(1, "can't find root device");
|
||||||
|
|
||||||
/* print resource usage? */
|
if (path) {
|
||||||
if (uflag) {
|
if (devinfo_foreach_device_child(root, print_path, (void *)path) == 0)
|
||||||
|
errx(1, "%s: Not found", path);
|
||||||
|
printf("\n");
|
||||||
|
} else if (uflag) {
|
||||||
|
/* print resource usage? */
|
||||||
devinfo_foreach_rman(print_rman, NULL);
|
devinfo_foreach_rman(print_rman, NULL);
|
||||||
} else {
|
} else {
|
||||||
/* print device hierarchy */
|
/* print device hierarchy */
|
||||||
|
Loading…
Reference in New Issue
Block a user