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