1 /* $NetBSD: lfs_debug.c,v 1.24 2003/10/30 01:43:10 simonb Exp $ */ 2 3 /*- 4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 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. Neither the name of the University nor the names of its contributors 51 * may be used to endorse or promote products derived from this software 52 * without specific prior written permission. 53 * 54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 64 * SUCH DAMAGE. 65 * 66 * @(#)lfs_debug.c 8.1 (Berkeley) 6/11/93 67 */ 68 69 #ifdef DEBUG 70 71 #include <sys/cdefs.h> 72 __KERNEL_RCSID(0, "$NetBSD: lfs_debug.c,v 1.24 2003/10/30 01:43:10 simonb Exp $"); 73 #include <sys/param.h> 74 #include <sys/systm.h> 75 #include <sys/namei.h> 76 #include <sys/vnode.h> 77 #include <sys/mount.h> 78 #include <sys/buf.h> 79 80 #include <ufs/ufs/inode.h> 81 #include <ufs/lfs/lfs.h> 82 #include <ufs/lfs/lfs_extern.h> 83 84 int lfs_lognum; 85 struct lfs_log_entry lfs_log[LFS_LOGLENGTH]; 86 87 int lfs_bwrite_log(struct buf *bp, char *file, int line) 88 { 89 struct vop_bwrite_args a; 90 a.a_desc = VDESC(vop_bwrite); 91 a.a_bp = bp; 92 93 if (!(bp->b_flags & (B_DELWRI | B_GATHERED))) 94 LFS_ENTER_LOG("write", file, line, bp->b_lblkno, bp->b_flags); 95 return (VCALL(bp->b_vp, VOFFSET(vop_bwrite), &a)); 96 } 97 98 void lfs_dumplog(void) 99 { 100 int i; 101 102 for (i = lfs_lognum; i != (lfs_lognum - 1) % LFS_LOGLENGTH; i = (i + 1) % LFS_LOGLENGTH) 103 if (lfs_log[i].file) { 104 printf("lbn %" PRId64 " %s %lx %d %s\n", 105 lfs_log[i].block, 106 lfs_log[i].op, 107 lfs_log[i].flags, 108 lfs_log[i].line, 109 lfs_log[i].file + 56); 110 } 111 } 112 113 void 114 lfs_dump_super(struct lfs *lfsp) 115 { 116 int i; 117 118 printf("%s%x\t%s%x\t%s%d\t%s%d\n", 119 "magic ", lfsp->lfs_magic, 120 "version ", lfsp->lfs_version, 121 "size ", lfsp->lfs_size, 122 "ssize ", lfsp->lfs_ssize); 123 printf("%s%d\t%s%d\t%s%d\t%s%d\n", 124 "dsize ", lfsp->lfs_dsize, 125 "bsize ", lfsp->lfs_bsize, 126 "fsize ", lfsp->lfs_fsize, 127 "frag ", lfsp->lfs_frag); 128 129 printf("%s%d\t%s%d\t%s%d\t%s%d\n", 130 "minfree ", lfsp->lfs_minfree, 131 "inopb ", lfsp->lfs_inopb, 132 "ifpb ", lfsp->lfs_ifpb, 133 "nindir ", lfsp->lfs_nindir); 134 135 printf("%s%d\t%s%d\t%s%d\t%s%d\n", 136 "nseg ", lfsp->lfs_nseg, 137 "nspf ", lfsp->lfs_nspf, 138 "cleansz ", lfsp->lfs_cleansz, 139 "segtabsz ", lfsp->lfs_segtabsz); 140 141 printf("%s%x\t%s%d\t%s%lx\t%s%d\n", 142 "segmask ", lfsp->lfs_segmask, 143 "segshift ", lfsp->lfs_segshift, 144 "bmask ", (unsigned long)lfsp->lfs_bmask, 145 "bshift ", lfsp->lfs_bshift); 146 147 printf("%s%lu\t%s%d\t%s%lx\t%s%u\n", 148 "ffmask ", (unsigned long)lfsp->lfs_ffmask, 149 "ffshift ", lfsp->lfs_ffshift, 150 "fbmask ", (unsigned long)lfsp->lfs_fbmask, 151 "fbshift ", lfsp->lfs_fbshift); 152 153 printf("%s%d\t%s%d\t%s%x\t%s%qx\n", 154 "sushift ", lfsp->lfs_sushift, 155 "fsbtodb ", lfsp->lfs_fsbtodb, 156 "cksum ", lfsp->lfs_cksum, 157 "maxfilesize ", (long long)lfsp->lfs_maxfilesize); 158 159 printf("Superblock disk addresses:"); 160 for (i = 0; i < LFS_MAXNUMSB; i++) 161 printf(" %x", lfsp->lfs_sboffs[i]); 162 printf("\n"); 163 164 printf("Checkpoint Info\n"); 165 printf("%s%d\t%s%x\t%s%d\n", 166 "freehd ", lfsp->lfs_freehd, 167 "idaddr ", lfsp->lfs_idaddr, 168 "ifile ", lfsp->lfs_ifile); 169 printf("%s%x\t%s%d\t%s%x\t%s%x\t%s%x\t%s%x\n", 170 "bfree ", lfsp->lfs_bfree, 171 "nfiles ", lfsp->lfs_nfiles, 172 "lastseg ", lfsp->lfs_lastseg, 173 "nextseg ", lfsp->lfs_nextseg, 174 "curseg ", lfsp->lfs_curseg, 175 "offset ", lfsp->lfs_offset); 176 printf("tstamp %llx\n", (long long)lfsp->lfs_tstamp); 177 } 178 179 void 180 lfs_dump_dinode(struct ufs1_dinode *dip) 181 { 182 int i; 183 184 printf("%s%u\t%s%d\t%s%u\t%s%u\t%s%qu\t%s%d\n", 185 "mode ", dip->di_mode, 186 "nlink ", dip->di_nlink, 187 "uid ", dip->di_uid, 188 "gid ", dip->di_gid, 189 "size ", (long long)dip->di_size, 190 "blocks ", dip->di_blocks); 191 printf("inum %d\n", dip->di_inumber); 192 printf("Direct Addresses\n"); 193 for (i = 0; i < NDADDR; i++) { 194 printf("\t%x", dip->di_db[i]); 195 if ((i % 6) == 5) 196 printf("\n"); 197 } 198 for (i = 0; i < NIADDR; i++) 199 printf("\t%x", dip->di_ib[i]); 200 printf("\n"); 201 } 202 203 void 204 lfs_check_segsum(struct lfs *fs, struct segment *sp, char *file, int line) 205 { 206 int actual; 207 #if 0 208 static int offset; 209 #endif 210 211 if ((actual = 1) == 1) 212 return; /* XXXX not checking this anymore, really */ 213 214 if (sp->sum_bytes_left >= FINFOSIZE 215 && sp->fip->fi_nblocks > 512) { 216 printf("%s:%d: fi_nblocks = %d\n",file,line,sp->fip->fi_nblocks); 217 #ifdef DDB 218 Debugger(); 219 #endif 220 } 221 222 if (sp->sum_bytes_left > 484) { 223 printf("%s:%d: bad value (%d = -%d) for sum_bytes_left\n", 224 file, line, sp->sum_bytes_left, fs->lfs_sumsize-sp->sum_bytes_left); 225 panic("too many bytes"); 226 } 227 228 actual = fs->lfs_sumsize 229 /* amount taken up by FINFOs */ 230 - ((char *)&(sp->fip->fi_blocks[sp->fip->fi_nblocks]) - (char *)(sp->segsum)) 231 /* amount taken up by inode blocks */ 232 - sizeof(int32_t)*((sp->ninodes+INOPB(fs)-1) / INOPB(fs)); 233 #if 0 234 if (actual - sp->sum_bytes_left < offset) 235 { 236 printf("%s:%d: offset changed %d -> %d\n", file, line, 237 offset, actual-sp->sum_bytes_left); 238 offset = actual - sp->sum_bytes_left; 239 /* panic("byte mismatch"); */ 240 } 241 #endif 242 #if 0 243 if (actual != sp->sum_bytes_left) 244 printf("%s:%d: warning: segsum miscalc at %d (-%d => %d)\n", 245 file, line, sp->sum_bytes_left, 246 fs->lfs_sumsize-sp->sum_bytes_left, 247 actual); 248 #endif 249 if (sp->sum_bytes_left > 0 250 && ((char *)(sp->segsum))[fs->lfs_sumsize 251 - sizeof(int32_t) * ((sp->ninodes+INOPB(fs)-1) / INOPB(fs)) 252 - sp->sum_bytes_left] != '\0') { 253 printf("%s:%d: warning: segsum overwrite at %d (-%d => %d)\n", 254 file, line, sp->sum_bytes_left, 255 fs->lfs_sumsize-sp->sum_bytes_left, 256 actual); 257 #ifdef DDB 258 Debugger(); 259 #endif 260 } 261 } 262 263 void 264 lfs_check_bpp(struct lfs *fs, struct segment *sp, char *file, int line) 265 { 266 daddr_t blkno; 267 struct buf **bpp; 268 struct vnode *devvp; 269 270 devvp = VTOI(fs->lfs_ivnode)->i_devvp; 271 blkno = (*(sp->bpp))->b_blkno; 272 for (bpp = sp->bpp; bpp < sp->cbpp; bpp++) { 273 if ((*bpp)->b_blkno != blkno) { 274 if ((*bpp)->b_vp == devvp) { 275 printf("Oops, would misplace raw block " 276 "0x%" PRIx64 " at 0x%" PRIx64 "\n", 277 (*bpp)->b_blkno, 278 blkno); 279 } else { 280 printf("%s:%d: misplace ino %d lbn %" PRId64 281 " at 0x%" PRIx64 " instead of " 282 "0x%" PRIx64 "\n", 283 file, line, 284 VTOI((*bpp)->b_vp)->i_number, (*bpp)->b_lblkno, 285 blkno, 286 (*bpp)->b_blkno); 287 } 288 } 289 blkno += fsbtodb(fs, btofsb(fs, (*bpp)->b_bcount)); 290 } 291 } 292 #endif /* DEBUG */ 293