debug.c revision 232548
169800Stomsoft/*
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: head/sbin/growfs/debug.c 232548 2012-03-05 16:37:51Z trasz $";
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{
13069800Stomsoft#ifdef FSMAXSNAP
131232548Strasz	int j;
13269800Stomsoft#endif /* FSMAXSNAP */
13369800Stomsoft
134232548Strasz	if (!dbg_log)
13569800Stomsoft		return;
13669800Stomsoft
13769800Stomsoft	fprintf(dbg_log, "===== START SUPERBLOCK =====\n");
13869800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)sb, comment);
13969800Stomsoft	indent++;
14069800Stomsoft
141118915Srwatson	fprintf(dbg_log, "sblkno            int32_t          0x%08x\n",
14269800Stomsoft	    sb->fs_sblkno);
143118915Srwatson	fprintf(dbg_log, "cblkno            int32_t          0x%08x\n",
14469800Stomsoft	    sb->fs_cblkno);
145118915Srwatson	fprintf(dbg_log, "iblkno            int32_t          0x%08x\n",
14669800Stomsoft	    sb->fs_iblkno);
147118915Srwatson	fprintf(dbg_log, "dblkno            int32_t          0x%08x\n",
14869800Stomsoft	    sb->fs_dblkno);
14969800Stomsoft
150118915Srwatson	fprintf(dbg_log, "old_cgoffset      int32_t          0x%08x\n",
151118915Srwatson	    sb->fs_old_cgoffset);
152118915Srwatson	fprintf(dbg_log, "old_cgmask        int32_t          0x%08x\n",
153118915Srwatson	    sb->fs_old_cgmask);
154118915Srwatson	fprintf(dbg_log, "old_time          int32_t          %10u\n",
155118915Srwatson	    (unsigned int)sb->fs_old_time);
156118915Srwatson	fprintf(dbg_log, "old_size          int32_t          0x%08x\n",
157118915Srwatson	    sb->fs_old_size);
158118915Srwatson	fprintf(dbg_log, "old_dsize         int32_t          0x%08x\n",
159118915Srwatson	    sb->fs_old_dsize);
160118915Srwatson	fprintf(dbg_log, "ncg               int32_t          0x%08x\n",
16169800Stomsoft	    sb->fs_ncg);
162118915Srwatson	fprintf(dbg_log, "bsize             int32_t          0x%08x\n",
16369800Stomsoft	    sb->fs_bsize);
164118915Srwatson	fprintf(dbg_log, "fsize             int32_t          0x%08x\n",
16569800Stomsoft	    sb->fs_fsize);
166118915Srwatson	fprintf(dbg_log, "frag              int32_t          0x%08x\n",
16769800Stomsoft	    sb->fs_frag);
16869800Stomsoft
169118915Srwatson	fprintf(dbg_log, "minfree           int32_t          0x%08x\n",
17069800Stomsoft	    sb->fs_minfree);
171118915Srwatson	fprintf(dbg_log, "old_rotdelay      int32_t          0x%08x\n",
172118915Srwatson	    sb->fs_old_rotdelay);
173118915Srwatson	fprintf(dbg_log, "old_rps           int32_t          0x%08x\n",
174118915Srwatson	    sb->fs_old_rps);
17569800Stomsoft
176118915Srwatson	fprintf(dbg_log, "bmask             int32_t          0x%08x\n",
17769800Stomsoft	    sb->fs_bmask);
178118915Srwatson	fprintf(dbg_log, "fmask             int32_t          0x%08x\n",
17969800Stomsoft	    sb->fs_fmask);
180118915Srwatson	fprintf(dbg_log, "bshift            int32_t          0x%08x\n",
18169800Stomsoft	    sb->fs_bshift);
182118915Srwatson	fprintf(dbg_log, "fshift            int32_t          0x%08x\n",
18369800Stomsoft	    sb->fs_fshift);
18469800Stomsoft
185118915Srwatson	fprintf(dbg_log, "maxcontig         int32_t          0x%08x\n",
18669800Stomsoft	    sb->fs_maxcontig);
187118915Srwatson	fprintf(dbg_log, "maxbpg            int32_t          0x%08x\n",
18869800Stomsoft	    sb->fs_maxbpg);
18969800Stomsoft
190118915Srwatson	fprintf(dbg_log, "fragshift         int32_t          0x%08x\n",
19169800Stomsoft	    sb->fs_fragshift);
192118915Srwatson	fprintf(dbg_log, "fsbtodb           int32_t          0x%08x\n",
19369800Stomsoft	    sb->fs_fsbtodb);
194118915Srwatson	fprintf(dbg_log, "sbsize            int32_t          0x%08x\n",
19569800Stomsoft	    sb->fs_sbsize);
196118915Srwatson	fprintf(dbg_log, "spare1            int32_t[2]       0x%08x 0x%08x\n",
197118915Srwatson	    sb->fs_spare1[0], sb->fs_spare1[1]);
198118915Srwatson	fprintf(dbg_log, "nindir            int32_t          0x%08x\n",
19969800Stomsoft	    sb->fs_nindir);
200118915Srwatson	fprintf(dbg_log, "inopb             int32_t          0x%08x\n",
20169800Stomsoft	    sb->fs_inopb);
202118915Srwatson	fprintf(dbg_log, "old_nspf          int32_t          0x%08x\n",
203118915Srwatson	    sb->fs_old_nspf);
20469800Stomsoft
205118915Srwatson	fprintf(dbg_log, "optim             int32_t          0x%08x\n",
20669800Stomsoft	    sb->fs_optim);
20769800Stomsoft
208118915Srwatson	fprintf(dbg_log, "old_npsect        int32_t          0x%08x\n",
209118915Srwatson	    sb->fs_old_npsect);
210118915Srwatson	fprintf(dbg_log, "old_interleave    int32_t          0x%08x\n",
211118915Srwatson	    sb->fs_old_interleave);
212118915Srwatson	fprintf(dbg_log, "old_trackskew     int32_t          0x%08x\n",
213118915Srwatson	    sb->fs_old_trackskew);
21469800Stomsoft
215118915Srwatson	fprintf(dbg_log, "id                int32_t[2]       0x%08x 0x%08x\n",
21669800Stomsoft	    sb->fs_id[0], sb->fs_id[1]);
21769800Stomsoft
218118915Srwatson	fprintf(dbg_log, "old_csaddr        int32_t          0x%08x\n",
219118915Srwatson	    sb->fs_old_csaddr);
220118915Srwatson	fprintf(dbg_log, "cssize            int32_t          0x%08x\n",
22169800Stomsoft	    sb->fs_cssize);
222118915Srwatson	fprintf(dbg_log, "cgsize            int32_t          0x%08x\n",
22369800Stomsoft	    sb->fs_cgsize);
22469800Stomsoft
225118915Srwatson	fprintf(dbg_log, "spare2            int32_t          0x%08x\n",
226118915Srwatson	    sb->fs_spare2);
227118915Srwatson	fprintf(dbg_log, "old_nsect         int32_t          0x%08x\n",
228118915Srwatson	    sb->fs_old_nsect);
229118915Srwatson	fprintf(dbg_log, "old_spc           int32_t          0x%08x\n",
230118915Srwatson	    sb->fs_old_spc);
23169800Stomsoft
232118915Srwatson	fprintf(dbg_log, "old_ncyl          int32_t          0x%08x\n",
233118915Srwatson	    sb->fs_old_ncyl);
23469800Stomsoft
235118915Srwatson	fprintf(dbg_log, "old_cpg           int32_t          0x%08x\n",
236118915Srwatson	    sb->fs_old_cpg);
237118915Srwatson	fprintf(dbg_log, "ipg               int32_t          0x%08x\n",
23869800Stomsoft	    sb->fs_ipg);
239118915Srwatson	fprintf(dbg_log, "fpg               int32_t          0x%08x\n",
24069800Stomsoft	    sb->fs_fpg);
24169800Stomsoft
242118915Srwatson	dbg_dump_csum("internal old_cstotal", &sb->fs_old_cstotal);
24369800Stomsoft
244118915Srwatson	fprintf(dbg_log, "fmod              int8_t           0x%02x\n",
24569800Stomsoft	    sb->fs_fmod);
246118915Srwatson	fprintf(dbg_log, "clean             int8_t           0x%02x\n",
24769800Stomsoft	    sb->fs_clean);
248118915Srwatson	fprintf(dbg_log, "ronly             int8_t           0x%02x\n",
24969800Stomsoft	    sb->fs_ronly);
250118915Srwatson	fprintf(dbg_log, "old_flags         int8_t           0x%02x\n",
251118915Srwatson	    sb->fs_old_flags);
252118915Srwatson	fprintf(dbg_log, "fsmnt             u_char[MAXMNTLEN] \"%s\"\n",
25369800Stomsoft	    sb->fs_fsmnt);
254118915Srwatson	fprintf(dbg_log, "volname           u_char[MAXVOLLEN] \"%s\"\n",
255118915Srwatson	    sb->fs_volname);
256118915Srwatson	fprintf(dbg_log, "swuid             u_int64_t        0x%08x%08x\n",
257118915Srwatson	    ((unsigned int *)&(sb->fs_swuid))[1],
258118915Srwatson		((unsigned int *)&(sb->fs_swuid))[0]);
25969800Stomsoft
260118915Srwatson	fprintf(dbg_log, "pad               int32_t          0x%08x\n",
261118915Srwatson	    sb->fs_pad);
262118915Srwatson
263118915Srwatson	fprintf(dbg_log, "cgrotor           int32_t          0x%08x\n",
26469800Stomsoft	    sb->fs_cgrotor);
26569800Stomsoft/*
26669800Stomsoft * struct csum[MAXCSBUFS] - is only maintained in memory
26769800Stomsoft */
26869800Stomsoft/*	fprintf(dbg_log, " int32_t\n", sb->*fs_maxcluster);*/
269118915Srwatson	fprintf(dbg_log, "old_cpc           int32_t          0x%08x\n",
270118915Srwatson	    sb->fs_old_cpc);
27169800Stomsoft/*
27269800Stomsoft * int16_t fs_opostbl[16][8] - is dumped when used in dbg_dump_sptbl
27369800Stomsoft */
274118915Srwatson	fprintf(dbg_log, "maxbsize          int32_t          0x%08x\n",
275118915Srwatson	    sb->fs_maxbsize);
276215704Sbrucec	fprintf(dbg_log, "unrefs            int64_t          0x%08jx\n",
277163844Spjd	    sb->fs_unrefs);
278118915Srwatson	fprintf(dbg_log, "sblockloc         int64_t          0x%08x%08x\n",
279118915Srwatson		((unsigned int *)&(sb->fs_sblockloc))[1],
280118915Srwatson		((unsigned int *)&(sb->fs_sblockloc))[0]);
281118915Srwatson
282118915Srwatson	dbg_dump_csum_total("internal cstotal", &sb->fs_cstotal);
283118915Srwatson
284118915Srwatson	fprintf(dbg_log, "time              ufs_time_t       %10u\n",
285118915Srwatson	    (unsigned int)sb->fs_time);
286118915Srwatson
287118915Srwatson	fprintf(dbg_log, "size              int64_t          0x%08x%08x\n",
288118915Srwatson		((unsigned int *)&(sb->fs_size))[1],
289118915Srwatson		((unsigned int *)&(sb->fs_size))[0]);
290118915Srwatson	fprintf(dbg_log, "dsize             int64_t          0x%08x%08x\n",
291118915Srwatson		((unsigned int *)&(sb->fs_dsize))[1],
292118915Srwatson		((unsigned int *)&(sb->fs_dsize))[0]);
293118915Srwatson	fprintf(dbg_log, "csaddr            ufs2_daddr_t     0x%08x%08x\n",
294118915Srwatson		((unsigned int *)&(sb->fs_csaddr))[1],
295118915Srwatson		((unsigned int *)&(sb->fs_csaddr))[0]);
296118915Srwatson	fprintf(dbg_log, "pendingblocks     int64_t          0x%08x%08x\n",
297118915Srwatson		((unsigned int *)&(sb->fs_pendingblocks))[1],
298118915Srwatson		((unsigned int *)&(sb->fs_pendingblocks))[0]);
299118915Srwatson	fprintf(dbg_log, "pendinginodes     int32_t          0x%08x\n",
300118915Srwatson	    sb->fs_pendinginodes);
301118915Srwatson
30269800Stomsoft#ifdef FSMAXSNAP
303232548Strasz	for (j = 0; j < FSMAXSNAP; j++) {
304118915Srwatson		fprintf(dbg_log, "snapinum          int32_t[%2d]      0x%08x\n",
30569800Stomsoft		    j, sb->fs_snapinum[j]);
306232548Strasz		if (!sb->fs_snapinum[j]) { /* list is dense */
30769800Stomsoft			break;
30869800Stomsoft		}
30969800Stomsoft	}
31069800Stomsoft#endif /* FSMAXSNAP */
311118915Srwatson	fprintf(dbg_log, "avgfilesize       int32_t          0x%08x\n",
312118915Srwatson	    sb->fs_avgfilesize);
313118915Srwatson	fprintf(dbg_log, "avgfpdir          int32_t          0x%08x\n",
314118915Srwatson	    sb->fs_avgfpdir);
315118915Srwatson	fprintf(dbg_log, "save_cgsize       int32_t          0x%08x\n",
316118915Srwatson	    sb->fs_save_cgsize);
317118915Srwatson	fprintf(dbg_log, "flags             int32_t          0x%08x\n",
318118915Srwatson	    sb->fs_flags);
319118915Srwatson	fprintf(dbg_log, "contigsumsize     int32_t          0x%08x\n",
32069800Stomsoft	    sb->fs_contigsumsize);
321118915Srwatson	fprintf(dbg_log, "maxsymlinklen     int32_t          0x%08x\n",
32269800Stomsoft	    sb->fs_maxsymlinklen);
323118915Srwatson	fprintf(dbg_log, "old_inodefmt      int32_t          0x%08x\n",
324118915Srwatson	    sb->fs_old_inodefmt);
325118915Srwatson	fprintf(dbg_log, "maxfilesize       u_int64_t        0x%08x%08x\n",
32669800Stomsoft	    ((unsigned int *)&(sb->fs_maxfilesize))[1],
32769800Stomsoft	    ((unsigned int *)&(sb->fs_maxfilesize))[0]);
328118915Srwatson	fprintf(dbg_log, "qbmask            int64_t          0x%08x%08x\n",
32969800Stomsoft	    ((unsigned int *)&(sb->fs_qbmask))[1],
33069800Stomsoft	    ((unsigned int *)&(sb->fs_qbmask))[0]);
331118915Srwatson	fprintf(dbg_log, "qfmask            int64_t          0x%08x%08x\n",
33269800Stomsoft	    ((unsigned int *)&(sb->fs_qfmask))[1],
33369800Stomsoft	    ((unsigned int *)&(sb->fs_qfmask))[0]);
334118915Srwatson	fprintf(dbg_log, "state             int32_t          0x%08x\n",
33569800Stomsoft	    sb->fs_state);
336118915Srwatson	fprintf(dbg_log, "old_postblformat  int32_t          0x%08x\n",
337118915Srwatson	    sb->fs_old_postblformat);
338118915Srwatson	fprintf(dbg_log, "old_nrpos         int32_t          0x%08x\n",
339118915Srwatson	    sb->fs_old_nrpos);
340118915Srwatson	fprintf(dbg_log, "spare5            int32_t[2]       0x%08x 0x%08x\n",
341118915Srwatson	    sb->fs_spare5[0], sb->fs_spare5[1]);
342118915Srwatson	fprintf(dbg_log, "magic             int32_t          0x%08x\n",
34369800Stomsoft	    sb->fs_magic);
34469800Stomsoft
34569800Stomsoft	indent--;
34669800Stomsoft	fprintf(dbg_log, "===== END SUPERBLOCK =====\n");
34769800Stomsoft
34869800Stomsoft	return;
34969800Stomsoft}
35069800Stomsoft
35169800Stomsoft/*
35269800Stomsoft * Dump a cylinder group.
35369800Stomsoft */
35469800Stomsoftvoid
35569800Stomsoftdbg_dump_cg(const char *comment, struct cg *cgr)
35669800Stomsoft{
35769800Stomsoft	int j;
35869800Stomsoft
359232548Strasz	if (!dbg_log)
36069800Stomsoft		return;
36169800Stomsoft
36269800Stomsoft	fprintf(dbg_log, "===== START CYLINDER GROUP =====\n");
36369800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
36469800Stomsoft	indent++;
36569800Stomsoft
36669800Stomsoft	fprintf(dbg_log, "magic         int32_t    0x%08x\n", cgr->cg_magic);
367118915Srwatson	fprintf(dbg_log, "old_time      int32_t    0x%08x\n", cgr->cg_old_time);
36869800Stomsoft	fprintf(dbg_log, "cgx           int32_t    0x%08x\n", cgr->cg_cgx);
369118915Srwatson	fprintf(dbg_log, "old_ncyl      int16_t    0x%04x\n", cgr->cg_old_ncyl);
370118915Srwatson	fprintf(dbg_log, "old_niblk     int16_t    0x%04x\n", cgr->cg_old_niblk);
37169800Stomsoft	fprintf(dbg_log, "ndblk         int32_t    0x%08x\n", cgr->cg_ndblk);
37269800Stomsoft	dbg_dump_csum("internal cs", &cgr->cg_cs);
37369800Stomsoft	fprintf(dbg_log, "rotor         int32_t    0x%08x\n", cgr->cg_rotor);
37469800Stomsoft	fprintf(dbg_log, "frotor        int32_t    0x%08x\n", cgr->cg_frotor);
37569800Stomsoft	fprintf(dbg_log, "irotor        int32_t    0x%08x\n", cgr->cg_irotor);
376232548Strasz	for (j = 0; j < MAXFRAG; j++) {
37769800Stomsoft		fprintf(dbg_log, "frsum         int32_t[%d] 0x%08x\n", j,
37869800Stomsoft		    cgr->cg_frsum[j]);
37969800Stomsoft	}
380118915Srwatson	fprintf(dbg_log, "old_btotoff   int32_t    0x%08x\n", cgr->cg_old_btotoff);
381118915Srwatson	fprintf(dbg_log, "old_boff      int32_t    0x%08x\n", cgr->cg_old_boff);
38269800Stomsoft	fprintf(dbg_log, "iusedoff      int32_t    0x%08x\n", cgr->cg_iusedoff);
38369800Stomsoft	fprintf(dbg_log, "freeoff       int32_t    0x%08x\n", cgr->cg_freeoff);
38469800Stomsoft	fprintf(dbg_log, "nextfreeoff   int32_t    0x%08x\n",
38569800Stomsoft	    cgr->cg_nextfreeoff);
38669800Stomsoft	fprintf(dbg_log, "clustersumoff int32_t    0x%08x\n",
38769800Stomsoft	    cgr->cg_clustersumoff);
388118915Srwatson	fprintf(dbg_log, "clusteroff    int32_t    0x%08x\n",
38969800Stomsoft	    cgr->cg_clusteroff);
39069800Stomsoft	fprintf(dbg_log, "nclusterblks  int32_t    0x%08x\n",
39169800Stomsoft	    cgr->cg_nclusterblks);
392118915Srwatson	fprintf(dbg_log, "niblk         int32_t    0x%08x\n", cgr->cg_niblk);
393118915Srwatson	fprintf(dbg_log, "initediblk    int32_t    0x%08x\n", cgr->cg_initediblk);
394163844Spjd	fprintf(dbg_log, "unrefs        int32_t    0x%08x\n", cgr->cg_unrefs);
395118915Srwatson	fprintf(dbg_log, "time          ufs_time_t %10u\n",
396118915Srwatson		(unsigned int)cgr->cg_initediblk);
39769800Stomsoft
39869800Stomsoft	indent--;
39969800Stomsoft	fprintf(dbg_log, "===== END CYLINDER GROUP =====\n");
40069800Stomsoft
40169800Stomsoft	return;
40269800Stomsoft}
40369800Stomsoft
40469800Stomsoft/*
40569800Stomsoft * Dump a cylinder summary.
40669800Stomsoft */
40769800Stomsoftvoid
40869800Stomsoftdbg_dump_csum(const char *comment, struct csum *cs)
40969800Stomsoft{
41069800Stomsoft
411232548Strasz	if (!dbg_log)
41269800Stomsoft		return;
41369800Stomsoft
41469800Stomsoft	fprintf(dbg_log, "===== START CYLINDER SUMMARY =====\n");
41569800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cs, comment);
41669800Stomsoft	indent++;
41769800Stomsoft
41869800Stomsoft	fprintf(dbg_log, "ndir   int32_t 0x%08x\n", cs->cs_ndir);
41969800Stomsoft	fprintf(dbg_log, "nbfree int32_t 0x%08x\n", cs->cs_nbfree);
42069800Stomsoft	fprintf(dbg_log, "nifree int32_t 0x%08x\n", cs->cs_nifree);
42169800Stomsoft	fprintf(dbg_log, "nffree int32_t 0x%08x\n", cs->cs_nffree);
42269800Stomsoft
42369800Stomsoft	indent--;
42469800Stomsoft	fprintf(dbg_log, "===== END CYLINDER SUMMARY =====\n");
42569800Stomsoft
42669800Stomsoft	return;
42769800Stomsoft}
42869800Stomsoft
429118915Srwatson/*
430118915Srwatson * Dump a cylinder summary.
431118915Srwatson */
432118915Srwatsonvoid
433118915Srwatsondbg_dump_csum_total(const char *comment, struct csum_total *cs)
434118915Srwatson{
435118915Srwatson
436232548Strasz	if (!dbg_log)
437118915Srwatson		return;
438118915Srwatson
439118915Srwatson	fprintf(dbg_log, "===== START CYLINDER SUMMARY TOTAL =====\n");
440118915Srwatson	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cs, comment);
441118915Srwatson	indent++;
442118915Srwatson
443118915Srwatson	fprintf(dbg_log, "ndir        int64_t 0x%08x%08x\n",
444118915Srwatson		((unsigned int *)&(cs->cs_ndir))[1],
445118915Srwatson		((unsigned int *)&(cs->cs_ndir))[0]);
446118915Srwatson	fprintf(dbg_log, "nbfree      int64_t 0x%08x%08x\n",
447118915Srwatson		((unsigned int *)&(cs->cs_nbfree))[1],
448118915Srwatson		((unsigned int *)&(cs->cs_nbfree))[0]);
449118915Srwatson	fprintf(dbg_log, "nifree      int64_t 0x%08x%08x\n",
450118915Srwatson		((unsigned int *)&(cs->cs_nifree))[1],
451118915Srwatson		((unsigned int *)&(cs->cs_nifree))[0]);
452118915Srwatson	fprintf(dbg_log, "nffree      int64_t 0x%08x%08x\n",
453118915Srwatson		((unsigned int *)&(cs->cs_nffree))[1],
454118915Srwatson		((unsigned int *)&(cs->cs_nffree))[0]);
455118915Srwatson	fprintf(dbg_log, "numclusters int64_t 0x%08x%08x\n",
456118915Srwatson		((unsigned int *)&(cs->cs_numclusters))[1],
457118915Srwatson		((unsigned int *)&(cs->cs_numclusters))[0]);
458118915Srwatson
459118915Srwatson	indent--;
460118915Srwatson	fprintf(dbg_log, "===== END CYLINDER SUMMARY TOTAL =====\n");
461118915Srwatson
462118915Srwatson	return;
463118915Srwatson}
46469800Stomsoft/*
46569800Stomsoft * Dump the inode allocation map in one cylinder group.
46669800Stomsoft */
46769800Stomsoftvoid
46869800Stomsoftdbg_dump_inmap(struct fs *sb, const char *comment, struct cg *cgr)
46969800Stomsoft{
47069800Stomsoft	int j,k,l,e;
47169800Stomsoft	unsigned char *cp;
47269800Stomsoft
473232548Strasz	if (!dbg_log)
47469800Stomsoft		return;
47569800Stomsoft
47669800Stomsoft	fprintf(dbg_log, "===== START INODE ALLOCATION MAP =====\n");
47769800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
47869800Stomsoft	indent++;
47969800Stomsoft
480232548Strasz	cp = (unsigned char *)cg_inosused(cgr);
481232548Strasz	e = sb->fs_ipg / 8;
482232548Strasz	for (j = 0; j < e; j += 32) {
48369800Stomsoft		fprintf(dbg_log, "%08x: ", j);
484232548Strasz		for (k = 0; k < 32; k += 8) {
485232548Strasz			if (j + k + 8 < e) {
48669800Stomsoft				fprintf(dbg_log,
48769800Stomsoft				    "%02x%02x%02x%02x%02x%02x%02x%02x ",
48869800Stomsoft				    cp[0], cp[1], cp[2], cp[3],
48969800Stomsoft				    cp[4], cp[5], cp[6], cp[7]);
49069800Stomsoft			} else {
491232548Strasz				for (l = 0; (l < 8) && (j + k + l < e); l++) {
49269800Stomsoft					fprintf(dbg_log, "%02x", cp[l]);
49369800Stomsoft				}
49469800Stomsoft			}
495232548Strasz			cp += 8;
49669800Stomsoft		}
49769800Stomsoft		fprintf(dbg_log, "\n");
49869800Stomsoft	}
49969800Stomsoft
50069800Stomsoft	indent--;
50169800Stomsoft	fprintf(dbg_log, "===== END INODE ALLOCATION MAP =====\n");
50269800Stomsoft
50369800Stomsoft	return;
50469800Stomsoft}
50569800Stomsoft
50669800Stomsoft
50769800Stomsoft/*
50869800Stomsoft * Dump the fragment allocation map in one cylinder group.
50969800Stomsoft */
51069800Stomsoftvoid
51169800Stomsoftdbg_dump_frmap(struct fs *sb, const char *comment, struct cg *cgr)
51269800Stomsoft{
51369800Stomsoft	int j,k,l,e;
51469800Stomsoft	unsigned char *cp;
51569800Stomsoft
516232548Strasz	if (!dbg_log)
51769800Stomsoft		return;
51869800Stomsoft
51969800Stomsoft	fprintf(dbg_log, "===== START FRAGMENT ALLOCATION MAP =====\n");
52069800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
52169800Stomsoft	indent++;
52269800Stomsoft
523232548Strasz	cp = (unsigned char *)cg_blksfree(cgr);
524118915Srwatson	if (sb->fs_old_nspf)
525232548Strasz		e = howmany((sb->fs_old_cpg * sb->fs_old_spc / sb->fs_old_nspf), CHAR_BIT);
526118915Srwatson	else
527118915Srwatson		e = 0;
528232548Strasz	for (j = 0; j < e; j += 32) {
52969800Stomsoft		fprintf(dbg_log, "%08x: ", j);
530232548Strasz		for (k = 0; k < 32; k += 8) {
531232548Strasz			if (j + k + 8 <e) {
53269800Stomsoft				fprintf(dbg_log,
53369800Stomsoft				    "%02x%02x%02x%02x%02x%02x%02x%02x ",
53469800Stomsoft				    cp[0], cp[1], cp[2], cp[3],
53569800Stomsoft				    cp[4], cp[5], cp[6], cp[7]);
53669800Stomsoft			} else {
537232548Strasz				for (l = 0; (l < 8) && (j + k + l < e); l++) {
53869800Stomsoft					fprintf(dbg_log, "%02x", cp[l]);
53969800Stomsoft				}
54069800Stomsoft			}
541232548Strasz			cp += 8;
54269800Stomsoft		}
54369800Stomsoft		fprintf(dbg_log, "\n");
54469800Stomsoft	}
54569800Stomsoft
54669800Stomsoft	indent--;
54769800Stomsoft	fprintf(dbg_log, "===== END FRAGMENT ALLOCATION MAP =====\n");
54869800Stomsoft
54969800Stomsoft	return;
55069800Stomsoft}
55169800Stomsoft
55269800Stomsoft/*
55369800Stomsoft * Dump the cluster allocation map in one cylinder group.
55469800Stomsoft */
55569800Stomsoftvoid
55669800Stomsoftdbg_dump_clmap(struct fs *sb, const char *comment, struct cg *cgr)
55769800Stomsoft{
55869800Stomsoft	int j,k,l,e;
55969800Stomsoft	unsigned char *cp;
56069800Stomsoft
561232548Strasz	if (!dbg_log)
56269800Stomsoft		return;
56369800Stomsoft
56469800Stomsoft	fprintf(dbg_log, "===== START CLUSTER ALLOCATION MAP =====\n");
56569800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
56669800Stomsoft	indent++;
56769800Stomsoft
568232548Strasz	cp = (unsigned char *)cg_clustersfree(cgr);
569118915Srwatson	if (sb->fs_old_nspf)
570232548Strasz		e = howmany(sb->fs_old_cpg * sb->fs_old_spc / (sb->fs_old_nspf << sb->fs_fragshift), CHAR_BIT);
571118915Srwatson	else
572118915Srwatson		e = 0;
573232548Strasz	for (j = 0; j < e; j += 32) {
57469800Stomsoft		fprintf(dbg_log, "%08x: ", j);
575232548Strasz		for (k = 0; k < 32; k += 8) {
576232548Strasz			if (j + k + 8 < e) {
57769800Stomsoft				fprintf(dbg_log,
57869800Stomsoft				    "%02x%02x%02x%02x%02x%02x%02x%02x ",
57969800Stomsoft				    cp[0], cp[1], cp[2], cp[3],
58069800Stomsoft				    cp[4], cp[5], cp[6], cp[7]);
58169800Stomsoft			} else {
582232548Strasz				for (l = 0; (l < 8) && (j + k + l <e); l++) {
58369800Stomsoft					fprintf(dbg_log, "%02x", cp[l]);
58469800Stomsoft				}
58569800Stomsoft			}
586232548Strasz			cp += 8;
58769800Stomsoft		}
58869800Stomsoft		fprintf(dbg_log, "\n");
58969800Stomsoft	}
59069800Stomsoft
59169800Stomsoft	indent--;
59269800Stomsoft	fprintf(dbg_log, "===== END CLUSTER ALLOCATION MAP =====\n");
59369800Stomsoft
59469800Stomsoft	return;
59569800Stomsoft}
59669800Stomsoft
59769800Stomsoft/*
59869800Stomsoft * Dump the cluster availability summary of one cylinder group.
59969800Stomsoft */
60069800Stomsoftvoid
60169800Stomsoftdbg_dump_clsum(struct fs *sb, const char *comment, struct cg *cgr)
60269800Stomsoft{
60369800Stomsoft	int j;
60477885Stomsoft	int *ip;
60569800Stomsoft
606232548Strasz	if (!dbg_log)
60769800Stomsoft		return;
60869800Stomsoft
60969800Stomsoft	fprintf(dbg_log, "===== START CLUSTER SUMMARY =====\n");
61069800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
61169800Stomsoft	indent++;
61269800Stomsoft
613232548Strasz	ip = (int *)cg_clustersum(cgr);
614232548Strasz	for (j = 0; j <= sb->fs_contigsumsize; j++) {
61577885Stomsoft		fprintf(dbg_log, "%02d: %8d\n", j, *ip++);
61669800Stomsoft	}
61769800Stomsoft
61869800Stomsoft	indent--;
61969800Stomsoft	fprintf(dbg_log, "===== END CLUSTER SUMMARY =====\n");
62069800Stomsoft
62169800Stomsoft	return;
62269800Stomsoft}
62369800Stomsoft
624118915Srwatson#ifdef NOT_CURRENTLY
625118915Srwatson/*
626118915Srwatson * This code dates from before the UFS2 integration, and doesn't compile
627118915Srwatson * post-UFS2 due to the use of cg_blks().  I'm not sure how best to update
628118915Srwatson * this for UFS2, where the rotational bits of UFS no longer apply, so
629118915Srwatson * will leave it disabled for now; it should probably be re-enabled
630118915Srwatson * specifically for UFS1.
631118915Srwatson */
63269800Stomsoft/*
63369800Stomsoft * Dump the block summary, and the rotational layout table.
63469800Stomsoft */
63569800Stomsoftvoid
63669800Stomsoftdbg_dump_sptbl(struct fs *sb, const char *comment, struct cg *cgr)
63769800Stomsoft{
63869800Stomsoft	int j,k;
63977885Stomsoft	int *ip;
64069800Stomsoft
641232548Strasz	if (!dbg_log)
64269800Stomsoft		return;
64369800Stomsoft
64469800Stomsoft	fprintf(dbg_log,
64569800Stomsoft	    "===== START BLOCK SUMMARY AND POSITION TABLE =====\n");
64669800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
64769800Stomsoft	indent++;
64869800Stomsoft
649232548Strasz	ip = (int *)cg_blktot(cgr);
650232548Strasz	for (j = 0; j < sb->fs_old_cpg; j++) {
65177885Stomsoft		fprintf(dbg_log, "%2d: %5d = ", j, *ip++);
652232548Strasz		for (k = 0; k < sb->fs_old_nrpos; k++) {
65369800Stomsoft			fprintf(dbg_log, "%4d", cg_blks(sb, cgr, j)[k]);
654232548Strasz			if (k < sb->fs_old_nrpos - 1)
65569800Stomsoft				fprintf(dbg_log, " + ");
65669800Stomsoft		}
65769800Stomsoft		fprintf(dbg_log, "\n");
65869800Stomsoft	}
65969800Stomsoft
66069800Stomsoft	indent--;
66169800Stomsoft	fprintf(dbg_log, "===== END BLOCK SUMMARY AND POSITION TABLE =====\n");
66269800Stomsoft
66369800Stomsoft	return;
66469800Stomsoft}
665118915Srwatson#endif
66669800Stomsoft
66769800Stomsoft/*
668118915Srwatson * Dump a UFS1 inode structure.
66969800Stomsoft */
67069800Stomsoftvoid
671118915Srwatsondbg_dump_ufs1_ino(struct fs *sb, const char *comment, struct ufs1_dinode *ino)
67269800Stomsoft{
67369800Stomsoft	int ictr;
67469800Stomsoft	int remaining_blocks;
67569800Stomsoft
676232548Strasz	if (!dbg_log)
67769800Stomsoft		return;
67869800Stomsoft
679118915Srwatson	fprintf(dbg_log, "===== START UFS1 INODE DUMP =====\n");
68069800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)ino, comment);
68169800Stomsoft	indent++;
68269800Stomsoft
68369800Stomsoft	fprintf(dbg_log, "mode       u_int16_t      0%o\n", ino->di_mode);
68469800Stomsoft	fprintf(dbg_log, "nlink      int16_t        0x%04x\n", ino->di_nlink);
68569800Stomsoft	fprintf(dbg_log, "size       u_int64_t      0x%08x%08x\n",
68669800Stomsoft	    ((unsigned int *)&(ino->di_size))[1],
68769800Stomsoft	    ((unsigned int *)&(ino->di_size))[0]);
68869800Stomsoft	fprintf(dbg_log, "atime      int32_t        0x%08x\n", ino->di_atime);
68969800Stomsoft	fprintf(dbg_log, "atimensec  int32_t        0x%08x\n",
69069800Stomsoft	    ino->di_atimensec);
69169800Stomsoft	fprintf(dbg_log, "mtime      int32_t        0x%08x\n",
69269800Stomsoft	    ino->di_mtime);
69369800Stomsoft	fprintf(dbg_log, "mtimensec  int32_t        0x%08x\n",
69469800Stomsoft	    ino->di_mtimensec);
69569800Stomsoft	fprintf(dbg_log, "ctime      int32_t        0x%08x\n", ino->di_ctime);
69669800Stomsoft	fprintf(dbg_log, "ctimensec  int32_t        0x%08x\n",
69769800Stomsoft	    ino->di_ctimensec);
69869800Stomsoft
699232548Strasz	remaining_blocks = howmany(ino->di_size, sb->fs_bsize); /* XXX ts - +1? */
700232548Strasz	for (ictr = 0; ictr < MIN(NDADDR, remaining_blocks); ictr++) {
70169800Stomsoft		fprintf(dbg_log, "db         ufs_daddr_t[%x] 0x%08x\n", ictr,
70269800Stomsoft		    ino->di_db[ictr]);
70369800Stomsoft	}
704232548Strasz	remaining_blocks -= NDADDR;
705232548Strasz	if (remaining_blocks > 0) {
70669800Stomsoft		fprintf(dbg_log, "ib         ufs_daddr_t[0] 0x%08x\n",
70769800Stomsoft		    ino->di_ib[0]);
70869800Stomsoft	}
709232548Strasz	remaining_blocks -= howmany(sb->fs_bsize, sizeof(ufs1_daddr_t));
710232548Strasz	if (remaining_blocks > 0) {
71169800Stomsoft		fprintf(dbg_log, "ib         ufs_daddr_t[1] 0x%08x\n",
71269800Stomsoft		    ino->di_ib[1]);
71369800Stomsoft	}
714232548Strasz#define SQUARE(a) ((a) * (a))
715232548Strasz	remaining_blocks -= SQUARE(howmany(sb->fs_bsize, sizeof(ufs1_daddr_t)));
71669800Stomsoft#undef SQUARE
717232548Strasz	if (remaining_blocks > 0) {
71869800Stomsoft		fprintf(dbg_log, "ib         ufs_daddr_t[2] 0x%08x\n",
71969800Stomsoft		    ino->di_ib[2]);
72069800Stomsoft	}
72169800Stomsoft
72269800Stomsoft	fprintf(dbg_log, "flags      u_int32_t      0x%08x\n", ino->di_flags);
72369800Stomsoft	fprintf(dbg_log, "blocks     int32_t        0x%08x\n", ino->di_blocks);
72469800Stomsoft	fprintf(dbg_log, "gen        int32_t        0x%08x\n", ino->di_gen);
72569800Stomsoft	fprintf(dbg_log, "uid        u_int32_t      0x%08x\n", ino->di_uid);
72669800Stomsoft	fprintf(dbg_log, "gid        u_int32_t      0x%08x\n", ino->di_gid);
72769800Stomsoft
72869800Stomsoft	indent--;
729118915Srwatson	fprintf(dbg_log, "===== END UFS1 INODE DUMP =====\n");
73069800Stomsoft
73169800Stomsoft	return;
73269800Stomsoft}
73369800Stomsoft
734118915Srwatson/*
735118915Srwatson * Dump a UFS2 inode structure.
736118915Srwatson */
737118915Srwatsonvoid
738118915Srwatsondbg_dump_ufs2_ino(struct fs *sb, const char *comment, struct ufs2_dinode *ino)
739118915Srwatson{
740118915Srwatson	int ictr;
741118915Srwatson	int remaining_blocks;
742118915Srwatson
743232548Strasz	if (!dbg_log)
744118915Srwatson		return;
745118915Srwatson
746118915Srwatson	fprintf(dbg_log, "===== START UFS2 INODE DUMP =====\n");
747118915Srwatson	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)ino, comment);
748118915Srwatson	indent++;
749118915Srwatson
750118915Srwatson	fprintf(dbg_log, "mode       u_int16_t      0%o\n", ino->di_mode);
751118915Srwatson	fprintf(dbg_log, "nlink      int16_t        0x%04x\n", ino->di_nlink);
752118915Srwatson	fprintf(dbg_log, "uid        u_int32_t      0x%08x\n", ino->di_uid);
753118915Srwatson	fprintf(dbg_log, "gid        u_int32_t      0x%08x\n", ino->di_gid);
754118915Srwatson	fprintf(dbg_log, "blksize    u_int32_t      0x%08x\n", ino->di_blksize);
755118915Srwatson	fprintf(dbg_log, "size       u_int64_t      0x%08x%08x\n",
756118915Srwatson	    ((unsigned int *)&(ino->di_size))[1],
757118915Srwatson	    ((unsigned int *)&(ino->di_size))[0]);
758118915Srwatson	fprintf(dbg_log, "blocks     u_int64_t      0x%08x%08x\n",
759232548Strasz	    ((unsigned int *)&(ino->di_blocks))[1],
760232548Strasz	    ((unsigned int *)&(ino->di_blocks))[0]);
761127798Sle	fprintf(dbg_log, "atime      ufs_time_t     %10jd\n", ino->di_atime);
762127798Sle	fprintf(dbg_log, "mtime      ufs_time_t     %10jd\n", ino->di_mtime);
763127798Sle	fprintf(dbg_log, "ctime      ufs_time_t     %10jd\n", ino->di_ctime);
764127798Sle	fprintf(dbg_log, "birthtime  ufs_time_t     %10jd\n", ino->di_birthtime);
765118915Srwatson	fprintf(dbg_log, "mtimensec  int32_t        0x%08x\n", ino->di_mtimensec);
766118915Srwatson	fprintf(dbg_log, "atimensec  int32_t        0x%08x\n", ino->di_atimensec);
767118915Srwatson	fprintf(dbg_log, "ctimensec  int32_t        0x%08x\n", ino->di_ctimensec);
768118915Srwatson	fprintf(dbg_log, "birthnsec  int32_t        0x%08x\n", ino->di_birthnsec);
769118915Srwatson	fprintf(dbg_log, "gen        int32_t        0x%08x\n", ino->di_gen);
770118915Srwatson	fprintf(dbg_log, "kernflags  u_int32_t      0x%08x\n", ino->di_kernflags);
771118915Srwatson	fprintf(dbg_log, "flags      u_int32_t      0x%08x\n", ino->di_flags);
772118915Srwatson	fprintf(dbg_log, "extsize    int32_t        0x%08x\n", ino->di_extsize);
773118915Srwatson
774118915Srwatson	/* XXX: What do we do with di_extb[NXADDR]? */
775118915Srwatson
776232548Strasz	remaining_blocks = howmany(ino->di_size, sb->fs_bsize); /* XXX ts - +1? */
777232548Strasz	for (ictr = 0; ictr < MIN(NDADDR, remaining_blocks); ictr++) {
778127798Sle		fprintf(dbg_log, "db         ufs2_daddr_t[%x] 0x%16jx\n", ictr,
779118915Srwatson		    ino->di_db[ictr]);
780118915Srwatson	}
781232548Strasz	remaining_blocks -= NDADDR;
782232548Strasz	if (remaining_blocks > 0) {
783127798Sle		fprintf(dbg_log, "ib         ufs2_daddr_t[0] 0x%16jx\n",
784118915Srwatson		    ino->di_ib[0]);
785118915Srwatson	}
786232548Strasz	remaining_blocks -= howmany(sb->fs_bsize, sizeof(ufs2_daddr_t));
787232548Strasz	if (remaining_blocks > 0) {
788127798Sle		fprintf(dbg_log, "ib         ufs2_daddr_t[1] 0x%16jx\n",
789118915Srwatson		    ino->di_ib[1]);
790118915Srwatson	}
791232548Strasz#define SQUARE(a) ((a) * (a))
792232548Strasz	remaining_blocks -= SQUARE(howmany(sb->fs_bsize, sizeof(ufs2_daddr_t)));
793118915Srwatson#undef SQUARE
794232548Strasz	if (remaining_blocks > 0) {
795127798Sle		fprintf(dbg_log, "ib         ufs2_daddr_t[2] 0x%16jx\n",
796118915Srwatson		    ino->di_ib[2]);
797118915Srwatson	}
798118915Srwatson
799118915Srwatson	indent--;
800118915Srwatson	fprintf(dbg_log, "===== END UFS2 INODE DUMP =====\n");
801118915Srwatson
802118915Srwatson	return;
803118915Srwatson}
804118915Srwatson
80569800Stomsoft/*
80669800Stomsoft * Dump an indirect block. The iteration to dump a full file has to be
80769800Stomsoft * written around.
80869800Stomsoft */
80969800Stomsoftvoid
81069800Stomsoftdbg_dump_iblk(struct fs *sb, const char *comment, char *block, size_t length)
81169800Stomsoft{
812127798Sle	unsigned int *mem, i, j, size;
81369800Stomsoft
814232548Strasz	if (!dbg_log)
81569800Stomsoft		return;
81669800Stomsoft
81769800Stomsoft	fprintf(dbg_log, "===== START INDIRECT BLOCK DUMP =====\n");
81869800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)block,
81969800Stomsoft	    comment);
82069800Stomsoft	indent++;
82169800Stomsoft
822118915Srwatson	if (sb->fs_magic == FS_UFS1_MAGIC)
823118915Srwatson		size = sizeof(ufs1_daddr_t);
824118915Srwatson	else
825118915Srwatson		size = sizeof(ufs2_daddr_t);
826118915Srwatson
827232548Strasz	mem = (unsigned int *)block;
828232548Strasz	for (i = 0; (size_t)i < MIN(howmany(sb->fs_bsize, size), length);
829232548Strasz	    i += 8) {
83069800Stomsoft		fprintf(dbg_log, "%04x: ", i);
831232548Strasz		for (j = 0; j < 8; j++) {
832232548Strasz			if ((size_t)(i + j) < length)
83369800Stomsoft				fprintf(dbg_log, "%08X ", *mem++);
83469800Stomsoft		}
83569800Stomsoft		fprintf(dbg_log, "\n");
83669800Stomsoft	}
83769800Stomsoft
83869800Stomsoft	indent--;
83969800Stomsoft	fprintf(dbg_log, "===== END INDIRECT BLOCK DUMP =====\n");
84069800Stomsoft
84169800Stomsoft	return;
84269800Stomsoft}
84369800Stomsoft
84469800Stomsoft#endif /* FS_DEBUG */
84569800Stomsoft
846