xref: /illumos-gate/usr/src/uts/common/io/dedump.c (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*ca9327a6Smeem  * Common Development and Distribution License (the "License").
6*ca9327a6Smeem  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*ca9327a6Smeem  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * Dump STREAMS module.  Could be used anywhere on a stream to
287c478bd9Sstevel@tonic-gate  * print all message headers and data on to the console.
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/param.h>
337c478bd9Sstevel@tonic-gate #include <sys/systm.h>
347c478bd9Sstevel@tonic-gate #include <sys/stream.h>
357c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
367c478bd9Sstevel@tonic-gate #include <sys/errno.h>
377c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
387c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
397c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #include <sys/conf.h>
427c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate static char	hdr[100];	/* current message header */
457c478bd9Sstevel@tonic-gate static char  	hdrpad[100];	/* pad of same length as hdr[] */
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * Raw buffer dumping routine.  Displays the contents of the first message in
497c478bd9Sstevel@tonic-gate  * message chain `mp', using the "traditional" dump format.
507c478bd9Sstevel@tonic-gate  *
517c478bd9Sstevel@tonic-gate  * For instance, "Hello STREAMS, panicked lately?" would be displayed as:
527c478bd9Sstevel@tonic-gate  *
537c478bd9Sstevel@tonic-gate  * RD 30001dbb240 M_DATA 48656C6C 6F205354 5245414D 532C2070  Hello STREAMS, p
547c478bd9Sstevel@tonic-gate  *                       616E6963 6B656420 6C617465 6C793F    anicked lately?
557c478bd9Sstevel@tonic-gate  *
567c478bd9Sstevel@tonic-gate  * If the character being displayed is not printable, a '.' is shown.
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate #define	DEDUMP_HEXPERBLK	4
607c478bd9Sstevel@tonic-gate #define	DEDUMP_HEXLEN		(sizeof ("11223344") * 4)
617c478bd9Sstevel@tonic-gate #define	DEDUMP_ASCLEN		(sizeof ("0123456789ABCDEF") - 1)
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate static void
dedump_raw(mblk_t * mp)647c478bd9Sstevel@tonic-gate dedump_raw(mblk_t *mp)
657c478bd9Sstevel@tonic-gate {
667c478bd9Sstevel@tonic-gate 	char	hex[DEDUMP_HEXLEN + 1], asc[DEDUMP_ASCLEN + 1];
677c478bd9Sstevel@tonic-gate 	int	hexi = 0, asci = 0, i = 0;
687c478bd9Sstevel@tonic-gate 	uchar_t	c;
697c478bd9Sstevel@tonic-gate 	char	*hdrp = hdr;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 	hex[DEDUMP_HEXLEN] = '\0';
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	for (;;) {
747c478bd9Sstevel@tonic-gate 		if (i == MBLKL(mp) || (i != 0 && (i % DEDUMP_ASCLEN) == 0)) {
757c478bd9Sstevel@tonic-gate 			/*
767c478bd9Sstevel@tonic-gate 			 * We're either out of data or we've filled a complete
777c478bd9Sstevel@tonic-gate 			 * line.  In either case, print out what we've got --
787c478bd9Sstevel@tonic-gate 			 * but first NUL-terminate asc[] and pad out hex[]
797c478bd9Sstevel@tonic-gate 			 * with spaces.
807c478bd9Sstevel@tonic-gate 			 */
817c478bd9Sstevel@tonic-gate 			asc[asci] = '\0';
827c478bd9Sstevel@tonic-gate 			(void) memset(hex + hexi, ' ', DEDUMP_HEXLEN - hexi);
837c478bd9Sstevel@tonic-gate 			(void) printf("%s %s %s\n", hdrp, hex, asc);
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 			/*
867c478bd9Sstevel@tonic-gate 			 * If we're out of data, bail.  Otherwise, reset asci
877c478bd9Sstevel@tonic-gate 			 * and hexi for another lap around.  Also, set hdrp to
887c478bd9Sstevel@tonic-gate 			 * the pad since we only want to show the header once.
897c478bd9Sstevel@tonic-gate 			 */
907c478bd9Sstevel@tonic-gate 			if (i == MBLKL(mp))
917c478bd9Sstevel@tonic-gate 				break;
927c478bd9Sstevel@tonic-gate 			asci = 0;
937c478bd9Sstevel@tonic-gate 			hexi = 0;
947c478bd9Sstevel@tonic-gate 			hdrp = hdrpad;
957c478bd9Sstevel@tonic-gate 		}
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 		c = mp->b_rptr[i++];
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 		hexi += snprintf(hex + hexi, 3, "%02X", c);
1007c478bd9Sstevel@tonic-gate 		if ((i % DEDUMP_HEXPERBLK) == 0)
1017c478bd9Sstevel@tonic-gate 			hex[hexi++] = ' ';
1027c478bd9Sstevel@tonic-gate 		asc[asci++] = (c >= 32 && c <= 126) ? c : '.';
1037c478bd9Sstevel@tonic-gate 	}
1047c478bd9Sstevel@tonic-gate }
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate static void
dedump_char(mblk_t * mp)1077c478bd9Sstevel@tonic-gate dedump_char(mblk_t *mp)
1087c478bd9Sstevel@tonic-gate {
1097c478bd9Sstevel@tonic-gate 	(void) printf("%s 0x%x\n", hdr, *(uchar_t *)mp->b_rptr);
1107c478bd9Sstevel@tonic-gate }
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate static void
dedump_int(mblk_t * mp)1137c478bd9Sstevel@tonic-gate dedump_int(mblk_t *mp)
1147c478bd9Sstevel@tonic-gate {
1157c478bd9Sstevel@tonic-gate 	(void) printf("%s %d\n", hdr, *(int *)mp->b_rptr);
1167c478bd9Sstevel@tonic-gate }
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate static void
dedump_ssize(mblk_t * mp)1197c478bd9Sstevel@tonic-gate dedump_ssize(mblk_t *mp)
1207c478bd9Sstevel@tonic-gate {
1217c478bd9Sstevel@tonic-gate 	(void) printf("%s %ld\n", hdr, *(ssize_t *)mp->b_rptr);
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate static void
dedump_cmdblk(mblk_t * mp)125*ca9327a6Smeem dedump_cmdblk(mblk_t *mp)
126*ca9327a6Smeem {
127*ca9327a6Smeem 	struct cmdblk *cbp = (struct cmdblk *)mp->b_rptr;
128*ca9327a6Smeem 
129*ca9327a6Smeem 	(void) printf("%s cmd %x cred %p len %u error %d\n", hdr, cbp->cb_cmd,
130*ca9327a6Smeem 	    (void *)cbp->cb_cr, cbp->cb_len, cbp->cb_error);
131*ca9327a6Smeem }
132*ca9327a6Smeem 
133*ca9327a6Smeem static void
dedump_iocblk(mblk_t * mp)1347c478bd9Sstevel@tonic-gate dedump_iocblk(mblk_t *mp)
1357c478bd9Sstevel@tonic-gate {
1367c478bd9Sstevel@tonic-gate 	struct iocblk *ic = (struct iocblk *)mp->b_rptr;
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	(void) printf("%s cmd %x cred %p id %u flag %x count %ld rval %d "
1397c478bd9Sstevel@tonic-gate 	    "err %d\n", hdr, ic->ioc_cmd, (void *)ic->ioc_cr, ic->ioc_id,
1407c478bd9Sstevel@tonic-gate 	    ic->ioc_flag, ic->ioc_count, ic->ioc_rval, ic->ioc_error);
1417c478bd9Sstevel@tonic-gate }
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate static void
dedump_stroptions(mblk_t * mp)1447c478bd9Sstevel@tonic-gate dedump_stroptions(mblk_t *mp)
1457c478bd9Sstevel@tonic-gate {
1467c478bd9Sstevel@tonic-gate 	struct stroptions *so = (struct stroptions *)mp->b_rptr;
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	(void) printf("%s flag %x readopt %d wroff %u\n", hdr,
1497c478bd9Sstevel@tonic-gate 	    so->so_flags, so->so_readopt, so->so_wroff);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 	(void) printf("%s minpsz %ld maxpsz %ld hiwat %lu lowat %lu\n", hdrpad,
1527c478bd9Sstevel@tonic-gate 	    so->so_minpsz, so->so_maxpsz, so->so_hiwat, so->so_lowat);
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	(void) printf("%s band %u erropt %u maxblk %ld copyopt %u\n", hdrpad,
1557c478bd9Sstevel@tonic-gate 	    so->so_band, so->so_erropt, so->so_maxblk, so->so_copyopt);
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate static void
dedump_copyreq(mblk_t * mp)1597c478bd9Sstevel@tonic-gate dedump_copyreq(mblk_t *mp)
1607c478bd9Sstevel@tonic-gate {
1617c478bd9Sstevel@tonic-gate 	struct copyreq *cq = (struct copyreq *)mp->b_rptr;
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	(void) printf("%s cmd %x cred %p id %u flag %x priv %p addr %p size "
1647c478bd9Sstevel@tonic-gate 	    "%lu\n", hdr, cq->cq_cmd, (void *)cq->cq_cr, cq->cq_id, cq->cq_flag,
1657c478bd9Sstevel@tonic-gate 	    (void *)cq->cq_private, (void *)cq->cq_addr, cq->cq_size);
1667c478bd9Sstevel@tonic-gate }
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate static void
dedump_copyresp(mblk_t * mp)1697c478bd9Sstevel@tonic-gate dedump_copyresp(mblk_t *mp)
1707c478bd9Sstevel@tonic-gate {
1717c478bd9Sstevel@tonic-gate 	struct copyresp *cp = (struct copyresp *)mp->b_rptr;
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 	(void) printf("%s cmd %x cred %p id %u flag %x priv %p rval %p\n", hdr,
1747c478bd9Sstevel@tonic-gate 	    cp->cp_cmd, (void *)cp->cp_cr, cp->cp_id, cp->cp_flag,
1757c478bd9Sstevel@tonic-gate 	    (void *)cp->cp_private, (void *)cp->cp_rval);
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate typedef struct msgfmt {
1797c478bd9Sstevel@tonic-gate 	uchar_t	m_type;
1807c478bd9Sstevel@tonic-gate 	char	m_desc[15];
1817c478bd9Sstevel@tonic-gate 	void	(*m_print)(mblk_t *);
1827c478bd9Sstevel@tonic-gate } msgfmt_t;
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate static msgfmt_t msgfmt[256] = {
1857c478bd9Sstevel@tonic-gate 	{	M_DATA,		"M_DATA    ", 	dedump_raw		},
1867c478bd9Sstevel@tonic-gate 	{	M_PROTO,	"M_PROTO   ", 	dedump_raw		},
1877c478bd9Sstevel@tonic-gate 	{	M_BREAK,	"M_BREAK   ", 	dedump_raw		},
1887c478bd9Sstevel@tonic-gate 	{	M_PASSFP,	"M_PASSFP  ", 	dedump_raw		},
1897c478bd9Sstevel@tonic-gate 	{	M_EVENT,	"M_EVENT   ", 	dedump_raw		},
1907c478bd9Sstevel@tonic-gate 	{	M_SIG,		"M_SIG     ", 	dedump_char		},
1917c478bd9Sstevel@tonic-gate 	{	M_DELAY,	"M_DELAY   ", 	dedump_int		},
1927c478bd9Sstevel@tonic-gate 	{	M_CTL,		"M_CTL     ", 	dedump_raw		},
1937c478bd9Sstevel@tonic-gate 	{	M_IOCTL,	"M_IOCTL   ", 	dedump_iocblk		},
1947c478bd9Sstevel@tonic-gate 	{	M_SETOPTS,	"M_SETOPTS ", 	dedump_stroptions	},
1957c478bd9Sstevel@tonic-gate 	{	M_RSE,		"M_RSE     ", 	dedump_raw		},
1967c478bd9Sstevel@tonic-gate 	{	M_IOCACK,	"M_IOCACK  ", 	dedump_iocblk		},
1977c478bd9Sstevel@tonic-gate 	{	M_IOCNAK,	"M_IOCNAK  ", 	dedump_iocblk		},
1987c478bd9Sstevel@tonic-gate 	{	M_PCPROTO,	"M_PCPROTO ", 	dedump_raw		},
1997c478bd9Sstevel@tonic-gate 	{	M_PCSIG,	"M_PCSIG   ", 	dedump_char		},
2007c478bd9Sstevel@tonic-gate 	{	M_READ,		"M_READ    ", 	dedump_ssize		},
2017c478bd9Sstevel@tonic-gate 	{	M_FLUSH,	"M_FLUSH   ", 	dedump_char		},
2027c478bd9Sstevel@tonic-gate 	{	M_STOP,		"M_STOP    ", 	dedump_raw		},
2037c478bd9Sstevel@tonic-gate 	{	M_START,	"M_START   ", 	dedump_raw		},
2047c478bd9Sstevel@tonic-gate 	{	M_HANGUP,	"M_HANGUP  ", 	dedump_raw		},
2057c478bd9Sstevel@tonic-gate 	{	M_ERROR,	"M_ERROR   ", 	dedump_char		},
2067c478bd9Sstevel@tonic-gate 	{	M_COPYIN,	"M_COPYIN  ", 	dedump_copyreq		},
2077c478bd9Sstevel@tonic-gate 	{	M_COPYOUT,	"M_COPYOUT ", 	dedump_copyreq		},
2087c478bd9Sstevel@tonic-gate 	{	M_IOCDATA,	"M_IOCDATA ", 	dedump_copyresp		},
2097c478bd9Sstevel@tonic-gate 	{	M_PCRSE,	"M_PCRSE   ", 	dedump_raw		},
2107c478bd9Sstevel@tonic-gate 	{	M_STOPI,	"M_STOPI   ", 	dedump_raw		},
2117c478bd9Sstevel@tonic-gate 	{	M_STARTI,	"M_STARTI  ", 	dedump_raw		},
2127c478bd9Sstevel@tonic-gate 	{	M_PCEVENT,	"M_PCEVENT ", 	dedump_raw		},
2137c478bd9Sstevel@tonic-gate 	{	M_UNHANGUP,	"M_UNHANGUP", 	dedump_raw		},
214*ca9327a6Smeem 	{	M_CMD,		"M_CMD     ", 	dedump_cmdblk		},
2157c478bd9Sstevel@tonic-gate };
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate /*ARGSUSED1*/
2187c478bd9Sstevel@tonic-gate static int
dedumpopen(queue_t * q,dev_t * devp,int oflag,int sflag,cred_t * crp)2197c478bd9Sstevel@tonic-gate dedumpopen(queue_t *q, dev_t *devp, int oflag, int sflag, cred_t *crp)
2207c478bd9Sstevel@tonic-gate {
2217c478bd9Sstevel@tonic-gate 	if (!sflag)
2227c478bd9Sstevel@tonic-gate 		return (ENXIO);
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 	if (q->q_ptr)
2257c478bd9Sstevel@tonic-gate 		return (0);		/* already attached */
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	qprocson(q);
2287c478bd9Sstevel@tonic-gate 	return (0);
2297c478bd9Sstevel@tonic-gate }
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate /*ARGSUSED1*/
2327c478bd9Sstevel@tonic-gate static int
dedumpclose(queue_t * q,int flag,cred_t * crp)2337c478bd9Sstevel@tonic-gate dedumpclose(queue_t *q, int flag, cred_t *crp)
2347c478bd9Sstevel@tonic-gate {
2357c478bd9Sstevel@tonic-gate 	qprocsoff(q);
2367c478bd9Sstevel@tonic-gate 	return (0);
2377c478bd9Sstevel@tonic-gate }
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate /*
2407c478bd9Sstevel@tonic-gate  * Common put procedure for upstream and downstream.
2417c478bd9Sstevel@tonic-gate  */
2427c478bd9Sstevel@tonic-gate static int
dedumpput(queue_t * q,mblk_t * mp)2437c478bd9Sstevel@tonic-gate dedumpput(queue_t *q, mblk_t *mp)
2447c478bd9Sstevel@tonic-gate {
2457c478bd9Sstevel@tonic-gate 	unsigned char type = DB_TYPE(mp);
2467c478bd9Sstevel@tonic-gate 	ssize_t hdrlen;
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	hdrlen = snprintf(hdr, sizeof (hdr), "%s %p %10s ",
2497c478bd9Sstevel@tonic-gate 	    (q->q_flag & QREADR) ? "RD" : "WR", (void *)q, msgfmt[type].m_desc);
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	hdrpad[hdrlen] = '\0';
2527c478bd9Sstevel@tonic-gate 	msgfmt[type].m_print(mp);
2537c478bd9Sstevel@tonic-gate 	hdrpad[hdrlen] = ' ';
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	putnext(q, mp);
2567c478bd9Sstevel@tonic-gate 	return (0);
2577c478bd9Sstevel@tonic-gate }
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate struct module_info dedump_minfo = {
2607c478bd9Sstevel@tonic-gate 	0xaaa, "dedump", 0, INFPSZ, 0, 0
2617c478bd9Sstevel@tonic-gate };
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate struct qinit dedumprinit = {
2647c478bd9Sstevel@tonic-gate 	dedumpput, NULL, dedumpopen, dedumpclose, NULL, &dedump_minfo, NULL
2657c478bd9Sstevel@tonic-gate };
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate struct qinit dedumpwinit = {
2687c478bd9Sstevel@tonic-gate 	dedumpput, NULL, NULL, NULL, NULL, &dedump_minfo, NULL
2697c478bd9Sstevel@tonic-gate };
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate struct streamtab dedumpinfo = {
2727c478bd9Sstevel@tonic-gate 	&dedumprinit, &dedumpwinit, NULL, NULL,
2737c478bd9Sstevel@tonic-gate };
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate static struct fmodsw fsw = {
2767c478bd9Sstevel@tonic-gate 	"dedump",
2777c478bd9Sstevel@tonic-gate 	&dedumpinfo,
2787c478bd9Sstevel@tonic-gate 	D_MP | D_MTPERMOD	/* just to serialize printfs */
2797c478bd9Sstevel@tonic-gate };
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate static struct modlstrmod modlstrmod = {
2827c478bd9Sstevel@tonic-gate 	&mod_strmodops, "dump streams module", &fsw
2837c478bd9Sstevel@tonic-gate };
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
2867c478bd9Sstevel@tonic-gate 	MODREV_1, &modlstrmod, NULL
2877c478bd9Sstevel@tonic-gate };
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate int
_init(void)2907c478bd9Sstevel@tonic-gate _init(void)
2917c478bd9Sstevel@tonic-gate {
2927c478bd9Sstevel@tonic-gate 	int i;
2937c478bd9Sstevel@tonic-gate 	msgfmt_t mf;
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate 	/*
2967c478bd9Sstevel@tonic-gate 	 * Sort msgfmt[] so that msgfmt[n] describes message type n.
2977c478bd9Sstevel@tonic-gate 	 */
2987c478bd9Sstevel@tonic-gate 	for (i = 255; i != 0; i--) {
2997c478bd9Sstevel@tonic-gate 		mf = msgfmt[i];
3007c478bd9Sstevel@tonic-gate 		msgfmt[i].m_type = i;
3017c478bd9Sstevel@tonic-gate 		(void) sprintf(msgfmt[i].m_desc, "M_BOGUS_0x%x", i);
3027c478bd9Sstevel@tonic-gate 		msgfmt[i].m_print = dedump_raw;
3037c478bd9Sstevel@tonic-gate 		if (mf.m_desc[0] != 0)
3047c478bd9Sstevel@tonic-gate 			msgfmt[mf.m_type] = mf;
3057c478bd9Sstevel@tonic-gate 	}
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	/*
3087c478bd9Sstevel@tonic-gate 	 * Fill hdrpad[] with as many spaces as will fit.
3097c478bd9Sstevel@tonic-gate 	 */
3107c478bd9Sstevel@tonic-gate 	(void) memset(hdrpad, ' ', sizeof (hdrpad) - 1);
3117c478bd9Sstevel@tonic-gate 	hdrpad[sizeof (hdrpad) - 1] = '\0';
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 	return (mod_install(&modlinkage));
3147c478bd9Sstevel@tonic-gate }
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate int
_fini(void)3177c478bd9Sstevel@tonic-gate _fini(void)
3187c478bd9Sstevel@tonic-gate {
3197c478bd9Sstevel@tonic-gate 	return (mod_remove(&modlinkage));
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)3237c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
3247c478bd9Sstevel@tonic-gate {
3257c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
3267c478bd9Sstevel@tonic-gate }
327