Print this page
6992 devprop(1M) should work also with logical names
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/devprop/devprop.c
+++ new/usr/src/cmd/devprop/devprop.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 -#pragma ident "%Z%%M% %I% %E% SMI"
27 26
28 27 #include <stdio.h>
29 28 #include <unistd.h>
30 29 #include <strings.h>
31 30 #include <libdevinfo.h>
32 31
33 32 static void
34 33 usage(void)
35 34 {
36 35 (void) fprintf(stderr,
37 36 "Usage: devprop [-n device-path] "
38 37 "[-vq] [-{b|i|l|s}] [property [...]]\n");
39 38 }
40 39
41 40 int
42 41 main(int argc, char *argv[])
↓ open down ↓ |
6 lines elided |
↑ open up ↑ |
43 42 {
44 43 int c;
45 44 boolean_t verbose = B_FALSE, quote = B_FALSE,
46 45 error = B_FALSE;
47 46 int type = DI_PROP_TYPE_UNKNOWN;
48 47 char *path = "/";
49 48 di_node_t dn;
50 49 uchar_t *val_b;
51 50 int *val_i;
52 51 int64_t *val_l;
53 - char *val_s;
52 + char *val_s, *ptr;
54 53 int n;
55 54
56 55 extern char *optarg;
57 56 extern int optind;
58 57
59 58 #define BOOL(ch, var) \
60 59 case ch: \
61 60 var = B_TRUE; \
62 61 break
63 62
64 63 #define PER_OPT(ch, typ) \
65 64 case ch: \
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
66 65 if (type != DI_PROP_TYPE_UNKNOWN) { \
67 66 usage(); \
68 67 return (1); \
69 68 } \
70 69 type = (typ); \
71 70 break
72 71
73 72 while ((c = getopt(argc, argv, ":n:vqbils")) != -1) {
74 73 switch (c) {
75 74 case 'n':
76 - path = optarg;
75 + if ((path = realpath(optarg, NULL)) == NULL)
76 + path = optarg;
77 77 break;
78 78 case ':':
79 79 usage();
80 80 return (1);
81 81
82 82 BOOL('v', verbose);
83 83 BOOL('q', quote);
84 84 BOOL('?', error);
85 85
86 86 PER_OPT('b', DI_PROP_TYPE_BYTE);
87 87 PER_OPT('i', DI_PROP_TYPE_INT);
88 88 PER_OPT('l', DI_PROP_TYPE_INT64);
89 89 PER_OPT('s', DI_PROP_TYPE_STRING);
90 90 }
91 91 }
92 92
93 93 #undef BOOL
94 94 #undef PER_OPT
95 95
96 96 if (error) {
97 97 usage();
98 98 return (1);
99 99 }
100 100
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
101 101 /* default to strings */
102 102 if (type == DI_PROP_TYPE_UNKNOWN)
103 103 type = DI_PROP_TYPE_STRING;
104 104
105 105 /*
106 106 * It's convenient to use the filesystem as a source of device
107 107 * node paths. In that case, the path will be prefixed with
108 108 * "/devices", which we strip off here as di_init() expects
109 109 * just the path to the node.
110 110 */
111 - if (strncmp("/devices/", path, strlen("/devices/")) == 0)
111 + if (strncmp("/devices/", path, strlen("/devices/")) == 0) {
112 112 path += strlen("/devices");
113 113
114 + /* cut off minor name */
115 + if ((ptr = strrchr(path, ':')) != NULL)
116 + *ptr = '\0';
117 + }
118 +
114 119 if ((dn = di_init(path, DINFOPROP)) == DI_NODE_NIL) {
115 120 perror("di_init");
116 121 return (1);
117 122 }
118 123
119 124 /* Careful with that axe, Eugene... */
120 125 #define PER_TYPE(typ, func, val, incr, form, pv, sep) \
121 126 case (typ): \
122 127 n = func(DDI_DEV_T_ANY, \
123 128 dn, argv[optind], &(val)); \
124 129 while (n > 0) { \
125 130 (void) printf((form), pv); \
126 131 incr; \
127 132 n--; \
128 133 if (n > 0) \
129 134 (void) printf(sep); \
130 135 } \
131 136 (void) printf("\n"); \
132 137 break
133 138
134 139 while (optind < argc) {
135 140 if (verbose)
136 141 (void) printf("%s=", argv[optind]);
137 142
138 143 switch (type) {
139 144 PER_TYPE(DI_PROP_TYPE_BYTE, di_prop_lookup_bytes,
140 145 val_b, val_b++, "%2.2x", *val_b, ".");
141 146 PER_TYPE(DI_PROP_TYPE_INT, di_prop_lookup_ints,
142 147 val_i, val_i++, "%8.8x", *val_i, ".");
143 148 PER_TYPE(DI_PROP_TYPE_INT64, di_prop_lookup_int64,
144 149 val_l, val_l++, "%16.16llx", *val_l, ".");
145 150 PER_TYPE(DI_PROP_TYPE_STRING, di_prop_lookup_strings,
146 151 val_s, val_s += strlen(val_s) + 1,
147 152 (quote ? "\"%s\"" : "%s"), val_s, " + ");
148 153 }
149 154
150 155 optind++;
151 156 }
152 157
153 158 #undef PER_TYPE
154 159
155 160 di_fini(dn);
156 161
157 162 return (0);
158 163 }
↓ open down ↓ |
35 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX