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