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