1 /*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)print.c 8.2 (Berkeley) 05/24/95"; 10 #endif /* not lint */ 11 12 #include <sys/param.h> 13 #include <sys/ucred.h> 14 #include <sys/mount.h> 15 #include <sys/time.h> 16 17 #include <ufs/ufs/dinode.h> 18 #include <ufs/lfs/lfs.h> 19 20 #include <stdlib.h> 21 #include <stdio.h> 22 #include "clean.h" 23 24 /* 25 * Print out a summary block; return number of blocks in segment; 0 26 * for empty segment or corrupt segment. 27 * Returns a pointer to the array of inode addresses. 28 */ 29 int 30 dump_summary(lfsp, sp, flags, iaddrp) 31 struct lfs *lfsp; 32 SEGSUM *sp; 33 u_long flags; 34 daddr_t **iaddrp; 35 { 36 int i, j, numblocks; 37 daddr_t *dp; 38 39 FINFO *fp; 40 int ck; 41 42 if (sp->ss_magic != SS_MAGIC) 43 return(-1); 44 45 if (sp->ss_sumsum != (ck = cksum(&sp->ss_datasum, 46 LFS_SUMMARY_SIZE - sizeof(sp->ss_sumsum)))) 47 return(-1); 48 49 numblocks = (sp->ss_ninos + INOPB(lfsp) - 1) / INOPB(lfsp); 50 51 /* Do some basic sanity checking. */ 52 if (sp->ss_nfinfo > LFS_SUMMARY_SIZE / sizeof(FINFO) || 53 numblocks > lfsp->lfs_ssize || 54 numblocks > LFS_SUMMARY_SIZE / sizeof(daddr_t)) 55 return(-1); 56 57 if (flags & DUMP_SUM_HEADER) { 58 (void)printf(" %s0x%X\t%s%d\t%s%d\n %s0x%X\t%s0x%X\t%s0x%X\n", 59 "next ", sp->ss_next, 60 "nfinfo ", sp->ss_nfinfo, 61 "ninos ", sp->ss_ninos, 62 "sumsum ", sp->ss_sumsum, 63 "datasum ", sp->ss_datasum, 64 "magic ", sp->ss_magic); 65 (void)printf(" create %s", ctime((time_t *)&sp->ss_create)); 66 } 67 68 /* Dump out inode disk addresses */ 69 if (flags & DUMP_INODE_ADDRS) 70 printf(" Inode addresses:"); 71 72 dp = (daddr_t *)((caddr_t)sp + LFS_SUMMARY_SIZE); 73 for (--dp, i = 0; i < sp->ss_ninos; --dp) 74 if (flags & DUMP_INODE_ADDRS) { 75 (void)printf("\t0x%lx", *dp); 76 if (++i % 7 == 0) 77 (void)printf("\n"); 78 } else 79 ++i; 80 if (iaddrp) 81 *iaddrp = ++dp; 82 if (flags & DUMP_INODE_ADDRS) 83 printf("\n"); 84 85 for (fp = (FINFO *)(sp + 1), i = 0; i < sp->ss_nfinfo; ++i) { 86 numblocks += fp->fi_nblocks; 87 if (flags & DUMP_FINFOS) { 88 (void)printf(" %s%d version %d nblocks %d\n", 89 "FINFO for inode: ", fp->fi_ino, 90 fp->fi_version, fp->fi_nblocks); 91 dp = &(fp->fi_blocks[0]); 92 for (j = 0; j < fp->fi_nblocks; j++, dp++) { 93 (void)printf("\t%d", *dp); 94 if ((j % 8) == 7) 95 (void)printf("\n"); 96 } 97 if ((j % 8) != 0) 98 (void)printf("\n"); 99 fp = (FINFO *)dp; 100 } else { 101 fp = (FINFO *)(&fp->fi_blocks[fp->fi_nblocks]); 102 } 103 } 104 return (numblocks); 105 } 106 107 #ifdef VERBOSE 108 void 109 dump_cleaner_info(ipage) 110 void *ipage; 111 { 112 CLEANERINFO *cip; 113 114 cip = (CLEANERINFO *)ipage; 115 (void)printf("segments clean\t%d\tsegments dirty\t%d\n\n", 116 cip->clean, cip->dirty); 117 } 118 119 void 120 dump_super(lfsp) 121 struct lfs *lfsp; 122 { 123 int i; 124 125 (void)printf("%s0x%X\t%s0x%X\t%s%d\t%s%d\n", 126 "magic ", lfsp->lfs_magic, 127 "version ", lfsp->lfs_version, 128 "size ", lfsp->lfs_size, 129 "ssize ", lfsp->lfs_ssize); 130 (void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n", 131 "dsize ", lfsp->lfs_dsize, 132 "bsize ", lfsp->lfs_bsize, 133 "fsize ", lfsp->lfs_fsize, 134 "frag ", lfsp->lfs_frag); 135 136 (void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n", 137 "minfree ", lfsp->lfs_minfree, 138 "inopb ", lfsp->lfs_inopb, 139 "ifpb ", lfsp->lfs_ifpb, 140 "nindir ", lfsp->lfs_nindir); 141 142 (void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n", 143 "nseg ", lfsp->lfs_nseg, 144 "nspf ", lfsp->lfs_nspf, 145 "cleansz ", lfsp->lfs_cleansz, 146 "segtabsz ", lfsp->lfs_segtabsz); 147 148 (void)printf("%s0x%X\t%s%d\t%s0x%qX\t%s%d\n", 149 "segmask ", lfsp->lfs_segmask, 150 "segshift ", lfsp->lfs_segshift, 151 "bmask ", lfsp->lfs_bmask, 152 "bshift ", lfsp->lfs_bshift); 153 154 (void)printf("%s0x%qX\t\t%s%d\t%s0x%qX\t%s%d\n", 155 "ffmask ", lfsp->lfs_ffmask, 156 "ffshift ", lfsp->lfs_ffshift, 157 "fbmask ", lfsp->lfs_fbmask, 158 "fbshift ", lfsp->lfs_fbshift); 159 160 (void)printf("%s%d\t\t%s0x%X\t%s0x%qx\n", 161 "fsbtodb ", lfsp->lfs_fsbtodb, 162 "cksum ", lfsp->lfs_cksum, 163 "maxfilesize ", lfsp->lfs_maxfilesize); 164 165 (void)printf("Superblock disk addresses:\t"); 166 for (i = 0; i < LFS_MAXNUMSB; i++) { 167 (void)printf(" 0x%X", lfsp->lfs_sboffs[i]); 168 if ( i == (LFS_MAXNUMSB >> 1)) 169 (void)printf("\n\t\t\t\t"); 170 } 171 (void)printf("\n"); 172 173 (void)printf("Checkpoint Info\n"); 174 (void)printf("%s%d\t%s0x%X\t%s%d\n", 175 "free ", lfsp->lfs_free, 176 "idaddr ", lfsp->lfs_idaddr, 177 "ifile ", lfsp->lfs_ifile); 178 (void)printf("%s%d\t%s%d\t%s%d\n", 179 "bfree ", lfsp->lfs_bfree, 180 "avail ", lfsp->lfs_avail, 181 "uinodes ", lfsp->lfs_uinodes); 182 (void)printf("%s%d\t%s0x%X\t%s0x%X\n%s0x%X\t%s0x%X\t", 183 "nfiles ", lfsp->lfs_nfiles, 184 "lastseg ", lfsp->lfs_lastseg, 185 "nextseg ", lfsp->lfs_nextseg, 186 "curseg ", lfsp->lfs_curseg, 187 "offset ", lfsp->lfs_offset); 188 (void)printf("tstamp %s", ctime((time_t *)&lfsp->lfs_tstamp)); 189 (void)printf("\nIn-Memory Information\n"); 190 (void)printf("%s%d\t%s0x%X\t%s%d\t%s%d\t%s%d\n", 191 "seglock ", lfsp->lfs_seglock, 192 "iocount ", lfsp->lfs_iocount, 193 "writer ", lfsp->lfs_writer, 194 "dirops ", lfsp->lfs_dirops, 195 "doifile ", lfsp->lfs_doifile ); 196 (void)printf("%s%d\t%s%d\t%s0x%X\t%s%d\n", 197 "nactive ", lfsp->lfs_nactive, 198 "fmod ", lfsp->lfs_fmod, 199 "clean ", lfsp->lfs_clean, 200 "ronly ", lfsp->lfs_ronly); 201 } 202 #endif /* VERBOSE */ 203