151144Sbostic /*- 261488Sbostic * Copyright (c) 1991, 1993 361488Sbostic * The Regents of the University of California. All rights reserved. 451144Sbostic * 551144Sbostic * %sccs.include.redist.c% 651144Sbostic */ 751144Sbostic 851144Sbostic #ifndef lint 961488Sbostic static char copyright[] = 1061488Sbostic "@(#) Copyright (c) 1991, 1993\n\ 1161488Sbostic The Regents of the University of California. All rights reserved.\n"; 1251144Sbostic #endif /* not lint */ 1351144Sbostic 1451144Sbostic #ifndef lint 15*68988Sbostic static char sccsid[] = "@(#)dumplfs.c 8.3 (Berkeley) 04/28/95"; 1651144Sbostic #endif /* not lint */ 1751144Sbostic 1851144Sbostic #include <sys/param.h> 1951867Sbostic #include <sys/ucred.h> 2051144Sbostic #include <sys/mount.h> 2154714Sbostic #include <sys/time.h> 2251862Sbostic 2351862Sbostic #include <ufs/ufs/dinode.h> 2451862Sbostic #include <ufs/lfs/lfs.h> 2551862Sbostic 26*68988Sbostic #include <err.h> 27*68988Sbostic #include <errno.h> 2854714Sbostic #include <fcntl.h> 2951144Sbostic #include <fstab.h> 30*68988Sbostic #include <stdio.h> 3151144Sbostic #include <stdlib.h> 3251144Sbostic #include <string.h> 33*68988Sbostic #include <unistd.h> 3451144Sbostic #include "extern.h" 3551144Sbostic 3651861Sbostic static void addseg __P((char *)); 3751862Sbostic static void dump_cleaner_info __P((struct lfs *, void *)); 3851144Sbostic static void dump_dinode __P((struct dinode *)); 3951862Sbostic static void dump_ifile __P((int, struct lfs *, int)); 4051144Sbostic static int dump_ipage_ifile __P((int, IFILE *, int)); 4151862Sbostic static int dump_ipage_segusage __P((struct lfs *, int, IFILE *, int)); 4251862Sbostic static void dump_segment __P((int, int, daddr_t, struct lfs *, int)); 4352464Sstaelin static int dump_sum __P((int, struct lfs *, SEGSUM *, int, daddr_t)); 4451862Sbostic static void dump_super __P((struct lfs *)); 4551144Sbostic static void usage __P((void)); 4651144Sbostic 4751861Sbostic typedef struct seglist SEGLIST; 4851861Sbostic struct seglist { 4951861Sbostic SEGLIST *next; 5051861Sbostic int num; 5151861Sbostic }; 5251861Sbostic SEGLIST *seglist; 5351861Sbostic 5451861Sbostic int daddr_shift; 5551144Sbostic char *special; 5651144Sbostic 5751144Sbostic /* Segment Usage formats */ 5851144Sbostic #define print_suheader \ 5955597Sbostic (void)printf("segnum\tflags\tnbytes\tninos\tnsums\tlastmod\n") 6051929Sbostic 6151144Sbostic #define print_suentry(i, sp) \ 6255597Sbostic (void)printf("%d\t%c%c%c\t%d\t%d\t%d\t%s", i, \ 6351929Sbostic (((sp)->su_flags & SEGUSE_ACTIVE) ? 'A' : ' '), \ 6451929Sbostic (((sp)->su_flags & SEGUSE_DIRTY) ? 'D' : 'C'), \ 6551929Sbostic (((sp)->su_flags & SEGUSE_SUPERBLOCK) ? 'S' : ' '), \ 6655597Sbostic (sp)->su_nbytes, (sp)->su_ninos, (sp)->su_nsums, \ 6755597Sbostic ctime((time_t *)&(sp)->su_lastmod)) 6851144Sbostic 6951144Sbostic /* Ifile formats */ 7051144Sbostic #define print_iheader \ 7152094Sbostic (void)printf("inum\tstatus\tversion\tdaddr\t\tfreeptr\n") 7251144Sbostic #define print_ientry(i, ip) \ 7351144Sbostic if (ip->if_daddr == LFS_UNUSED_DADDR) \ 7452094Sbostic (void)printf("%d\tFREE\t%d\t \t\t%d\n", \ 7551144Sbostic i, ip->if_version, ip->if_nextfree); \ 7651144Sbostic else \ 7752094Sbostic (void)printf("%d\tINUSE\t%d\t%8X \n", \ 7852094Sbostic i, ip->if_version, ip->if_daddr) 7951144Sbostic int 8051862Sbostic main(argc, argv) 8151144Sbostic int argc; 8251144Sbostic char *argv[]; 8351144Sbostic { 8451862Sbostic struct lfs lfs_sb1, lfs_sb2, *lfs_master; 8551861Sbostic daddr_t seg_addr; 8651861Sbostic int ch, do_allsb, do_ientries, fd, segnum; 8751144Sbostic 8851144Sbostic do_allsb = 0; 8951144Sbostic do_ientries = 0; 90*68988Sbostic while ((ch = getopt(argc, argv, "ais:")) != -1) 9151144Sbostic switch(ch) { 9251861Sbostic case 'a': /* Dump all superblocks */ 9351861Sbostic do_allsb = 1; 9451861Sbostic break; 9551144Sbostic case 'i': /* Dump ifile entries */ 9651144Sbostic do_ientries = 1; 9751144Sbostic break; 9851861Sbostic case 's': /* Dump out these segments */ 9951861Sbostic addseg(optarg); 10051144Sbostic break; 10151144Sbostic default: 10251144Sbostic usage(); 10351144Sbostic } 10451144Sbostic argc -= optind; 10551144Sbostic argv += optind; 10651144Sbostic 10751144Sbostic if (argc != 1) 10851144Sbostic usage(); 10951144Sbostic 11051144Sbostic special = argv[0]; 11151144Sbostic if ((fd = open(special, O_RDONLY, 0)) < 0) 112*68988Sbostic err(1, "%s", special); 11351144Sbostic 11451144Sbostic /* Read the first superblock */ 11551862Sbostic get(fd, LFS_LABELPAD, &lfs_sb1, sizeof(struct lfs)); 11651144Sbostic daddr_shift = lfs_sb1.lfs_bshift - lfs_sb1.lfs_fsbtodb; 11751144Sbostic 11851144Sbostic /* 11951144Sbostic * Read the second superblock and figure out which check point is 12051144Sbostic * most up to date. 12151144Sbostic */ 12251862Sbostic get(fd, 12351862Sbostic lfs_sb1.lfs_sboffs[1] << daddr_shift, &lfs_sb2, sizeof(struct lfs)); 12451861Sbostic 12551144Sbostic lfs_master = &lfs_sb1; 12651144Sbostic if (lfs_sb1.lfs_tstamp < lfs_sb2.lfs_tstamp) 12751144Sbostic lfs_master = &lfs_sb2; 12851144Sbostic 12951144Sbostic (void)printf("Master Superblock:\n"); 13051144Sbostic dump_super(lfs_master); 13151144Sbostic 13251144Sbostic dump_ifile(fd, lfs_master, do_ientries); 13351144Sbostic 13451861Sbostic if (seglist != NULL) 13551861Sbostic for (; seglist != NULL; seglist = seglist->next) { 13651861Sbostic seg_addr = lfs_master->lfs_sboffs[0] + seglist->num * 13751861Sbostic (lfs_master->lfs_ssize << lfs_master->lfs_fsbtodb); 13851861Sbostic dump_segment(fd, 13951861Sbostic seglist->num, seg_addr, lfs_master, do_allsb); 14051861Sbostic } 14151861Sbostic else 14251861Sbostic for (segnum = 0, seg_addr = lfs_master->lfs_sboffs[0]; 14351861Sbostic segnum < lfs_master->lfs_nseg; segnum++, seg_addr += 14451861Sbostic lfs_master->lfs_ssize << lfs_master->lfs_fsbtodb) 14551861Sbostic dump_segment(fd, 14651861Sbostic segnum, seg_addr, lfs_master, do_allsb); 14751861Sbostic 14851144Sbostic (void)close(fd); 14951144Sbostic exit(0); 15051144Sbostic } 15151144Sbostic 15251144Sbostic /* 15351144Sbostic * We are reading all the blocks of an inode and dumping out the ifile table. 15451862Sbostic * This code could be tighter, but this is a first pass at getting the stuff 15551144Sbostic * printed out rather than making this code incredibly efficient. 15651144Sbostic */ 15751144Sbostic static void 15851144Sbostic dump_ifile(fd, lfsp, do_ientries) 15951144Sbostic int fd; 16051862Sbostic struct lfs *lfsp; 16151144Sbostic int do_ientries; 16251144Sbostic { 16351144Sbostic IFILE *ipage; 16451144Sbostic struct dinode *dip, *dpage; 16551862Sbostic daddr_t addr, *addrp, *dindir, *iaddrp, *indir; 16651862Sbostic int block_limit, i, inum, j, nblocks, nsupb, psize; 16751144Sbostic 16851144Sbostic psize = lfsp->lfs_bsize; 16951144Sbostic addr = lfsp->lfs_idaddr; 17051144Sbostic 17156032Sbostic if (!(dpage = malloc(psize))) 172*68988Sbostic err(1, NULL); 17356032Sbostic get(fd, addr << daddr_shift, dpage, psize); 17451144Sbostic 17556032Sbostic for (dip = dpage + INOPB(lfsp) - 1; dip >= dpage; --dip) 17657204Smargo if (dip->di_inumber == LFS_IFILE_INUM) 17751144Sbostic break; 17851144Sbostic 17956032Sbostic if (dip < dpage) 180*68988Sbostic errx(1, "unable to locate ifile inode"); 18151144Sbostic 18251144Sbostic (void)printf("\nIFILE inode\n"); 18351144Sbostic dump_dinode(dip); 18451861Sbostic 18551144Sbostic (void)printf("\nIFILE contents\n"); 18651144Sbostic nblocks = dip->di_size >> lfsp->lfs_bshift; 18751144Sbostic block_limit = MIN(nblocks, NDADDR); 18851144Sbostic 18951144Sbostic /* Get the direct block */ 19051144Sbostic if ((ipage = malloc(psize)) == NULL) 191*68988Sbostic err(1, NULL); 19251144Sbostic for (inum = 0, addrp = dip->di_db, i = 0; i < block_limit; 19351144Sbostic i++, addrp++) { 19451144Sbostic get(fd, *addrp << daddr_shift, ipage, psize); 19551862Sbostic if (i < lfsp->lfs_cleansz) { 19651862Sbostic dump_cleaner_info(lfsp, ipage); 19752094Sbostic print_suheader; 19851862Sbostic continue; 19952094Sbostic } 20051144Sbostic 20152094Sbostic if (i < (lfsp->lfs_segtabsz + lfsp->lfs_cleansz)) { 20251862Sbostic inum = dump_ipage_segusage(lfsp, inum, ipage, 20351862Sbostic lfsp->lfs_sepb); 20451144Sbostic if (!inum) 20551144Sbostic if(!do_ientries) 20655479Sbostic goto e0; 20751144Sbostic else 20851144Sbostic print_iheader; 20951144Sbostic } else 21051144Sbostic inum = dump_ipage_ifile(inum, ipage, lfsp->lfs_ifpb); 21151862Sbostic 21251144Sbostic } 21351144Sbostic 21451144Sbostic if (nblocks <= NDADDR) 21551144Sbostic goto e0; 21651144Sbostic 21751144Sbostic /* Dump out blocks off of single indirect block */ 21851144Sbostic if (!(indir = malloc(psize))) 219*68988Sbostic err(1, NULL); 22051144Sbostic get(fd, dip->di_ib[0] << daddr_shift, indir, psize); 22151144Sbostic block_limit = MIN(i + lfsp->lfs_nindir, nblocks); 22251144Sbostic for (addrp = indir; i < block_limit; i++, addrp++) { 22351144Sbostic if (*addrp == LFS_UNUSED_DADDR) 22451144Sbostic break; 22551144Sbostic get(fd, *addrp << daddr_shift,ipage, psize); 22651862Sbostic if (i < lfsp->lfs_cleansz) { 22751862Sbostic dump_cleaner_info(lfsp, ipage); 22851862Sbostic continue; 22951862Sbostic } else 23051862Sbostic i -= lfsp->lfs_cleansz; 23151862Sbostic 23251144Sbostic if (i < lfsp->lfs_segtabsz) { 23351862Sbostic inum = dump_ipage_segusage(lfsp, inum, ipage, 23451862Sbostic lfsp->lfs_sepb); 23551144Sbostic if (!inum) 23651144Sbostic if(!do_ientries) 23751144Sbostic goto e1; 23851144Sbostic else 23951144Sbostic print_iheader; 24051144Sbostic } else 24151144Sbostic inum = dump_ipage_ifile(inum, ipage, lfsp->lfs_ifpb); 24251144Sbostic } 24351144Sbostic 24451144Sbostic if (nblocks <= lfsp->lfs_nindir * lfsp->lfs_ifpb) 24551144Sbostic goto e1; 24651861Sbostic 24751144Sbostic /* Get the double indirect block */ 24851144Sbostic if (!(dindir = malloc(psize))) 249*68988Sbostic err(1, NULL); 25051144Sbostic get(fd, dip->di_ib[1] << daddr_shift, dindir, psize); 25151144Sbostic for (iaddrp = dindir, j = 0; j < lfsp->lfs_nindir; j++, iaddrp++) { 25251144Sbostic if (*iaddrp == LFS_UNUSED_DADDR) 25351144Sbostic break; 25451144Sbostic get(fd, *iaddrp << daddr_shift, indir, psize); 25551144Sbostic block_limit = MIN(i + lfsp->lfs_nindir, nblocks); 25651144Sbostic for (addrp = indir; i < block_limit; i++, addrp++) { 25751144Sbostic if (*addrp == LFS_UNUSED_DADDR) 25851144Sbostic break; 25951144Sbostic get(fd, *addrp << daddr_shift, ipage, psize); 26051862Sbostic if (i < lfsp->lfs_cleansz) { 26151862Sbostic dump_cleaner_info(lfsp, ipage); 26251862Sbostic continue; 26351862Sbostic } else 26451862Sbostic i -= lfsp->lfs_cleansz; 26551862Sbostic 26651144Sbostic if (i < lfsp->lfs_segtabsz) { 26751144Sbostic inum = dump_ipage_segusage(lfsp, 26851862Sbostic inum, ipage, lfsp->lfs_sepb); 26951144Sbostic if (!inum) 27051144Sbostic if(!do_ientries) 27151144Sbostic goto e2; 27251144Sbostic else 27351144Sbostic print_iheader; 27451144Sbostic } else 27551144Sbostic inum = dump_ipage_ifile(inum, 27651144Sbostic ipage, lfsp->lfs_ifpb); 27751144Sbostic } 27851144Sbostic } 27951144Sbostic e2: free(dindir); 28051144Sbostic e1: free(indir); 28151144Sbostic e0: free(dpage); 28251144Sbostic free(ipage); 28351144Sbostic } 28451144Sbostic 28551144Sbostic static int 28651144Sbostic dump_ipage_ifile(i, pp, tot) 28751144Sbostic int i; 28851144Sbostic IFILE *pp; 28951144Sbostic int tot; 29051144Sbostic { 29151144Sbostic IFILE *ip; 29251144Sbostic int cnt, max; 29351144Sbostic 29451144Sbostic max = i + tot; 29551144Sbostic 29651144Sbostic for (ip = pp, cnt = i; cnt < max; cnt++, ip++) 29751144Sbostic print_ientry(cnt, ip); 29851144Sbostic return (max); 29951144Sbostic } 30051144Sbostic 30151144Sbostic static int 30251144Sbostic dump_ipage_segusage(lfsp, i, pp, tot) 30351862Sbostic struct lfs *lfsp; 30451144Sbostic int i; 30551144Sbostic IFILE *pp; 30651144Sbostic int tot; 30751144Sbostic { 30851861Sbostic SEGUSE *sp; 30951144Sbostic int cnt, max; 31051144Sbostic 31151144Sbostic max = i + tot; 31251861Sbostic for (sp = (SEGUSE *)pp, cnt = i; 31351144Sbostic cnt < lfsp->lfs_nseg && cnt < max; cnt++, sp++) 31451144Sbostic print_suentry(cnt, sp); 31551144Sbostic if (max >= lfsp->lfs_nseg) 31651144Sbostic return (0); 31751144Sbostic else 31851144Sbostic return (max); 31951144Sbostic } 32051144Sbostic 32151144Sbostic static void 32251144Sbostic dump_dinode(dip) 32351144Sbostic struct dinode *dip; 32451144Sbostic { 32551144Sbostic int i; 32651144Sbostic 32751144Sbostic (void)printf("%s%d\t%s%d\t%s%d\t%s%d\t%s%d\n", 32851144Sbostic "mode ", dip->di_mode, 32951144Sbostic "nlink ", dip->di_nlink, 33051144Sbostic "uid ", dip->di_uid, 33151144Sbostic "gid ", dip->di_gid, 33251144Sbostic "size ", dip->di_size); 33351144Sbostic (void)printf("%s%s%s%s%s%s", 33454714Sbostic "atime ", ctime(&dip->di_atime.ts_sec), 33554714Sbostic "mtime ", ctime(&dip->di_mtime.ts_sec), 33654714Sbostic "ctime ", ctime(&dip->di_ctime.ts_sec)); 33757204Smargo (void)printf("inum %d\n", dip->di_inumber); 33851144Sbostic (void)printf("Direct Addresses\n"); 33951144Sbostic for (i = 0; i < NDADDR; i++) { 34055479Sbostic (void)printf("\t0x%X", dip->di_db[i]); 34151144Sbostic if ((i % 6) == 5) 34251144Sbostic (void)printf("\n"); 34351144Sbostic } 34451144Sbostic for (i = 0; i < NIADDR; i++) 34555479Sbostic (void)printf("\t0x%X", dip->di_ib[i]); 34651144Sbostic (void)printf("\n"); 34751144Sbostic } 34851144Sbostic 34951144Sbostic static int 35052464Sstaelin dump_sum(fd, lfsp, sp, segnum, addr) 35151862Sbostic struct lfs *lfsp; 35251144Sbostic SEGSUM *sp; 35352464Sstaelin int fd, segnum; 35451861Sbostic daddr_t addr; 35551144Sbostic { 35651144Sbostic FINFO *fp; 35768016Smckusick daddr_t *dp; 35851862Sbostic int i, j; 35951861Sbostic int ck; 36051862Sbostic int numblocks; 36152464Sstaelin struct dinode *inop; 36251144Sbostic 36351862Sbostic if (sp->ss_sumsum != (ck = cksum(&sp->ss_datasum, 36455479Sbostic LFS_SUMMARY_SIZE - sizeof(sp->ss_sumsum)))) { 36555479Sbostic (void)printf("dumplfs: %s %d address 0x%lx\n", 36651861Sbostic "corrupt summary block; segment", segnum, addr); 36755479Sbostic return(0); 36855479Sbostic } 36951861Sbostic 37055479Sbostic (void)printf("Segment Summary Info at 0x%lx\n", addr); 37155479Sbostic (void)printf(" %s0x%X\t%s%d\t%s%d\n %s0x%X\t%s0x%X", 37251144Sbostic "next ", sp->ss_next, 37351144Sbostic "nfinfo ", sp->ss_nfinfo, 37451144Sbostic "ninos ", sp->ss_ninos, 37551862Sbostic "sumsum ", sp->ss_sumsum, 37651862Sbostic "datasum ", sp->ss_datasum ); 37751144Sbostic (void)printf("\tcreate %s", ctime((time_t *)&sp->ss_create)); 37851144Sbostic 37951862Sbostic numblocks = (sp->ss_ninos + INOPB(lfsp) - 1) / INOPB(lfsp); 38051862Sbostic 38151862Sbostic /* Dump out inode disk addresses */ 38251862Sbostic dp = (daddr_t *)sp; 38351862Sbostic dp += LFS_SUMMARY_SIZE / sizeof(daddr_t); 38452464Sstaelin inop = malloc(1 << lfsp->lfs_bshift); 38555479Sbostic printf(" Inode addresses:"); 38652464Sstaelin for (dp--, i = 0; i < sp->ss_ninos; dp--) { 38755479Sbostic printf("\t0x%X {", *dp); 38852464Sstaelin get(fd, *dp << (lfsp->lfs_bshift - lfsp->lfs_fsbtodb), inop, 38952464Sstaelin (1 << lfsp->lfs_bshift)); 39052464Sstaelin for (j = 0; i < sp->ss_ninos && j < INOPB(lfsp); j++, i++) { 39152464Sstaelin if (j > 0) 39252464Sstaelin (void)printf(", "); 39357204Smargo (void)printf("%d", inop[j].di_inumber); 39452464Sstaelin } 39552464Sstaelin (void)printf("}"); 39652464Sstaelin if (((i/INOPB(lfsp)) % 4) == 3) 39752464Sstaelin (void)printf("\n"); 39852464Sstaelin } 39952464Sstaelin free(inop); 40051862Sbostic 40151862Sbostic printf("\n"); 40251144Sbostic for (fp = (FINFO *)(sp + 1), i = 0; i < sp->ss_nfinfo; i++) { 40351862Sbostic numblocks += fp->fi_nblocks; 40455479Sbostic (void)printf(" FINFO for inode: %d version %d nblocks %d\n", 40551144Sbostic fp->fi_ino, fp->fi_version, fp->fi_nblocks); 40651144Sbostic dp = &(fp->fi_blocks[0]); 40751144Sbostic for (j = 0; j < fp->fi_nblocks; j++, dp++) { 40851144Sbostic (void)printf("\t%d", *dp); 40951144Sbostic if ((j % 8) == 7) 41051144Sbostic (void)printf("\n"); 41151144Sbostic } 41251144Sbostic if ((j % 8) != 0) 41351144Sbostic (void)printf("\n"); 41451144Sbostic fp = (FINFO *)dp; 41551144Sbostic } 41651862Sbostic return (numblocks); 41751144Sbostic } 41851144Sbostic 41951862Sbostic static void 42051861Sbostic dump_segment(fd, segnum, addr, lfsp, dump_sb) 42151861Sbostic int fd, segnum; 42251144Sbostic daddr_t addr; 42351862Sbostic struct lfs *lfsp; 42451144Sbostic int dump_sb; 42551144Sbostic { 42651862Sbostic struct lfs lfs_sb, *sbp; 42751144Sbostic SEGSUM *sump; 42851144Sbostic char sumblock[LFS_SUMMARY_SIZE]; 42951862Sbostic int did_one, nblocks, sb; 43051862Sbostic off_t sum_offset, super_off; 43151144Sbostic 43255479Sbostic (void)printf("\nSEGMENT %d (Disk Address 0x%X)\n", 43351144Sbostic addr >> (lfsp->lfs_segshift - daddr_shift), addr); 43451862Sbostic sum_offset = (addr << (lfsp->lfs_bshift - lfsp->lfs_fsbtodb)); 43551861Sbostic 43651144Sbostic sb = 0; 43751862Sbostic did_one = 0; 43851144Sbostic do { 43951144Sbostic get(fd, sum_offset, sumblock, LFS_SUMMARY_SIZE); 44051144Sbostic sump = (SEGSUM *)sumblock; 44151862Sbostic if (sump->ss_sumsum != cksum (&sump->ss_datasum, 44251862Sbostic LFS_SUMMARY_SIZE - sizeof(sump->ss_sumsum))) { 44351862Sbostic sbp = (struct lfs *)sump; 44451862Sbostic if (sb = (sbp->lfs_magic == LFS_MAGIC)) { 44551862Sbostic super_off = sum_offset; 44651862Sbostic sum_offset += LFS_SBPAD; 44751862Sbostic } else if (did_one) 44851862Sbostic break; 44951862Sbostic else { 45055479Sbostic printf("Segment at 0x%X corrupt\n", addr); 45151862Sbostic break; 45251862Sbostic } 45351862Sbostic } else { 45455479Sbostic nblocks = dump_sum(fd, lfsp, sump, segnum, sum_offset >> 45555479Sbostic (lfsp->lfs_bshift - lfsp->lfs_fsbtodb)); 45651862Sbostic if (nblocks) 45752464Sstaelin sum_offset += LFS_SUMMARY_SIZE + 45852464Sstaelin (nblocks << lfsp->lfs_bshift); 45951862Sbostic else 46051862Sbostic sum_offset = 0; 46151862Sbostic did_one = 1; 46251862Sbostic } 46351144Sbostic } while (sum_offset); 46451862Sbostic 46551144Sbostic if (dump_sb && sb) { 46651862Sbostic get(fd, super_off, &lfs_sb, sizeof(struct lfs)); 46751144Sbostic dump_super(&lfs_sb); 46851144Sbostic } 46951862Sbostic return; 47051144Sbostic } 47151144Sbostic 47251861Sbostic static void 47351144Sbostic dump_super(lfsp) 47451862Sbostic struct lfs *lfsp; 47551144Sbostic { 47651144Sbostic int i; 47751144Sbostic 47855479Sbostic (void)printf("%s0x%X\t%s0x%X\t%s%d\t%s%d\n", 47951144Sbostic "magic ", lfsp->lfs_magic, 48051144Sbostic "version ", lfsp->lfs_version, 48151144Sbostic "size ", lfsp->lfs_size, 48251144Sbostic "ssize ", lfsp->lfs_ssize); 48355479Sbostic (void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n", 48451144Sbostic "dsize ", lfsp->lfs_dsize, 48551144Sbostic "bsize ", lfsp->lfs_bsize, 48651144Sbostic "fsize ", lfsp->lfs_fsize, 48751144Sbostic "frag ", lfsp->lfs_frag); 48851144Sbostic 48955479Sbostic (void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n", 49051144Sbostic "minfree ", lfsp->lfs_minfree, 49151144Sbostic "inopb ", lfsp->lfs_inopb, 49251144Sbostic "ifpb ", lfsp->lfs_ifpb, 49351144Sbostic "nindir ", lfsp->lfs_nindir); 49451144Sbostic 49555479Sbostic (void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n", 49651144Sbostic "nseg ", lfsp->lfs_nseg, 49751144Sbostic "nspf ", lfsp->lfs_nspf, 49851862Sbostic "cleansz ", lfsp->lfs_cleansz, 49951144Sbostic "segtabsz ", lfsp->lfs_segtabsz); 50051144Sbostic 50155479Sbostic (void)printf("%s0x%X\t%s%d\t%s0x%X\t%s%d\n", 50251144Sbostic "segmask ", lfsp->lfs_segmask, 50351144Sbostic "segshift ", lfsp->lfs_segshift, 50451144Sbostic "bmask ", lfsp->lfs_bmask, 50551144Sbostic "bshift ", lfsp->lfs_bshift); 50651144Sbostic 50755479Sbostic (void)printf("%s0x%X\t\t%s%d\t%s0x%X\t%s%d\n", 50851144Sbostic "ffmask ", lfsp->lfs_ffmask, 50951144Sbostic "ffshift ", lfsp->lfs_ffshift, 51051144Sbostic "fbmask ", lfsp->lfs_fbmask, 51151144Sbostic "fbshift ", lfsp->lfs_fbshift); 51251144Sbostic 51355597Sbostic (void)printf("%s%d\t%s%d\t%s0x%X\t%s0x%qx\n", 51455597Sbostic "sushift ", lfsp->lfs_sushift, 51551144Sbostic "fsbtodb ", lfsp->lfs_fsbtodb, 51655388Sbostic "cksum ", lfsp->lfs_cksum, 51755388Sbostic "maxfilesize ", lfsp->lfs_maxfilesize); 51851144Sbostic 51955479Sbostic (void)printf("Superblock disk addresses:\t"); 52055479Sbostic for (i = 0; i < LFS_MAXNUMSB; i++) { 52155479Sbostic (void)printf(" 0x%X", lfsp->lfs_sboffs[i]); 52255479Sbostic if ( i == (LFS_MAXNUMSB >> 1)) 52355479Sbostic (void)printf("\n\t\t\t\t"); 52455479Sbostic } 52551144Sbostic (void)printf("\n"); 52651144Sbostic 52751144Sbostic (void)printf("Checkpoint Info\n"); 52855479Sbostic (void)printf("%s%d\t%s0x%X\t%s%d\n", 52951144Sbostic "free ", lfsp->lfs_free, 53051144Sbostic "idaddr ", lfsp->lfs_idaddr, 53151861Sbostic "ifile ", lfsp->lfs_ifile); 53256032Sbostic (void)printf("%s%d\t%s%d\t%s%d\n", 53351861Sbostic "bfree ", lfsp->lfs_bfree, 53456032Sbostic "avail ", lfsp->lfs_avail, 53556032Sbostic "uinodes ", lfsp->lfs_uinodes); 53656032Sbostic (void)printf("%s%d\t%s0x%X\t%s0x%X\n%s0x%X\t%s0x%X\t", 53751861Sbostic "nfiles ", lfsp->lfs_nfiles, 53851861Sbostic "lastseg ", lfsp->lfs_lastseg, 53951862Sbostic "nextseg ", lfsp->lfs_nextseg, 54051862Sbostic "curseg ", lfsp->lfs_curseg, 54151862Sbostic "offset ", lfsp->lfs_offset); 54251144Sbostic (void)printf("tstamp %s", ctime((time_t *)&lfsp->lfs_tstamp)); 54355479Sbostic (void)printf("\nIn-Memory Information\n"); 54456032Sbostic (void)printf("%s%d\t%s0x%X\t%s%d%s%d\t%s%d\n", 54555239Sbostic "seglock ", lfsp->lfs_seglock, 54655239Sbostic "iocount ", lfsp->lfs_iocount, 54755239Sbostic "writer ", lfsp->lfs_writer, 54855239Sbostic "dirops ", lfsp->lfs_dirops, 54956032Sbostic "doifile ", lfsp->lfs_doifile); 55056032Sbostic (void)printf("%s%d\t%s%d\t%s0x%X\t%s%d\n", 55156032Sbostic "nactive ", lfsp->lfs_nactive, 55255239Sbostic "fmod ", lfsp->lfs_fmod, 55355239Sbostic "clean ", lfsp->lfs_clean, 55455239Sbostic "ronly ", lfsp->lfs_ronly); 55551144Sbostic } 55651144Sbostic 55751144Sbostic static void 55851861Sbostic addseg(arg) 55951861Sbostic char *arg; 56051861Sbostic { 56151861Sbostic SEGLIST *p; 56251861Sbostic 56351861Sbostic if ((p = malloc(sizeof(SEGLIST))) == NULL) 564*68988Sbostic err(1, NULL); 56551861Sbostic p->next = seglist; 56651861Sbostic p->num = atoi(arg); 56751861Sbostic seglist = p; 56851861Sbostic } 56951861Sbostic 57051861Sbostic static void 57151862Sbostic dump_cleaner_info(lfsp, ipage) 57251862Sbostic struct lfs *lfsp; 57351862Sbostic void *ipage; 57451862Sbostic { 57551929Sbostic CLEANERINFO *cip; 57651929Sbostic 57751929Sbostic cip = (CLEANERINFO *)ipage; 57855479Sbostic (void)printf("segments clean\t%d\tsegments dirty\t%d\n\n", 57951929Sbostic cip->clean, cip->dirty); 58051862Sbostic } 58151862Sbostic 58251862Sbostic static void 58351144Sbostic usage() 58451144Sbostic { 58551861Sbostic (void)fprintf(stderr, "usage: dumplfs [-ai] [-s segnum] file\n"); 58651144Sbostic exit(1); 58751144Sbostic } 588