xref: /freebsd/sbin/growfs/debug.c (revision 5521ff5a4d1929056e7ffc982fac3341ca54df7c)
1 /*
2  * Copyright (c) 2000 Christoph Herrmann, Thomas-Henning von Kamptz
3  * Copyright (c) 1980, 1989, 1993 The Regents of the University of California.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * Christoph Herrmann and Thomas-Henning von Kamptz, Munich and Frankfurt.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgment:
19  *      This product includes software developed by the University of
20  *      California, Berkeley and its contributors, as well as Christoph
21  *      Herrmann and Thomas-Henning von Kamptz.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  * $TSHeader: src/sbin/growfs/debug.c,v 1.3 2000/12/12 19:31:00 tomsoft Exp $
39  * $FreeBSD$
40  *
41  */
42 
43 #ifndef lint
44 static const char rcsid[] =
45   "$FreeBSD$";
46 #endif /* not lint */
47 
48 /* ********************************************************** INCLUDES ***** */
49 #include <sys/param.h>
50 
51 #include <stdio.h>
52 #include <ufs/ufs/dinode.h>
53 #include <ufs/ffs/fs.h>
54 
55 #include "debug.h"
56 
57 #ifdef FS_DEBUG
58 
59 /* *********************************************************** GLOBALS ***** */
60 static FILE	*dbg_log=NULL;
61 static unsigned int	indent=0;
62 
63 /*
64  * prototypes not done here, as they come with debug.h
65  */
66 
67 /* ********************************************************** dbg_open ***** */
68 /*
69  * Open the filehandle where all debug output has to go.
70  */
71 void
72 dbg_open(const char *fn)
73 {
74 
75 	dbg_log=fopen(fn, "a");
76 
77 	return;
78 }
79 
80 /* ********************************************************* dbg_close ***** */
81 /*
82  * Close the filehandle where all debug output went to.
83  */
84 void
85 dbg_close(void)
86 {
87 
88 	if(dbg_log) {
89 		fclose(dbg_log);
90 		dbg_log=NULL;
91 	}
92 
93 	return;
94 }
95 
96 /* ****************************************************** dbg_dump_hex ***** */
97 /*
98  * Dump out a full filesystem block in hex.
99  */
100 void
101 dbg_dump_hex(struct fs *sb, const char *comment, unsigned char *mem)
102 {
103 	int i, j, k;
104 
105 	if(!dbg_log) {
106 		return;
107 	}
108 	fprintf(dbg_log, "===== START HEXDUMP =====\n");
109 	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)mem, comment);
110 	indent++;
111 	for (i=0; i<sb->fs_bsize; i+=24) {
112 		for (j=0; j<3; j++) {
113 			for (k=0; k<8; k++) {
114 				fprintf(dbg_log, "%02x ", *mem++);
115 			}
116 			fprintf(dbg_log, "  ");
117 		}
118 		fprintf(dbg_log, "\n");
119 	}
120 	indent--;
121 	fprintf(dbg_log, "===== END HEXDUMP =====\n");
122 
123 	return;
124 }
125 
126 /* ******************************************************* dbg_dump_fs ***** */
127 /*
128  * Dump the superblock.
129  */
130 void
131 dbg_dump_fs(struct fs *sb, const char *comment)
132 {
133 #ifdef FSMAXSNAP
134 	int	j;
135 #endif /* FSMAXSNAP */
136 
137 	if(!dbg_log) {
138 		return;
139 	}
140 
141 	fprintf(dbg_log, "===== START SUPERBLOCK =====\n");
142 	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)sb, comment);
143 	indent++;
144 
145 	fprintf(dbg_log, "sblkno        ufs_daddr_t       0x%08x\n",
146 	    sb->fs_sblkno);
147 	fprintf(dbg_log, "cblkno        ufs_daddr_t       0x%08x\n",
148 	    sb->fs_cblkno);
149 	fprintf(dbg_log, "iblkno        ufs_daddr_t       0x%08x\n",
150 	    sb->fs_iblkno);
151 	fprintf(dbg_log, "dblkno        ufs_daddr_t       0x%08x\n",
152 	    sb->fs_dblkno);
153 
154 	fprintf(dbg_log, "cgoffset      int32_t           0x%08x\n",
155 	    sb->fs_cgoffset);
156 	fprintf(dbg_log, "cgmask        int32_t           0x%08x\n",
157 	    sb->fs_cgmask);
158 	fprintf(dbg_log, "time          time_t            %10u\n",
159 	    (unsigned int)sb->fs_time);
160 	fprintf(dbg_log, "size          int32_t           0x%08x\n",
161 	    sb->fs_size);
162 	fprintf(dbg_log, "dsize         int32_t           0x%08x\n",
163 	    sb->fs_dsize);
164 	fprintf(dbg_log, "ncg           int32_t           0x%08x\n",
165 	    sb->fs_ncg);
166 	fprintf(dbg_log, "bsize         int32_t           0x%08x\n",
167 	    sb->fs_bsize);
168 	fprintf(dbg_log, "fsize         int32_t           0x%08x\n",
169 	    sb->fs_fsize);
170 	fprintf(dbg_log, "frag          int32_t           0x%08x\n",
171 	    sb->fs_frag);
172 
173 	fprintf(dbg_log, "minfree       int32_t           0x%08x\n",
174 	    sb->fs_minfree);
175 	fprintf(dbg_log, "rotdelay      int32_t           0x%08x\n",
176 	    sb->fs_rotdelay);
177 	fprintf(dbg_log, "rps           int32_t           0x%08x\n",
178 	    sb->fs_rps);
179 
180 	fprintf(dbg_log, "bmask         int32_t           0x%08x\n",
181 	    sb->fs_bmask);
182 	fprintf(dbg_log, "fmask         int32_t           0x%08x\n",
183 	    sb->fs_fmask);
184 	fprintf(dbg_log, "bshift        int32_t           0x%08x\n",
185 	    sb->fs_bshift);
186 	fprintf(dbg_log, "fshift        int32_t           0x%08x\n",
187 	    sb->fs_fshift);
188 
189 	fprintf(dbg_log, "maxcontig     int32_t           0x%08x\n",
190 	    sb->fs_maxcontig);
191 	fprintf(dbg_log, "maxbpg        int32_t           0x%08x\n",
192 	    sb->fs_maxbpg);
193 
194 	fprintf(dbg_log, "fragshift     int32_t           0x%08x\n",
195 	    sb->fs_fragshift);
196 	fprintf(dbg_log, "fsbtodb       int32_t           0x%08x\n",
197 	    sb->fs_fsbtodb);
198 	fprintf(dbg_log, "sbsize        int32_t           0x%08x\n",
199 	    sb->fs_sbsize);
200 	fprintf(dbg_log, "csmask        int32_t           0x%08x\n",
201 	    sb->fs_csmask);
202 	fprintf(dbg_log, "csshift       int32_t           0x%08x\n",
203 	    sb->fs_csshift);
204 	fprintf(dbg_log, "nindir        int32_t           0x%08x\n",
205 	    sb->fs_nindir);
206 	fprintf(dbg_log, "inopb         int32_t           0x%08x\n",
207 	    sb->fs_inopb);
208 	fprintf(dbg_log, "nspf          int32_t           0x%08x\n",
209 	    sb->fs_nspf);
210 
211 	fprintf(dbg_log, "optim         int32_t           0x%08x\n",
212 	    sb->fs_optim);
213 
214 	fprintf(dbg_log, "npsect        int32_t           0x%08x\n",
215 	    sb->fs_npsect);
216 	fprintf(dbg_log, "interleave    int32_t           0x%08x\n",
217 	    sb->fs_interleave);
218 	fprintf(dbg_log, "trackskew     int32_t           0x%08x\n",
219 	    sb->fs_trackskew);
220 
221 	fprintf(dbg_log, "id            int32_t[2]        %08x %08x\n",
222 	    sb->fs_id[0], sb->fs_id[1]);
223 
224 	fprintf(dbg_log, "csaddr        ufs_daddr_t       0x%08x\n",
225 	    sb->fs_csaddr);
226 	fprintf(dbg_log, "cssize        int32_t           0x%08x\n",
227 	    sb->fs_cssize);
228 	fprintf(dbg_log, "cgsize        int32_t           0x%08x\n",
229 	    sb->fs_cgsize);
230 
231 	fprintf(dbg_log, "ntrak         int32_t           0x%08x\n",
232 	    sb->fs_ntrak);
233 	fprintf(dbg_log, "nsect         int32_t           0x%08x\n",
234 	    sb->fs_nsect);
235 	fprintf(dbg_log, "spc           int32_t           0x%08x\n",
236 	    sb->fs_spc);
237 
238 	fprintf(dbg_log, "ncyl          int32_t           0x%08x\n",
239 	    sb->fs_ncyl);
240 
241 	fprintf(dbg_log, "cpg           int32_t           0x%08x\n",
242 	    sb->fs_cpg);
243 	fprintf(dbg_log, "ipg           int32_t           0x%08x\n",
244 	    sb->fs_ipg);
245 	fprintf(dbg_log, "fpg           int32_t           0x%08x\n",
246 	    sb->fs_fpg);
247 
248 	dbg_dump_csum("internal cstotal", &sb->fs_cstotal);
249 
250 	fprintf(dbg_log, "fmod          int8_t            0x%02x\n",
251 	    sb->fs_fmod);
252 	fprintf(dbg_log, "clean         int8_t            0x%02x\n",
253 	    sb->fs_clean);
254 	fprintf(dbg_log, "ronly         int8_t            0x%02x\n",
255 	    sb->fs_ronly);
256 	fprintf(dbg_log, "flags         int8_t            0x%02x\n",
257 	    sb->fs_flags);
258 	fprintf(dbg_log, "fsmnt         u_char[MAXMNTLEN] \"%s\"\n",
259 	    sb->fs_fsmnt);
260 
261 	fprintf(dbg_log, "cgrotor       int32_t           0x%08x\n",
262 	    sb->fs_cgrotor);
263 /*
264  * struct csum[MAXCSBUFS] - is only maintained in memory
265  */
266 /*	fprintf(dbg_log, " int32_t\n", sb->*fs_maxcluster);*/
267 	fprintf(dbg_log, "cpc           int32_t           0x%08x\n",
268 	    sb->fs_cpc);
269 /*
270  * int16_t fs_opostbl[16][8] - is dumped when used in dbg_dump_sptbl
271  */
272 #ifdef FSMAXSNAP
273 	for(j=0; j<FSMAXSNAP; j++) {
274 		fprintf(dbg_log, "snapinum      int32_t[%2d]       0x%08x\n",
275 		    j, sb->fs_snapinum[j]);
276 		if(!sb->fs_snapinum[j]) { /* list is dense */
277 			break;
278 		}
279 	}
280 #endif /* FSMAXSNAP */
281 	fprintf(dbg_log, "contigsumsize int32_t           0x%08x\n",
282 	    sb->fs_contigsumsize);
283 	fprintf(dbg_log, "maxsymlinklen int32_t           0x%08x\n",
284 	    sb->fs_maxsymlinklen);
285 	fprintf(dbg_log, "inodefmt      int32_t           0x%08x\n",
286 	    sb->fs_inodefmt);
287 	fprintf(dbg_log, "maxfilesize   u_int64_t         0x%08x%08x\n",
288 	    ((unsigned int *)&(sb->fs_maxfilesize))[1],
289 	    ((unsigned int *)&(sb->fs_maxfilesize))[0]);
290 	fprintf(dbg_log, "qbmask        int64_t           0x%08x%08x\n",
291 	    ((unsigned int *)&(sb->fs_qbmask))[1],
292 	    ((unsigned int *)&(sb->fs_qbmask))[0]);
293 	fprintf(dbg_log, "qfmask        int64_t           0x%08x%08x\n",
294 	    ((unsigned int *)&(sb->fs_qfmask))[1],
295 	    ((unsigned int *)&(sb->fs_qfmask))[0]);
296 	fprintf(dbg_log, "state         int32_t           0x%08x\n",
297 	    sb->fs_state);
298 	fprintf(dbg_log, "postblformat  int32_t           0x%08x\n",
299 	    sb->fs_postblformat);
300 	fprintf(dbg_log, "nrpos         int32_t           0x%08x\n",
301 	    sb->fs_nrpos);
302 	fprintf(dbg_log, "postbloff     int32_t           0x%08x\n",
303 	    sb->fs_postbloff);
304 	fprintf(dbg_log, "rotbloff      int32_t           0x%08x\n",
305 	    sb->fs_rotbloff);
306 	fprintf(dbg_log, "magic         int32_t           0x%08x\n",
307 	    sb->fs_magic);
308 
309 	indent--;
310 	fprintf(dbg_log, "===== END SUPERBLOCK =====\n");
311 
312 	return;
313 }
314 
315 /* ******************************************************* dbg_dump_cg ***** */
316 /*
317  * Dump a cylinder group.
318  */
319 void
320 dbg_dump_cg(const char *comment, struct cg *cgr)
321 {
322 	int j;
323 
324 	if(!dbg_log) {
325 		return;
326 	}
327 
328 	fprintf(dbg_log, "===== START CYLINDER GROUP =====\n");
329 	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
330 	indent++;
331 
332 	fprintf(dbg_log, "magic         int32_t    0x%08x\n", cgr->cg_magic);
333 	fprintf(dbg_log, "time          time_t     %10u\n", (unsigned int)
334 	    cgr->cg_time);
335 	fprintf(dbg_log, "cgx           int32_t    0x%08x\n", cgr->cg_cgx);
336 	fprintf(dbg_log, "ncyl          int16_t    0x%04x\n", cgr->cg_ncyl);
337 	fprintf(dbg_log, "niblk         int16_t    0x%04x\n", cgr->cg_niblk);
338 	fprintf(dbg_log, "ndblk         int32_t    0x%08x\n", cgr->cg_ndblk);
339 	dbg_dump_csum("internal cs", &cgr->cg_cs);
340 	fprintf(dbg_log, "rotor         int32_t    0x%08x\n", cgr->cg_rotor);
341 	fprintf(dbg_log, "frotor        int32_t    0x%08x\n", cgr->cg_frotor);
342 	fprintf(dbg_log, "irotor        int32_t    0x%08x\n", cgr->cg_irotor);
343 	for(j=0; j<MAXFRAG; j++) {
344 		fprintf(dbg_log, "frsum         int32_t[%d] 0x%08x\n", j,
345 		    cgr->cg_frsum[j]);
346 	}
347 	fprintf(dbg_log, "btotoff       int32_t    0x%08x\n", cgr->cg_btotoff);
348 	fprintf(dbg_log, "boff          int32_t    0x%08x\n", cgr->cg_boff);
349 	fprintf(dbg_log, "iusedoff      int32_t    0x%08x\n", cgr->cg_iusedoff);
350 	fprintf(dbg_log, "freeoff       int32_t    0x%08x\n", cgr->cg_freeoff);
351 	fprintf(dbg_log, "nextfreeoff   int32_t    0x%08x\n",
352 	    cgr->cg_nextfreeoff);
353 	fprintf(dbg_log, "clustersumoff int32_t    0x%08x\n",
354 	    cgr->cg_clustersumoff);
355 	fprintf(dbg_log, "clusterof     int32_t    0x%08x\n",
356 	    cgr->cg_clusteroff);
357 	fprintf(dbg_log, "nclusterblks  int32_t    0x%08x\n",
358 	    cgr->cg_nclusterblks);
359 
360 	indent--;
361 	fprintf(dbg_log, "===== END CYLINDER GROUP =====\n");
362 
363 	return;
364 }
365 
366 /* ***************************************************** dbg_dump_csum ***** */
367 /*
368  * Dump a cylinder summary.
369  */
370 void
371 dbg_dump_csum(const char *comment, struct csum *cs)
372 {
373 
374 	if(!dbg_log) {
375 		return;
376 	}
377 
378 	fprintf(dbg_log, "===== START CYLINDER SUMMARY =====\n");
379 	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cs, comment);
380 	indent++;
381 
382 	fprintf(dbg_log, "ndir   int32_t 0x%08x\n", cs->cs_ndir);
383 	fprintf(dbg_log, "nbfree int32_t 0x%08x\n", cs->cs_nbfree);
384 	fprintf(dbg_log, "nifree int32_t 0x%08x\n", cs->cs_nifree);
385 	fprintf(dbg_log, "nffree int32_t 0x%08x\n", cs->cs_nffree);
386 
387 	indent--;
388 	fprintf(dbg_log, "===== END CYLINDER SUMMARY =====\n");
389 
390 	return;
391 }
392 
393 /* **************************************************** dbg_dump_inmap ***** */
394 /*
395  * Dump the inode allocation map in one cylinder group.
396  */
397 void
398 dbg_dump_inmap(struct fs *sb, const char *comment, struct cg *cgr)
399 {
400 	int j,k,l,e;
401 	unsigned char *cp;
402 
403 	if(!dbg_log) {
404 		return;
405 	}
406 
407 	fprintf(dbg_log, "===== START INODE ALLOCATION MAP =====\n");
408 	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
409 	indent++;
410 
411 	cp=(unsigned char *)cg_inosused(cgr);
412 	e=sb->fs_ipg/8;
413 	for(j=0; j<e; j+=32) {
414 		fprintf(dbg_log, "%08x: ", j);
415 		for(k=0; k<32; k+=8) {
416 			if(j+k+8<e) {
417 				fprintf(dbg_log,
418 				    "%02x%02x%02x%02x%02x%02x%02x%02x ",
419 				    cp[0], cp[1], cp[2], cp[3],
420 				    cp[4], cp[5], cp[6], cp[7]);
421 			} else {
422 				for(l=0; (l<8)&&(j+k+l<e); l++) {
423 					fprintf(dbg_log, "%02x", cp[l]);
424 				}
425 			}
426 			cp+=8;
427 		}
428 		fprintf(dbg_log, "\n");
429 	}
430 
431 	indent--;
432 	fprintf(dbg_log, "===== END INODE ALLOCATION MAP =====\n");
433 
434 	return;
435 }
436 
437 
438 /* **************************************************** dbg_dump_frmap ***** */
439 /*
440  * Dump the fragment allocation map in one cylinder group.
441  */
442 void
443 dbg_dump_frmap(struct fs *sb, const char *comment, struct cg *cgr)
444 {
445 	int j,k,l,e;
446 	unsigned char *cp;
447 
448 	if(!dbg_log) {
449 		return;
450 	}
451 
452 	fprintf(dbg_log, "===== START FRAGMENT ALLOCATION MAP =====\n");
453 	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
454 	indent++;
455 
456 	cp=(unsigned char *)cg_blksfree(cgr);
457 	e=howmany((sb->fs_cpg * sb->fs_spc / NSPF(sb)), NBBY);
458 	for(j=0; j<e; j+=32) {
459 		fprintf(dbg_log, "%08x: ", j);
460 		for(k=0; k<32; k+=8) {
461 			if(j+k+8<e) {
462 				fprintf(dbg_log,
463 				    "%02x%02x%02x%02x%02x%02x%02x%02x ",
464 				    cp[0], cp[1], cp[2], cp[3],
465 				    cp[4], cp[5], cp[6], cp[7]);
466 			} else {
467 				for(l=0; (l<8)&&(j+k+l<e); l++) {
468 					fprintf(dbg_log, "%02x", cp[l]);
469 				}
470 			}
471 			cp+=8;
472 		}
473 		fprintf(dbg_log, "\n");
474 	}
475 
476 	indent--;
477 	fprintf(dbg_log, "===== END FRAGMENT ALLOCATION MAP =====\n");
478 
479 	return;
480 }
481 
482 /* **************************************************** dbg_dump_clmap ***** */
483 /*
484  * Dump the cluster allocation map in one cylinder group.
485  */
486 void
487 dbg_dump_clmap(struct fs *sb, const char *comment, struct cg *cgr)
488 {
489 	int j,k,l,e;
490 	unsigned char *cp;
491 
492 	if(!dbg_log) {
493 		return;
494 	}
495 
496 	fprintf(dbg_log, "===== START CLUSTER ALLOCATION MAP =====\n");
497 	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
498 	indent++;
499 
500 	cp=(unsigned char *)cg_clustersfree(cgr);
501 	e=howmany(sb->fs_cpg * sb->fs_spc / NSPB(sb), NBBY);
502 	for(j=0; j<e; j+=32) {
503 		fprintf(dbg_log, "%08x: ", j);
504 		for(k=0; k<32; k+=8) {
505 			if(j+k+8<e) {
506 				fprintf(dbg_log,
507 				    "%02x%02x%02x%02x%02x%02x%02x%02x ",
508 				    cp[0], cp[1], cp[2], cp[3],
509 				    cp[4], cp[5], cp[6], cp[7]);
510 			} else {
511 				for(l=0; (l<8)&&(j+k+l<e); l++) {
512 					fprintf(dbg_log, "%02x", cp[l]);
513 				}
514 			}
515 			cp+=8;
516 		}
517 		fprintf(dbg_log, "\n");
518 	}
519 
520 	indent--;
521 	fprintf(dbg_log, "===== END CLUSTER ALLOCATION MAP =====\n");
522 
523 	return;
524 }
525 
526 /* **************************************************** dbg_dump_clsum ***** */
527 /*
528  * Dump the cluster availability summary of one cylinder group.
529  */
530 void
531 dbg_dump_clsum(struct fs *sb, const char *comment, struct cg *cgr)
532 {
533 	int j;
534 	int *ip;
535 
536 	if(!dbg_log) {
537 		return;
538 	}
539 
540 	fprintf(dbg_log, "===== START CLUSTER SUMMARY =====\n");
541 	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
542 	indent++;
543 
544 	ip=(int *)cg_clustersum(cgr);
545 	for(j=0; j<=sb->fs_contigsumsize; j++) {
546 		fprintf(dbg_log, "%02d: %8d\n", j, *ip++);
547 	}
548 
549 	indent--;
550 	fprintf(dbg_log, "===== END CLUSTER SUMMARY =====\n");
551 
552 	return;
553 }
554 
555 /* **************************************************** dbg_dump_sptbl ***** */
556 /*
557  * Dump the block summary, and the rotational layout table.
558  */
559 void
560 dbg_dump_sptbl(struct fs *sb, const char *comment, struct cg *cgr)
561 {
562 	int j,k;
563 	int *ip;
564 
565 	if(!dbg_log) {
566 		return;
567 	}
568 
569 	fprintf(dbg_log,
570 	    "===== START BLOCK SUMMARY AND POSITION TABLE =====\n");
571 	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
572 	indent++;
573 
574 	ip=(int *)cg_blktot(cgr);
575 	for(j=0; j<sb->fs_cpg; j++) {
576 		fprintf(dbg_log, "%2d: %5d = ", j, *ip++);
577 		for(k=0; k<sb->fs_nrpos; k++) {
578 			fprintf(dbg_log, "%4d", cg_blks(sb, cgr, j)[k]);
579 			if(k<sb->fs_nrpos-1) {
580 				fprintf(dbg_log, " + ");
581 			}
582 		}
583 		fprintf(dbg_log, "\n");
584 	}
585 
586 	indent--;
587 	fprintf(dbg_log, "===== END BLOCK SUMMARY AND POSITION TABLE =====\n");
588 
589 	return;
590 }
591 
592 /* ****************************************************** dbg_dump_ino ***** */
593 /*
594  * Dump an inode structure.
595  */
596 void
597 dbg_dump_ino(struct fs *sb, const char *comment, struct dinode *ino)
598 {
599 	int ictr;
600 	int remaining_blocks;
601 
602 	if(!dbg_log) {
603 		return;
604 	}
605 
606 	fprintf(dbg_log, "===== START INODE DUMP =====\n");
607 	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)ino, comment);
608 	indent++;
609 
610 	fprintf(dbg_log, "mode       u_int16_t      0%o\n", ino->di_mode);
611 	fprintf(dbg_log, "nlink      int16_t        0x%04x\n", ino->di_nlink);
612 	fprintf(dbg_log, "size       u_int64_t      0x%08x%08x\n",
613 	    ((unsigned int *)&(ino->di_size))[1],
614 	    ((unsigned int *)&(ino->di_size))[0]);
615 	fprintf(dbg_log, "atime      int32_t        0x%08x\n", ino->di_atime);
616 	fprintf(dbg_log, "atimensec  int32_t        0x%08x\n",
617 	    ino->di_atimensec);
618 	fprintf(dbg_log, "mtime      int32_t        0x%08x\n",
619 	    ino->di_mtime);
620 	fprintf(dbg_log, "mtimensec  int32_t        0x%08x\n",
621 	    ino->di_mtimensec);
622 	fprintf(dbg_log, "ctime      int32_t        0x%08x\n", ino->di_ctime);
623 	fprintf(dbg_log, "ctimensec  int32_t        0x%08x\n",
624 	    ino->di_ctimensec);
625 
626 	remaining_blocks=howmany(ino->di_size, sb->fs_bsize); /* XXX ts - +1? */
627 	for(ictr=0; ictr < MIN(NDADDR, remaining_blocks); ictr++) {
628 		fprintf(dbg_log, "db         ufs_daddr_t[%x] 0x%08x\n", ictr,
629 		    ino->di_db[ictr]);
630 	}
631 	remaining_blocks-=NDADDR;
632 	if(remaining_blocks>0) {
633 		fprintf(dbg_log, "ib         ufs_daddr_t[0] 0x%08x\n",
634 		    ino->di_ib[0]);
635 	}
636 	remaining_blocks-=howmany(sb->fs_bsize, sizeof(ufs_daddr_t));
637 	if(remaining_blocks>0) {
638 		fprintf(dbg_log, "ib         ufs_daddr_t[1] 0x%08x\n",
639 		    ino->di_ib[1]);
640 	}
641 #define SQUARE(a) ((a)*(a))
642 	remaining_blocks-=SQUARE(howmany(sb->fs_bsize, sizeof(ufs_daddr_t)));
643 #undef SQUARE
644 	if(remaining_blocks>0) {
645 		fprintf(dbg_log, "ib         ufs_daddr_t[2] 0x%08x\n",
646 		    ino->di_ib[2]);
647 	}
648 
649 	fprintf(dbg_log, "flags      u_int32_t      0x%08x\n", ino->di_flags);
650 	fprintf(dbg_log, "blocks     int32_t        0x%08x\n", ino->di_blocks);
651 	fprintf(dbg_log, "gen        int32_t        0x%08x\n", ino->di_gen);
652 	fprintf(dbg_log, "uid        u_int32_t      0x%08x\n", ino->di_uid);
653 	fprintf(dbg_log, "gid        u_int32_t      0x%08x\n", ino->di_gid);
654 
655 	indent--;
656 	fprintf(dbg_log, "===== END INODE DUMP =====\n");
657 
658 	return;
659 }
660 
661 /* ***************************************************** dbg_dump_iblk ***** */
662 /*
663  * Dump an indirect block. The iteration to dump a full file has to be
664  * written around.
665  */
666 void
667 dbg_dump_iblk(struct fs *sb, const char *comment, char *block, size_t length)
668 {
669 	unsigned int *mem;
670 	int i, j;
671 
672 	if(!dbg_log) {
673 		return;
674 	}
675 
676 	fprintf(dbg_log, "===== START INDIRECT BLOCK DUMP =====\n");
677 	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)block,
678 	    comment);
679 	indent++;
680 
681 	mem=(unsigned int *)block;
682 	for (i=0; (size_t)i<MIN(howmany(sb->fs_bsize, sizeof(ufs_daddr_t)),
683 	    length); i+=8) {
684 		fprintf(dbg_log, "%04x: ", i);
685 		for (j=0; j<8; j++) {
686 			if((size_t)(i+j)<length) {
687 				fprintf(dbg_log, "%08X ", *mem++);
688 			}
689 		}
690 		fprintf(dbg_log, "\n");
691 	}
692 
693 	indent--;
694 	fprintf(dbg_log, "===== END INDIRECT BLOCK DUMP =====\n");
695 
696 	return;
697 }
698 
699 #endif /* FS_DEBUG */
700 
701