2 * SPDX-License-Identifier: BSD-4-Clause
4 * Copyright (c) 2000 Christoph Herrmann, Thomas-Henning von Kamptz
5 * Copyright (c) 1980, 1989, 1993 The Regents of the University of California.
8 * This code is derived from software contributed to Berkeley by
9 * Christoph Herrmann and Thomas-Henning von Kamptz, Munich and Frankfurt.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgment:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors, as well as Christoph
23 * Herrmann and Thomas-Henning von Kamptz.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * $TSHeader: src/sbin/growfs/debug.c,v 1.3 2000/12/12 19:31:00 tomsoft Exp $
44 #include <sys/param.h>
49 #include <ufs/ufs/dinode.h>
50 #include <ufs/ffs/fs.h>
56 static FILE *dbg_log = NULL;
57 static unsigned int indent = 0;
60 * prototypes are not done here, as they come with debug.h
64 * Open the filehandle where all debug output has to go.
67 dbg_open(const char *fn)
70 if (strcmp(fn, "-") == 0)
71 dbg_log = fopen("/dev/stdout", "a");
73 dbg_log = fopen(fn, "a");
79 * Close the filehandle where all debug output went to.
94 * Dump out a full file system block in hex.
97 dbg_dump_hex(struct fs *sb, const char *comment, unsigned char *mem)
104 fprintf(dbg_log, "===== START HEXDUMP =====\n");
105 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)mem, comment);
107 for (i = 0; i < sb->fs_bsize; i += 24) {
108 for (j = 0; j < 3; j++) {
109 for (k = 0; k < 8; k++)
110 fprintf(dbg_log, "%02x ", *mem++);
111 fprintf(dbg_log, " ");
113 fprintf(dbg_log, "\n");
116 fprintf(dbg_log, "===== END HEXDUMP =====\n");
122 * Dump the superblock.
125 dbg_dump_fs(struct fs *sb, const char *comment)
132 fprintf(dbg_log, "===== START SUPERBLOCK =====\n");
133 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)sb, comment);
136 fprintf(dbg_log, "sblkno int32_t 0x%08x\n",
138 fprintf(dbg_log, "cblkno int32_t 0x%08x\n",
140 fprintf(dbg_log, "iblkno int32_t 0x%08x\n",
142 fprintf(dbg_log, "dblkno int32_t 0x%08x\n",
145 fprintf(dbg_log, "old_cgoffset int32_t 0x%08x\n",
146 sb->fs_old_cgoffset);
147 fprintf(dbg_log, "old_cgmask int32_t 0x%08x\n",
149 fprintf(dbg_log, "old_time int32_t %10u\n",
150 (unsigned int)sb->fs_old_time);
151 fprintf(dbg_log, "old_size int32_t 0x%08x\n",
153 fprintf(dbg_log, "old_dsize int32_t 0x%08x\n",
155 fprintf(dbg_log, "ncg int32_t 0x%08x\n",
157 fprintf(dbg_log, "bsize int32_t 0x%08x\n",
159 fprintf(dbg_log, "fsize int32_t 0x%08x\n",
161 fprintf(dbg_log, "frag int32_t 0x%08x\n",
164 fprintf(dbg_log, "minfree int32_t 0x%08x\n",
166 fprintf(dbg_log, "old_rotdelay int32_t 0x%08x\n",
167 sb->fs_old_rotdelay);
168 fprintf(dbg_log, "old_rps int32_t 0x%08x\n",
171 fprintf(dbg_log, "bmask int32_t 0x%08x\n",
173 fprintf(dbg_log, "fmask int32_t 0x%08x\n",
175 fprintf(dbg_log, "bshift int32_t 0x%08x\n",
177 fprintf(dbg_log, "fshift int32_t 0x%08x\n",
180 fprintf(dbg_log, "maxcontig int32_t 0x%08x\n",
182 fprintf(dbg_log, "maxbpg int32_t 0x%08x\n",
185 fprintf(dbg_log, "fragshift int32_t 0x%08x\n",
187 fprintf(dbg_log, "fsbtodb int32_t 0x%08x\n",
189 fprintf(dbg_log, "sbsize int32_t 0x%08x\n",
191 fprintf(dbg_log, "spare1 int32_t[2] 0x%08x 0x%08x\n",
192 sb->fs_spare1[0], sb->fs_spare1[1]);
193 fprintf(dbg_log, "nindir int32_t 0x%08x\n",
195 fprintf(dbg_log, "inopb int32_t 0x%08x\n",
197 fprintf(dbg_log, "old_nspf int32_t 0x%08x\n",
200 fprintf(dbg_log, "optim int32_t 0x%08x\n",
203 fprintf(dbg_log, "old_npsect int32_t 0x%08x\n",
205 fprintf(dbg_log, "old_interleave int32_t 0x%08x\n",
206 sb->fs_old_interleave);
207 fprintf(dbg_log, "old_trackskew int32_t 0x%08x\n",
208 sb->fs_old_trackskew);
210 fprintf(dbg_log, "id int32_t[2] 0x%08x 0x%08x\n",
211 sb->fs_id[0], sb->fs_id[1]);
213 fprintf(dbg_log, "old_csaddr int32_t 0x%08x\n",
215 fprintf(dbg_log, "cssize int32_t 0x%08x\n",
217 fprintf(dbg_log, "cgsize int32_t 0x%08x\n",
220 fprintf(dbg_log, "spare2 int32_t 0x%08x\n",
222 fprintf(dbg_log, "old_nsect int32_t 0x%08x\n",
224 fprintf(dbg_log, "old_spc int32_t 0x%08x\n",
227 fprintf(dbg_log, "old_ncyl int32_t 0x%08x\n",
230 fprintf(dbg_log, "old_cpg int32_t 0x%08x\n",
232 fprintf(dbg_log, "ipg int32_t 0x%08x\n",
234 fprintf(dbg_log, "fpg int32_t 0x%08x\n",
237 dbg_dump_csum("internal old_cstotal", &sb->fs_old_cstotal);
239 fprintf(dbg_log, "fmod int8_t 0x%02x\n",
241 fprintf(dbg_log, "clean int8_t 0x%02x\n",
243 fprintf(dbg_log, "ronly int8_t 0x%02x\n",
245 fprintf(dbg_log, "old_flags int8_t 0x%02x\n",
247 fprintf(dbg_log, "fsmnt u_char[MAXMNTLEN] \"%s\"\n",
249 fprintf(dbg_log, "volname u_char[MAXVOLLEN] \"%s\"\n",
251 fprintf(dbg_log, "swuid u_int64_t 0x%08x%08x\n",
252 ((unsigned int *)&(sb->fs_swuid))[1],
253 ((unsigned int *)&(sb->fs_swuid))[0]);
255 fprintf(dbg_log, "pad int32_t 0x%08x\n",
258 fprintf(dbg_log, "cgrotor int32_t 0x%08x\n",
261 * struct csum[MAXCSBUFS] - is only maintained in memory
263 /* fprintf(dbg_log, " int32_t\n", sb->*fs_maxcluster);*/
264 fprintf(dbg_log, "old_cpc int32_t 0x%08x\n",
267 * int16_t fs_opostbl[16][8] - is dumped when used in dbg_dump_sptbl
269 fprintf(dbg_log, "maxbsize int32_t 0x%08x\n",
271 fprintf(dbg_log, "unrefs int64_t 0x%08jx\n",
273 fprintf(dbg_log, "sblockloc int64_t 0x%08x%08x\n",
274 ((unsigned int *)&(sb->fs_sblockloc))[1],
275 ((unsigned int *)&(sb->fs_sblockloc))[0]);
277 dbg_dump_csum_total("internal cstotal", &sb->fs_cstotal);
279 fprintf(dbg_log, "time ufs_time_t %10u\n",
280 (unsigned int)sb->fs_time);
282 fprintf(dbg_log, "size int64_t 0x%08x%08x\n",
283 ((unsigned int *)&(sb->fs_size))[1],
284 ((unsigned int *)&(sb->fs_size))[0]);
285 fprintf(dbg_log, "dsize int64_t 0x%08x%08x\n",
286 ((unsigned int *)&(sb->fs_dsize))[1],
287 ((unsigned int *)&(sb->fs_dsize))[0]);
288 fprintf(dbg_log, "csaddr ufs2_daddr_t 0x%08x%08x\n",
289 ((unsigned int *)&(sb->fs_csaddr))[1],
290 ((unsigned int *)&(sb->fs_csaddr))[0]);
291 fprintf(dbg_log, "pendingblocks int64_t 0x%08x%08x\n",
292 ((unsigned int *)&(sb->fs_pendingblocks))[1],
293 ((unsigned int *)&(sb->fs_pendingblocks))[0]);
294 fprintf(dbg_log, "pendinginodes int32_t 0x%08x\n",
295 sb->fs_pendinginodes);
297 for (j = 0; j < FSMAXSNAP; j++) {
298 fprintf(dbg_log, "snapinum int32_t[%2d] 0x%08x\n",
299 j, sb->fs_snapinum[j]);
300 if (!sb->fs_snapinum[j]) { /* list is dense */
304 fprintf(dbg_log, "avgfilesize int32_t 0x%08x\n",
306 fprintf(dbg_log, "avgfpdir int32_t 0x%08x\n",
308 fprintf(dbg_log, "save_cgsize int32_t 0x%08x\n",
310 fprintf(dbg_log, "flags int32_t 0x%08x\n",
312 fprintf(dbg_log, "contigsumsize int32_t 0x%08x\n",
313 sb->fs_contigsumsize);
314 fprintf(dbg_log, "maxsymlinklen int32_t 0x%08x\n",
315 sb->fs_maxsymlinklen);
316 fprintf(dbg_log, "old_inodefmt int32_t 0x%08x\n",
317 sb->fs_old_inodefmt);
318 fprintf(dbg_log, "maxfilesize u_int64_t 0x%08x%08x\n",
319 ((unsigned int *)&(sb->fs_maxfilesize))[1],
320 ((unsigned int *)&(sb->fs_maxfilesize))[0]);
321 fprintf(dbg_log, "qbmask int64_t 0x%08x%08x\n",
322 ((unsigned int *)&(sb->fs_qbmask))[1],
323 ((unsigned int *)&(sb->fs_qbmask))[0]);
324 fprintf(dbg_log, "qfmask int64_t 0x%08x%08x\n",
325 ((unsigned int *)&(sb->fs_qfmask))[1],
326 ((unsigned int *)&(sb->fs_qfmask))[0]);
327 fprintf(dbg_log, "state int32_t 0x%08x\n",
329 fprintf(dbg_log, "old_postblformat int32_t 0x%08x\n",
330 sb->fs_old_postblformat);
331 fprintf(dbg_log, "old_nrpos int32_t 0x%08x\n",
333 fprintf(dbg_log, "spare5 int32_t[2] 0x%08x 0x%08x\n",
334 sb->fs_spare5[0], sb->fs_spare5[1]);
335 fprintf(dbg_log, "magic int32_t 0x%08x\n",
339 fprintf(dbg_log, "===== END SUPERBLOCK =====\n");
345 * Dump a cylinder group.
348 dbg_dump_cg(const char *comment, struct cg *cgr)
355 fprintf(dbg_log, "===== START CYLINDER GROUP =====\n");
356 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
359 fprintf(dbg_log, "magic int32_t 0x%08x\n", cgr->cg_magic);
360 fprintf(dbg_log, "old_time int32_t 0x%08x\n", cgr->cg_old_time);
361 fprintf(dbg_log, "cgx int32_t 0x%08x\n", cgr->cg_cgx);
362 fprintf(dbg_log, "old_ncyl int16_t 0x%04x\n", cgr->cg_old_ncyl);
363 fprintf(dbg_log, "old_niblk int16_t 0x%04x\n", cgr->cg_old_niblk);
364 fprintf(dbg_log, "ndblk int32_t 0x%08x\n", cgr->cg_ndblk);
365 dbg_dump_csum("internal cs", &cgr->cg_cs);
366 fprintf(dbg_log, "rotor int32_t 0x%08x\n", cgr->cg_rotor);
367 fprintf(dbg_log, "frotor int32_t 0x%08x\n", cgr->cg_frotor);
368 fprintf(dbg_log, "irotor int32_t 0x%08x\n", cgr->cg_irotor);
369 for (j = 0; j < MAXFRAG; j++) {
370 fprintf(dbg_log, "frsum int32_t[%d] 0x%08x\n", j,
373 fprintf(dbg_log, "old_btotoff int32_t 0x%08x\n", cgr->cg_old_btotoff);
374 fprintf(dbg_log, "old_boff int32_t 0x%08x\n", cgr->cg_old_boff);
375 fprintf(dbg_log, "iusedoff int32_t 0x%08x\n", cgr->cg_iusedoff);
376 fprintf(dbg_log, "freeoff int32_t 0x%08x\n", cgr->cg_freeoff);
377 fprintf(dbg_log, "nextfreeoff int32_t 0x%08x\n",
378 cgr->cg_nextfreeoff);
379 fprintf(dbg_log, "clustersumoff int32_t 0x%08x\n",
380 cgr->cg_clustersumoff);
381 fprintf(dbg_log, "clusteroff int32_t 0x%08x\n",
383 fprintf(dbg_log, "nclusterblks int32_t 0x%08x\n",
384 cgr->cg_nclusterblks);
385 fprintf(dbg_log, "niblk int32_t 0x%08x\n", cgr->cg_niblk);
386 fprintf(dbg_log, "initediblk int32_t 0x%08x\n", cgr->cg_initediblk);
387 fprintf(dbg_log, "unrefs int32_t 0x%08x\n", cgr->cg_unrefs);
388 fprintf(dbg_log, "time ufs_time_t %10u\n",
389 (unsigned int)cgr->cg_initediblk);
392 fprintf(dbg_log, "===== END CYLINDER GROUP =====\n");
398 * Dump a cylinder summary.
401 dbg_dump_csum(const char *comment, struct csum *cs)
407 fprintf(dbg_log, "===== START CYLINDER SUMMARY =====\n");
408 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cs, comment);
411 fprintf(dbg_log, "ndir int32_t 0x%08x\n", cs->cs_ndir);
412 fprintf(dbg_log, "nbfree int32_t 0x%08x\n", cs->cs_nbfree);
413 fprintf(dbg_log, "nifree int32_t 0x%08x\n", cs->cs_nifree);
414 fprintf(dbg_log, "nffree int32_t 0x%08x\n", cs->cs_nffree);
417 fprintf(dbg_log, "===== END CYLINDER SUMMARY =====\n");
423 * Dump a cylinder summary.
426 dbg_dump_csum_total(const char *comment, struct csum_total *cs)
432 fprintf(dbg_log, "===== START CYLINDER SUMMARY TOTAL =====\n");
433 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cs, comment);
436 fprintf(dbg_log, "ndir int64_t 0x%08x%08x\n",
437 ((unsigned int *)&(cs->cs_ndir))[1],
438 ((unsigned int *)&(cs->cs_ndir))[0]);
439 fprintf(dbg_log, "nbfree int64_t 0x%08x%08x\n",
440 ((unsigned int *)&(cs->cs_nbfree))[1],
441 ((unsigned int *)&(cs->cs_nbfree))[0]);
442 fprintf(dbg_log, "nifree int64_t 0x%08x%08x\n",
443 ((unsigned int *)&(cs->cs_nifree))[1],
444 ((unsigned int *)&(cs->cs_nifree))[0]);
445 fprintf(dbg_log, "nffree int64_t 0x%08x%08x\n",
446 ((unsigned int *)&(cs->cs_nffree))[1],
447 ((unsigned int *)&(cs->cs_nffree))[0]);
448 fprintf(dbg_log, "numclusters int64_t 0x%08x%08x\n",
449 ((unsigned int *)&(cs->cs_numclusters))[1],
450 ((unsigned int *)&(cs->cs_numclusters))[0]);
453 fprintf(dbg_log, "===== END CYLINDER SUMMARY TOTAL =====\n");
458 * Dump the inode allocation map in one cylinder group.
461 dbg_dump_inmap(struct fs *sb, const char *comment, struct cg *cgr)
469 fprintf(dbg_log, "===== START INODE ALLOCATION MAP =====\n");
470 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
473 cp = (unsigned char *)cg_inosused(cgr);
475 for (j = 0; j < e; j += 32) {
476 fprintf(dbg_log, "%08x: ", j);
477 for (k = 0; k < 32; k += 8) {
480 "%02x%02x%02x%02x%02x%02x%02x%02x ",
481 cp[0], cp[1], cp[2], cp[3],
482 cp[4], cp[5], cp[6], cp[7]);
484 for (l = 0; (l < 8) && (j + k + l < e); l++) {
485 fprintf(dbg_log, "%02x", cp[l]);
490 fprintf(dbg_log, "\n");
494 fprintf(dbg_log, "===== END INODE ALLOCATION MAP =====\n");
501 * Dump the fragment allocation map in one cylinder group.
504 dbg_dump_frmap(struct fs *sb, const char *comment, struct cg *cgr)
512 fprintf(dbg_log, "===== START FRAGMENT ALLOCATION MAP =====\n");
513 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
516 cp = (unsigned char *)cg_blksfree(cgr);
518 e = howmany(sb->fs_old_cpg * sb->fs_old_spc / sb->fs_old_nspf,
522 for (j = 0; j < e; j += 32) {
523 fprintf(dbg_log, "%08x: ", j);
524 for (k = 0; k < 32; k += 8) {
527 "%02x%02x%02x%02x%02x%02x%02x%02x ",
528 cp[0], cp[1], cp[2], cp[3],
529 cp[4], cp[5], cp[6], cp[7]);
531 for (l = 0; (l < 8) && (j + k + l < e); l++) {
532 fprintf(dbg_log, "%02x", cp[l]);
537 fprintf(dbg_log, "\n");
541 fprintf(dbg_log, "===== END FRAGMENT ALLOCATION MAP =====\n");
547 * Dump the cluster allocation map in one cylinder group.
550 dbg_dump_clmap(struct fs *sb, const char *comment, struct cg *cgr)
558 fprintf(dbg_log, "===== START CLUSTER ALLOCATION MAP =====\n");
559 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
562 cp = (unsigned char *)cg_clustersfree(cgr);
564 e = howmany(sb->fs_old_cpg * sb->fs_old_spc / (sb->fs_old_nspf << sb->fs_fragshift), CHAR_BIT);
567 for (j = 0; j < e; j += 32) {
568 fprintf(dbg_log, "%08x: ", j);
569 for (k = 0; k < 32; k += 8) {
572 "%02x%02x%02x%02x%02x%02x%02x%02x ",
573 cp[0], cp[1], cp[2], cp[3],
574 cp[4], cp[5], cp[6], cp[7]);
576 for (l = 0; (l < 8) && (j + k + l <e); l++) {
577 fprintf(dbg_log, "%02x", cp[l]);
582 fprintf(dbg_log, "\n");
586 fprintf(dbg_log, "===== END CLUSTER ALLOCATION MAP =====\n");
592 * Dump the cluster availability summary of one cylinder group.
595 dbg_dump_clsum(struct fs *sb, const char *comment, struct cg *cgr)
603 fprintf(dbg_log, "===== START CLUSTER SUMMARY =====\n");
604 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
607 ip = (int *)cg_clustersum(cgr);
608 for (j = 0; j <= sb->fs_contigsumsize; j++) {
609 fprintf(dbg_log, "%02d: %8d\n", j, *ip++);
613 fprintf(dbg_log, "===== END CLUSTER SUMMARY =====\n");
620 * This code dates from before the UFS2 integration, and doesn't compile
621 * post-UFS2 due to the use of cg_blks(). I'm not sure how best to update
622 * this for UFS2, where the rotational bits of UFS no longer apply, so
623 * will leave it disabled for now; it should probably be re-enabled
624 * specifically for UFS1.
627 * Dump the block summary, and the rotational layout table.
630 dbg_dump_sptbl(struct fs *sb, const char *comment, struct cg *cgr)
639 "===== START BLOCK SUMMARY AND POSITION TABLE =====\n");
640 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
643 ip = (int *)cg_blktot(cgr);
644 for (j = 0; j < sb->fs_old_cpg; j++) {
645 fprintf(dbg_log, "%2d: %5d = ", j, *ip++);
646 for (k = 0; k < sb->fs_old_nrpos; k++) {
647 fprintf(dbg_log, "%4d", cg_blks(sb, cgr, j)[k]);
648 if (k < sb->fs_old_nrpos - 1)
649 fprintf(dbg_log, " + ");
651 fprintf(dbg_log, "\n");
655 fprintf(dbg_log, "===== END BLOCK SUMMARY AND POSITION TABLE =====\n");
662 * Dump a UFS1 inode structure.
665 dbg_dump_ufs1_ino(struct fs *sb, const char *comment, struct ufs1_dinode *ino)
668 int remaining_blocks;
673 fprintf(dbg_log, "===== START UFS1 INODE DUMP =====\n");
674 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)ino, comment);
677 fprintf(dbg_log, "mode u_int16_t 0%o\n", ino->di_mode);
678 fprintf(dbg_log, "nlink int16_t 0x%04x\n", ino->di_nlink);
679 fprintf(dbg_log, "size u_int64_t 0x%08x%08x\n",
680 ((unsigned int *)&(ino->di_size))[1],
681 ((unsigned int *)&(ino->di_size))[0]);
682 fprintf(dbg_log, "atime int32_t 0x%08x\n", ino->di_atime);
683 fprintf(dbg_log, "atimensec int32_t 0x%08x\n",
685 fprintf(dbg_log, "mtime int32_t 0x%08x\n",
687 fprintf(dbg_log, "mtimensec int32_t 0x%08x\n",
689 fprintf(dbg_log, "ctime int32_t 0x%08x\n", ino->di_ctime);
690 fprintf(dbg_log, "ctimensec int32_t 0x%08x\n",
693 remaining_blocks = howmany(ino->di_size, sb->fs_bsize); /* XXX ts - +1? */
694 for (ictr = 0; ictr < MIN(UFS_NDADDR, remaining_blocks); ictr++) {
695 fprintf(dbg_log, "db ufs_daddr_t[%x] 0x%08x\n", ictr,
698 remaining_blocks -= UFS_NDADDR;
699 if (remaining_blocks > 0) {
700 fprintf(dbg_log, "ib ufs_daddr_t[0] 0x%08x\n",
703 remaining_blocks -= howmany(sb->fs_bsize, sizeof(ufs1_daddr_t));
704 if (remaining_blocks > 0) {
705 fprintf(dbg_log, "ib ufs_daddr_t[1] 0x%08x\n",
708 #define SQUARE(a) ((a) * (a))
709 remaining_blocks -= SQUARE(howmany(sb->fs_bsize, sizeof(ufs1_daddr_t)));
711 if (remaining_blocks > 0) {
712 fprintf(dbg_log, "ib ufs_daddr_t[2] 0x%08x\n",
716 fprintf(dbg_log, "flags u_int32_t 0x%08x\n", ino->di_flags);
717 fprintf(dbg_log, "blocks int32_t 0x%08x\n", ino->di_blocks);
718 fprintf(dbg_log, "gen int32_t 0x%08x\n", ino->di_gen);
719 fprintf(dbg_log, "uid u_int32_t 0x%08x\n", ino->di_uid);
720 fprintf(dbg_log, "gid u_int32_t 0x%08x\n", ino->di_gid);
723 fprintf(dbg_log, "===== END UFS1 INODE DUMP =====\n");
729 * Dump a UFS2 inode structure.
732 dbg_dump_ufs2_ino(struct fs *sb, const char *comment, struct ufs2_dinode *ino)
735 int remaining_blocks;
740 fprintf(dbg_log, "===== START UFS2 INODE DUMP =====\n");
741 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)ino, comment);
744 fprintf(dbg_log, "mode u_int16_t 0%o\n", ino->di_mode);
745 fprintf(dbg_log, "nlink int16_t 0x%04x\n", ino->di_nlink);
746 fprintf(dbg_log, "uid u_int32_t 0x%08x\n", ino->di_uid);
747 fprintf(dbg_log, "gid u_int32_t 0x%08x\n", ino->di_gid);
748 fprintf(dbg_log, "blksize u_int32_t 0x%08x\n", ino->di_blksize);
749 fprintf(dbg_log, "size u_int64_t 0x%08x%08x\n",
750 ((unsigned int *)&(ino->di_size))[1],
751 ((unsigned int *)&(ino->di_size))[0]);
752 fprintf(dbg_log, "blocks u_int64_t 0x%08x%08x\n",
753 ((unsigned int *)&(ino->di_blocks))[1],
754 ((unsigned int *)&(ino->di_blocks))[0]);
755 fprintf(dbg_log, "atime ufs_time_t %10jd\n", ino->di_atime);
756 fprintf(dbg_log, "mtime ufs_time_t %10jd\n", ino->di_mtime);
757 fprintf(dbg_log, "ctime ufs_time_t %10jd\n", ino->di_ctime);
758 fprintf(dbg_log, "birthtime ufs_time_t %10jd\n", ino->di_birthtime);
759 fprintf(dbg_log, "mtimensec int32_t 0x%08x\n", ino->di_mtimensec);
760 fprintf(dbg_log, "atimensec int32_t 0x%08x\n", ino->di_atimensec);
761 fprintf(dbg_log, "ctimensec int32_t 0x%08x\n", ino->di_ctimensec);
762 fprintf(dbg_log, "birthnsec int32_t 0x%08x\n", ino->di_birthnsec);
763 fprintf(dbg_log, "gen int32_t 0x%08x\n", ino->di_gen);
764 fprintf(dbg_log, "kernflags u_int32_t 0x%08x\n", ino->di_kernflags);
765 fprintf(dbg_log, "flags u_int32_t 0x%08x\n", ino->di_flags);
766 fprintf(dbg_log, "extsize u_int32_t 0x%08x\n", ino->di_extsize);
768 /* XXX: What do we do with di_extb[UFS_NXADDR]? */
770 remaining_blocks = howmany(ino->di_size, sb->fs_bsize); /* XXX ts - +1? */
771 for (ictr = 0; ictr < MIN(UFS_NDADDR, remaining_blocks); ictr++) {
772 fprintf(dbg_log, "db ufs2_daddr_t[%x] 0x%16jx\n", ictr,
775 remaining_blocks -= UFS_NDADDR;
776 if (remaining_blocks > 0) {
777 fprintf(dbg_log, "ib ufs2_daddr_t[0] 0x%16jx\n",
780 remaining_blocks -= howmany(sb->fs_bsize, sizeof(ufs2_daddr_t));
781 if (remaining_blocks > 0) {
782 fprintf(dbg_log, "ib ufs2_daddr_t[1] 0x%16jx\n",
785 #define SQUARE(a) ((a) * (a))
786 remaining_blocks -= SQUARE(howmany(sb->fs_bsize, sizeof(ufs2_daddr_t)));
788 if (remaining_blocks > 0) {
789 fprintf(dbg_log, "ib ufs2_daddr_t[2] 0x%16jx\n",
794 fprintf(dbg_log, "===== END UFS2 INODE DUMP =====\n");
800 * Dump an indirect block. The iteration to dump a full file has to be
804 dbg_dump_iblk(struct fs *sb, const char *comment, char *block, size_t length)
806 unsigned int *mem, i, j, size;
811 fprintf(dbg_log, "===== START INDIRECT BLOCK DUMP =====\n");
812 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)block,
816 if (sb->fs_magic == FS_UFS1_MAGIC)
817 size = sizeof(ufs1_daddr_t);
819 size = sizeof(ufs2_daddr_t);
821 mem = (unsigned int *)block;
822 for (i = 0; (size_t)i < MIN(howmany(sb->fs_bsize, size), length);
824 fprintf(dbg_log, "%04x: ", i);
825 for (j = 0; j < 8; j++) {
826 if ((size_t)(i + j) < length)
827 fprintf(dbg_log, "%08X ", *mem++);
829 fprintf(dbg_log, "\n");
833 fprintf(dbg_log, "===== END INDIRECT BLOCK DUMP =====\n");
838 #endif /* FS_DEBUG */