xref: /netbsd-src/sys/ufs/lfs/lfs_debug.c (revision 89c5a767f8fc7a4633b2d409966e2becbb98ff92)
1 /*	$NetBSD: lfs_debug.c,v 1.9 1999/03/10 00:20:00 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\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 	printf("inum  %d\n", dip->di_inumber);
165 	printf("Direct Addresses\n");
166 	for (i = 0; i < NDADDR; i++) {
167 		printf("\t%x", dip->di_db[i]);
168 		if ((i % 6) == 5)
169 			printf("\n");
170 	}
171 	for (i = 0; i < NIADDR; i++)
172 		printf("\t%x", dip->di_ib[i]);
173 	printf("\n");
174 }
175 
176 void
177 lfs_check_segsum(struct lfs *fs, struct segment *sp, char *file, int line)
178 {
179 	int actual, i;
180 #if 0
181 	static int offset;
182 #endif
183 
184 	if((actual = i = 1) == 1)
185 		return; /* XXXX not checking this anymore, really */
186 
187 	if(sp->sum_bytes_left >= sizeof(FINFO) - sizeof(ufs_daddr_t)
188 	   && sp->fip->fi_nblocks > 512) {
189 		printf("%s:%d: fi_nblocks = %d\n",file,line,sp->fip->fi_nblocks);
190 #ifdef DDB
191 		Debugger();
192 #endif
193 	}
194 
195 	if(sp->sum_bytes_left > 484) {
196 		printf("%s:%d: bad value (%d = -%d) for sum_bytes_left\n",
197 		       file, line, sp->sum_bytes_left, LFS_SUMMARY_SIZE-sp->sum_bytes_left);
198 		panic("too many bytes");
199 	}
200 
201 	actual = LFS_SUMMARY_SIZE
202 		/* amount taken up by FINFOs */
203 		- ((char *)&(sp->fip->fi_blocks[sp->fip->fi_nblocks]) - (char *)(sp->segsum))
204 			/* amount taken up by inode blocks */
205 			- sizeof(ufs_daddr_t)*((sp->ninodes+INOPB(fs)-1) / INOPB(fs));
206 #if 0
207 	if(actual - sp->sum_bytes_left < offset)
208 	{
209 		printf("%s:%d: offset changed %d -> %d\n", file, line,
210 		       offset, actual-sp->sum_bytes_left);
211 		offset = actual - sp->sum_bytes_left;
212 		/* panic("byte mismatch"); */
213 	}
214 #endif
215 #if 0
216 	if(actual != sp->sum_bytes_left)
217 		printf("%s:%d: warning: segsum miscalc at %d (-%d => %d)\n",
218 		       file, line, sp->sum_bytes_left,
219 		       LFS_SUMMARY_SIZE-sp->sum_bytes_left,
220 		       actual);
221 #endif
222 	if(sp->sum_bytes_left > 0
223 	   && ((char *)(sp->segsum))[LFS_SUMMARY_SIZE
224 				     - sizeof(ufs_daddr_t) * ((sp->ninodes+INOPB(fs)-1) / INOPB(fs))
225 				     - sp->sum_bytes_left] != '\0') {
226 		printf("%s:%d: warning: segsum overwrite at %d (-%d => %d)\n",
227 		       file, line, sp->sum_bytes_left,
228 		       LFS_SUMMARY_SIZE-sp->sum_bytes_left,
229 		       actual);
230 #ifdef DDB
231 		Debugger();
232 #endif
233 	}
234 }
235 
236 void
237 lfs_check_bpp(fs, sp, file, line)
238 	struct lfs *fs;
239 	struct segment *sp;
240 	char *file;
241 	int line;
242 {
243 	daddr_t blkno;
244 	struct buf **bpp;
245 	struct vnode *devvp;
246 
247 	devvp = VTOI(fs->lfs_ivnode)->i_devvp;
248 	blkno = (*(sp->bpp))->b_blkno;
249 	for(bpp=sp->bpp; bpp < sp->cbpp; bpp++) {
250 		if((*bpp)->b_blkno != blkno) {
251 			if((*bpp)->b_vp == devvp) {
252 				printf("Oops, would misplace raw block 0x%x at "
253 				       "0x%x\n",
254 				       (*bpp)->b_blkno,
255 				       blkno);
256 			} else {
257 				printf("%s:%d: misplace ino %d lbn %d at "
258 				       "0x%x instead of 0x%x\n",
259 				       file, line,
260 				       VTOI((*bpp)->b_vp)->i_number, (*bpp)->b_lblkno,
261 				       blkno,
262 				       (*bpp)->b_blkno);
263 			}
264 		}
265 		blkno += (*bpp)->b_bcount / DEV_BSIZE;
266 	}
267 }
268 #endif /* DEBUG */
269