Home | History | Annotate | Line # | Download | only in dumplfs
dumplfs.c revision 1.14
      1 /*	$NetBSD: dumplfs.c,v 1.14 2000/06/14 01:55:37 perseant 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.14 2000/06/14 01:55:37 perseant 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, 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, idaddr, sbdaddr;
    125 	int ch, do_allsb, do_ientries, fd, segnum;
    126 
    127 	do_allsb = 0;
    128 	do_ientries = 0;
    129 	idaddr = 0x0;
    130 	sbdaddr = 0x0;
    131 	while ((ch = getopt(argc, argv, "ab:iI:s:")) != -1)
    132 		switch(ch) {
    133 		case 'a':		/* Dump all superblocks */
    134 			do_allsb = 1;
    135 			break;
    136 		case 'b':		/* Use this superblock */
    137 			sbdaddr = strtol(optarg, NULL, 0);
    138 			break;
    139 		case 'i':		/* Dump ifile entries */
    140 			do_ientries = 1;
    141 			break;
    142 		case 'I':		/* Use this ifile inode */
    143 			idaddr = strtol(optarg, NULL, 0);
    144 			break;
    145 		case 's':		/* Dump out these segments */
    146 			addseg(optarg);
    147 			break;
    148 		default:
    149 			usage();
    150 		}
    151 	argc -= optind;
    152 	argv += optind;
    153 
    154 	if (argc != 1)
    155 		usage();
    156 
    157 	special = argv[0];
    158 	if ((fd = open(special, O_RDONLY, 0)) < 0)
    159 		err(1, "%s", special);
    160 
    161 	if (sbdaddr == 0x0) {
    162 		/* Read the first superblock */
    163 		get(fd, LFS_LABELPAD, &(lfs_sb1.lfs_dlfs), sizeof(struct dlfs));
    164 		daddr_shift = lfs_sb1.lfs_bshift - lfs_sb1.lfs_fsbtodb;
    165 
    166 		/*
    167 	 	* Read the second superblock and figure out which check point is
    168 	 	* most up to date.
    169 	 	*/
    170 		get(fd,
    171 	    	lfs_sb1.lfs_sboffs[1] << daddr_shift, &(lfs_sb2.lfs_dlfs), sizeof(struct dlfs));
    172 
    173 		lfs_master = &lfs_sb1;
    174 		if (lfs_sb1.lfs_tstamp > lfs_sb2.lfs_tstamp) {
    175 			lfs_master = &lfs_sb2;
    176 			sbdaddr = lfs_sb1.lfs_sboffs[1] << daddr_shift;
    177 		} else
    178 			sbdaddr = btodb(LFS_LABELPAD);
    179 	} else {
    180 		/* Read the first superblock */
    181 		get(fd, dbtob(sbdaddr), &(lfs_sb1.lfs_dlfs), sizeof(struct dlfs));
    182 		daddr_shift = lfs_sb1.lfs_bshift - lfs_sb1.lfs_fsbtodb;
    183 		lfs_master = &lfs_sb1;
    184 	}
    185 
    186 	(void)printf("Master Superblock at 0x%x:\n", sbdaddr);
    187 	dump_super(lfs_master);
    188 
    189 	dump_ifile(fd, lfs_master, do_ientries, idaddr);
    190 
    191 	if (seglist != NULL)
    192 		for (; seglist != NULL; seglist = seglist->next) {
    193 			seg_addr = lfs_master->lfs_sboffs[0] + seglist->num *
    194 			    (lfs_master->lfs_ssize << lfs_master->lfs_fsbtodb);
    195 			dump_segment(fd,
    196 			    seglist->num, seg_addr, lfs_master, do_allsb);
    197 		}
    198 	else
    199 		for (segnum = 0, seg_addr = lfs_master->lfs_sboffs[0];
    200 		    segnum < lfs_master->lfs_nseg; segnum++, seg_addr +=
    201 		    lfs_master->lfs_ssize << lfs_master->lfs_fsbtodb)
    202 			dump_segment(fd,
    203 			    segnum, seg_addr, lfs_master, do_allsb);
    204 
    205 	(void)close(fd);
    206 	exit(0);
    207 }
    208 
    209 /*
    210  * We are reading all the blocks of an inode and dumping out the ifile table.
    211  * This code could be tighter, but this is a first pass at getting the stuff
    212  * printed out rather than making this code incredibly efficient.
    213  */
    214 static void
    215 dump_ifile(fd, lfsp, do_ientries, addr)
    216 	int fd;
    217 	struct lfs *lfsp;
    218 	int do_ientries;
    219 	daddr_t addr;
    220 {
    221 	IFILE *ipage;
    222 	struct dinode *dip, *dpage;
    223 	daddr_t *addrp, *dindir, *iaddrp, *indir;
    224 	int block_limit, i, inum, j, nblocks, psize;
    225 
    226 	psize = lfsp->lfs_bsize;
    227 	if (!addr)
    228 		addr = lfsp->lfs_idaddr;
    229 
    230 	if (!(dpage = malloc(psize)))
    231 		err(1, "malloc");
    232 	get(fd, addr << daddr_shift, dpage, psize);
    233 
    234 	for (dip = dpage + INOPB(lfsp) - 1; dip >= dpage; --dip)
    235 		if (dip->di_inumber == LFS_IFILE_INUM)
    236 			break;
    237 
    238 	if (dip < dpage)
    239 		errx(1, "unable to locate ifile inode at disk address 0x%x",
    240 		     addr);
    241 
    242 	(void)printf("\nIFILE inode\n");
    243 	dump_dinode(dip);
    244 
    245 	(void)printf("\nIFILE contents\n");
    246 	nblocks = dip->di_size >> lfsp->lfs_bshift;
    247 	block_limit = MIN(nblocks, NDADDR);
    248 
    249 	/* Get the direct block */
    250 	if ((ipage = malloc(psize)) == NULL)
    251 		err(1, "malloc");
    252 	for (inum = 0, addrp = dip->di_db, i = 0; i < block_limit;
    253 	    i++, addrp++) {
    254 		get(fd, *addrp << daddr_shift, ipage, psize);
    255 		if (i < lfsp->lfs_cleansz) {
    256 			dump_cleaner_info(lfsp, ipage);
    257 			print_suheader;
    258 			continue;
    259 		}
    260 
    261 		if (i < (lfsp->lfs_segtabsz + lfsp->lfs_cleansz)) {
    262 			inum = dump_ipage_segusage(lfsp, inum, ipage,
    263 			    lfsp->lfs_sepb);
    264 			if (!inum) {
    265 				if(!do_ientries)
    266 					goto e0;
    267 				else
    268 					print_iheader;
    269 			}
    270 		} else
    271 			inum = dump_ipage_ifile(inum, ipage, lfsp->lfs_ifpb);
    272 
    273 	}
    274 
    275 	if (nblocks <= NDADDR)
    276 		goto e0;
    277 
    278 	/* Dump out blocks off of single indirect block */
    279 	if (!(indir = malloc(psize)))
    280 		err(1, "malloc");
    281 	get(fd, dip->di_ib[0] << daddr_shift, indir, psize);
    282 	block_limit = MIN(i + lfsp->lfs_nindir, nblocks);
    283 	for (addrp = indir; i < block_limit; i++, addrp++) {
    284 		if (*addrp == LFS_UNUSED_DADDR)
    285 			break;
    286 		get(fd, *addrp << daddr_shift,ipage, psize);
    287 		if (i < lfsp->lfs_cleansz) {
    288 			dump_cleaner_info(lfsp, ipage);
    289 			continue;
    290 		} else
    291 			i -= lfsp->lfs_cleansz;
    292 
    293 		if (i < lfsp->lfs_segtabsz) {
    294 			inum = dump_ipage_segusage(lfsp, inum, ipage,
    295 			    lfsp->lfs_sepb);
    296 			if (!inum) {
    297 				if(!do_ientries)
    298 					goto e1;
    299 				else
    300 					print_iheader;
    301 			}
    302 		} else
    303 			inum = dump_ipage_ifile(inum, ipage, lfsp->lfs_ifpb);
    304 	}
    305 
    306 	if (nblocks <= lfsp->lfs_nindir * lfsp->lfs_ifpb)
    307 		goto e1;
    308 
    309 	/* Get the double indirect block */
    310 	if (!(dindir = malloc(psize)))
    311 		err(1, "malloc");
    312 	get(fd, dip->di_ib[1] << daddr_shift, dindir, psize);
    313 	for (iaddrp = dindir, j = 0; j < lfsp->lfs_nindir; j++, iaddrp++) {
    314 		if (*iaddrp == LFS_UNUSED_DADDR)
    315 			break;
    316 		get(fd, *iaddrp << daddr_shift, indir, psize);
    317 		block_limit = MIN(i + lfsp->lfs_nindir, nblocks);
    318 		for (addrp = indir; i < block_limit; i++, addrp++) {
    319 			if (*addrp == LFS_UNUSED_DADDR)
    320 				break;
    321 			get(fd, *addrp << daddr_shift, ipage, psize);
    322 			if (i < lfsp->lfs_cleansz) {
    323 				dump_cleaner_info(lfsp, ipage);
    324 				continue;
    325 			} else
    326 				i -= lfsp->lfs_cleansz;
    327 
    328 			if (i < lfsp->lfs_segtabsz) {
    329 				inum = dump_ipage_segusage(lfsp,
    330 				    inum, ipage, lfsp->lfs_sepb);
    331 				if (!inum) {
    332 					if(!do_ientries)
    333 						goto e2;
    334 					else
    335 						print_iheader;
    336 				}
    337 			} else
    338 				inum = dump_ipage_ifile(inum,
    339 				    ipage, lfsp->lfs_ifpb);
    340 		}
    341 	}
    342 e2:	free(dindir);
    343 e1:	free(indir);
    344 e0:	free(dpage);
    345 	free(ipage);
    346 }
    347 
    348 static int
    349 dump_ipage_ifile(i, pp, tot)
    350 	int i;
    351 	IFILE *pp;
    352 	int tot;
    353 {
    354 	IFILE *ip;
    355 	int cnt, max;
    356 
    357 	max = i + tot;
    358 
    359 	for (ip = pp, cnt = i; cnt < max; cnt++, ip++)
    360 		print_ientry(cnt, ip);
    361 	return (max);
    362 }
    363 
    364 static int
    365 dump_ipage_segusage(lfsp, i, pp, tot)
    366 	struct lfs *lfsp;
    367 	int i;
    368 	IFILE *pp;
    369 	int tot;
    370 {
    371 	SEGUSE *sp;
    372 	int cnt, max;
    373 
    374 	max = i + tot;
    375 	for (sp = (SEGUSE *)pp, cnt = i;
    376 	     cnt < lfsp->lfs_nseg && cnt < max; cnt++, sp++)
    377 		print_suentry(cnt, sp);
    378 	if (max >= lfsp->lfs_nseg)
    379 		return (0);
    380 	else
    381 		return (max);
    382 }
    383 
    384 static void
    385 dump_dinode(dip)
    386 	struct dinode *dip;
    387 {
    388 	int i;
    389 	time_t at, mt, ct;
    390 
    391 	at = dip->di_atime;
    392 	mt = dip->di_mtime;
    393 	ct = dip->di_ctime;
    394 
    395 	(void)printf("%s%d\t%s%d\t%s%d\t%s%d\t%s%qu\n",
    396 		"mode  ", dip->di_mode,
    397 		"nlink ", dip->di_nlink,
    398 		"uid   ", dip->di_uid,
    399 		"gid   ", dip->di_gid,
    400 		"size  ", (long long)dip->di_size);
    401 	(void)printf("%s%s%s%s%s%s",
    402 		"atime ", ctime(&at),
    403 		"mtime ", ctime(&mt),
    404 		"ctime ", ctime(&ct));
    405 	(void)printf("inum  %d\n", dip->di_inumber);
    406 	(void)printf("Direct Addresses\n");
    407 	for (i = 0; i < NDADDR; i++) {
    408 		(void)printf("\t0x%x", dip->di_db[i]);
    409 		if ((i % 6) == 5)
    410 			(void)printf("\n");
    411 	}
    412 	for (i = 0; i < NIADDR; i++)
    413 		(void)printf("\t0x%x", dip->di_ib[i]);
    414 	(void)printf("\n");
    415 }
    416 
    417 static int
    418 dump_sum(fd, lfsp, sp, segnum, addr)
    419 	struct lfs *lfsp;
    420 	SEGSUM *sp;
    421 	int fd, segnum;
    422 	daddr_t addr;
    423 {
    424 	FINFO *fp;
    425 	daddr_t *dp;
    426 	int i, j;
    427 	int ck;
    428 	int numbytes;
    429 	struct dinode *inop;
    430 
    431 	if (sp->ss_magic != SS_MAGIC ||
    432 	    sp->ss_sumsum != (ck = cksum(&sp->ss_datasum,
    433 	    LFS_SUMMARY_SIZE - sizeof(sp->ss_sumsum)))) {
    434 		/* Don't print "corrupt" if we're just too close to the edge */
    435 		if (datosn(lfsp, addr + fsbtodb(lfsp, lfsp->lfs_bsize)) ==
    436 		    datosn(lfsp, addr))
    437 			(void)printf("dumplfs: %s %d address 0x%x\n",
    438 		                     "corrupt summary block; segment", segnum,
    439 				     addr);
    440 		return(0);
    441 	}
    442 
    443 	(void)printf("Segment Summary Info at 0x%x\n", addr);
    444 	(void)printf("    %s0x%x\t%s%d\t%s%d\t%s%c%c\n    %s0x%x\t%s0x%x",
    445 		"next     ", sp->ss_next,
    446 		"nfinfo   ", sp->ss_nfinfo,
    447 		"ninos    ", sp->ss_ninos,
    448 		"flags    ", (sp->ss_flags & SS_DIROP) ? 'D' : '-',
    449 			     (sp->ss_flags & SS_CONT)  ? 'C' : '-',
    450 		"sumsum   ", sp->ss_sumsum,
    451 		"datasum  ", sp->ss_datasum );
    452 	(void)printf("\tcreate   %s", ctime((time_t *)&sp->ss_create));
    453 
    454 	/* Dump out inode disk addresses */
    455 	dp = (daddr_t *)sp;
    456 	dp += LFS_SUMMARY_SIZE / sizeof(daddr_t);
    457 	inop = malloc(1 << lfsp->lfs_bshift);
    458 	printf("    Inode addresses:");
    459 	numbytes = 0;
    460 	for (dp--, i = 0; i < sp->ss_ninos; dp--) {
    461 		numbytes += lfsp->lfs_bsize;	/* add bytes for inode block */
    462 		printf("\t0x%x {", *dp);
    463 		get(fd, *dp << (lfsp->lfs_bshift - lfsp->lfs_fsbtodb), inop,
    464 		    (1 << lfsp->lfs_bshift));
    465 		for (j = 0; i < sp->ss_ninos && j < INOPB(lfsp); j++, i++) {
    466 			if (j > 0)
    467 				(void)printf(", ");
    468 			(void)printf("%d", inop[j].di_inumber);
    469 		}
    470 		(void)printf("}");
    471 		if (((i/INOPB(lfsp)) % 4) == 3)
    472 			(void)printf("\n");
    473 	}
    474 	free(inop);
    475 
    476 	printf("\n");
    477 	for (fp = (FINFO *)(sp + 1), i = 0; i < sp->ss_nfinfo; i++) {
    478 		(void)printf("    FINFO for inode: %d version %d nblocks %d lastlength %d\n",
    479 		    fp->fi_ino, fp->fi_version, fp->fi_nblocks,
    480 		    fp->fi_lastlength);
    481 		dp = &(fp->fi_blocks[0]);
    482 		for (j = 0; j < fp->fi_nblocks; j++, dp++) {
    483 			(void)printf("\t%d", *dp);
    484 			if ((j % 8) == 7)
    485 				(void)printf("\n");
    486 			if (j == fp->fi_nblocks - 1)
    487 				numbytes += fp->fi_lastlength;
    488 			else
    489 				numbytes += lfsp->lfs_bsize;
    490 		}
    491 		if ((j % 8) != 0)
    492 			(void)printf("\n");
    493 		fp = (FINFO *)dp;
    494 	}
    495 	return (numbytes);
    496 }
    497 
    498 static void
    499 dump_segment(fd, segnum, addr, lfsp, dump_sb)
    500 	int fd, segnum;
    501 	daddr_t addr;
    502 	struct lfs *lfsp;
    503 	int dump_sb;
    504 {
    505 	struct lfs lfs_sb, *sbp;
    506 	SEGSUM *sump;
    507 	char sumblock[LFS_SUMMARY_SIZE];
    508 	int did_one, nbytes, sb;
    509 	off_t sum_offset;
    510 	daddr_t new_addr;
    511 
    512 	(void)printf("\nSEGMENT %d (Disk Address 0x%x)\n",
    513 	    /* addr >> (lfsp->lfs_segshift - daddr_shift), */
    514 		datosn(lfsp, addr),
    515 		addr);
    516 	sum_offset = (addr << (lfsp->lfs_bshift - lfsp->lfs_fsbtodb));
    517 
    518 	sb = 0;
    519 	did_one = 0;
    520 	do {
    521 		get(fd, sum_offset, sumblock, LFS_SUMMARY_SIZE);
    522 		sump = (SEGSUM *)sumblock;
    523 		if (sump->ss_sumsum != cksum (&sump->ss_datasum,
    524 			LFS_SUMMARY_SIZE - sizeof(sump->ss_sumsum))) {
    525 			sbp = (struct lfs *)sump;
    526 			if ((sb = (sbp->lfs_magic == LFS_MAGIC))) {
    527 				if (dump_sb)  {
    528 					get(fd, sum_offset, &(lfs_sb.lfs_dlfs),
    529 					    sizeof(struct dlfs));
    530 					(void)printf("\nSuperblock at 0x%x:\n",
    531 						   (unsigned)btodb(sum_offset));
    532 					dump_super(&lfs_sb);
    533 					(void)printf("%s","\n");
    534 				}
    535 				sum_offset += LFS_SBPAD;
    536 			} else if (did_one)
    537 				break;
    538 			else {
    539 				printf("Segment at 0x%x corrupt\n", addr);
    540 				break;
    541 			}
    542 		} else {
    543 			nbytes = dump_sum(fd, lfsp, sump, segnum, sum_offset >>
    544 			     (lfsp->lfs_bshift - lfsp->lfs_fsbtodb));
    545 			if (nbytes)
    546 				sum_offset += LFS_SUMMARY_SIZE + nbytes;
    547 			else
    548 				sum_offset = 0;
    549 			did_one = 1;
    550 		}
    551 		/* If the segment ends right on a boundary, it still ends */
    552 		new_addr = sum_offset >> (lfsp->lfs_bshift - lfsp->lfs_fsbtodb);
    553 		if (datosn(lfsp, new_addr) != datosn(lfsp, addr))
    554 			break;
    555 	} while (sum_offset);
    556 
    557 	return;
    558 }
    559 
    560 static void
    561 dump_super(lfsp)
    562 	struct lfs *lfsp;
    563 {
    564 	int i;
    565 
    566 	(void)printf("%s0x%x\t%s0x%x\t%s%d\t%s%d\n",
    567 		"magic    ", lfsp->lfs_magic,
    568 		"version  ", lfsp->lfs_version,
    569 		"size     ", lfsp->lfs_size,
    570 		"ssize    ", lfsp->lfs_ssize);
    571 	(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
    572 		"dsize    ", lfsp->lfs_dsize,
    573 		"bsize    ", lfsp->lfs_bsize,
    574 		"fsize    ", lfsp->lfs_fsize,
    575 		"frag     ", lfsp->lfs_frag);
    576 
    577 	(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
    578 		"minfree  ", lfsp->lfs_minfree,
    579 		"inopb    ", lfsp->lfs_inopb,
    580 		"ifpb     ", lfsp->lfs_ifpb,
    581 		"nindir   ", lfsp->lfs_nindir);
    582 
    583 	(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
    584 		"nseg     ", lfsp->lfs_nseg,
    585 		"nspf     ", lfsp->lfs_nspf,
    586 		"cleansz  ", lfsp->lfs_cleansz,
    587 		"segtabsz ", lfsp->lfs_segtabsz);
    588 
    589 	(void)printf("%s0x%x\t%s%d\t%s0x%qX\t%s%d\n",
    590 		"segmask  ", lfsp->lfs_segmask,
    591 		"segshift ", lfsp->lfs_segshift,
    592 		"bmask    ", (long long)lfsp->lfs_bmask,
    593 		"bshift   ", lfsp->lfs_bshift);
    594 
    595 	(void)printf("%s0x%qX\t\t%s%d\t%s0x%qX\t%s%u\n",
    596 		"ffmask   ", (long long)lfsp->lfs_ffmask,
    597 		"ffshift  ", lfsp->lfs_ffshift,
    598 		"fbmask   ", (long long)lfsp->lfs_fbmask,
    599 		"fbshift  ", lfsp->lfs_fbshift);
    600 
    601 	(void)printf("%s%d\t%s%d\t%s0x%x\t%s0x%qx\n",
    602 		"sushift  ", lfsp->lfs_sushift,
    603 		"fsbtodb  ", lfsp->lfs_fsbtodb,
    604 		"cksum    ", lfsp->lfs_cksum,
    605 		"maxfilesize  ", (long long)lfsp->lfs_maxfilesize);
    606 
    607 	(void)printf("Superblock disk addresses:\t");
    608 	for (i = 0; i < LFS_MAXNUMSB; i++) {
    609 		(void)printf(" 0x%x", lfsp->lfs_sboffs[i]);
    610 		if ( i == (LFS_MAXNUMSB >> 1))
    611 			(void)printf("\n\t\t\t\t");
    612 	}
    613 	(void)printf("\n");
    614 
    615 	(void)printf("Checkpoint Info\n");
    616 	(void)printf("%s%d\t%s0x%x\t%s%d\n",
    617 		"free     ", lfsp->lfs_free,
    618 		"idaddr   ", lfsp->lfs_idaddr,
    619 		"ifile    ", lfsp->lfs_ifile);
    620 	(void)printf("%s%d\t%s%d\t%s%d\n",
    621 		"bfree    ", lfsp->lfs_bfree,
    622 		"avail    ", lfsp->lfs_avail,
    623 		"uinodes  ", lfsp->lfs_uinodes);
    624 	(void)printf("%s%d\t%s0x%x\t%s0x%x\n%s0x%x\t%s0x%x\t",
    625 		"nfiles   ", lfsp->lfs_nfiles,
    626 		"lastseg  ", lfsp->lfs_lastseg,
    627 		"nextseg  ", lfsp->lfs_nextseg,
    628 		"curseg   ", lfsp->lfs_curseg,
    629 		"offset   ", lfsp->lfs_offset);
    630 	(void)printf("tstamp   %s", ctime((time_t *)&lfsp->lfs_tstamp));
    631 #if 0  /* This is no longer stored on disk! --ks */
    632 	(void)printf("\nIn-Memory Information\n");
    633 	(void)printf("%s%d\t%s0x%x\t%s%d%s%d\t%s%d\n",
    634 		"seglock  ", lfsp->lfs_seglock,
    635 		"iocount  ", lfsp->lfs_iocount,
    636 		"writer   ", lfsp->lfs_writer,
    637 		"dirops   ", lfsp->lfs_dirops,
    638 		"doifile  ", lfsp->lfs_doifile);
    639 	(void)printf("%s%d\t%s%d\t%s0x%x\t%s%d\n",
    640 		"nactive  ", lfsp->lfs_nactive,
    641 		"fmod     ", lfsp->lfs_fmod,
    642 		"clean    ", lfsp->lfs_clean,
    643 		"ronly    ", lfsp->lfs_ronly);
    644 #endif
    645 }
    646 
    647 static void
    648 addseg(arg)
    649 	char *arg;
    650 {
    651 	SEGLIST *p;
    652 
    653 	if ((p = malloc(sizeof(SEGLIST))) == NULL)
    654 		err(1, "malloc");
    655 	p->next = seglist;
    656 	p->num = atoi(arg);
    657 	seglist = p;
    658 }
    659 
    660 static void
    661 dump_cleaner_info(lfsp, ipage)
    662 	struct lfs *lfsp;
    663 	void *ipage;
    664 {
    665 	CLEANERINFO *cip;
    666 
    667 	cip = (CLEANERINFO *)ipage;
    668 	(void)printf("segments clean\t%d\tsegments dirty\t%d\n\n",
    669 	    cip->clean, cip->dirty);
    670 }
    671 
    672 static void
    673 usage()
    674 {
    675 	(void)fprintf(stderr, "usage: dumplfs [-ai] [-s segnum] file\n");
    676 	exit(1);
    677 }
    678