xref: /titanic_41/usr/src/cmd/mdb/common/modules/ufs/ufs.c (revision 9df12a23948bd40cbe37ce88d84e272c3894e675)
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*9df12a23Ssjelinek  * Common Development and Distribution License (the "License").
6*9df12a23Ssjelinek  * 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*9df12a23Ssjelinek  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <mdb/mdb_modapi.h>
297c478bd9Sstevel@tonic-gate #include <mdb/mdb_ks.h>
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
327c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_inode.h>
337c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_acl.h>
347c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fs.h>
357c478bd9Sstevel@tonic-gate 
36*9df12a23Ssjelinek #include "ufs_cmds.h"
37*9df12a23Ssjelinek 
387c478bd9Sstevel@tonic-gate typedef struct inode_walk_data {
397c478bd9Sstevel@tonic-gate 	int iw_inohsz;
407c478bd9Sstevel@tonic-gate 	int iw_inohcnt;
417c478bd9Sstevel@tonic-gate 	uintptr_t iw_ihead;
427c478bd9Sstevel@tonic-gate 	inode_t iw_inode;
437c478bd9Sstevel@tonic-gate } inode_walk_data_t;
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate static int
inode_walk_init(mdb_walk_state_t * wsp)467c478bd9Sstevel@tonic-gate inode_walk_init(mdb_walk_state_t *wsp)
477c478bd9Sstevel@tonic-gate {
487c478bd9Sstevel@tonic-gate 	int inohsz;
497c478bd9Sstevel@tonic-gate 	uintptr_t ihead;
507c478bd9Sstevel@tonic-gate 	union ihead ih;
517c478bd9Sstevel@tonic-gate 	inode_walk_data_t *iw;
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate 	if (wsp->walk_addr != NULL) {
547c478bd9Sstevel@tonic-gate 		mdb_warn("inode_cache only supports global walks\n");
557c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
567c478bd9Sstevel@tonic-gate 	}
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&inohsz, "inohsz") == -1) {
597c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read 'inohsz'");
607c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
617c478bd9Sstevel@tonic-gate 	}
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 	if (inohsz == 0)
647c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&ihead, "ihead") == -1) {
677c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read 'ihead'");
687c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
697c478bd9Sstevel@tonic-gate 	}
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 	if (mdb_vread(&ih, sizeof (union ihead), ihead) == -1) {
727c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read ihead at %p", ihead);
737c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
747c478bd9Sstevel@tonic-gate 	}
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	iw = mdb_alloc(sizeof (inode_walk_data_t), UM_SLEEP);
777c478bd9Sstevel@tonic-gate 	iw->iw_inohsz = inohsz;
787c478bd9Sstevel@tonic-gate 	iw->iw_inohcnt = 0;
797c478bd9Sstevel@tonic-gate 	iw->iw_ihead = ihead;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)ih.ih_chain[0];
827c478bd9Sstevel@tonic-gate 	wsp->walk_data = iw;
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
857c478bd9Sstevel@tonic-gate }
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate static int
inode_walk_step(mdb_walk_state_t * wsp)887c478bd9Sstevel@tonic-gate inode_walk_step(mdb_walk_state_t *wsp)
897c478bd9Sstevel@tonic-gate {
907c478bd9Sstevel@tonic-gate 	uintptr_t addr = wsp->walk_addr;
917c478bd9Sstevel@tonic-gate 	inode_walk_data_t *iw = wsp->walk_data;
927c478bd9Sstevel@tonic-gate 	union ihead ih;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	while (addr == iw->iw_ihead) {
957c478bd9Sstevel@tonic-gate 		if (++iw->iw_inohcnt >= iw->iw_inohsz)
967c478bd9Sstevel@tonic-gate 			return (WALK_DONE);
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate 		iw->iw_ihead += sizeof (union ihead);
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 		if (mdb_vread(&ih, sizeof (union ihead), iw->iw_ihead) == -1) {
1017c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read ihead at %p", iw->iw_ihead);
1027c478bd9Sstevel@tonic-gate 			return (WALK_DONE);
1037c478bd9Sstevel@tonic-gate 		}
1047c478bd9Sstevel@tonic-gate 		addr = (uintptr_t)ih.ih_chain[0];
1057c478bd9Sstevel@tonic-gate 	}
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 	if (mdb_vread(&iw->iw_inode, sizeof (inode_t), addr) == -1) {
1087c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read inode at %p", addr);
1097c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
1107c478bd9Sstevel@tonic-gate 	}
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)iw->iw_inode.i_forw;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 	return (wsp->walk_callback(addr, (void *)(uintptr_t)iw->iw_inohcnt,
1157c478bd9Sstevel@tonic-gate 	    wsp->walk_cbdata));
1167c478bd9Sstevel@tonic-gate }
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate static void
inode_walk_fini(mdb_walk_state_t * wsp)1197c478bd9Sstevel@tonic-gate inode_walk_fini(mdb_walk_state_t *wsp)
1207c478bd9Sstevel@tonic-gate {
1217c478bd9Sstevel@tonic-gate 	mdb_free(wsp->walk_data, sizeof (inode_walk_data_t));
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate typedef struct inode_cbdata {
1257c478bd9Sstevel@tonic-gate 	ino_t id_inumber;
1267c478bd9Sstevel@tonic-gate 	dev_t id_device;
1277c478bd9Sstevel@tonic-gate 	uintptr_t id_addr;
1287c478bd9Sstevel@tonic-gate 	uint_t id_flags;
1297c478bd9Sstevel@tonic-gate } inode_cbdata_t;
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate static int
inode_cache_cb(uintptr_t addr,const int inohcnt,inode_cbdata_t * id)1327c478bd9Sstevel@tonic-gate inode_cache_cb(uintptr_t addr, const int inohcnt, inode_cbdata_t *id)
1337c478bd9Sstevel@tonic-gate {
1347c478bd9Sstevel@tonic-gate 	inode_t inode;
1357c478bd9Sstevel@tonic-gate 	int inohsz;
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate 	if (mdb_vread(&inode, sizeof (inode), addr) == -1) {
1387c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read inode_t at %p", addr);
1397c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
1407c478bd9Sstevel@tonic-gate 	}
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	if (id->id_device != 0 && inode.i_dev != id->id_device)
1437c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	if (id->id_inumber != 0 && inode.i_number != id->id_inumber)
1467c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	if (id->id_flags & DCMD_ADDRSPEC && addr != id->id_addr)
1497c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 	if (id->id_flags & DCMD_PIPE_OUT) {
1527c478bd9Sstevel@tonic-gate 		mdb_printf("%p\n", addr);
1537c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
1547c478bd9Sstevel@tonic-gate 	}
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 	mdb_printf("%0?p %10lld %15lx",
1577c478bd9Sstevel@tonic-gate 	    addr, (u_longlong_t)inode.i_number, inode.i_dev);
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	/*
1607c478bd9Sstevel@tonic-gate 	 * INOHASH needs inohsz.
1617c478bd9Sstevel@tonic-gate 	 */
1627c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&inohsz, "inohsz") == -1) {
1637c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read 'inohsz'");
1647c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
1657c478bd9Sstevel@tonic-gate 	}
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	/*
1687c478bd9Sstevel@tonic-gate 	 * Is the inode in the hash chain it should be?
1697c478bd9Sstevel@tonic-gate 	 */
1707c478bd9Sstevel@tonic-gate 	if (inohcnt == INOHASH(inode.i_number)) {
1717c478bd9Sstevel@tonic-gate 		mdb_printf(" %5d\n", inohcnt);
1727c478bd9Sstevel@tonic-gate 	} else {
1737c478bd9Sstevel@tonic-gate 		mdb_printf(" %<b>%5d/%5d ??</b>\n",
1747c478bd9Sstevel@tonic-gate 		    inohcnt, INOHASH(inode.i_number));
1757c478bd9Sstevel@tonic-gate 	}
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
1787c478bd9Sstevel@tonic-gate }
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1817c478bd9Sstevel@tonic-gate static int
inode_cache(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1827c478bd9Sstevel@tonic-gate inode_cache(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1837c478bd9Sstevel@tonic-gate {
1847c478bd9Sstevel@tonic-gate 	inode_cbdata_t id;
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate 	id.id_inumber = 0;
1877c478bd9Sstevel@tonic-gate 	id.id_device = 0;
1887c478bd9Sstevel@tonic-gate 	id.id_addr = addr;
1897c478bd9Sstevel@tonic-gate 	id.id_flags = flags;
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
1927c478bd9Sstevel@tonic-gate 	    'i', MDB_OPT_UINT64, &id.id_inumber,
1937c478bd9Sstevel@tonic-gate 	    'd', MDB_OPT_UINTPTR, &id.id_device, NULL) != argc)
1947c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags) && (flags & DCMD_PIPE_OUT) == 0) {
1977c478bd9Sstevel@tonic-gate 		mdb_printf("%<u>%-?s %10s %15s %5s%</u>\n",
1987c478bd9Sstevel@tonic-gate 		    "ADDR", "INUMBER", "DEVICE", "CHAIN");
1997c478bd9Sstevel@tonic-gate 	}
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	if (mdb_walk("inode_cache", (mdb_walk_cb_t)inode_cache_cb, &id) == -1) {
2027c478bd9Sstevel@tonic-gate 		mdb_warn("can't walk inode cache");
2037c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
2047c478bd9Sstevel@tonic-gate 	}
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
2077c478bd9Sstevel@tonic-gate }
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2107c478bd9Sstevel@tonic-gate static int
inode(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)2117c478bd9Sstevel@tonic-gate inode(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2127c478bd9Sstevel@tonic-gate {
2137c478bd9Sstevel@tonic-gate 	uint_t verbose = FALSE;
2147c478bd9Sstevel@tonic-gate 	inode_t inode;
2157c478bd9Sstevel@tonic-gate 	char buf[64];
2167c478bd9Sstevel@tonic-gate 	char path[MAXPATHLEN];
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	static const mdb_bitmask_t i_flag_masks[] = {
2197c478bd9Sstevel@tonic-gate 		{ "UPD",		IUPD,		IUPD		},
2207c478bd9Sstevel@tonic-gate 		{ "ACC",		IACC,		IACC		},
2217c478bd9Sstevel@tonic-gate 		{ "MOD",		IMOD,		IMOD		},
2227c478bd9Sstevel@tonic-gate 		{ "CHG",		ICHG,		ICHG		},
2237c478bd9Sstevel@tonic-gate 		{ "NOACC",		INOACC,		INOACC		},
2247c478bd9Sstevel@tonic-gate 		{ "MODTIME",		IMODTIME,	IMODTIME	},
2257c478bd9Sstevel@tonic-gate 		{ "REF",		IREF,		IREF		},
2267c478bd9Sstevel@tonic-gate 		{ "SYNC",		ISYNC,		ISYNC		},
2277c478bd9Sstevel@tonic-gate 		{ "FASTSYMLNK",		IFASTSYMLNK,	IFASTSYMLNK	},
2287c478bd9Sstevel@tonic-gate 		{ "MODACC",		IMODACC,	IMODACC		},
2297c478bd9Sstevel@tonic-gate 		{ "ATTCHG",		IATTCHG,	IATTCHG		},
2307c478bd9Sstevel@tonic-gate 		{ "BDWRITE",		IBDWRITE,	IBDWRITE	},
2317c478bd9Sstevel@tonic-gate 		{ "STALE",		ISTALE,		ISTALE		},
2327c478bd9Sstevel@tonic-gate 		{ "DEL",		IDEL,		IDEL		},
2337c478bd9Sstevel@tonic-gate 		{ "DIRECTIO",		IDIRECTIO,	IDIRECTIO	},
2347c478bd9Sstevel@tonic-gate 		{ "JUNKIQ",		IJUNKIQ,	IJUNKIQ		},
2357c478bd9Sstevel@tonic-gate 		{ NULL,			0,		0		}
2367c478bd9Sstevel@tonic-gate 	};
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate 	static const mdb_bitmask_t i_modetype_masks[] = {
2397c478bd9Sstevel@tonic-gate 		{ "p",	IFMT,	IFIFO		},
2407c478bd9Sstevel@tonic-gate 		{ "c",	IFMT,	IFCHR		},
2417c478bd9Sstevel@tonic-gate 		{ "d",	IFMT,	IFDIR		},
2427c478bd9Sstevel@tonic-gate 		{ "b",	IFMT,	IFBLK		},
2437c478bd9Sstevel@tonic-gate 		{ "-",	IFMT,	IFREG		},
2447c478bd9Sstevel@tonic-gate 		{ "l",	IFMT,	IFLNK		},
2457c478bd9Sstevel@tonic-gate 		{ "S",	IFMT,	IFSHAD		},
2467c478bd9Sstevel@tonic-gate 		{ "s",	IFMT,	IFSOCK		},
2477c478bd9Sstevel@tonic-gate 		{ "A",	IFMT,	IFATTRDIR	},
2487c478bd9Sstevel@tonic-gate 		{ NULL,	0,	0		}
2497c478bd9Sstevel@tonic-gate 	};
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
2527c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
2557c478bd9Sstevel@tonic-gate 	    'v', MDB_OPT_SETBITS, TRUE, &verbose, NULL) != argc)
2567c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags) && (flags & DCMD_PIPE_OUT) == 0) {
2597c478bd9Sstevel@tonic-gate 		mdb_printf("%<u>%-?s %10s %1s %5s %8s",
2607c478bd9Sstevel@tonic-gate 		    "ADDR", "INUMBER", "T", "MODE", "SIZE");
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate 		if (verbose)
2637c478bd9Sstevel@tonic-gate 			mdb_printf(" %11s %-22s%</u>\n", "DEVICE", "FLAG");
2647c478bd9Sstevel@tonic-gate 		else
2657c478bd9Sstevel@tonic-gate 			mdb_printf(" %-12s %-21s%</u>\n", "MTIME", "NAME");
2667c478bd9Sstevel@tonic-gate 	}
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 	if (mdb_vread(&inode, sizeof (inode), addr) == -1) {
2697c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read inode_t at %p", addr);
2707c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
2717c478bd9Sstevel@tonic-gate 	}
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 	mdb_printf("%0?p %10lld %b %5#o %8llx",
2747c478bd9Sstevel@tonic-gate 	    addr, (u_longlong_t)inode.i_number, inode.i_mode, i_modetype_masks,
2757c478bd9Sstevel@tonic-gate 	    inode.i_mode & ~IFMT, inode.i_size);
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	if (verbose) {
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 		mdb_printf(" %11lx <%b>\n",
2807c478bd9Sstevel@tonic-gate 		    inode.i_dev, inode.i_flag, i_flag_masks);
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 		mdb_inc_indent(2);
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 		mdb_printf("%Y\n", inode.i_mtime.tv_sec);
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 		if (mdb_vnode2path((uintptr_t)inode.i_vnode, path,
2877c478bd9Sstevel@tonic-gate 		    sizeof (path)) == 0 && *path != '\0')
2887c478bd9Sstevel@tonic-gate 			mdb_printf("%s\n", path);
2897c478bd9Sstevel@tonic-gate 		else
2907c478bd9Sstevel@tonic-gate 			mdb_printf("??\n");
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 		mdb_dec_indent(2);
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 		return (DCMD_OK);
2957c478bd9Sstevel@tonic-gate 	}
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 	/*
2987c478bd9Sstevel@tonic-gate 	 * Not verbose, everything must fit into one line.
2997c478bd9Sstevel@tonic-gate 	 */
3007c478bd9Sstevel@tonic-gate 	mdb_snprintf(buf, sizeof (buf), "%Y", inode.i_mtime.tv_sec);
3017c478bd9Sstevel@tonic-gate 	buf[17] = '\0'; /* drop seconds */
3027c478bd9Sstevel@tonic-gate 	if (buf[0] == '1' || buf[0] == '2')
3037c478bd9Sstevel@tonic-gate 		mdb_printf(" %12s", buf + 5); /* drop year */
3047c478bd9Sstevel@tonic-gate 	else
3057c478bd9Sstevel@tonic-gate 		mdb_printf(" %-12s", "?");
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	if (mdb_vnode2path((uintptr_t)inode.i_vnode, path,
3087c478bd9Sstevel@tonic-gate 	    sizeof (path)) == 0 && *path != '\0') {
3097c478bd9Sstevel@tonic-gate 		if (strlen(path) <= 21)
3107c478bd9Sstevel@tonic-gate 			mdb_printf(" %-21s\n", path);
3117c478bd9Sstevel@tonic-gate 		else
3127c478bd9Sstevel@tonic-gate 			mdb_printf(" ...%-18s\n", path + strlen(path) - 18);
3137c478bd9Sstevel@tonic-gate 	} else {
3147c478bd9Sstevel@tonic-gate 		mdb_printf(" ??\n");
3157c478bd9Sstevel@tonic-gate 	}
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate static struct {
3217c478bd9Sstevel@tonic-gate 	int am_offset;
3227c478bd9Sstevel@tonic-gate 	char *am_tag;
3237c478bd9Sstevel@tonic-gate } acl_map[] = {
3247c478bd9Sstevel@tonic-gate 	{ offsetof(si_t, aowner), "USER_OBJ" },
3257c478bd9Sstevel@tonic-gate 	{ offsetof(si_t, agroup), "GROUP_OBJ" },
3267c478bd9Sstevel@tonic-gate 	{ offsetof(si_t, aother), "OTHER_OBJ" },
3277c478bd9Sstevel@tonic-gate 	{ offsetof(si_t, ausers), "USER" },
3287c478bd9Sstevel@tonic-gate 	{ offsetof(si_t, agroups), "GROUP" },
3297c478bd9Sstevel@tonic-gate 	{ offsetof(si_t, downer), "DEF_USER_OBJ" },
3307c478bd9Sstevel@tonic-gate 	{ offsetof(si_t, dgroup), "DEF_GROUP_OBJ" },
3317c478bd9Sstevel@tonic-gate 	{ offsetof(si_t, dother), "DEF_OTHER_OBJ" },
3327c478bd9Sstevel@tonic-gate 	{ offsetof(si_t, dusers), "DEF_USER" },
3337c478bd9Sstevel@tonic-gate 	{ offsetof(si_t, dgroups), "DEF_GROUP" },
3347c478bd9Sstevel@tonic-gate 	{ -1, NULL }
3357c478bd9Sstevel@tonic-gate };
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate static int
acl_walk_init(mdb_walk_state_t * wsp)3387c478bd9Sstevel@tonic-gate acl_walk_init(mdb_walk_state_t *wsp)
3397c478bd9Sstevel@tonic-gate {
3407c478bd9Sstevel@tonic-gate 	uintptr_t addr = wsp->walk_addr;
3417c478bd9Sstevel@tonic-gate 	inode_t inode;
3427c478bd9Sstevel@tonic-gate 	si_t *si;
3437c478bd9Sstevel@tonic-gate 	ufs_ic_acl_t **aclpp;
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	if (addr == NULL) {
3467c478bd9Sstevel@tonic-gate 		mdb_warn("acl walk needs an inode address\n");
3477c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
3487c478bd9Sstevel@tonic-gate 	}
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate 	if (mdb_vread(&inode, sizeof (inode), addr) == -1) {
3517c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read inode_t at %p", addr);
3527c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
3537c478bd9Sstevel@tonic-gate 	}
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate 	if (inode.i_ufs_acl == NULL)
3567c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate 	si = mdb_alloc(sizeof (si_t), UM_SLEEP);
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate 	if (mdb_vread(si, sizeof (si_t), (uintptr_t)inode.i_ufs_acl) == -1) {
3617c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read si_t at %p", inode.i_ufs_acl);
3627c478bd9Sstevel@tonic-gate 		mdb_free(si, sizeof (si_t));
3637c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
3647c478bd9Sstevel@tonic-gate 	}
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate 	/* LINTED - alignment */
3677c478bd9Sstevel@tonic-gate 	aclpp = (ufs_ic_acl_t **)((caddr_t)si + acl_map[0].am_offset);
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)*aclpp;
3707c478bd9Sstevel@tonic-gate 	wsp->walk_data = si;
3717c478bd9Sstevel@tonic-gate 	wsp->walk_arg = 0;
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
3747c478bd9Sstevel@tonic-gate }
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate static int
acl_walk_step(mdb_walk_state_t * wsp)3777c478bd9Sstevel@tonic-gate acl_walk_step(mdb_walk_state_t *wsp)
3787c478bd9Sstevel@tonic-gate {
3797c478bd9Sstevel@tonic-gate 	uintptr_t addr = wsp->walk_addr;
3807c478bd9Sstevel@tonic-gate 	si_t *si = wsp->walk_data;
3817c478bd9Sstevel@tonic-gate 	uint_t i = (uintptr_t)wsp->walk_arg;
3827c478bd9Sstevel@tonic-gate 	ufs_ic_acl_t **aclpp;
3837c478bd9Sstevel@tonic-gate 	ufs_ic_acl_t acl;
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate 	while (addr == NULL) {
3867c478bd9Sstevel@tonic-gate 		wsp->walk_arg = (void *)(uintptr_t)++i;
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 		if (acl_map[i].am_offset == -1)
3897c478bd9Sstevel@tonic-gate 			return (WALK_DONE);
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate 		/* LINTED - alignment */
3927c478bd9Sstevel@tonic-gate 		aclpp = (ufs_ic_acl_t **)((caddr_t)si + acl_map[i].am_offset);
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate 		addr = (uintptr_t)*aclpp;
3957c478bd9Sstevel@tonic-gate 	}
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate 	if (mdb_vread(&acl, sizeof (acl), addr) == -1) {
3987c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read acl at %p", addr);
3997c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
4007c478bd9Sstevel@tonic-gate 	}
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)acl.acl_ic_next;
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate 	return (wsp->walk_callback(addr, &acl, acl_map[i].am_tag));
4057c478bd9Sstevel@tonic-gate }
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate static void
acl_walk_fini(mdb_walk_state_t * wsp)4087c478bd9Sstevel@tonic-gate acl_walk_fini(mdb_walk_state_t *wsp)
4097c478bd9Sstevel@tonic-gate {
4107c478bd9Sstevel@tonic-gate 	mdb_free(wsp->walk_data, sizeof (si_t));
4117c478bd9Sstevel@tonic-gate }
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate static int
acl_cb(uintptr_t addr,const void * arg,void * data)4147c478bd9Sstevel@tonic-gate acl_cb(uintptr_t addr, const void *arg, void *data)
4157c478bd9Sstevel@tonic-gate {
4167c478bd9Sstevel@tonic-gate 	ufs_ic_acl_t *aclp = (ufs_ic_acl_t *)arg;
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate 	mdb_printf("%?p %-16s %7#o %10d\n",
4197c478bd9Sstevel@tonic-gate 	    addr, (char *)data, aclp->acl_ic_perm, aclp->acl_ic_who);
4207c478bd9Sstevel@tonic-gate 
4217c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
4227c478bd9Sstevel@tonic-gate }
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4257c478bd9Sstevel@tonic-gate static int
acl_dcmd(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)4267c478bd9Sstevel@tonic-gate acl_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
4277c478bd9Sstevel@tonic-gate {
4287c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
4297c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate 	if (argc != 0)
4327c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
4357c478bd9Sstevel@tonic-gate 		mdb_printf("%<u>%?s %-16s %7s %10s%</u>\n",
4367c478bd9Sstevel@tonic-gate 		    "ADDR", "TAG", "PERM", "WHO");
4377c478bd9Sstevel@tonic-gate 	}
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate 	if (mdb_pwalk("acl", (mdb_walk_cb_t)acl_cb, NULL, addr) == -1) {
4407c478bd9Sstevel@tonic-gate 		mdb_warn("can't walk acls of inode %p", addr);
4417c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
4427c478bd9Sstevel@tonic-gate 	}
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
4457c478bd9Sstevel@tonic-gate }
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate static int
cg_walk_init(mdb_walk_state_t * wsp)4497c478bd9Sstevel@tonic-gate cg_walk_init(mdb_walk_state_t *wsp)
4507c478bd9Sstevel@tonic-gate {
4517c478bd9Sstevel@tonic-gate 	if (mdb_layered_walk("buf", wsp) == -1) {
4527c478bd9Sstevel@tonic-gate 		mdb_warn("couldn't walk bio buf hash");
4537c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
4547c478bd9Sstevel@tonic-gate 	}
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
4577c478bd9Sstevel@tonic-gate }
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate static int
cg_walk_step(mdb_walk_state_t * wsp)4607c478bd9Sstevel@tonic-gate cg_walk_step(mdb_walk_state_t *wsp)
4617c478bd9Sstevel@tonic-gate {
4627c478bd9Sstevel@tonic-gate 	uintptr_t addr = (uintptr_t)((const buf_t *)wsp->walk_layer)->b_un.b_cg;
4637c478bd9Sstevel@tonic-gate 	struct cg cg;
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 	if (mdb_vread(&cg, sizeof (cg), addr) == -1) {
4667c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read cg struct at %p", addr);
4677c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
4687c478bd9Sstevel@tonic-gate 	}
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate 	if (cg.cg_magic != CG_MAGIC)
4717c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate 	return (wsp->walk_callback(addr, &cg, wsp->walk_cbdata));
4747c478bd9Sstevel@tonic-gate }
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate static void
pbits(const uchar_t * cp,const int max,const int linelen)4777c478bd9Sstevel@tonic-gate pbits(const uchar_t *cp, const int max, const int linelen)
4787c478bd9Sstevel@tonic-gate {
4797c478bd9Sstevel@tonic-gate 	int i, j, len;
4807c478bd9Sstevel@tonic-gate 	char entry[40];
4817c478bd9Sstevel@tonic-gate 	int linecnt = -1;
4827c478bd9Sstevel@tonic-gate 
4837c478bd9Sstevel@tonic-gate 	for (i = 0; i < max; i++) {
4847c478bd9Sstevel@tonic-gate 		if (isset(cp, i)) {
4857c478bd9Sstevel@tonic-gate 			len = mdb_snprintf(entry, sizeof (entry), "%d", i);
4867c478bd9Sstevel@tonic-gate 			j = i;
4877c478bd9Sstevel@tonic-gate 			while ((i + 1) < max && isset(cp, i+1))
4887c478bd9Sstevel@tonic-gate 				i++;
4897c478bd9Sstevel@tonic-gate 			if (i != j)
4907c478bd9Sstevel@tonic-gate 				len += mdb_snprintf(entry + len,
4917c478bd9Sstevel@tonic-gate 				    sizeof (entry) - len, "-%d", i);
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 			if (linecnt == -1) {
4947c478bd9Sstevel@tonic-gate 				/* first entry */
4957c478bd9Sstevel@tonic-gate 				mdb_printf("%s", entry);
4967c478bd9Sstevel@tonic-gate 				linecnt = linelen - len;
4977c478bd9Sstevel@tonic-gate 			} else if (linecnt - (len + 3) > 0) {
4987c478bd9Sstevel@tonic-gate 				/* subsequent entry on same line */
4997c478bd9Sstevel@tonic-gate 				mdb_printf(", %s", entry);
5007c478bd9Sstevel@tonic-gate 				linecnt -= len + 2;
5017c478bd9Sstevel@tonic-gate 			} else {
5027c478bd9Sstevel@tonic-gate 				/* subsequent enty on new line */
5037c478bd9Sstevel@tonic-gate 				mdb_printf(",\n%s", entry);
5047c478bd9Sstevel@tonic-gate 				linecnt = linelen - len;
5057c478bd9Sstevel@tonic-gate 			}
5067c478bd9Sstevel@tonic-gate 		}
5077c478bd9Sstevel@tonic-gate 	}
5087c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
5097c478bd9Sstevel@tonic-gate }
5107c478bd9Sstevel@tonic-gate 
5117c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5127c478bd9Sstevel@tonic-gate static int
cg(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)5137c478bd9Sstevel@tonic-gate cg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
5147c478bd9Sstevel@tonic-gate {
5157c478bd9Sstevel@tonic-gate 	uint_t verbose = FALSE;
5167c478bd9Sstevel@tonic-gate 	struct cg cg;
5177c478bd9Sstevel@tonic-gate 	struct cg *cgp = &cg;
5187c478bd9Sstevel@tonic-gate 	size_t size;
5197c478bd9Sstevel@tonic-gate 	int i, j, cnt, off;
5207c478bd9Sstevel@tonic-gate 	int32_t *blktot;
5217c478bd9Sstevel@tonic-gate 	short *blks;
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
5247c478bd9Sstevel@tonic-gate 		if (mdb_walk_dcmd("cg", "cg", argc, argv) == -1) {
5257c478bd9Sstevel@tonic-gate 			mdb_warn("can't walk cylinder group structs");
5267c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
5277c478bd9Sstevel@tonic-gate 		}
5287c478bd9Sstevel@tonic-gate 		return (DCMD_OK);
5297c478bd9Sstevel@tonic-gate 	}
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
5327c478bd9Sstevel@tonic-gate 	    'v', MDB_OPT_SETBITS, TRUE, &verbose, NULL) != argc)
5337c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate 	if (mdb_vread(cgp, sizeof (cg), addr) == -1) {
5367c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read cg struct at %p", addr);
5377c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
5387c478bd9Sstevel@tonic-gate 	}
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate 	if (!verbose) {
5417c478bd9Sstevel@tonic-gate 		if (DCMD_HDRSPEC(flags))
5427c478bd9Sstevel@tonic-gate 			mdb_printf("%<u>%4s %?s %10s %10s %10s %10s%</u>\n",
5437c478bd9Sstevel@tonic-gate 			    "CGX", "CG", "NDIR", "NBFREE", "NIFREE", "NFFREE");
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 		mdb_printf("%4d %?p %10d %10d %10d %10d\n", cgp->cg_cgx,
5467c478bd9Sstevel@tonic-gate 		    addr, cgp->cg_cs.cs_ndir, cgp->cg_cs.cs_nbfree,
5477c478bd9Sstevel@tonic-gate 		    cgp->cg_cs.cs_nifree, cgp->cg_cs.cs_nffree);
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate 		return (DCMD_OK);
5507c478bd9Sstevel@tonic-gate 	}
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 	/*
5537c478bd9Sstevel@tonic-gate 	 * Verbose: produce output similiar to "fstyp -v".
5547c478bd9Sstevel@tonic-gate 	 */
5557c478bd9Sstevel@tonic-gate 	if (cgp->cg_btotoff >= cgp->cg_nextfreeoff ||
5567c478bd9Sstevel@tonic-gate 	    cgp->cg_boff >= cgp->cg_nextfreeoff ||
5577c478bd9Sstevel@tonic-gate 	    cgp->cg_iusedoff >= cgp->cg_nextfreeoff ||
5587c478bd9Sstevel@tonic-gate 	    cgp->cg_freeoff >= cgp->cg_nextfreeoff) {
5597c478bd9Sstevel@tonic-gate 		mdb_warn("struct cg at %p seems broken\n", addr);
5607c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
5617c478bd9Sstevel@tonic-gate 	}
5627c478bd9Sstevel@tonic-gate 
5637c478bd9Sstevel@tonic-gate 	size = cgp->cg_nextfreeoff;
5647c478bd9Sstevel@tonic-gate 	cgp = mdb_alloc(size, UM_SLEEP);
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate 	if (mdb_vread(cgp, size, addr) == -1) {
5677c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read struct cg and maps at %p", addr);
5687c478bd9Sstevel@tonic-gate 		mdb_free(cgp, size);
5697c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
5707c478bd9Sstevel@tonic-gate 	}
5717c478bd9Sstevel@tonic-gate 
5727c478bd9Sstevel@tonic-gate 	mdb_printf("%<b>cg %d (%0?p)%</b>\n", cgp->cg_cgx, addr);
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate 	mdb_inc_indent(4);
5757c478bd9Sstevel@tonic-gate 
5767c478bd9Sstevel@tonic-gate 	mdb_printf("time:\t%Y\n", cgp->cg_time);
5777c478bd9Sstevel@tonic-gate 	mdb_printf("ndir:\t%d\n", cgp->cg_cs.cs_ndir);
5787c478bd9Sstevel@tonic-gate 	mdb_printf("nbfree:\t%d\n", cgp->cg_cs.cs_nbfree);
5797c478bd9Sstevel@tonic-gate 	mdb_printf("nifree:\t%d\n", cgp->cg_cs.cs_nifree);
5807c478bd9Sstevel@tonic-gate 	mdb_printf("nffree:\t%d\n", cgp->cg_cs.cs_nffree);
5817c478bd9Sstevel@tonic-gate 
5827c478bd9Sstevel@tonic-gate 	mdb_printf("frsum:");
5837c478bd9Sstevel@tonic-gate 	for (i = 1; i < MAXFRAG; i++)
5847c478bd9Sstevel@tonic-gate 		mdb_printf("\t%d", cgp->cg_frsum[i]);
5857c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
5867c478bd9Sstevel@tonic-gate 
5877c478bd9Sstevel@tonic-gate 	off = cgp->cg_iusedoff;
5887c478bd9Sstevel@tonic-gate 	mdb_printf("used inode map (%0?p):\n", (char *)addr + off);
5897c478bd9Sstevel@tonic-gate 	mdb_inc_indent(4);
5907c478bd9Sstevel@tonic-gate 	pbits((uchar_t *)cgp + off, cgp->cg_niblk / sizeof (char), 72);
5917c478bd9Sstevel@tonic-gate 	mdb_dec_indent(4);
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate 	off = cgp->cg_freeoff;
5947c478bd9Sstevel@tonic-gate 	mdb_printf("free block map (%0?p):\n", (char *)addr + off);
5957c478bd9Sstevel@tonic-gate 	mdb_inc_indent(4);
5967c478bd9Sstevel@tonic-gate 	pbits((uchar_t *)cgp + off, cgp->cg_ndblk / sizeof (char), 72);
5977c478bd9Sstevel@tonic-gate 	mdb_dec_indent(4);
5987c478bd9Sstevel@tonic-gate 
5997c478bd9Sstevel@tonic-gate 	/* LINTED - alignment */
6007c478bd9Sstevel@tonic-gate 	blktot = (int32_t *)((char *)cgp + cgp->cg_btotoff);
6017c478bd9Sstevel@tonic-gate 	/* LINTED - alignment */
6027c478bd9Sstevel@tonic-gate 	blks = (short *)((char *)cgp + cgp->cg_boff);
6037c478bd9Sstevel@tonic-gate 	cnt = (cgp->cg_iusedoff - cgp->cg_boff) / cgp->cg_ncyl / sizeof (short);
6047c478bd9Sstevel@tonic-gate 	mdb_printf("free block positions:\n");
6057c478bd9Sstevel@tonic-gate 	mdb_inc_indent(4);
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate 	for (i = 0; i < cgp->cg_ncyl; i++) {
6087c478bd9Sstevel@tonic-gate 		mdb_printf("c%d:\t(%d)\t", i, blktot[i]);
6097c478bd9Sstevel@tonic-gate 		for (j = 0; j < cnt; j++)
6107c478bd9Sstevel@tonic-gate 			mdb_printf(" %d", blks[i*cnt + j]);
6117c478bd9Sstevel@tonic-gate 		mdb_printf("\n");
6127c478bd9Sstevel@tonic-gate 	}
6137c478bd9Sstevel@tonic-gate 	mdb_dec_indent(4);
6147c478bd9Sstevel@tonic-gate 
6157c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
6167c478bd9Sstevel@tonic-gate 	mdb_dec_indent(4);
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate 	mdb_free(cgp, size);
6197c478bd9Sstevel@tonic-gate 
6207c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
6217c478bd9Sstevel@tonic-gate }
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate void
inode_cache_help(void)6247c478bd9Sstevel@tonic-gate inode_cache_help(void)
6257c478bd9Sstevel@tonic-gate {
6267c478bd9Sstevel@tonic-gate 	mdb_printf(
6277c478bd9Sstevel@tonic-gate 	    "Displays cached inode_t. If an address, an inode number and/or a\n"
6287c478bd9Sstevel@tonic-gate 	    "device is specified, searches inode cache for inodes which match\n"
6297c478bd9Sstevel@tonic-gate 	    "the specified criteria. Prints nothing but the address, if\n"
6307c478bd9Sstevel@tonic-gate 	    "output is a pipe.\n"
6317c478bd9Sstevel@tonic-gate 	    "\n"
6327c478bd9Sstevel@tonic-gate 	    "Options:\n"
6337c478bd9Sstevel@tonic-gate 	    "  -d device    Filter out inodes, which reside on the specified"
6347c478bd9Sstevel@tonic-gate 	    " device.\n"
6357c478bd9Sstevel@tonic-gate 	    "  -i inumber   Filter out inodes with the specified inode"
6367c478bd9Sstevel@tonic-gate 	    " number.\n");
6377c478bd9Sstevel@tonic-gate }
6387c478bd9Sstevel@tonic-gate 
6397c478bd9Sstevel@tonic-gate /*
6407c478bd9Sstevel@tonic-gate  * MDB module linkage
6417c478bd9Sstevel@tonic-gate  */
6427c478bd9Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
6437c478bd9Sstevel@tonic-gate 	{ "inode_cache", "?[-d device] [-i inumber]",
6447c478bd9Sstevel@tonic-gate 		"search/display inodes from inode cache",
6457c478bd9Sstevel@tonic-gate 		inode_cache, inode_cache_help },
6467c478bd9Sstevel@tonic-gate 	{ "inode", ":[-v]", "display summarized inode_t", inode },
6477c478bd9Sstevel@tonic-gate 	{ "acl", ":", "given an inode, display its in core acl's", acl_dcmd },
6487c478bd9Sstevel@tonic-gate 	{ "cg", "?[-v]", "display a summarized cylinder group structure", cg },
649*9df12a23Ssjelinek 	{ "mapentry", ":", "dumps ufslog mapentry", mapentry_dcmd },
650*9df12a23Ssjelinek 	{ "mapstats", ":", "dumps ufslog stats", mapstats_dcmd },
6517c478bd9Sstevel@tonic-gate 	{ NULL }
6527c478bd9Sstevel@tonic-gate };
6537c478bd9Sstevel@tonic-gate 
6547c478bd9Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
6557c478bd9Sstevel@tonic-gate 	{ "inode_cache", "walk inode cache",
6567c478bd9Sstevel@tonic-gate 		inode_walk_init, inode_walk_step, inode_walk_fini },
6577c478bd9Sstevel@tonic-gate 	{ "acl", "given an inode, walk chains of in core acl's",
6587c478bd9Sstevel@tonic-gate 		acl_walk_init, acl_walk_step, acl_walk_fini },
6597c478bd9Sstevel@tonic-gate 	{ "cg", "walk cg's in bio buffer cache",
6607c478bd9Sstevel@tonic-gate 		cg_walk_init, cg_walk_step, NULL },
661*9df12a23Ssjelinek 	{ "ufslogmap", "walk map entries in a ufs_log mt_map",
662*9df12a23Ssjelinek 		ufslogmap_walk_init, ufslogmap_walk_step, NULL },
6637c478bd9Sstevel@tonic-gate 	{ NULL }
6647c478bd9Sstevel@tonic-gate };
6657c478bd9Sstevel@tonic-gate 
6667c478bd9Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers };
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate const mdb_modinfo_t *
_mdb_init(void)6697c478bd9Sstevel@tonic-gate _mdb_init(void)
6707c478bd9Sstevel@tonic-gate {
6717c478bd9Sstevel@tonic-gate 	return (&modinfo);
6727c478bd9Sstevel@tonic-gate }
673