debug.c revision 102231
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 102231 2002-08-21 18:11:48Z trhodes $";
4569800Stomsoft#endif /* not lint */
4669800Stomsoft
4769800Stomsoft/* ********************************************************** INCLUDES ***** */
4869800Stomsoft#include <sys/param.h>
4969800Stomsoft
5069800Stomsoft#include <stdio.h>
5169800Stomsoft#include <ufs/ufs/dinode.h>
5269800Stomsoft#include <ufs/ffs/fs.h>
5369800Stomsoft
5469800Stomsoft#include "debug.h"
5569800Stomsoft
5669800Stomsoft#ifdef FS_DEBUG
5769800Stomsoft
5869800Stomsoft/* *********************************************************** GLOBALS ***** */
5969800Stomsoftstatic FILE	*dbg_log=NULL;
6069800Stomsoftstatic unsigned int	indent=0;
6169800Stomsoft
6269800Stomsoft/*
6369800Stomsoft * prototypes not done here, as they come with debug.h
6469800Stomsoft */
6569800Stomsoft
6669800Stomsoft/* ********************************************************** dbg_open ***** */
6769800Stomsoft/*
6869800Stomsoft * Open the filehandle where all debug output has to go.
6969800Stomsoft */
7069800Stomsoftvoid
7169800Stomsoftdbg_open(const char *fn)
7269800Stomsoft{
7369800Stomsoft
7492743Srwatson	if (strcmp(fn, "-") == 0)
7592743Srwatson		dbg_log=fopen("/dev/stdout", "a");
7692743Srwatson	else
7792743Srwatson		dbg_log=fopen(fn, "a");
7869800Stomsoft
7969800Stomsoft	return;
8069800Stomsoft}
8169800Stomsoft
8269800Stomsoft/* ********************************************************* dbg_close ***** */
8369800Stomsoft/*
8469800Stomsoft * Close the filehandle where all debug output went to.
8569800Stomsoft */
8669800Stomsoftvoid
8769800Stomsoftdbg_close(void)
8869800Stomsoft{
8969800Stomsoft
9069800Stomsoft	if(dbg_log) {
9169800Stomsoft		fclose(dbg_log);
9269800Stomsoft		dbg_log=NULL;
9369800Stomsoft	}
9469800Stomsoft
9569800Stomsoft	return;
9669800Stomsoft}
9769800Stomsoft
9869800Stomsoft/* ****************************************************** dbg_dump_hex ***** */
9969800Stomsoft/*
100102231Strhodes * Dump out a full file system block in hex.
10169800Stomsoft */
10269800Stomsoftvoid
10369800Stomsoftdbg_dump_hex(struct fs *sb, const char *comment, unsigned char *mem)
10469800Stomsoft{
10569800Stomsoft	int i, j, k;
10669800Stomsoft
10769800Stomsoft	if(!dbg_log) {
10869800Stomsoft		return;
10969800Stomsoft	}
11069800Stomsoft	fprintf(dbg_log, "===== START HEXDUMP =====\n");
11169800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)mem, comment);
11269800Stomsoft	indent++;
11369800Stomsoft	for (i=0; i<sb->fs_bsize; i+=24) {
11469800Stomsoft		for (j=0; j<3; j++) {
11569800Stomsoft			for (k=0; k<8; k++) {
11669800Stomsoft				fprintf(dbg_log, "%02x ", *mem++);
11769800Stomsoft			}
11869800Stomsoft			fprintf(dbg_log, "  ");
11969800Stomsoft		}
12069800Stomsoft		fprintf(dbg_log, "\n");
12169800Stomsoft	}
12269800Stomsoft	indent--;
12369800Stomsoft	fprintf(dbg_log, "===== END HEXDUMP =====\n");
12469800Stomsoft
12569800Stomsoft	return;
12669800Stomsoft}
12769800Stomsoft
12869800Stomsoft/* ******************************************************* dbg_dump_fs ***** */
12969800Stomsoft/*
13069800Stomsoft * Dump the superblock.
13169800Stomsoft */
13269800Stomsoftvoid
13369800Stomsoftdbg_dump_fs(struct fs *sb, const char *comment)
13469800Stomsoft{
13569800Stomsoft#ifdef FSMAXSNAP
13669800Stomsoft	int	j;
13769800Stomsoft#endif /* FSMAXSNAP */
13869800Stomsoft
13969800Stomsoft	if(!dbg_log) {
14069800Stomsoft		return;
14169800Stomsoft	}
14269800Stomsoft
14369800Stomsoft	fprintf(dbg_log, "===== START SUPERBLOCK =====\n");
14469800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)sb, comment);
14569800Stomsoft	indent++;
14669800Stomsoft
14769800Stomsoft	fprintf(dbg_log, "sblkno        ufs_daddr_t       0x%08x\n",
14869800Stomsoft	    sb->fs_sblkno);
14969800Stomsoft	fprintf(dbg_log, "cblkno        ufs_daddr_t       0x%08x\n",
15069800Stomsoft	    sb->fs_cblkno);
15169800Stomsoft	fprintf(dbg_log, "iblkno        ufs_daddr_t       0x%08x\n",
15269800Stomsoft	    sb->fs_iblkno);
15369800Stomsoft	fprintf(dbg_log, "dblkno        ufs_daddr_t       0x%08x\n",
15469800Stomsoft	    sb->fs_dblkno);
15569800Stomsoft
15669800Stomsoft	fprintf(dbg_log, "cgoffset      int32_t           0x%08x\n",
15769800Stomsoft	    sb->fs_cgoffset);
15869800Stomsoft	fprintf(dbg_log, "cgmask        int32_t           0x%08x\n",
15969800Stomsoft	    sb->fs_cgmask);
16077885Stomsoft	fprintf(dbg_log, "time          time_t            %10u\n",
16177885Stomsoft	    (unsigned int)sb->fs_time);
16269800Stomsoft	fprintf(dbg_log, "size          int32_t           0x%08x\n",
16369800Stomsoft	    sb->fs_size);
16469800Stomsoft	fprintf(dbg_log, "dsize         int32_t           0x%08x\n",
16569800Stomsoft	    sb->fs_dsize);
16669800Stomsoft	fprintf(dbg_log, "ncg           int32_t           0x%08x\n",
16769800Stomsoft	    sb->fs_ncg);
16869800Stomsoft	fprintf(dbg_log, "bsize         int32_t           0x%08x\n",
16969800Stomsoft	    sb->fs_bsize);
17069800Stomsoft	fprintf(dbg_log, "fsize         int32_t           0x%08x\n",
17169800Stomsoft	    sb->fs_fsize);
17269800Stomsoft	fprintf(dbg_log, "frag          int32_t           0x%08x\n",
17369800Stomsoft	    sb->fs_frag);
17469800Stomsoft
17569800Stomsoft	fprintf(dbg_log, "minfree       int32_t           0x%08x\n",
17669800Stomsoft	    sb->fs_minfree);
17769800Stomsoft	fprintf(dbg_log, "rotdelay      int32_t           0x%08x\n",
17869800Stomsoft	    sb->fs_rotdelay);
17969800Stomsoft	fprintf(dbg_log, "rps           int32_t           0x%08x\n",
18069800Stomsoft	    sb->fs_rps);
18169800Stomsoft
18269800Stomsoft	fprintf(dbg_log, "bmask         int32_t           0x%08x\n",
18369800Stomsoft	    sb->fs_bmask);
18469800Stomsoft	fprintf(dbg_log, "fmask         int32_t           0x%08x\n",
18569800Stomsoft	    sb->fs_fmask);
18669800Stomsoft	fprintf(dbg_log, "bshift        int32_t           0x%08x\n",
18769800Stomsoft	    sb->fs_bshift);
18869800Stomsoft	fprintf(dbg_log, "fshift        int32_t           0x%08x\n",
18969800Stomsoft	    sb->fs_fshift);
19069800Stomsoft
19169800Stomsoft	fprintf(dbg_log, "maxcontig     int32_t           0x%08x\n",
19269800Stomsoft	    sb->fs_maxcontig);
19369800Stomsoft	fprintf(dbg_log, "maxbpg        int32_t           0x%08x\n",
19469800Stomsoft	    sb->fs_maxbpg);
19569800Stomsoft
19669800Stomsoft	fprintf(dbg_log, "fragshift     int32_t           0x%08x\n",
19769800Stomsoft	    sb->fs_fragshift);
19869800Stomsoft	fprintf(dbg_log, "fsbtodb       int32_t           0x%08x\n",
19969800Stomsoft	    sb->fs_fsbtodb);
20069800Stomsoft	fprintf(dbg_log, "sbsize        int32_t           0x%08x\n",
20169800Stomsoft	    sb->fs_sbsize);
20269800Stomsoft	fprintf(dbg_log, "csmask        int32_t           0x%08x\n",
20369800Stomsoft	    sb->fs_csmask);
20469800Stomsoft	fprintf(dbg_log, "csshift       int32_t           0x%08x\n",
20569800Stomsoft	    sb->fs_csshift);
20669800Stomsoft	fprintf(dbg_log, "nindir        int32_t           0x%08x\n",
20769800Stomsoft	    sb->fs_nindir);
20869800Stomsoft	fprintf(dbg_log, "inopb         int32_t           0x%08x\n",
20969800Stomsoft	    sb->fs_inopb);
21069800Stomsoft	fprintf(dbg_log, "nspf          int32_t           0x%08x\n",
21169800Stomsoft	    sb->fs_nspf);
21269800Stomsoft
21369800Stomsoft	fprintf(dbg_log, "optim         int32_t           0x%08x\n",
21469800Stomsoft	    sb->fs_optim);
21569800Stomsoft
21669800Stomsoft	fprintf(dbg_log, "npsect        int32_t           0x%08x\n",
21769800Stomsoft	    sb->fs_npsect);
21869800Stomsoft	fprintf(dbg_log, "interleave    int32_t           0x%08x\n",
21969800Stomsoft	    sb->fs_interleave);
22069800Stomsoft	fprintf(dbg_log, "trackskew     int32_t           0x%08x\n",
22169800Stomsoft	    sb->fs_trackskew);
22269800Stomsoft
22369800Stomsoft	fprintf(dbg_log, "id            int32_t[2]        %08x %08x\n",
22469800Stomsoft	    sb->fs_id[0], sb->fs_id[1]);
22569800Stomsoft
22669800Stomsoft	fprintf(dbg_log, "csaddr        ufs_daddr_t       0x%08x\n",
22769800Stomsoft	    sb->fs_csaddr);
22869800Stomsoft	fprintf(dbg_log, "cssize        int32_t           0x%08x\n",
22969800Stomsoft	    sb->fs_cssize);
23069800Stomsoft	fprintf(dbg_log, "cgsize        int32_t           0x%08x\n",
23169800Stomsoft	    sb->fs_cgsize);
23269800Stomsoft
23369800Stomsoft	fprintf(dbg_log, "ntrak         int32_t           0x%08x\n",
23469800Stomsoft	    sb->fs_ntrak);
23569800Stomsoft	fprintf(dbg_log, "nsect         int32_t           0x%08x\n",
23669800Stomsoft	    sb->fs_nsect);
23769800Stomsoft	fprintf(dbg_log, "spc           int32_t           0x%08x\n",
23869800Stomsoft	    sb->fs_spc);
23969800Stomsoft
24069800Stomsoft	fprintf(dbg_log, "ncyl          int32_t           0x%08x\n",
24169800Stomsoft	    sb->fs_ncyl);
24269800Stomsoft
24369800Stomsoft	fprintf(dbg_log, "cpg           int32_t           0x%08x\n",
24469800Stomsoft	    sb->fs_cpg);
24569800Stomsoft	fprintf(dbg_log, "ipg           int32_t           0x%08x\n",
24669800Stomsoft	    sb->fs_ipg);
24769800Stomsoft	fprintf(dbg_log, "fpg           int32_t           0x%08x\n",
24869800Stomsoft	    sb->fs_fpg);
24969800Stomsoft
25069800Stomsoft	dbg_dump_csum("internal cstotal", &sb->fs_cstotal);
25169800Stomsoft
25269800Stomsoft	fprintf(dbg_log, "fmod          int8_t            0x%02x\n",
25369800Stomsoft	    sb->fs_fmod);
25469800Stomsoft	fprintf(dbg_log, "clean         int8_t            0x%02x\n",
25569800Stomsoft	    sb->fs_clean);
25669800Stomsoft	fprintf(dbg_log, "ronly         int8_t            0x%02x\n",
25769800Stomsoft	    sb->fs_ronly);
25869800Stomsoft	fprintf(dbg_log, "flags         int8_t            0x%02x\n",
25969800Stomsoft	    sb->fs_flags);
26069800Stomsoft	fprintf(dbg_log, "fsmnt         u_char[MAXMNTLEN] \"%s\"\n",
26169800Stomsoft	    sb->fs_fsmnt);
26269800Stomsoft
26369800Stomsoft	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);*/
26969800Stomsoft	fprintf(dbg_log, "cpc           int32_t           0x%08x\n",
27069800Stomsoft	    sb->fs_cpc);
27169800Stomsoft/*
27269800Stomsoft * int16_t fs_opostbl[16][8] - is dumped when used in dbg_dump_sptbl
27369800Stomsoft */
27469800Stomsoft#ifdef FSMAXSNAP
27569800Stomsoft	for(j=0; j<FSMAXSNAP; j++) {
27669800Stomsoft		fprintf(dbg_log, "snapinum      int32_t[%2d]       0x%08x\n",
27769800Stomsoft		    j, sb->fs_snapinum[j]);
27869800Stomsoft		if(!sb->fs_snapinum[j]) { /* list is dense */
27969800Stomsoft			break;
28069800Stomsoft		}
28169800Stomsoft	}
28269800Stomsoft#endif /* FSMAXSNAP */
28369800Stomsoft	fprintf(dbg_log, "contigsumsize int32_t           0x%08x\n",
28469800Stomsoft	    sb->fs_contigsumsize);
28569800Stomsoft	fprintf(dbg_log, "maxsymlinklen int32_t           0x%08x\n",
28669800Stomsoft	    sb->fs_maxsymlinklen);
28769800Stomsoft	fprintf(dbg_log, "inodefmt      int32_t           0x%08x\n",
28869800Stomsoft	    sb->fs_inodefmt);
28969800Stomsoft	fprintf(dbg_log, "maxfilesize   u_int64_t         0x%08x%08x\n",
29069800Stomsoft	    ((unsigned int *)&(sb->fs_maxfilesize))[1],
29169800Stomsoft	    ((unsigned int *)&(sb->fs_maxfilesize))[0]);
29269800Stomsoft	fprintf(dbg_log, "qbmask        int64_t           0x%08x%08x\n",
29369800Stomsoft	    ((unsigned int *)&(sb->fs_qbmask))[1],
29469800Stomsoft	    ((unsigned int *)&(sb->fs_qbmask))[0]);
29569800Stomsoft	fprintf(dbg_log, "qfmask        int64_t           0x%08x%08x\n",
29669800Stomsoft	    ((unsigned int *)&(sb->fs_qfmask))[1],
29769800Stomsoft	    ((unsigned int *)&(sb->fs_qfmask))[0]);
29869800Stomsoft	fprintf(dbg_log, "state         int32_t           0x%08x\n",
29969800Stomsoft	    sb->fs_state);
30069800Stomsoft	fprintf(dbg_log, "postblformat  int32_t           0x%08x\n",
30169800Stomsoft	    sb->fs_postblformat);
30269800Stomsoft	fprintf(dbg_log, "nrpos         int32_t           0x%08x\n",
30369800Stomsoft	    sb->fs_nrpos);
30469800Stomsoft	fprintf(dbg_log, "postbloff     int32_t           0x%08x\n",
30569800Stomsoft	    sb->fs_postbloff);
30669800Stomsoft	fprintf(dbg_log, "rotbloff      int32_t           0x%08x\n",
30769800Stomsoft	    sb->fs_rotbloff);
30869800Stomsoft	fprintf(dbg_log, "magic         int32_t           0x%08x\n",
30969800Stomsoft	    sb->fs_magic);
31069800Stomsoft
31169800Stomsoft	indent--;
31269800Stomsoft	fprintf(dbg_log, "===== END SUPERBLOCK =====\n");
31369800Stomsoft
31469800Stomsoft	return;
31569800Stomsoft}
31669800Stomsoft
31769800Stomsoft/* ******************************************************* dbg_dump_cg ***** */
31869800Stomsoft/*
31969800Stomsoft * Dump a cylinder group.
32069800Stomsoft */
32169800Stomsoftvoid
32269800Stomsoftdbg_dump_cg(const char *comment, struct cg *cgr)
32369800Stomsoft{
32469800Stomsoft	int j;
32569800Stomsoft
32669800Stomsoft	if(!dbg_log) {
32769800Stomsoft		return;
32869800Stomsoft	}
32969800Stomsoft
33069800Stomsoft	fprintf(dbg_log, "===== START CYLINDER GROUP =====\n");
33169800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
33269800Stomsoft	indent++;
33369800Stomsoft
33469800Stomsoft	fprintf(dbg_log, "magic         int32_t    0x%08x\n", cgr->cg_magic);
33577885Stomsoft	fprintf(dbg_log, "time          time_t     %10u\n", (unsigned int)
33677885Stomsoft	    cgr->cg_time);
33769800Stomsoft	fprintf(dbg_log, "cgx           int32_t    0x%08x\n", cgr->cg_cgx);
33869800Stomsoft	fprintf(dbg_log, "ncyl          int16_t    0x%04x\n", cgr->cg_ncyl);
33969800Stomsoft	fprintf(dbg_log, "niblk         int16_t    0x%04x\n", cgr->cg_niblk);
34069800Stomsoft	fprintf(dbg_log, "ndblk         int32_t    0x%08x\n", cgr->cg_ndblk);
34169800Stomsoft	dbg_dump_csum("internal cs", &cgr->cg_cs);
34269800Stomsoft	fprintf(dbg_log, "rotor         int32_t    0x%08x\n", cgr->cg_rotor);
34369800Stomsoft	fprintf(dbg_log, "frotor        int32_t    0x%08x\n", cgr->cg_frotor);
34469800Stomsoft	fprintf(dbg_log, "irotor        int32_t    0x%08x\n", cgr->cg_irotor);
34569800Stomsoft	for(j=0; j<MAXFRAG; j++) {
34669800Stomsoft		fprintf(dbg_log, "frsum         int32_t[%d] 0x%08x\n", j,
34769800Stomsoft		    cgr->cg_frsum[j]);
34869800Stomsoft	}
34969800Stomsoft	fprintf(dbg_log, "btotoff       int32_t    0x%08x\n", cgr->cg_btotoff);
35069800Stomsoft	fprintf(dbg_log, "boff          int32_t    0x%08x\n", cgr->cg_boff);
35169800Stomsoft	fprintf(dbg_log, "iusedoff      int32_t    0x%08x\n", cgr->cg_iusedoff);
35269800Stomsoft	fprintf(dbg_log, "freeoff       int32_t    0x%08x\n", cgr->cg_freeoff);
35369800Stomsoft	fprintf(dbg_log, "nextfreeoff   int32_t    0x%08x\n",
35469800Stomsoft	    cgr->cg_nextfreeoff);
35569800Stomsoft	fprintf(dbg_log, "clustersumoff int32_t    0x%08x\n",
35669800Stomsoft	    cgr->cg_clustersumoff);
35769800Stomsoft	fprintf(dbg_log, "clusterof     int32_t    0x%08x\n",
35869800Stomsoft	    cgr->cg_clusteroff);
35969800Stomsoft	fprintf(dbg_log, "nclusterblks  int32_t    0x%08x\n",
36069800Stomsoft	    cgr->cg_nclusterblks);
36169800Stomsoft
36269800Stomsoft	indent--;
36369800Stomsoft	fprintf(dbg_log, "===== END CYLINDER GROUP =====\n");
36469800Stomsoft
36569800Stomsoft	return;
36669800Stomsoft}
36769800Stomsoft
36869800Stomsoft/* ***************************************************** dbg_dump_csum ***** */
36969800Stomsoft/*
37069800Stomsoft * Dump a cylinder summary.
37169800Stomsoft */
37269800Stomsoftvoid
37369800Stomsoftdbg_dump_csum(const char *comment, struct csum *cs)
37469800Stomsoft{
37569800Stomsoft
37669800Stomsoft	if(!dbg_log) {
37769800Stomsoft		return;
37869800Stomsoft	}
37969800Stomsoft
38069800Stomsoft	fprintf(dbg_log, "===== START CYLINDER SUMMARY =====\n");
38169800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cs, comment);
38269800Stomsoft	indent++;
38369800Stomsoft
38469800Stomsoft	fprintf(dbg_log, "ndir   int32_t 0x%08x\n", cs->cs_ndir);
38569800Stomsoft	fprintf(dbg_log, "nbfree int32_t 0x%08x\n", cs->cs_nbfree);
38669800Stomsoft	fprintf(dbg_log, "nifree int32_t 0x%08x\n", cs->cs_nifree);
38769800Stomsoft	fprintf(dbg_log, "nffree int32_t 0x%08x\n", cs->cs_nffree);
38869800Stomsoft
38969800Stomsoft	indent--;
39069800Stomsoft	fprintf(dbg_log, "===== END CYLINDER SUMMARY =====\n");
39169800Stomsoft
39269800Stomsoft	return;
39369800Stomsoft}
39469800Stomsoft
39569800Stomsoft/* **************************************************** dbg_dump_inmap ***** */
39669800Stomsoft/*
39769800Stomsoft * Dump the inode allocation map in one cylinder group.
39869800Stomsoft */
39969800Stomsoftvoid
40069800Stomsoftdbg_dump_inmap(struct fs *sb, const char *comment, struct cg *cgr)
40169800Stomsoft{
40269800Stomsoft	int j,k,l,e;
40369800Stomsoft	unsigned char *cp;
40469800Stomsoft
40569800Stomsoft	if(!dbg_log) {
40669800Stomsoft		return;
40769800Stomsoft	}
40869800Stomsoft
40969800Stomsoft	fprintf(dbg_log, "===== START INODE ALLOCATION MAP =====\n");
41069800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
41169800Stomsoft	indent++;
41269800Stomsoft
41369800Stomsoft	cp=(unsigned char *)cg_inosused(cgr);
41469800Stomsoft	e=sb->fs_ipg/8;
41569800Stomsoft	for(j=0; j<e; j+=32) {
41669800Stomsoft		fprintf(dbg_log, "%08x: ", j);
41769800Stomsoft		for(k=0; k<32; k+=8) {
41869800Stomsoft			if(j+k+8<e) {
41969800Stomsoft				fprintf(dbg_log,
42069800Stomsoft				    "%02x%02x%02x%02x%02x%02x%02x%02x ",
42169800Stomsoft				    cp[0], cp[1], cp[2], cp[3],
42269800Stomsoft				    cp[4], cp[5], cp[6], cp[7]);
42369800Stomsoft			} else {
42469800Stomsoft				for(l=0; (l<8)&&(j+k+l<e); l++) {
42569800Stomsoft					fprintf(dbg_log, "%02x", cp[l]);
42669800Stomsoft				}
42769800Stomsoft			}
42869800Stomsoft			cp+=8;
42969800Stomsoft		}
43069800Stomsoft		fprintf(dbg_log, "\n");
43169800Stomsoft	}
43269800Stomsoft
43369800Stomsoft	indent--;
43469800Stomsoft	fprintf(dbg_log, "===== END INODE ALLOCATION MAP =====\n");
43569800Stomsoft
43669800Stomsoft	return;
43769800Stomsoft}
43869800Stomsoft
43969800Stomsoft
44069800Stomsoft/* **************************************************** dbg_dump_frmap ***** */
44169800Stomsoft/*
44269800Stomsoft * Dump the fragment allocation map in one cylinder group.
44369800Stomsoft */
44469800Stomsoftvoid
44569800Stomsoftdbg_dump_frmap(struct fs *sb, const char *comment, struct cg *cgr)
44669800Stomsoft{
44769800Stomsoft	int j,k,l,e;
44869800Stomsoft	unsigned char *cp;
44969800Stomsoft
45069800Stomsoft	if(!dbg_log) {
45169800Stomsoft		return;
45269800Stomsoft	}
45369800Stomsoft
45469800Stomsoft	fprintf(dbg_log, "===== START FRAGMENT ALLOCATION MAP =====\n");
45569800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
45669800Stomsoft	indent++;
45769800Stomsoft
45869800Stomsoft	cp=(unsigned char *)cg_blksfree(cgr);
45969800Stomsoft	e=howmany((sb->fs_cpg * sb->fs_spc / NSPF(sb)), NBBY);
46069800Stomsoft	for(j=0; j<e; j+=32) {
46169800Stomsoft		fprintf(dbg_log, "%08x: ", j);
46269800Stomsoft		for(k=0; k<32; k+=8) {
46369800Stomsoft			if(j+k+8<e) {
46469800Stomsoft				fprintf(dbg_log,
46569800Stomsoft				    "%02x%02x%02x%02x%02x%02x%02x%02x ",
46669800Stomsoft				    cp[0], cp[1], cp[2], cp[3],
46769800Stomsoft				    cp[4], cp[5], cp[6], cp[7]);
46869800Stomsoft			} else {
46969800Stomsoft				for(l=0; (l<8)&&(j+k+l<e); l++) {
47069800Stomsoft					fprintf(dbg_log, "%02x", cp[l]);
47169800Stomsoft				}
47269800Stomsoft			}
47369800Stomsoft			cp+=8;
47469800Stomsoft		}
47569800Stomsoft		fprintf(dbg_log, "\n");
47669800Stomsoft	}
47769800Stomsoft
47869800Stomsoft	indent--;
47969800Stomsoft	fprintf(dbg_log, "===== END FRAGMENT ALLOCATION MAP =====\n");
48069800Stomsoft
48169800Stomsoft	return;
48269800Stomsoft}
48369800Stomsoft
48469800Stomsoft/* **************************************************** dbg_dump_clmap ***** */
48569800Stomsoft/*
48669800Stomsoft * Dump the cluster allocation map in one cylinder group.
48769800Stomsoft */
48869800Stomsoftvoid
48969800Stomsoftdbg_dump_clmap(struct fs *sb, const char *comment, struct cg *cgr)
49069800Stomsoft{
49169800Stomsoft	int j,k,l,e;
49269800Stomsoft	unsigned char *cp;
49369800Stomsoft
49469800Stomsoft	if(!dbg_log) {
49569800Stomsoft		return;
49669800Stomsoft	}
49769800Stomsoft
49869800Stomsoft	fprintf(dbg_log, "===== START CLUSTER ALLOCATION MAP =====\n");
49969800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
50069800Stomsoft	indent++;
50169800Stomsoft
50269800Stomsoft	cp=(unsigned char *)cg_clustersfree(cgr);
50369800Stomsoft	e=howmany(sb->fs_cpg * sb->fs_spc / NSPB(sb), NBBY);
50469800Stomsoft	for(j=0; j<e; j+=32) {
50569800Stomsoft		fprintf(dbg_log, "%08x: ", j);
50669800Stomsoft		for(k=0; k<32; k+=8) {
50769800Stomsoft			if(j+k+8<e) {
50869800Stomsoft				fprintf(dbg_log,
50969800Stomsoft				    "%02x%02x%02x%02x%02x%02x%02x%02x ",
51069800Stomsoft				    cp[0], cp[1], cp[2], cp[3],
51169800Stomsoft				    cp[4], cp[5], cp[6], cp[7]);
51269800Stomsoft			} else {
51369800Stomsoft				for(l=0; (l<8)&&(j+k+l<e); l++) {
51469800Stomsoft					fprintf(dbg_log, "%02x", cp[l]);
51569800Stomsoft				}
51669800Stomsoft			}
51769800Stomsoft			cp+=8;
51869800Stomsoft		}
51969800Stomsoft		fprintf(dbg_log, "\n");
52069800Stomsoft	}
52169800Stomsoft
52269800Stomsoft	indent--;
52369800Stomsoft	fprintf(dbg_log, "===== END CLUSTER ALLOCATION MAP =====\n");
52469800Stomsoft
52569800Stomsoft	return;
52669800Stomsoft}
52769800Stomsoft
52869800Stomsoft/* **************************************************** dbg_dump_clsum ***** */
52969800Stomsoft/*
53069800Stomsoft * Dump the cluster availability summary of one cylinder group.
53169800Stomsoft */
53269800Stomsoftvoid
53369800Stomsoftdbg_dump_clsum(struct fs *sb, const char *comment, struct cg *cgr)
53469800Stomsoft{
53569800Stomsoft	int j;
53677885Stomsoft	int *ip;
53769800Stomsoft
53869800Stomsoft	if(!dbg_log) {
53969800Stomsoft		return;
54069800Stomsoft	}
54169800Stomsoft
54269800Stomsoft	fprintf(dbg_log, "===== START CLUSTER SUMMARY =====\n");
54369800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
54469800Stomsoft	indent++;
54569800Stomsoft
54677885Stomsoft	ip=(int *)cg_clustersum(cgr);
54769800Stomsoft	for(j=0; j<=sb->fs_contigsumsize; j++) {
54877885Stomsoft		fprintf(dbg_log, "%02d: %8d\n", j, *ip++);
54969800Stomsoft	}
55069800Stomsoft
55169800Stomsoft	indent--;
55269800Stomsoft	fprintf(dbg_log, "===== END CLUSTER SUMMARY =====\n");
55369800Stomsoft
55469800Stomsoft	return;
55569800Stomsoft}
55669800Stomsoft
55769800Stomsoft/* **************************************************** dbg_dump_sptbl ***** */
55869800Stomsoft/*
55969800Stomsoft * Dump the block summary, and the rotational layout table.
56069800Stomsoft */
56169800Stomsoftvoid
56269800Stomsoftdbg_dump_sptbl(struct fs *sb, const char *comment, struct cg *cgr)
56369800Stomsoft{
56469800Stomsoft	int j,k;
56577885Stomsoft	int *ip;
56669800Stomsoft
56769800Stomsoft	if(!dbg_log) {
56869800Stomsoft		return;
56969800Stomsoft	}
57069800Stomsoft
57169800Stomsoft	fprintf(dbg_log,
57269800Stomsoft	    "===== START BLOCK SUMMARY AND POSITION TABLE =====\n");
57369800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment);
57469800Stomsoft	indent++;
57569800Stomsoft
57677885Stomsoft	ip=(int *)cg_blktot(cgr);
57769800Stomsoft	for(j=0; j<sb->fs_cpg; j++) {
57877885Stomsoft		fprintf(dbg_log, "%2d: %5d = ", j, *ip++);
57969800Stomsoft		for(k=0; k<sb->fs_nrpos; k++) {
58069800Stomsoft			fprintf(dbg_log, "%4d", cg_blks(sb, cgr, j)[k]);
58169800Stomsoft			if(k<sb->fs_nrpos-1) {
58269800Stomsoft				fprintf(dbg_log, " + ");
58369800Stomsoft			}
58469800Stomsoft		}
58569800Stomsoft		fprintf(dbg_log, "\n");
58669800Stomsoft	}
58769800Stomsoft
58869800Stomsoft	indent--;
58969800Stomsoft	fprintf(dbg_log, "===== END BLOCK SUMMARY AND POSITION TABLE =====\n");
59069800Stomsoft
59169800Stomsoft	return;
59269800Stomsoft}
59369800Stomsoft
59469800Stomsoft/* ****************************************************** dbg_dump_ino ***** */
59569800Stomsoft/*
59669800Stomsoft * Dump an inode structure.
59769800Stomsoft */
59869800Stomsoftvoid
59969800Stomsoftdbg_dump_ino(struct fs *sb, const char *comment, struct dinode *ino)
60069800Stomsoft{
60169800Stomsoft	int ictr;
60269800Stomsoft	int remaining_blocks;
60369800Stomsoft
60469800Stomsoft	if(!dbg_log) {
60569800Stomsoft		return;
60669800Stomsoft	}
60769800Stomsoft
60869800Stomsoft	fprintf(dbg_log, "===== START INODE DUMP =====\n");
60969800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)ino, comment);
61069800Stomsoft	indent++;
61169800Stomsoft
61269800Stomsoft	fprintf(dbg_log, "mode       u_int16_t      0%o\n", ino->di_mode);
61369800Stomsoft	fprintf(dbg_log, "nlink      int16_t        0x%04x\n", ino->di_nlink);
61469800Stomsoft	fprintf(dbg_log, "size       u_int64_t      0x%08x%08x\n",
61569800Stomsoft	    ((unsigned int *)&(ino->di_size))[1],
61669800Stomsoft	    ((unsigned int *)&(ino->di_size))[0]);
61769800Stomsoft	fprintf(dbg_log, "atime      int32_t        0x%08x\n", ino->di_atime);
61869800Stomsoft	fprintf(dbg_log, "atimensec  int32_t        0x%08x\n",
61969800Stomsoft	    ino->di_atimensec);
62069800Stomsoft	fprintf(dbg_log, "mtime      int32_t        0x%08x\n",
62169800Stomsoft	    ino->di_mtime);
62269800Stomsoft	fprintf(dbg_log, "mtimensec  int32_t        0x%08x\n",
62369800Stomsoft	    ino->di_mtimensec);
62469800Stomsoft	fprintf(dbg_log, "ctime      int32_t        0x%08x\n", ino->di_ctime);
62569800Stomsoft	fprintf(dbg_log, "ctimensec  int32_t        0x%08x\n",
62669800Stomsoft	    ino->di_ctimensec);
62769800Stomsoft
62869800Stomsoft	remaining_blocks=howmany(ino->di_size, sb->fs_bsize); /* XXX ts - +1? */
62969800Stomsoft	for(ictr=0; ictr < MIN(NDADDR, remaining_blocks); ictr++) {
63069800Stomsoft		fprintf(dbg_log, "db         ufs_daddr_t[%x] 0x%08x\n", ictr,
63169800Stomsoft		    ino->di_db[ictr]);
63269800Stomsoft	}
63369800Stomsoft	remaining_blocks-=NDADDR;
63469800Stomsoft	if(remaining_blocks>0) {
63569800Stomsoft		fprintf(dbg_log, "ib         ufs_daddr_t[0] 0x%08x\n",
63669800Stomsoft		    ino->di_ib[0]);
63769800Stomsoft	}
63869800Stomsoft	remaining_blocks-=howmany(sb->fs_bsize, sizeof(ufs_daddr_t));
63969800Stomsoft	if(remaining_blocks>0) {
64069800Stomsoft		fprintf(dbg_log, "ib         ufs_daddr_t[1] 0x%08x\n",
64169800Stomsoft		    ino->di_ib[1]);
64269800Stomsoft	}
64369800Stomsoft#define SQUARE(a) ((a)*(a))
64469800Stomsoft	remaining_blocks-=SQUARE(howmany(sb->fs_bsize, sizeof(ufs_daddr_t)));
64569800Stomsoft#undef SQUARE
64669800Stomsoft	if(remaining_blocks>0) {
64769800Stomsoft		fprintf(dbg_log, "ib         ufs_daddr_t[2] 0x%08x\n",
64869800Stomsoft		    ino->di_ib[2]);
64969800Stomsoft	}
65069800Stomsoft
65169800Stomsoft	fprintf(dbg_log, "flags      u_int32_t      0x%08x\n", ino->di_flags);
65269800Stomsoft	fprintf(dbg_log, "blocks     int32_t        0x%08x\n", ino->di_blocks);
65369800Stomsoft	fprintf(dbg_log, "gen        int32_t        0x%08x\n", ino->di_gen);
65469800Stomsoft	fprintf(dbg_log, "uid        u_int32_t      0x%08x\n", ino->di_uid);
65569800Stomsoft	fprintf(dbg_log, "gid        u_int32_t      0x%08x\n", ino->di_gid);
65669800Stomsoft
65769800Stomsoft	indent--;
65869800Stomsoft	fprintf(dbg_log, "===== END INODE DUMP =====\n");
65969800Stomsoft
66069800Stomsoft	return;
66169800Stomsoft}
66269800Stomsoft
66369800Stomsoft/* ***************************************************** dbg_dump_iblk ***** */
66469800Stomsoft/*
66569800Stomsoft * Dump an indirect block. The iteration to dump a full file has to be
66669800Stomsoft * written around.
66769800Stomsoft */
66869800Stomsoftvoid
66969800Stomsoftdbg_dump_iblk(struct fs *sb, const char *comment, char *block, size_t length)
67069800Stomsoft{
67169800Stomsoft	unsigned int *mem;
67269800Stomsoft	int i, j;
67369800Stomsoft
67469800Stomsoft	if(!dbg_log) {
67569800Stomsoft		return;
67669800Stomsoft	}
67769800Stomsoft
67869800Stomsoft	fprintf(dbg_log, "===== START INDIRECT BLOCK DUMP =====\n");
67969800Stomsoft	fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)block,
68069800Stomsoft	    comment);
68169800Stomsoft	indent++;
68269800Stomsoft
68369800Stomsoft	mem=(unsigned int *)block;
68469800Stomsoft	for (i=0; (size_t)i<MIN(howmany(sb->fs_bsize, sizeof(ufs_daddr_t)),
68569800Stomsoft	    length); i+=8) {
68669800Stomsoft		fprintf(dbg_log, "%04x: ", i);
68769800Stomsoft		for (j=0; j<8; j++) {
68869800Stomsoft			if((size_t)(i+j)<length) {
68969800Stomsoft				fprintf(dbg_log, "%08X ", *mem++);
69069800Stomsoft			}
69169800Stomsoft		}
69269800Stomsoft		fprintf(dbg_log, "\n");
69369800Stomsoft	}
69469800Stomsoft
69569800Stomsoft	indent--;
69669800Stomsoft	fprintf(dbg_log, "===== END INDIRECT BLOCK DUMP =====\n");
69769800Stomsoft
69869800Stomsoft	return;
69969800Stomsoft}
70069800Stomsoft
70169800Stomsoft#endif /* FS_DEBUG */
70269800Stomsoft
703