1 /* 2 * Copyright (c) 2000 Christoph Herrmann, Thomas-Henning von Kamptz 3 * Copyright (c) 1980, 1989, 1993 The Regents of the University of California. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Christoph Herrmann and Thomas-Henning von Kamptz, Munich and Frankfurt. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgment: 19 * This product includes software developed by the University of 20 * California, Berkeley and its contributors, as well as Christoph 21 * Herrmann and Thomas-Henning von Kamptz. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * $TSHeader: src/sbin/growfs/debug.c,v 1.3 2000/12/12 19:31:00 tomsoft Exp $ 39 * 40 */ 41 42 #ifndef lint 43 static const char rcsid[] = 44 "$FreeBSD$"; 45 #endif /* not lint */ 46 47 /* ********************************************************** INCLUDES ***** */ 48 #include <sys/param.h> 49 50 #include <limits.h> 51 #include <stdio.h> 52 #include <ufs/ufs/dinode.h> 53 #include <ufs/ffs/fs.h> 54 55 #include "debug.h" 56 57 #ifdef FS_DEBUG 58 59 /* *********************************************************** GLOBALS ***** */ 60 static FILE *dbg_log=NULL; 61 static unsigned int indent=0; 62 63 /* 64 * prototypes not done here, as they come with debug.h 65 */ 66 67 /* ********************************************************** dbg_open ***** */ 68 /* 69 * Open the filehandle where all debug output has to go. 70 */ 71 void 72 dbg_open(const char *fn) 73 { 74 75 if (strcmp(fn, "-") == 0) 76 dbg_log=fopen("/dev/stdout", "a"); 77 else 78 dbg_log=fopen(fn, "a"); 79 80 return; 81 } 82 83 /* ********************************************************* dbg_close ***** */ 84 /* 85 * Close the filehandle where all debug output went to. 86 */ 87 void 88 dbg_close(void) 89 { 90 91 if(dbg_log) { 92 fclose(dbg_log); 93 dbg_log=NULL; 94 } 95 96 return; 97 } 98 99 /* ****************************************************** dbg_dump_hex ***** */ 100 /* 101 * Dump out a full file system block in hex. 102 */ 103 void 104 dbg_dump_hex(struct fs *sb, const char *comment, unsigned char *mem) 105 { 106 int i, j, k; 107 108 if(!dbg_log) { 109 return; 110 } 111 fprintf(dbg_log, "===== START HEXDUMP =====\n"); 112 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)mem, comment); 113 indent++; 114 for (i=0; i<sb->fs_bsize; i+=24) { 115 for (j=0; j<3; j++) { 116 for (k=0; k<8; k++) { 117 fprintf(dbg_log, "%02x ", *mem++); 118 } 119 fprintf(dbg_log, " "); 120 } 121 fprintf(dbg_log, "\n"); 122 } 123 indent--; 124 fprintf(dbg_log, "===== END HEXDUMP =====\n"); 125 126 return; 127 } 128 129 /* ******************************************************* dbg_dump_fs ***** */ 130 /* 131 * Dump the superblock. 132 */ 133 void 134 dbg_dump_fs(struct fs *sb, const char *comment) 135 { 136 #ifdef FSMAXSNAP 137 int j; 138 #endif /* FSMAXSNAP */ 139 140 if(!dbg_log) { 141 return; 142 } 143 144 fprintf(dbg_log, "===== START SUPERBLOCK =====\n"); 145 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)sb, comment); 146 indent++; 147 148 fprintf(dbg_log, "sblkno int32_t 0x%08x\n", 149 sb->fs_sblkno); 150 fprintf(dbg_log, "cblkno int32_t 0x%08x\n", 151 sb->fs_cblkno); 152 fprintf(dbg_log, "iblkno int32_t 0x%08x\n", 153 sb->fs_iblkno); 154 fprintf(dbg_log, "dblkno int32_t 0x%08x\n", 155 sb->fs_dblkno); 156 157 fprintf(dbg_log, "old_cgoffset int32_t 0x%08x\n", 158 sb->fs_old_cgoffset); 159 fprintf(dbg_log, "old_cgmask int32_t 0x%08x\n", 160 sb->fs_old_cgmask); 161 fprintf(dbg_log, "old_time int32_t %10u\n", 162 (unsigned int)sb->fs_old_time); 163 fprintf(dbg_log, "old_size int32_t 0x%08x\n", 164 sb->fs_old_size); 165 fprintf(dbg_log, "old_dsize int32_t 0x%08x\n", 166 sb->fs_old_dsize); 167 fprintf(dbg_log, "ncg int32_t 0x%08x\n", 168 sb->fs_ncg); 169 fprintf(dbg_log, "bsize int32_t 0x%08x\n", 170 sb->fs_bsize); 171 fprintf(dbg_log, "fsize int32_t 0x%08x\n", 172 sb->fs_fsize); 173 fprintf(dbg_log, "frag int32_t 0x%08x\n", 174 sb->fs_frag); 175 176 fprintf(dbg_log, "minfree int32_t 0x%08x\n", 177 sb->fs_minfree); 178 fprintf(dbg_log, "old_rotdelay int32_t 0x%08x\n", 179 sb->fs_old_rotdelay); 180 fprintf(dbg_log, "old_rps int32_t 0x%08x\n", 181 sb->fs_old_rps); 182 183 fprintf(dbg_log, "bmask int32_t 0x%08x\n", 184 sb->fs_bmask); 185 fprintf(dbg_log, "fmask int32_t 0x%08x\n", 186 sb->fs_fmask); 187 fprintf(dbg_log, "bshift int32_t 0x%08x\n", 188 sb->fs_bshift); 189 fprintf(dbg_log, "fshift int32_t 0x%08x\n", 190 sb->fs_fshift); 191 192 fprintf(dbg_log, "maxcontig int32_t 0x%08x\n", 193 sb->fs_maxcontig); 194 fprintf(dbg_log, "maxbpg int32_t 0x%08x\n", 195 sb->fs_maxbpg); 196 197 fprintf(dbg_log, "fragshift int32_t 0x%08x\n", 198 sb->fs_fragshift); 199 fprintf(dbg_log, "fsbtodb int32_t 0x%08x\n", 200 sb->fs_fsbtodb); 201 fprintf(dbg_log, "sbsize int32_t 0x%08x\n", 202 sb->fs_sbsize); 203 fprintf(dbg_log, "spare1 int32_t[2] 0x%08x 0x%08x\n", 204 sb->fs_spare1[0], sb->fs_spare1[1]); 205 fprintf(dbg_log, "nindir int32_t 0x%08x\n", 206 sb->fs_nindir); 207 fprintf(dbg_log, "inopb int32_t 0x%08x\n", 208 sb->fs_inopb); 209 fprintf(dbg_log, "old_nspf int32_t 0x%08x\n", 210 sb->fs_old_nspf); 211 212 fprintf(dbg_log, "optim int32_t 0x%08x\n", 213 sb->fs_optim); 214 215 fprintf(dbg_log, "old_npsect int32_t 0x%08x\n", 216 sb->fs_old_npsect); 217 fprintf(dbg_log, "old_interleave int32_t 0x%08x\n", 218 sb->fs_old_interleave); 219 fprintf(dbg_log, "old_trackskew int32_t 0x%08x\n", 220 sb->fs_old_trackskew); 221 222 fprintf(dbg_log, "id int32_t[2] 0x%08x 0x%08x\n", 223 sb->fs_id[0], sb->fs_id[1]); 224 225 fprintf(dbg_log, "old_csaddr int32_t 0x%08x\n", 226 sb->fs_old_csaddr); 227 fprintf(dbg_log, "cssize int32_t 0x%08x\n", 228 sb->fs_cssize); 229 fprintf(dbg_log, "cgsize int32_t 0x%08x\n", 230 sb->fs_cgsize); 231 232 fprintf(dbg_log, "spare2 int32_t 0x%08x\n", 233 sb->fs_spare2); 234 fprintf(dbg_log, "old_nsect int32_t 0x%08x\n", 235 sb->fs_old_nsect); 236 fprintf(dbg_log, "old_spc int32_t 0x%08x\n", 237 sb->fs_old_spc); 238 239 fprintf(dbg_log, "old_ncyl int32_t 0x%08x\n", 240 sb->fs_old_ncyl); 241 242 fprintf(dbg_log, "old_cpg int32_t 0x%08x\n", 243 sb->fs_old_cpg); 244 fprintf(dbg_log, "ipg int32_t 0x%08x\n", 245 sb->fs_ipg); 246 fprintf(dbg_log, "fpg int32_t 0x%08x\n", 247 sb->fs_fpg); 248 249 dbg_dump_csum("internal old_cstotal", &sb->fs_old_cstotal); 250 251 fprintf(dbg_log, "fmod int8_t 0x%02x\n", 252 sb->fs_fmod); 253 fprintf(dbg_log, "clean int8_t 0x%02x\n", 254 sb->fs_clean); 255 fprintf(dbg_log, "ronly int8_t 0x%02x\n", 256 sb->fs_ronly); 257 fprintf(dbg_log, "old_flags int8_t 0x%02x\n", 258 sb->fs_old_flags); 259 fprintf(dbg_log, "fsmnt u_char[MAXMNTLEN] \"%s\"\n", 260 sb->fs_fsmnt); 261 fprintf(dbg_log, "volname u_char[MAXVOLLEN] \"%s\"\n", 262 sb->fs_volname); 263 fprintf(dbg_log, "swuid u_int64_t 0x%08x%08x\n", 264 ((unsigned int *)&(sb->fs_swuid))[1], 265 ((unsigned int *)&(sb->fs_swuid))[0]); 266 267 fprintf(dbg_log, "pad int32_t 0x%08x\n", 268 sb->fs_pad); 269 270 fprintf(dbg_log, "cgrotor int32_t 0x%08x\n", 271 sb->fs_cgrotor); 272 /* 273 * struct csum[MAXCSBUFS] - is only maintained in memory 274 */ 275 /* fprintf(dbg_log, " int32_t\n", sb->*fs_maxcluster);*/ 276 fprintf(dbg_log, "old_cpc int32_t 0x%08x\n", 277 sb->fs_old_cpc); 278 /* 279 * int16_t fs_opostbl[16][8] - is dumped when used in dbg_dump_sptbl 280 */ 281 fprintf(dbg_log, "maxbsize int32_t 0x%08x\n", 282 sb->fs_maxbsize); 283 fprintf(dbg_log, "sblockloc int64_t 0x%08x%08x\n", 284 ((unsigned int *)&(sb->fs_sblockloc))[1], 285 ((unsigned int *)&(sb->fs_sblockloc))[0]); 286 287 dbg_dump_csum_total("internal cstotal", &sb->fs_cstotal); 288 289 fprintf(dbg_log, "time ufs_time_t %10u\n", 290 (unsigned int)sb->fs_time); 291 292 fprintf(dbg_log, "size int64_t 0x%08x%08x\n", 293 ((unsigned int *)&(sb->fs_size))[1], 294 ((unsigned int *)&(sb->fs_size))[0]); 295 fprintf(dbg_log, "dsize int64_t 0x%08x%08x\n", 296 ((unsigned int *)&(sb->fs_dsize))[1], 297 ((unsigned int *)&(sb->fs_dsize))[0]); 298 fprintf(dbg_log, "csaddr ufs2_daddr_t 0x%08x%08x\n", 299 ((unsigned int *)&(sb->fs_csaddr))[1], 300 ((unsigned int *)&(sb->fs_csaddr))[0]); 301 fprintf(dbg_log, "pendingblocks int64_t 0x%08x%08x\n", 302 ((unsigned int *)&(sb->fs_pendingblocks))[1], 303 ((unsigned int *)&(sb->fs_pendingblocks))[0]); 304 fprintf(dbg_log, "pendinginodes int32_t 0x%08x\n", 305 sb->fs_pendinginodes); 306 307 #ifdef FSMAXSNAP 308 for(j=0; j<FSMAXSNAP; j++) { 309 fprintf(dbg_log, "snapinum int32_t[%2d] 0x%08x\n", 310 j, sb->fs_snapinum[j]); 311 if(!sb->fs_snapinum[j]) { /* list is dense */ 312 break; 313 } 314 } 315 #endif /* FSMAXSNAP */ 316 fprintf(dbg_log, "avgfilesize int32_t 0x%08x\n", 317 sb->fs_avgfilesize); 318 fprintf(dbg_log, "avgfpdir int32_t 0x%08x\n", 319 sb->fs_avgfpdir); 320 fprintf(dbg_log, "save_cgsize int32_t 0x%08x\n", 321 sb->fs_save_cgsize); 322 fprintf(dbg_log, "flags int32_t 0x%08x\n", 323 sb->fs_flags); 324 fprintf(dbg_log, "contigsumsize int32_t 0x%08x\n", 325 sb->fs_contigsumsize); 326 fprintf(dbg_log, "maxsymlinklen int32_t 0x%08x\n", 327 sb->fs_maxsymlinklen); 328 fprintf(dbg_log, "old_inodefmt int32_t 0x%08x\n", 329 sb->fs_old_inodefmt); 330 fprintf(dbg_log, "maxfilesize u_int64_t 0x%08x%08x\n", 331 ((unsigned int *)&(sb->fs_maxfilesize))[1], 332 ((unsigned int *)&(sb->fs_maxfilesize))[0]); 333 fprintf(dbg_log, "qbmask int64_t 0x%08x%08x\n", 334 ((unsigned int *)&(sb->fs_qbmask))[1], 335 ((unsigned int *)&(sb->fs_qbmask))[0]); 336 fprintf(dbg_log, "qfmask int64_t 0x%08x%08x\n", 337 ((unsigned int *)&(sb->fs_qfmask))[1], 338 ((unsigned int *)&(sb->fs_qfmask))[0]); 339 fprintf(dbg_log, "state int32_t 0x%08x\n", 340 sb->fs_state); 341 fprintf(dbg_log, "old_postblformat int32_t 0x%08x\n", 342 sb->fs_old_postblformat); 343 fprintf(dbg_log, "old_nrpos int32_t 0x%08x\n", 344 sb->fs_old_nrpos); 345 fprintf(dbg_log, "spare5 int32_t[2] 0x%08x 0x%08x\n", 346 sb->fs_spare5[0], sb->fs_spare5[1]); 347 fprintf(dbg_log, "magic int32_t 0x%08x\n", 348 sb->fs_magic); 349 350 indent--; 351 fprintf(dbg_log, "===== END SUPERBLOCK =====\n"); 352 353 return; 354 } 355 356 /* ******************************************************* dbg_dump_cg ***** */ 357 /* 358 * Dump a cylinder group. 359 */ 360 void 361 dbg_dump_cg(const char *comment, struct cg *cgr) 362 { 363 int j; 364 365 if(!dbg_log) { 366 return; 367 } 368 369 fprintf(dbg_log, "===== START CYLINDER GROUP =====\n"); 370 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment); 371 indent++; 372 373 fprintf(dbg_log, "magic int32_t 0x%08x\n", cgr->cg_magic); 374 fprintf(dbg_log, "old_time int32_t 0x%08x\n", cgr->cg_old_time); 375 fprintf(dbg_log, "cgx int32_t 0x%08x\n", cgr->cg_cgx); 376 fprintf(dbg_log, "old_ncyl int16_t 0x%04x\n", cgr->cg_old_ncyl); 377 fprintf(dbg_log, "old_niblk int16_t 0x%04x\n", cgr->cg_old_niblk); 378 fprintf(dbg_log, "ndblk int32_t 0x%08x\n", cgr->cg_ndblk); 379 dbg_dump_csum("internal cs", &cgr->cg_cs); 380 fprintf(dbg_log, "rotor int32_t 0x%08x\n", cgr->cg_rotor); 381 fprintf(dbg_log, "frotor int32_t 0x%08x\n", cgr->cg_frotor); 382 fprintf(dbg_log, "irotor int32_t 0x%08x\n", cgr->cg_irotor); 383 for(j=0; j<MAXFRAG; j++) { 384 fprintf(dbg_log, "frsum int32_t[%d] 0x%08x\n", j, 385 cgr->cg_frsum[j]); 386 } 387 fprintf(dbg_log, "old_btotoff int32_t 0x%08x\n", cgr->cg_old_btotoff); 388 fprintf(dbg_log, "old_boff int32_t 0x%08x\n", cgr->cg_old_boff); 389 fprintf(dbg_log, "iusedoff int32_t 0x%08x\n", cgr->cg_iusedoff); 390 fprintf(dbg_log, "freeoff int32_t 0x%08x\n", cgr->cg_freeoff); 391 fprintf(dbg_log, "nextfreeoff int32_t 0x%08x\n", 392 cgr->cg_nextfreeoff); 393 fprintf(dbg_log, "clustersumoff int32_t 0x%08x\n", 394 cgr->cg_clustersumoff); 395 fprintf(dbg_log, "clusteroff int32_t 0x%08x\n", 396 cgr->cg_clusteroff); 397 fprintf(dbg_log, "nclusterblks int32_t 0x%08x\n", 398 cgr->cg_nclusterblks); 399 fprintf(dbg_log, "niblk int32_t 0x%08x\n", cgr->cg_niblk); 400 fprintf(dbg_log, "initediblk int32_t 0x%08x\n", cgr->cg_initediblk); 401 fprintf(dbg_log, "time ufs_time_t %10u\n", 402 (unsigned int)cgr->cg_initediblk); 403 404 indent--; 405 fprintf(dbg_log, "===== END CYLINDER GROUP =====\n"); 406 407 return; 408 } 409 410 /* ***************************************************** dbg_dump_csum ***** */ 411 /* 412 * Dump a cylinder summary. 413 */ 414 void 415 dbg_dump_csum(const char *comment, struct csum *cs) 416 { 417 418 if(!dbg_log) { 419 return; 420 } 421 422 fprintf(dbg_log, "===== START CYLINDER SUMMARY =====\n"); 423 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cs, comment); 424 indent++; 425 426 fprintf(dbg_log, "ndir int32_t 0x%08x\n", cs->cs_ndir); 427 fprintf(dbg_log, "nbfree int32_t 0x%08x\n", cs->cs_nbfree); 428 fprintf(dbg_log, "nifree int32_t 0x%08x\n", cs->cs_nifree); 429 fprintf(dbg_log, "nffree int32_t 0x%08x\n", cs->cs_nffree); 430 431 indent--; 432 fprintf(dbg_log, "===== END CYLINDER SUMMARY =====\n"); 433 434 return; 435 } 436 437 /* ************************************************ dbg_dump_csum_total ***** */ 438 /* 439 * Dump a cylinder summary. 440 */ 441 void 442 dbg_dump_csum_total(const char *comment, struct csum_total *cs) 443 { 444 445 if(!dbg_log) { 446 return; 447 } 448 449 fprintf(dbg_log, "===== START CYLINDER SUMMARY TOTAL =====\n"); 450 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cs, comment); 451 indent++; 452 453 fprintf(dbg_log, "ndir int64_t 0x%08x%08x\n", 454 ((unsigned int *)&(cs->cs_ndir))[1], 455 ((unsigned int *)&(cs->cs_ndir))[0]); 456 fprintf(dbg_log, "nbfree int64_t 0x%08x%08x\n", 457 ((unsigned int *)&(cs->cs_nbfree))[1], 458 ((unsigned int *)&(cs->cs_nbfree))[0]); 459 fprintf(dbg_log, "nifree int64_t 0x%08x%08x\n", 460 ((unsigned int *)&(cs->cs_nifree))[1], 461 ((unsigned int *)&(cs->cs_nifree))[0]); 462 fprintf(dbg_log, "nffree int64_t 0x%08x%08x\n", 463 ((unsigned int *)&(cs->cs_nffree))[1], 464 ((unsigned int *)&(cs->cs_nffree))[0]); 465 fprintf(dbg_log, "numclusters int64_t 0x%08x%08x\n", 466 ((unsigned int *)&(cs->cs_numclusters))[1], 467 ((unsigned int *)&(cs->cs_numclusters))[0]); 468 469 indent--; 470 fprintf(dbg_log, "===== END CYLINDER SUMMARY TOTAL =====\n"); 471 472 return; 473 } 474 /* **************************************************** dbg_dump_inmap ***** */ 475 /* 476 * Dump the inode allocation map in one cylinder group. 477 */ 478 void 479 dbg_dump_inmap(struct fs *sb, const char *comment, struct cg *cgr) 480 { 481 int j,k,l,e; 482 unsigned char *cp; 483 484 if(!dbg_log) { 485 return; 486 } 487 488 fprintf(dbg_log, "===== START INODE ALLOCATION MAP =====\n"); 489 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment); 490 indent++; 491 492 cp=(unsigned char *)cg_inosused(cgr); 493 e=sb->fs_ipg/8; 494 for(j=0; j<e; j+=32) { 495 fprintf(dbg_log, "%08x: ", j); 496 for(k=0; k<32; k+=8) { 497 if(j+k+8<e) { 498 fprintf(dbg_log, 499 "%02x%02x%02x%02x%02x%02x%02x%02x ", 500 cp[0], cp[1], cp[2], cp[3], 501 cp[4], cp[5], cp[6], cp[7]); 502 } else { 503 for(l=0; (l<8)&&(j+k+l<e); l++) { 504 fprintf(dbg_log, "%02x", cp[l]); 505 } 506 } 507 cp+=8; 508 } 509 fprintf(dbg_log, "\n"); 510 } 511 512 indent--; 513 fprintf(dbg_log, "===== END INODE ALLOCATION MAP =====\n"); 514 515 return; 516 } 517 518 519 /* **************************************************** dbg_dump_frmap ***** */ 520 /* 521 * Dump the fragment allocation map in one cylinder group. 522 */ 523 void 524 dbg_dump_frmap(struct fs *sb, const char *comment, struct cg *cgr) 525 { 526 int j,k,l,e; 527 unsigned char *cp; 528 529 if(!dbg_log) { 530 return; 531 } 532 533 fprintf(dbg_log, "===== START FRAGMENT ALLOCATION MAP =====\n"); 534 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment); 535 indent++; 536 537 cp=(unsigned char *)cg_blksfree(cgr); 538 if (sb->fs_old_nspf) 539 e=howmany((sb->fs_old_cpg * sb->fs_old_spc / sb->fs_old_nspf), CHAR_BIT); 540 else 541 e = 0; 542 for(j=0; j<e; j+=32) { 543 fprintf(dbg_log, "%08x: ", j); 544 for(k=0; k<32; k+=8) { 545 if(j+k+8<e) { 546 fprintf(dbg_log, 547 "%02x%02x%02x%02x%02x%02x%02x%02x ", 548 cp[0], cp[1], cp[2], cp[3], 549 cp[4], cp[5], cp[6], cp[7]); 550 } else { 551 for(l=0; (l<8)&&(j+k+l<e); l++) { 552 fprintf(dbg_log, "%02x", cp[l]); 553 } 554 } 555 cp+=8; 556 } 557 fprintf(dbg_log, "\n"); 558 } 559 560 indent--; 561 fprintf(dbg_log, "===== END FRAGMENT ALLOCATION MAP =====\n"); 562 563 return; 564 } 565 566 /* **************************************************** dbg_dump_clmap ***** */ 567 /* 568 * Dump the cluster allocation map in one cylinder group. 569 */ 570 void 571 dbg_dump_clmap(struct fs *sb, const char *comment, struct cg *cgr) 572 { 573 int j,k,l,e; 574 unsigned char *cp; 575 576 if(!dbg_log) { 577 return; 578 } 579 580 fprintf(dbg_log, "===== START CLUSTER ALLOCATION MAP =====\n"); 581 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment); 582 indent++; 583 584 cp=(unsigned char *)cg_clustersfree(cgr); 585 if (sb->fs_old_nspf) 586 e=howmany(sb->fs_old_cpg * sb->fs_old_spc / (sb->fs_old_nspf << sb->fs_fragshift), CHAR_BIT); 587 else 588 e = 0; 589 for(j=0; j<e; j+=32) { 590 fprintf(dbg_log, "%08x: ", j); 591 for(k=0; k<32; k+=8) { 592 if(j+k+8<e) { 593 fprintf(dbg_log, 594 "%02x%02x%02x%02x%02x%02x%02x%02x ", 595 cp[0], cp[1], cp[2], cp[3], 596 cp[4], cp[5], cp[6], cp[7]); 597 } else { 598 for(l=0; (l<8)&&(j+k+l<e); l++) { 599 fprintf(dbg_log, "%02x", cp[l]); 600 } 601 } 602 cp+=8; 603 } 604 fprintf(dbg_log, "\n"); 605 } 606 607 indent--; 608 fprintf(dbg_log, "===== END CLUSTER ALLOCATION MAP =====\n"); 609 610 return; 611 } 612 613 /* **************************************************** dbg_dump_clsum ***** */ 614 /* 615 * Dump the cluster availability summary of one cylinder group. 616 */ 617 void 618 dbg_dump_clsum(struct fs *sb, const char *comment, struct cg *cgr) 619 { 620 int j; 621 int *ip; 622 623 if(!dbg_log) { 624 return; 625 } 626 627 fprintf(dbg_log, "===== START CLUSTER SUMMARY =====\n"); 628 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment); 629 indent++; 630 631 ip=(int *)cg_clustersum(cgr); 632 for(j=0; j<=sb->fs_contigsumsize; j++) { 633 fprintf(dbg_log, "%02d: %8d\n", j, *ip++); 634 } 635 636 indent--; 637 fprintf(dbg_log, "===== END CLUSTER SUMMARY =====\n"); 638 639 return; 640 } 641 642 #ifdef NOT_CURRENTLY 643 /* 644 * This code dates from before the UFS2 integration, and doesn't compile 645 * post-UFS2 due to the use of cg_blks(). I'm not sure how best to update 646 * this for UFS2, where the rotational bits of UFS no longer apply, so 647 * will leave it disabled for now; it should probably be re-enabled 648 * specifically for UFS1. 649 */ 650 /* **************************************************** dbg_dump_sptbl ***** */ 651 /* 652 * Dump the block summary, and the rotational layout table. 653 */ 654 void 655 dbg_dump_sptbl(struct fs *sb, const char *comment, struct cg *cgr) 656 { 657 int j,k; 658 int *ip; 659 660 if(!dbg_log) { 661 return; 662 } 663 664 fprintf(dbg_log, 665 "===== START BLOCK SUMMARY AND POSITION TABLE =====\n"); 666 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)cgr, comment); 667 indent++; 668 669 ip=(int *)cg_blktot(cgr); 670 for(j=0; j<sb->fs_old_cpg; j++) { 671 fprintf(dbg_log, "%2d: %5d = ", j, *ip++); 672 for(k=0; k<sb->fs_old_nrpos; k++) { 673 fprintf(dbg_log, "%4d", cg_blks(sb, cgr, j)[k]); 674 if(k<sb->fs_old_nrpos-1) { 675 fprintf(dbg_log, " + "); 676 } 677 } 678 fprintf(dbg_log, "\n"); 679 } 680 681 indent--; 682 fprintf(dbg_log, "===== END BLOCK SUMMARY AND POSITION TABLE =====\n"); 683 684 return; 685 } 686 #endif 687 688 /* ************************************************** dbg_dump_ufs1_ino ***** */ 689 /* 690 * Dump a UFS1 inode structure. 691 */ 692 void 693 dbg_dump_ufs1_ino(struct fs *sb, const char *comment, struct ufs1_dinode *ino) 694 { 695 int ictr; 696 int remaining_blocks; 697 698 if(!dbg_log) { 699 return; 700 } 701 702 fprintf(dbg_log, "===== START UFS1 INODE DUMP =====\n"); 703 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)ino, comment); 704 indent++; 705 706 fprintf(dbg_log, "mode u_int16_t 0%o\n", ino->di_mode); 707 fprintf(dbg_log, "nlink int16_t 0x%04x\n", ino->di_nlink); 708 fprintf(dbg_log, "size u_int64_t 0x%08x%08x\n", 709 ((unsigned int *)&(ino->di_size))[1], 710 ((unsigned int *)&(ino->di_size))[0]); 711 fprintf(dbg_log, "atime int32_t 0x%08x\n", ino->di_atime); 712 fprintf(dbg_log, "atimensec int32_t 0x%08x\n", 713 ino->di_atimensec); 714 fprintf(dbg_log, "mtime int32_t 0x%08x\n", 715 ino->di_mtime); 716 fprintf(dbg_log, "mtimensec int32_t 0x%08x\n", 717 ino->di_mtimensec); 718 fprintf(dbg_log, "ctime int32_t 0x%08x\n", ino->di_ctime); 719 fprintf(dbg_log, "ctimensec int32_t 0x%08x\n", 720 ino->di_ctimensec); 721 722 remaining_blocks=howmany(ino->di_size, sb->fs_bsize); /* XXX ts - +1? */ 723 for(ictr=0; ictr < MIN(NDADDR, remaining_blocks); ictr++) { 724 fprintf(dbg_log, "db ufs_daddr_t[%x] 0x%08x\n", ictr, 725 ino->di_db[ictr]); 726 } 727 remaining_blocks-=NDADDR; 728 if(remaining_blocks>0) { 729 fprintf(dbg_log, "ib ufs_daddr_t[0] 0x%08x\n", 730 ino->di_ib[0]); 731 } 732 remaining_blocks-=howmany(sb->fs_bsize, sizeof(ufs1_daddr_t)); 733 if(remaining_blocks>0) { 734 fprintf(dbg_log, "ib ufs_daddr_t[1] 0x%08x\n", 735 ino->di_ib[1]); 736 } 737 #define SQUARE(a) ((a)*(a)) 738 remaining_blocks-=SQUARE(howmany(sb->fs_bsize, sizeof(ufs1_daddr_t))); 739 #undef SQUARE 740 if(remaining_blocks>0) { 741 fprintf(dbg_log, "ib ufs_daddr_t[2] 0x%08x\n", 742 ino->di_ib[2]); 743 } 744 745 fprintf(dbg_log, "flags u_int32_t 0x%08x\n", ino->di_flags); 746 fprintf(dbg_log, "blocks int32_t 0x%08x\n", ino->di_blocks); 747 fprintf(dbg_log, "gen int32_t 0x%08x\n", ino->di_gen); 748 fprintf(dbg_log, "uid u_int32_t 0x%08x\n", ino->di_uid); 749 fprintf(dbg_log, "gid u_int32_t 0x%08x\n", ino->di_gid); 750 751 indent--; 752 fprintf(dbg_log, "===== END UFS1 INODE DUMP =====\n"); 753 754 return; 755 } 756 757 /* ************************************************** dbg_dump_ufs2_ino ***** */ 758 /* 759 * Dump a UFS2 inode structure. 760 */ 761 void 762 dbg_dump_ufs2_ino(struct fs *sb, const char *comment, struct ufs2_dinode *ino) 763 { 764 int ictr; 765 int remaining_blocks; 766 767 if(!dbg_log) { 768 return; 769 } 770 771 fprintf(dbg_log, "===== START UFS2 INODE DUMP =====\n"); 772 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)ino, comment); 773 indent++; 774 775 fprintf(dbg_log, "mode u_int16_t 0%o\n", ino->di_mode); 776 fprintf(dbg_log, "nlink int16_t 0x%04x\n", ino->di_nlink); 777 fprintf(dbg_log, "uid u_int32_t 0x%08x\n", ino->di_uid); 778 fprintf(dbg_log, "gid u_int32_t 0x%08x\n", ino->di_gid); 779 fprintf(dbg_log, "blksize u_int32_t 0x%08x\n", ino->di_blksize); 780 fprintf(dbg_log, "size u_int64_t 0x%08x%08x\n", 781 ((unsigned int *)&(ino->di_size))[1], 782 ((unsigned int *)&(ino->di_size))[0]); 783 fprintf(dbg_log, "blocks u_int64_t 0x%08x%08x\n", 784 ((unsigned int *)&(ino->di_blocks))[1], 785 ((unsigned int *)&(ino->di_blocks))[0]); 786 fprintf(dbg_log, "atime ufs_time_t %10u\n", ino->di_atime); 787 fprintf(dbg_log, "mtime ufs_time_t %10u\n", ino->di_mtime); 788 fprintf(dbg_log, "ctime ufs_time_t %10u\n", ino->di_ctime); 789 fprintf(dbg_log, "birthtime ufs_time_t %10u\n", ino->di_birthtime); 790 fprintf(dbg_log, "mtimensec int32_t 0x%08x\n", ino->di_mtimensec); 791 fprintf(dbg_log, "atimensec int32_t 0x%08x\n", ino->di_atimensec); 792 fprintf(dbg_log, "ctimensec int32_t 0x%08x\n", ino->di_ctimensec); 793 fprintf(dbg_log, "birthnsec int32_t 0x%08x\n", ino->di_birthnsec); 794 fprintf(dbg_log, "gen int32_t 0x%08x\n", ino->di_gen); 795 fprintf(dbg_log, "kernflags u_int32_t 0x%08x\n", ino->di_kernflags); 796 fprintf(dbg_log, "flags u_int32_t 0x%08x\n", ino->di_flags); 797 fprintf(dbg_log, "extsize int32_t 0x%08x\n", ino->di_extsize); 798 799 /* XXX: What do we do with di_extb[NXADDR]? */ 800 801 remaining_blocks=howmany(ino->di_size, sb->fs_bsize); /* XXX ts - +1? */ 802 for(ictr=0; ictr < MIN(NDADDR, remaining_blocks); ictr++) { 803 fprintf(dbg_log, "db ufs2_daddr_t[%x] 0x%16x\n", ictr, 804 ino->di_db[ictr]); 805 } 806 remaining_blocks-=NDADDR; 807 if(remaining_blocks>0) { 808 fprintf(dbg_log, "ib ufs2_daddr_t[0] 0x%16x\n", 809 ino->di_ib[0]); 810 } 811 remaining_blocks-=howmany(sb->fs_bsize, sizeof(ufs2_daddr_t)); 812 if(remaining_blocks>0) { 813 fprintf(dbg_log, "ib ufs2_daddr_t[1] 0x%16x\n", 814 ino->di_ib[1]); 815 } 816 #define SQUARE(a) ((a)*(a)) 817 remaining_blocks-=SQUARE(howmany(sb->fs_bsize, sizeof(ufs2_daddr_t))); 818 #undef SQUARE 819 if(remaining_blocks>0) { 820 fprintf(dbg_log, "ib ufs2_daddr_t[2] 0x%16x\n", 821 ino->di_ib[2]); 822 } 823 824 indent--; 825 fprintf(dbg_log, "===== END UFS2 INODE DUMP =====\n"); 826 827 return; 828 } 829 830 /* ***************************************************** dbg_dump_iblk ***** */ 831 /* 832 * Dump an indirect block. The iteration to dump a full file has to be 833 * written around. 834 */ 835 void 836 dbg_dump_iblk(struct fs *sb, const char *comment, char *block, size_t length) 837 { 838 unsigned int *mem; 839 int i, j, size; 840 841 if(!dbg_log) { 842 return; 843 } 844 845 fprintf(dbg_log, "===== START INDIRECT BLOCK DUMP =====\n"); 846 fprintf(dbg_log, "# %d@%lx: %s\n", indent, (unsigned long)block, 847 comment); 848 indent++; 849 850 if (sb->fs_magic == FS_UFS1_MAGIC) 851 size = sizeof(ufs1_daddr_t); 852 else 853 size = sizeof(ufs2_daddr_t); 854 855 mem=(unsigned int *)block; 856 for (i=0; (size_t)i<MIN(howmany(sb->fs_bsize, size), 857 length); i+=8) { 858 fprintf(dbg_log, "%04x: ", i); 859 for (j=0; j<8; j++) { 860 if((size_t)(i+j)<length) { 861 fprintf(dbg_log, "%08X ", *mem++); 862 } 863 } 864 fprintf(dbg_log, "\n"); 865 } 866 867 indent--; 868 fprintf(dbg_log, "===== END INDIRECT BLOCK DUMP =====\n"); 869 870 return; 871 } 872 873 #endif /* FS_DEBUG */ 874 875