1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate #include "mdinclude.h"
30*7c478bd9Sstevel@tonic-gate #include <sys/lvm/md_names.h>
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate /*
33*7c478bd9Sstevel@tonic-gate * work out the offset size
34*7c478bd9Sstevel@tonic-gate */
35*7c478bd9Sstevel@tonic-gate #define MY_DID_SHR_NAMSIZ(n) \
36*7c478bd9Sstevel@tonic-gate (((sizeof (struct did_shr_name) - 1) + \
37*7c478bd9Sstevel@tonic-gate n + (sizeof (uint_t) - 1)) & ~(sizeof (uint_t) - 1))
38*7c478bd9Sstevel@tonic-gate #define MY_SHR_NAMSIZ(n) \
39*7c478bd9Sstevel@tonic-gate (((sizeof (struct nm_shared_name) - 1) + \
40*7c478bd9Sstevel@tonic-gate n + (sizeof (uint_t) - 1)) & ~(sizeof (uint_t) - 1))
41*7c478bd9Sstevel@tonic-gate #define MY_DID_NAMSIZ(n) \
42*7c478bd9Sstevel@tonic-gate (((sizeof (struct did_min_name) - 1) + \
43*7c478bd9Sstevel@tonic-gate n + (sizeof (uint_t) - 1)) & ~(sizeof (uint_t) - 1))
44*7c478bd9Sstevel@tonic-gate #define MY_NAMSIZ(n) \
45*7c478bd9Sstevel@tonic-gate (((sizeof (struct nm_name) - 1) + \
46*7c478bd9Sstevel@tonic-gate n + (sizeof (uint_t) - 1)) & ~(sizeof (uint_t) - 1))
47*7c478bd9Sstevel@tonic-gate
48*7c478bd9Sstevel@tonic-gate static uintptr_t
print_did_shared_name(uintptr_t addr,int i)49*7c478bd9Sstevel@tonic-gate print_did_shared_name(uintptr_t addr, int i)
50*7c478bd9Sstevel@tonic-gate {
51*7c478bd9Sstevel@tonic-gate struct did_shr_name shn;
52*7c478bd9Sstevel@tonic-gate uintptr_t sn_name_addr;
53*7c478bd9Sstevel@tonic-gate void *sn_name;
54*7c478bd9Sstevel@tonic-gate uintptr_t next_addr = addr;
55*7c478bd9Sstevel@tonic-gate
56*7c478bd9Sstevel@tonic-gate if (mdb_vread(&shn, sizeof (struct did_shr_name), addr) !=
57*7c478bd9Sstevel@tonic-gate sizeof (struct did_shr_name)) {
58*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read did_shr_name at %p\n", addr);
59*7c478bd9Sstevel@tonic-gate return (NULL);
60*7c478bd9Sstevel@tonic-gate }
61*7c478bd9Sstevel@tonic-gate if (shn.did_size == 0)
62*7c478bd9Sstevel@tonic-gate return (NULL);
63*7c478bd9Sstevel@tonic-gate mdb_printf("device_id[%d] at %p\n", i, addr);
64*7c478bd9Sstevel@tonic-gate mdb_inc_indent(2);
65*7c478bd9Sstevel@tonic-gate mdb_printf("did_key: %d\n", shn.did_key);
66*7c478bd9Sstevel@tonic-gate mdb_printf("did_count: %u\n", shn.did_count);
67*7c478bd9Sstevel@tonic-gate mdb_printf("did_data: 0x%x \n", shn.did_data);
68*7c478bd9Sstevel@tonic-gate mdb_printf("did_size: %u\n", shn.did_size);
69*7c478bd9Sstevel@tonic-gate sn_name_addr = addr + ((uintptr_t)&shn.did_devid - (uintptr_t)&shn);
70*7c478bd9Sstevel@tonic-gate if (shn.did_size > 0) {
71*7c478bd9Sstevel@tonic-gate sn_name = mdb_alloc(shn.did_size + 1, UM_SLEEP | UM_GC);
72*7c478bd9Sstevel@tonic-gate if (mdb_readstr((char *)sn_name, shn.did_size + 1,
73*7c478bd9Sstevel@tonic-gate sn_name_addr) <= 0) {
74*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read sn_name at %p\n",
75*7c478bd9Sstevel@tonic-gate sn_name_addr);
76*7c478bd9Sstevel@tonic-gate return (NULL);
77*7c478bd9Sstevel@tonic-gate }
78*7c478bd9Sstevel@tonic-gate mdb_printf("did_devid: %s at %p\n", (char *)sn_name,
79*7c478bd9Sstevel@tonic-gate sn_name_addr);
80*7c478bd9Sstevel@tonic-gate next_addr = addr + MY_DID_SHR_NAMSIZ(shn.did_size);
81*7c478bd9Sstevel@tonic-gate }
82*7c478bd9Sstevel@tonic-gate mdb_dec_indent(2);
83*7c478bd9Sstevel@tonic-gate return (next_addr);
84*7c478bd9Sstevel@tonic-gate }
85*7c478bd9Sstevel@tonic-gate
86*7c478bd9Sstevel@tonic-gate static uintptr_t
print_nm_shared_name(uintptr_t addr,int i)87*7c478bd9Sstevel@tonic-gate print_nm_shared_name(uintptr_t addr, int i)
88*7c478bd9Sstevel@tonic-gate {
89*7c478bd9Sstevel@tonic-gate struct nm_shared_name shn;
90*7c478bd9Sstevel@tonic-gate uintptr_t sn_name_addr;
91*7c478bd9Sstevel@tonic-gate void *sn_name;
92*7c478bd9Sstevel@tonic-gate uintptr_t next_addr = addr;
93*7c478bd9Sstevel@tonic-gate
94*7c478bd9Sstevel@tonic-gate if (mdb_vread(&shn, sizeof (struct nm_shared_name), addr) !=
95*7c478bd9Sstevel@tonic-gate sizeof (struct nm_shared_name)) {
96*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read nm_shared_name at %p\n", addr);
97*7c478bd9Sstevel@tonic-gate return (NULL);
98*7c478bd9Sstevel@tonic-gate }
99*7c478bd9Sstevel@tonic-gate if (shn.sn_namlen == 0)
100*7c478bd9Sstevel@tonic-gate return (NULL);
101*7c478bd9Sstevel@tonic-gate mdb_printf("sr_name[%d] at %p\n", i, addr);
102*7c478bd9Sstevel@tonic-gate mdb_inc_indent(2);
103*7c478bd9Sstevel@tonic-gate mdb_printf("sn_key: %d \n", shn.sn_key);
104*7c478bd9Sstevel@tonic-gate mdb_printf("sn_count: %u\n", shn.sn_count);
105*7c478bd9Sstevel@tonic-gate mdb_printf("sn_data: 0x%x \n", shn.sn_data);
106*7c478bd9Sstevel@tonic-gate mdb_printf("sn_namlen: %u\n", shn.sn_namlen);
107*7c478bd9Sstevel@tonic-gate sn_name_addr = addr + ((uintptr_t)&shn.sn_name - (uintptr_t)&shn);
108*7c478bd9Sstevel@tonic-gate if (shn.sn_namlen > 0) {
109*7c478bd9Sstevel@tonic-gate sn_name = mdb_alloc(shn.sn_namlen + 1, UM_SLEEP | UM_GC);
110*7c478bd9Sstevel@tonic-gate if (mdb_readstr((char *)sn_name, shn.sn_namlen + 1,
111*7c478bd9Sstevel@tonic-gate sn_name_addr) <= 0) {
112*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read sn_name at %p\n",
113*7c478bd9Sstevel@tonic-gate sn_name_addr);
114*7c478bd9Sstevel@tonic-gate }
115*7c478bd9Sstevel@tonic-gate mdb_printf("sn_name: %s at %p\n", (char *)sn_name,
116*7c478bd9Sstevel@tonic-gate sn_name_addr);
117*7c478bd9Sstevel@tonic-gate next_addr = addr + MY_SHR_NAMSIZ(shn.sn_namlen);
118*7c478bd9Sstevel@tonic-gate }
119*7c478bd9Sstevel@tonic-gate mdb_dec_indent(2);
120*7c478bd9Sstevel@tonic-gate return (next_addr);
121*7c478bd9Sstevel@tonic-gate }
122*7c478bd9Sstevel@tonic-gate
123*7c478bd9Sstevel@tonic-gate static uintptr_t
print_devid_name(uintptr_t addr,int i)124*7c478bd9Sstevel@tonic-gate print_devid_name(uintptr_t addr, int i)
125*7c478bd9Sstevel@tonic-gate {
126*7c478bd9Sstevel@tonic-gate struct did_min_name didmn;
127*7c478bd9Sstevel@tonic-gate uintptr_t did_name_addr;
128*7c478bd9Sstevel@tonic-gate void *min_name;
129*7c478bd9Sstevel@tonic-gate uintptr_t next_addr = addr;
130*7c478bd9Sstevel@tonic-gate
131*7c478bd9Sstevel@tonic-gate if (mdb_vread(&didmn, sizeof (struct did_min_name), addr) !=
132*7c478bd9Sstevel@tonic-gate sizeof (struct did_min_name)) {
133*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read did_min_name at %p\n", addr);
134*7c478bd9Sstevel@tonic-gate return (NULL);
135*7c478bd9Sstevel@tonic-gate }
136*7c478bd9Sstevel@tonic-gate if (didmn.min_namlen == 0)
137*7c478bd9Sstevel@tonic-gate return (NULL);
138*7c478bd9Sstevel@tonic-gate mdb_printf("minor_name[%d] at %p\n", i, addr);
139*7c478bd9Sstevel@tonic-gate mdb_inc_indent(2);
140*7c478bd9Sstevel@tonic-gate mdb_printf("min_key: %d \n", didmn.min_key);
141*7c478bd9Sstevel@tonic-gate mdb_printf("min_count: %u\n", didmn.min_count);
142*7c478bd9Sstevel@tonic-gate mdb_printf("min_devid_key: %d \n", didmn.min_devid_key);
143*7c478bd9Sstevel@tonic-gate mdb_printf("min_namlen: %u\n", didmn.min_namlen);
144*7c478bd9Sstevel@tonic-gate did_name_addr = addr + ((uintptr_t)&didmn.min_name - (uintptr_t)&didmn);
145*7c478bd9Sstevel@tonic-gate if (didmn.min_namlen > 0) {
146*7c478bd9Sstevel@tonic-gate min_name = mdb_alloc(didmn.min_namlen + 1, UM_SLEEP | UM_GC);
147*7c478bd9Sstevel@tonic-gate if (mdb_readstr((char *)min_name, didmn.min_namlen + 1,
148*7c478bd9Sstevel@tonic-gate did_name_addr) <= 0) {
149*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read min_name at %p\n",
150*7c478bd9Sstevel@tonic-gate did_name_addr);
151*7c478bd9Sstevel@tonic-gate }
152*7c478bd9Sstevel@tonic-gate mdb_printf("min_name: %s at %p\n", (char *)min_name,
153*7c478bd9Sstevel@tonic-gate did_name_addr);
154*7c478bd9Sstevel@tonic-gate next_addr = addr + MY_DID_NAMSIZ(didmn.min_namlen);
155*7c478bd9Sstevel@tonic-gate }
156*7c478bd9Sstevel@tonic-gate mdb_dec_indent(2);
157*7c478bd9Sstevel@tonic-gate return (next_addr);
158*7c478bd9Sstevel@tonic-gate }
159*7c478bd9Sstevel@tonic-gate
160*7c478bd9Sstevel@tonic-gate static uintptr_t
print_nm_name(uintptr_t addr,int i)161*7c478bd9Sstevel@tonic-gate print_nm_name(uintptr_t addr, int i)
162*7c478bd9Sstevel@tonic-gate {
163*7c478bd9Sstevel@tonic-gate struct nm_name nm;
164*7c478bd9Sstevel@tonic-gate uintptr_t nm_name_addr;
165*7c478bd9Sstevel@tonic-gate void *n_name;
166*7c478bd9Sstevel@tonic-gate uintptr_t next_addr = addr;
167*7c478bd9Sstevel@tonic-gate
168*7c478bd9Sstevel@tonic-gate if (mdb_vread(&nm, sizeof (struct nm_name), addr) !=
169*7c478bd9Sstevel@tonic-gate sizeof (struct nm_name)) {
170*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read nm_name at %p\n", addr);
171*7c478bd9Sstevel@tonic-gate return (NULL);
172*7c478bd9Sstevel@tonic-gate }
173*7c478bd9Sstevel@tonic-gate if (nm.n_namlen == 0)
174*7c478bd9Sstevel@tonic-gate return (NULL);
175*7c478bd9Sstevel@tonic-gate mdb_printf("r_name[%d] at %p\n", i, addr);
176*7c478bd9Sstevel@tonic-gate mdb_inc_indent(2);
177*7c478bd9Sstevel@tonic-gate mdb_printf("n_key: %d \n", nm.n_key);
178*7c478bd9Sstevel@tonic-gate mdb_printf("n_count: %u\n", nm.n_count);
179*7c478bd9Sstevel@tonic-gate mdb_printf("n_minor: %x\n", nm.n_minor);
180*7c478bd9Sstevel@tonic-gate mdb_printf("n_drv_key: %d \n", nm.n_drv_key);
181*7c478bd9Sstevel@tonic-gate mdb_printf("n_dir_key: %d \n", nm.n_dir_key);
182*7c478bd9Sstevel@tonic-gate mdb_printf("n_namlen: %u\n", nm.n_namlen);
183*7c478bd9Sstevel@tonic-gate nm_name_addr = addr + ((uintptr_t)&nm.n_name - (uintptr_t)&nm);
184*7c478bd9Sstevel@tonic-gate if (nm.n_namlen > 0) {
185*7c478bd9Sstevel@tonic-gate n_name = mdb_alloc(nm.n_namlen + 1, UM_SLEEP | UM_GC);
186*7c478bd9Sstevel@tonic-gate if (mdb_readstr((char *)n_name, nm.n_namlen + 1,
187*7c478bd9Sstevel@tonic-gate nm_name_addr) <= 0) {
188*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read n_name at %p\n", nm_name_addr);
189*7c478bd9Sstevel@tonic-gate }
190*7c478bd9Sstevel@tonic-gate mdb_printf("n_name: %s at %p\n", (char *)n_name,
191*7c478bd9Sstevel@tonic-gate nm_name_addr);
192*7c478bd9Sstevel@tonic-gate next_addr = addr + MY_NAMSIZ(nm.n_namlen);
193*7c478bd9Sstevel@tonic-gate }
194*7c478bd9Sstevel@tonic-gate
195*7c478bd9Sstevel@tonic-gate mdb_dec_indent(2);
196*7c478bd9Sstevel@tonic-gate return (next_addr);
197*7c478bd9Sstevel@tonic-gate }
198*7c478bd9Sstevel@tonic-gate
199*7c478bd9Sstevel@tonic-gate static uint_t
process_nmn_record_hdr(uintptr_t addr)200*7c478bd9Sstevel@tonic-gate process_nmn_record_hdr(uintptr_t addr)
201*7c478bd9Sstevel@tonic-gate {
202*7c478bd9Sstevel@tonic-gate struct nm_rec_hdr rhdr;
203*7c478bd9Sstevel@tonic-gate
204*7c478bd9Sstevel@tonic-gate /*
205*7c478bd9Sstevel@tonic-gate * we read this anyway as the first part of nm_rec, devid_min_rec,
206*7c478bd9Sstevel@tonic-gate * nm_shr_rec, and devid_shr_rec record is a nm_rec_hdr
207*7c478bd9Sstevel@tonic-gate */
208*7c478bd9Sstevel@tonic-gate if (mdb_vread(&rhdr, sizeof (struct nm_rec_hdr), addr) !=
209*7c478bd9Sstevel@tonic-gate sizeof (struct nm_rec_hdr)) {
210*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read nm_rec_hdr at %p\n", addr);
211*7c478bd9Sstevel@tonic-gate return (0);
212*7c478bd9Sstevel@tonic-gate }
213*7c478bd9Sstevel@tonic-gate
214*7c478bd9Sstevel@tonic-gate mdb_printf("nmn_record: %p\n", addr);
215*7c478bd9Sstevel@tonic-gate mdb_inc_indent(2);
216*7c478bd9Sstevel@tonic-gate mdb_printf("r_revision: %4u\n", rhdr.r_revision);
217*7c478bd9Sstevel@tonic-gate mdb_printf("r_alloc_size: %4u\n", rhdr.r_alloc_size);
218*7c478bd9Sstevel@tonic-gate mdb_printf("r_used_size: %4u\n", rhdr.r_used_size);
219*7c478bd9Sstevel@tonic-gate mdb_printf("r_next_recid: %4x\n", rhdr.r_next_recid);
220*7c478bd9Sstevel@tonic-gate mdb_printf("xr_next_rec: %4u\n", rhdr.xr_next_rec);
221*7c478bd9Sstevel@tonic-gate mdb_printf("r_next_key: %4d\n", rhdr.r_next_key);
222*7c478bd9Sstevel@tonic-gate mdb_dec_indent(2);
223*7c478bd9Sstevel@tonic-gate return (rhdr.r_used_size);
224*7c478bd9Sstevel@tonic-gate }
225*7c478bd9Sstevel@tonic-gate
226*7c478bd9Sstevel@tonic-gate static void
process_nmn_record(uintptr_t addr,int shared,int devid)227*7c478bd9Sstevel@tonic-gate process_nmn_record(uintptr_t addr, int shared, int devid)
228*7c478bd9Sstevel@tonic-gate {
229*7c478bd9Sstevel@tonic-gate struct nm_shr_rec srhdr;
230*7c478bd9Sstevel@tonic-gate struct devid_shr_rec didsrhdr;
231*7c478bd9Sstevel@tonic-gate struct nm_rec nm_record;
232*7c478bd9Sstevel@tonic-gate struct devid_min_rec devid_record;
233*7c478bd9Sstevel@tonic-gate uintptr_t shn_addr;
234*7c478bd9Sstevel@tonic-gate int i;
235*7c478bd9Sstevel@tonic-gate uintptr_t next_addr, start_addr;
236*7c478bd9Sstevel@tonic-gate uint_t used_size;
237*7c478bd9Sstevel@tonic-gate
238*7c478bd9Sstevel@tonic-gate used_size = process_nmn_record_hdr(addr);
239*7c478bd9Sstevel@tonic-gate
240*7c478bd9Sstevel@tonic-gate if (devid) {
241*7c478bd9Sstevel@tonic-gate if (shared) {
242*7c478bd9Sstevel@tonic-gate if (mdb_vread(&didsrhdr, sizeof (struct devid_shr_rec),
243*7c478bd9Sstevel@tonic-gate addr) != sizeof (struct devid_shr_rec)) {
244*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read devid_shr_rec at %p\n",
245*7c478bd9Sstevel@tonic-gate addr);
246*7c478bd9Sstevel@tonic-gate return;
247*7c478bd9Sstevel@tonic-gate }
248*7c478bd9Sstevel@tonic-gate } else {
249*7c478bd9Sstevel@tonic-gate if (mdb_vread(&devid_record,
250*7c478bd9Sstevel@tonic-gate sizeof (struct devid_min_rec), addr)
251*7c478bd9Sstevel@tonic-gate != sizeof (struct devid_min_rec)) {
252*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read devid_min_rec at %p\n",
253*7c478bd9Sstevel@tonic-gate addr);
254*7c478bd9Sstevel@tonic-gate return;
255*7c478bd9Sstevel@tonic-gate }
256*7c478bd9Sstevel@tonic-gate }
257*7c478bd9Sstevel@tonic-gate } else {
258*7c478bd9Sstevel@tonic-gate if (shared) {
259*7c478bd9Sstevel@tonic-gate if (mdb_vread(&srhdr, sizeof (struct nm_shr_rec), addr)
260*7c478bd9Sstevel@tonic-gate != sizeof (struct nm_shr_rec)) {
261*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read nm_shr_rec at %p\n",
262*7c478bd9Sstevel@tonic-gate addr);
263*7c478bd9Sstevel@tonic-gate return;
264*7c478bd9Sstevel@tonic-gate }
265*7c478bd9Sstevel@tonic-gate } else {
266*7c478bd9Sstevel@tonic-gate if (mdb_vread(&nm_record, sizeof (struct nm_rec), addr)
267*7c478bd9Sstevel@tonic-gate != sizeof (struct nm_rec)) {
268*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read nm_rec at %p\n", addr);
269*7c478bd9Sstevel@tonic-gate return;
270*7c478bd9Sstevel@tonic-gate }
271*7c478bd9Sstevel@tonic-gate }
272*7c478bd9Sstevel@tonic-gate }
273*7c478bd9Sstevel@tonic-gate mdb_inc_indent(2);
274*7c478bd9Sstevel@tonic-gate if (devid) {
275*7c478bd9Sstevel@tonic-gate if (shared) {
276*7c478bd9Sstevel@tonic-gate /*
277*7c478bd9Sstevel@tonic-gate * Do the rest of the device_id records.
278*7c478bd9Sstevel@tonic-gate */
279*7c478bd9Sstevel@tonic-gate next_addr = addr + ((uintptr_t)&didsrhdr.device_id[0] -
280*7c478bd9Sstevel@tonic-gate (uintptr_t)&didsrhdr);
281*7c478bd9Sstevel@tonic-gate start_addr = next_addr;
282*7c478bd9Sstevel@tonic-gate for (i = 0; ; i++) {
283*7c478bd9Sstevel@tonic-gate shn_addr = next_addr;
284*7c478bd9Sstevel@tonic-gate next_addr = print_did_shared_name(shn_addr, i);
285*7c478bd9Sstevel@tonic-gate if (next_addr == NULL) {
286*7c478bd9Sstevel@tonic-gate mdb_dec_indent(2);
287*7c478bd9Sstevel@tonic-gate return;
288*7c478bd9Sstevel@tonic-gate }
289*7c478bd9Sstevel@tonic-gate /*
290*7c478bd9Sstevel@tonic-gate * Causes us to print one extra record.
291*7c478bd9Sstevel@tonic-gate */
292*7c478bd9Sstevel@tonic-gate if ((next_addr - start_addr > used_size) ||
293*7c478bd9Sstevel@tonic-gate (next_addr == shn_addr)) {
294*7c478bd9Sstevel@tonic-gate break;
295*7c478bd9Sstevel@tonic-gate }
296*7c478bd9Sstevel@tonic-gate }
297*7c478bd9Sstevel@tonic-gate } else {
298*7c478bd9Sstevel@tonic-gate /*
299*7c478bd9Sstevel@tonic-gate * Now do the rest of the record.
300*7c478bd9Sstevel@tonic-gate */
301*7c478bd9Sstevel@tonic-gate next_addr = addr +
302*7c478bd9Sstevel@tonic-gate ((uintptr_t)&devid_record.minor_name[0] -
303*7c478bd9Sstevel@tonic-gate (uintptr_t)&devid_record);
304*7c478bd9Sstevel@tonic-gate start_addr = next_addr;
305*7c478bd9Sstevel@tonic-gate for (i = 0; ; i++) {
306*7c478bd9Sstevel@tonic-gate shn_addr = next_addr;
307*7c478bd9Sstevel@tonic-gate next_addr = print_devid_name(shn_addr, i);
308*7c478bd9Sstevel@tonic-gate if (next_addr == NULL) {
309*7c478bd9Sstevel@tonic-gate mdb_dec_indent(2);
310*7c478bd9Sstevel@tonic-gate return;
311*7c478bd9Sstevel@tonic-gate }
312*7c478bd9Sstevel@tonic-gate if ((next_addr - start_addr > used_size) ||
313*7c478bd9Sstevel@tonic-gate (next_addr == shn_addr)) {
314*7c478bd9Sstevel@tonic-gate break;
315*7c478bd9Sstevel@tonic-gate }
316*7c478bd9Sstevel@tonic-gate }
317*7c478bd9Sstevel@tonic-gate }
318*7c478bd9Sstevel@tonic-gate } else {
319*7c478bd9Sstevel@tonic-gate if (shared) {
320*7c478bd9Sstevel@tonic-gate /*
321*7c478bd9Sstevel@tonic-gate * Now do the rest of the sr_name records.
322*7c478bd9Sstevel@tonic-gate */
323*7c478bd9Sstevel@tonic-gate next_addr = addr + ((uintptr_t)&srhdr.sr_name[0] -
324*7c478bd9Sstevel@tonic-gate (uintptr_t)&srhdr);
325*7c478bd9Sstevel@tonic-gate start_addr = next_addr;
326*7c478bd9Sstevel@tonic-gate for (i = 0; ; i++) {
327*7c478bd9Sstevel@tonic-gate shn_addr = next_addr;
328*7c478bd9Sstevel@tonic-gate next_addr = print_nm_shared_name(shn_addr, i);
329*7c478bd9Sstevel@tonic-gate if (next_addr == NULL) {
330*7c478bd9Sstevel@tonic-gate mdb_dec_indent(2);
331*7c478bd9Sstevel@tonic-gate return;
332*7c478bd9Sstevel@tonic-gate }
333*7c478bd9Sstevel@tonic-gate /*
334*7c478bd9Sstevel@tonic-gate * Causes us to print one extra record
335*7c478bd9Sstevel@tonic-gate */
336*7c478bd9Sstevel@tonic-gate if ((next_addr - start_addr > used_size) ||
337*7c478bd9Sstevel@tonic-gate (next_addr == shn_addr)) {
338*7c478bd9Sstevel@tonic-gate break;
339*7c478bd9Sstevel@tonic-gate }
340*7c478bd9Sstevel@tonic-gate }
341*7c478bd9Sstevel@tonic-gate } else {
342*7c478bd9Sstevel@tonic-gate /*
343*7c478bd9Sstevel@tonic-gate * Now do the rest of the record
344*7c478bd9Sstevel@tonic-gate */
345*7c478bd9Sstevel@tonic-gate next_addr = addr + ((uintptr_t)&nm_record.r_name[0] -
346*7c478bd9Sstevel@tonic-gate (uintptr_t)&nm_record);
347*7c478bd9Sstevel@tonic-gate start_addr = next_addr;
348*7c478bd9Sstevel@tonic-gate for (i = 0; ; i++) {
349*7c478bd9Sstevel@tonic-gate shn_addr = next_addr;
350*7c478bd9Sstevel@tonic-gate next_addr = print_nm_name(shn_addr, i);
351*7c478bd9Sstevel@tonic-gate if (next_addr == NULL) {
352*7c478bd9Sstevel@tonic-gate mdb_dec_indent(2);
353*7c478bd9Sstevel@tonic-gate return;
354*7c478bd9Sstevel@tonic-gate }
355*7c478bd9Sstevel@tonic-gate if ((next_addr - start_addr > used_size) ||
356*7c478bd9Sstevel@tonic-gate (next_addr == shn_addr)) {
357*7c478bd9Sstevel@tonic-gate break;
358*7c478bd9Sstevel@tonic-gate }
359*7c478bd9Sstevel@tonic-gate }
360*7c478bd9Sstevel@tonic-gate }
361*7c478bd9Sstevel@tonic-gate }
362*7c478bd9Sstevel@tonic-gate mdb_dec_indent(2);
363*7c478bd9Sstevel@tonic-gate }
364*7c478bd9Sstevel@tonic-gate
365*7c478bd9Sstevel@tonic-gate static void
process_nm_next_hdr(uintptr_t addr,int shared,int devid)366*7c478bd9Sstevel@tonic-gate process_nm_next_hdr(uintptr_t addr, int shared, int devid)
367*7c478bd9Sstevel@tonic-gate {
368*7c478bd9Sstevel@tonic-gate uintptr_t next = addr;
369*7c478bd9Sstevel@tonic-gate struct nm_next_hdr nhdr;
370*7c478bd9Sstevel@tonic-gate
371*7c478bd9Sstevel@tonic-gate mdb_inc_indent(2);
372*7c478bd9Sstevel@tonic-gate mdb_printf("%p\n", next);
373*7c478bd9Sstevel@tonic-gate if (mdb_vread(&nhdr, sizeof (struct nm_next_hdr), next) !=
374*7c478bd9Sstevel@tonic-gate sizeof (struct nm_next_hdr)) {
375*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read nm_next_hdr at %p", next);
376*7c478bd9Sstevel@tonic-gate return;
377*7c478bd9Sstevel@tonic-gate }
378*7c478bd9Sstevel@tonic-gate (void) process_nmn_record_hdr((uintptr_t)nhdr.nmn_record);
379*7c478bd9Sstevel@tonic-gate next = (uintptr_t)nhdr.nmn_nextp;
380*7c478bd9Sstevel@tonic-gate while (next != (uintptr_t)0) {
381*7c478bd9Sstevel@tonic-gate
382*7c478bd9Sstevel@tonic-gate mdb_printf("\n");
383*7c478bd9Sstevel@tonic-gate mdb_printf("nmn_nextp %p\n", nhdr.nmn_nextp);
384*7c478bd9Sstevel@tonic-gate if (mdb_vread(&nhdr, sizeof (struct nm_next_hdr), next) !=
385*7c478bd9Sstevel@tonic-gate sizeof (struct nm_next_hdr)) {
386*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read nm_next_hdr at %p\n", next);
387*7c478bd9Sstevel@tonic-gate break;
388*7c478bd9Sstevel@tonic-gate }
389*7c478bd9Sstevel@tonic-gate process_nmn_record((uintptr_t)nhdr.nmn_record, shared, devid);
390*7c478bd9Sstevel@tonic-gate next = (uintptr_t)nhdr.nmn_nextp;
391*7c478bd9Sstevel@tonic-gate }
392*7c478bd9Sstevel@tonic-gate mdb_printf("\n");
393*7c478bd9Sstevel@tonic-gate mdb_dec_indent(2);
394*7c478bd9Sstevel@tonic-gate }
395*7c478bd9Sstevel@tonic-gate /*
396*7c478bd9Sstevel@tonic-gate * Start the processing of a nominated set
397*7c478bd9Sstevel@tonic-gate */
398*7c478bd9Sstevel@tonic-gate static void
process_set(int setno)399*7c478bd9Sstevel@tonic-gate process_set(int setno)
400*7c478bd9Sstevel@tonic-gate {
401*7c478bd9Sstevel@tonic-gate uintptr_t addr = (uintptr_t)mdset[setno].s_nm;
402*7c478bd9Sstevel@tonic-gate uintptr_t did_addr = (uintptr_t)mdset[setno].s_did_nm;
403*7c478bd9Sstevel@tonic-gate uintptr_t shared_addr, names_addr;
404*7c478bd9Sstevel@tonic-gate uintptr_t did_names_addr, did_shared_addr;
405*7c478bd9Sstevel@tonic-gate struct nm_header_hdr hdr, did_hdr;
406*7c478bd9Sstevel@tonic-gate
407*7c478bd9Sstevel@tonic-gate mdb_printf("------ Name Space for setno %d ------\n", setno);
408*7c478bd9Sstevel@tonic-gate
409*7c478bd9Sstevel@tonic-gate if (mdb_vread(&hdr, sizeof (struct nm_header_hdr), addr) !=
410*7c478bd9Sstevel@tonic-gate sizeof (struct nm_header_hdr)) {
411*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read nm_header_hdr at %p\n", addr);
412*7c478bd9Sstevel@tonic-gate return;
413*7c478bd9Sstevel@tonic-gate }
414*7c478bd9Sstevel@tonic-gate mdb_printf("hh_header: %p \n", hdr.hh_header);
415*7c478bd9Sstevel@tonic-gate if (did_addr != NULL) { /* device id's exist */
416*7c478bd9Sstevel@tonic-gate if (mdb_vread(&did_hdr, sizeof (struct nm_header_hdr),
417*7c478bd9Sstevel@tonic-gate did_addr) != sizeof (struct nm_header_hdr)) {
418*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read nm_header_hdr at %p\n",
419*7c478bd9Sstevel@tonic-gate did_addr);
420*7c478bd9Sstevel@tonic-gate return;
421*7c478bd9Sstevel@tonic-gate }
422*7c478bd9Sstevel@tonic-gate mdb_printf("did hh_header: %p \n", did_hdr.hh_header);
423*7c478bd9Sstevel@tonic-gate did_names_addr =
424*7c478bd9Sstevel@tonic-gate (uintptr_t)&(((struct nm_header_hdr *)did_addr)->hh_names);
425*7c478bd9Sstevel@tonic-gate did_shared_addr =
426*7c478bd9Sstevel@tonic-gate (uintptr_t)&(((struct nm_header_hdr *)did_addr)->hh_shared);
427*7c478bd9Sstevel@tonic-gate }
428*7c478bd9Sstevel@tonic-gate
429*7c478bd9Sstevel@tonic-gate names_addr = (uintptr_t)&(((struct nm_header_hdr *)addr)->hh_names);
430*7c478bd9Sstevel@tonic-gate shared_addr = (uintptr_t)&(((struct nm_header_hdr *)addr)->hh_shared);
431*7c478bd9Sstevel@tonic-gate mdb_printf("hh_names: %p \n", names_addr);
432*7c478bd9Sstevel@tonic-gate mdb_printf("hh_shared: %p\n", shared_addr);
433*7c478bd9Sstevel@tonic-gate
434*7c478bd9Sstevel@tonic-gate if (did_addr != NULL) {
435*7c478bd9Sstevel@tonic-gate mdb_printf("did hh_names: %p \n", did_names_addr);
436*7c478bd9Sstevel@tonic-gate mdb_printf("did hh_shared: %p\n", did_shared_addr);
437*7c478bd9Sstevel@tonic-gate }
438*7c478bd9Sstevel@tonic-gate
439*7c478bd9Sstevel@tonic-gate mdb_printf("hh_names:");
440*7c478bd9Sstevel@tonic-gate process_nm_next_hdr(names_addr, 0, 0);
441*7c478bd9Sstevel@tonic-gate mdb_printf("\nhh_shared:");
442*7c478bd9Sstevel@tonic-gate process_nm_next_hdr(shared_addr, 1, 0);
443*7c478bd9Sstevel@tonic-gate
444*7c478bd9Sstevel@tonic-gate if (did_addr != NULL) {
445*7c478bd9Sstevel@tonic-gate mdb_printf("did hh_names:");
446*7c478bd9Sstevel@tonic-gate process_nm_next_hdr(did_names_addr, 0, 1);
447*7c478bd9Sstevel@tonic-gate mdb_printf("\ndid hh_shared:");
448*7c478bd9Sstevel@tonic-gate process_nm_next_hdr(did_shared_addr, 1, 1);
449*7c478bd9Sstevel@tonic-gate }
450*7c478bd9Sstevel@tonic-gate }
451*7c478bd9Sstevel@tonic-gate /*
452*7c478bd9Sstevel@tonic-gate * Dump the name space for all sets or specified set (-s option)
453*7c478bd9Sstevel@tonic-gate * usage: ::dumpnamespace [-s setname]
454*7c478bd9Sstevel@tonic-gate */
455*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
456*7c478bd9Sstevel@tonic-gate int
dumpnamespace(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)457*7c478bd9Sstevel@tonic-gate dumpnamespace(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
458*7c478bd9Sstevel@tonic-gate {
459*7c478bd9Sstevel@tonic-gate char *s_opt = NULL;
460*7c478bd9Sstevel@tonic-gate int j;
461*7c478bd9Sstevel@tonic-gate int setno;
462*7c478bd9Sstevel@tonic-gate
463*7c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv, 's', MDB_OPT_STR, &s_opt,
464*7c478bd9Sstevel@tonic-gate NULL) != argc) {
465*7c478bd9Sstevel@tonic-gate /* left over arguments ?? */
466*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
467*7c478bd9Sstevel@tonic-gate }
468*7c478bd9Sstevel@tonic-gate
469*7c478bd9Sstevel@tonic-gate snarf_sets();
470*7c478bd9Sstevel@tonic-gate
471*7c478bd9Sstevel@tonic-gate if (argc == 0) {
472*7c478bd9Sstevel@tonic-gate for (j = 0; j < md_nsets; j++) {
473*7c478bd9Sstevel@tonic-gate if (mdset[j].s_status & MD_SET_NM_LOADED) {
474*7c478bd9Sstevel@tonic-gate process_set(j);
475*7c478bd9Sstevel@tonic-gate }
476*7c478bd9Sstevel@tonic-gate }
477*7c478bd9Sstevel@tonic-gate } else {
478*7c478bd9Sstevel@tonic-gate setno = findset(s_opt);
479*7c478bd9Sstevel@tonic-gate if (setno == -1) {
480*7c478bd9Sstevel@tonic-gate mdb_warn("no such set: %s\n", s_opt);
481*7c478bd9Sstevel@tonic-gate return (DCMD_ERR);
482*7c478bd9Sstevel@tonic-gate }
483*7c478bd9Sstevel@tonic-gate if (mdset[setno].s_status & MD_SET_NM_LOADED) {
484*7c478bd9Sstevel@tonic-gate process_set(setno);
485*7c478bd9Sstevel@tonic-gate }
486*7c478bd9Sstevel@tonic-gate }
487*7c478bd9Sstevel@tonic-gate return (DCMD_OK);
488*7c478bd9Sstevel@tonic-gate }
489