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