1 /* $NetBSD: lfs_debug.c,v 1.12 2001/07/13 20:30:23 perseant Exp $ */ 2 3 /*- 4 * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Konrad E. Schroder <perseant@hhhh.org>. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 /* 39 * Copyright (c) 1991, 1993 40 * The Regents of the University of California. All rights reserved. 41 * 42 * Redistribution and use in source and binary forms, with or without 43 * modification, are permitted provided that the following conditions 44 * are met: 45 * 1. Redistributions of source code must retain the above copyright 46 * notice, this list of conditions and the following disclaimer. 47 * 2. Redistributions in binary form must reproduce the above copyright 48 * notice, this list of conditions and the following disclaimer in the 49 * documentation and/or other materials provided with the distribution. 50 * 3. All advertising materials mentioning features or use of this software 51 * must display the following acknowledgement: 52 * This product includes software developed by the University of 53 * California, Berkeley and its contributors. 54 * 4. Neither the name of the University nor the names of its contributors 55 * may be used to endorse or promote products derived from this software 56 * without specific prior written permission. 57 * 58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 68 * SUCH DAMAGE. 69 * 70 * @(#)lfs_debug.c 8.1 (Berkeley) 6/11/93 71 */ 72 73 #ifdef DEBUG 74 #include <sys/param.h> 75 #include <sys/systm.h> 76 #include <sys/namei.h> 77 #include <sys/vnode.h> 78 #include <sys/mount.h> 79 80 #include <ufs/ufs/quota.h> 81 #include <ufs/ufs/inode.h> 82 #include <ufs/lfs/lfs.h> 83 #include <ufs/lfs/lfs_extern.h> 84 85 void 86 lfs_dump_super(struct lfs *lfsp) 87 { 88 int i; 89 90 printf("%s%x\t%s%x\t%s%d\t%s%d\n", 91 "magic ", lfsp->lfs_magic, 92 "version ", lfsp->lfs_version, 93 "size ", lfsp->lfs_size, 94 "ssize ", lfsp->lfs_ssize); 95 printf("%s%d\t%s%d\t%s%d\t%s%d\n", 96 "dsize ", lfsp->lfs_dsize, 97 "bsize ", lfsp->lfs_bsize, 98 "fsize ", lfsp->lfs_fsize, 99 "frag ", lfsp->lfs_frag); 100 101 printf("%s%d\t%s%d\t%s%d\t%s%d\n", 102 "minfree ", lfsp->lfs_minfree, 103 "inopb ", lfsp->lfs_inopb, 104 "ifpb ", lfsp->lfs_ifpb, 105 "nindir ", lfsp->lfs_nindir); 106 107 printf("%s%d\t%s%d\t%s%d\t%s%d\n", 108 "nseg ", lfsp->lfs_nseg, 109 "nspf ", lfsp->lfs_nspf, 110 "cleansz ", lfsp->lfs_cleansz, 111 "segtabsz ", lfsp->lfs_segtabsz); 112 113 printf("%s%x\t%s%d\t%s%lx\t%s%d\n", 114 "segmask ", lfsp->lfs_segmask, 115 "segshift ", lfsp->lfs_segshift, 116 "bmask ", (unsigned long)lfsp->lfs_bmask, 117 "bshift ", lfsp->lfs_bshift); 118 119 printf("%s%lu\t%s%d\t%s%lx\t%s%u\n", 120 "ffmask ", (unsigned long)lfsp->lfs_ffmask, 121 "ffshift ", lfsp->lfs_ffshift, 122 "fbmask ", (unsigned long)lfsp->lfs_fbmask, 123 "fbshift ", lfsp->lfs_fbshift); 124 125 printf("%s%d\t%s%d\t%s%x\t%s%qx\n", 126 "sushift ", lfsp->lfs_sushift, 127 "fsbtodb ", lfsp->lfs_fsbtodb, 128 "cksum ", lfsp->lfs_cksum, 129 "maxfilesize ", (long long)lfsp->lfs_maxfilesize); 130 131 printf("Superblock disk addresses:"); 132 for (i = 0; i < LFS_MAXNUMSB; i++) 133 printf(" %x", lfsp->lfs_sboffs[i]); 134 printf("\n"); 135 136 printf("Checkpoint Info\n"); 137 printf("%s%d\t%s%x\t%s%d\n", 138 "free ", lfsp->lfs_free, 139 "idaddr ", lfsp->lfs_idaddr, 140 "ifile ", lfsp->lfs_ifile); 141 printf("%s%x\t%s%d\t%s%x\t%s%x\t%s%x\t%s%x\n", 142 "bfree ", lfsp->lfs_bfree, 143 "nfiles ", lfsp->lfs_nfiles, 144 "lastseg ", lfsp->lfs_lastseg, 145 "nextseg ", lfsp->lfs_nextseg, 146 "curseg ", lfsp->lfs_curseg, 147 "offset ", lfsp->lfs_offset); 148 printf("tstamp %llx\n", (long long)lfsp->lfs_tstamp); 149 } 150 151 void 152 lfs_dump_dinode(struct dinode *dip) 153 { 154 int i; 155 156 printf("%s%u\t%s%d\t%s%u\t%s%u\t%s%qu\t%s%d\n", 157 "mode ", dip->di_mode, 158 "nlink ", dip->di_nlink, 159 "uid ", dip->di_uid, 160 "gid ", dip->di_gid, 161 "size ", (long long)dip->di_size, 162 "blocks ", dip->di_blocks); 163 printf("inum %d\n", dip->di_inumber); 164 printf("Direct Addresses\n"); 165 for (i = 0; i < NDADDR; i++) { 166 printf("\t%x", dip->di_db[i]); 167 if ((i % 6) == 5) 168 printf("\n"); 169 } 170 for (i = 0; i < NIADDR; i++) 171 printf("\t%x", dip->di_ib[i]); 172 printf("\n"); 173 } 174 175 void 176 lfs_check_segsum(struct lfs *fs, struct segment *sp, char *file, int line) 177 { 178 int actual, i; 179 #if 0 180 static int offset; 181 #endif 182 183 if((actual = i = 1) == 1) 184 return; /* XXXX not checking this anymore, really */ 185 186 if(sp->sum_bytes_left >= sizeof(FINFO) - sizeof(ufs_daddr_t) 187 && sp->fip->fi_nblocks > 512) { 188 printf("%s:%d: fi_nblocks = %d\n",file,line,sp->fip->fi_nblocks); 189 #ifdef DDB 190 Debugger(); 191 #endif 192 } 193 194 if(sp->sum_bytes_left > 484) { 195 printf("%s:%d: bad value (%d = -%d) for sum_bytes_left\n", 196 file, line, sp->sum_bytes_left, fs->lfs_sumsize-sp->sum_bytes_left); 197 panic("too many bytes"); 198 } 199 200 actual = fs->lfs_sumsize 201 /* amount taken up by FINFOs */ 202 - ((char *)&(sp->fip->fi_blocks[sp->fip->fi_nblocks]) - (char *)(sp->segsum)) 203 /* amount taken up by inode blocks */ 204 - sizeof(ufs_daddr_t)*((sp->ninodes+INOPB(fs)-1) / INOPB(fs)); 205 #if 0 206 if(actual - sp->sum_bytes_left < offset) 207 { 208 printf("%s:%d: offset changed %d -> %d\n", file, line, 209 offset, actual-sp->sum_bytes_left); 210 offset = actual - sp->sum_bytes_left; 211 /* panic("byte mismatch"); */ 212 } 213 #endif 214 #if 0 215 if(actual != sp->sum_bytes_left) 216 printf("%s:%d: warning: segsum miscalc at %d (-%d => %d)\n", 217 file, line, sp->sum_bytes_left, 218 fs->lfs_sumsize-sp->sum_bytes_left, 219 actual); 220 #endif 221 if(sp->sum_bytes_left > 0 222 && ((char *)(sp->segsum))[fs->lfs_sumsize 223 - sizeof(ufs_daddr_t) * ((sp->ninodes+INOPB(fs)-1) / INOPB(fs)) 224 - sp->sum_bytes_left] != '\0') { 225 printf("%s:%d: warning: segsum overwrite at %d (-%d => %d)\n", 226 file, line, sp->sum_bytes_left, 227 fs->lfs_sumsize-sp->sum_bytes_left, 228 actual); 229 #ifdef DDB 230 Debugger(); 231 #endif 232 } 233 } 234 235 void 236 lfs_check_bpp(struct lfs *fs, struct segment *sp, char *file, int line) 237 { 238 daddr_t blkno; 239 struct buf **bpp; 240 struct vnode *devvp; 241 242 devvp = VTOI(fs->lfs_ivnode)->i_devvp; 243 blkno = (*(sp->bpp))->b_blkno; 244 for(bpp=sp->bpp; bpp < sp->cbpp; bpp++) { 245 if((*bpp)->b_blkno != blkno) { 246 if((*bpp)->b_vp == devvp) { 247 printf("Oops, would misplace raw block 0x%x at " 248 "0x%x\n", 249 (*bpp)->b_blkno, 250 blkno); 251 } else { 252 printf("%s:%d: misplace ino %d lbn %d at " 253 "0x%x instead of 0x%x\n", 254 file, line, 255 VTOI((*bpp)->b_vp)->i_number, (*bpp)->b_lblkno, 256 blkno, 257 (*bpp)->b_blkno); 258 } 259 } 260 blkno += fsbtodb(fs, btofsb(fs, (*bpp)->b_bcount)); 261 } 262 } 263 #endif /* DEBUG */ 264