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