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