1331722Seadler/*
269800Stomsoft * Copyright (c) 2000 Christoph Herrmann, Thomas-Henning von Kamptz
369800Stomsoft * Copyright (c) 1980, 1989, 1993 The Regents of the University of California.
469800Stomsoft * All rights reserved.
569800Stomsoft *
669800Stomsoft * This code is derived from software contributed to Berkeley by
769800Stomsoft * Christoph Herrmann and Thomas-Henning von Kamptz, Munich and Frankfurt.
869800Stomsoft *
969800Stomsoft * Redistribution and use in source and binary forms, with or without
1069800Stomsoft * modification, are permitted provided that the following conditions
1169800Stomsoft * are met:
1269800Stomsoft * 1. Redistributions of source code must retain the above copyright
1369800Stomsoft *    notice, this list of conditions and the following disclaimer.
1469800Stomsoft * 2. Redistributions in binary form must reproduce the above copyright
1569800Stomsoft *    notice, this list of conditions and the following disclaimer in the
1669800Stomsoft *    documentation and/or other materials provided with the distribution.
1769800Stomsoft * 3. All advertising materials mentioning features or use of this software
1869800Stomsoft *    must display the following acknowledgment:
1969800Stomsoft *      This product includes software developed by the University of
2069800Stomsoft *      California, Berkeley and its contributors, as well as Christoph
2169800Stomsoft *      Herrmann and Thomas-Henning von Kamptz.
2269800Stomsoft * 4. Neither the name of the University nor the names of its contributors
2369800Stomsoft *    may be used to endorse or promote products derived from this software
2469800Stomsoft *    without specific prior written permission.
2569800Stomsoft *
2669800Stomsoft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2769800Stomsoft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2869800Stomsoft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2969800Stomsoft * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3069800Stomsoft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3169800Stomsoft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3269800Stomsoft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3369800Stomsoft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3469800Stomsoft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3569800Stomsoft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3669800Stomsoft * SUCH DAMAGE.
3769800Stomsoft *
3869926Stomsoft * $TSHeader: src/sbin/growfs/debug.c,v 1.3 2000/12/12 19:31:00 tomsoft Exp $
3969800Stomsoft *
4069800Stomsoft */
4169800Stomsoft
4269800Stomsoft#ifndef lint
4369800Stomsoftstatic const char rcsid[] =
4469926Stomsoft  "$FreeBSD$";
4569800Stomsoft#endif /* not lint */
4669800Stomsoft
4769800Stomsoft#include <sys/param.h>
4869800Stomsoft
49103949Smike#include <limits.h>
5069800Stomsoft#include <stdio.h>
51127798Sle#include <string.h>
5269800Stomsoft#include <ufs/ufs/dinode.h>
5369800Stomsoft#include <ufs/ffs/fs.h>
5469800Stomsoft
5569800Stomsoft#include "debug.h"
5669800Stomsoft
5769800Stomsoft#ifdef FS_DEBUG
5869800Stomsoft
59232548Straszstatic FILE		*dbg_log = NULL;
60232548Straszstatic unsigned int	indent = 0;
6169800Stomsoft
6269800Stomsoft/*
6369800Stomsoft * prototypes not done here, as they come with debug.h
6469800Stomsoft */
6569800Stomsoft
6669800Stomsoft/*
6769800Stomsoft * Open the filehandle where all debug output has to go.
6869800Stomsoft */
6969800Stomsoftvoid
7069800Stomsoftdbg_open(const char *fn)
7169800Stomsoft{
7269800Stomsoft
7392743Srwatson	if (strcmp(fn, "-") == 0)
74232548Strasz		dbg_log = fopen("/dev/stdout", "a");
7592743Srwatson	else
76232548Strasz		dbg_log = fopen(fn, "a");
7769800Stomsoft
7869800Stomsoft	return;
7969800Stomsoft}
8069800Stomsoft
8169800Stomsoft/*
8269800Stomsoft * Close the filehandle where all debug output went to.
8369800Stomsoft */
8469800Stomsoftvoid
8569800Stomsoftdbg_close(void)
8669800Stomsoft{
8769800Stomsoft
88232548Strasz	if (dbg_log) {
8969800Stomsoft		fclose(dbg_log);
90232548Strasz		dbg_log = NULL;
9169800Stomsoft	}
9269800Stomsoft
9369800Stomsoft	return;
9469800Stomsoft}
9569800Stomsoft
9669800Stomsoft/*
97102231Strhodes * Dump out a full file system block in hex.
9869800Stomsoft */
9969800Stomsoftvoid
10069800Stomsoftdbg_dump_hex(struct fs *sb, const char *comment, unsigned char *mem)
10169800Stomsoft{
10269800Stomsoft	int i, j, k;
10369800Stomsoft
104232548Strasz	if (!dbg_log)
10569800Stomsoft		return;
106232548Strasz
10769800Stomsoft	fprintf(dbg_log, "===== START HEXDUMP =====\n");
10869800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)mem, comment);
10969800Stomsoft	indent++;
110232548Strasz	for (i = 0; i < sb->fs_bsize; i += 24) {
111232548Strasz		for (j = 0; j < 3; j++) {
112232548Strasz			for (k = 0; k < 8; k++)
11369800Stomsoft				fprintf(dbg_log, "%02x ", *mem++);
11469800Stomsoft			fprintf(dbg_log, "  ");
11569800Stomsoft		}
11669800Stomsoft		fprintf(dbg_log, "\n");
11769800Stomsoft	}
11869800Stomsoft	indent--;
11969800Stomsoft	fprintf(dbg_log, "===== END HEXDUMP =====\n");
12069800Stomsoft
12169800Stomsoft	return;
12269800Stomsoft}
12369800Stomsoft
12469800Stomsoft/*
12569800Stomsoft * Dump the superblock.
12669800Stomsoft */
12769800Stomsoftvoid
12869800Stomsoftdbg_dump_fs(struct fs *sb, const char *comment)
12969800Stomsoft{
130232548Strasz	int j;
13169800Stomsoft
132232548Strasz	if (!dbg_log)
13369800Stomsoft		return;
13469800Stomsoft
13569800Stomsoft	fprintf(dbg_log, "===== START SUPERBLOCK =====\n");
13669800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)sb, comment);
13769800Stomsoft	indent++;
13869800Stomsoft
139118915Srwatson	fprintf(dbg_log, "sblkno            int32_t          0x%08x\n",
14069800Stomsoft	    sb->fs_sblkno);
141118915Srwatson	fprintf(dbg_log, "cblkno            int32_t          0x%08x\n",
14269800Stomsoft	    sb->fs_cblkno);
143118915Srwatson	fprintf(dbg_log, "iblkno            int32_t          0x%08x\n",
14469800Stomsoft	    sb->fs_iblkno);
145118915Srwatson	fprintf(dbg_log, "dblkno            int32_t          0x%08x\n",
14669800Stomsoft	    sb->fs_dblkno);
14769800Stomsoft
148118915Srwatson	fprintf(dbg_log, "old_cgoffset      int32_t          0x%08x\n",
149118915Srwatson	    sb->fs_old_cgoffset);
150118915Srwatson	fprintf(dbg_log, "old_cgmask        int32_t          0x%08x\n",
151118915Srwatson	    sb->fs_old_cgmask);
152118915Srwatson	fprintf(dbg_log, "old_time          int32_t          %10u\n",
153118915Srwatson	    (unsigned int)sb->fs_old_time);
154118915Srwatson	fprintf(dbg_log, "old_size          int32_t          0x%08x\n",
155118915Srwatson	    sb->fs_old_size);
156118915Srwatson	fprintf(dbg_log, "old_dsize         int32_t          0x%08x\n",
157118915Srwatson	    sb->fs_old_dsize);
158118915Srwatson	fprintf(dbg_log, "ncg               int32_t          0x%08x\n",
15969800Stomsoft	    sb->fs_ncg);
160118915Srwatson	fprintf(dbg_log, "bsize             int32_t          0x%08x\n",
16169800Stomsoft	    sb->fs_bsize);
162118915Srwatson	fprintf(dbg_log, "fsize             int32_t          0x%08x\n",
16369800Stomsoft	    sb->fs_fsize);
164118915Srwatson	fprintf(dbg_log, "frag              int32_t          0x%08x\n",
16569800Stomsoft	    sb->fs_frag);
16669800Stomsoft
167118915Srwatson	fprintf(dbg_log, "minfree           int32_t          0x%08x\n",
16869800Stomsoft	    sb->fs_minfree);
169118915Srwatson	fprintf(dbg_log, "old_rotdelay      int32_t          0x%08x\n",
170118915Srwatson	    sb->fs_old_rotdelay);
171118915Srwatson	fprintf(dbg_log, "old_rps           int32_t          0x%08x\n",
172118915Srwatson	    sb->fs_old_rps);
17369800Stomsoft
174118915Srwatson	fprintf(dbg_log, "bmask             int32_t          0x%08x\n",
17569800Stomsoft	    sb->fs_bmask);
176118915Srwatson	fprintf(dbg_log, "fmask             int32_t          0x%08x\n",
17769800Stomsoft	    sb->fs_fmask);
178118915Srwatson	fprintf(dbg_log, "bshift            int32_t          0x%08x\n",
17969800Stomsoft	    sb->fs_bshift);
180118915Srwatson	fprintf(dbg_log, "fshift            int32_t          0x%08x\n",
18169800Stomsoft	    sb->fs_fshift);
18269800Stomsoft
183118915Srwatson	fprintf(dbg_log, "maxcontig         int32_t          0x%08x\n",
18469800Stomsoft	    sb->fs_maxcontig);
185118915Srwatson	fprintf(dbg_log, "maxbpg            int32_t          0x%08x\n",
18669800Stomsoft	    sb->fs_maxbpg);
18769800Stomsoft
188118915Srwatson	fprintf(dbg_log, "fragshift         int32_t          0x%08x\n",
18969800Stomsoft	    sb->fs_fragshift);
190118915Srwatson	fprintf(dbg_log, "fsbtodb           int32_t          0x%08x\n",
19169800Stomsoft	    sb->fs_fsbtodb);
192118915Srwatson	fprintf(dbg_log, "sbsize            int32_t          0x%08x\n",
19369800Stomsoft	    sb->fs_sbsize);
194118915Srwatson	fprintf(dbg_log, "spare1            int32_t[2]       0x%08x 0x%08x\n",
195118915Srwatson	    sb->fs_spare1[0], sb->fs_spare1[1]);
196118915Srwatson	fprintf(dbg_log, "nindir            int32_t          0x%08x\n",
19769800Stomsoft	    sb->fs_nindir);
198118915Srwatson	fprintf(dbg_log, "inopb             int32_t          0x%08x\n",
19969800Stomsoft	    sb->fs_inopb);
200118915Srwatson	fprintf(dbg_log, "old_nspf          int32_t          0x%08x\n",
201118915Srwatson	    sb->fs_old_nspf);
20269800Stomsoft
203118915Srwatson	fprintf(dbg_log, "optim             int32_t          0x%08x\n",
20469800Stomsoft	    sb->fs_optim);
20569800Stomsoft
206118915Srwatson	fprintf(dbg_log, "old_npsect        int32_t          0x%08x\n",
207118915Srwatson	    sb->fs_old_npsect);
208118915Srwatson	fprintf(dbg_log, "old_interleave    int32_t          0x%08x\n",
209118915Srwatson	    sb->fs_old_interleave);
210118915Srwatson	fprintf(dbg_log, "old_trackskew     int32_t          0x%08x\n",
211118915Srwatson	    sb->fs_old_trackskew);
21269800Stomsoft
213118915Srwatson	fprintf(dbg_log, "id                int32_t[2]       0x%08x 0x%08x\n",
21469800Stomsoft	    sb->fs_id[0], sb->fs_id[1]);
21569800Stomsoft
216118915Srwatson	fprintf(dbg_log, "old_csaddr        int32_t          0x%08x\n",
217118915Srwatson	    sb->fs_old_csaddr);
218118915Srwatson	fprintf(dbg_log, "cssize            int32_t          0x%08x\n",
21969800Stomsoft	    sb->fs_cssize);
220118915Srwatson	fprintf(dbg_log, "cgsize            int32_t          0x%08x\n",
22169800Stomsoft	    sb->fs_cgsize);
22269800Stomsoft
223118915Srwatson	fprintf(dbg_log, "spare2            int32_t          0x%08x\n",
224118915Srwatson	    sb->fs_spare2);
225118915Srwatson	fprintf(dbg_log, "old_nsect         int32_t          0x%08x\n",
226118915Srwatson	    sb->fs_old_nsect);
227118915Srwatson	fprintf(dbg_log, "old_spc           int32_t          0x%08x\n",
228118915Srwatson	    sb->fs_old_spc);
22969800Stomsoft
230118915Srwatson	fprintf(dbg_log, "old_ncyl          int32_t          0x%08x\n",
231118915Srwatson	    sb->fs_old_ncyl);
23269800Stomsoft
233118915Srwatson	fprintf(dbg_log, "old_cpg           int32_t          0x%08x\n",
234118915Srwatson	    sb->fs_old_cpg);
235118915Srwatson	fprintf(dbg_log, "ipg               int32_t          0x%08x\n",
23669800Stomsoft	    sb->fs_ipg);
237118915Srwatson	fprintf(dbg_log, "fpg               int32_t          0x%08x\n",
23869800Stomsoft	    sb->fs_fpg);
23969800Stomsoft
240118915Srwatson	dbg_dump_csum("internal old_cstotal", &sb->fs_old_cstotal);
24169800Stomsoft
242118915Srwatson	fprintf(dbg_log, "fmod              int8_t           0x%02x\n",
24369800Stomsoft	    sb->fs_fmod);
244118915Srwatson	fprintf(dbg_log, "clean             int8_t           0x%02x\n",
24569800Stomsoft	    sb->fs_clean);
246118915Srwatson	fprintf(dbg_log, "ronly             int8_t           0x%02x\n",
24769800Stomsoft	    sb->fs_ronly);
248118915Srwatson	fprintf(dbg_log, "old_flags         int8_t           0x%02x\n",
249118915Srwatson	    sb->fs_old_flags);
250118915Srwatson	fprintf(dbg_log, "fsmnt             u_char[MAXMNTLEN] \"%s\"\n",
25169800Stomsoft	    sb->fs_fsmnt);
252118915Srwatson	fprintf(dbg_log, "volname           u_char[MAXVOLLEN] \"%s\"\n",
253118915Srwatson	    sb->fs_volname);
254118915Srwatson	fprintf(dbg_log, "swuid             u_int64_t        0x%08x%08x\n",
255118915Srwatson	    ((unsigned int *)&(sb->fs_swuid))[1],
256118915Srwatson		((unsigned int *)&(sb->fs_swuid))[0]);
25769800Stomsoft
258118915Srwatson	fprintf(dbg_log, "pad               int32_t          0x%08x\n",
259118915Srwatson	    sb->fs_pad);
260118915Srwatson
261118915Srwatson	fprintf(dbg_log, "cgrotor           int32_t          0x%08x\n",
26269800Stomsoft	    sb->fs_cgrotor);
26369800Stomsoft/*
26469800Stomsoft * struct csum[MAXCSBUFS] - is only maintained in memory
26569800Stomsoft */
26669800Stomsoft/*	fprintf(dbg_log, " int32_t\n", sb->*fs_maxcluster);*/
267118915Srwatson	fprintf(dbg_log, "old_cpc           int32_t          0x%08x\n",
268118915Srwatson	    sb->fs_old_cpc);
26969800Stomsoft/*
27069800Stomsoft * int16_t fs_opostbl[16][8] - is dumped when used in dbg_dump_sptbl
27169800Stomsoft */
272118915Srwatson	fprintf(dbg_log, "maxbsize          int32_t          0x%08x\n",
273118915Srwatson	    sb->fs_maxbsize);
274215704Sbrucec	fprintf(dbg_log, "unrefs            int64_t          0x%08jx\n",
275163844Spjd	    sb->fs_unrefs);
276118915Srwatson	fprintf(dbg_log, "sblockloc         int64_t          0x%08x%08x\n",
277118915Srwatson		((unsigned int *)&(sb->fs_sblockloc))[1],
278118915Srwatson		((unsigned int *)&(sb->fs_sblockloc))[0]);
279118915Srwatson
280118915Srwatson	dbg_dump_csum_total("internal cstotal", &sb->fs_cstotal);
281118915Srwatson
282118915Srwatson	fprintf(dbg_log, "time              ufs_time_t       %10u\n",
283118915Srwatson	    (unsigned int)sb->fs_time);
284118915Srwatson
285118915Srwatson	fprintf(dbg_log, "size              int64_t          0x%08x%08x\n",
286118915Srwatson		((unsigned int *)&(sb->fs_size))[1],
287118915Srwatson		((unsigned int *)&(sb->fs_size))[0]);
288118915Srwatson	fprintf(dbg_log, "dsize             int64_t          0x%08x%08x\n",
289118915Srwatson		((unsigned int *)&(sb->fs_dsize))[1],
290118915Srwatson		((unsigned int *)&(sb->fs_dsize))[0]);
291118915Srwatson	fprintf(dbg_log, "csaddr            ufs2_daddr_t     0x%08x%08x\n",
292118915Srwatson		((unsigned int *)&(sb->fs_csaddr))[1],
293118915Srwatson		((unsigned int *)&(sb->fs_csaddr))[0]);
294118915Srwatson	fprintf(dbg_log, "pendingblocks     int64_t          0x%08x%08x\n",
295118915Srwatson		((unsigned int *)&(sb->fs_pendingblocks))[1],
296118915Srwatson		((unsigned int *)&(sb->fs_pendingblocks))[0]);
297118915Srwatson	fprintf(dbg_log, "pendinginodes     int32_t          0x%08x\n",
298118915Srwatson	    sb->fs_pendinginodes);
299118915Srwatson
300232548Strasz	for (j = 0; j < FSMAXSNAP; j++) {
301118915Srwatson		fprintf(dbg_log, "snapinum          int32_t[%2d]      0x%08x\n",
30269800Stomsoft		    j, sb->fs_snapinum[j]);
303232548Strasz		if (!sb->fs_snapinum[j]) { /* list is dense */
30469800Stomsoft			break;
30569800Stomsoft		}
30669800Stomsoft	}
307118915Srwatson	fprintf(dbg_log, "avgfilesize       int32_t          0x%08x\n",
308118915Srwatson	    sb->fs_avgfilesize);
309118915Srwatson	fprintf(dbg_log, "avgfpdir          int32_t          0x%08x\n",
310118915Srwatson	    sb->fs_avgfpdir);
311118915Srwatson	fprintf(dbg_log, "save_cgsize       int32_t          0x%08x\n",
312118915Srwatson	    sb->fs_save_cgsize);
313118915Srwatson	fprintf(dbg_log, "flags             int32_t          0x%08x\n",
314118915Srwatson	    sb->fs_flags);
315118915Srwatson	fprintf(dbg_log, "contigsumsize     int32_t          0x%08x\n",
31669800Stomsoft	    sb->fs_contigsumsize);
317118915Srwatson	fprintf(dbg_log, "maxsymlinklen     int32_t          0x%08x\n",
31869800Stomsoft	    sb->fs_maxsymlinklen);
319118915Srwatson	fprintf(dbg_log, "old_inodefmt      int32_t          0x%08x\n",
320118915Srwatson	    sb->fs_old_inodefmt);
321118915Srwatson	fprintf(dbg_log, "maxfilesize       u_int64_t        0x%08x%08x\n",
32269800Stomsoft	    ((unsigned int *)&(sb->fs_maxfilesize))[1],
32369800Stomsoft	    ((unsigned int *)&(sb->fs_maxfilesize))[0]);
324118915Srwatson	fprintf(dbg_log, "qbmask            int64_t          0x%08x%08x\n",
32569800Stomsoft	    ((unsigned int *)&(sb->fs_qbmask))[1],
32669800Stomsoft	    ((unsigned int *)&(sb->fs_qbmask))[0]);
327118915Srwatson	fprintf(dbg_log, "qfmask            int64_t          0x%08x%08x\n",
32869800Stomsoft	    ((unsigned int *)&(sb->fs_qfmask))[1],
32969800Stomsoft	    ((unsigned int *)&(sb->fs_qfmask))[0]);
330118915Srwatson	fprintf(dbg_log, "state             int32_t          0x%08x\n",
33169800Stomsoft	    sb->fs_state);
332118915Srwatson	fprintf(dbg_log, "old_postblformat  int32_t          0x%08x\n",
333118915Srwatson	    sb->fs_old_postblformat);
334118915Srwatson	fprintf(dbg_log, "old_nrpos         int32_t          0x%08x\n",
335118915Srwatson	    sb->fs_old_nrpos);
336118915Srwatson	fprintf(dbg_log, "spare5            int32_t[2]       0x%08x 0x%08x\n",
337118915Srwatson	    sb->fs_spare5[0], sb->fs_spare5[1]);
338118915Srwatson	fprintf(dbg_log, "magic             int32_t          0x%08x\n",
33969800Stomsoft	    sb->fs_magic);
34069800Stomsoft
34169800Stomsoft	indent--;
34269800Stomsoft	fprintf(dbg_log, "===== END SUPERBLOCK =====\n");
34369800Stomsoft
34469800Stomsoft	return;
34569800Stomsoft}
34669800Stomsoft
34769800Stomsoft/*
34869800Stomsoft * Dump a cylinder group.
34969800Stomsoft */
35069800Stomsoftvoid
35169800Stomsoftdbg_dump_cg(const char *comment, struct cg *cgr)
35269800Stomsoft{
35369800Stomsoft	int j;
35469800Stomsoft
355232548Strasz	if (!dbg_log)
35669800Stomsoft		return;
35769800Stomsoft
35869800Stomsoft	fprintf(dbg_log, "===== START CYLINDER GROUP =====\n");
35969800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
36069800Stomsoft	indent++;
36169800Stomsoft
36269800Stomsoft	fprintf(dbg_log, "magic         int32_t    0x%08x\n", cgr->cg_magic);
363118915Srwatson	fprintf(dbg_log, "old_time      int32_t    0x%08x\n", cgr->cg_old_time);
36469800Stomsoft	fprintf(dbg_log, "cgx           int32_t    0x%08x\n", cgr->cg_cgx);
365118915Srwatson	fprintf(dbg_log, "old_ncyl      int16_t    0x%04x\n", cgr->cg_old_ncyl);
366118915Srwatson	fprintf(dbg_log, "old_niblk     int16_t    0x%04x\n", cgr->cg_old_niblk);
36769800Stomsoft	fprintf(dbg_log, "ndblk         int32_t    0x%08x\n", cgr->cg_ndblk);
36869800Stomsoft	dbg_dump_csum("internal cs", &cgr->cg_cs);
36969800Stomsoft	fprintf(dbg_log, "rotor         int32_t    0x%08x\n", cgr->cg_rotor);
37069800Stomsoft	fprintf(dbg_log, "frotor        int32_t    0x%08x\n", cgr->cg_frotor);
37169800Stomsoft	fprintf(dbg_log, "irotor        int32_t    0x%08x\n", cgr->cg_irotor);
372232548Strasz	for (j = 0; j < MAXFRAG; j++) {
37369800Stomsoft		fprintf(dbg_log, "frsum         int32_t[%d] 0x%08x\n", j,
37469800Stomsoft		    cgr->cg_frsum[j]);
37569800Stomsoft	}
376118915Srwatson	fprintf(dbg_log, "old_btotoff   int32_t    0x%08x\n", cgr->cg_old_btotoff);
377118915Srwatson	fprintf(dbg_log, "old_boff      int32_t    0x%08x\n", cgr->cg_old_boff);
37869800Stomsoft	fprintf(dbg_log, "iusedoff      int32_t    0x%08x\n", cgr->cg_iusedoff);
37969800Stomsoft	fprintf(dbg_log, "freeoff       int32_t    0x%08x\n", cgr->cg_freeoff);
38069800Stomsoft	fprintf(dbg_log, "nextfreeoff   int32_t    0x%08x\n",
38169800Stomsoft	    cgr->cg_nextfreeoff);
38269800Stomsoft	fprintf(dbg_log, "clustersumoff int32_t    0x%08x\n",
38369800Stomsoft	    cgr->cg_clustersumoff);
384118915Srwatson	fprintf(dbg_log, "clusteroff    int32_t    0x%08x\n",
38569800Stomsoft	    cgr->cg_clusteroff);
38669800Stomsoft	fprintf(dbg_log, "nclusterblks  int32_t    0x%08x\n",
38769800Stomsoft	    cgr->cg_nclusterblks);
388118915Srwatson	fprintf(dbg_log, "niblk         int32_t    0x%08x\n", cgr->cg_niblk);
389118915Srwatson	fprintf(dbg_log, "initediblk    int32_t    0x%08x\n", cgr->cg_initediblk);
390163844Spjd	fprintf(dbg_log, "unrefs        int32_t    0x%08x\n", cgr->cg_unrefs);
391118915Srwatson	fprintf(dbg_log, "time          ufs_time_t %10u\n",
392118915Srwatson		(unsigned int)cgr->cg_initediblk);
39369800Stomsoft
39469800Stomsoft	indent--;
39569800Stomsoft	fprintf(dbg_log, "===== END CYLINDER GROUP =====\n");
39669800Stomsoft
39769800Stomsoft	return;
39869800Stomsoft}
39969800Stomsoft
40069800Stomsoft/*
40169800Stomsoft * Dump a cylinder summary.
40269800Stomsoft */
40369800Stomsoftvoid
40469800Stomsoftdbg_dump_csum(const char *comment, struct csum *cs)
40569800Stomsoft{
40669800Stomsoft
407232548Strasz	if (!dbg_log)
40869800Stomsoft		return;
40969800Stomsoft
41069800Stomsoft	fprintf(dbg_log, "===== START CYLINDER SUMMARY =====\n");
41169800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cs, comment);
41269800Stomsoft	indent++;
41369800Stomsoft
41469800Stomsoft	fprintf(dbg_log, "ndir   int32_t 0x%08x\n", cs->cs_ndir);
41569800Stomsoft	fprintf(dbg_log, "nbfree int32_t 0x%08x\n", cs->cs_nbfree);
41669800Stomsoft	fprintf(dbg_log, "nifree int32_t 0x%08x\n", cs->cs_nifree);
41769800Stomsoft	fprintf(dbg_log, "nffree int32_t 0x%08x\n", cs->cs_nffree);
41869800Stomsoft
41969800Stomsoft	indent--;
42069800Stomsoft	fprintf(dbg_log, "===== END CYLINDER SUMMARY =====\n");
42169800Stomsoft
42269800Stomsoft	return;
42369800Stomsoft}
42469800Stomsoft
425118915Srwatson/*
426118915Srwatson * Dump a cylinder summary.
427118915Srwatson */
428118915Srwatsonvoid
429118915Srwatsondbg_dump_csum_total(const char *comment, struct csum_total *cs)
430118915Srwatson{
431118915Srwatson
432232548Strasz	if (!dbg_log)
433118915Srwatson		return;
434118915Srwatson
435118915Srwatson	fprintf(dbg_log, "===== START CYLINDER SUMMARY TOTAL =====\n");
436118915Srwatson	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cs, comment);
437118915Srwatson	indent++;
438118915Srwatson
439118915Srwatson	fprintf(dbg_log, "ndir        int64_t 0x%08x%08x\n",
440118915Srwatson		((unsigned int *)&(cs->cs_ndir))[1],
441118915Srwatson		((unsigned int *)&(cs->cs_ndir))[0]);
442118915Srwatson	fprintf(dbg_log, "nbfree      int64_t 0x%08x%08x\n",
443118915Srwatson		((unsigned int *)&(cs->cs_nbfree))[1],
444118915Srwatson		((unsigned int *)&(cs->cs_nbfree))[0]);
445118915Srwatson	fprintf(dbg_log, "nifree      int64_t 0x%08x%08x\n",
446118915Srwatson		((unsigned int *)&(cs->cs_nifree))[1],
447118915Srwatson		((unsigned int *)&(cs->cs_nifree))[0]);
448118915Srwatson	fprintf(dbg_log, "nffree      int64_t 0x%08x%08x\n",
449118915Srwatson		((unsigned int *)&(cs->cs_nffree))[1],
450118915Srwatson		((unsigned int *)&(cs->cs_nffree))[0]);
451118915Srwatson	fprintf(dbg_log, "numclusters int64_t 0x%08x%08x\n",
452118915Srwatson		((unsigned int *)&(cs->cs_numclusters))[1],
453118915Srwatson		((unsigned int *)&(cs->cs_numclusters))[0]);
454118915Srwatson
455118915Srwatson	indent--;
456118915Srwatson	fprintf(dbg_log, "===== END CYLINDER SUMMARY TOTAL =====\n");
457118915Srwatson
458118915Srwatson	return;
459118915Srwatson}
46069800Stomsoft/*
46169800Stomsoft * Dump the inode allocation map in one cylinder group.
46269800Stomsoft */
46369800Stomsoftvoid
46469800Stomsoftdbg_dump_inmap(struct fs *sb, const char *comment, struct cg *cgr)
46569800Stomsoft{
46669800Stomsoft	int j,k,l,e;
46769800Stomsoft	unsigned char *cp;
46869800Stomsoft
469232548Strasz	if (!dbg_log)
47069800Stomsoft		return;
47169800Stomsoft
47269800Stomsoft	fprintf(dbg_log, "===== START INODE ALLOCATION MAP =====\n");
47369800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
47469800Stomsoft	indent++;
47569800Stomsoft
476232548Strasz	cp = (unsigned char *)cg_inosused(cgr);
477232548Strasz	e = sb->fs_ipg / 8;
478232548Strasz	for (j = 0; j < e; j += 32) {
47969800Stomsoft		fprintf(dbg_log, "%08x: ", j);
480232548Strasz		for (k = 0; k < 32; k += 8) {
481232548Strasz			if (j + k + 8 < e) {
48269800Stomsoft				fprintf(dbg_log,
48369800Stomsoft				    "%02x%02x%02x%02x%02x%02x%02x%02x ",
48469800Stomsoft				    cp[0], cp[1], cp[2], cp[3],
48569800Stomsoft				    cp[4], cp[5], cp[6], cp[7]);
48669800Stomsoft			} else {
487232548Strasz				for (l = 0; (l < 8) && (j + k + l < e); l++) {
48869800Stomsoft					fprintf(dbg_log, "%02x", cp[l]);
48969800Stomsoft				}
49069800Stomsoft			}
491232548Strasz			cp += 8;
49269800Stomsoft		}
49369800Stomsoft		fprintf(dbg_log, "\n");
49469800Stomsoft	}
49569800Stomsoft
49669800Stomsoft	indent--;
49769800Stomsoft	fprintf(dbg_log, "===== END INODE ALLOCATION MAP =====\n");
49869800Stomsoft
49969800Stomsoft	return;
50069800Stomsoft}
50169800Stomsoft
50269800Stomsoft
50369800Stomsoft/*
50469800Stomsoft * Dump the fragment allocation map in one cylinder group.
50569800Stomsoft */
50669800Stomsoftvoid
50769800Stomsoftdbg_dump_frmap(struct fs *sb, const char *comment, struct cg *cgr)
50869800Stomsoft{
50969800Stomsoft	int j,k,l,e;
51069800Stomsoft	unsigned char *cp;
51169800Stomsoft
512232548Strasz	if (!dbg_log)
51369800Stomsoft		return;
51469800Stomsoft
51569800Stomsoft	fprintf(dbg_log, "===== START FRAGMENT ALLOCATION MAP =====\n");
51669800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
51769800Stomsoft	indent++;
51869800Stomsoft
519232548Strasz	cp = (unsigned char *)cg_blksfree(cgr);
520118915Srwatson	if (sb->fs_old_nspf)
521298871Spfg		e = howmany(sb->fs_old_cpg * sb->fs_old_spc / sb->fs_old_nspf,
522298871Spfg		    CHAR_BIT);
523118915Srwatson	else
524118915Srwatson		e = 0;
525232548Strasz	for (j = 0; j < e; j += 32) {
52669800Stomsoft		fprintf(dbg_log, "%08x: ", j);
527232548Strasz		for (k = 0; k < 32; k += 8) {
528232548Strasz			if (j + k + 8 <e) {
52969800Stomsoft				fprintf(dbg_log,
53069800Stomsoft				    "%02x%02x%02x%02x%02x%02x%02x%02x ",
53169800Stomsoft				    cp[0], cp[1], cp[2], cp[3],
53269800Stomsoft				    cp[4], cp[5], cp[6], cp[7]);
53369800Stomsoft			} else {
534232548Strasz				for (l = 0; (l < 8) && (j + k + l < e); l++) {
53569800Stomsoft					fprintf(dbg_log, "%02x", cp[l]);
53669800Stomsoft				}
53769800Stomsoft			}
538232548Strasz			cp += 8;
53969800Stomsoft		}
54069800Stomsoft		fprintf(dbg_log, "\n");
54169800Stomsoft	}
54269800Stomsoft
54369800Stomsoft	indent--;
54469800Stomsoft	fprintf(dbg_log, "===== END FRAGMENT ALLOCATION MAP =====\n");
54569800Stomsoft
54669800Stomsoft	return;
54769800Stomsoft}
54869800Stomsoft
54969800Stomsoft/*
55069800Stomsoft * Dump the cluster allocation map in one cylinder group.
55169800Stomsoft */
55269800Stomsoftvoid
55369800Stomsoftdbg_dump_clmap(struct fs *sb, const char *comment, struct cg *cgr)
55469800Stomsoft{
55569800Stomsoft	int j,k,l,e;
55669800Stomsoft	unsigned char *cp;
55769800Stomsoft
558232548Strasz	if (!dbg_log)
55969800Stomsoft		return;
56069800Stomsoft
56169800Stomsoft	fprintf(dbg_log, "===== START CLUSTER ALLOCATION MAP =====\n");
56269800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
56369800Stomsoft	indent++;
56469800Stomsoft
565232548Strasz	cp = (unsigned char *)cg_clustersfree(cgr);
566118915Srwatson	if (sb->fs_old_nspf)
567232548Strasz		e = howmany(sb->fs_old_cpg * sb->fs_old_spc / (sb->fs_old_nspf << sb->fs_fragshift), CHAR_BIT);
568118915Srwatson	else
569118915Srwatson		e = 0;
570232548Strasz	for (j = 0; j < e; j += 32) {
57169800Stomsoft		fprintf(dbg_log, "%08x: ", j);
572232548Strasz		for (k = 0; k < 32; k += 8) {
573232548Strasz			if (j + k + 8 < e) {
57469800Stomsoft				fprintf(dbg_log,
57569800Stomsoft				    "%02x%02x%02x%02x%02x%02x%02x%02x ",
57669800Stomsoft				    cp[0], cp[1], cp[2], cp[3],
57769800Stomsoft				    cp[4], cp[5], cp[6], cp[7]);
57869800Stomsoft			} else {
579232548Strasz				for (l = 0; (l < 8) && (j + k + l <e); l++) {
58069800Stomsoft					fprintf(dbg_log, "%02x", cp[l]);
58169800Stomsoft				}
58269800Stomsoft			}
583232548Strasz			cp += 8;
58469800Stomsoft		}
58569800Stomsoft		fprintf(dbg_log, "\n");
58669800Stomsoft	}
58769800Stomsoft
58869800Stomsoft	indent--;
58969800Stomsoft	fprintf(dbg_log, "===== END CLUSTER ALLOCATION MAP =====\n");
59069800Stomsoft
59169800Stomsoft	return;
59269800Stomsoft}
59369800Stomsoft
59469800Stomsoft/*
59569800Stomsoft * Dump the cluster availability summary of one cylinder group.
59669800Stomsoft */
59769800Stomsoftvoid
59869800Stomsoftdbg_dump_clsum(struct fs *sb, const char *comment, struct cg *cgr)
59969800Stomsoft{
60069800Stomsoft	int j;
60177885Stomsoft	int *ip;
60269800Stomsoft
603232548Strasz	if (!dbg_log)
60469800Stomsoft		return;
60569800Stomsoft
60669800Stomsoft	fprintf(dbg_log, "===== START CLUSTER SUMMARY =====\n");
60769800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
60869800Stomsoft	indent++;
60969800Stomsoft
610232548Strasz	ip = (int *)cg_clustersum(cgr);
611232548Strasz	for (j = 0; j <= sb->fs_contigsumsize; j++) {
61277885Stomsoft		fprintf(dbg_log, "%02d: %8d\n", j, *ip++);
61369800Stomsoft	}
61469800Stomsoft
61569800Stomsoft	indent--;
61669800Stomsoft	fprintf(dbg_log, "===== END CLUSTER SUMMARY =====\n");
61769800Stomsoft
61869800Stomsoft	return;
61969800Stomsoft}
62069800Stomsoft
621118915Srwatson#ifdef NOT_CURRENTLY
622118915Srwatson/*
623118915Srwatson * This code dates from before the UFS2 integration, and doesn't compile
624118915Srwatson * post-UFS2 due to the use of cg_blks().  I'm not sure how best to update
625118915Srwatson * this for UFS2, where the rotational bits of UFS no longer apply, so
626118915Srwatson * will leave it disabled for now; it should probably be re-enabled
627118915Srwatson * specifically for UFS1.
628118915Srwatson */
62969800Stomsoft/*
63069800Stomsoft * Dump the block summary, and the rotational layout table.
63169800Stomsoft */
63269800Stomsoftvoid
63369800Stomsoftdbg_dump_sptbl(struct fs *sb, const char *comment, struct cg *cgr)
63469800Stomsoft{
63569800Stomsoft	int j,k;
63677885Stomsoft	int *ip;
63769800Stomsoft
638232548Strasz	if (!dbg_log)
63969800Stomsoft		return;
64069800Stomsoft
64169800Stomsoft	fprintf(dbg_log,
64269800Stomsoft	    "===== START BLOCK SUMMARY AND POSITION TABLE =====\n");
64369800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
64469800Stomsoft	indent++;
64569800Stomsoft
646232548Strasz	ip = (int *)cg_blktot(cgr);
647232548Strasz	for (j = 0; j < sb->fs_old_cpg; j++) {
64877885Stomsoft		fprintf(dbg_log, "%2d: %5d = ", j, *ip++);
649232548Strasz		for (k = 0; k < sb->fs_old_nrpos; k++) {
65069800Stomsoft			fprintf(dbg_log, "%4d", cg_blks(sb, cgr, j)[k]);
651232548Strasz			if (k < sb->fs_old_nrpos - 1)
65269800Stomsoft				fprintf(dbg_log, " + ");
65369800Stomsoft		}
65469800Stomsoft		fprintf(dbg_log, "\n");
65569800Stomsoft	}
65669800Stomsoft
65769800Stomsoft	indent--;
65869800Stomsoft	fprintf(dbg_log, "===== END BLOCK SUMMARY AND POSITION TABLE =====\n");
65969800Stomsoft
66069800Stomsoft	return;
66169800Stomsoft}
662118915Srwatson#endif
66369800Stomsoft
66469800Stomsoft/*
665118915Srwatson * Dump a UFS1 inode structure.
66669800Stomsoft */
66769800Stomsoftvoid
668118915Srwatsondbg_dump_ufs1_ino(struct fs *sb, const char *comment, struct ufs1_dinode *ino)
66969800Stomsoft{
67069800Stomsoft	int ictr;
67169800Stomsoft	int remaining_blocks;
67269800Stomsoft
673232548Strasz	if (!dbg_log)
67469800Stomsoft		return;
67569800Stomsoft
676118915Srwatson	fprintf(dbg_log, "===== START UFS1 INODE DUMP =====\n");
67769800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)ino, comment);
67869800Stomsoft	indent++;
67969800Stomsoft
68069800Stomsoft	fprintf(dbg_log, "mode       u_int16_t      0%o\n", ino->di_mode);
68169800Stomsoft	fprintf(dbg_log, "nlink      int16_t        0x%04x\n", ino->di_nlink);
68269800Stomsoft	fprintf(dbg_log, "size       u_int64_t      0x%08x%08x\n",
68369800Stomsoft	    ((unsigned int *)&(ino->di_size))[1],
68469800Stomsoft	    ((unsigned int *)&(ino->di_size))[0]);
68569800Stomsoft	fprintf(dbg_log, "atime      int32_t        0x%08x\n", ino->di_atime);
68669800Stomsoft	fprintf(dbg_log, "atimensec  int32_t        0x%08x\n",
68769800Stomsoft	    ino->di_atimensec);
68869800Stomsoft	fprintf(dbg_log, "mtime      int32_t        0x%08x\n",
68969800Stomsoft	    ino->di_mtime);
69069800Stomsoft	fprintf(dbg_log, "mtimensec  int32_t        0x%08x\n",
69169800Stomsoft	    ino->di_mtimensec);
69269800Stomsoft	fprintf(dbg_log, "ctime      int32_t        0x%08x\n", ino->di_ctime);
69369800Stomsoft	fprintf(dbg_log, "ctimensec  int32_t        0x%08x\n",
69469800Stomsoft	    ino->di_ctimensec);
69569800Stomsoft
696232548Strasz	remaining_blocks = howmany(ino->di_size, sb->fs_bsize); /* XXX ts - +1? */
697232548Strasz	for (ictr = 0; ictr < MIN(NDADDR, remaining_blocks); ictr++) {
69869800Stomsoft		fprintf(dbg_log, "db         ufs_daddr_t[%x] 0x%08x\n", ictr,
69969800Stomsoft		    ino->di_db[ictr]);
70069800Stomsoft	}
701232548Strasz	remaining_blocks -= NDADDR;
702232548Strasz	if (remaining_blocks > 0) {
70369800Stomsoft		fprintf(dbg_log, "ib         ufs_daddr_t[0] 0x%08x\n",
70469800Stomsoft		    ino->di_ib[0]);
70569800Stomsoft	}
706232548Strasz	remaining_blocks -= howmany(sb->fs_bsize, sizeof(ufs1_daddr_t));
707232548Strasz	if (remaining_blocks > 0) {
70869800Stomsoft		fprintf(dbg_log, "ib         ufs_daddr_t[1] 0x%08x\n",
70969800Stomsoft		    ino->di_ib[1]);
71069800Stomsoft	}
711232548Strasz#define SQUARE(a) ((a) * (a))
712232548Strasz	remaining_blocks -= SQUARE(howmany(sb->fs_bsize, sizeof(ufs1_daddr_t)));
71369800Stomsoft#undef SQUARE
714232548Strasz	if (remaining_blocks > 0) {
71569800Stomsoft		fprintf(dbg_log, "ib         ufs_daddr_t[2] 0x%08x\n",
71669800Stomsoft		    ino->di_ib[2]);
71769800Stomsoft	}
71869800Stomsoft
71969800Stomsoft	fprintf(dbg_log, "flags      u_int32_t      0x%08x\n", ino->di_flags);
72069800Stomsoft	fprintf(dbg_log, "blocks     int32_t        0x%08x\n", ino->di_blocks);
72169800Stomsoft	fprintf(dbg_log, "gen        int32_t        0x%08x\n", ino->di_gen);
72269800Stomsoft	fprintf(dbg_log, "uid        u_int32_t      0x%08x\n", ino->di_uid);
72369800Stomsoft	fprintf(dbg_log, "gid        u_int32_t      0x%08x\n", ino->di_gid);
72469800Stomsoft
72569800Stomsoft	indent--;
726118915Srwatson	fprintf(dbg_log, "===== END UFS1 INODE DUMP =====\n");
72769800Stomsoft
72869800Stomsoft	return;
72969800Stomsoft}
73069800Stomsoft
731118915Srwatson/*
732118915Srwatson * Dump a UFS2 inode structure.
733118915Srwatson */
734118915Srwatsonvoid
735118915Srwatsondbg_dump_ufs2_ino(struct fs *sb, const char *comment, struct ufs2_dinode *ino)
736118915Srwatson{
737118915Srwatson	int ictr;
738118915Srwatson	int remaining_blocks;
739118915Srwatson
740232548Strasz	if (!dbg_log)
741118915Srwatson		return;
742118915Srwatson
743118915Srwatson	fprintf(dbg_log, "===== START UFS2 INODE DUMP =====\n");
744118915Srwatson	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)ino, comment);
745118915Srwatson	indent++;
746118915Srwatson
747118915Srwatson	fprintf(dbg_log, "mode       u_int16_t      0%o\n", ino->di_mode);
748118915Srwatson	fprintf(dbg_log, "nlink      int16_t        0x%04x\n", ino->di_nlink);
749118915Srwatson	fprintf(dbg_log, "uid        u_int32_t      0x%08x\n", ino->di_uid);
750118915Srwatson	fprintf(dbg_log, "gid        u_int32_t      0x%08x\n", ino->di_gid);
751118915Srwatson	fprintf(dbg_log, "blksize    u_int32_t      0x%08x\n", ino->di_blksize);
752118915Srwatson	fprintf(dbg_log, "size       u_int64_t      0x%08x%08x\n",
753118915Srwatson	    ((unsigned int *)&(ino->di_size))[1],
754118915Srwatson	    ((unsigned int *)&(ino->di_size))[0]);
755118915Srwatson	fprintf(dbg_log, "blocks     u_int64_t      0x%08x%08x\n",
756232548Strasz	    ((unsigned int *)&(ino->di_blocks))[1],
757232548Strasz	    ((unsigned int *)&(ino->di_blocks))[0]);
758127798Sle	fprintf(dbg_log, "atime      ufs_time_t     %10jd\n", ino->di_atime);
759127798Sle	fprintf(dbg_log, "mtime      ufs_time_t     %10jd\n", ino->di_mtime);
760127798Sle	fprintf(dbg_log, "ctime      ufs_time_t     %10jd\n", ino->di_ctime);
761127798Sle	fprintf(dbg_log, "birthtime  ufs_time_t     %10jd\n", ino->di_birthtime);
762118915Srwatson	fprintf(dbg_log, "mtimensec  int32_t        0x%08x\n", ino->di_mtimensec);
763118915Srwatson	fprintf(dbg_log, "atimensec  int32_t        0x%08x\n", ino->di_atimensec);
764118915Srwatson	fprintf(dbg_log, "ctimensec  int32_t        0x%08x\n", ino->di_ctimensec);
765118915Srwatson	fprintf(dbg_log, "birthnsec  int32_t        0x%08x\n", ino->di_birthnsec);
766118915Srwatson	fprintf(dbg_log, "gen        int32_t        0x%08x\n", ino->di_gen);
767118915Srwatson	fprintf(dbg_log, "kernflags  u_int32_t      0x%08x\n", ino->di_kernflags);
768118915Srwatson	fprintf(dbg_log, "flags      u_int32_t      0x%08x\n", ino->di_flags);
769257029Spfg	fprintf(dbg_log, "extsize    u_int32_t      0x%08x\n", ino->di_extsize);
770118915Srwatson
771118915Srwatson	/* XXX: What do we do with di_extb[NXADDR]? */
772118915Srwatson
773232548Strasz	remaining_blocks = howmany(ino->di_size, sb->fs_bsize); /* XXX ts - +1? */
774232548Strasz	for (ictr = 0; ictr < MIN(NDADDR, remaining_blocks); ictr++) {
775127798Sle		fprintf(dbg_log, "db         ufs2_daddr_t[%x] 0x%16jx\n", ictr,
776118915Srwatson		    ino->di_db[ictr]);
777118915Srwatson	}
778232548Strasz	remaining_blocks -= NDADDR;
779232548Strasz	if (remaining_blocks > 0) {
780127798Sle		fprintf(dbg_log, "ib         ufs2_daddr_t[0] 0x%16jx\n",
781118915Srwatson		    ino->di_ib[0]);
782118915Srwatson	}
783232548Strasz	remaining_blocks -= howmany(sb->fs_bsize, sizeof(ufs2_daddr_t));
784232548Strasz	if (remaining_blocks > 0) {
785127798Sle		fprintf(dbg_log, "ib         ufs2_daddr_t[1] 0x%16jx\n",
786118915Srwatson		    ino->di_ib[1]);
787118915Srwatson	}
788232548Strasz#define SQUARE(a) ((a) * (a))
789232548Strasz	remaining_blocks -= SQUARE(howmany(sb->fs_bsize, sizeof(ufs2_daddr_t)));
790118915Srwatson#undef SQUARE
791232548Strasz	if (remaining_blocks > 0) {
792127798Sle		fprintf(dbg_log, "ib         ufs2_daddr_t[2] 0x%16jx\n",
793118915Srwatson		    ino->di_ib[2]);
794118915Srwatson	}
795118915Srwatson
796118915Srwatson	indent--;
797118915Srwatson	fprintf(dbg_log, "===== END UFS2 INODE DUMP =====\n");
798118915Srwatson
799118915Srwatson	return;
800118915Srwatson}
801118915Srwatson
80269800Stomsoft/*
80369800Stomsoft * Dump an indirect block. The iteration to dump a full file has to be
80469800Stomsoft * written around.
80569800Stomsoft */
80669800Stomsoftvoid
80769800Stomsoftdbg_dump_iblk(struct fs *sb, const char *comment, char *block, size_t length)
80869800Stomsoft{
809127798Sle	unsigned int *mem, i, j, size;
81069800Stomsoft
811232548Strasz	if (!dbg_log)
81269800Stomsoft		return;
81369800Stomsoft
81469800Stomsoft	fprintf(dbg_log, "===== START INDIRECT BLOCK DUMP =====\n");
81569800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)block,
81669800Stomsoft	    comment);
81769800Stomsoft	indent++;
81869800Stomsoft
819118915Srwatson	if (sb->fs_magic == FS_UFS1_MAGIC)
820118915Srwatson		size = sizeof(ufs1_daddr_t);
821118915Srwatson	else
822118915Srwatson		size = sizeof(ufs2_daddr_t);
823118915Srwatson
824232548Strasz	mem = (unsigned int *)block;
825232548Strasz	for (i = 0; (size_t)i < MIN(howmany(sb->fs_bsize, size), length);
826232548Strasz	    i += 8) {
82769800Stomsoft		fprintf(dbg_log, "%04x: ", i);
828232548Strasz		for (j = 0; j < 8; j++) {
829232548Strasz			if ((size_t)(i + j) < length)
83069800Stomsoft				fprintf(dbg_log, "%08X ", *mem++);
83169800Stomsoft		}
83269800Stomsoft		fprintf(dbg_log, "\n");
83369800Stomsoft	}
83469800Stomsoft
83569800Stomsoft	indent--;
83669800Stomsoft	fprintf(dbg_log, "===== END INDIRECT BLOCK DUMP =====\n");
83769800Stomsoft
83869800Stomsoft	return;
83969800Stomsoft}
84069800Stomsoft
84169800Stomsoft#endif /* FS_DEBUG */
84269800Stomsoft
843