xref: /csrg-svn/sbin/dumplfs/dumplfs.c (revision 56032)
151144Sbostic /*-
251144Sbostic  * Copyright (c) 1991 The Regents of the University of California.
351144Sbostic  * All rights reserved.
451144Sbostic  *
551144Sbostic  * %sccs.include.redist.c%
651144Sbostic  */
751144Sbostic 
851144Sbostic #ifndef lint
951144Sbostic char copyright[] =
1051144Sbostic "@(#) Copyright (c) 1991 The Regents of the University of California.\n\
1151144Sbostic  All rights reserved.\n";
1251144Sbostic #endif /* not lint */
1351144Sbostic 
1451144Sbostic #ifndef lint
15*56032Sbostic static char sccsid[] = "@(#)dumplfs.c	5.13 (Berkeley) 08/25/92";
1651144Sbostic #endif /* not lint */
1751144Sbostic 
1851144Sbostic #include <sys/param.h>
1951867Sbostic #include <sys/ucred.h>
2051144Sbostic #include <sys/mount.h>
2154714Sbostic #include <sys/time.h>
2251862Sbostic 
2351862Sbostic #include <ufs/ufs/dinode.h>
2451862Sbostic #include <ufs/lfs/lfs.h>
2551862Sbostic 
2654714Sbostic #include <fcntl.h>
2751144Sbostic #include <fstab.h>
2851144Sbostic #include <errno.h>
2951144Sbostic #include <unistd.h>
3051144Sbostic #include <stdlib.h>
3151144Sbostic #include <stdio.h>
3251144Sbostic #include <string.h>
3351144Sbostic #include "extern.h"
3451144Sbostic 
3551861Sbostic static void	addseg __P((char *));
3651862Sbostic static void	dump_cleaner_info __P((struct lfs *, void *));
3751144Sbostic static void	dump_dinode __P((struct dinode *));
3851862Sbostic static void	dump_ifile __P((int, struct lfs *, int));
3951144Sbostic static int	dump_ipage_ifile __P((int, IFILE *, int));
4051862Sbostic static int	dump_ipage_segusage __P((struct lfs *, int, IFILE *, int));
4151862Sbostic static void	dump_segment __P((int, int, daddr_t, struct lfs *, int));
4252464Sstaelin static int	dump_sum __P((int, struct lfs *, SEGSUM *, int, daddr_t));
4351862Sbostic static void	dump_super __P((struct lfs *));
4451144Sbostic static void	usage __P((void));
4551144Sbostic 
4651861Sbostic typedef struct seglist SEGLIST;
4751861Sbostic struct seglist {
4851861Sbostic         SEGLIST *next;
4951861Sbostic 	int num;
5051861Sbostic };
5151861Sbostic SEGLIST	*seglist;
5251861Sbostic 
5351861Sbostic int daddr_shift;
5451144Sbostic char *special;
5551144Sbostic 
5651144Sbostic /* Segment Usage formats */
5751144Sbostic #define print_suheader \
5855597Sbostic 	(void)printf("segnum\tflags\tnbytes\tninos\tnsums\tlastmod\n")
5951929Sbostic 
6051144Sbostic #define print_suentry(i, sp) \
6155597Sbostic 	(void)printf("%d\t%c%c%c\t%d\t%d\t%d\t%s", i, \
6251929Sbostic 	    (((sp)->su_flags & SEGUSE_ACTIVE) ? 'A' : ' '), \
6351929Sbostic 	    (((sp)->su_flags & SEGUSE_DIRTY) ? 'D' : 'C'), \
6451929Sbostic 	    (((sp)->su_flags & SEGUSE_SUPERBLOCK) ? 'S' : ' '), \
6555597Sbostic 	    (sp)->su_nbytes, (sp)->su_ninos, (sp)->su_nsums, \
6655597Sbostic 	    ctime((time_t *)&(sp)->su_lastmod))
6751144Sbostic 
6851144Sbostic /* Ifile formats */
6951144Sbostic #define print_iheader \
7052094Sbostic 	(void)printf("inum\tstatus\tversion\tdaddr\t\tfreeptr\n")
7151144Sbostic #define print_ientry(i, ip) \
7251144Sbostic 	if (ip->if_daddr == LFS_UNUSED_DADDR) \
7352094Sbostic 		(void)printf("%d\tFREE\t%d\t \t\t%d\n", \
7451144Sbostic 		    i, ip->if_version, ip->if_nextfree); \
7551144Sbostic 	else \
7652094Sbostic 		(void)printf("%d\tINUSE\t%d\t%8X    \n", \
7752094Sbostic 		    i, ip->if_version, ip->if_daddr)
7851144Sbostic int
7951862Sbostic main(argc, argv)
8051144Sbostic 	int argc;
8151144Sbostic 	char *argv[];
8251144Sbostic {
8351862Sbostic 	struct lfs lfs_sb1, lfs_sb2, *lfs_master;
8451861Sbostic 	daddr_t seg_addr;
8551861Sbostic 	int ch, do_allsb, do_ientries, fd, segnum;
8651144Sbostic 
8751144Sbostic 	do_allsb = 0;
8851144Sbostic 	do_ientries = 0;
8951861Sbostic 	while ((ch = getopt(argc, argv, "ais:")) != EOF)
9051144Sbostic 		switch(ch) {
9151861Sbostic 		case 'a':		/* Dump all superblocks */
9251861Sbostic 			do_allsb = 1;
9351861Sbostic 			break;
9451144Sbostic 		case 'i':		/* Dump ifile entries */
9551144Sbostic 			do_ientries = 1;
9651144Sbostic 			break;
9751861Sbostic 		case 's':		/* Dump out these segments */
9851861Sbostic 			addseg(optarg);
9951144Sbostic 			break;
10051144Sbostic 		default:
10151144Sbostic 			usage();
10251144Sbostic 		}
10351144Sbostic 	argc -= optind;
10451144Sbostic 	argv += optind;
10551144Sbostic 
10651144Sbostic 	if (argc != 1)
10751144Sbostic 		usage();
10851144Sbostic 
10951144Sbostic 	special = argv[0];
11051144Sbostic 	if ((fd = open(special, O_RDONLY, 0)) < 0)
11151144Sbostic 		err("%s: %s", special, strerror(errno));
11251144Sbostic 
11351144Sbostic 	/* Read the first superblock */
11451862Sbostic 	get(fd, LFS_LABELPAD, &lfs_sb1, sizeof(struct lfs));
11551144Sbostic 	daddr_shift = lfs_sb1.lfs_bshift - lfs_sb1.lfs_fsbtodb;
11651144Sbostic 
11751144Sbostic 	/*
11851144Sbostic 	 * Read the second superblock and figure out which check point is
11951144Sbostic 	 * most up to date.
12051144Sbostic 	 */
12151862Sbostic 	get(fd,
12251862Sbostic 	    lfs_sb1.lfs_sboffs[1] << daddr_shift, &lfs_sb2, sizeof(struct lfs));
12351861Sbostic 
12451144Sbostic 	lfs_master = &lfs_sb1;
12551144Sbostic 	if (lfs_sb1.lfs_tstamp < lfs_sb2.lfs_tstamp)
12651144Sbostic 		lfs_master = &lfs_sb2;
12751144Sbostic 
12851144Sbostic 	(void)printf("Master Superblock:\n");
12951144Sbostic 	dump_super(lfs_master);
13051144Sbostic 
13151144Sbostic 	dump_ifile(fd, lfs_master, do_ientries);
13251144Sbostic 
13351861Sbostic 	if (seglist != NULL)
13451861Sbostic 		for (; seglist != NULL; seglist = seglist->next) {
13551861Sbostic 			seg_addr = lfs_master->lfs_sboffs[0] + seglist->num *
13651861Sbostic 			    (lfs_master->lfs_ssize << lfs_master->lfs_fsbtodb);
13751861Sbostic 			dump_segment(fd,
13851861Sbostic 			    seglist->num, seg_addr, lfs_master, do_allsb);
13951861Sbostic 		}
14051861Sbostic 	else
14151861Sbostic 		for (segnum = 0, seg_addr = lfs_master->lfs_sboffs[0];
14251861Sbostic 		    segnum < lfs_master->lfs_nseg; segnum++, seg_addr +=
14351861Sbostic 		    lfs_master->lfs_ssize << lfs_master->lfs_fsbtodb)
14451861Sbostic 			dump_segment(fd,
14551861Sbostic 			    segnum, seg_addr, lfs_master, do_allsb);
14651861Sbostic 
14751144Sbostic 	(void)close(fd);
14851144Sbostic 	exit(0);
14951144Sbostic }
15051144Sbostic 
15151144Sbostic /*
15251144Sbostic  * We are reading all the blocks of an inode and dumping out the ifile table.
15351862Sbostic  * This code could be tighter, but this is a first pass at getting the stuff
15451144Sbostic  * printed out rather than making this code incredibly efficient.
15551144Sbostic  */
15651144Sbostic static void
15751144Sbostic dump_ifile(fd, lfsp, do_ientries)
15851144Sbostic 	int fd;
15951862Sbostic 	struct lfs *lfsp;
16051144Sbostic 	int do_ientries;
16151144Sbostic {
16251144Sbostic 	IFILE *ipage;
16351144Sbostic 	struct dinode *dip, *dpage;
16451862Sbostic 	daddr_t addr, *addrp, *dindir, *iaddrp, *indir;
16551862Sbostic 	int block_limit, i, inum, j, nblocks, nsupb, psize;
16651144Sbostic 
16751144Sbostic 	psize = lfsp->lfs_bsize;
16851144Sbostic 	addr = lfsp->lfs_idaddr;
16951144Sbostic 
170*56032Sbostic 	if (!(dpage = malloc(psize)))
17151144Sbostic 		err("%s", strerror(errno));
172*56032Sbostic 	get(fd, addr << daddr_shift, dpage, psize);
17351144Sbostic 
174*56032Sbostic 	for (dip = dpage + INOPB(lfsp) - 1; dip >= dpage; --dip)
17551144Sbostic 		if (dip->di_inum == LFS_IFILE_INUM)
17651144Sbostic 			break;
17751144Sbostic 
178*56032Sbostic 	if (dip < dpage)
17951144Sbostic 		err("unable to locate ifile inode");
18051144Sbostic 
18151144Sbostic 	(void)printf("\nIFILE inode\n");
18251144Sbostic 	dump_dinode(dip);
18351861Sbostic 
18451144Sbostic 	(void)printf("\nIFILE contents\n");
18551144Sbostic 	nblocks = dip->di_size >> lfsp->lfs_bshift;
18651144Sbostic 	block_limit = MIN(nblocks, NDADDR);
18751144Sbostic 
18851144Sbostic 	/* Get the direct block */
18951144Sbostic 	if ((ipage = malloc(psize)) == NULL)
19051144Sbostic 		err("%s", strerror(errno));
19151144Sbostic 	for (inum = 0, addrp = dip->di_db, i = 0; i < block_limit;
19251144Sbostic 	    i++, addrp++) {
19351144Sbostic 		get(fd, *addrp << daddr_shift, ipage, psize);
19451862Sbostic 		if (i < lfsp->lfs_cleansz) {
19551862Sbostic 			dump_cleaner_info(lfsp, ipage);
19652094Sbostic 			print_suheader;
19751862Sbostic 			continue;
19852094Sbostic 		}
19951144Sbostic 
20052094Sbostic 		if (i < (lfsp->lfs_segtabsz + lfsp->lfs_cleansz)) {
20151862Sbostic 			inum = dump_ipage_segusage(lfsp, inum, ipage,
20251862Sbostic 			    lfsp->lfs_sepb);
20351144Sbostic 			if (!inum)
20451144Sbostic 				if(!do_ientries)
20555479Sbostic 					goto e0;
20651144Sbostic 				else
20751144Sbostic 					print_iheader;
20851144Sbostic 		} else
20951144Sbostic 			inum = dump_ipage_ifile(inum, ipage, lfsp->lfs_ifpb);
21051862Sbostic 
21151144Sbostic 	}
21251144Sbostic 
21351144Sbostic 	if (nblocks <= NDADDR)
21451144Sbostic 		goto e0;
21551144Sbostic 
21651144Sbostic 	/* Dump out blocks off of single indirect block */
21751144Sbostic 	if (!(indir = malloc(psize)))
21851144Sbostic 		err("%s", strerror(errno));
21951144Sbostic 	get(fd, dip->di_ib[0] << daddr_shift, indir, psize);
22051144Sbostic 	block_limit = MIN(i + lfsp->lfs_nindir, nblocks);
22151144Sbostic 	for (addrp = indir; i < block_limit; i++, addrp++) {
22251144Sbostic 		if (*addrp == LFS_UNUSED_DADDR)
22351144Sbostic 			break;
22451144Sbostic 		get(fd, *addrp << daddr_shift,ipage, psize);
22551862Sbostic 		if (i < lfsp->lfs_cleansz) {
22651862Sbostic 			dump_cleaner_info(lfsp, ipage);
22751862Sbostic 			continue;
22851862Sbostic 		} else
22951862Sbostic 			i -= lfsp->lfs_cleansz;
23051862Sbostic 
23151144Sbostic 		if (i < lfsp->lfs_segtabsz) {
23251862Sbostic 			inum = dump_ipage_segusage(lfsp, inum, ipage,
23351862Sbostic 			    lfsp->lfs_sepb);
23451144Sbostic 			if (!inum)
23551144Sbostic 				if(!do_ientries)
23651144Sbostic 					goto e1;
23751144Sbostic 				else
23851144Sbostic 					print_iheader;
23951144Sbostic 		} else
24051144Sbostic 			inum = dump_ipage_ifile(inum, ipage, lfsp->lfs_ifpb);
24151144Sbostic 	}
24251144Sbostic 
24351144Sbostic 	if (nblocks <= lfsp->lfs_nindir * lfsp->lfs_ifpb)
24451144Sbostic 		goto e1;
24551861Sbostic 
24651144Sbostic 	/* Get the double indirect block */
24751144Sbostic 	if (!(dindir = malloc(psize)))
24851144Sbostic 		err("%s", strerror(errno));
24951144Sbostic 	get(fd, dip->di_ib[1] << daddr_shift, dindir, psize);
25051144Sbostic 	for (iaddrp = dindir, j = 0; j < lfsp->lfs_nindir; j++, iaddrp++) {
25151144Sbostic 		if (*iaddrp == LFS_UNUSED_DADDR)
25251144Sbostic 			break;
25351144Sbostic 		get(fd, *iaddrp << daddr_shift, indir, psize);
25451144Sbostic 		block_limit = MIN(i + lfsp->lfs_nindir, nblocks);
25551144Sbostic 		for (addrp = indir; i < block_limit; i++, addrp++) {
25651144Sbostic 			if (*addrp == LFS_UNUSED_DADDR)
25751144Sbostic 				break;
25851144Sbostic 			get(fd, *addrp << daddr_shift, ipage, psize);
25951862Sbostic 			if (i < lfsp->lfs_cleansz) {
26051862Sbostic 				dump_cleaner_info(lfsp, ipage);
26151862Sbostic 				continue;
26251862Sbostic 			} else
26351862Sbostic 				i -= lfsp->lfs_cleansz;
26451862Sbostic 
26551144Sbostic 			if (i < lfsp->lfs_segtabsz) {
26651144Sbostic 				inum = dump_ipage_segusage(lfsp,
26751862Sbostic 				    inum, ipage, lfsp->lfs_sepb);
26851144Sbostic 				if (!inum)
26951144Sbostic 					if(!do_ientries)
27051144Sbostic 						goto e2;
27151144Sbostic 					else
27251144Sbostic 						print_iheader;
27351144Sbostic 			} else
27451144Sbostic 				inum = dump_ipage_ifile(inum,
27551144Sbostic 				    ipage, lfsp->lfs_ifpb);
27651144Sbostic 		}
27751144Sbostic 	}
27851144Sbostic e2:	free(dindir);
27951144Sbostic e1:	free(indir);
28051144Sbostic e0:	free(dpage);
28151144Sbostic 	free(ipage);
28251144Sbostic }
28351144Sbostic 
28451144Sbostic static int
28551144Sbostic dump_ipage_ifile(i, pp, tot)
28651144Sbostic 	int i;
28751144Sbostic 	IFILE *pp;
28851144Sbostic 	int tot;
28951144Sbostic {
29051144Sbostic 	IFILE *ip;
29151144Sbostic 	int cnt, max;
29251144Sbostic 
29351144Sbostic 	max = i + tot;
29451144Sbostic 
29551144Sbostic 	for (ip = pp, cnt = i; cnt < max; cnt++, ip++)
29651144Sbostic 		print_ientry(cnt, ip);
29751144Sbostic 	return (max);
29851144Sbostic }
29951144Sbostic 
30051144Sbostic static int
30151144Sbostic dump_ipage_segusage(lfsp, i, pp, tot)
30251862Sbostic 	struct lfs *lfsp;
30351144Sbostic 	int i;
30451144Sbostic 	IFILE *pp;
30551144Sbostic 	int tot;
30651144Sbostic {
30751861Sbostic 	SEGUSE *sp;
30851144Sbostic 	int cnt, max;
30951144Sbostic 
31051144Sbostic 	max = i + tot;
31151861Sbostic 	for (sp = (SEGUSE *)pp, cnt = i;
31251144Sbostic 	     cnt < lfsp->lfs_nseg && cnt < max; cnt++, sp++)
31351144Sbostic 		print_suentry(cnt, sp);
31451144Sbostic 	if (max >= lfsp->lfs_nseg)
31551144Sbostic 		return (0);
31651144Sbostic 	else
31751144Sbostic 		return (max);
31851144Sbostic }
31951144Sbostic 
32051144Sbostic static void
32151144Sbostic dump_dinode(dip)
32251144Sbostic 	struct dinode *dip;
32351144Sbostic {
32451144Sbostic 	int i;
32551144Sbostic 
32651144Sbostic 	(void)printf("%s%d\t%s%d\t%s%d\t%s%d\t%s%d\n",
32751144Sbostic 		"mode  ", dip->di_mode,
32851144Sbostic 		"nlink ", dip->di_nlink,
32951144Sbostic 		"uid   ", dip->di_uid,
33051144Sbostic 		"gid   ", dip->di_gid,
33151144Sbostic 		"size  ", dip->di_size);
33251144Sbostic 	(void)printf("%s%s%s%s%s%s",
33354714Sbostic 		"atime ", ctime(&dip->di_atime.ts_sec),
33454714Sbostic 		"mtime ", ctime(&dip->di_mtime.ts_sec),
33554714Sbostic 		"ctime ", ctime(&dip->di_ctime.ts_sec));
33651144Sbostic 	(void)printf("inum  %d\n", dip->di_inum);
33751144Sbostic 	(void)printf("Direct Addresses\n");
33851144Sbostic 	for (i = 0; i < NDADDR; i++) {
33955479Sbostic 		(void)printf("\t0x%X", dip->di_db[i]);
34051144Sbostic 		if ((i % 6) == 5)
34151144Sbostic 			(void)printf("\n");
34251144Sbostic 	}
34351144Sbostic 	for (i = 0; i < NIADDR; i++)
34455479Sbostic 		(void)printf("\t0x%X", dip->di_ib[i]);
34551144Sbostic 	(void)printf("\n");
34651144Sbostic }
34751144Sbostic 
34851144Sbostic static int
34952464Sstaelin dump_sum(fd, lfsp, sp, segnum, addr)
35051862Sbostic 	struct lfs *lfsp;
35151144Sbostic 	SEGSUM *sp;
35252464Sstaelin 	int fd, segnum;
35351861Sbostic 	daddr_t addr;
35451144Sbostic {
35551144Sbostic 	FINFO *fp;
35651861Sbostic 	long *dp;
35751862Sbostic 	int i, j;
35851861Sbostic 	int ck;
35951862Sbostic 	int numblocks;
36052464Sstaelin 	struct dinode *inop;
36151144Sbostic 
36251862Sbostic 	if (sp->ss_sumsum != (ck = cksum(&sp->ss_datasum,
36355479Sbostic 	    LFS_SUMMARY_SIZE - sizeof(sp->ss_sumsum)))) {
36455479Sbostic 		(void)printf("dumplfs: %s %d address 0x%lx\n",
36551861Sbostic 		    "corrupt summary block; segment", segnum, addr);
36655479Sbostic 		return(0);
36755479Sbostic 	}
36851861Sbostic 
36955479Sbostic 	(void)printf("Segment Summary Info at 0x%lx\n", addr);
37055479Sbostic 	(void)printf("    %s0x%X\t%s%d\t%s%d\n    %s0x%X\t%s0x%X",
37151144Sbostic 		"next     ", sp->ss_next,
37251144Sbostic 		"nfinfo   ", sp->ss_nfinfo,
37351144Sbostic 		"ninos    ", sp->ss_ninos,
37451862Sbostic 		"sumsum   ", sp->ss_sumsum,
37551862Sbostic 		"datasum  ", sp->ss_datasum );
37651144Sbostic 	(void)printf("\tcreate   %s", ctime((time_t *)&sp->ss_create));
37751144Sbostic 
37851862Sbostic 	numblocks = (sp->ss_ninos + INOPB(lfsp) - 1) / INOPB(lfsp);
37951862Sbostic 
38051862Sbostic 	/* Dump out inode disk addresses */
38151862Sbostic 	dp = (daddr_t *)sp;
38251862Sbostic 	dp += LFS_SUMMARY_SIZE / sizeof(daddr_t);
38352464Sstaelin 	inop = malloc(1 << lfsp->lfs_bshift);
38455479Sbostic 	printf("    Inode addresses:");
38552464Sstaelin 	for (dp--, i = 0; i < sp->ss_ninos; dp--) {
38655479Sbostic 		printf("\t0x%X {", *dp);
38752464Sstaelin 		get(fd, *dp << (lfsp->lfs_bshift - lfsp->lfs_fsbtodb), inop,
38852464Sstaelin 		    (1 << lfsp->lfs_bshift));
38952464Sstaelin 		for (j = 0; i < sp->ss_ninos && j < INOPB(lfsp); j++, i++) {
39052464Sstaelin 			if (j > 0)
39152464Sstaelin 				(void)printf(", ");
39252464Sstaelin 			(void)printf("%d", inop[j].di_inum);
39352464Sstaelin 		}
39452464Sstaelin 		(void)printf("}");
39552464Sstaelin 		if (((i/INOPB(lfsp)) % 4) == 3)
39652464Sstaelin 			(void)printf("\n");
39752464Sstaelin 	}
39852464Sstaelin 	free(inop);
39951862Sbostic 
40051862Sbostic 	printf("\n");
40151144Sbostic 	for (fp = (FINFO *)(sp + 1), i = 0; i < sp->ss_nfinfo; i++) {
40251862Sbostic 		numblocks += fp->fi_nblocks;
40355479Sbostic 		(void)printf("    FINFO for inode: %d version %d nblocks %d\n",
40451144Sbostic 		    fp->fi_ino, fp->fi_version, fp->fi_nblocks);
40551144Sbostic 		dp = &(fp->fi_blocks[0]);
40651144Sbostic 		for (j = 0; j < fp->fi_nblocks; j++, dp++) {
40751144Sbostic 			(void)printf("\t%d", *dp);
40851144Sbostic 			if ((j % 8) == 7)
40951144Sbostic 				(void)printf("\n");
41051144Sbostic 		}
41151144Sbostic 		if ((j % 8) != 0)
41251144Sbostic 			(void)printf("\n");
41351144Sbostic 		fp = (FINFO *)dp;
41451144Sbostic 	}
41551862Sbostic 	return (numblocks);
41651144Sbostic }
41751144Sbostic 
41851862Sbostic static void
41951861Sbostic dump_segment(fd, segnum, addr, lfsp, dump_sb)
42051861Sbostic 	int fd, segnum;
42151144Sbostic 	daddr_t addr;
42251862Sbostic 	struct lfs *lfsp;
42351144Sbostic 	int dump_sb;
42451144Sbostic {
42551862Sbostic 	struct lfs lfs_sb, *sbp;
42651144Sbostic 	SEGSUM *sump;
42751144Sbostic 	char sumblock[LFS_SUMMARY_SIZE];
42851862Sbostic 	int did_one, nblocks, sb;
42951862Sbostic 	off_t sum_offset, super_off;
43051144Sbostic 
43155479Sbostic 	(void)printf("\nSEGMENT %d (Disk Address 0x%X)\n",
43251144Sbostic 	    addr >> (lfsp->lfs_segshift - daddr_shift), addr);
43351862Sbostic 	sum_offset = (addr << (lfsp->lfs_bshift - lfsp->lfs_fsbtodb));
43451861Sbostic 
43551144Sbostic 	sb = 0;
43651862Sbostic 	did_one = 0;
43751144Sbostic 	do {
43851144Sbostic 		get(fd, sum_offset, sumblock, LFS_SUMMARY_SIZE);
43951144Sbostic 		sump = (SEGSUM *)sumblock;
44051862Sbostic 		if (sump->ss_sumsum != cksum (&sump->ss_datasum,
44151862Sbostic 			LFS_SUMMARY_SIZE - sizeof(sump->ss_sumsum))) {
44251862Sbostic 			sbp = (struct lfs *)sump;
44351862Sbostic 			if (sb = (sbp->lfs_magic == LFS_MAGIC)) {
44451862Sbostic 				super_off = sum_offset;
44551862Sbostic 				sum_offset += LFS_SBPAD;
44651862Sbostic 			} else if (did_one)
44751862Sbostic 				break;
44851862Sbostic 			else {
44955479Sbostic 				printf("Segment at 0x%X corrupt\n", addr);
45051862Sbostic 				break;
45151862Sbostic 			}
45251862Sbostic 		} else {
45355479Sbostic 			nblocks = dump_sum(fd, lfsp, sump, segnum, sum_offset >>
45455479Sbostic 			     (lfsp->lfs_bshift - lfsp->lfs_fsbtodb));
45551862Sbostic 			if (nblocks)
45652464Sstaelin 				sum_offset += LFS_SUMMARY_SIZE +
45752464Sstaelin 					(nblocks << lfsp->lfs_bshift);
45851862Sbostic 			else
45951862Sbostic 				sum_offset = 0;
46051862Sbostic 			did_one = 1;
46151862Sbostic 		}
46251144Sbostic 	} while (sum_offset);
46351862Sbostic 
46451144Sbostic 	if (dump_sb && sb)  {
46551862Sbostic 		get(fd, super_off, &lfs_sb, sizeof(struct lfs));
46651144Sbostic 		dump_super(&lfs_sb);
46751144Sbostic 	}
46851862Sbostic 	return;
46951144Sbostic }
47051144Sbostic 
47151861Sbostic static void
47251144Sbostic dump_super(lfsp)
47351862Sbostic 	struct lfs *lfsp;
47451144Sbostic {
47551144Sbostic 	int i;
47651144Sbostic 
47755479Sbostic 	(void)printf("%s0x%X\t%s0x%X\t%s%d\t%s%d\n",
47851144Sbostic 		"magic    ", lfsp->lfs_magic,
47951144Sbostic 		"version  ", lfsp->lfs_version,
48051144Sbostic 		"size     ", lfsp->lfs_size,
48151144Sbostic 		"ssize    ", lfsp->lfs_ssize);
48255479Sbostic 	(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
48351144Sbostic 		"dsize    ", lfsp->lfs_dsize,
48451144Sbostic 		"bsize    ", lfsp->lfs_bsize,
48551144Sbostic 		"fsize    ", lfsp->lfs_fsize,
48651144Sbostic 		"frag     ", lfsp->lfs_frag);
48751144Sbostic 
48855479Sbostic 	(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
48951144Sbostic 		"minfree  ", lfsp->lfs_minfree,
49051144Sbostic 		"inopb    ", lfsp->lfs_inopb,
49151144Sbostic 		"ifpb     ", lfsp->lfs_ifpb,
49251144Sbostic 		"nindir   ", lfsp->lfs_nindir);
49351144Sbostic 
49455479Sbostic 	(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
49551144Sbostic 		"nseg     ", lfsp->lfs_nseg,
49651144Sbostic 		"nspf     ", lfsp->lfs_nspf,
49751862Sbostic 		"cleansz  ", lfsp->lfs_cleansz,
49851144Sbostic 		"segtabsz ", lfsp->lfs_segtabsz);
49951144Sbostic 
50055479Sbostic 	(void)printf("%s0x%X\t%s%d\t%s0x%X\t%s%d\n",
50151144Sbostic 		"segmask  ", lfsp->lfs_segmask,
50251144Sbostic 		"segshift ", lfsp->lfs_segshift,
50351144Sbostic 		"bmask    ", lfsp->lfs_bmask,
50451144Sbostic 		"bshift   ", lfsp->lfs_bshift);
50551144Sbostic 
50655479Sbostic 	(void)printf("%s0x%X\t\t%s%d\t%s0x%X\t%s%d\n",
50751144Sbostic 		"ffmask   ", lfsp->lfs_ffmask,
50851144Sbostic 		"ffshift  ", lfsp->lfs_ffshift,
50951144Sbostic 		"fbmask   ", lfsp->lfs_fbmask,
51051144Sbostic 		"fbshift  ", lfsp->lfs_fbshift);
51151144Sbostic 
51255597Sbostic 	(void)printf("%s%d\t%s%d\t%s0x%X\t%s0x%qx\n",
51355597Sbostic 		"sushift  ", lfsp->lfs_sushift,
51451144Sbostic 		"fsbtodb  ", lfsp->lfs_fsbtodb,
51555388Sbostic 		"cksum    ", lfsp->lfs_cksum,
51655388Sbostic 		"maxfilesize  ", lfsp->lfs_maxfilesize);
51751144Sbostic 
51855479Sbostic 	(void)printf("Superblock disk addresses:\t");
51955479Sbostic 	for (i = 0; i < LFS_MAXNUMSB; i++) {
52055479Sbostic 		(void)printf(" 0x%X", lfsp->lfs_sboffs[i]);
52155479Sbostic 		if ( i == (LFS_MAXNUMSB >> 1))
52255479Sbostic 			(void)printf("\n\t\t\t\t");
52355479Sbostic 	}
52451144Sbostic 	(void)printf("\n");
52551144Sbostic 
52651144Sbostic 	(void)printf("Checkpoint Info\n");
52755479Sbostic 	(void)printf("%s%d\t%s0x%X\t%s%d\n",
52851144Sbostic 		"free     ", lfsp->lfs_free,
52951144Sbostic 		"idaddr   ", lfsp->lfs_idaddr,
53051861Sbostic 		"ifile    ", lfsp->lfs_ifile);
531*56032Sbostic 	(void)printf("%s%d\t%s%d\t%s%d\n",
53251861Sbostic 		"bfree    ", lfsp->lfs_bfree,
533*56032Sbostic 		"avail    ", lfsp->lfs_avail,
534*56032Sbostic 		"uinodes  ", lfsp->lfs_uinodes);
535*56032Sbostic 	(void)printf("%s%d\t%s0x%X\t%s0x%X\n%s0x%X\t%s0x%X\t",
53651861Sbostic 		"nfiles   ", lfsp->lfs_nfiles,
53751861Sbostic 		"lastseg  ", lfsp->lfs_lastseg,
53851862Sbostic 		"nextseg  ", lfsp->lfs_nextseg,
53951862Sbostic 		"curseg   ", lfsp->lfs_curseg,
54051862Sbostic 		"offset   ", lfsp->lfs_offset);
54151144Sbostic 	(void)printf("tstamp   %s", ctime((time_t *)&lfsp->lfs_tstamp));
54255479Sbostic 	(void)printf("\nIn-Memory Information\n");
543*56032Sbostic 	(void)printf("%s%d\t%s0x%X\t%s%d%s%d\t%s%d\n",
54455239Sbostic 		"seglock  ", lfsp->lfs_seglock,
54555239Sbostic 		"iocount  ", lfsp->lfs_iocount,
54655239Sbostic 		"writer   ", lfsp->lfs_writer,
54755239Sbostic 		"dirops   ", lfsp->lfs_dirops,
548*56032Sbostic 		"doifile  ", lfsp->lfs_doifile);
549*56032Sbostic 	(void)printf("%s%d\t%s%d\t%s0x%X\t%s%d\n",
550*56032Sbostic 		"nactive  ", lfsp->lfs_nactive,
55155239Sbostic 		"fmod     ", lfsp->lfs_fmod,
55255239Sbostic 		"clean    ", lfsp->lfs_clean,
55355239Sbostic 		"ronly    ", lfsp->lfs_ronly);
55451144Sbostic }
55551144Sbostic 
55651144Sbostic static void
55751861Sbostic addseg(arg)
55851861Sbostic 	char *arg;
55951861Sbostic {
56051861Sbostic 	SEGLIST *p;
56151861Sbostic 
56251861Sbostic 	if ((p = malloc(sizeof(SEGLIST))) == NULL)
56351861Sbostic 		err("%s", strerror(errno));
56451861Sbostic 	p->next = seglist;
56551861Sbostic 	p->num = atoi(arg);
56651861Sbostic 	seglist = p;
56751861Sbostic }
56851861Sbostic 
56951861Sbostic static void
57051862Sbostic dump_cleaner_info(lfsp, ipage)
57151862Sbostic 	struct lfs *lfsp;
57251862Sbostic 	void *ipage;
57351862Sbostic {
57451929Sbostic 	CLEANERINFO *cip;
57551929Sbostic 
57651929Sbostic 	cip = (CLEANERINFO *)ipage;
57755479Sbostic 	(void)printf("segments clean\t%d\tsegments dirty\t%d\n\n",
57851929Sbostic 	    cip->clean, cip->dirty);
57951862Sbostic }
58051862Sbostic 
58151862Sbostic static void
58251144Sbostic usage()
58351144Sbostic {
58451861Sbostic 	(void)fprintf(stderr, "usage: dumplfs [-ai] [-s segnum] file\n");
58551144Sbostic 	exit(1);
58651144Sbostic }
587