7 * with the License.
8 *
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.
13 *
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]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 #include "ndievents.h"
30 #include <sys/sunndi.h>
31 #include <sys/ndi_impldefs.h>
32 #include <sys/dditypes.h>
33 #include <sys/ddi_impldefs.h>
34 #include <sys/sunddi.h>
35 #include <sys/param.h>
36
37
38 int
39 dip_to_pathname(struct dev_info *device, char *path, int buflen) {
40
41 char *bp;
42 char *addr;
43 char addr_str[32];
44 char nodename[MAXNAMELEN];
45 struct dev_info devi_parent;
46
47 if (!device) {
63 return (0);
64 }
65
66 if (mdb_vread(&devi_parent, sizeof (struct dev_info),
67 (uintptr_t)device->devi_parent) == -1) {
68 mdb_warn("Unable to access devi_parent at %p",
69 (uintptr_t)device->devi_parent);
70 return (-1);
71 }
72
73 if (dip_to_pathname(&devi_parent, path, buflen) == -1) {
74 return (-1);
75 }
76
77 if (mdb_readstr(nodename, sizeof (nodename),
78 (uintptr_t)device->devi_node_name) == -1) {
79 return (-1);
80 }
81
82 if (device->devi_node_state < DS_INITIALIZED) {
83 strncpy(addr_str, '\0', sizeof ('\0'));
84 } else {
85 addr = device->devi_addr;
86 if (mdb_readstr(addr_str, sizeof (addr_str),
87 (uintptr_t)addr) == -1) {
88 return (-1);
89 }
90 }
91
92 bp = path + strlen(path);
93
94 if (addr_str[0] == '\0') {
95 (void) mdb_snprintf(bp, buflen - strlen(path), "/%s", nodename);
96 } else {
97 (void) mdb_snprintf(bp, buflen - strlen(path), "/%s@%s",
98 nodename, addr_str);
99 }
100 return (0);
101
102 }
103
|
7 * with the License.
8 *
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.
13 *
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]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright (c) 2018, Joyent, Inc.
29 */
30
31 #include "ndievents.h"
32 #include <sys/sunndi.h>
33 #include <sys/ndi_impldefs.h>
34 #include <sys/dditypes.h>
35 #include <sys/ddi_impldefs.h>
36 #include <sys/sunddi.h>
37 #include <sys/param.h>
38
39
40 int
41 dip_to_pathname(struct dev_info *device, char *path, int buflen) {
42
43 char *bp;
44 char *addr;
45 char addr_str[32];
46 char nodename[MAXNAMELEN];
47 struct dev_info devi_parent;
48
49 if (!device) {
65 return (0);
66 }
67
68 if (mdb_vread(&devi_parent, sizeof (struct dev_info),
69 (uintptr_t)device->devi_parent) == -1) {
70 mdb_warn("Unable to access devi_parent at %p",
71 (uintptr_t)device->devi_parent);
72 return (-1);
73 }
74
75 if (dip_to_pathname(&devi_parent, path, buflen) == -1) {
76 return (-1);
77 }
78
79 if (mdb_readstr(nodename, sizeof (nodename),
80 (uintptr_t)device->devi_node_name) == -1) {
81 return (-1);
82 }
83
84 if (device->devi_node_state < DS_INITIALIZED) {
85 addr_str[0] = '\0';
86 } else {
87 addr = device->devi_addr;
88 if (mdb_readstr(addr_str, sizeof (addr_str),
89 (uintptr_t)addr) == -1) {
90 return (-1);
91 }
92 }
93
94 bp = path + strlen(path);
95
96 if (addr_str[0] == '\0') {
97 (void) mdb_snprintf(bp, buflen - strlen(path), "/%s", nodename);
98 } else {
99 (void) mdb_snprintf(bp, buflen - strlen(path), "/%s@%s",
100 nodename, addr_str);
101 }
102 return (0);
103
104 }
105
|