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