Home | History | Annotate | Line # | Download | only in dumplfs
dumplfs.c revision 1.38.6.2
      1  1.38.6.2      yamt /*	$NetBSD: dumplfs.c,v 1.38.6.2 2014/05/22 11:43:03 yamt Exp $	*/
      2       1.5       cgd 
      3       1.1   mycroft /*-
      4       1.1   mycroft  * Copyright (c) 1991, 1993
      5       1.1   mycroft  *	The Regents of the University of California.  All rights reserved.
      6       1.1   mycroft  *
      7       1.1   mycroft  * Redistribution and use in source and binary forms, with or without
      8       1.1   mycroft  * modification, are permitted provided that the following conditions
      9       1.1   mycroft  * are met:
     10       1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     11       1.1   mycroft  *    notice, this list of conditions and the following disclaimer.
     12       1.1   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1   mycroft  *    notice, this list of conditions and the following disclaimer in the
     14       1.1   mycroft  *    documentation and/or other materials provided with the distribution.
     15      1.28       agc  * 3. Neither the name of the University nor the names of its contributors
     16       1.1   mycroft  *    may be used to endorse or promote products derived from this software
     17       1.1   mycroft  *    without specific prior written permission.
     18       1.1   mycroft  *
     19       1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20       1.1   mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21       1.1   mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22       1.1   mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23       1.1   mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24       1.1   mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25       1.1   mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26       1.1   mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27       1.1   mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28       1.1   mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29       1.1   mycroft  * SUCH DAMAGE.
     30       1.1   mycroft  */
     31       1.1   mycroft 
     32       1.8      fvdl #include <sys/cdefs.h>
     33       1.8      fvdl 
     34       1.1   mycroft #ifndef lint
     35      1.37     lukem __COPYRIGHT("@(#) Copyright (c) 1991, 1993\
     36      1.37     lukem  The Regents of the University of California.  All rights reserved.");
     37       1.1   mycroft #endif /* not lint */
     38       1.1   mycroft 
     39       1.1   mycroft #ifndef lint
     40       1.5       cgd #if 0
     41       1.8      fvdl static char sccsid[] = "@(#)dumplfs.c	8.5 (Berkeley) 5/24/95";
     42       1.5       cgd #else
     43  1.38.6.2      yamt __RCSID("$NetBSD: dumplfs.c,v 1.38.6.2 2014/05/22 11:43:03 yamt Exp $");
     44       1.5       cgd #endif
     45       1.1   mycroft #endif /* not lint */
     46       1.1   mycroft 
     47       1.1   mycroft #include <sys/param.h>
     48       1.1   mycroft #include <sys/ucred.h>
     49       1.1   mycroft #include <sys/mount.h>
     50       1.1   mycroft #include <sys/time.h>
     51       1.1   mycroft 
     52       1.1   mycroft #include <ufs/lfs/lfs.h>
     53       1.1   mycroft 
     54       1.2   mycroft #include <err.h>
     55       1.2   mycroft #include <errno.h>
     56       1.1   mycroft #include <fcntl.h>
     57       1.1   mycroft #include <fstab.h>
     58       1.1   mycroft #include <stdlib.h>
     59       1.1   mycroft #include <stdio.h>
     60       1.1   mycroft #include <string.h>
     61       1.2   mycroft #include <unistd.h>
     62       1.1   mycroft #include "extern.h"
     63       1.1   mycroft 
     64      1.19  perseant static void	addseg(char *);
     65      1.19  perseant static void	dump_cleaner_info(struct lfs *, void *);
     66  1.38.6.2      yamt static void	dump_dinode(struct ulfs1_dinode *);
     67      1.20      fvdl static void	dump_ifile(int, struct lfs *, int, int, daddr_t);
     68      1.19  perseant static int	dump_ipage_ifile(struct lfs *, int, char *, int);
     69      1.19  perseant static int	dump_ipage_segusage(struct lfs *, int, char *, int);
     70      1.19  perseant static void	dump_segment(int, int, daddr_t, struct lfs *, int);
     71      1.19  perseant static int	dump_sum(int, struct lfs *, SEGSUM *, int, daddr_t);
     72      1.19  perseant static void	dump_super(struct lfs *);
     73      1.19  perseant static void	usage(void);
     74       1.1   mycroft 
     75      1.36      matt extern uint32_t	cksum(void *, size_t);
     76       1.8      fvdl 
     77       1.1   mycroft typedef struct seglist SEGLIST;
     78       1.1   mycroft struct seglist {
     79       1.1   mycroft         SEGLIST *next;
     80       1.1   mycroft 	int num;
     81       1.1   mycroft };
     82       1.1   mycroft SEGLIST	*seglist;
     83       1.1   mycroft 
     84       1.1   mycroft char *special;
     85       1.1   mycroft 
     86       1.1   mycroft /* Segment Usage formats */
     87       1.1   mycroft #define print_suheader \
     88       1.1   mycroft 	(void)printf("segnum\tflags\tnbytes\tninos\tnsums\tlastmod\n")
     89       1.1   mycroft 
     90      1.31  perseant static inline void
     91      1.31  perseant print_suentry(int i, SEGUSE *sp, struct lfs *fs)
     92      1.31  perseant {
     93      1.31  perseant 	time_t t;
     94      1.31  perseant 	char flags[4] = "   ";
     95      1.31  perseant 
     96      1.31  perseant 	if (sp->su_flags & SEGUSE_ACTIVE)
     97      1.31  perseant 		flags[0] = 'A';
     98      1.31  perseant 	if (sp->su_flags & SEGUSE_DIRTY)
     99      1.31  perseant 		flags[1] = 'D';
    100      1.31  perseant 	else
    101      1.31  perseant 		flags[1] = 'C';
    102      1.31  perseant 	if (sp->su_flags & SEGUSE_SUPERBLOCK)
    103      1.31  perseant 		flags[2] = 'S';
    104      1.31  perseant 
    105      1.31  perseant 	t = (fs->lfs_version == 1 ? sp->su_olastmod : sp->su_lastmod);
    106      1.31  perseant 
    107      1.31  perseant 	printf("%d\t%s\t%d\t%d\t%d\t%s", i, flags,
    108      1.31  perseant 		sp->su_nbytes, sp->su_ninos, sp->su_nsums,
    109      1.31  perseant 		ctime(&t));
    110      1.31  perseant }
    111       1.1   mycroft 
    112       1.1   mycroft /* Ifile formats */
    113       1.1   mycroft #define print_iheader \
    114       1.1   mycroft 	(void)printf("inum\tstatus\tversion\tdaddr\t\tfreeptr\n")
    115      1.31  perseant 
    116      1.31  perseant static inline void
    117      1.31  perseant print_ientry(int i, IFILE *ip)
    118      1.31  perseant {
    119      1.31  perseant 	if (ip->if_daddr == LFS_UNUSED_DADDR)
    120      1.31  perseant 		printf("%d\tFREE\t%d\t \t\t%llu\n", i, ip->if_version,
    121      1.31  perseant 		    (unsigned long long)ip->if_nextfree);
    122      1.31  perseant 	else
    123      1.34  perseant 		printf("%d\tINUSE\t%d\t%8X\t%s\n",
    124      1.34  perseant 		    i, ip->if_version, ip->if_daddr,
    125      1.34  perseant 		    (ip->if_nextfree == LFS_ORPHAN_NEXTFREE ? "FFFFFFFF" : "-"));
    126      1.31  perseant }
    127      1.31  perseant 
    128  1.38.6.2      yamt #define fsbtobyte(fs, b)	lfs_fsbtob((fs), (off_t)((b)))
    129      1.16    toshii 
    130      1.25  perseant int datasum_check = 0;
    131      1.25  perseant 
    132       1.1   mycroft int
    133      1.19  perseant main(int argc, char **argv)
    134       1.1   mycroft {
    135       1.1   mycroft 	struct lfs lfs_sb1, lfs_sb2, *lfs_master;
    136      1.14  perseant 	daddr_t seg_addr, idaddr, sbdaddr;
    137      1.19  perseant 	int ch, do_allsb, do_ientries, do_segentries, fd, segnum;
    138      1.38   mlelstv 	void *sbuf;
    139       1.1   mycroft 
    140       1.1   mycroft 	do_allsb = 0;
    141       1.1   mycroft 	do_ientries = 0;
    142      1.19  perseant 	do_segentries = 0;
    143      1.14  perseant 	idaddr = 0x0;
    144      1.14  perseant 	sbdaddr = 0x0;
    145      1.25  perseant 	while ((ch = getopt(argc, argv, "ab:diI:Ss:")) != -1)
    146       1.1   mycroft 		switch(ch) {
    147       1.1   mycroft 		case 'a':		/* Dump all superblocks */
    148       1.1   mycroft 			do_allsb = 1;
    149       1.1   mycroft 			break;
    150      1.14  perseant 		case 'b':		/* Use this superblock */
    151      1.14  perseant 			sbdaddr = strtol(optarg, NULL, 0);
    152      1.14  perseant 			break;
    153      1.25  perseant 		case 'd':
    154      1.25  perseant 			datasum_check = 1;
    155      1.25  perseant 			break;
    156       1.1   mycroft 		case 'i':		/* Dump ifile entries */
    157      1.19  perseant 			do_ientries = !do_ientries;
    158       1.1   mycroft 			break;
    159      1.14  perseant 		case 'I':		/* Use this ifile inode */
    160      1.14  perseant 			idaddr = strtol(optarg, NULL, 0);
    161      1.14  perseant 			break;
    162      1.19  perseant 		case 'S':
    163      1.19  perseant 			do_segentries = !do_segentries;
    164      1.19  perseant 			break;
    165       1.1   mycroft 		case 's':		/* Dump out these segments */
    166       1.1   mycroft 			addseg(optarg);
    167       1.1   mycroft 			break;
    168       1.1   mycroft 		default:
    169       1.1   mycroft 			usage();
    170       1.1   mycroft 		}
    171       1.1   mycroft 	argc -= optind;
    172       1.1   mycroft 	argv += optind;
    173       1.1   mycroft 
    174       1.1   mycroft 	if (argc != 1)
    175       1.1   mycroft 		usage();
    176       1.1   mycroft 
    177       1.1   mycroft 	special = argv[0];
    178       1.1   mycroft 	if ((fd = open(special, O_RDONLY, 0)) < 0)
    179       1.2   mycroft 		err(1, "%s", special);
    180       1.1   mycroft 
    181      1.38   mlelstv 	sbuf = malloc(LFS_SBPAD);
    182      1.38   mlelstv 	if (sbuf == NULL)
    183      1.38   mlelstv 		err(1, "malloc");
    184      1.38   mlelstv 
    185      1.14  perseant 	if (sbdaddr == 0x0) {
    186      1.19  perseant 		/* Read the proto-superblock */
    187      1.38   mlelstv 		get(fd, LFS_LABELPAD, sbuf, LFS_SBPAD);
    188      1.38   mlelstv 		memcpy(&(lfs_sb1.lfs_dlfs), sbuf, sizeof(struct dlfs));
    189      1.19  perseant 
    190      1.19  perseant 		/* If that wasn't the real first sb, get the real first sb */
    191      1.19  perseant 		if (lfs_sb1.lfs_version > 1 &&
    192  1.38.6.2      yamt 		    lfs_sb1.lfs_sboffs[0] > lfs_btofsb(&lfs_sb1, LFS_LABELPAD))
    193  1.38.6.2      yamt 			get(fd, lfs_fsbtob(&lfs_sb1, lfs_sb1.lfs_sboffs[0]),
    194      1.19  perseant 			    &(lfs_sb1.lfs_dlfs), sizeof(struct dlfs));
    195      1.14  perseant 
    196      1.14  perseant 		/*
    197      1.14  perseant 	 	* Read the second superblock and figure out which check point is
    198      1.14  perseant 	 	* most up to date.
    199      1.14  perseant 	 	*/
    200      1.14  perseant 		get(fd,
    201      1.19  perseant 		    fsbtobyte(&lfs_sb1, lfs_sb1.lfs_sboffs[1]),
    202      1.38   mlelstv 		    sbuf, LFS_SBPAD);
    203      1.38   mlelstv 		memcpy(&(lfs_sb2.lfs_dlfs), sbuf, sizeof(struct dlfs));
    204      1.14  perseant 
    205      1.14  perseant 		lfs_master = &lfs_sb1;
    206      1.19  perseant 		if (lfs_sb1.lfs_version > 1) {
    207      1.19  perseant 			if (lfs_sb1.lfs_serial > lfs_sb2.lfs_serial) {
    208      1.19  perseant 				lfs_master = &lfs_sb2;
    209      1.19  perseant 				sbdaddr = lfs_sb1.lfs_sboffs[1];
    210      1.19  perseant 			} else
    211      1.19  perseant 				sbdaddr = lfs_sb1.lfs_sboffs[0];
    212      1.19  perseant 		} else {
    213      1.19  perseant 			if (lfs_sb1.lfs_otstamp > lfs_sb2.lfs_otstamp) {
    214      1.19  perseant 				lfs_master = &lfs_sb2;
    215      1.19  perseant 				sbdaddr = lfs_sb1.lfs_sboffs[1];
    216      1.19  perseant 			} else
    217      1.19  perseant 				sbdaddr = lfs_sb1.lfs_sboffs[0];
    218      1.19  perseant 		}
    219      1.14  perseant 	} else {
    220      1.14  perseant 		/* Read the first superblock */
    221      1.38   mlelstv 		get(fd, dbtob((off_t)sbdaddr), sbuf, LFS_SBPAD);
    222      1.38   mlelstv 		memcpy(&(lfs_sb1.lfs_dlfs), sbuf, sizeof(struct dlfs));
    223      1.14  perseant 		lfs_master = &lfs_sb1;
    224      1.13  perseant 	}
    225       1.1   mycroft 
    226      1.38   mlelstv 	free(sbuf);
    227      1.38   mlelstv 
    228      1.19  perseant 	/* Compatibility */
    229      1.19  perseant 	if (lfs_master->lfs_version == 1) {
    230      1.19  perseant 		lfs_master->lfs_sumsize = LFS_V1_SUMMARY_SIZE;
    231      1.19  perseant 		lfs_master->lfs_ibsize = lfs_master->lfs_bsize;
    232      1.19  perseant 		lfs_master->lfs_start = lfs_master->lfs_sboffs[0];
    233      1.19  perseant 		lfs_master->lfs_tstamp = lfs_master->lfs_otstamp;
    234      1.19  perseant 		lfs_master->lfs_fsbtodb = 0;
    235      1.19  perseant 	}
    236      1.19  perseant 
    237      1.20      fvdl 	(void)printf("Master Superblock at 0x%llx:\n", (long long)sbdaddr);
    238       1.1   mycroft 	dump_super(lfs_master);
    239       1.1   mycroft 
    240      1.19  perseant 	dump_ifile(fd, lfs_master, do_ientries, do_segentries, idaddr);
    241       1.1   mycroft 
    242       1.1   mycroft 	if (seglist != NULL)
    243       1.1   mycroft 		for (; seglist != NULL; seglist = seglist->next) {
    244  1.38.6.2      yamt 			seg_addr = lfs_sntod(lfs_master, seglist->num);
    245      1.19  perseant 			dump_segment(fd, seglist->num, seg_addr, lfs_master,
    246      1.19  perseant 				     do_allsb);
    247       1.1   mycroft 		}
    248       1.1   mycroft 	else
    249  1.38.6.2      yamt 		for (segnum = 0, seg_addr = lfs_sntod(lfs_master, 0);
    250      1.19  perseant 		     segnum < lfs_master->lfs_nseg;
    251  1.38.6.2      yamt 		     segnum++, seg_addr = lfs_sntod(lfs_master, segnum))
    252      1.19  perseant 			dump_segment(fd, segnum, seg_addr, lfs_master,
    253      1.19  perseant 				     do_allsb);
    254       1.1   mycroft 
    255       1.1   mycroft 	(void)close(fd);
    256       1.1   mycroft 	exit(0);
    257       1.1   mycroft }
    258       1.1   mycroft 
    259       1.1   mycroft /*
    260       1.1   mycroft  * We are reading all the blocks of an inode and dumping out the ifile table.
    261       1.1   mycroft  * This code could be tighter, but this is a first pass at getting the stuff
    262       1.1   mycroft  * printed out rather than making this code incredibly efficient.
    263       1.1   mycroft  */
    264       1.1   mycroft static void
    265      1.19  perseant dump_ifile(int fd, struct lfs *lfsp, int do_ientries, int do_segentries, daddr_t addr)
    266       1.1   mycroft {
    267      1.19  perseant 	char *ipage;
    268  1.38.6.2      yamt 	struct ulfs1_dinode *dip, *dpage;
    269      1.20      fvdl 	/* XXX ondisk32 */
    270      1.20      fvdl 	int32_t *addrp, *dindir, *iaddrp, *indir;
    271       1.4       cgd 	int block_limit, i, inum, j, nblocks, psize;
    272       1.1   mycroft 
    273       1.1   mycroft 	psize = lfsp->lfs_bsize;
    274      1.14  perseant 	if (!addr)
    275      1.14  perseant 		addr = lfsp->lfs_idaddr;
    276       1.1   mycroft 
    277       1.1   mycroft 	if (!(dpage = malloc(psize)))
    278       1.2   mycroft 		err(1, "malloc");
    279      1.19  perseant 	get(fd, fsbtobyte(lfsp, addr), dpage, psize);
    280       1.1   mycroft 
    281  1.38.6.2      yamt 	for (dip = dpage + LFS_INOPB(lfsp) - 1; dip >= dpage; --dip)
    282       1.1   mycroft 		if (dip->di_inumber == LFS_IFILE_INUM)
    283       1.1   mycroft 			break;
    284       1.1   mycroft 
    285      1.35     joerg 	if (dip < dpage) {
    286      1.35     joerg 		warnx("unable to locate ifile inode at disk address 0x%llx",
    287      1.20      fvdl 		     (long long)addr);
    288      1.35     joerg 		return;
    289      1.35     joerg 	}
    290       1.1   mycroft 
    291       1.1   mycroft 	(void)printf("\nIFILE inode\n");
    292       1.1   mycroft 	dump_dinode(dip);
    293       1.1   mycroft 
    294       1.1   mycroft 	(void)printf("\nIFILE contents\n");
    295       1.1   mycroft 	nblocks = dip->di_size >> lfsp->lfs_bshift;
    296  1.38.6.2      yamt 	block_limit = MIN(nblocks, ULFS_NDADDR);
    297       1.1   mycroft 
    298       1.1   mycroft 	/* Get the direct block */
    299       1.1   mycroft 	if ((ipage = malloc(psize)) == NULL)
    300       1.2   mycroft 		err(1, "malloc");
    301       1.1   mycroft 	for (inum = 0, addrp = dip->di_db, i = 0; i < block_limit;
    302       1.1   mycroft 	    i++, addrp++) {
    303      1.19  perseant 		get(fd, fsbtobyte(lfsp, *addrp), ipage, psize);
    304       1.1   mycroft 		if (i < lfsp->lfs_cleansz) {
    305       1.1   mycroft 			dump_cleaner_info(lfsp, ipage);
    306      1.19  perseant 			if (do_segentries)
    307      1.19  perseant 				print_suheader;
    308       1.1   mycroft 			continue;
    309       1.1   mycroft 		}
    310       1.1   mycroft 
    311       1.1   mycroft 		if (i < (lfsp->lfs_segtabsz + lfsp->lfs_cleansz)) {
    312      1.19  perseant 			if (do_segentries)
    313      1.19  perseant 				inum = dump_ipage_segusage(lfsp, inum, ipage,
    314      1.19  perseant 							   lfsp->lfs_sepb);
    315      1.19  perseant 			else
    316      1.19  perseant 				inum = (i < lfsp->lfs_segtabsz + lfsp->lfs_cleansz - 1);
    317      1.10      ross 			if (!inum) {
    318       1.1   mycroft 				if(!do_ientries)
    319       1.1   mycroft 					goto e0;
    320       1.1   mycroft 				else
    321       1.1   mycroft 					print_iheader;
    322      1.10      ross 			}
    323       1.1   mycroft 		} else
    324      1.19  perseant 			inum = dump_ipage_ifile(lfsp, inum, ipage, lfsp->lfs_ifpb);
    325       1.1   mycroft 	}
    326       1.1   mycroft 
    327  1.38.6.2      yamt 	if (nblocks <= ULFS_NDADDR)
    328       1.1   mycroft 		goto e0;
    329       1.1   mycroft 
    330       1.1   mycroft 	/* Dump out blocks off of single indirect block */
    331       1.1   mycroft 	if (!(indir = malloc(psize)))
    332       1.2   mycroft 		err(1, "malloc");
    333      1.19  perseant 	get(fd, fsbtobyte(lfsp, dip->di_ib[0]), indir, psize);
    334       1.1   mycroft 	block_limit = MIN(i + lfsp->lfs_nindir, nblocks);
    335       1.1   mycroft 	for (addrp = indir; i < block_limit; i++, addrp++) {
    336       1.1   mycroft 		if (*addrp == LFS_UNUSED_DADDR)
    337       1.1   mycroft 			break;
    338      1.19  perseant 		get(fd, fsbtobyte(lfsp, *addrp), ipage, psize);
    339       1.1   mycroft 		if (i < lfsp->lfs_cleansz) {
    340       1.1   mycroft 			dump_cleaner_info(lfsp, ipage);
    341       1.1   mycroft 			continue;
    342      1.19  perseant 		}
    343       1.1   mycroft 
    344      1.19  perseant 		if (i < lfsp->lfs_segtabsz + lfsp->lfs_cleansz) {
    345      1.19  perseant 			if (do_segentries)
    346      1.19  perseant 				inum = dump_ipage_segusage(lfsp, inum, ipage,
    347      1.19  perseant 							   lfsp->lfs_sepb);
    348      1.19  perseant 			else
    349      1.19  perseant 				inum = (i < lfsp->lfs_segtabsz + lfsp->lfs_cleansz - 1);
    350      1.11   nathanw 			if (!inum) {
    351       1.1   mycroft 				if(!do_ientries)
    352       1.1   mycroft 					goto e1;
    353       1.1   mycroft 				else
    354       1.1   mycroft 					print_iheader;
    355      1.11   nathanw 			}
    356       1.1   mycroft 		} else
    357      1.19  perseant 			inum = dump_ipage_ifile(lfsp, inum, ipage, lfsp->lfs_ifpb);
    358       1.1   mycroft 	}
    359       1.1   mycroft 
    360       1.1   mycroft 	if (nblocks <= lfsp->lfs_nindir * lfsp->lfs_ifpb)
    361       1.1   mycroft 		goto e1;
    362       1.1   mycroft 
    363       1.1   mycroft 	/* Get the double indirect block */
    364       1.1   mycroft 	if (!(dindir = malloc(psize)))
    365       1.2   mycroft 		err(1, "malloc");
    366      1.19  perseant 	get(fd, fsbtobyte(lfsp, dip->di_ib[1]), dindir, psize);
    367       1.1   mycroft 	for (iaddrp = dindir, j = 0; j < lfsp->lfs_nindir; j++, iaddrp++) {
    368       1.1   mycroft 		if (*iaddrp == LFS_UNUSED_DADDR)
    369       1.1   mycroft 			break;
    370      1.19  perseant 		get(fd, fsbtobyte(lfsp, *iaddrp), indir, psize);
    371       1.1   mycroft 		block_limit = MIN(i + lfsp->lfs_nindir, nblocks);
    372       1.1   mycroft 		for (addrp = indir; i < block_limit; i++, addrp++) {
    373       1.1   mycroft 			if (*addrp == LFS_UNUSED_DADDR)
    374       1.1   mycroft 				break;
    375      1.19  perseant 			get(fd, fsbtobyte(lfsp, *addrp), ipage, psize);
    376       1.1   mycroft 			if (i < lfsp->lfs_cleansz) {
    377       1.1   mycroft 				dump_cleaner_info(lfsp, ipage);
    378       1.1   mycroft 				continue;
    379      1.19  perseant 			}
    380       1.1   mycroft 
    381      1.19  perseant 			if (i < lfsp->lfs_segtabsz + lfsp->lfs_cleansz) {
    382      1.19  perseant 				if (do_segentries)
    383      1.19  perseant 					inum = dump_ipage_segusage(lfsp,
    384      1.19  perseant 						 inum, ipage, lfsp->lfs_sepb);
    385      1.19  perseant 				else
    386      1.19  perseant 					inum = (i < lfsp->lfs_segtabsz +
    387      1.19  perseant 						lfsp->lfs_cleansz - 1);
    388      1.10      ross 				if (!inum) {
    389       1.1   mycroft 					if(!do_ientries)
    390       1.1   mycroft 						goto e2;
    391       1.1   mycroft 					else
    392       1.1   mycroft 						print_iheader;
    393      1.10      ross 				}
    394       1.1   mycroft 			} else
    395      1.19  perseant 				inum = dump_ipage_ifile(lfsp, inum,
    396       1.1   mycroft 				    ipage, lfsp->lfs_ifpb);
    397       1.1   mycroft 		}
    398       1.1   mycroft 	}
    399       1.1   mycroft e2:	free(dindir);
    400       1.1   mycroft e1:	free(indir);
    401       1.1   mycroft e0:	free(dpage);
    402       1.1   mycroft 	free(ipage);
    403       1.1   mycroft }
    404       1.1   mycroft 
    405       1.1   mycroft static int
    406      1.19  perseant dump_ipage_ifile(struct lfs *lfsp, int i, char *pp, int tot)
    407       1.1   mycroft {
    408      1.19  perseant 	char *ip;
    409      1.19  perseant 	int cnt, max, entsize;
    410       1.1   mycroft 
    411      1.19  perseant 	if (lfsp->lfs_version == 1)
    412      1.19  perseant 		entsize = sizeof(IFILE_V1);
    413      1.19  perseant 	else
    414      1.19  perseant 		entsize = sizeof(IFILE);
    415       1.1   mycroft 	max = i + tot;
    416       1.1   mycroft 
    417      1.19  perseant 	for (ip = pp, cnt = i; cnt < max; cnt++, ip += entsize)
    418      1.19  perseant 		print_ientry(cnt, (IFILE *)ip);
    419       1.1   mycroft 	return (max);
    420       1.1   mycroft }
    421       1.1   mycroft 
    422       1.1   mycroft static int
    423      1.19  perseant dump_ipage_segusage(struct lfs *lfsp, int i, char *pp, int tot)
    424       1.1   mycroft {
    425       1.1   mycroft 	SEGUSE *sp;
    426       1.1   mycroft 	int cnt, max;
    427      1.15  perseant 	struct seglist *slp;
    428       1.1   mycroft 
    429       1.1   mycroft 	max = i + tot;
    430       1.1   mycroft 	for (sp = (SEGUSE *)pp, cnt = i;
    431      1.19  perseant 	     cnt < lfsp->lfs_nseg && cnt < max; cnt++) {
    432      1.15  perseant 		if (seglist == NULL)
    433      1.19  perseant 			print_suentry(cnt, sp, lfsp);
    434      1.15  perseant 		else {
    435      1.15  perseant 			for (slp = seglist; slp != NULL; slp = slp->next)
    436      1.15  perseant 				if (cnt == slp->num) {
    437      1.19  perseant 					print_suentry(cnt, sp, lfsp);
    438      1.15  perseant 					break;
    439      1.15  perseant 				}
    440      1.15  perseant 		}
    441      1.19  perseant 		if (lfsp->lfs_version > 1)
    442      1.19  perseant 			++sp;
    443      1.19  perseant 		else
    444      1.19  perseant 			sp = (SEGUSE *)((SEGUSE_V1 *)sp + 1);
    445      1.15  perseant 	}
    446       1.1   mycroft 	if (max >= lfsp->lfs_nseg)
    447       1.1   mycroft 		return (0);
    448       1.1   mycroft 	else
    449       1.1   mycroft 		return (max);
    450       1.1   mycroft }
    451       1.1   mycroft 
    452       1.1   mycroft static void
    453  1.38.6.2      yamt dump_dinode(struct ulfs1_dinode *dip)
    454       1.1   mycroft {
    455       1.1   mycroft 	int i;
    456       1.7   thorpej 	time_t at, mt, ct;
    457       1.7   thorpej 
    458       1.7   thorpej 	at = dip->di_atime;
    459       1.7   thorpej 	mt = dip->di_mtime;
    460       1.7   thorpej 	ct = dip->di_ctime;
    461       1.1   mycroft 
    462      1.19  perseant 	(void)printf("    %so%o\t%s%d\t%s%d\t%s%d\t%s%llu\n",
    463       1.1   mycroft 		"mode  ", dip->di_mode,
    464       1.1   mycroft 		"nlink ", dip->di_nlink,
    465       1.1   mycroft 		"uid   ", dip->di_uid,
    466       1.1   mycroft 		"gid   ", dip->di_gid,
    467       1.9   thorpej 		"size  ", (long long)dip->di_size);
    468      1.19  perseant 	(void)printf("    %s%s    %s%s    %s%s",
    469       1.7   thorpej 		"atime ", ctime(&at),
    470       1.7   thorpej 		"mtime ", ctime(&mt),
    471       1.7   thorpej 		"ctime ", ctime(&ct));
    472      1.19  perseant 	(void)printf("    inum  %d\n", dip->di_inumber);
    473      1.19  perseant 	(void)printf("    Direct Addresses\n");
    474  1.38.6.2      yamt 	for (i = 0; i < ULFS_NDADDR; i++) {
    475      1.14  perseant 		(void)printf("\t0x%x", dip->di_db[i]);
    476       1.1   mycroft 		if ((i % 6) == 5)
    477       1.1   mycroft 			(void)printf("\n");
    478       1.1   mycroft 	}
    479  1.38.6.2      yamt 	for (i = 0; i < ULFS_NIADDR; i++)
    480      1.14  perseant 		(void)printf("\t0x%x", dip->di_ib[i]);
    481       1.1   mycroft 	(void)printf("\n");
    482       1.1   mycroft }
    483       1.1   mycroft 
    484       1.1   mycroft static int
    485      1.19  perseant dump_sum(int fd, struct lfs *lfsp, SEGSUM *sp, int segnum, daddr_t addr)
    486       1.1   mycroft {
    487       1.1   mycroft 	FINFO *fp;
    488      1.25  perseant 	int32_t *dp, *idp;
    489      1.25  perseant 	int i, j, acc;
    490       1.1   mycroft 	int ck;
    491      1.25  perseant 	int numbytes, numblocks;
    492      1.25  perseant 	char *datap;
    493  1.38.6.2      yamt 	struct ulfs1_dinode *inop;
    494      1.25  perseant 	size_t el_size;
    495      1.25  perseant 	u_int32_t datasum;
    496      1.31  perseant 	time_t t;
    497      1.25  perseant 	char *buf;
    498       1.1   mycroft 
    499       1.8      fvdl 	if (sp->ss_magic != SS_MAGIC ||
    500       1.8      fvdl 	    sp->ss_sumsum != (ck = cksum(&sp->ss_datasum,
    501      1.19  perseant 	    lfsp->lfs_sumsize - sizeof(sp->ss_sumsum)))) {
    502      1.14  perseant 		/* Don't print "corrupt" if we're just too close to the edge */
    503  1.38.6.2      yamt 		if (lfs_dtosn(lfsp, addr + LFS_FSBTODB(lfsp, 1)) ==
    504  1.38.6.2      yamt 		    lfs_dtosn(lfsp, addr))
    505      1.20      fvdl 			(void)printf("dumplfs: %s %d address 0x%llx\n",
    506      1.14  perseant 		                     "corrupt summary block; segment", segnum,
    507      1.20      fvdl 				     (long long)addr);
    508      1.34  perseant 		return -1;
    509      1.19  perseant 	}
    510      1.19  perseant 	if (lfsp->lfs_version > 1 && sp->ss_ident != lfsp->lfs_ident) {
    511      1.20      fvdl 		(void)printf("dumplfs: %s %d address 0x%llx\n",
    512      1.19  perseant 	                     "summary from a former life; segment", segnum,
    513      1.21       mrg 			     (long long)addr);
    514      1.34  perseant 		return -1;
    515       1.1   mycroft 	}
    516       1.1   mycroft 
    517      1.20      fvdl 	(void)printf("Segment Summary Info at 0x%llx\n", (long long)addr);
    518      1.34  perseant 	(void)printf("    %s0x%x\t%s%d\t%s%d\t%s%c%c%c%c\n    %s0x%x\t%s0x%x",
    519       1.1   mycroft 		"next     ", sp->ss_next,
    520       1.1   mycroft 		"nfinfo   ", sp->ss_nfinfo,
    521       1.1   mycroft 		"ninos    ", sp->ss_ninos,
    522      1.14  perseant 		"flags    ", (sp->ss_flags & SS_DIROP) ? 'D' : '-',
    523      1.14  perseant 			     (sp->ss_flags & SS_CONT)  ? 'C' : '-',
    524      1.33  perseant 			     (sp->ss_flags & SS_CLEAN)  ? 'L' : '-',
    525      1.34  perseant 			     (sp->ss_flags & SS_RFW)  ? 'R' : '-',
    526       1.1   mycroft 		"sumsum   ", sp->ss_sumsum,
    527       1.1   mycroft 		"datasum  ", sp->ss_datasum );
    528      1.31  perseant 	if (lfsp->lfs_version == 1) {
    529      1.32  perseant 		t = sp->ss_ocreate;
    530      1.31  perseant 		(void)printf("\tcreate   %s\n", ctime(&t));
    531      1.31  perseant 	} else {
    532      1.32  perseant 		t = sp->ss_create;
    533      1.31  perseant 		(void)printf("\tcreate   %s", ctime(&t));
    534      1.19  perseant 		(void)printf("    roll_id  %-8x", sp->ss_ident);
    535      1.19  perseant 		(void)printf("   serial   %lld\n", (long long)sp->ss_serial);
    536      1.19  perseant 	}
    537       1.1   mycroft 
    538       1.1   mycroft 	/* Dump out inode disk addresses */
    539      1.20      fvdl 	dp = (int32_t *)sp;
    540      1.20      fvdl 	dp += lfsp->lfs_sumsize / sizeof(int32_t);
    541      1.19  perseant 	inop = malloc(lfsp->lfs_bsize);
    542       1.1   mycroft 	printf("    Inode addresses:");
    543       1.8      fvdl 	numbytes = 0;
    544      1.25  perseant 	numblocks = 0;
    545       1.1   mycroft 	for (dp--, i = 0; i < sp->ss_ninos; dp--) {
    546      1.25  perseant 		++numblocks;
    547      1.19  perseant 		numbytes += lfsp->lfs_ibsize;	/* add bytes for inode block */
    548      1.14  perseant 		printf("\t0x%x {", *dp);
    549      1.19  perseant 		get(fd, fsbtobyte(lfsp, *dp), inop, lfsp->lfs_ibsize);
    550  1.38.6.2      yamt 		for (j = 0; i < sp->ss_ninos && j < LFS_INOPB(lfsp); j++, i++) {
    551       1.1   mycroft 			if (j > 0)
    552       1.1   mycroft 				(void)printf(", ");
    553      1.19  perseant 			(void)printf("%dv%d", inop[j].di_inumber, inop[j].di_gen);
    554       1.1   mycroft 		}
    555       1.1   mycroft 		(void)printf("}");
    556  1.38.6.2      yamt 		if (((i/LFS_INOPB(lfsp)) % 4) == 3)
    557       1.1   mycroft 			(void)printf("\n");
    558       1.1   mycroft 	}
    559       1.1   mycroft 	free(inop);
    560       1.1   mycroft 
    561       1.1   mycroft 	printf("\n");
    562      1.25  perseant 
    563      1.19  perseant 	if (lfsp->lfs_version == 1)
    564      1.19  perseant 		fp = (FINFO *)((SEGSUM_V1 *)sp + 1);
    565      1.19  perseant 	else
    566      1.19  perseant 		fp = (FINFO *)(sp + 1);
    567      1.19  perseant 	for (i = 0; i < sp->ss_nfinfo; i++) {
    568       1.8      fvdl 		(void)printf("    FINFO for inode: %d version %d nblocks %d lastlength %d\n",
    569       1.8      fvdl 		    fp->fi_ino, fp->fi_version, fp->fi_nblocks,
    570       1.8      fvdl 		    fp->fi_lastlength);
    571       1.1   mycroft 		dp = &(fp->fi_blocks[0]);
    572      1.25  perseant 		numblocks += fp->fi_nblocks;
    573       1.1   mycroft 		for (j = 0; j < fp->fi_nblocks; j++, dp++) {
    574       1.1   mycroft 			(void)printf("\t%d", *dp);
    575       1.1   mycroft 			if ((j % 8) == 7)
    576       1.1   mycroft 				(void)printf("\n");
    577       1.8      fvdl 			if (j == fp->fi_nblocks - 1)
    578       1.8      fvdl 				numbytes += fp->fi_lastlength;
    579       1.8      fvdl 			else
    580       1.8      fvdl 				numbytes += lfsp->lfs_bsize;
    581       1.1   mycroft 		}
    582       1.1   mycroft 		if ((j % 8) != 0)
    583       1.1   mycroft 			(void)printf("\n");
    584       1.1   mycroft 		fp = (FINFO *)dp;
    585       1.1   mycroft 	}
    586      1.25  perseant 
    587      1.25  perseant 	if (datasum_check == 0)
    588      1.25  perseant 		return (numbytes);
    589      1.25  perseant 
    590      1.25  perseant 	/*
    591      1.25  perseant 	 * Now that we know the number of blocks, run back through and
    592      1.25  perseant 	 * compute the data checksum.  (A bad data checksum is not enough
    593      1.25  perseant 	 * to prevent us from continuing, but it odes merit a warning.)
    594      1.25  perseant 	 */
    595      1.25  perseant 	idp = (int32_t *)sp;
    596      1.25  perseant 	idp += lfsp->lfs_sumsize / sizeof(int32_t);
    597      1.25  perseant 	--idp;
    598      1.25  perseant 	if (lfsp->lfs_version == 1) {
    599      1.25  perseant 		fp = (FINFO *)((SEGSUM_V1 *)sp + 1);
    600      1.25  perseant 		el_size = sizeof(unsigned long);
    601      1.25  perseant 	} else {
    602      1.25  perseant 		fp = (FINFO *)(sp + 1);
    603      1.25  perseant 		el_size = sizeof(u_int32_t);
    604      1.25  perseant 	}
    605      1.25  perseant 	datap = (char *)malloc(el_size * numblocks);
    606      1.25  perseant 	memset(datap, 0, el_size * numblocks);
    607      1.25  perseant 	acc = 0;
    608  1.38.6.2      yamt 	addr += lfs_btofsb(lfsp, lfsp->lfs_sumsize);
    609      1.25  perseant 	buf = malloc(lfsp->lfs_bsize);
    610      1.25  perseant 	for (i = 0; i < sp->ss_nfinfo; i++) {
    611      1.25  perseant 		while (addr == *idp) {
    612      1.25  perseant 			get(fd, fsbtobyte(lfsp, addr), buf, lfsp->lfs_ibsize);
    613      1.25  perseant 			memcpy(datap + acc * el_size, buf, el_size);
    614  1.38.6.2      yamt 			addr += lfs_btofsb(lfsp, lfsp->lfs_ibsize);
    615      1.25  perseant 			--idp;
    616      1.25  perseant 			++acc;
    617      1.25  perseant 		}
    618      1.25  perseant 		for (j = 0; j < fp->fi_nblocks; j++) {
    619      1.25  perseant 			get(fd, fsbtobyte(lfsp, addr), buf, lfsp->lfs_fsize);
    620      1.25  perseant 			memcpy(datap + acc * el_size, buf, el_size);
    621      1.25  perseant 			if (j == fp->fi_nblocks - 1)
    622  1.38.6.2      yamt 				addr += lfs_btofsb(lfsp, fp->fi_lastlength);
    623      1.25  perseant 			else
    624  1.38.6.2      yamt 				addr += lfs_btofsb(lfsp, lfsp->lfs_bsize);
    625      1.25  perseant 			++acc;
    626      1.25  perseant 		}
    627      1.25  perseant 		fp = (FINFO *)&(fp->fi_blocks[fp->fi_nblocks]);
    628      1.25  perseant 	}
    629      1.25  perseant 	while (addr == *idp) {
    630      1.25  perseant 		get(fd, fsbtobyte(lfsp, addr), buf, lfsp->lfs_ibsize);
    631      1.25  perseant 		memcpy(datap + acc * el_size, buf, el_size);
    632  1.38.6.2      yamt 		addr += lfs_btofsb(lfsp, lfsp->lfs_ibsize);
    633      1.25  perseant 		--idp;
    634      1.25  perseant 		++acc;
    635      1.25  perseant 	}
    636      1.25  perseant 	free(buf);
    637      1.25  perseant 	if (acc != numblocks)
    638      1.25  perseant 		printf("** counted %d blocks but should have been %d\n",
    639      1.25  perseant 		     acc, numblocks);
    640      1.25  perseant 	datasum = cksum(datap, numblocks * el_size);
    641      1.25  perseant 	if (datasum != sp->ss_datasum)
    642      1.25  perseant 		printf("** computed datasum 0x%lx does not match given datasum 0x%lx\n", (unsigned long)datasum, (unsigned long)sp->ss_datasum);
    643      1.25  perseant 	free(datap);
    644      1.25  perseant 
    645       1.8      fvdl 	return (numbytes);
    646       1.1   mycroft }
    647       1.1   mycroft 
    648       1.1   mycroft static void
    649      1.19  perseant dump_segment(int fd, int segnum, daddr_t addr, struct lfs *lfsp, int dump_sb)
    650       1.1   mycroft {
    651       1.1   mycroft 	struct lfs lfs_sb, *sbp;
    652       1.1   mycroft 	SEGSUM *sump;
    653      1.19  perseant 	char *sumblock;
    654       1.8      fvdl 	int did_one, nbytes, sb;
    655      1.14  perseant 	off_t sum_offset;
    656      1.14  perseant 	daddr_t new_addr;
    657       1.1   mycroft 
    658      1.20      fvdl 	(void)printf("\nSEGMENT %lld (Disk Address 0x%llx)\n",
    659  1.38.6.2      yamt 		     (long long)lfs_dtosn(lfsp, addr), (long long)addr);
    660      1.19  perseant 	sum_offset = fsbtobyte(lfsp, addr);
    661      1.19  perseant 	sumblock = malloc(lfsp->lfs_sumsize);
    662      1.19  perseant 
    663      1.19  perseant 	if (lfsp->lfs_version > 1 && segnum == 0) {
    664  1.38.6.2      yamt 		if (lfs_fsbtob(lfsp, lfsp->lfs_start) < LFS_LABELPAD) {
    665      1.24  perseant 			/* First segment eats the disklabel */
    666  1.38.6.2      yamt 			sum_offset += lfs_fragroundup(lfsp, LFS_LABELPAD) -
    667  1.38.6.2      yamt 				      lfs_fsbtob(lfsp, lfsp->lfs_start);
    668  1.38.6.2      yamt 			addr += lfs_btofsb(lfsp, lfs_fragroundup(lfsp, LFS_LABELPAD)) -
    669      1.24  perseant 				lfsp->lfs_start;
    670      1.24  perseant 			printf("Disklabel at 0x0\n");
    671      1.24  perseant 		}
    672      1.19  perseant 	}
    673       1.1   mycroft 
    674       1.1   mycroft 	sb = 0;
    675       1.1   mycroft 	did_one = 0;
    676       1.1   mycroft 	do {
    677      1.19  perseant 		get(fd, sum_offset, sumblock, lfsp->lfs_sumsize);
    678       1.1   mycroft 		sump = (SEGSUM *)sumblock;
    679      1.19  perseant 		if ((lfsp->lfs_version > 1 &&
    680      1.19  perseant 		     sump->ss_ident != lfsp->lfs_ident) ||
    681      1.19  perseant 		    sump->ss_sumsum != cksum (&sump->ss_datasum,
    682      1.19  perseant 			      lfsp->lfs_sumsize - sizeof(sump->ss_sumsum))) {
    683       1.1   mycroft 			sbp = (struct lfs *)sump;
    684       1.8      fvdl 			if ((sb = (sbp->lfs_magic == LFS_MAGIC))) {
    685      1.19  perseant 				printf("Superblock at 0x%x\n",
    686  1.38.6.2      yamt 				       (unsigned)lfs_btofsb(lfsp, sum_offset));
    687      1.14  perseant 				if (dump_sb)  {
    688      1.14  perseant 					get(fd, sum_offset, &(lfs_sb.lfs_dlfs),
    689      1.14  perseant 					    sizeof(struct dlfs));
    690      1.14  perseant 					dump_super(&lfs_sb);
    691      1.14  perseant 				}
    692      1.19  perseant 				if (lfsp->lfs_version > 1)
    693  1.38.6.2      yamt 					sum_offset += lfs_fragroundup(lfsp, LFS_SBPAD);
    694      1.19  perseant 				else
    695      1.19  perseant 					sum_offset += LFS_SBPAD;
    696       1.1   mycroft 			} else if (did_one)
    697       1.1   mycroft 				break;
    698       1.1   mycroft 			else {
    699      1.20      fvdl 				printf("Segment at 0x%llx empty or corrupt\n",
    700      1.20      fvdl                                        (long long)addr);
    701       1.1   mycroft 				break;
    702       1.1   mycroft 			}
    703       1.1   mycroft 		} else {
    704      1.19  perseant 			nbytes = dump_sum(fd, lfsp, sump, segnum,
    705  1.38.6.2      yamt 				lfs_btofsb(lfsp, sum_offset));
    706      1.34  perseant 			if (nbytes >= 0)
    707      1.19  perseant 				sum_offset += lfsp->lfs_sumsize + nbytes;
    708       1.1   mycroft 			else
    709       1.1   mycroft 				sum_offset = 0;
    710       1.1   mycroft 			did_one = 1;
    711       1.1   mycroft 		}
    712      1.14  perseant 		/* If the segment ends right on a boundary, it still ends */
    713  1.38.6.2      yamt 		new_addr = lfs_btofsb(lfsp, sum_offset);
    714      1.19  perseant 		/* printf("end daddr = 0x%lx\n", (long)new_addr); */
    715  1.38.6.2      yamt 		if (lfs_dtosn(lfsp, new_addr) != lfs_dtosn(lfsp, addr))
    716      1.14  perseant 			break;
    717       1.1   mycroft 	} while (sum_offset);
    718       1.1   mycroft 
    719      1.30       dsl 	free(sumblock);
    720       1.1   mycroft }
    721       1.1   mycroft 
    722       1.1   mycroft static void
    723      1.19  perseant dump_super(struct lfs *lfsp)
    724       1.1   mycroft {
    725       1.1   mycroft 	int i;
    726       1.1   mycroft 
    727      1.19  perseant  	(void)printf("    %s0x%-8x  %s0x%-8x  %s%-10d\n",
    728      1.19  perseant  		     "magic    ", lfsp->lfs_magic,
    729      1.19  perseant  		     "version  ", lfsp->lfs_version,
    730      1.19  perseant  		     "size     ", lfsp->lfs_size);
    731      1.19  perseant  	(void)printf("    %s%-10d  %s%-10d  %s%-10d\n",
    732      1.19  perseant  		     "ssize    ", lfsp->lfs_ssize,
    733      1.19  perseant  		     "dsize    ", lfsp->lfs_dsize,
    734      1.19  perseant  		     "bsize    ", lfsp->lfs_bsize);
    735      1.19  perseant  	(void)printf("    %s%-10d  %s%-10d  %s%-10d\n",
    736      1.19  perseant  		     "fsize    ", lfsp->lfs_fsize,
    737      1.19  perseant  		     "frag     ", lfsp->lfs_frag,
    738      1.19  perseant  		     "minfree  ", lfsp->lfs_minfree);
    739      1.19  perseant  	(void)printf("    %s%-10d  %s%-10d  %s%-10d\n",
    740      1.19  perseant  		     "inopb    ", lfsp->lfs_inopb,
    741      1.19  perseant  		     "ifpb     ", lfsp->lfs_ifpb,
    742      1.19  perseant  		     "nindir   ", lfsp->lfs_nindir);
    743      1.19  perseant  	(void)printf("    %s%-10d  %s%-10d  %s%-10d\n",
    744      1.19  perseant  		     "nseg     ", lfsp->lfs_nseg,
    745      1.19  perseant  		     "sepb     ", lfsp->lfs_sepb,
    746      1.19  perseant  		     "cleansz  ", lfsp->lfs_cleansz);
    747      1.19  perseant  	(void)printf("    %s%-10d  %s0x%-8x  %s%-10d\n",
    748      1.19  perseant  		     "segtabsz ", lfsp->lfs_segtabsz,
    749      1.19  perseant  		     "segmask  ", lfsp->lfs_segmask,
    750      1.19  perseant  		     "segshift ", lfsp->lfs_segshift);
    751      1.19  perseant  	(void)printf("    %s0x%-8qx  %s%-10d  %s0x%-8qX\n",
    752      1.19  perseant  		     "bmask    ", (long long)lfsp->lfs_bmask,
    753      1.19  perseant  		     "bshift   ", lfsp->lfs_bshift,
    754      1.19  perseant  		     "ffmask   ", (long long)lfsp->lfs_ffmask);
    755      1.19  perseant  	(void)printf("    %s%-10d  %s0x%-8qx  %s%u\n",
    756      1.19  perseant  		     "ffshift  ", lfsp->lfs_ffshift,
    757      1.19  perseant  		     "fbmask   ", (long long)lfsp->lfs_fbmask,
    758      1.19  perseant  		     "fbshift  ", lfsp->lfs_fbshift);
    759      1.19  perseant 
    760      1.19  perseant  	(void)printf("    %s%-10d  %s%-10d  %s0x%-8x\n",
    761      1.19  perseant  		     "sushift  ", lfsp->lfs_sushift,
    762      1.19  perseant  		     "fsbtodb  ", lfsp->lfs_fsbtodb,
    763      1.19  perseant  		     "cksum    ", lfsp->lfs_cksum);
    764      1.19  perseant  	(void)printf("    %s%-10d  %s%-10d  %s%-10d\n",
    765      1.19  perseant  		     "nclean   ", lfsp->lfs_nclean,
    766      1.19  perseant  		     "dmeta    ", lfsp->lfs_dmeta,
    767      1.19  perseant  		     "minfreeseg ", lfsp->lfs_minfreeseg);
    768      1.19  perseant  	(void)printf("    %s0x%-8x  %s%-9d %s%-10d\n",
    769      1.19  perseant  		     "roll_id  ", lfsp->lfs_ident,
    770      1.19  perseant  		     "interleave ", lfsp->lfs_interleave,
    771      1.19  perseant  		     "sumsize  ", lfsp->lfs_sumsize);
    772      1.23    simonb  	(void)printf("    %s%-10d  %s0x%-8qx\n",
    773      1.23    simonb 		     "seg0addr ", lfsp->lfs_start,
    774      1.19  perseant  		     "maxfilesize  ", (long long)lfsp->lfs_maxfilesize);
    775      1.19  perseant 
    776      1.19  perseant 
    777      1.19  perseant  	(void)printf("  Superblock disk addresses:\n    ");
    778      1.19  perseant   	for (i = 0; i < LFS_MAXNUMSB; i++) {
    779      1.19  perseant  		(void)printf(" 0x%-8x", lfsp->lfs_sboffs[i]);
    780      1.19  perseant  		if (i == (LFS_MAXNUMSB >> 1))
    781      1.19  perseant  			(void)printf("\n    ");
    782      1.19  perseant   	}
    783      1.19  perseant   	(void)printf("\n");
    784      1.19  perseant 
    785      1.19  perseant  	(void)printf("  Checkpoint Info\n");
    786      1.19  perseant  	(void)printf("    %s%-10d  %s0x%-8x  %s%-10d\n",
    787      1.22  perseant  		     "freehd   ", lfsp->lfs_freehd,
    788      1.19  perseant  		     "idaddr   ", lfsp->lfs_idaddr,
    789      1.19  perseant  		     "ifile    ", lfsp->lfs_ifile);
    790      1.19  perseant  	(void)printf("    %s%-10d  %s%-10d  %s%-10d\n",
    791      1.19  perseant  		     "uinodes  ", lfsp->lfs_uinodes,
    792      1.19  perseant  		     "bfree    ", lfsp->lfs_bfree,
    793      1.19  perseant  		     "avail    ", lfsp->lfs_avail);
    794      1.19  perseant  	(void)printf("    %s%-10d  %s0x%-8x  %s0x%-8x\n",
    795      1.19  perseant  		     "nfiles   ", lfsp->lfs_nfiles,
    796      1.19  perseant  		     "lastseg  ", lfsp->lfs_lastseg,
    797      1.19  perseant  		     "nextseg  ", lfsp->lfs_nextseg);
    798      1.19  perseant  	(void)printf("    %s0x%-8x  %s0x%-8x  %s%-10lld\n",
    799      1.19  perseant  		     "curseg   ", lfsp->lfs_curseg,
    800      1.19  perseant  		     "offset   ", lfsp->lfs_offset,
    801      1.19  perseant 		     "serial   ", (long long)lfsp->lfs_serial);
    802      1.19  perseant  	(void)printf("    tstamp   %s", ctime((time_t *)&lfsp->lfs_tstamp));
    803       1.1   mycroft }
    804       1.1   mycroft 
    805       1.1   mycroft static void
    806      1.19  perseant addseg(char *arg)
    807       1.1   mycroft {
    808       1.1   mycroft 	SEGLIST *p;
    809       1.1   mycroft 
    810       1.1   mycroft 	if ((p = malloc(sizeof(SEGLIST))) == NULL)
    811       1.2   mycroft 		err(1, "malloc");
    812       1.1   mycroft 	p->next = seglist;
    813       1.1   mycroft 	p->num = atoi(arg);
    814       1.1   mycroft 	seglist = p;
    815       1.1   mycroft }
    816       1.1   mycroft 
    817       1.1   mycroft static void
    818      1.19  perseant dump_cleaner_info(struct lfs *lfsp, void *ipage)
    819       1.1   mycroft {
    820       1.1   mycroft 	CLEANERINFO *cip;
    821       1.1   mycroft 
    822       1.1   mycroft 	cip = (CLEANERINFO *)ipage;
    823      1.19  perseant 	if (lfsp->lfs_version > 1) {
    824      1.19  perseant 		(void)printf("free_head %d\n", cip->free_head);
    825      1.19  perseant 		(void)printf("free_tail %d\n", cip->free_tail);
    826      1.19  perseant 	}
    827      1.17  perseant 	(void)printf("clean\t%d\tdirty\t%d\n",
    828      1.17  perseant 		     cip->clean, cip->dirty);
    829      1.17  perseant 	(void)printf("bfree\t%d\tavail\t%d\n\n",
    830      1.17  perseant 		     cip->bfree, cip->avail);
    831       1.1   mycroft }
    832       1.1   mycroft 
    833       1.1   mycroft static void
    834      1.19  perseant usage(void)
    835       1.1   mycroft {
    836      1.27       wiz 	(void)fprintf(stderr, "usage: dumplfs [-adiS] [-b blkno] [-I blkno] [-s segno] filesys|device\n");
    837       1.1   mycroft 	exit(1);
    838       1.1   mycroft }
    839