1 /* $NetBSD: lfs_debug.c,v 1.15 2001/11/23 21:44:27 chs 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 75 #include <sys/cdefs.h> 76 __KERNEL_RCSID(0, "$NetBSD: lfs_debug.c,v 1.15 2001/11/23 21:44:27 chs Exp $"); 77 78 #include <sys/param.h> 79 #include <sys/systm.h> 80 #include <sys/namei.h> 81 #include <sys/vnode.h> 82 #include <sys/mount.h> 83 84 #include <ufs/ufs/inode.h> 85 #include <ufs/lfs/lfs.h> 86 #include <ufs/lfs/lfs_extern.h> 87 88 void 89 lfs_dump_super(struct lfs *lfsp) 90 { 91 int i; 92 93 printf("%s%x\t%s%x\t%s%d\t%s%d\n", 94 "magic ", lfsp->lfs_magic, 95 "version ", lfsp->lfs_version, 96 "size ", lfsp->lfs_size, 97 "ssize ", lfsp->lfs_ssize); 98 printf("%s%d\t%s%d\t%s%d\t%s%d\n", 99 "dsize ", lfsp->lfs_dsize, 100 "bsize ", lfsp->lfs_bsize, 101 "fsize ", lfsp->lfs_fsize, 102 "frag ", lfsp->lfs_frag); 103 104 printf("%s%d\t%s%d\t%s%d\t%s%d\n", 105 "minfree ", lfsp->lfs_minfree, 106 "inopb ", lfsp->lfs_inopb, 107 "ifpb ", lfsp->lfs_ifpb, 108 "nindir ", lfsp->lfs_nindir); 109 110 printf("%s%d\t%s%d\t%s%d\t%s%d\n", 111 "nseg ", lfsp->lfs_nseg, 112 "nspf ", lfsp->lfs_nspf, 113 "cleansz ", lfsp->lfs_cleansz, 114 "segtabsz ", lfsp->lfs_segtabsz); 115 116 printf("%s%x\t%s%d\t%s%lx\t%s%d\n", 117 "segmask ", lfsp->lfs_segmask, 118 "segshift ", lfsp->lfs_segshift, 119 "bmask ", (unsigned long)lfsp->lfs_bmask, 120 "bshift ", lfsp->lfs_bshift); 121 122 printf("%s%lu\t%s%d\t%s%lx\t%s%u\n", 123 "ffmask ", (unsigned long)lfsp->lfs_ffmask, 124 "ffshift ", lfsp->lfs_ffshift, 125 "fbmask ", (unsigned long)lfsp->lfs_fbmask, 126 "fbshift ", lfsp->lfs_fbshift); 127 128 printf("%s%d\t%s%d\t%s%x\t%s%qx\n", 129 "sushift ", lfsp->lfs_sushift, 130 "fsbtodb ", lfsp->lfs_fsbtodb, 131 "cksum ", lfsp->lfs_cksum, 132 "maxfilesize ", (long long)lfsp->lfs_maxfilesize); 133 134 printf("Superblock disk addresses:"); 135 for (i = 0; i < LFS_MAXNUMSB; i++) 136 printf(" %x", lfsp->lfs_sboffs[i]); 137 printf("\n"); 138 139 printf("Checkpoint Info\n"); 140 printf("%s%d\t%s%x\t%s%d\n", 141 "free ", lfsp->lfs_free, 142 "idaddr ", lfsp->lfs_idaddr, 143 "ifile ", lfsp->lfs_ifile); 144 printf("%s%x\t%s%d\t%s%x\t%s%x\t%s%x\t%s%x\n", 145 "bfree ", lfsp->lfs_bfree, 146 "nfiles ", lfsp->lfs_nfiles, 147 "lastseg ", lfsp->lfs_lastseg, 148 "nextseg ", lfsp->lfs_nextseg, 149 "curseg ", lfsp->lfs_curseg, 150 "offset ", lfsp->lfs_offset); 151 printf("tstamp %llx\n", (long long)lfsp->lfs_tstamp); 152 } 153 154 void 155 lfs_dump_dinode(struct dinode *dip) 156 { 157 int i; 158 159 printf("%s%u\t%s%d\t%s%u\t%s%u\t%s%qu\t%s%d\n", 160 "mode ", dip->di_mode, 161 "nlink ", dip->di_nlink, 162 "uid ", dip->di_uid, 163 "gid ", dip->di_gid, 164 "size ", (long long)dip->di_size, 165 "blocks ", dip->di_blocks); 166 printf("inum %d\n", dip->di_inumber); 167 printf("Direct Addresses\n"); 168 for (i = 0; i < NDADDR; i++) { 169 printf("\t%x", dip->di_db[i]); 170 if ((i % 6) == 5) 171 printf("\n"); 172 } 173 for (i = 0; i < NIADDR; i++) 174 printf("\t%x", dip->di_ib[i]); 175 printf("\n"); 176 } 177 178 void 179 lfs_check_segsum(struct lfs *fs, struct segment *sp, char *file, int line) 180 { 181 int actual, i; 182 #if 0 183 static int offset; 184 #endif 185 186 if ((actual = i = 1) == 1) 187 return; /* XXXX not checking this anymore, really */ 188 189 if (sp->sum_bytes_left >= sizeof(FINFO) - sizeof(ufs_daddr_t) 190 && sp->fip->fi_nblocks > 512) { 191 printf("%s:%d: fi_nblocks = %d\n",file,line,sp->fip->fi_nblocks); 192 #ifdef DDB 193 Debugger(); 194 #endif 195 } 196 197 if (sp->sum_bytes_left > 484) { 198 printf("%s:%d: bad value (%d = -%d) for sum_bytes_left\n", 199 file, line, sp->sum_bytes_left, fs->lfs_sumsize-sp->sum_bytes_left); 200 panic("too many bytes"); 201 } 202 203 actual = fs->lfs_sumsize 204 /* amount taken up by FINFOs */ 205 - ((char *)&(sp->fip->fi_blocks[sp->fip->fi_nblocks]) - (char *)(sp->segsum)) 206 /* amount taken up by inode blocks */ 207 - sizeof(ufs_daddr_t)*((sp->ninodes+INOPB(fs)-1) / INOPB(fs)); 208 #if 0 209 if (actual - sp->sum_bytes_left < offset) 210 { 211 printf("%s:%d: offset changed %d -> %d\n", file, line, 212 offset, actual-sp->sum_bytes_left); 213 offset = actual - sp->sum_bytes_left; 214 /* panic("byte mismatch"); */ 215 } 216 #endif 217 #if 0 218 if (actual != sp->sum_bytes_left) 219 printf("%s:%d: warning: segsum miscalc at %d (-%d => %d)\n", 220 file, line, sp->sum_bytes_left, 221 fs->lfs_sumsize-sp->sum_bytes_left, 222 actual); 223 #endif 224 if (sp->sum_bytes_left > 0 225 && ((char *)(sp->segsum))[fs->lfs_sumsize 226 - sizeof(ufs_daddr_t) * ((sp->ninodes+INOPB(fs)-1) / INOPB(fs)) 227 - sp->sum_bytes_left] != '\0') { 228 printf("%s:%d: warning: segsum overwrite at %d (-%d => %d)\n", 229 file, line, sp->sum_bytes_left, 230 fs->lfs_sumsize-sp->sum_bytes_left, 231 actual); 232 #ifdef DDB 233 Debugger(); 234 #endif 235 } 236 } 237 238 void 239 lfs_check_bpp(struct lfs *fs, struct segment *sp, char *file, int line) 240 { 241 daddr_t blkno; 242 struct buf **bpp; 243 struct vnode *devvp; 244 245 devvp = VTOI(fs->lfs_ivnode)->i_devvp; 246 blkno = (*(sp->bpp))->b_blkno; 247 for (bpp = sp->bpp; bpp < sp->cbpp; bpp++) { 248 if ((*bpp)->b_blkno != blkno) { 249 if ((*bpp)->b_vp == devvp) { 250 printf("Oops, would misplace raw block 0x%x at " 251 "0x%x\n", 252 (*bpp)->b_blkno, 253 blkno); 254 } else { 255 printf("%s:%d: misplace ino %d lbn %d at " 256 "0x%x instead of 0x%x\n", 257 file, line, 258 VTOI((*bpp)->b_vp)->i_number, (*bpp)->b_lblkno, 259 blkno, 260 (*bpp)->b_blkno); 261 } 262 } 263 blkno += fsbtodb(fs, btofsb(fs, (*bpp)->b_bcount)); 264 } 265 } 266 #endif /* DEBUG */ 267