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 * --- 22 unchanged lines hidden (view full) --- 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/ffsinfo/ffsinfo.c,v 1.4 2000/12/12 19:30:55 tomsoft Exp $ |
39 * $FreeBSD: head/sbin/ffsinfo/ffsinfo.c 77885 2001-06-07 20:43:00Z tomsoft $ |
40 * 41 */ 42 43#ifndef lint 44static const char copyright[] = 45"@(#) Copyright (c) 2000 Christoph Herrmann, Thomas-Henning von Kamptz\n\ 46Copyright (c) 1980, 1989, 1993 The Regents of the University of California.\n\ 47All rights reserved.\n"; 48#endif /* not lint */ 49 50#ifndef lint 51static const char rcsid[] = |
52 "$FreeBSD: head/sbin/ffsinfo/ffsinfo.c 77885 2001-06-07 20:43:00Z tomsoft $"; |
53#endif /* not lint */ 54 55/* ********************************************************** INCLUDES ***** */ 56#include <sys/param.h> 57#include <sys/disklabel.h> 58#include <sys/stat.h> 59 60#include <stdio.h> --- 28 unchanged lines hidden (view full) --- 89static char ablk[MAXBSIZE]; 90static char i1blk[MAXBSIZE]; 91static char i2blk[MAXBSIZE]; 92static char i3blk[MAXBSIZE]; 93 94static struct csum *fscs; 95 96/* ******************************************************** PROTOTYPES ***** */ |
97static void rdfs(daddr_t, size_t, void *, int); |
98static void usage(void); 99static struct disklabel *get_disklabel(int); 100static struct dinode *ginode(ino_t, int); 101static void dump_whole_inode(ino_t, int, int); 102 103/* ************************************************************** rdfs ***** */ 104/* 105 * Here we read some block(s) from disk. 106 */ 107void |
108rdfs(daddr_t bno, size_t size, void *bf, int fsi) |
109{ 110 DBG_FUNC("rdfs") |
111 ssize_t n; |
112 113 DBG_ENTER; 114 115 if (lseek(fsi, (off_t)bno * DEV_BSIZE, 0) < 0) { 116 err(33, "rdfs: seek error: %ld", (long)bno); 117 } |
118 n = read(fsi, bf, size); 119 if (n != (ssize_t)size) { |
120 err(34, "rdfs: read error: %ld", (long)bno); 121 } 122 123 DBG_LEAVE; 124 return; 125} 126 127/* ************************************************************** main ***** */ --- 163 unchanged lines hidden (view full) --- 291 if (pp->p_fstype != FS_BSDFFS) { 292 errx(1, "partition not 4.2BSD"); 293 } 294 } 295 296 /* 297 * Read the current superblock. 298 */ |
299 rdfs((daddr_t)(SBOFF/DEV_BSIZE), (size_t)SBSIZE, (void *)&sblock, fsi); |
300 if (sblock.fs_magic != FS_MAGIC) { 301 errx(1, "superblock not recognized"); 302 } 303 304 DBG_OPEN(out_file); /* already here we need a superblock */ 305 306 if(cfg_lv & 0x001) { 307 DBG_DUMP_FS(&sblock, --- 13 unchanged lines hidden (view full) --- 321 cg_start=cfg_cg; 322 cg_stop=cfg_cg+1; 323 } else { 324 cg_start=sblock.fs_ncg; 325 cg_stop=sblock.fs_ncg; 326 } 327 328 if (cfg_lv & 0x004) { |
329 fscs = (struct csum *)calloc((size_t)1, 330 (size_t)sblock.fs_cssize); |
331 if(fscs == NULL) { 332 errx(1, "calloc failed"); 333 } 334 335 /* 336 * Get the cylinder summary into the memory ... 337 */ 338 for (i = 0; i < sblock.fs_cssize; i += sblock.fs_bsize) { 339 rdfs(fsbtodb(&sblock, sblock.fs_csaddr + |
340 numfrags(&sblock, i)), (size_t)(sblock.fs_cssize-i< |
341 sblock.fs_bsize ? sblock.fs_cssize - i : |
342 sblock.fs_bsize), (void *)(((char *)fscs)+i), fsi); |
343 } 344 345 dbg_csp=fscs; 346 /* 347 * ... and dump it. 348 */ 349 for(dbg_csc=0; dbg_csc<sblock.fs_ncg; dbg_csc++) { |
350 snprintf(dbg_line, sizeof(dbg_line), 351 "%d. csum in fscs", dbg_csc); |
352 DBG_DUMP_CSUM(&sblock, 353 dbg_line, 354 dbg_csp++); 355 } 356 } 357 358 /* 359 * For each requested cylinder group ... 360 */ 361 for(cylno=cg_start; cylno<cg_stop; cylno++) { |
362 snprintf(dbg_line, sizeof(dbg_line), "cgr %d", cylno); |
363 if(cfg_lv & 0x002) { 364 /* 365 * ... dump the superblock copies ... 366 */ 367 rdfs(fsbtodb(&sblock, cgsblock(&sblock, cylno)), |
368 (size_t)SBSIZE, (void *)&osblock, fsi); |
369 DBG_DUMP_FS(&osblock, 370 dbg_line); 371 } 372 /* 373 * ... read the cylinder group and dump whatever was requested. 374 */ |
375 rdfs(fsbtodb(&sblock, cgtod(&sblock, cylno)), 376 (size_t)sblock.fs_cgsize, (void *)&acg, fsi); |
377 if(cfg_lv & 0x008) { 378 DBG_DUMP_CG(&sblock, 379 dbg_line, 380 &acg); 381 } 382 if(cfg_lv & 0x010) { 383 DBG_DUMP_INMAP(&sblock, 384 dbg_line, --- 63 unchanged lines hidden (view full) --- 448 if(ino->di_nlink==0) { 449 DBG_LEAVE; 450 return; /* inode not in use */ 451 } 452 453 /* 454 * Dump the main inode structure. 455 */ |
456 snprintf(comment, sizeof(comment), "Inode 0x%08x", inode); |
457 if (level & 0x100) { 458 DBG_DUMP_INO(&sblock, 459 comment, 460 ino); 461 } 462 463 if (!(level & 0x200)) { 464 DBG_LEAVE; 465 return; 466 } 467 468 /* 469 * Ok, now prepare for dumping all direct and indirect pointers. 470 */ 471 rb=howmany(ino->di_size, sblock.fs_bsize)-NDADDR; 472 if(rb>0) { 473 /* 474 * Dump single indirect block. 475 */ |
476 rdfs(fsbtodb(&sblock, ino->di_ib[0]), (size_t)sblock.fs_bsize, 477 (void *)&i1blk, fsi); 478 snprintf(comment, sizeof(comment), "Inode 0x%08x: indirect 0", 479 inode); |
480 DBG_DUMP_IBLK(&sblock, 481 comment, 482 i1blk, 483 (size_t)rb); 484 rb-=howmany(sblock.fs_bsize, sizeof(ufs_daddr_t)); 485 } 486 if(rb>0) { 487 /* 488 * Dump double indirect blocks. 489 */ |
490 rdfs(fsbtodb(&sblock, ino->di_ib[1]), (size_t)sblock.fs_bsize, 491 (void *)&i2blk, fsi); 492 snprintf(comment, sizeof(comment), "Inode 0x%08x: indirect 1", 493 inode); |
494 DBG_DUMP_IBLK(&sblock, 495 comment, 496 i2blk, 497 howmany(rb, howmany(sblock.fs_bsize, sizeof(ufs_daddr_t)))); 498 for(ind2ctr=0; ((ind2ctr < howmany(sblock.fs_bsize, 499 sizeof(ufs_daddr_t)))&&(rb>0)); ind2ctr++) { |
500 ind2ptr=&((ufs_daddr_t *)(void *)&i2blk)[ind2ctr]; |
501 |
502 rdfs(fsbtodb(&sblock, *ind2ptr), 503 (size_t)sblock.fs_bsize, (void *)&i1blk, fsi); 504 snprintf(comment, sizeof(comment), 505 "Inode 0x%08x: indirect 1->%d", inode, ind2ctr); |
506 DBG_DUMP_IBLK(&sblock, 507 comment, 508 i1blk, 509 (size_t)rb); 510 rb-=howmany(sblock.fs_bsize, sizeof(ufs_daddr_t)); 511 } 512 } 513 if(rb>0) { 514 /* 515 * Dump triple indirect blocks. 516 */ |
517 rdfs(fsbtodb(&sblock, ino->di_ib[2]), (size_t)sblock.fs_bsize, 518 (void *)&i3blk, fsi); 519 snprintf(comment, sizeof(comment), "Inode 0x%08x: indirect 2", 520 inode); |
521#define SQUARE(a) ((a)*(a)) 522 DBG_DUMP_IBLK(&sblock, 523 comment, 524 i3blk, 525 howmany(rb, 526 SQUARE(howmany(sblock.fs_bsize, sizeof(ufs_daddr_t))))); 527#undef SQUARE 528 for(ind3ctr=0; ((ind3ctr < howmany(sblock.fs_bsize, 529 sizeof(ufs_daddr_t)))&&(rb>0)); ind3ctr ++) { |
530 ind3ptr=&((ufs_daddr_t *)(void *)&i3blk)[ind3ctr]; |
531 |
532 rdfs(fsbtodb(&sblock, *ind3ptr), 533 (size_t)sblock.fs_bsize, (void *)&i2blk, fsi); 534 snprintf(comment, sizeof(comment), 535 "Inode 0x%08x: indirect 2->%d", inode, ind3ctr); |
536 DBG_DUMP_IBLK(&sblock, 537 comment, 538 i2blk, 539 howmany(rb, 540 howmany(sblock.fs_bsize, sizeof(ufs_daddr_t)))); 541 for(ind2ctr=0; ((ind2ctr < howmany(sblock.fs_bsize, 542 sizeof(ufs_daddr_t)))&&(rb>0)); ind2ctr ++) { |
543 ind2ptr=&((ufs_daddr_t *)(void *)&i2blk) 544 [ind2ctr]; |
545 rdfs(fsbtodb(&sblock, *ind2ptr), |
546 (size_t)sblock.fs_bsize, (void *)&i1blk, 547 fsi); 548 snprintf(comment, sizeof(comment), |
549 "Inode 0x%08x: indirect 2->%d->%d", inode, 550 ind3ctr, ind3ctr); 551 DBG_DUMP_IBLK(&sblock, 552 comment, 553 i1blk, 554 (size_t)rb); 555 rb-=howmany(sblock.fs_bsize, 556 sizeof(ufs_daddr_t)); --- 64 unchanged lines hidden (view full) --- 621{ 622 DBG_FUNC("ginode") 623 ufs_daddr_t iblk; 624 static ino_t startinum=0; /* first inode in cached block */ 625 struct dinode *pi; 626 627 DBG_ENTER; 628 |
629 pi=(struct dinode *)(void *)ablk; |
630 if (startinum == 0 || inumber < startinum || 631 inumber >= startinum + INOPB(&sblock)) { 632 /* 633 * The block needed is not cached, so we have to read it from 634 * disk now. 635 */ 636 iblk = ino_to_fsba(&sblock, inumber); |
637 rdfs(fsbtodb(&sblock, iblk), (size_t)sblock.fs_bsize, 638 (void *)&ablk, fsi); |
639 startinum = (inumber / INOPB(&sblock)) * INOPB(&sblock); 640 } 641 642 DBG_LEAVE; 643 return (&(pi[inumber % INOPB(&sblock)])); 644} 645 |