1 /* $NetBSD: lfs_debug.c,v 1.39 2011/07/17 20:54:54 joerg Exp $ */
4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 * Copyright (c) 1991, 1993
33 * The Regents of the University of California. All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * @(#)lfs_debug.c 8.1 (Berkeley) 6/11/93
62 #include <sys/cdefs.h>
63 __KERNEL_RCSID(0, "$NetBSD: lfs_debug.c,v 1.39 2011/07/17 20:54:54 joerg Exp $");
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/namei.h>
70 #include <sys/vnode.h>
71 #include <sys/mount.h>
73 #include <sys/syslog.h>
76 #include <ufs/ufs/inode.h>
77 #include <ufs/lfs/lfs.h>
78 #include <ufs/lfs/lfs_extern.h>
81 struct lfs_log_entry lfs_log
[LFS_LOGLENGTH
];
84 lfs_bwrite_log(struct buf
*bp
, const char *file
, int line
)
86 struct vop_bwrite_args a
;
88 a
.a_desc
= VDESC(vop_bwrite
);
91 if (!(bp
->b_flags
& B_GATHERED
) && !(bp
->b_oflags
& BO_DELWRI
)) {
92 LFS_ENTER_LOG("write", file
, line
, bp
->b_lblkno
, bp
->b_flags
,
95 return (VCALL(bp
->b_vp
, VOFFSET(vop_bwrite
), &a
));
104 for (i
= lfs_lognum
; i
!= (lfs_lognum
- 1) % LFS_LOGLENGTH
;
105 i
= (i
+ 1) % LFS_LOGLENGTH
)
106 if (lfs_log
[i
].file
) {
107 /* Only print out basename, for readability */
108 cp
= lfs_log
[i
].file
;
111 while(*cp
!= '/' && cp
> lfs_log
[i
].file
)
114 printf("lbn %" PRId64
" %s %lx %d, %d %s\n",
125 lfs_dump_super(struct lfs
*lfsp
)
129 printf("%s%x\t%s%x\t%s%d\t%s%d\n",
130 "magic ", lfsp
->lfs_magic
,
131 "version ", lfsp
->lfs_version
,
132 "size ", lfsp
->lfs_size
,
133 "ssize ", lfsp
->lfs_ssize
);
134 printf("%s%d\t%s%d\t%s%d\t%s%d\n",
135 "dsize ", lfsp
->lfs_dsize
,
136 "bsize ", lfsp
->lfs_bsize
,
137 "fsize ", lfsp
->lfs_fsize
,
138 "frag ", lfsp
->lfs_frag
);
140 printf("%s%d\t%s%d\t%s%d\t%s%d\n",
141 "minfree ", lfsp
->lfs_minfree
,
142 "inopb ", lfsp
->lfs_inopb
,
143 "ifpb ", lfsp
->lfs_ifpb
,
144 "nindir ", lfsp
->lfs_nindir
);
146 printf("%s%d\t%s%d\t%s%d\t%s%d\n",
147 "nseg ", lfsp
->lfs_nseg
,
148 "nspf ", lfsp
->lfs_nspf
,
149 "cleansz ", lfsp
->lfs_cleansz
,
150 "segtabsz ", lfsp
->lfs_segtabsz
);
152 printf("%s%x\t%s%d\t%s%lx\t%s%d\n",
153 "segmask ", lfsp
->lfs_segmask
,
154 "segshift ", lfsp
->lfs_segshift
,
155 "bmask ", (unsigned long)lfsp
->lfs_bmask
,
156 "bshift ", lfsp
->lfs_bshift
);
158 printf("%s%lu\t%s%d\t%s%lx\t%s%u\n",
159 "ffmask ", (unsigned long)lfsp
->lfs_ffmask
,
160 "ffshift ", lfsp
->lfs_ffshift
,
161 "fbmask ", (unsigned long)lfsp
->lfs_fbmask
,
162 "fbshift ", lfsp
->lfs_fbshift
);
164 printf("%s%d\t%s%d\t%s%x\t%s%qx\n",
165 "sushift ", lfsp
->lfs_sushift
,
166 "fsbtodb ", lfsp
->lfs_fsbtodb
,
167 "cksum ", lfsp
->lfs_cksum
,
168 "maxfilesize ", (long long)lfsp
->lfs_maxfilesize
);
170 printf("Superblock disk addresses:");
171 for (i
= 0; i
< LFS_MAXNUMSB
; i
++)
172 printf(" %x", lfsp
->lfs_sboffs
[i
]);
175 printf("Checkpoint Info\n");
176 printf("%s%d\t%s%x\t%s%d\n",
177 "freehd ", lfsp
->lfs_freehd
,
178 "idaddr ", lfsp
->lfs_idaddr
,
179 "ifile ", lfsp
->lfs_ifile
);
180 printf("%s%x\t%s%d\t%s%x\t%s%x\t%s%x\t%s%x\n",
181 "bfree ", lfsp
->lfs_bfree
,
182 "nfiles ", lfsp
->lfs_nfiles
,
183 "lastseg ", lfsp
->lfs_lastseg
,
184 "nextseg ", lfsp
->lfs_nextseg
,
185 "curseg ", lfsp
->lfs_curseg
,
186 "offset ", lfsp
->lfs_offset
);
187 printf("tstamp %llx\n", (long long)lfsp
->lfs_tstamp
);
191 lfs_dump_dinode(struct ufs1_dinode
*dip
)
195 printf("%s%u\t%s%d\t%s%u\t%s%u\t%s%qu\t%s%d\n",
196 "mode ", dip
->di_mode
,
197 "nlink ", dip
->di_nlink
,
200 "size ", (long long)dip
->di_size
,
201 "blocks ", dip
->di_blocks
);
202 printf("inum %d\n", dip
->di_inumber
);
203 printf("Direct Addresses\n");
204 for (i
= 0; i
< NDADDR
; i
++) {
205 printf("\t%x", dip
->di_db
[i
]);
209 for (i
= 0; i
< NIADDR
; i
++)
210 printf("\t%x", dip
->di_ib
[i
]);
215 lfs_check_segsum(struct lfs
*fs
, struct segment
*sp
, char *file
, int line
)
222 if ((actual
= 1) == 1)
223 return; /* XXXX not checking this anymore, really */
225 if (sp
->sum_bytes_left
>= FINFOSIZE
226 && sp
->fip
->fi_nblocks
> 512) {
227 printf("%s:%d: fi_nblocks = %d\n",file
,line
,sp
->fip
->fi_nblocks
);
233 if (sp
->sum_bytes_left
> 484) {
234 printf("%s:%d: bad value (%d = -%d) for sum_bytes_left\n",
235 file
, line
, sp
->sum_bytes_left
, fs
->lfs_sumsize
-sp
->sum_bytes_left
);
236 panic("too many bytes");
239 actual
= fs
->lfs_sumsize
240 /* amount taken up by FINFOs */
241 - ((char *)&(sp
->fip
->fi_blocks
[sp
->fip
->fi_nblocks
]) - (char *)(sp
->segsum
))
242 /* amount taken up by inode blocks */
243 - sizeof(int32_t)*((sp
->ninodes
+INOPB(fs
)-1) / INOPB(fs
));
245 if (actual
- sp
->sum_bytes_left
< offset
)
247 printf("%s:%d: offset changed %d -> %d\n", file
, line
,
248 offset
, actual
-sp
->sum_bytes_left
);
249 offset
= actual
- sp
->sum_bytes_left
;
250 /* panic("byte mismatch"); */
254 if (actual
!= sp
->sum_bytes_left
)
255 printf("%s:%d: warning: segsum miscalc at %d (-%d => %d)\n",
256 file
, line
, sp
->sum_bytes_left
,
257 fs
->lfs_sumsize
-sp
->sum_bytes_left
,
260 if (sp
->sum_bytes_left
> 0
261 && ((char *)(sp
->segsum
))[fs
->lfs_sumsize
262 - sizeof(int32_t) * ((sp
->ninodes
+INOPB(fs
)-1) / INOPB(fs
))
263 - sp
->sum_bytes_left
] != '\0') {
264 printf("%s:%d: warning: segsum overwrite at %d (-%d => %d)\n",
265 file
, line
, sp
->sum_bytes_left
,
266 fs
->lfs_sumsize
-sp
->sum_bytes_left
,
275 lfs_check_bpp(struct lfs
*fs
, struct segment
*sp
, char *file
, int line
)
281 devvp
= VTOI(fs
->lfs_ivnode
)->i_devvp
;
282 blkno
= (*(sp
->bpp
))->b_blkno
;
283 for (bpp
= sp
->bpp
; bpp
< sp
->cbpp
; bpp
++) {
284 if ((*bpp
)->b_blkno
!= blkno
) {
285 if ((*bpp
)->b_vp
== devvp
) {
286 printf("Oops, would misplace raw block "
287 "0x%" PRIx64
" at 0x%" PRIx64
"\n",
291 printf("%s:%d: misplace ino %llu lbn %" PRId64
292 " at 0x%" PRIx64
" instead of "
296 VTOI((*bpp
)->b_vp
)->i_number
,
302 blkno
+= fsbtodb(fs
, btofsb(fs
, (*bpp
)->b_bcount
));
306 int lfs_debug_log_subsys
[DLOG_MAX
];
309 * Log events from various debugging areas of LFS, depending on what
310 * the user has enabled.
313 lfs_debug_log(int subsys
, const char *fmt
, ...)
317 /* If not debugging this subsys, exit */
318 if (lfs_debug_log_subsys
[subsys
] == 0)
322 vlog(LOG_DEBUG
, fmt
, ap
);