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