4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1990 - 1997, Sun Microsystems, Inc.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * For machines that support the openprom, fetch and print the list
30 * of devices that the kernel has fetched from the prom or conjured up.
38 #include <libdevinfo.h>
40 static char *progname
= "sysdef";
41 extern int devflag
; /* SunOS4.x devinfo compatible output */
42 extern int drvname_flag
; /* print out the driver name too */
44 static int _error(char *opt_noperror
, ...);
45 static int dump_node(di_node_t node
, void *arg
);
52 /* take a snapshot of kernel devinfo tree */
53 if ((root_node
= di_init("/", DINFOSUBTREE
)) == DI_NODE_NIL
) {
54 exit(_error("di_init() failed."));
58 * ...and call di_walk_node to report it out...
60 di_walk_node(root_node
, DI_WALK_CLDFIRST
, NULL
, dump_node
);
66 * print out information about this node
69 dump_node(di_node_t node
, void *arg
)
76 /* find indent level */
78 while ((tmp
= di_parent_node(tmp
)) != DI_NODE_NIL
)
81 /* we would start at 0, except that we skip the root node */
85 for (i
= 0; i
< indent_level
; i
++)
88 if (indent_level
>= 0) {
91 * 4.x devinfo(8) compatible..
93 (void) printf("Node '%s', unit #%d",
97 if (driver_name
= di_driver_name(node
)) {
98 (void) printf(" (driver name: %s)",
101 } else if (di_state(node
) & DI_DRIVER_DETACHED
) {
102 (void) printf(" (no driver)");
106 * prtconf(1M) compatible..
108 (void) printf("%s", di_node_name(node
));
109 if (di_instance(node
) >= 0)
110 (void) printf(", instance #%d",
113 if (driver_name
= di_driver_name(node
)) {
114 (void) printf(" (driver name: %s)",
117 } else if (di_state(node
) & DI_DRIVER_DETACHED
) {
118 (void) printf(" (driver not attached)");
123 return (DI_WALK_CONTINUE
);
130 /* _error([no_perror, ] fmt [, arg ...]) */
132 _error(char *opt_noperror
, ...)
138 extern int errno
, _doprnt();
143 (void) fprintf(stderr
, "%s: ", progname
);
145 va_start(ap
, opt_noperror
);
146 if (opt_noperror
== NULL
) {
148 fmt
= va_arg(ap
, char *);
151 (void) _doprnt(fmt
, ap
, stderr
);
155 (void) fprintf(stderr
, "\n");
157 (void) fprintf(stderr
, ": ");