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$"; 4569800Stomsoft#endif /* not lint */ 4669800Stomsoft 4769800Stomsoft#include <sys/param.h> 4869800Stomsoft 49103949Smike#include <limits.h> 5069800Stomsoft#include <stdio.h> 51127798Sle#include <string.h> 5269800Stomsoft#include <ufs/ufs/dinode.h> 5369800Stomsoft#include <ufs/ffs/fs.h> 5469800Stomsoft 5569800Stomsoft#include "debug.h" 5669800Stomsoft 5769800Stomsoft#ifdef FS_DEBUG 5869800Stomsoft 59237497Straszstatic FILE *dbg_log = NULL; 60237497Straszstatic unsigned int indent = 0; 6169800Stomsoft 6269800Stomsoft/* 6369800Stomsoft * prototypes not done here, as they come with debug.h 6469800Stomsoft */ 6569800Stomsoft 6669800Stomsoft/* 6769800Stomsoft * Open the filehandle where all debug output has to go. 6869800Stomsoft */ 6969800Stomsoftvoid 7069800Stomsoftdbg_open(const char *fn) 7169800Stomsoft{ 7269800Stomsoft 7392743Srwatson if (strcmp(fn, "-") == 0) 74237497Strasz dbg_log = fopen("/dev/stdout", "a"); 7592743Srwatson else 76237497Strasz dbg_log = fopen(fn, "a"); 7769800Stomsoft 7869800Stomsoft return; 7969800Stomsoft} 8069800Stomsoft 8169800Stomsoft/* 8269800Stomsoft * Close the filehandle where all debug output went to. 8369800Stomsoft */ 8469800Stomsoftvoid 8569800Stomsoftdbg_close(void) 8669800Stomsoft{ 8769800Stomsoft 88237497Strasz if (dbg_log) { 8969800Stomsoft fclose(dbg_log); 90237497Strasz dbg_log = NULL; 9169800Stomsoft } 9269800Stomsoft 9369800Stomsoft return; 9469800Stomsoft} 9569800Stomsoft 9669800Stomsoft/* 97102231Strhodes * Dump out a full file system block in hex. 9869800Stomsoft */ 9969800Stomsoftvoid 10069800Stomsoftdbg_dump_hex(struct fs *sb, const char *comment, unsigned char *mem) 10169800Stomsoft{ 10269800Stomsoft int i, j, k; 10369800Stomsoft 104237497Strasz if (!dbg_log) 10569800Stomsoft return; 106237497Strasz 10769800Stomsoft fprintf(dbg_log, "===== START HEXDUMP =====\n"); 10869800Stomsoft fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)mem, comment); 10969800Stomsoft indent++; 110237497Strasz for (i = 0; i < sb->fs_bsize; i += 24) { 111237497Strasz for (j = 0; j < 3; j++) { 112237497Strasz for (k = 0; k < 8; k++) 11369800Stomsoft fprintf(dbg_log, "%02x ", *mem++); 11469800Stomsoft fprintf(dbg_log, " "); 11569800Stomsoft } 11669800Stomsoft fprintf(dbg_log, "\n"); 11769800Stomsoft } 11869800Stomsoft indent--; 11969800Stomsoft fprintf(dbg_log, "===== END HEXDUMP =====\n"); 12069800Stomsoft 12169800Stomsoft return; 12269800Stomsoft} 12369800Stomsoft 12469800Stomsoft/* 12569800Stomsoft * Dump the superblock. 12669800Stomsoft */ 12769800Stomsoftvoid 12869800Stomsoftdbg_dump_fs(struct fs *sb, const char *comment) 12969800Stomsoft{ 130237497Strasz int j; 13169800Stomsoft 132237497Strasz if (!dbg_log) 13369800Stomsoft return; 13469800Stomsoft 13569800Stomsoft fprintf(dbg_log, "===== START SUPERBLOCK =====\n"); 13669800Stomsoft fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)sb, comment); 13769800Stomsoft indent++; 13869800Stomsoft 139118915Srwatson fprintf(dbg_log, "sblkno int32_t 0x%08x\n", 14069800Stomsoft sb->fs_sblkno); 141118915Srwatson fprintf(dbg_log, "cblkno int32_t 0x%08x\n", 14269800Stomsoft sb->fs_cblkno); 143118915Srwatson fprintf(dbg_log, "iblkno int32_t 0x%08x\n", 14469800Stomsoft sb->fs_iblkno); 145118915Srwatson fprintf(dbg_log, "dblkno int32_t 0x%08x\n", 14669800Stomsoft sb->fs_dblkno); 14769800Stomsoft 148118915Srwatson fprintf(dbg_log, "old_cgoffset int32_t 0x%08x\n", 149118915Srwatson sb->fs_old_cgoffset); 150118915Srwatson fprintf(dbg_log, "old_cgmask int32_t 0x%08x\n", 151118915Srwatson sb->fs_old_cgmask); 152118915Srwatson fprintf(dbg_log, "old_time int32_t %10u\n", 153118915Srwatson (unsigned int)sb->fs_old_time); 154118915Srwatson fprintf(dbg_log, "old_size int32_t 0x%08x\n", 155118915Srwatson sb->fs_old_size); 156118915Srwatson fprintf(dbg_log, "old_dsize int32_t 0x%08x\n", 157118915Srwatson sb->fs_old_dsize); 158118915Srwatson fprintf(dbg_log, "ncg int32_t 0x%08x\n", 15969800Stomsoft sb->fs_ncg); 160118915Srwatson fprintf(dbg_log, "bsize int32_t 0x%08x\n", 16169800Stomsoft sb->fs_bsize); 162118915Srwatson fprintf(dbg_log, "fsize int32_t 0x%08x\n", 16369800Stomsoft sb->fs_fsize); 164118915Srwatson fprintf(dbg_log, "frag int32_t 0x%08x\n", 16569800Stomsoft sb->fs_frag); 16669800Stomsoft 167118915Srwatson fprintf(dbg_log, "minfree int32_t 0x%08x\n", 16869800Stomsoft sb->fs_minfree); 169118915Srwatson fprintf(dbg_log, "old_rotdelay int32_t 0x%08x\n", 170118915Srwatson sb->fs_old_rotdelay); 171118915Srwatson fprintf(dbg_log, "old_rps int32_t 0x%08x\n", 172118915Srwatson sb->fs_old_rps); 17369800Stomsoft 174118915Srwatson fprintf(dbg_log, "bmask int32_t 0x%08x\n", 17569800Stomsoft sb->fs_bmask); 176118915Srwatson fprintf(dbg_log, "fmask int32_t 0x%08x\n", 17769800Stomsoft sb->fs_fmask); 178118915Srwatson fprintf(dbg_log, "bshift int32_t 0x%08x\n", 17969800Stomsoft sb->fs_bshift); 180118915Srwatson fprintf(dbg_log, "fshift int32_t 0x%08x\n", 18169800Stomsoft sb->fs_fshift); 18269800Stomsoft 183118915Srwatson fprintf(dbg_log, "maxcontig int32_t 0x%08x\n", 18469800Stomsoft sb->fs_maxcontig); 185118915Srwatson fprintf(dbg_log, "maxbpg int32_t 0x%08x\n", 18669800Stomsoft sb->fs_maxbpg); 18769800Stomsoft 188118915Srwatson fprintf(dbg_log, "fragshift int32_t 0x%08x\n", 18969800Stomsoft sb->fs_fragshift); 190118915Srwatson fprintf(dbg_log, "fsbtodb int32_t 0x%08x\n", 19169800Stomsoft sb->fs_fsbtodb); 192118915Srwatson fprintf(dbg_log, "sbsize int32_t 0x%08x\n", 19369800Stomsoft sb->fs_sbsize); 194118915Srwatson fprintf(dbg_log, "spare1 int32_t[2] 0x%08x 0x%08x\n", 195118915Srwatson sb->fs_spare1[0], sb->fs_spare1[1]); 196118915Srwatson fprintf(dbg_log, "nindir int32_t 0x%08x\n", 19769800Stomsoft sb->fs_nindir); 198118915Srwatson fprintf(dbg_log, "inopb int32_t 0x%08x\n", 19969800Stomsoft sb->fs_inopb); 200118915Srwatson fprintf(dbg_log, "old_nspf int32_t 0x%08x\n", 201118915Srwatson sb->fs_old_nspf); 20269800Stomsoft 203118915Srwatson fprintf(dbg_log, "optim int32_t 0x%08x\n", 20469800Stomsoft sb->fs_optim); 20569800Stomsoft 206118915Srwatson fprintf(dbg_log, "old_npsect int32_t 0x%08x\n", 207118915Srwatson sb->fs_old_npsect); 208118915Srwatson fprintf(dbg_log, "old_interleave int32_t 0x%08x\n", 209118915Srwatson sb->fs_old_interleave); 210118915Srwatson fprintf(dbg_log, "old_trackskew int32_t 0x%08x\n", 211118915Srwatson sb->fs_old_trackskew); 21269800Stomsoft 213118915Srwatson fprintf(dbg_log, "id int32_t[2] 0x%08x 0x%08x\n", 21469800Stomsoft sb->fs_id[0], sb->fs_id[1]); 21569800Stomsoft 216118915Srwatson fprintf(dbg_log, "old_csaddr int32_t 0x%08x\n", 217118915Srwatson sb->fs_old_csaddr); 218118915Srwatson fprintf(dbg_log, "cssize int32_t 0x%08x\n", 21969800Stomsoft sb->fs_cssize); 220118915Srwatson fprintf(dbg_log, "cgsize int32_t 0x%08x\n", 22169800Stomsoft sb->fs_cgsize); 22269800Stomsoft 223118915Srwatson fprintf(dbg_log, "spare2 int32_t 0x%08x\n", 224118915Srwatson sb->fs_spare2); 225118915Srwatson fprintf(dbg_log, "old_nsect int32_t 0x%08x\n", 226118915Srwatson sb->fs_old_nsect); 227118915Srwatson fprintf(dbg_log, "old_spc int32_t 0x%08x\n", 228118915Srwatson sb->fs_old_spc); 22969800Stomsoft 230118915Srwatson fprintf(dbg_log, "old_ncyl int32_t 0x%08x\n", 231118915Srwatson sb->fs_old_ncyl); 23269800Stomsoft 233118915Srwatson fprintf(dbg_log, "old_cpg int32_t 0x%08x\n", 234118915Srwatson sb->fs_old_cpg); 235118915Srwatson fprintf(dbg_log, "ipg int32_t 0x%08x\n", 23669800Stomsoft sb->fs_ipg); 237118915Srwatson fprintf(dbg_log, "fpg int32_t 0x%08x\n", 23869800Stomsoft sb->fs_fpg); 23969800Stomsoft 240118915Srwatson dbg_dump_csum("internal old_cstotal", &sb->fs_old_cstotal); 24169800Stomsoft 242118915Srwatson fprintf(dbg_log, "fmod int8_t 0x%02x\n", 24369800Stomsoft sb->fs_fmod); 244118915Srwatson fprintf(dbg_log, "clean int8_t 0x%02x\n", 24569800Stomsoft sb->fs_clean); 246118915Srwatson fprintf(dbg_log, "ronly int8_t 0x%02x\n", 24769800Stomsoft sb->fs_ronly); 248118915Srwatson fprintf(dbg_log, "old_flags int8_t 0x%02x\n", 249118915Srwatson sb->fs_old_flags); 250118915Srwatson fprintf(dbg_log, "fsmnt u_char[MAXMNTLEN] \"%s\"\n", 25169800Stomsoft sb->fs_fsmnt); 252118915Srwatson fprintf(dbg_log, "volname u_char[MAXVOLLEN] \"%s\"\n", 253118915Srwatson sb->fs_volname); 254118915Srwatson fprintf(dbg_log, "swuid u_int64_t 0x%08x%08x\n", 255118915Srwatson ((unsigned int *)&(sb->fs_swuid))[1], 256118915Srwatson ((unsigned int *)&(sb->fs_swuid))[0]); 25769800Stomsoft 258118915Srwatson fprintf(dbg_log, "pad int32_t 0x%08x\n", 259118915Srwatson sb->fs_pad); 260118915Srwatson 261118915Srwatson 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);*/ 267118915Srwatson fprintf(dbg_log, "old_cpc int32_t 0x%08x\n", 268118915Srwatson sb->fs_old_cpc); 26969800Stomsoft/* 27069800Stomsoft * int16_t fs_opostbl[16][8] - is dumped when used in dbg_dump_sptbl 27169800Stomsoft */ 272118915Srwatson fprintf(dbg_log, "maxbsize int32_t 0x%08x\n", 273118915Srwatson sb->fs_maxbsize); 274215704Sbrucec fprintf(dbg_log, "unrefs int64_t 0x%08jx\n", 275163844Spjd sb->fs_unrefs); 276118915Srwatson fprintf(dbg_log, "sblockloc int64_t 0x%08x%08x\n", 277118915Srwatson ((unsigned int *)&(sb->fs_sblockloc))[1], 278118915Srwatson ((unsigned int *)&(sb->fs_sblockloc))[0]); 279118915Srwatson 280118915Srwatson dbg_dump_csum_total("internal cstotal", &sb->fs_cstotal); 281118915Srwatson 282118915Srwatson fprintf(dbg_log, "time ufs_time_t %10u\n", 283118915Srwatson (unsigned int)sb->fs_time); 284118915Srwatson 285118915Srwatson fprintf(dbg_log, "size int64_t 0x%08x%08x\n", 286118915Srwatson ((unsigned int *)&(sb->fs_size))[1], 287118915Srwatson ((unsigned int *)&(sb->fs_size))[0]); 288118915Srwatson fprintf(dbg_log, "dsize int64_t 0x%08x%08x\n", 289118915Srwatson ((unsigned int *)&(sb->fs_dsize))[1], 290118915Srwatson ((unsigned int *)&(sb->fs_dsize))[0]); 291118915Srwatson fprintf(dbg_log, "csaddr ufs2_daddr_t 0x%08x%08x\n", 292118915Srwatson ((unsigned int *)&(sb->fs_csaddr))[1], 293118915Srwatson ((unsigned int *)&(sb->fs_csaddr))[0]); 294118915Srwatson fprintf(dbg_log, "pendingblocks int64_t 0x%08x%08x\n", 295118915Srwatson ((unsigned int *)&(sb->fs_pendingblocks))[1], 296118915Srwatson ((unsigned int *)&(sb->fs_pendingblocks))[0]); 297118915Srwatson fprintf(dbg_log, "pendinginodes int32_t 0x%08x\n", 298118915Srwatson sb->fs_pendinginodes); 299118915Srwatson 300237497Strasz for (j = 0; j < FSMAXSNAP; j++) { 301118915Srwatson fprintf(dbg_log, "snapinum int32_t[%2d] 0x%08x\n", 30269800Stomsoft j, sb->fs_snapinum[j]); 303237497Strasz if (!sb->fs_snapinum[j]) { /* list is dense */ 30469800Stomsoft break; 30569800Stomsoft } 30669800Stomsoft } 307118915Srwatson fprintf(dbg_log, "avgfilesize int32_t 0x%08x\n", 308118915Srwatson sb->fs_avgfilesize); 309118915Srwatson fprintf(dbg_log, "avgfpdir int32_t 0x%08x\n", 310118915Srwatson sb->fs_avgfpdir); 311118915Srwatson fprintf(dbg_log, "save_cgsize int32_t 0x%08x\n", 312118915Srwatson sb->fs_save_cgsize); 313118915Srwatson fprintf(dbg_log, "flags int32_t 0x%08x\n", 314118915Srwatson sb->fs_flags); 315118915Srwatson fprintf(dbg_log, "contigsumsize int32_t 0x%08x\n", 31669800Stomsoft sb->fs_contigsumsize); 317118915Srwatson fprintf(dbg_log, "maxsymlinklen int32_t 0x%08x\n", 31869800Stomsoft sb->fs_maxsymlinklen); 319118915Srwatson fprintf(dbg_log, "old_inodefmt int32_t 0x%08x\n", 320118915Srwatson sb->fs_old_inodefmt); 321118915Srwatson fprintf(dbg_log, "maxfilesize u_int64_t 0x%08x%08x\n", 32269800Stomsoft ((unsigned int *)&(sb->fs_maxfilesize))[1], 32369800Stomsoft ((unsigned int *)&(sb->fs_maxfilesize))[0]); 324118915Srwatson fprintf(dbg_log, "qbmask int64_t 0x%08x%08x\n", 32569800Stomsoft ((unsigned int *)&(sb->fs_qbmask))[1], 32669800Stomsoft ((unsigned int *)&(sb->fs_qbmask))[0]); 327118915Srwatson fprintf(dbg_log, "qfmask int64_t 0x%08x%08x\n", 32869800Stomsoft ((unsigned int *)&(sb->fs_qfmask))[1], 32969800Stomsoft ((unsigned int *)&(sb->fs_qfmask))[0]); 330118915Srwatson fprintf(dbg_log, "state int32_t 0x%08x\n", 33169800Stomsoft sb->fs_state); 332118915Srwatson fprintf(dbg_log, "old_postblformat int32_t 0x%08x\n", 333118915Srwatson sb->fs_old_postblformat); 334118915Srwatson fprintf(dbg_log, "old_nrpos int32_t 0x%08x\n", 335118915Srwatson sb->fs_old_nrpos); 336118915Srwatson fprintf(dbg_log, "spare5 int32_t[2] 0x%08x 0x%08x\n", 337118915Srwatson sb->fs_spare5[0], sb->fs_spare5[1]); 338118915Srwatson fprintf(dbg_log, "magic int32_t 0x%08x\n", 33969800Stomsoft sb->fs_magic); 34069800Stomsoft 34169800Stomsoft indent--; 34269800Stomsoft fprintf(dbg_log, "===== END SUPERBLOCK =====\n"); 34369800Stomsoft 34469800Stomsoft return; 34569800Stomsoft} 34669800Stomsoft 34769800Stomsoft/* 34869800Stomsoft * Dump a cylinder group. 34969800Stomsoft */ 35069800Stomsoftvoid 35169800Stomsoftdbg_dump_cg(const char *comment, struct cg *cgr) 35269800Stomsoft{ 35369800Stomsoft int j; 35469800Stomsoft 355237497Strasz if (!dbg_log) 35669800Stomsoft return; 35769800Stomsoft 35869800Stomsoft fprintf(dbg_log, "===== START CYLINDER GROUP =====\n"); 35969800Stomsoft fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment); 36069800Stomsoft indent++; 36169800Stomsoft 36269800Stomsoft fprintf(dbg_log, "magic int32_t 0x%08x\n", cgr->cg_magic); 363118915Srwatson fprintf(dbg_log, "old_time int32_t 0x%08x\n", cgr->cg_old_time); 36469800Stomsoft fprintf(dbg_log, "cgx int32_t 0x%08x\n", cgr->cg_cgx); 365118915Srwatson fprintf(dbg_log, "old_ncyl int16_t 0x%04x\n", cgr->cg_old_ncyl); 366118915Srwatson fprintf(dbg_log, "old_niblk int16_t 0x%04x\n", cgr->cg_old_niblk); 36769800Stomsoft fprintf(dbg_log, "ndblk int32_t 0x%08x\n", cgr->cg_ndblk); 36869800Stomsoft dbg_dump_csum("internal cs", &cgr->cg_cs); 36969800Stomsoft fprintf(dbg_log, "rotor int32_t 0x%08x\n", cgr->cg_rotor); 37069800Stomsoft fprintf(dbg_log, "frotor int32_t 0x%08x\n", cgr->cg_frotor); 37169800Stomsoft fprintf(dbg_log, "irotor int32_t 0x%08x\n", cgr->cg_irotor); 372237497Strasz for (j = 0; j < MAXFRAG; j++) { 37369800Stomsoft fprintf(dbg_log, "frsum int32_t[%d] 0x%08x\n", j, 37469800Stomsoft cgr->cg_frsum[j]); 37569800Stomsoft } 376118915Srwatson fprintf(dbg_log, "old_btotoff int32_t 0x%08x\n", cgr->cg_old_btotoff); 377118915Srwatson fprintf(dbg_log, "old_boff int32_t 0x%08x\n", cgr->cg_old_boff); 37869800Stomsoft fprintf(dbg_log, "iusedoff int32_t 0x%08x\n", cgr->cg_iusedoff); 37969800Stomsoft fprintf(dbg_log, "freeoff int32_t 0x%08x\n", cgr->cg_freeoff); 38069800Stomsoft fprintf(dbg_log, "nextfreeoff int32_t 0x%08x\n", 38169800Stomsoft cgr->cg_nextfreeoff); 38269800Stomsoft fprintf(dbg_log, "clustersumoff int32_t 0x%08x\n", 38369800Stomsoft cgr->cg_clustersumoff); 384118915Srwatson fprintf(dbg_log, "clusteroff int32_t 0x%08x\n", 38569800Stomsoft cgr->cg_clusteroff); 38669800Stomsoft fprintf(dbg_log, "nclusterblks int32_t 0x%08x\n", 38769800Stomsoft cgr->cg_nclusterblks); 388118915Srwatson fprintf(dbg_log, "niblk int32_t 0x%08x\n", cgr->cg_niblk); 389118915Srwatson fprintf(dbg_log, "initediblk int32_t 0x%08x\n", cgr->cg_initediblk); 390163844Spjd fprintf(dbg_log, "unrefs int32_t 0x%08x\n", cgr->cg_unrefs); 391118915Srwatson fprintf(dbg_log, "time ufs_time_t %10u\n", 392118915Srwatson (unsigned int)cgr->cg_initediblk); 39369800Stomsoft 39469800Stomsoft indent--; 39569800Stomsoft fprintf(dbg_log, "===== END CYLINDER GROUP =====\n"); 39669800Stomsoft 39769800Stomsoft return; 39869800Stomsoft} 39969800Stomsoft 40069800Stomsoft/* 40169800Stomsoft * Dump a cylinder summary. 40269800Stomsoft */ 40369800Stomsoftvoid 40469800Stomsoftdbg_dump_csum(const char *comment, struct csum *cs) 40569800Stomsoft{ 40669800Stomsoft 407237497Strasz if (!dbg_log) 40869800Stomsoft return; 40969800Stomsoft 41069800Stomsoft fprintf(dbg_log, "===== START CYLINDER SUMMARY =====\n"); 41169800Stomsoft fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cs, comment); 41269800Stomsoft indent++; 41369800Stomsoft 41469800Stomsoft fprintf(dbg_log, "ndir int32_t 0x%08x\n", cs->cs_ndir); 41569800Stomsoft fprintf(dbg_log, "nbfree int32_t 0x%08x\n", cs->cs_nbfree); 41669800Stomsoft fprintf(dbg_log, "nifree int32_t 0x%08x\n", cs->cs_nifree); 41769800Stomsoft fprintf(dbg_log, "nffree int32_t 0x%08x\n", cs->cs_nffree); 41869800Stomsoft 41969800Stomsoft indent--; 42069800Stomsoft fprintf(dbg_log, "===== END CYLINDER SUMMARY =====\n"); 42169800Stomsoft 42269800Stomsoft return; 42369800Stomsoft} 42469800Stomsoft 425118915Srwatson/* 426118915Srwatson * Dump a cylinder summary. 427118915Srwatson */ 428118915Srwatsonvoid 429118915Srwatsondbg_dump_csum_total(const char *comment, struct csum_total *cs) 430118915Srwatson{ 431118915Srwatson 432237497Strasz if (!dbg_log) 433118915Srwatson return; 434118915Srwatson 435118915Srwatson fprintf(dbg_log, "===== START CYLINDER SUMMARY TOTAL =====\n"); 436118915Srwatson fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cs, comment); 437118915Srwatson indent++; 438118915Srwatson 439118915Srwatson fprintf(dbg_log, "ndir int64_t 0x%08x%08x\n", 440118915Srwatson ((unsigned int *)&(cs->cs_ndir))[1], 441118915Srwatson ((unsigned int *)&(cs->cs_ndir))[0]); 442118915Srwatson fprintf(dbg_log, "nbfree int64_t 0x%08x%08x\n", 443118915Srwatson ((unsigned int *)&(cs->cs_nbfree))[1], 444118915Srwatson ((unsigned int *)&(cs->cs_nbfree))[0]); 445118915Srwatson fprintf(dbg_log, "nifree int64_t 0x%08x%08x\n", 446118915Srwatson ((unsigned int *)&(cs->cs_nifree))[1], 447118915Srwatson ((unsigned int *)&(cs->cs_nifree))[0]); 448118915Srwatson fprintf(dbg_log, "nffree int64_t 0x%08x%08x\n", 449118915Srwatson ((unsigned int *)&(cs->cs_nffree))[1], 450118915Srwatson ((unsigned int *)&(cs->cs_nffree))[0]); 451118915Srwatson fprintf(dbg_log, "numclusters int64_t 0x%08x%08x\n", 452118915Srwatson ((unsigned int *)&(cs->cs_numclusters))[1], 453118915Srwatson ((unsigned int *)&(cs->cs_numclusters))[0]); 454118915Srwatson 455118915Srwatson indent--; 456118915Srwatson fprintf(dbg_log, "===== END CYLINDER SUMMARY TOTAL =====\n"); 457118915Srwatson 458118915Srwatson return; 459118915Srwatson} 46069800Stomsoft/* 46169800Stomsoft * Dump the inode allocation map in one cylinder group. 46269800Stomsoft */ 46369800Stomsoftvoid 46469800Stomsoftdbg_dump_inmap(struct fs *sb, const char *comment, struct cg *cgr) 46569800Stomsoft{ 46669800Stomsoft int j,k,l,e; 46769800Stomsoft unsigned char *cp; 46869800Stomsoft 469237497Strasz if (!dbg_log) 47069800Stomsoft return; 47169800Stomsoft 47269800Stomsoft fprintf(dbg_log, "===== START INODE ALLOCATION MAP =====\n"); 47369800Stomsoft fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment); 47469800Stomsoft indent++; 47569800Stomsoft 476237497Strasz cp = (unsigned char *)cg_inosused(cgr); 477237497Strasz e = sb->fs_ipg / 8; 478237497Strasz for (j = 0; j < e; j += 32) { 47969800Stomsoft fprintf(dbg_log, "%08x: ", j); 480237497Strasz for (k = 0; k < 32; k += 8) { 481237497Strasz if (j + k + 8 < e) { 48269800Stomsoft fprintf(dbg_log, 48369800Stomsoft "%02x%02x%02x%02x%02x%02x%02x%02x ", 48469800Stomsoft cp[0], cp[1], cp[2], cp[3], 48569800Stomsoft cp[4], cp[5], cp[6], cp[7]); 48669800Stomsoft } else { 487237497Strasz for (l = 0; (l < 8) && (j + k + l < e); l++) { 48869800Stomsoft fprintf(dbg_log, "%02x", cp[l]); 48969800Stomsoft } 49069800Stomsoft } 491237497Strasz cp += 8; 49269800Stomsoft } 49369800Stomsoft fprintf(dbg_log, "\n"); 49469800Stomsoft } 49569800Stomsoft 49669800Stomsoft indent--; 49769800Stomsoft fprintf(dbg_log, "===== END INODE ALLOCATION MAP =====\n"); 49869800Stomsoft 49969800Stomsoft return; 50069800Stomsoft} 50169800Stomsoft 50269800Stomsoft 50369800Stomsoft/* 50469800Stomsoft * Dump the fragment allocation map in one cylinder group. 50569800Stomsoft */ 50669800Stomsoftvoid 50769800Stomsoftdbg_dump_frmap(struct fs *sb, const char *comment, struct cg *cgr) 50869800Stomsoft{ 50969800Stomsoft int j,k,l,e; 51069800Stomsoft unsigned char *cp; 51169800Stomsoft 512237497Strasz if (!dbg_log) 51369800Stomsoft return; 51469800Stomsoft 51569800Stomsoft fprintf(dbg_log, "===== START FRAGMENT ALLOCATION MAP =====\n"); 51669800Stomsoft fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment); 51769800Stomsoft indent++; 51869800Stomsoft 519237497Strasz cp = (unsigned char *)cg_blksfree(cgr); 520118915Srwatson if (sb->fs_old_nspf) 521237497Strasz e = howmany((sb->fs_old_cpg * sb->fs_old_spc / sb->fs_old_nspf), CHAR_BIT); 522118915Srwatson else 523118915Srwatson e = 0; 524237497Strasz for (j = 0; j < e; j += 32) { 52569800Stomsoft fprintf(dbg_log, "%08x: ", j); 526237497Strasz for (k = 0; k < 32; k += 8) { 527237497Strasz if (j + k + 8 <e) { 52869800Stomsoft fprintf(dbg_log, 52969800Stomsoft "%02x%02x%02x%02x%02x%02x%02x%02x ", 53069800Stomsoft cp[0], cp[1], cp[2], cp[3], 53169800Stomsoft cp[4], cp[5], cp[6], cp[7]); 53269800Stomsoft } else { 533237497Strasz for (l = 0; (l < 8) && (j + k + l < e); l++) { 53469800Stomsoft fprintf(dbg_log, "%02x", cp[l]); 53569800Stomsoft } 53669800Stomsoft } 537237497Strasz cp += 8; 53869800Stomsoft } 53969800Stomsoft fprintf(dbg_log, "\n"); 54069800Stomsoft } 54169800Stomsoft 54269800Stomsoft indent--; 54369800Stomsoft fprintf(dbg_log, "===== END FRAGMENT ALLOCATION MAP =====\n"); 54469800Stomsoft 54569800Stomsoft return; 54669800Stomsoft} 54769800Stomsoft 54869800Stomsoft/* 54969800Stomsoft * Dump the cluster allocation map in one cylinder group. 55069800Stomsoft */ 55169800Stomsoftvoid 55269800Stomsoftdbg_dump_clmap(struct fs *sb, const char *comment, struct cg *cgr) 55369800Stomsoft{ 55469800Stomsoft int j,k,l,e; 55569800Stomsoft unsigned char *cp; 55669800Stomsoft 557237497Strasz if (!dbg_log) 55869800Stomsoft return; 55969800Stomsoft 56069800Stomsoft fprintf(dbg_log, "===== START CLUSTER ALLOCATION MAP =====\n"); 56169800Stomsoft fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment); 56269800Stomsoft indent++; 56369800Stomsoft 564237497Strasz cp = (unsigned char *)cg_clustersfree(cgr); 565118915Srwatson if (sb->fs_old_nspf) 566237497Strasz e = howmany(sb->fs_old_cpg * sb->fs_old_spc / (sb->fs_old_nspf << sb->fs_fragshift), CHAR_BIT); 567118915Srwatson else 568118915Srwatson e = 0; 569237497Strasz for (j = 0; j < e; j += 32) { 57069800Stomsoft fprintf(dbg_log, "%08x: ", j); 571237497Strasz for (k = 0; k < 32; k += 8) { 572237497Strasz if (j + k + 8 < e) { 57369800Stomsoft fprintf(dbg_log, 57469800Stomsoft "%02x%02x%02x%02x%02x%02x%02x%02x ", 57569800Stomsoft cp[0], cp[1], cp[2], cp[3], 57669800Stomsoft cp[4], cp[5], cp[6], cp[7]); 57769800Stomsoft } else { 578237497Strasz for (l = 0; (l < 8) && (j + k + l <e); l++) { 57969800Stomsoft fprintf(dbg_log, "%02x", cp[l]); 58069800Stomsoft } 58169800Stomsoft } 582237497Strasz cp += 8; 58369800Stomsoft } 58469800Stomsoft fprintf(dbg_log, "\n"); 58569800Stomsoft } 58669800Stomsoft 58769800Stomsoft indent--; 58869800Stomsoft fprintf(dbg_log, "===== END CLUSTER ALLOCATION MAP =====\n"); 58969800Stomsoft 59069800Stomsoft return; 59169800Stomsoft} 59269800Stomsoft 59369800Stomsoft/* 59469800Stomsoft * Dump the cluster availability summary of one cylinder group. 59569800Stomsoft */ 59669800Stomsoftvoid 59769800Stomsoftdbg_dump_clsum(struct fs *sb, const char *comment, struct cg *cgr) 59869800Stomsoft{ 59969800Stomsoft int j; 60077885Stomsoft int *ip; 60169800Stomsoft 602237497Strasz if (!dbg_log) 60369800Stomsoft return; 60469800Stomsoft 60569800Stomsoft fprintf(dbg_log, "===== START CLUSTER SUMMARY =====\n"); 60669800Stomsoft fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment); 60769800Stomsoft indent++; 60869800Stomsoft 609237497Strasz ip = (int *)cg_clustersum(cgr); 610237497Strasz for (j = 0; j <= sb->fs_contigsumsize; j++) { 61177885Stomsoft fprintf(dbg_log, "%02d: %8d\n", j, *ip++); 61269800Stomsoft } 61369800Stomsoft 61469800Stomsoft indent--; 61569800Stomsoft fprintf(dbg_log, "===== END CLUSTER SUMMARY =====\n"); 61669800Stomsoft 61769800Stomsoft return; 61869800Stomsoft} 61969800Stomsoft 620118915Srwatson#ifdef NOT_CURRENTLY 621118915Srwatson/* 622118915Srwatson * This code dates from before the UFS2 integration, and doesn't compile 623118915Srwatson * post-UFS2 due to the use of cg_blks(). I'm not sure how best to update 624118915Srwatson * this for UFS2, where the rotational bits of UFS no longer apply, so 625118915Srwatson * will leave it disabled for now; it should probably be re-enabled 626118915Srwatson * specifically for UFS1. 627118915Srwatson */ 62869800Stomsoft/* 62969800Stomsoft * Dump the block summary, and the rotational layout table. 63069800Stomsoft */ 63169800Stomsoftvoid 63269800Stomsoftdbg_dump_sptbl(struct fs *sb, const char *comment, struct cg *cgr) 63369800Stomsoft{ 63469800Stomsoft int j,k; 63577885Stomsoft int *ip; 63669800Stomsoft 637237497Strasz if (!dbg_log) 63869800Stomsoft return; 63969800Stomsoft 64069800Stomsoft fprintf(dbg_log, 64169800Stomsoft "===== START BLOCK SUMMARY AND POSITION TABLE =====\n"); 64269800Stomsoft fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment); 64369800Stomsoft indent++; 64469800Stomsoft 645237497Strasz ip = (int *)cg_blktot(cgr); 646237497Strasz for (j = 0; j < sb->fs_old_cpg; j++) { 64777885Stomsoft fprintf(dbg_log, "%2d: %5d = ", j, *ip++); 648237497Strasz for (k = 0; k < sb->fs_old_nrpos; k++) { 64969800Stomsoft fprintf(dbg_log, "%4d", cg_blks(sb, cgr, j)[k]); 650237497Strasz if (k < sb->fs_old_nrpos - 1) 65169800Stomsoft fprintf(dbg_log, " + "); 65269800Stomsoft } 65369800Stomsoft fprintf(dbg_log, "\n"); 65469800Stomsoft } 65569800Stomsoft 65669800Stomsoft indent--; 65769800Stomsoft fprintf(dbg_log, "===== END BLOCK SUMMARY AND POSITION TABLE =====\n"); 65869800Stomsoft 65969800Stomsoft return; 66069800Stomsoft} 661118915Srwatson#endif 66269800Stomsoft 66369800Stomsoft/* 664118915Srwatson * Dump a UFS1 inode structure. 66569800Stomsoft */ 66669800Stomsoftvoid 667118915Srwatsondbg_dump_ufs1_ino(struct fs *sb, const char *comment, struct ufs1_dinode *ino) 66869800Stomsoft{ 66969800Stomsoft int ictr; 67069800Stomsoft int remaining_blocks; 67169800Stomsoft 672237497Strasz if (!dbg_log) 67369800Stomsoft return; 67469800Stomsoft 675118915Srwatson fprintf(dbg_log, "===== START UFS1 INODE DUMP =====\n"); 67669800Stomsoft fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)ino, comment); 67769800Stomsoft indent++; 67869800Stomsoft 67969800Stomsoft fprintf(dbg_log, "mode u_int16_t 0%o\n", ino->di_mode); 68069800Stomsoft fprintf(dbg_log, "nlink int16_t 0x%04x\n", ino->di_nlink); 68169800Stomsoft fprintf(dbg_log, "size u_int64_t 0x%08x%08x\n", 68269800Stomsoft ((unsigned int *)&(ino->di_size))[1], 68369800Stomsoft ((unsigned int *)&(ino->di_size))[0]); 68469800Stomsoft fprintf(dbg_log, "atime int32_t 0x%08x\n", ino->di_atime); 68569800Stomsoft fprintf(dbg_log, "atimensec int32_t 0x%08x\n", 68669800Stomsoft ino->di_atimensec); 68769800Stomsoft fprintf(dbg_log, "mtime int32_t 0x%08x\n", 68869800Stomsoft ino->di_mtime); 68969800Stomsoft fprintf(dbg_log, "mtimensec int32_t 0x%08x\n", 69069800Stomsoft ino->di_mtimensec); 69169800Stomsoft fprintf(dbg_log, "ctime int32_t 0x%08x\n", ino->di_ctime); 69269800Stomsoft fprintf(dbg_log, "ctimensec int32_t 0x%08x\n", 69369800Stomsoft ino->di_ctimensec); 69469800Stomsoft 695237497Strasz remaining_blocks = howmany(ino->di_size, sb->fs_bsize); /* XXX ts - +1? */ 696237497Strasz for (ictr = 0; ictr < MIN(NDADDR, remaining_blocks); ictr++) { 69769800Stomsoft fprintf(dbg_log, "db ufs_daddr_t[%x] 0x%08x\n", ictr, 69869800Stomsoft ino->di_db[ictr]); 69969800Stomsoft } 700237497Strasz remaining_blocks -= NDADDR; 701237497Strasz if (remaining_blocks > 0) { 70269800Stomsoft fprintf(dbg_log, "ib ufs_daddr_t[0] 0x%08x\n", 70369800Stomsoft ino->di_ib[0]); 70469800Stomsoft } 705237497Strasz remaining_blocks -= howmany(sb->fs_bsize, sizeof(ufs1_daddr_t)); 706237497Strasz if (remaining_blocks > 0) { 70769800Stomsoft fprintf(dbg_log, "ib ufs_daddr_t[1] 0x%08x\n", 70869800Stomsoft ino->di_ib[1]); 70969800Stomsoft } 710237497Strasz#define SQUARE(a) ((a) * (a)) 711237497Strasz remaining_blocks -= SQUARE(howmany(sb->fs_bsize, sizeof(ufs1_daddr_t))); 71269800Stomsoft#undef SQUARE 713237497Strasz if (remaining_blocks > 0) { 71469800Stomsoft fprintf(dbg_log, "ib ufs_daddr_t[2] 0x%08x\n", 71569800Stomsoft ino->di_ib[2]); 71669800Stomsoft } 71769800Stomsoft 71869800Stomsoft fprintf(dbg_log, "flags u_int32_t 0x%08x\n", ino->di_flags); 71969800Stomsoft fprintf(dbg_log, "blocks int32_t 0x%08x\n", ino->di_blocks); 72069800Stomsoft fprintf(dbg_log, "gen int32_t 0x%08x\n", ino->di_gen); 72169800Stomsoft fprintf(dbg_log, "uid u_int32_t 0x%08x\n", ino->di_uid); 72269800Stomsoft fprintf(dbg_log, "gid u_int32_t 0x%08x\n", ino->di_gid); 72369800Stomsoft 72469800Stomsoft indent--; 725118915Srwatson fprintf(dbg_log, "===== END UFS1 INODE DUMP =====\n"); 72669800Stomsoft 72769800Stomsoft return; 72869800Stomsoft} 72969800Stomsoft 730118915Srwatson/* 731118915Srwatson * Dump a UFS2 inode structure. 732118915Srwatson */ 733118915Srwatsonvoid 734118915Srwatsondbg_dump_ufs2_ino(struct fs *sb, const char *comment, struct ufs2_dinode *ino) 735118915Srwatson{ 736118915Srwatson int ictr; 737118915Srwatson int remaining_blocks; 738118915Srwatson 739237497Strasz if (!dbg_log) 740118915Srwatson return; 741118915Srwatson 742118915Srwatson fprintf(dbg_log, "===== START UFS2 INODE DUMP =====\n"); 743118915Srwatson fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)ino, comment); 744118915Srwatson indent++; 745118915Srwatson 746118915Srwatson fprintf(dbg_log, "mode u_int16_t 0%o\n", ino->di_mode); 747118915Srwatson fprintf(dbg_log, "nlink int16_t 0x%04x\n", ino->di_nlink); 748118915Srwatson fprintf(dbg_log, "uid u_int32_t 0x%08x\n", ino->di_uid); 749118915Srwatson fprintf(dbg_log, "gid u_int32_t 0x%08x\n", ino->di_gid); 750118915Srwatson fprintf(dbg_log, "blksize u_int32_t 0x%08x\n", ino->di_blksize); 751118915Srwatson fprintf(dbg_log, "size u_int64_t 0x%08x%08x\n", 752118915Srwatson ((unsigned int *)&(ino->di_size))[1], 753118915Srwatson ((unsigned int *)&(ino->di_size))[0]); 754118915Srwatson fprintf(dbg_log, "blocks u_int64_t 0x%08x%08x\n", 755237497Strasz ((unsigned int *)&(ino->di_blocks))[1], 756237497Strasz ((unsigned int *)&(ino->di_blocks))[0]); 757127798Sle fprintf(dbg_log, "atime ufs_time_t %10jd\n", ino->di_atime); 758127798Sle fprintf(dbg_log, "mtime ufs_time_t %10jd\n", ino->di_mtime); 759127798Sle fprintf(dbg_log, "ctime ufs_time_t %10jd\n", ino->di_ctime); 760127798Sle fprintf(dbg_log, "birthtime ufs_time_t %10jd\n", ino->di_birthtime); 761118915Srwatson fprintf(dbg_log, "mtimensec int32_t 0x%08x\n", ino->di_mtimensec); 762118915Srwatson fprintf(dbg_log, "atimensec int32_t 0x%08x\n", ino->di_atimensec); 763118915Srwatson fprintf(dbg_log, "ctimensec int32_t 0x%08x\n", ino->di_ctimensec); 764118915Srwatson fprintf(dbg_log, "birthnsec int32_t 0x%08x\n", ino->di_birthnsec); 765118915Srwatson fprintf(dbg_log, "gen int32_t 0x%08x\n", ino->di_gen); 766118915Srwatson fprintf(dbg_log, "kernflags u_int32_t 0x%08x\n", ino->di_kernflags); 767118915Srwatson fprintf(dbg_log, "flags u_int32_t 0x%08x\n", ino->di_flags); 768259224Spfg fprintf(dbg_log, "extsize u_int32_t 0x%08x\n", ino->di_extsize); 769118915Srwatson 770118915Srwatson /* XXX: What do we do with di_extb[NXADDR]? */ 771118915Srwatson 772237497Strasz remaining_blocks = howmany(ino->di_size, sb->fs_bsize); /* XXX ts - +1? */ 773237497Strasz for (ictr = 0; ictr < MIN(NDADDR, remaining_blocks); ictr++) { 774127798Sle fprintf(dbg_log, "db ufs2_daddr_t[%x] 0x%16jx\n", ictr, 775118915Srwatson ino->di_db[ictr]); 776118915Srwatson } 777237497Strasz remaining_blocks -= NDADDR; 778237497Strasz if (remaining_blocks > 0) { 779127798Sle fprintf(dbg_log, "ib ufs2_daddr_t[0] 0x%16jx\n", 780118915Srwatson ino->di_ib[0]); 781118915Srwatson } 782237497Strasz remaining_blocks -= howmany(sb->fs_bsize, sizeof(ufs2_daddr_t)); 783237497Strasz if (remaining_blocks > 0) { 784127798Sle fprintf(dbg_log, "ib ufs2_daddr_t[1] 0x%16jx\n", 785118915Srwatson ino->di_ib[1]); 786118915Srwatson } 787237497Strasz#define SQUARE(a) ((a) * (a)) 788237497Strasz remaining_blocks -= SQUARE(howmany(sb->fs_bsize, sizeof(ufs2_daddr_t))); 789118915Srwatson#undef SQUARE 790237497Strasz if (remaining_blocks > 0) { 791127798Sle fprintf(dbg_log, "ib ufs2_daddr_t[2] 0x%16jx\n", 792118915Srwatson ino->di_ib[2]); 793118915Srwatson } 794118915Srwatson 795118915Srwatson indent--; 796118915Srwatson fprintf(dbg_log, "===== END UFS2 INODE DUMP =====\n"); 797118915Srwatson 798118915Srwatson return; 799118915Srwatson} 800118915Srwatson 80169800Stomsoft/* 80269800Stomsoft * Dump an indirect block. The iteration to dump a full file has to be 80369800Stomsoft * written around. 80469800Stomsoft */ 80569800Stomsoftvoid 80669800Stomsoftdbg_dump_iblk(struct fs *sb, const char *comment, char *block, size_t length) 80769800Stomsoft{ 808127798Sle unsigned int *mem, i, j, size; 80969800Stomsoft 810237497Strasz if (!dbg_log) 81169800Stomsoft return; 81269800Stomsoft 81369800Stomsoft fprintf(dbg_log, "===== START INDIRECT BLOCK DUMP =====\n"); 81469800Stomsoft fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)block, 81569800Stomsoft comment); 81669800Stomsoft indent++; 81769800Stomsoft 818118915Srwatson if (sb->fs_magic == FS_UFS1_MAGIC) 819118915Srwatson size = sizeof(ufs1_daddr_t); 820118915Srwatson else 821118915Srwatson size = sizeof(ufs2_daddr_t); 822118915Srwatson 823237497Strasz mem = (unsigned int *)block; 824237497Strasz for (i = 0; (size_t)i < MIN(howmany(sb->fs_bsize, size), length); 825237497Strasz i += 8) { 82669800Stomsoft fprintf(dbg_log, "%04x: ", i); 827237497Strasz for (j = 0; j < 8; j++) { 828237497Strasz if ((size_t)(i + j) < length) 82969800Stomsoft fprintf(dbg_log, "%08X ", *mem++); 83069800Stomsoft } 83169800Stomsoft fprintf(dbg_log, "\n"); 83269800Stomsoft } 83369800Stomsoft 83469800Stomsoft indent--; 83569800Stomsoft fprintf(dbg_log, "===== END INDIRECT BLOCK DUMP =====\n"); 83669800Stomsoft 83769800Stomsoft return; 83869800Stomsoft} 83969800Stomsoft 84069800Stomsoft#endif /* FS_DEBUG */ 84169800Stomsoft 842