Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/dedump.c
+++ new/usr/src/uts/common/io/dedump.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 2008 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" /* SVr3.2H */
27 -
28 26 /*
29 27 * Dump STREAMS module. Could be used anywhere on a stream to
30 28 * print all message headers and data on to the console.
31 29 */
32 30
33 31 #include <sys/types.h>
34 32 #include <sys/param.h>
35 33 #include <sys/systm.h>
36 34 #include <sys/stream.h>
37 35 #include <sys/stropts.h>
38 36 #include <sys/errno.h>
39 37 #include <sys/cmn_err.h>
40 38 #include <sys/ddi.h>
41 39 #include <sys/strsun.h>
42 40
43 41 #include <sys/conf.h>
44 42 #include <sys/modctl.h>
45 43
46 44 static char hdr[100]; /* current message header */
47 45 static char hdrpad[100]; /* pad of same length as hdr[] */
48 46
49 47 /*
50 48 * Raw buffer dumping routine. Displays the contents of the first message in
51 49 * message chain `mp', using the "traditional" dump format.
52 50 *
53 51 * For instance, "Hello STREAMS, panicked lately?" would be displayed as:
54 52 *
55 53 * RD 30001dbb240 M_DATA 48656C6C 6F205354 5245414D 532C2070 Hello STREAMS, p
56 54 * 616E6963 6B656420 6C617465 6C793F anicked lately?
57 55 *
58 56 * If the character being displayed is not printable, a '.' is shown.
59 57 */
60 58
61 59 #define DEDUMP_HEXPERBLK 4
62 60 #define DEDUMP_HEXLEN (sizeof ("11223344") * 4)
63 61 #define DEDUMP_ASCLEN (sizeof ("0123456789ABCDEF") - 1)
64 62
65 63 static void
66 64 dedump_raw(mblk_t *mp)
67 65 {
68 66 char hex[DEDUMP_HEXLEN + 1], asc[DEDUMP_ASCLEN + 1];
69 67 int hexi = 0, asci = 0, i = 0;
70 68 uchar_t c;
71 69 char *hdrp = hdr;
72 70
73 71 hex[DEDUMP_HEXLEN] = '\0';
74 72
75 73 for (;;) {
76 74 if (i == MBLKL(mp) || (i != 0 && (i % DEDUMP_ASCLEN) == 0)) {
77 75 /*
78 76 * We're either out of data or we've filled a complete
79 77 * line. In either case, print out what we've got --
80 78 * but first NUL-terminate asc[] and pad out hex[]
81 79 * with spaces.
82 80 */
83 81 asc[asci] = '\0';
84 82 (void) memset(hex + hexi, ' ', DEDUMP_HEXLEN - hexi);
85 83 (void) printf("%s %s %s\n", hdrp, hex, asc);
86 84
87 85 /*
88 86 * If we're out of data, bail. Otherwise, reset asci
89 87 * and hexi for another lap around. Also, set hdrp to
90 88 * the pad since we only want to show the header once.
91 89 */
92 90 if (i == MBLKL(mp))
93 91 break;
94 92 asci = 0;
95 93 hexi = 0;
96 94 hdrp = hdrpad;
97 95 }
98 96
99 97 c = mp->b_rptr[i++];
100 98
101 99 hexi += snprintf(hex + hexi, 3, "%02X", c);
102 100 if ((i % DEDUMP_HEXPERBLK) == 0)
103 101 hex[hexi++] = ' ';
104 102 asc[asci++] = (c >= 32 && c <= 126) ? c : '.';
105 103 }
106 104 }
107 105
108 106 static void
109 107 dedump_char(mblk_t *mp)
110 108 {
111 109 (void) printf("%s 0x%x\n", hdr, *(uchar_t *)mp->b_rptr);
112 110 }
113 111
114 112 static void
115 113 dedump_int(mblk_t *mp)
116 114 {
117 115 (void) printf("%s %d\n", hdr, *(int *)mp->b_rptr);
118 116 }
119 117
120 118 static void
121 119 dedump_ssize(mblk_t *mp)
122 120 {
123 121 (void) printf("%s %ld\n", hdr, *(ssize_t *)mp->b_rptr);
124 122 }
125 123
126 124 static void
127 125 dedump_cmdblk(mblk_t *mp)
128 126 {
129 127 struct cmdblk *cbp = (struct cmdblk *)mp->b_rptr;
130 128
131 129 (void) printf("%s cmd %x cred %p len %u error %d\n", hdr, cbp->cb_cmd,
132 130 (void *)cbp->cb_cr, cbp->cb_len, cbp->cb_error);
133 131 }
134 132
135 133 static void
136 134 dedump_iocblk(mblk_t *mp)
137 135 {
138 136 struct iocblk *ic = (struct iocblk *)mp->b_rptr;
139 137
140 138 (void) printf("%s cmd %x cred %p id %u flag %x count %ld rval %d "
141 139 "err %d\n", hdr, ic->ioc_cmd, (void *)ic->ioc_cr, ic->ioc_id,
142 140 ic->ioc_flag, ic->ioc_count, ic->ioc_rval, ic->ioc_error);
143 141 }
144 142
145 143 static void
146 144 dedump_stroptions(mblk_t *mp)
147 145 {
148 146 struct stroptions *so = (struct stroptions *)mp->b_rptr;
149 147
150 148 (void) printf("%s flag %x readopt %d wroff %u\n", hdr,
151 149 so->so_flags, so->so_readopt, so->so_wroff);
152 150
153 151 (void) printf("%s minpsz %ld maxpsz %ld hiwat %lu lowat %lu\n", hdrpad,
154 152 so->so_minpsz, so->so_maxpsz, so->so_hiwat, so->so_lowat);
155 153
156 154 (void) printf("%s band %u erropt %u maxblk %ld copyopt %u\n", hdrpad,
157 155 so->so_band, so->so_erropt, so->so_maxblk, so->so_copyopt);
158 156 }
159 157
160 158 static void
161 159 dedump_copyreq(mblk_t *mp)
162 160 {
163 161 struct copyreq *cq = (struct copyreq *)mp->b_rptr;
164 162
165 163 (void) printf("%s cmd %x cred %p id %u flag %x priv %p addr %p size "
166 164 "%lu\n", hdr, cq->cq_cmd, (void *)cq->cq_cr, cq->cq_id, cq->cq_flag,
167 165 (void *)cq->cq_private, (void *)cq->cq_addr, cq->cq_size);
168 166 }
169 167
170 168 static void
171 169 dedump_copyresp(mblk_t *mp)
172 170 {
173 171 struct copyresp *cp = (struct copyresp *)mp->b_rptr;
174 172
175 173 (void) printf("%s cmd %x cred %p id %u flag %x priv %p rval %p\n", hdr,
176 174 cp->cp_cmd, (void *)cp->cp_cr, cp->cp_id, cp->cp_flag,
177 175 (void *)cp->cp_private, (void *)cp->cp_rval);
178 176 }
179 177
180 178 typedef struct msgfmt {
181 179 uchar_t m_type;
182 180 char m_desc[15];
183 181 void (*m_print)(mblk_t *);
184 182 } msgfmt_t;
185 183
186 184 static msgfmt_t msgfmt[256] = {
187 185 { M_DATA, "M_DATA ", dedump_raw },
188 186 { M_PROTO, "M_PROTO ", dedump_raw },
189 187 { M_BREAK, "M_BREAK ", dedump_raw },
190 188 { M_PASSFP, "M_PASSFP ", dedump_raw },
191 189 { M_EVENT, "M_EVENT ", dedump_raw },
192 190 { M_SIG, "M_SIG ", dedump_char },
193 191 { M_DELAY, "M_DELAY ", dedump_int },
194 192 { M_CTL, "M_CTL ", dedump_raw },
195 193 { M_IOCTL, "M_IOCTL ", dedump_iocblk },
196 194 { M_SETOPTS, "M_SETOPTS ", dedump_stroptions },
197 195 { M_RSE, "M_RSE ", dedump_raw },
198 196 { M_IOCACK, "M_IOCACK ", dedump_iocblk },
199 197 { M_IOCNAK, "M_IOCNAK ", dedump_iocblk },
200 198 { M_PCPROTO, "M_PCPROTO ", dedump_raw },
201 199 { M_PCSIG, "M_PCSIG ", dedump_char },
202 200 { M_READ, "M_READ ", dedump_ssize },
203 201 { M_FLUSH, "M_FLUSH ", dedump_char },
204 202 { M_STOP, "M_STOP ", dedump_raw },
205 203 { M_START, "M_START ", dedump_raw },
206 204 { M_HANGUP, "M_HANGUP ", dedump_raw },
207 205 { M_ERROR, "M_ERROR ", dedump_char },
208 206 { M_COPYIN, "M_COPYIN ", dedump_copyreq },
209 207 { M_COPYOUT, "M_COPYOUT ", dedump_copyreq },
210 208 { M_IOCDATA, "M_IOCDATA ", dedump_copyresp },
211 209 { M_PCRSE, "M_PCRSE ", dedump_raw },
212 210 { M_STOPI, "M_STOPI ", dedump_raw },
213 211 { M_STARTI, "M_STARTI ", dedump_raw },
214 212 { M_PCEVENT, "M_PCEVENT ", dedump_raw },
215 213 { M_UNHANGUP, "M_UNHANGUP", dedump_raw },
216 214 { M_CMD, "M_CMD ", dedump_cmdblk },
217 215 };
218 216
219 217 /*ARGSUSED1*/
220 218 static int
221 219 dedumpopen(queue_t *q, dev_t *devp, int oflag, int sflag, cred_t *crp)
222 220 {
223 221 if (!sflag)
224 222 return (ENXIO);
225 223
226 224 if (q->q_ptr)
227 225 return (0); /* already attached */
228 226
229 227 qprocson(q);
230 228 return (0);
231 229 }
232 230
233 231 /*ARGSUSED1*/
234 232 static int
235 233 dedumpclose(queue_t *q, int flag, cred_t *crp)
236 234 {
237 235 qprocsoff(q);
238 236 return (0);
239 237 }
240 238
241 239 /*
242 240 * Common put procedure for upstream and downstream.
243 241 */
244 242 static int
245 243 dedumpput(queue_t *q, mblk_t *mp)
246 244 {
247 245 unsigned char type = DB_TYPE(mp);
248 246 ssize_t hdrlen;
249 247
250 248 hdrlen = snprintf(hdr, sizeof (hdr), "%s %p %10s ",
251 249 (q->q_flag & QREADR) ? "RD" : "WR", (void *)q, msgfmt[type].m_desc);
252 250
253 251 hdrpad[hdrlen] = '\0';
254 252 msgfmt[type].m_print(mp);
255 253 hdrpad[hdrlen] = ' ';
256 254
257 255 putnext(q, mp);
258 256 return (0);
259 257 }
260 258
261 259 struct module_info dedump_minfo = {
262 260 0xaaa, "dedump", 0, INFPSZ, 0, 0
263 261 };
264 262
265 263 struct qinit dedumprinit = {
266 264 dedumpput, NULL, dedumpopen, dedumpclose, NULL, &dedump_minfo, NULL
267 265 };
268 266
269 267 struct qinit dedumpwinit = {
270 268 dedumpput, NULL, NULL, NULL, NULL, &dedump_minfo, NULL
271 269 };
272 270
273 271 struct streamtab dedumpinfo = {
274 272 &dedumprinit, &dedumpwinit, NULL, NULL,
275 273 };
276 274
277 275 static struct fmodsw fsw = {
↓ open down ↓ |
240 lines elided |
↑ open up ↑ |
278 276 "dedump",
279 277 &dedumpinfo,
280 278 D_MP | D_MTPERMOD /* just to serialize printfs */
281 279 };
282 280
283 281 static struct modlstrmod modlstrmod = {
284 282 &mod_strmodops, "dump streams module", &fsw
285 283 };
286 284
287 285 static struct modlinkage modlinkage = {
288 - MODREV_1, &modlstrmod, NULL
286 + MODREV_1, { &modlstrmod, NULL }
289 287 };
290 288
291 289 int
292 290 _init(void)
293 291 {
294 292 int i;
295 293 msgfmt_t mf;
296 294
297 295 /*
298 296 * Sort msgfmt[] so that msgfmt[n] describes message type n.
299 297 */
300 298 for (i = 255; i != 0; i--) {
301 299 mf = msgfmt[i];
302 300 msgfmt[i].m_type = i;
303 301 (void) sprintf(msgfmt[i].m_desc, "M_BOGUS_0x%x", i);
304 302 msgfmt[i].m_print = dedump_raw;
305 303 if (mf.m_desc[0] != 0)
306 304 msgfmt[mf.m_type] = mf;
307 305 }
308 306
309 307 /*
310 308 * Fill hdrpad[] with as many spaces as will fit.
311 309 */
312 310 (void) memset(hdrpad, ' ', sizeof (hdrpad) - 1);
313 311 hdrpad[sizeof (hdrpad) - 1] = '\0';
314 312
315 313 return (mod_install(&modlinkage));
316 314 }
317 315
318 316 int
319 317 _fini(void)
320 318 {
321 319 return (mod_remove(&modlinkage));
322 320 }
323 321
324 322 int
325 323 _info(struct modinfo *modinfop)
326 324 {
327 325 return (mod_info(&modlinkage, modinfop));
328 326 }
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX