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