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