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