4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
31 #include <libdevinfo.h>
36 (void) fprintf(stderr
,
37 "Usage: devprop [-n device-path] "
38 "[-vq] [-{b|i|l|s}] [property [...]]\n");
42 main(int argc
, char *argv
[])
45 boolean_t verbose
= B_FALSE
, quote
= B_FALSE
,
47 int type
= DI_PROP_TYPE_UNKNOWN
;
59 #define BOOL(ch, var) \
64 #define PER_OPT(ch, typ) \
66 if (type != DI_PROP_TYPE_UNKNOWN) { \
73 while ((c
= getopt(argc
, argv
, ":n:vqbils")) != -1) {
86 PER_OPT('b', DI_PROP_TYPE_BYTE
);
87 PER_OPT('i', DI_PROP_TYPE_INT
);
88 PER_OPT('l', DI_PROP_TYPE_INT64
);
89 PER_OPT('s', DI_PROP_TYPE_STRING
);
101 /* default to strings */
102 if (type
== DI_PROP_TYPE_UNKNOWN
)
103 type
= DI_PROP_TYPE_STRING
;
106 * It's convenient to use the filesystem as a source of device
107 * node paths. In that case, the path will be prefixed with
108 * "/devices", which we strip off here as di_init() expects
109 * just the path to the node.
111 if (strncmp("/devices/", path
, strlen("/devices/")) == 0)
112 path
+= strlen("/devices");
114 if ((dn
= di_init(path
, DINFOPROP
)) == DI_NODE_NIL
) {
119 /* Careful with that axe, Eugene... */
120 #define PER_TYPE(typ, func, val, incr, form, pv, sep) \
122 n = func(DDI_DEV_T_ANY, \
123 dn, argv[optind], &(val)); \
125 (void) printf((form), pv); \
129 (void) printf(sep); \
131 (void) printf("\n"); \
134 while (optind
< argc
) {
136 (void) printf("%s=", argv
[optind
]);
139 PER_TYPE(DI_PROP_TYPE_BYTE
, di_prop_lookup_bytes
,
140 val_b
, val_b
++, "%2.2x", *val_b
, ".");
141 PER_TYPE(DI_PROP_TYPE_INT
, di_prop_lookup_ints
,
142 val_i
, val_i
++, "%8.8x", *val_i
, ".");
143 PER_TYPE(DI_PROP_TYPE_INT64
, di_prop_lookup_int64
,
144 val_l
, val_l
++, "%16.16llx", *val_l
, ".");
145 PER_TYPE(DI_PROP_TYPE_STRING
, di_prop_lookup_strings
,
146 val_s
, val_s
+= strlen(val_s
) + 1,
147 (quote
? "\"%s\"" : "%s"), val_s
, " + ");