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