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