Home | History | Annotate | Line # | Download | only in dumplfs
dumplfs.c revision 1.8
      1 /*	$NetBSD: dumplfs.c,v 1.8 1998/03/01 02:26:12 fvdl Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1991, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 
     36 #include <sys/cdefs.h>
     37 
     38 #ifndef lint
     39 __COPYRIGHT(
     40 "@(#) Copyright (c) 1991, 1993\n\
     41 	The Regents of the University of California.  All rights reserved.\n");
     42 #endif /* not lint */
     43 
     44 #ifndef lint
     45 #if 0
     46 static char sccsid[] = "@(#)dumplfs.c	8.5 (Berkeley) 5/24/95";
     47 #else
     48 __RCSID("$NetBSD: dumplfs.c,v 1.8 1998/03/01 02:26:12 fvdl Exp $");
     49 #endif
     50 #endif /* not lint */
     51 
     52 #include <sys/param.h>
     53 #include <sys/ucred.h>
     54 #include <sys/mount.h>
     55 #include <sys/time.h>
     56 
     57 #include <ufs/ufs/dinode.h>
     58 #include <ufs/lfs/lfs.h>
     59 
     60 #include <err.h>
     61 #include <errno.h>
     62 #include <fcntl.h>
     63 #include <fstab.h>
     64 #include <stdlib.h>
     65 #include <stdio.h>
     66 #include <string.h>
     67 #include <unistd.h>
     68 #include "extern.h"
     69 
     70 static void	addseg __P((char *));
     71 static void	dump_cleaner_info __P((struct lfs *, void *));
     72 static void	dump_dinode __P((struct dinode *));
     73 static void	dump_ifile __P((int, struct lfs *, int));
     74 static int	dump_ipage_ifile __P((int, IFILE *, int));
     75 static int	dump_ipage_segusage __P((struct lfs *, int, IFILE *, int));
     76 static void	dump_segment __P((int, int, daddr_t, struct lfs *, int));
     77 static int	dump_sum __P((int, struct lfs *, SEGSUM *, int, daddr_t));
     78 static void	dump_super __P((struct lfs *));
     79 static void	usage __P((void));
     80 
     81 int		main __P((int, char *[]));
     82 
     83 extern u_long	cksum __P((void *, size_t));
     84 
     85 typedef struct seglist SEGLIST;
     86 struct seglist {
     87         SEGLIST *next;
     88 	int num;
     89 };
     90 SEGLIST	*seglist;
     91 
     92 int daddr_shift;
     93 char *special;
     94 
     95 /* Segment Usage formats */
     96 #define print_suheader \
     97 	(void)printf("segnum\tflags\tnbytes\tninos\tnsums\tlastmod\n")
     98 
     99 #define print_suentry(i, sp) \
    100 	(void)printf("%d\t%c%c%c\t%d\t%d\t%d\t%s", i, \
    101 	    (((sp)->su_flags & SEGUSE_ACTIVE) ? 'A' : ' '), \
    102 	    (((sp)->su_flags & SEGUSE_DIRTY) ? 'D' : 'C'), \
    103 	    (((sp)->su_flags & SEGUSE_SUPERBLOCK) ? 'S' : ' '), \
    104 	    (sp)->su_nbytes, (sp)->su_ninos, (sp)->su_nsums, \
    105 	    ctime((time_t *)&(sp)->su_lastmod))
    106 
    107 /* Ifile formats */
    108 #define print_iheader \
    109 	(void)printf("inum\tstatus\tversion\tdaddr\t\tfreeptr\n")
    110 #define print_ientry(i, ip) \
    111 	if (ip->if_daddr == LFS_UNUSED_DADDR) \
    112 		(void)printf("%d\tFREE\t%d\t \t\t%d\n", \
    113 		    i, ip->if_version, ip->if_nextfree); \
    114 	else \
    115 		(void)printf("%d\tINUSE\t%d\t%8X    \n", \
    116 		    i, ip->if_version, ip->if_daddr)
    117 
    118 int
    119 main(argc, argv)
    120 	int argc;
    121 	char *argv[];
    122 {
    123 	struct lfs lfs_sb1, lfs_sb2, *lfs_master;
    124 	daddr_t seg_addr;
    125 	int ch, do_allsb, do_ientries, fd, segnum;
    126 
    127 	do_allsb = 0;
    128 	do_ientries = 0;
    129 	while ((ch = getopt(argc, argv, "ais:")) != -1)
    130 		switch(ch) {
    131 		case 'a':		/* Dump all superblocks */
    132 			do_allsb = 1;
    133 			break;
    134 		case 'i':		/* Dump ifile entries */
    135 			do_ientries = 1;
    136 			break;
    137 		case 's':		/* Dump out these segments */
    138 			addseg(optarg);
    139 			break;
    140 		default:
    141 			usage();
    142 		}
    143 	argc -= optind;
    144 	argv += optind;
    145 
    146 	if (argc != 1)
    147 		usage();
    148 
    149 	special = argv[0];
    150 	if ((fd = open(special, O_RDONLY, 0)) < 0)
    151 		err(1, "%s", special);
    152 
    153 	/* Read the first superblock */
    154 	get(fd, LFS_LABELPAD, &lfs_sb1, sizeof(struct lfs));
    155 	daddr_shift = lfs_sb1.lfs_bshift - lfs_sb1.lfs_fsbtodb;
    156 
    157 	/*
    158 	 * Read the second superblock and figure out which check point is
    159 	 * most up to date.
    160 	 */
    161 	get(fd,
    162 	    lfs_sb1.lfs_sboffs[1] << daddr_shift, &lfs_sb2, sizeof(struct lfs));
    163 
    164 	lfs_master = &lfs_sb1;
    165 	if (lfs_sb1.lfs_tstamp < lfs_sb2.lfs_tstamp)
    166 		lfs_master = &lfs_sb2;
    167 
    168 	(void)printf("Master Superblock:\n");
    169 	dump_super(lfs_master);
    170 
    171 	dump_ifile(fd, lfs_master, do_ientries);
    172 
    173 	if (seglist != NULL)
    174 		for (; seglist != NULL; seglist = seglist->next) {
    175 			seg_addr = lfs_master->lfs_sboffs[0] + seglist->num *
    176 			    (lfs_master->lfs_ssize << lfs_master->lfs_fsbtodb);
    177 			dump_segment(fd,
    178 			    seglist->num, seg_addr, lfs_master, do_allsb);
    179 		}
    180 	else
    181 		for (segnum = 0, seg_addr = lfs_master->lfs_sboffs[0];
    182 		    segnum < lfs_master->lfs_nseg; segnum++, seg_addr +=
    183 		    lfs_master->lfs_ssize << lfs_master->lfs_fsbtodb)
    184 			dump_segment(fd,
    185 			    segnum, seg_addr, lfs_master, do_allsb);
    186 
    187 	(void)close(fd);
    188 	exit(0);
    189 }
    190 
    191 /*
    192  * We are reading all the blocks of an inode and dumping out the ifile table.
    193  * This code could be tighter, but this is a first pass at getting the stuff
    194  * printed out rather than making this code incredibly efficient.
    195  */
    196 static void
    197 dump_ifile(fd, lfsp, do_ientries)
    198 	int fd;
    199 	struct lfs *lfsp;
    200 	int do_ientries;
    201 {
    202 	IFILE *ipage;
    203 	struct dinode *dip, *dpage;
    204 	daddr_t addr, *addrp, *dindir, *iaddrp, *indir;
    205 	int block_limit, i, inum, j, nblocks, psize;
    206 
    207 	psize = lfsp->lfs_bsize;
    208 	addr = lfsp->lfs_idaddr;
    209 
    210 	if (!(dpage = malloc(psize)))
    211 		err(1, "malloc");
    212 	get(fd, addr << daddr_shift, dpage, psize);
    213 
    214 	for (dip = dpage + INOPB(lfsp) - 1; dip >= dpage; --dip)
    215 		if (dip->di_inumber == LFS_IFILE_INUM)
    216 			break;
    217 
    218 	if (dip < dpage)
    219 		errx(1, "unable to locate ifile inode");
    220 
    221 	(void)printf("\nIFILE inode\n");
    222 	dump_dinode(dip);
    223 
    224 	(void)printf("\nIFILE contents\n");
    225 	nblocks = dip->di_size >> lfsp->lfs_bshift;
    226 	block_limit = MIN(nblocks, NDADDR);
    227 
    228 	/* Get the direct block */
    229 	if ((ipage = malloc(psize)) == NULL)
    230 		err(1, "malloc");
    231 	for (inum = 0, addrp = dip->di_db, i = 0; i < block_limit;
    232 	    i++, addrp++) {
    233 		get(fd, *addrp << daddr_shift, ipage, psize);
    234 		if (i < lfsp->lfs_cleansz) {
    235 			dump_cleaner_info(lfsp, ipage);
    236 			print_suheader;
    237 			continue;
    238 		}
    239 
    240 		if (i < (lfsp->lfs_segtabsz + lfsp->lfs_cleansz)) {
    241 			inum = dump_ipage_segusage(lfsp, inum, ipage,
    242 			    lfsp->lfs_sepb);
    243 			if (!inum)
    244 				if(!do_ientries)
    245 					goto e0;
    246 				else
    247 					print_iheader;
    248 		} else
    249 			inum = dump_ipage_ifile(inum, ipage, lfsp->lfs_ifpb);
    250 
    251 	}
    252 
    253 	if (nblocks <= NDADDR)
    254 		goto e0;
    255 
    256 	/* Dump out blocks off of single indirect block */
    257 	if (!(indir = malloc(psize)))
    258 		err(1, "malloc");
    259 	get(fd, dip->di_ib[0] << daddr_shift, indir, psize);
    260 	block_limit = MIN(i + lfsp->lfs_nindir, nblocks);
    261 	for (addrp = indir; i < block_limit; i++, addrp++) {
    262 		if (*addrp == LFS_UNUSED_DADDR)
    263 			break;
    264 		get(fd, *addrp << daddr_shift,ipage, psize);
    265 		if (i < lfsp->lfs_cleansz) {
    266 			dump_cleaner_info(lfsp, ipage);
    267 			continue;
    268 		} else
    269 			i -= lfsp->lfs_cleansz;
    270 
    271 		if (i < lfsp->lfs_segtabsz) {
    272 			inum = dump_ipage_segusage(lfsp, inum, ipage,
    273 			    lfsp->lfs_sepb);
    274 			if (!inum)
    275 				if(!do_ientries)
    276 					goto e1;
    277 				else
    278 					print_iheader;
    279 		} else
    280 			inum = dump_ipage_ifile(inum, ipage, lfsp->lfs_ifpb);
    281 	}
    282 
    283 	if (nblocks <= lfsp->lfs_nindir * lfsp->lfs_ifpb)
    284 		goto e1;
    285 
    286 	/* Get the double indirect block */
    287 	if (!(dindir = malloc(psize)))
    288 		err(1, "malloc");
    289 	get(fd, dip->di_ib[1] << daddr_shift, dindir, psize);
    290 	for (iaddrp = dindir, j = 0; j < lfsp->lfs_nindir; j++, iaddrp++) {
    291 		if (*iaddrp == LFS_UNUSED_DADDR)
    292 			break;
    293 		get(fd, *iaddrp << daddr_shift, indir, psize);
    294 		block_limit = MIN(i + lfsp->lfs_nindir, nblocks);
    295 		for (addrp = indir; i < block_limit; i++, addrp++) {
    296 			if (*addrp == LFS_UNUSED_DADDR)
    297 				break;
    298 			get(fd, *addrp << daddr_shift, ipage, psize);
    299 			if (i < lfsp->lfs_cleansz) {
    300 				dump_cleaner_info(lfsp, ipage);
    301 				continue;
    302 			} else
    303 				i -= lfsp->lfs_cleansz;
    304 
    305 			if (i < lfsp->lfs_segtabsz) {
    306 				inum = dump_ipage_segusage(lfsp,
    307 				    inum, ipage, lfsp->lfs_sepb);
    308 				if (!inum)
    309 					if(!do_ientries)
    310 						goto e2;
    311 					else
    312 						print_iheader;
    313 			} else
    314 				inum = dump_ipage_ifile(inum,
    315 				    ipage, lfsp->lfs_ifpb);
    316 		}
    317 	}
    318 e2:	free(dindir);
    319 e1:	free(indir);
    320 e0:	free(dpage);
    321 	free(ipage);
    322 }
    323 
    324 static int
    325 dump_ipage_ifile(i, pp, tot)
    326 	int i;
    327 	IFILE *pp;
    328 	int tot;
    329 {
    330 	IFILE *ip;
    331 	int cnt, max;
    332 
    333 	max = i + tot;
    334 
    335 	for (ip = pp, cnt = i; cnt < max; cnt++, ip++)
    336 		print_ientry(cnt, ip);
    337 	return (max);
    338 }
    339 
    340 static int
    341 dump_ipage_segusage(lfsp, i, pp, tot)
    342 	struct lfs *lfsp;
    343 	int i;
    344 	IFILE *pp;
    345 	int tot;
    346 {
    347 	SEGUSE *sp;
    348 	int cnt, max;
    349 
    350 	max = i + tot;
    351 	for (sp = (SEGUSE *)pp, cnt = i;
    352 	     cnt < lfsp->lfs_nseg && cnt < max; cnt++, sp++)
    353 		print_suentry(cnt, sp);
    354 	if (max >= lfsp->lfs_nseg)
    355 		return (0);
    356 	else
    357 		return (max);
    358 }
    359 
    360 static void
    361 dump_dinode(dip)
    362 	struct dinode *dip;
    363 {
    364 	int i;
    365 	time_t at, mt, ct;
    366 
    367 	at = dip->di_atime;
    368 	mt = dip->di_mtime;
    369 	ct = dip->di_ctime;
    370 
    371 	(void)printf("%s%d\t%s%d\t%s%d\t%s%d\t%s%qu\n",
    372 		"mode  ", dip->di_mode,
    373 		"nlink ", dip->di_nlink,
    374 		"uid   ", dip->di_uid,
    375 		"gid   ", dip->di_gid,
    376 		"size  ", dip->di_size);
    377 	(void)printf("%s%s%s%s%s%s",
    378 		"atime ", ctime(&at),
    379 		"mtime ", ctime(&mt),
    380 		"ctime ", ctime(&ct));
    381 	(void)printf("inum  %d\n", dip->di_inumber);
    382 	(void)printf("Direct Addresses\n");
    383 	for (i = 0; i < NDADDR; i++) {
    384 		(void)printf("\t0x%X", dip->di_db[i]);
    385 		if ((i % 6) == 5)
    386 			(void)printf("\n");
    387 	}
    388 	for (i = 0; i < NIADDR; i++)
    389 		(void)printf("\t0x%X", dip->di_ib[i]);
    390 	(void)printf("\n");
    391 }
    392 
    393 static int
    394 dump_sum(fd, lfsp, sp, segnum, addr)
    395 	struct lfs *lfsp;
    396 	SEGSUM *sp;
    397 	int fd, segnum;
    398 	daddr_t addr;
    399 {
    400 	FINFO *fp;
    401 	daddr_t *dp;
    402 	int i, j;
    403 	int ck;
    404 	int numbytes;
    405 	struct dinode *inop;
    406 
    407 	if (sp->ss_magic != SS_MAGIC ||
    408 	    sp->ss_sumsum != (ck = cksum(&sp->ss_datasum,
    409 	    LFS_SUMMARY_SIZE - sizeof(sp->ss_sumsum)))) {
    410 		(void)printf("dumplfs: %s %d address 0x%x\n",
    411 		    "corrupt summary block; segment", segnum, addr);
    412 		return(0);
    413 	}
    414 
    415 	(void)printf("Segment Summary Info at 0x%x\n", addr);
    416 	(void)printf("    %s0x%X\t%s%d\t%s%d\n    %s0x%X\t%s0x%X",
    417 		"next     ", sp->ss_next,
    418 		"nfinfo   ", sp->ss_nfinfo,
    419 		"ninos    ", sp->ss_ninos,
    420 		"sumsum   ", sp->ss_sumsum,
    421 		"datasum  ", sp->ss_datasum );
    422 	(void)printf("\tcreate   %s", ctime((time_t *)&sp->ss_create));
    423 
    424 	/* Dump out inode disk addresses */
    425 	dp = (daddr_t *)sp;
    426 	dp += LFS_SUMMARY_SIZE / sizeof(daddr_t);
    427 	inop = malloc(1 << lfsp->lfs_bshift);
    428 	printf("    Inode addresses:");
    429 	numbytes = 0;
    430 	for (dp--, i = 0; i < sp->ss_ninos; dp--) {
    431 		numbytes += lfsp->lfs_bsize;	/* add bytes for inode block */
    432 		printf("\t0x%X {", *dp);
    433 		get(fd, *dp << (lfsp->lfs_bshift - lfsp->lfs_fsbtodb), inop,
    434 		    (1 << lfsp->lfs_bshift));
    435 		for (j = 0; i < sp->ss_ninos && j < INOPB(lfsp); j++, i++) {
    436 			if (j > 0)
    437 				(void)printf(", ");
    438 			(void)printf("%d", inop[j].di_inumber);
    439 		}
    440 		(void)printf("}");
    441 		if (((i/INOPB(lfsp)) % 4) == 3)
    442 			(void)printf("\n");
    443 	}
    444 	free(inop);
    445 
    446 	printf("\n");
    447 	for (fp = (FINFO *)(sp + 1), i = 0; i < sp->ss_nfinfo; i++) {
    448 		(void)printf("    FINFO for inode: %d version %d nblocks %d lastlength %d\n",
    449 		    fp->fi_ino, fp->fi_version, fp->fi_nblocks,
    450 		    fp->fi_lastlength);
    451 		dp = &(fp->fi_blocks[0]);
    452 		for (j = 0; j < fp->fi_nblocks; j++, dp++) {
    453 			(void)printf("\t%d", *dp);
    454 			if ((j % 8) == 7)
    455 				(void)printf("\n");
    456 			if (j == fp->fi_nblocks - 1)
    457 				numbytes += fp->fi_lastlength;
    458 			else
    459 				numbytes += lfsp->lfs_bsize;
    460 		}
    461 		if ((j % 8) != 0)
    462 			(void)printf("\n");
    463 		fp = (FINFO *)dp;
    464 	}
    465 	return (numbytes);
    466 }
    467 
    468 static void
    469 dump_segment(fd, segnum, addr, lfsp, dump_sb)
    470 	int fd, segnum;
    471 	daddr_t addr;
    472 	struct lfs *lfsp;
    473 	int dump_sb;
    474 {
    475 	struct lfs lfs_sb, *sbp;
    476 	SEGSUM *sump;
    477 	char sumblock[LFS_SUMMARY_SIZE];
    478 	int did_one, nbytes, sb;
    479 	off_t sum_offset, super_off = 0;
    480 
    481 	(void)printf("\nSEGMENT %d (Disk Address 0x%X)\n",
    482 	    addr >> (lfsp->lfs_segshift - daddr_shift), addr);
    483 	sum_offset = (addr << (lfsp->lfs_bshift - lfsp->lfs_fsbtodb));
    484 
    485 	sb = 0;
    486 	did_one = 0;
    487 	do {
    488 		get(fd, sum_offset, sumblock, LFS_SUMMARY_SIZE);
    489 		sump = (SEGSUM *)sumblock;
    490 		if (sump->ss_sumsum != cksum (&sump->ss_datasum,
    491 			LFS_SUMMARY_SIZE - sizeof(sump->ss_sumsum))) {
    492 			sbp = (struct lfs *)sump;
    493 			if ((sb = (sbp->lfs_magic == LFS_MAGIC))) {
    494 				super_off = sum_offset;
    495 				sum_offset += LFS_SBPAD;
    496 			} else if (did_one)
    497 				break;
    498 			else {
    499 				printf("Segment at 0x%X corrupt\n", addr);
    500 				break;
    501 			}
    502 		} else {
    503 			nbytes = dump_sum(fd, lfsp, sump, segnum, sum_offset >>
    504 			     (lfsp->lfs_bshift - lfsp->lfs_fsbtodb));
    505 			if (nbytes)
    506 				sum_offset += LFS_SUMMARY_SIZE + nbytes;
    507 			else
    508 				sum_offset = 0;
    509 			did_one = 1;
    510 		}
    511 	} while (sum_offset);
    512 
    513 	if (dump_sb && sb)  {
    514 		get(fd, super_off, &lfs_sb, sizeof(struct lfs));
    515 		dump_super(&lfs_sb);
    516 	}
    517 	return;
    518 }
    519 
    520 static void
    521 dump_super(lfsp)
    522 	struct lfs *lfsp;
    523 {
    524 	int i;
    525 
    526 	(void)printf("%s0x%X\t%s0x%X\t%s%d\t%s%d\n",
    527 		"magic    ", lfsp->lfs_magic,
    528 		"version  ", lfsp->lfs_version,
    529 		"size     ", lfsp->lfs_size,
    530 		"ssize    ", lfsp->lfs_ssize);
    531 	(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
    532 		"dsize    ", lfsp->lfs_dsize,
    533 		"bsize    ", lfsp->lfs_bsize,
    534 		"fsize    ", lfsp->lfs_fsize,
    535 		"frag     ", lfsp->lfs_frag);
    536 
    537 	(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
    538 		"minfree  ", lfsp->lfs_minfree,
    539 		"inopb    ", lfsp->lfs_inopb,
    540 		"ifpb     ", lfsp->lfs_ifpb,
    541 		"nindir   ", lfsp->lfs_nindir);
    542 
    543 	(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
    544 		"nseg     ", lfsp->lfs_nseg,
    545 		"nspf     ", lfsp->lfs_nspf,
    546 		"cleansz  ", lfsp->lfs_cleansz,
    547 		"segtabsz ", lfsp->lfs_segtabsz);
    548 
    549 	(void)printf("%s0x%X\t%s%d\t%s0x%qX\t%s%d\n",
    550 		"segmask  ", lfsp->lfs_segmask,
    551 		"segshift ", lfsp->lfs_segshift,
    552 		"bmask    ", lfsp->lfs_bmask,
    553 		"bshift   ", lfsp->lfs_bshift);
    554 
    555 	(void)printf("%s0x%qX\t\t%s%d\t%s0x%qX\t%s%u\n",
    556 		"ffmask   ", lfsp->lfs_ffmask,
    557 		"ffshift  ", lfsp->lfs_ffshift,
    558 		"fbmask   ", lfsp->lfs_fbmask,
    559 		"fbshift  ", lfsp->lfs_fbshift);
    560 
    561 	(void)printf("%s%d\t%s%d\t%s0x%X\t%s0x%qx\n",
    562 		"sushift  ", lfsp->lfs_sushift,
    563 		"fsbtodb  ", lfsp->lfs_fsbtodb,
    564 		"cksum    ", lfsp->lfs_cksum,
    565 		"maxfilesize  ", lfsp->lfs_maxfilesize);
    566 
    567 	(void)printf("Superblock disk addresses:\t");
    568 	for (i = 0; i < LFS_MAXNUMSB; i++) {
    569 		(void)printf(" 0x%X", lfsp->lfs_sboffs[i]);
    570 		if ( i == (LFS_MAXNUMSB >> 1))
    571 			(void)printf("\n\t\t\t\t");
    572 	}
    573 	(void)printf("\n");
    574 
    575 	(void)printf("Checkpoint Info\n");
    576 	(void)printf("%s%d\t%s0x%X\t%s%d\n",
    577 		"free     ", lfsp->lfs_free,
    578 		"idaddr   ", lfsp->lfs_idaddr,
    579 		"ifile    ", lfsp->lfs_ifile);
    580 	(void)printf("%s%d\t%s%d\t%s%d\n",
    581 		"bfree    ", lfsp->lfs_bfree,
    582 		"avail    ", lfsp->lfs_avail,
    583 		"uinodes  ", lfsp->lfs_uinodes);
    584 	(void)printf("%s%d\t%s0x%X\t%s0x%X\n%s0x%X\t%s0x%X\t",
    585 		"nfiles   ", lfsp->lfs_nfiles,
    586 		"lastseg  ", lfsp->lfs_lastseg,
    587 		"nextseg  ", lfsp->lfs_nextseg,
    588 		"curseg   ", lfsp->lfs_curseg,
    589 		"offset   ", lfsp->lfs_offset);
    590 	(void)printf("tstamp   %s", ctime((time_t *)&lfsp->lfs_tstamp));
    591 	(void)printf("\nIn-Memory Information\n");
    592 	(void)printf("%s%d\t%s0x%X\t%s%d%s%d\t%s%d\n",
    593 		"seglock  ", lfsp->lfs_seglock,
    594 		"iocount  ", lfsp->lfs_iocount,
    595 		"writer   ", lfsp->lfs_writer,
    596 		"dirops   ", lfsp->lfs_dirops,
    597 		"doifile  ", lfsp->lfs_doifile);
    598 	(void)printf("%s%d\t%s%d\t%s0x%X\t%s%d\n",
    599 		"nactive  ", lfsp->lfs_nactive,
    600 		"fmod     ", lfsp->lfs_fmod,
    601 		"clean    ", lfsp->lfs_clean,
    602 		"ronly    ", lfsp->lfs_ronly);
    603 }
    604 
    605 static void
    606 addseg(arg)
    607 	char *arg;
    608 {
    609 	SEGLIST *p;
    610 
    611 	if ((p = malloc(sizeof(SEGLIST))) == NULL)
    612 		err(1, "malloc");
    613 	p->next = seglist;
    614 	p->num = atoi(arg);
    615 	seglist = p;
    616 }
    617 
    618 static void
    619 dump_cleaner_info(lfsp, ipage)
    620 	struct lfs *lfsp;
    621 	void *ipage;
    622 {
    623 	CLEANERINFO *cip;
    624 
    625 	cip = (CLEANERINFO *)ipage;
    626 	(void)printf("segments clean\t%d\tsegments dirty\t%d\n\n",
    627 	    cip->clean, cip->dirty);
    628 }
    629 
    630 static void
    631 usage()
    632 {
    633 	(void)fprintf(stderr, "usage: dumplfs [-ai] [-s segnum] file\n");
    634 	exit(1);
    635 }
    636