debug.c revision 118915
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 118915 2003-08-14 18:40:59Z rwatson $";
4569800Stomsoft#endif /* not lint */
4669800Stomsoft
4769800Stomsoft/* ********************************************************** INCLUDES ***** */
4869800Stomsoft#include <sys/param.h>
4969800Stomsoft
50103949Smike#include <limits.h>
5169800Stomsoft#include <stdio.h>
5269800Stomsoft#include <ufs/ufs/dinode.h>
5369800Stomsoft#include <ufs/ffs/fs.h>
5469800Stomsoft
5569800Stomsoft#include "debug.h"
5669800Stomsoft
5769800Stomsoft#ifdef FS_DEBUG
5869800Stomsoft
5969800Stomsoft/* *********************************************************** GLOBALS ***** */
6069800Stomsoftstatic FILE	*dbg_log=NULL;
6169800Stomsoftstatic unsigned int	indent=0;
6269800Stomsoft
6369800Stomsoft/*
6469800Stomsoft * prototypes not done here, as they come with debug.h
6569800Stomsoft */
6669800Stomsoft
6769800Stomsoft/* ********************************************************** dbg_open ***** */
6869800Stomsoft/*
6969800Stomsoft * Open the filehandle where all debug output has to go.
7069800Stomsoft */
7169800Stomsoftvoid
7269800Stomsoftdbg_open(const char *fn)
7369800Stomsoft{
7469800Stomsoft
7592743Srwatson	if (strcmp(fn, "-") == 0)
7692743Srwatson		dbg_log=fopen("/dev/stdout", "a");
7792743Srwatson	else
7892743Srwatson		dbg_log=fopen(fn, "a");
7969800Stomsoft
8069800Stomsoft	return;
8169800Stomsoft}
8269800Stomsoft
8369800Stomsoft/* ********************************************************* dbg_close ***** */
8469800Stomsoft/*
8569800Stomsoft * Close the filehandle where all debug output went to.
8669800Stomsoft */
8769800Stomsoftvoid
8869800Stomsoftdbg_close(void)
8969800Stomsoft{
9069800Stomsoft
9169800Stomsoft	if(dbg_log) {
9269800Stomsoft		fclose(dbg_log);
9369800Stomsoft		dbg_log=NULL;
9469800Stomsoft	}
9569800Stomsoft
9669800Stomsoft	return;
9769800Stomsoft}
9869800Stomsoft
9969800Stomsoft/* ****************************************************** dbg_dump_hex ***** */
10069800Stomsoft/*
101102231Strhodes * Dump out a full file system block in hex.
10269800Stomsoft */
10369800Stomsoftvoid
10469800Stomsoftdbg_dump_hex(struct fs *sb, const char *comment, unsigned char *mem)
10569800Stomsoft{
10669800Stomsoft	int i, j, k;
10769800Stomsoft
10869800Stomsoft	if(!dbg_log) {
10969800Stomsoft		return;
11069800Stomsoft	}
11169800Stomsoft	fprintf(dbg_log, "===== START HEXDUMP =====\n");
11269800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)mem, comment);
11369800Stomsoft	indent++;
11469800Stomsoft	for (i=0; i<sb->fs_bsize; i+=24) {
11569800Stomsoft		for (j=0; j<3; j++) {
11669800Stomsoft			for (k=0; k<8; k++) {
11769800Stomsoft				fprintf(dbg_log, "%02x ", *mem++);
11869800Stomsoft			}
11969800Stomsoft			fprintf(dbg_log, "  ");
12069800Stomsoft		}
12169800Stomsoft		fprintf(dbg_log, "\n");
12269800Stomsoft	}
12369800Stomsoft	indent--;
12469800Stomsoft	fprintf(dbg_log, "===== END HEXDUMP =====\n");
12569800Stomsoft
12669800Stomsoft	return;
12769800Stomsoft}
12869800Stomsoft
12969800Stomsoft/* ******************************************************* dbg_dump_fs ***** */
13069800Stomsoft/*
13169800Stomsoft * Dump the superblock.
13269800Stomsoft */
13369800Stomsoftvoid
13469800Stomsoftdbg_dump_fs(struct fs *sb, const char *comment)
13569800Stomsoft{
13669800Stomsoft#ifdef FSMAXSNAP
13769800Stomsoft	int	j;
13869800Stomsoft#endif /* FSMAXSNAP */
13969800Stomsoft
14069800Stomsoft	if(!dbg_log) {
14169800Stomsoft		return;
14269800Stomsoft	}
14369800Stomsoft
14469800Stomsoft	fprintf(dbg_log, "===== START SUPERBLOCK =====\n");
14569800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)sb, comment);
14669800Stomsoft	indent++;
14769800Stomsoft
148118915Srwatson	fprintf(dbg_log, "sblkno            int32_t          0x%08x\n",
14969800Stomsoft	    sb->fs_sblkno);
150118915Srwatson	fprintf(dbg_log, "cblkno            int32_t          0x%08x\n",
15169800Stomsoft	    sb->fs_cblkno);
152118915Srwatson	fprintf(dbg_log, "iblkno            int32_t          0x%08x\n",
15369800Stomsoft	    sb->fs_iblkno);
154118915Srwatson	fprintf(dbg_log, "dblkno            int32_t          0x%08x\n",
15569800Stomsoft	    sb->fs_dblkno);
15669800Stomsoft
157118915Srwatson	fprintf(dbg_log, "old_cgoffset      int32_t          0x%08x\n",
158118915Srwatson	    sb->fs_old_cgoffset);
159118915Srwatson	fprintf(dbg_log, "old_cgmask        int32_t          0x%08x\n",
160118915Srwatson	    sb->fs_old_cgmask);
161118915Srwatson	fprintf(dbg_log, "old_time          int32_t          %10u\n",
162118915Srwatson	    (unsigned int)sb->fs_old_time);
163118915Srwatson	fprintf(dbg_log, "old_size          int32_t          0x%08x\n",
164118915Srwatson	    sb->fs_old_size);
165118915Srwatson	fprintf(dbg_log, "old_dsize         int32_t          0x%08x\n",
166118915Srwatson	    sb->fs_old_dsize);
167118915Srwatson	fprintf(dbg_log, "ncg               int32_t          0x%08x\n",
16869800Stomsoft	    sb->fs_ncg);
169118915Srwatson	fprintf(dbg_log, "bsize             int32_t          0x%08x\n",
17069800Stomsoft	    sb->fs_bsize);
171118915Srwatson	fprintf(dbg_log, "fsize             int32_t          0x%08x\n",
17269800Stomsoft	    sb->fs_fsize);
173118915Srwatson	fprintf(dbg_log, "frag              int32_t          0x%08x\n",
17469800Stomsoft	    sb->fs_frag);
17569800Stomsoft
176118915Srwatson	fprintf(dbg_log, "minfree           int32_t          0x%08x\n",
17769800Stomsoft	    sb->fs_minfree);
178118915Srwatson	fprintf(dbg_log, "old_rotdelay      int32_t          0x%08x\n",
179118915Srwatson	    sb->fs_old_rotdelay);
180118915Srwatson	fprintf(dbg_log, "old_rps           int32_t          0x%08x\n",
181118915Srwatson	    sb->fs_old_rps);
18269800Stomsoft
183118915Srwatson	fprintf(dbg_log, "bmask             int32_t          0x%08x\n",
18469800Stomsoft	    sb->fs_bmask);
185118915Srwatson	fprintf(dbg_log, "fmask             int32_t          0x%08x\n",
18669800Stomsoft	    sb->fs_fmask);
187118915Srwatson	fprintf(dbg_log, "bshift            int32_t          0x%08x\n",
18869800Stomsoft	    sb->fs_bshift);
189118915Srwatson	fprintf(dbg_log, "fshift            int32_t          0x%08x\n",
19069800Stomsoft	    sb->fs_fshift);
19169800Stomsoft
192118915Srwatson	fprintf(dbg_log, "maxcontig         int32_t          0x%08x\n",
19369800Stomsoft	    sb->fs_maxcontig);
194118915Srwatson	fprintf(dbg_log, "maxbpg            int32_t          0x%08x\n",
19569800Stomsoft	    sb->fs_maxbpg);
19669800Stomsoft
197118915Srwatson	fprintf(dbg_log, "fragshift         int32_t          0x%08x\n",
19869800Stomsoft	    sb->fs_fragshift);
199118915Srwatson	fprintf(dbg_log, "fsbtodb           int32_t          0x%08x\n",
20069800Stomsoft	    sb->fs_fsbtodb);
201118915Srwatson	fprintf(dbg_log, "sbsize            int32_t          0x%08x\n",
20269800Stomsoft	    sb->fs_sbsize);
203118915Srwatson	fprintf(dbg_log, "spare1            int32_t[2]       0x%08x 0x%08x\n",
204118915Srwatson	    sb->fs_spare1[0], sb->fs_spare1[1]);
205118915Srwatson	fprintf(dbg_log, "nindir            int32_t          0x%08x\n",
20669800Stomsoft	    sb->fs_nindir);
207118915Srwatson	fprintf(dbg_log, "inopb             int32_t          0x%08x\n",
20869800Stomsoft	    sb->fs_inopb);
209118915Srwatson	fprintf(dbg_log, "old_nspf          int32_t          0x%08x\n",
210118915Srwatson	    sb->fs_old_nspf);
21169800Stomsoft
212118915Srwatson	fprintf(dbg_log, "optim             int32_t          0x%08x\n",
21369800Stomsoft	    sb->fs_optim);
21469800Stomsoft
215118915Srwatson	fprintf(dbg_log, "old_npsect        int32_t          0x%08x\n",
216118915Srwatson	    sb->fs_old_npsect);
217118915Srwatson	fprintf(dbg_log, "old_interleave    int32_t          0x%08x\n",
218118915Srwatson	    sb->fs_old_interleave);
219118915Srwatson	fprintf(dbg_log, "old_trackskew     int32_t          0x%08x\n",
220118915Srwatson	    sb->fs_old_trackskew);
22169800Stomsoft
222118915Srwatson	fprintf(dbg_log, "id                int32_t[2]       0x%08x 0x%08x\n",
22369800Stomsoft	    sb->fs_id[0], sb->fs_id[1]);
22469800Stomsoft
225118915Srwatson	fprintf(dbg_log, "old_csaddr        int32_t          0x%08x\n",
226118915Srwatson	    sb->fs_old_csaddr);
227118915Srwatson	fprintf(dbg_log, "cssize            int32_t          0x%08x\n",
22869800Stomsoft	    sb->fs_cssize);
229118915Srwatson	fprintf(dbg_log, "cgsize            int32_t          0x%08x\n",
23069800Stomsoft	    sb->fs_cgsize);
23169800Stomsoft
232118915Srwatson	fprintf(dbg_log, "spare2            int32_t          0x%08x\n",
233118915Srwatson	    sb->fs_spare2);
234118915Srwatson	fprintf(dbg_log, "old_nsect         int32_t          0x%08x\n",
235118915Srwatson	    sb->fs_old_nsect);
236118915Srwatson	fprintf(dbg_log, "old_spc           int32_t          0x%08x\n",
237118915Srwatson	    sb->fs_old_spc);
23869800Stomsoft
239118915Srwatson	fprintf(dbg_log, "old_ncyl          int32_t          0x%08x\n",
240118915Srwatson	    sb->fs_old_ncyl);
24169800Stomsoft
242118915Srwatson	fprintf(dbg_log, "old_cpg           int32_t          0x%08x\n",
243118915Srwatson	    sb->fs_old_cpg);
244118915Srwatson	fprintf(dbg_log, "ipg               int32_t          0x%08x\n",
24569800Stomsoft	    sb->fs_ipg);
246118915Srwatson	fprintf(dbg_log, "fpg               int32_t          0x%08x\n",
24769800Stomsoft	    sb->fs_fpg);
24869800Stomsoft
249118915Srwatson	dbg_dump_csum("internal old_cstotal", &sb->fs_old_cstotal);
25069800Stomsoft
251118915Srwatson	fprintf(dbg_log, "fmod              int8_t           0x%02x\n",
25269800Stomsoft	    sb->fs_fmod);
253118915Srwatson	fprintf(dbg_log, "clean             int8_t           0x%02x\n",
25469800Stomsoft	    sb->fs_clean);
255118915Srwatson	fprintf(dbg_log, "ronly             int8_t           0x%02x\n",
25669800Stomsoft	    sb->fs_ronly);
257118915Srwatson	fprintf(dbg_log, "old_flags         int8_t           0x%02x\n",
258118915Srwatson	    sb->fs_old_flags);
259118915Srwatson	fprintf(dbg_log, "fsmnt             u_char[MAXMNTLEN] \"%s\"\n",
26069800Stomsoft	    sb->fs_fsmnt);
261118915Srwatson	fprintf(dbg_log, "volname           u_char[MAXVOLLEN] \"%s\"\n",
262118915Srwatson	    sb->fs_volname);
263118915Srwatson	fprintf(dbg_log, "swuid             u_int64_t        0x%08x%08x\n",
264118915Srwatson	    ((unsigned int *)&(sb->fs_swuid))[1],
265118915Srwatson		((unsigned int *)&(sb->fs_swuid))[0]);
26669800Stomsoft
267118915Srwatson	fprintf(dbg_log, "pad               int32_t          0x%08x\n",
268118915Srwatson	    sb->fs_pad);
269118915Srwatson
270118915Srwatson	fprintf(dbg_log, "cgrotor           int32_t          0x%08x\n",
27169800Stomsoft	    sb->fs_cgrotor);
27269800Stomsoft/*
27369800Stomsoft * struct csum[MAXCSBUFS] - is only maintained in memory
27469800Stomsoft */
27569800Stomsoft/*	fprintf(dbg_log, " int32_t\n", sb->*fs_maxcluster);*/
276118915Srwatson	fprintf(dbg_log, "old_cpc           int32_t          0x%08x\n",
277118915Srwatson	    sb->fs_old_cpc);
27869800Stomsoft/*
27969800Stomsoft * int16_t fs_opostbl[16][8] - is dumped when used in dbg_dump_sptbl
28069800Stomsoft */
281118915Srwatson	fprintf(dbg_log, "maxbsize          int32_t          0x%08x\n",
282118915Srwatson	    sb->fs_maxbsize);
283118915Srwatson	fprintf(dbg_log, "sblockloc         int64_t          0x%08x%08x\n",
284118915Srwatson		((unsigned int *)&(sb->fs_sblockloc))[1],
285118915Srwatson		((unsigned int *)&(sb->fs_sblockloc))[0]);
286118915Srwatson
287118915Srwatson	dbg_dump_csum_total("internal cstotal", &sb->fs_cstotal);
288118915Srwatson
289118915Srwatson	fprintf(dbg_log, "time              ufs_time_t       %10u\n",
290118915Srwatson	    (unsigned int)sb->fs_time);
291118915Srwatson
292118915Srwatson	fprintf(dbg_log, "size              int64_t          0x%08x%08x\n",
293118915Srwatson		((unsigned int *)&(sb->fs_size))[1],
294118915Srwatson		((unsigned int *)&(sb->fs_size))[0]);
295118915Srwatson	fprintf(dbg_log, "dsize             int64_t          0x%08x%08x\n",
296118915Srwatson		((unsigned int *)&(sb->fs_dsize))[1],
297118915Srwatson		((unsigned int *)&(sb->fs_dsize))[0]);
298118915Srwatson	fprintf(dbg_log, "csaddr            ufs2_daddr_t     0x%08x%08x\n",
299118915Srwatson		((unsigned int *)&(sb->fs_csaddr))[1],
300118915Srwatson		((unsigned int *)&(sb->fs_csaddr))[0]);
301118915Srwatson	fprintf(dbg_log, "pendingblocks     int64_t          0x%08x%08x\n",
302118915Srwatson		((unsigned int *)&(sb->fs_pendingblocks))[1],
303118915Srwatson		((unsigned int *)&(sb->fs_pendingblocks))[0]);
304118915Srwatson	fprintf(dbg_log, "pendinginodes     int32_t          0x%08x\n",
305118915Srwatson	    sb->fs_pendinginodes);
306118915Srwatson
30769800Stomsoft#ifdef FSMAXSNAP
30869800Stomsoft	for(j=0; j<FSMAXSNAP; j++) {
309118915Srwatson		fprintf(dbg_log, "snapinum          int32_t[%2d]      0x%08x\n",
31069800Stomsoft		    j, sb->fs_snapinum[j]);
31169800Stomsoft		if(!sb->fs_snapinum[j]) { /* list is dense */
31269800Stomsoft			break;
31369800Stomsoft		}
31469800Stomsoft	}
31569800Stomsoft#endif /* FSMAXSNAP */
316118915Srwatson	fprintf(dbg_log, "avgfilesize       int32_t          0x%08x\n",
317118915Srwatson	    sb->fs_avgfilesize);
318118915Srwatson	fprintf(dbg_log, "avgfpdir          int32_t          0x%08x\n",
319118915Srwatson	    sb->fs_avgfpdir);
320118915Srwatson	fprintf(dbg_log, "save_cgsize       int32_t          0x%08x\n",
321118915Srwatson	    sb->fs_save_cgsize);
322118915Srwatson	fprintf(dbg_log, "flags             int32_t          0x%08x\n",
323118915Srwatson	    sb->fs_flags);
324118915Srwatson	fprintf(dbg_log, "contigsumsize     int32_t          0x%08x\n",
32569800Stomsoft	    sb->fs_contigsumsize);
326118915Srwatson	fprintf(dbg_log, "maxsymlinklen     int32_t          0x%08x\n",
32769800Stomsoft	    sb->fs_maxsymlinklen);
328118915Srwatson	fprintf(dbg_log, "old_inodefmt      int32_t          0x%08x\n",
329118915Srwatson	    sb->fs_old_inodefmt);
330118915Srwatson	fprintf(dbg_log, "maxfilesize       u_int64_t        0x%08x%08x\n",
33169800Stomsoft	    ((unsigned int *)&(sb->fs_maxfilesize))[1],
33269800Stomsoft	    ((unsigned int *)&(sb->fs_maxfilesize))[0]);
333118915Srwatson	fprintf(dbg_log, "qbmask            int64_t          0x%08x%08x\n",
33469800Stomsoft	    ((unsigned int *)&(sb->fs_qbmask))[1],
33569800Stomsoft	    ((unsigned int *)&(sb->fs_qbmask))[0]);
336118915Srwatson	fprintf(dbg_log, "qfmask            int64_t          0x%08x%08x\n",
33769800Stomsoft	    ((unsigned int *)&(sb->fs_qfmask))[1],
33869800Stomsoft	    ((unsigned int *)&(sb->fs_qfmask))[0]);
339118915Srwatson	fprintf(dbg_log, "state             int32_t          0x%08x\n",
34069800Stomsoft	    sb->fs_state);
341118915Srwatson	fprintf(dbg_log, "old_postblformat  int32_t          0x%08x\n",
342118915Srwatson	    sb->fs_old_postblformat);
343118915Srwatson	fprintf(dbg_log, "old_nrpos         int32_t          0x%08x\n",
344118915Srwatson	    sb->fs_old_nrpos);
345118915Srwatson	fprintf(dbg_log, "spare5            int32_t[2]       0x%08x 0x%08x\n",
346118915Srwatson	    sb->fs_spare5[0], sb->fs_spare5[1]);
347118915Srwatson	fprintf(dbg_log, "magic             int32_t          0x%08x\n",
34869800Stomsoft	    sb->fs_magic);
34969800Stomsoft
35069800Stomsoft	indent--;
35169800Stomsoft	fprintf(dbg_log, "===== END SUPERBLOCK =====\n");
35269800Stomsoft
35369800Stomsoft	return;
35469800Stomsoft}
35569800Stomsoft
35669800Stomsoft/* ******************************************************* dbg_dump_cg ***** */
35769800Stomsoft/*
35869800Stomsoft * Dump a cylinder group.
35969800Stomsoft */
36069800Stomsoftvoid
36169800Stomsoftdbg_dump_cg(const char *comment, struct cg *cgr)
36269800Stomsoft{
36369800Stomsoft	int j;
36469800Stomsoft
36569800Stomsoft	if(!dbg_log) {
36669800Stomsoft		return;
36769800Stomsoft	}
36869800Stomsoft
36969800Stomsoft	fprintf(dbg_log, "===== START CYLINDER GROUP =====\n");
37069800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
37169800Stomsoft	indent++;
37269800Stomsoft
37369800Stomsoft	fprintf(dbg_log, "magic         int32_t    0x%08x\n", cgr->cg_magic);
374118915Srwatson	fprintf(dbg_log, "old_time      int32_t    0x%08x\n", cgr->cg_old_time);
37569800Stomsoft	fprintf(dbg_log, "cgx           int32_t    0x%08x\n", cgr->cg_cgx);
376118915Srwatson	fprintf(dbg_log, "old_ncyl      int16_t    0x%04x\n", cgr->cg_old_ncyl);
377118915Srwatson	fprintf(dbg_log, "old_niblk     int16_t    0x%04x\n", cgr->cg_old_niblk);
37869800Stomsoft	fprintf(dbg_log, "ndblk         int32_t    0x%08x\n", cgr->cg_ndblk);
37969800Stomsoft	dbg_dump_csum("internal cs", &cgr->cg_cs);
38069800Stomsoft	fprintf(dbg_log, "rotor         int32_t    0x%08x\n", cgr->cg_rotor);
38169800Stomsoft	fprintf(dbg_log, "frotor        int32_t    0x%08x\n", cgr->cg_frotor);
38269800Stomsoft	fprintf(dbg_log, "irotor        int32_t    0x%08x\n", cgr->cg_irotor);
38369800Stomsoft	for(j=0; j<MAXFRAG; j++) {
38469800Stomsoft		fprintf(dbg_log, "frsum         int32_t[%d] 0x%08x\n", j,
38569800Stomsoft		    cgr->cg_frsum[j]);
38669800Stomsoft	}
387118915Srwatson	fprintf(dbg_log, "old_btotoff   int32_t    0x%08x\n", cgr->cg_old_btotoff);
388118915Srwatson	fprintf(dbg_log, "old_boff      int32_t    0x%08x\n", cgr->cg_old_boff);
38969800Stomsoft	fprintf(dbg_log, "iusedoff      int32_t    0x%08x\n", cgr->cg_iusedoff);
39069800Stomsoft	fprintf(dbg_log, "freeoff       int32_t    0x%08x\n", cgr->cg_freeoff);
39169800Stomsoft	fprintf(dbg_log, "nextfreeoff   int32_t    0x%08x\n",
39269800Stomsoft	    cgr->cg_nextfreeoff);
39369800Stomsoft	fprintf(dbg_log, "clustersumoff int32_t    0x%08x\n",
39469800Stomsoft	    cgr->cg_clustersumoff);
395118915Srwatson	fprintf(dbg_log, "clusteroff    int32_t    0x%08x\n",
39669800Stomsoft	    cgr->cg_clusteroff);
39769800Stomsoft	fprintf(dbg_log, "nclusterblks  int32_t    0x%08x\n",
39869800Stomsoft	    cgr->cg_nclusterblks);
399118915Srwatson	fprintf(dbg_log, "niblk         int32_t    0x%08x\n", cgr->cg_niblk);
400118915Srwatson	fprintf(dbg_log, "initediblk    int32_t    0x%08x\n", cgr->cg_initediblk);
401118915Srwatson	fprintf(dbg_log, "time          ufs_time_t %10u\n",
402118915Srwatson		(unsigned int)cgr->cg_initediblk);
40369800Stomsoft
40469800Stomsoft	indent--;
40569800Stomsoft	fprintf(dbg_log, "===== END CYLINDER GROUP =====\n");
40669800Stomsoft
40769800Stomsoft	return;
40869800Stomsoft}
40969800Stomsoft
41069800Stomsoft/* ***************************************************** dbg_dump_csum ***** */
41169800Stomsoft/*
41269800Stomsoft * Dump a cylinder summary.
41369800Stomsoft */
41469800Stomsoftvoid
41569800Stomsoftdbg_dump_csum(const char *comment, struct csum *cs)
41669800Stomsoft{
41769800Stomsoft
41869800Stomsoft	if(!dbg_log) {
41969800Stomsoft		return;
42069800Stomsoft	}
42169800Stomsoft
42269800Stomsoft	fprintf(dbg_log, "===== START CYLINDER SUMMARY =====\n");
42369800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cs, comment);
42469800Stomsoft	indent++;
42569800Stomsoft
42669800Stomsoft	fprintf(dbg_log, "ndir   int32_t 0x%08x\n", cs->cs_ndir);
42769800Stomsoft	fprintf(dbg_log, "nbfree int32_t 0x%08x\n", cs->cs_nbfree);
42869800Stomsoft	fprintf(dbg_log, "nifree int32_t 0x%08x\n", cs->cs_nifree);
42969800Stomsoft	fprintf(dbg_log, "nffree int32_t 0x%08x\n", cs->cs_nffree);
43069800Stomsoft
43169800Stomsoft	indent--;
43269800Stomsoft	fprintf(dbg_log, "===== END CYLINDER SUMMARY =====\n");
43369800Stomsoft
43469800Stomsoft	return;
43569800Stomsoft}
43669800Stomsoft
437118915Srwatson/* ************************************************ dbg_dump_csum_total ***** */
438118915Srwatson/*
439118915Srwatson * Dump a cylinder summary.
440118915Srwatson */
441118915Srwatsonvoid
442118915Srwatsondbg_dump_csum_total(const char *comment, struct csum_total *cs)
443118915Srwatson{
444118915Srwatson
445118915Srwatson	if(!dbg_log) {
446118915Srwatson		return;
447118915Srwatson	}
448118915Srwatson
449118915Srwatson	fprintf(dbg_log, "===== START CYLINDER SUMMARY TOTAL =====\n");
450118915Srwatson	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cs, comment);
451118915Srwatson	indent++;
452118915Srwatson
453118915Srwatson	fprintf(dbg_log, "ndir        int64_t 0x%08x%08x\n",
454118915Srwatson		((unsigned int *)&(cs->cs_ndir))[1],
455118915Srwatson		((unsigned int *)&(cs->cs_ndir))[0]);
456118915Srwatson	fprintf(dbg_log, "nbfree      int64_t 0x%08x%08x\n",
457118915Srwatson		((unsigned int *)&(cs->cs_nbfree))[1],
458118915Srwatson		((unsigned int *)&(cs->cs_nbfree))[0]);
459118915Srwatson	fprintf(dbg_log, "nifree      int64_t 0x%08x%08x\n",
460118915Srwatson		((unsigned int *)&(cs->cs_nifree))[1],
461118915Srwatson		((unsigned int *)&(cs->cs_nifree))[0]);
462118915Srwatson	fprintf(dbg_log, "nffree      int64_t 0x%08x%08x\n",
463118915Srwatson		((unsigned int *)&(cs->cs_nffree))[1],
464118915Srwatson		((unsigned int *)&(cs->cs_nffree))[0]);
465118915Srwatson	fprintf(dbg_log, "numclusters int64_t 0x%08x%08x\n",
466118915Srwatson		((unsigned int *)&(cs->cs_numclusters))[1],
467118915Srwatson		((unsigned int *)&(cs->cs_numclusters))[0]);
468118915Srwatson
469118915Srwatson	indent--;
470118915Srwatson	fprintf(dbg_log, "===== END CYLINDER SUMMARY TOTAL =====\n");
471118915Srwatson
472118915Srwatson	return;
473118915Srwatson}
47469800Stomsoft/* **************************************************** dbg_dump_inmap ***** */
47569800Stomsoft/*
47669800Stomsoft * Dump the inode allocation map in one cylinder group.
47769800Stomsoft */
47869800Stomsoftvoid
47969800Stomsoftdbg_dump_inmap(struct fs *sb, const char *comment, struct cg *cgr)
48069800Stomsoft{
48169800Stomsoft	int j,k,l,e;
48269800Stomsoft	unsigned char *cp;
48369800Stomsoft
48469800Stomsoft	if(!dbg_log) {
48569800Stomsoft		return;
48669800Stomsoft	}
48769800Stomsoft
48869800Stomsoft	fprintf(dbg_log, "===== START INODE ALLOCATION MAP =====\n");
48969800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
49069800Stomsoft	indent++;
49169800Stomsoft
49269800Stomsoft	cp=(unsigned char *)cg_inosused(cgr);
49369800Stomsoft	e=sb->fs_ipg/8;
49469800Stomsoft	for(j=0; j<e; j+=32) {
49569800Stomsoft		fprintf(dbg_log, "%08x: ", j);
49669800Stomsoft		for(k=0; k<32; k+=8) {
49769800Stomsoft			if(j+k+8<e) {
49869800Stomsoft				fprintf(dbg_log,
49969800Stomsoft				    "%02x%02x%02x%02x%02x%02x%02x%02x ",
50069800Stomsoft				    cp[0], cp[1], cp[2], cp[3],
50169800Stomsoft				    cp[4], cp[5], cp[6], cp[7]);
50269800Stomsoft			} else {
50369800Stomsoft				for(l=0; (l<8)&&(j+k+l<e); l++) {
50469800Stomsoft					fprintf(dbg_log, "%02x", cp[l]);
50569800Stomsoft				}
50669800Stomsoft			}
50769800Stomsoft			cp+=8;
50869800Stomsoft		}
50969800Stomsoft		fprintf(dbg_log, "\n");
51069800Stomsoft	}
51169800Stomsoft
51269800Stomsoft	indent--;
51369800Stomsoft	fprintf(dbg_log, "===== END INODE ALLOCATION MAP =====\n");
51469800Stomsoft
51569800Stomsoft	return;
51669800Stomsoft}
51769800Stomsoft
51869800Stomsoft
51969800Stomsoft/* **************************************************** dbg_dump_frmap ***** */
52069800Stomsoft/*
52169800Stomsoft * Dump the fragment allocation map in one cylinder group.
52269800Stomsoft */
52369800Stomsoftvoid
52469800Stomsoftdbg_dump_frmap(struct fs *sb, const char *comment, struct cg *cgr)
52569800Stomsoft{
52669800Stomsoft	int j,k,l,e;
52769800Stomsoft	unsigned char *cp;
52869800Stomsoft
52969800Stomsoft	if(!dbg_log) {
53069800Stomsoft		return;
53169800Stomsoft	}
53269800Stomsoft
53369800Stomsoft	fprintf(dbg_log, "===== START FRAGMENT ALLOCATION MAP =====\n");
53469800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
53569800Stomsoft	indent++;
53669800Stomsoft
53769800Stomsoft	cp=(unsigned char *)cg_blksfree(cgr);
538118915Srwatson	if (sb->fs_old_nspf)
539118915Srwatson		e=howmany((sb->fs_old_cpg * sb->fs_old_spc / sb->fs_old_nspf), CHAR_BIT);
540118915Srwatson	else
541118915Srwatson		e = 0;
54269800Stomsoft	for(j=0; j<e; j+=32) {
54369800Stomsoft		fprintf(dbg_log, "%08x: ", j);
54469800Stomsoft		for(k=0; k<32; k+=8) {
54569800Stomsoft			if(j+k+8<e) {
54669800Stomsoft				fprintf(dbg_log,
54769800Stomsoft				    "%02x%02x%02x%02x%02x%02x%02x%02x ",
54869800Stomsoft				    cp[0], cp[1], cp[2], cp[3],
54969800Stomsoft				    cp[4], cp[5], cp[6], cp[7]);
55069800Stomsoft			} else {
55169800Stomsoft				for(l=0; (l<8)&&(j+k+l<e); l++) {
55269800Stomsoft					fprintf(dbg_log, "%02x", cp[l]);
55369800Stomsoft				}
55469800Stomsoft			}
55569800Stomsoft			cp+=8;
55669800Stomsoft		}
55769800Stomsoft		fprintf(dbg_log, "\n");
55869800Stomsoft	}
55969800Stomsoft
56069800Stomsoft	indent--;
56169800Stomsoft	fprintf(dbg_log, "===== END FRAGMENT ALLOCATION MAP =====\n");
56269800Stomsoft
56369800Stomsoft	return;
56469800Stomsoft}
56569800Stomsoft
56669800Stomsoft/* **************************************************** dbg_dump_clmap ***** */
56769800Stomsoft/*
56869800Stomsoft * Dump the cluster allocation map in one cylinder group.
56969800Stomsoft */
57069800Stomsoftvoid
57169800Stomsoftdbg_dump_clmap(struct fs *sb, const char *comment, struct cg *cgr)
57269800Stomsoft{
57369800Stomsoft	int j,k,l,e;
57469800Stomsoft	unsigned char *cp;
57569800Stomsoft
57669800Stomsoft	if(!dbg_log) {
57769800Stomsoft		return;
57869800Stomsoft	}
57969800Stomsoft
58069800Stomsoft	fprintf(dbg_log, "===== START CLUSTER ALLOCATION MAP =====\n");
58169800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
58269800Stomsoft	indent++;
58369800Stomsoft
58469800Stomsoft	cp=(unsigned char *)cg_clustersfree(cgr);
585118915Srwatson	if (sb->fs_old_nspf)
586118915Srwatson		e=howmany(sb->fs_old_cpg * sb->fs_old_spc / (sb->fs_old_nspf << sb->fs_fragshift), CHAR_BIT);
587118915Srwatson	else
588118915Srwatson		e = 0;
58969800Stomsoft	for(j=0; j<e; j+=32) {
59069800Stomsoft		fprintf(dbg_log, "%08x: ", j);
59169800Stomsoft		for(k=0; k<32; k+=8) {
59269800Stomsoft			if(j+k+8<e) {
59369800Stomsoft				fprintf(dbg_log,
59469800Stomsoft				    "%02x%02x%02x%02x%02x%02x%02x%02x ",
59569800Stomsoft				    cp[0], cp[1], cp[2], cp[3],
59669800Stomsoft				    cp[4], cp[5], cp[6], cp[7]);
59769800Stomsoft			} else {
59869800Stomsoft				for(l=0; (l<8)&&(j+k+l<e); l++) {
59969800Stomsoft					fprintf(dbg_log, "%02x", cp[l]);
60069800Stomsoft				}
60169800Stomsoft			}
60269800Stomsoft			cp+=8;
60369800Stomsoft		}
60469800Stomsoft		fprintf(dbg_log, "\n");
60569800Stomsoft	}
60669800Stomsoft
60769800Stomsoft	indent--;
60869800Stomsoft	fprintf(dbg_log, "===== END CLUSTER ALLOCATION MAP =====\n");
60969800Stomsoft
61069800Stomsoft	return;
61169800Stomsoft}
61269800Stomsoft
61369800Stomsoft/* **************************************************** dbg_dump_clsum ***** */
61469800Stomsoft/*
61569800Stomsoft * Dump the cluster availability summary of one cylinder group.
61669800Stomsoft */
61769800Stomsoftvoid
61869800Stomsoftdbg_dump_clsum(struct fs *sb, const char *comment, struct cg *cgr)
61969800Stomsoft{
62069800Stomsoft	int j;
62177885Stomsoft	int *ip;
62269800Stomsoft
62369800Stomsoft	if(!dbg_log) {
62469800Stomsoft		return;
62569800Stomsoft	}
62669800Stomsoft
62769800Stomsoft	fprintf(dbg_log, "===== START CLUSTER SUMMARY =====\n");
62869800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
62969800Stomsoft	indent++;
63069800Stomsoft
63177885Stomsoft	ip=(int *)cg_clustersum(cgr);
63269800Stomsoft	for(j=0; j<=sb->fs_contigsumsize; j++) {
63377885Stomsoft		fprintf(dbg_log, "%02d: %8d\n", j, *ip++);
63469800Stomsoft	}
63569800Stomsoft
63669800Stomsoft	indent--;
63769800Stomsoft	fprintf(dbg_log, "===== END CLUSTER SUMMARY =====\n");
63869800Stomsoft
63969800Stomsoft	return;
64069800Stomsoft}
64169800Stomsoft
642118915Srwatson#ifdef NOT_CURRENTLY
643118915Srwatson/*
644118915Srwatson * This code dates from before the UFS2 integration, and doesn't compile
645118915Srwatson * post-UFS2 due to the use of cg_blks().  I'm not sure how best to update
646118915Srwatson * this for UFS2, where the rotational bits of UFS no longer apply, so
647118915Srwatson * will leave it disabled for now; it should probably be re-enabled
648118915Srwatson * specifically for UFS1.
649118915Srwatson */
65069800Stomsoft/* **************************************************** dbg_dump_sptbl ***** */
65169800Stomsoft/*
65269800Stomsoft * Dump the block summary, and the rotational layout table.
65369800Stomsoft */
65469800Stomsoftvoid
65569800Stomsoftdbg_dump_sptbl(struct fs *sb, const char *comment, struct cg *cgr)
65669800Stomsoft{
65769800Stomsoft	int j,k;
65877885Stomsoft	int *ip;
65969800Stomsoft
66069800Stomsoft	if(!dbg_log) {
66169800Stomsoft		return;
66269800Stomsoft	}
66369800Stomsoft
66469800Stomsoft	fprintf(dbg_log,
66569800Stomsoft	    "===== START BLOCK SUMMARY AND POSITION TABLE =====\n");
66669800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
66769800Stomsoft	indent++;
66869800Stomsoft
66977885Stomsoft	ip=(int *)cg_blktot(cgr);
670118915Srwatson	for(j=0; j<sb->fs_old_cpg; j++) {
67177885Stomsoft		fprintf(dbg_log, "%2d: %5d = ", j, *ip++);
672118915Srwatson		for(k=0; k<sb->fs_old_nrpos; k++) {
67369800Stomsoft			fprintf(dbg_log, "%4d", cg_blks(sb, cgr, j)[k]);
674118915Srwatson			if(k<sb->fs_old_nrpos-1) {
67569800Stomsoft				fprintf(dbg_log, " + ");
67669800Stomsoft			}
67769800Stomsoft		}
67869800Stomsoft		fprintf(dbg_log, "\n");
67969800Stomsoft	}
68069800Stomsoft
68169800Stomsoft	indent--;
68269800Stomsoft	fprintf(dbg_log, "===== END BLOCK SUMMARY AND POSITION TABLE =====\n");
68369800Stomsoft
68469800Stomsoft	return;
68569800Stomsoft}
686118915Srwatson#endif
68769800Stomsoft
688118915Srwatson/* ************************************************** dbg_dump_ufs1_ino ***** */
68969800Stomsoft/*
690118915Srwatson * Dump a UFS1 inode structure.
69169800Stomsoft */
69269800Stomsoftvoid
693118915Srwatsondbg_dump_ufs1_ino(struct fs *sb, const char *comment, struct ufs1_dinode *ino)
69469800Stomsoft{
69569800Stomsoft	int ictr;
69669800Stomsoft	int remaining_blocks;
69769800Stomsoft
69869800Stomsoft	if(!dbg_log) {
69969800Stomsoft		return;
70069800Stomsoft	}
70169800Stomsoft
702118915Srwatson	fprintf(dbg_log, "===== START UFS1 INODE DUMP =====\n");
70369800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)ino, comment);
70469800Stomsoft	indent++;
70569800Stomsoft
70669800Stomsoft	fprintf(dbg_log, "mode       u_int16_t      0%o\n", ino->di_mode);
70769800Stomsoft	fprintf(dbg_log, "nlink      int16_t        0x%04x\n", ino->di_nlink);
70869800Stomsoft	fprintf(dbg_log, "size       u_int64_t      0x%08x%08x\n",
70969800Stomsoft	    ((unsigned int *)&(ino->di_size))[1],
71069800Stomsoft	    ((unsigned int *)&(ino->di_size))[0]);
71169800Stomsoft	fprintf(dbg_log, "atime      int32_t        0x%08x\n", ino->di_atime);
71269800Stomsoft	fprintf(dbg_log, "atimensec  int32_t        0x%08x\n",
71369800Stomsoft	    ino->di_atimensec);
71469800Stomsoft	fprintf(dbg_log, "mtime      int32_t        0x%08x\n",
71569800Stomsoft	    ino->di_mtime);
71669800Stomsoft	fprintf(dbg_log, "mtimensec  int32_t        0x%08x\n",
71769800Stomsoft	    ino->di_mtimensec);
71869800Stomsoft	fprintf(dbg_log, "ctime      int32_t        0x%08x\n", ino->di_ctime);
71969800Stomsoft	fprintf(dbg_log, "ctimensec  int32_t        0x%08x\n",
72069800Stomsoft	    ino->di_ctimensec);
72169800Stomsoft
72269800Stomsoft	remaining_blocks=howmany(ino->di_size, sb->fs_bsize); /* XXX ts - +1? */
72369800Stomsoft	for(ictr=0; ictr < MIN(NDADDR, remaining_blocks); ictr++) {
72469800Stomsoft		fprintf(dbg_log, "db         ufs_daddr_t[%x] 0x%08x\n", ictr,
72569800Stomsoft		    ino->di_db[ictr]);
72669800Stomsoft	}
72769800Stomsoft	remaining_blocks-=NDADDR;
72869800Stomsoft	if(remaining_blocks>0) {
72969800Stomsoft		fprintf(dbg_log, "ib         ufs_daddr_t[0] 0x%08x\n",
73069800Stomsoft		    ino->di_ib[0]);
73169800Stomsoft	}
732118915Srwatson	remaining_blocks-=howmany(sb->fs_bsize, sizeof(ufs1_daddr_t));
73369800Stomsoft	if(remaining_blocks>0) {
73469800Stomsoft		fprintf(dbg_log, "ib         ufs_daddr_t[1] 0x%08x\n",
73569800Stomsoft		    ino->di_ib[1]);
73669800Stomsoft	}
73769800Stomsoft#define SQUARE(a) ((a)*(a))
738118915Srwatson	remaining_blocks-=SQUARE(howmany(sb->fs_bsize, sizeof(ufs1_daddr_t)));
73969800Stomsoft#undef SQUARE
74069800Stomsoft	if(remaining_blocks>0) {
74169800Stomsoft		fprintf(dbg_log, "ib         ufs_daddr_t[2] 0x%08x\n",
74269800Stomsoft		    ino->di_ib[2]);
74369800Stomsoft	}
74469800Stomsoft
74569800Stomsoft	fprintf(dbg_log, "flags      u_int32_t      0x%08x\n", ino->di_flags);
74669800Stomsoft	fprintf(dbg_log, "blocks     int32_t        0x%08x\n", ino->di_blocks);
74769800Stomsoft	fprintf(dbg_log, "gen        int32_t        0x%08x\n", ino->di_gen);
74869800Stomsoft	fprintf(dbg_log, "uid        u_int32_t      0x%08x\n", ino->di_uid);
74969800Stomsoft	fprintf(dbg_log, "gid        u_int32_t      0x%08x\n", ino->di_gid);
75069800Stomsoft
75169800Stomsoft	indent--;
752118915Srwatson	fprintf(dbg_log, "===== END UFS1 INODE DUMP =====\n");
75369800Stomsoft
75469800Stomsoft	return;
75569800Stomsoft}
75669800Stomsoft
757118915Srwatson/* ************************************************** dbg_dump_ufs2_ino ***** */
758118915Srwatson/*
759118915Srwatson * Dump a UFS2 inode structure.
760118915Srwatson */
761118915Srwatsonvoid
762118915Srwatsondbg_dump_ufs2_ino(struct fs *sb, const char *comment, struct ufs2_dinode *ino)
763118915Srwatson{
764118915Srwatson	int ictr;
765118915Srwatson	int remaining_blocks;
766118915Srwatson
767118915Srwatson	if(!dbg_log) {
768118915Srwatson		return;
769118915Srwatson	}
770118915Srwatson
771118915Srwatson	fprintf(dbg_log, "===== START UFS2 INODE DUMP =====\n");
772118915Srwatson	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)ino, comment);
773118915Srwatson	indent++;
774118915Srwatson
775118915Srwatson	fprintf(dbg_log, "mode       u_int16_t      0%o\n", ino->di_mode);
776118915Srwatson	fprintf(dbg_log, "nlink      int16_t        0x%04x\n", ino->di_nlink);
777118915Srwatson	fprintf(dbg_log, "uid        u_int32_t      0x%08x\n", ino->di_uid);
778118915Srwatson	fprintf(dbg_log, "gid        u_int32_t      0x%08x\n", ino->di_gid);
779118915Srwatson	fprintf(dbg_log, "blksize    u_int32_t      0x%08x\n", ino->di_blksize);
780118915Srwatson	fprintf(dbg_log, "size       u_int64_t      0x%08x%08x\n",
781118915Srwatson	    ((unsigned int *)&(ino->di_size))[1],
782118915Srwatson	    ((unsigned int *)&(ino->di_size))[0]);
783118915Srwatson	fprintf(dbg_log, "blocks     u_int64_t      0x%08x%08x\n",
784118915Srwatson		((unsigned int *)&(ino->di_blocks))[1],
785118915Srwatson		((unsigned int *)&(ino->di_blocks))[0]);
786118915Srwatson	fprintf(dbg_log, "atime      ufs_time_t     %10u\n", ino->di_atime);
787118915Srwatson	fprintf(dbg_log, "mtime      ufs_time_t     %10u\n", ino->di_mtime);
788118915Srwatson	fprintf(dbg_log, "ctime      ufs_time_t     %10u\n", ino->di_ctime);
789118915Srwatson	fprintf(dbg_log, "birthtime  ufs_time_t     %10u\n", ino->di_birthtime);
790118915Srwatson	fprintf(dbg_log, "mtimensec  int32_t        0x%08x\n", ino->di_mtimensec);
791118915Srwatson	fprintf(dbg_log, "atimensec  int32_t        0x%08x\n", ino->di_atimensec);
792118915Srwatson	fprintf(dbg_log, "ctimensec  int32_t        0x%08x\n", ino->di_ctimensec);
793118915Srwatson	fprintf(dbg_log, "birthnsec  int32_t        0x%08x\n", ino->di_birthnsec);
794118915Srwatson	fprintf(dbg_log, "gen        int32_t        0x%08x\n", ino->di_gen);
795118915Srwatson	fprintf(dbg_log, "kernflags  u_int32_t      0x%08x\n", ino->di_kernflags);
796118915Srwatson	fprintf(dbg_log, "flags      u_int32_t      0x%08x\n", ino->di_flags);
797118915Srwatson	fprintf(dbg_log, "extsize    int32_t        0x%08x\n", ino->di_extsize);
798118915Srwatson
799118915Srwatson	/* XXX: What do we do with di_extb[NXADDR]? */
800118915Srwatson
801118915Srwatson	remaining_blocks=howmany(ino->di_size, sb->fs_bsize); /* XXX ts - +1? */
802118915Srwatson	for(ictr=0; ictr < MIN(NDADDR, remaining_blocks); ictr++) {
803118915Srwatson		fprintf(dbg_log, "db         ufs2_daddr_t[%x] 0x%16x\n", ictr,
804118915Srwatson		    ino->di_db[ictr]);
805118915Srwatson	}
806118915Srwatson	remaining_blocks-=NDADDR;
807118915Srwatson	if(remaining_blocks>0) {
808118915Srwatson		fprintf(dbg_log, "ib         ufs2_daddr_t[0] 0x%16x\n",
809118915Srwatson		    ino->di_ib[0]);
810118915Srwatson	}
811118915Srwatson	remaining_blocks-=howmany(sb->fs_bsize, sizeof(ufs2_daddr_t));
812118915Srwatson	if(remaining_blocks>0) {
813118915Srwatson		fprintf(dbg_log, "ib         ufs2_daddr_t[1] 0x%16x\n",
814118915Srwatson		    ino->di_ib[1]);
815118915Srwatson	}
816118915Srwatson#define SQUARE(a) ((a)*(a))
817118915Srwatson	remaining_blocks-=SQUARE(howmany(sb->fs_bsize, sizeof(ufs2_daddr_t)));
818118915Srwatson#undef SQUARE
819118915Srwatson	if(remaining_blocks>0) {
820118915Srwatson		fprintf(dbg_log, "ib         ufs2_daddr_t[2] 0x%16x\n",
821118915Srwatson		    ino->di_ib[2]);
822118915Srwatson	}
823118915Srwatson
824118915Srwatson	indent--;
825118915Srwatson	fprintf(dbg_log, "===== END UFS2 INODE DUMP =====\n");
826118915Srwatson
827118915Srwatson	return;
828118915Srwatson}
829118915Srwatson
83069800Stomsoft/* ***************************************************** dbg_dump_iblk ***** */
83169800Stomsoft/*
83269800Stomsoft * Dump an indirect block. The iteration to dump a full file has to be
83369800Stomsoft * written around.
83469800Stomsoft */
83569800Stomsoftvoid
83669800Stomsoftdbg_dump_iblk(struct fs *sb, const char *comment, char *block, size_t length)
83769800Stomsoft{
83869800Stomsoft	unsigned int *mem;
839118915Srwatson	int i, j, size;
84069800Stomsoft
84169800Stomsoft	if(!dbg_log) {
84269800Stomsoft		return;
84369800Stomsoft	}
84469800Stomsoft
84569800Stomsoft	fprintf(dbg_log, "===== START INDIRECT BLOCK DUMP =====\n");
84669800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)block,
84769800Stomsoft	    comment);
84869800Stomsoft	indent++;
84969800Stomsoft
850118915Srwatson	if (sb->fs_magic == FS_UFS1_MAGIC)
851118915Srwatson		size = sizeof(ufs1_daddr_t);
852118915Srwatson	else
853118915Srwatson		size = sizeof(ufs2_daddr_t);
854118915Srwatson
85569800Stomsoft	mem=(unsigned int *)block;
856118915Srwatson	for (i=0; (size_t)i<MIN(howmany(sb->fs_bsize, size),
85769800Stomsoft	    length); i+=8) {
85869800Stomsoft		fprintf(dbg_log, "%04x: ", i);
85969800Stomsoft		for (j=0; j<8; j++) {
86069800Stomsoft			if((size_t)(i+j)<length) {
86169800Stomsoft				fprintf(dbg_log, "%08X ", *mem++);
86269800Stomsoft			}
86369800Stomsoft		}
86469800Stomsoft		fprintf(dbg_log, "\n");
86569800Stomsoft	}
86669800Stomsoft
86769800Stomsoft	indent--;
86869800Stomsoft	fprintf(dbg_log, "===== END INDIRECT BLOCK DUMP =====\n");
86969800Stomsoft
87069800Stomsoft	return;
87169800Stomsoft}
87269800Stomsoft
87369800Stomsoft#endif /* FS_DEBUG */
87469800Stomsoft
875