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