Deleted Added
full compact
ffsinfo.c (69926) ffsinfo.c (77885)
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 $
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 69926 2000-12-12 20:03:17Z tomsoft $
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[] =
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 69926 2000-12-12 20:03:17Z tomsoft $";
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 ***** */
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, int, char *, int);
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
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, int size, char *bf, int fsi)
108rdfs(daddr_t bno, size_t size, void *bf, int fsi)
109{
110 DBG_FUNC("rdfs")
109{
110 DBG_FUNC("rdfs")
111 int n;
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 }
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_t)size);
119 if (n != size) {
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 */
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), SBSIZE, (char *)&(sblock), fsi);
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) {
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(1, (size_t)sblock.fs_cssize);
329 fscs = (struct csum *)calloc((size_t)1,
330 (size_t)sblock.fs_cssize);
330 if(fscs == NULL) {
331 errx(1, "calloc failed");
332 }
333
334 /*
335 * Get the cylinder summary into the memory ...
336 */
337 for (i = 0; i < sblock.fs_cssize; i += sblock.fs_bsize) {
338 rdfs(fsbtodb(&sblock, sblock.fs_csaddr +
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 +
339 numfrags(&sblock, i)), sblock.fs_cssize - i <
340 numfrags(&sblock, i)), (size_t)(sblock.fs_cssize-i<
340 sblock.fs_bsize ? sblock.fs_cssize - i :
341 sblock.fs_bsize ? sblock.fs_cssize - i :
341 sblock.fs_bsize, ((char *)fscs) + i, fsi);
342 sblock.fs_bsize), (void *)(((char *)fscs)+i), fsi);
342 }
343
344 dbg_csp=fscs;
345 /*
346 * ... and dump it.
347 */
348 for(dbg_csc=0; dbg_csc<sblock.fs_ncg; dbg_csc++) {
343 }
344
345 dbg_csp=fscs;
346 /*
347 * ... and dump it.
348 */
349 for(dbg_csc=0; dbg_csc<sblock.fs_ncg; dbg_csc++) {
349 snprintf(dbg_line, 80, "%d. csum in fscs",
350 dbg_csc);
350 snprintf(dbg_line, sizeof(dbg_line),
351 "%d. csum in fscs", dbg_csc);
351 DBG_DUMP_CSUM(&sblock,
352 dbg_line,
353 dbg_csp++);
354 }
355 }
356
357 /*
358 * For each requested cylinder group ...
359 */
360 for(cylno=cg_start; cylno<cg_stop; cylno++) {
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++) {
361 snprintf(dbg_line, 80, "cgr %d", cylno);
362 snprintf(dbg_line, sizeof(dbg_line), "cgr %d", cylno);
362 if(cfg_lv & 0x002) {
363 /*
364 * ... dump the superblock copies ...
365 */
366 rdfs(fsbtodb(&sblock, cgsblock(&sblock, cylno)),
363 if(cfg_lv & 0x002) {
364 /*
365 * ... dump the superblock copies ...
366 */
367 rdfs(fsbtodb(&sblock, cgsblock(&sblock, cylno)),
367 SBSIZE, (char *)&osblock, fsi);
368 (size_t)SBSIZE, (void *)&osblock, fsi);
368 DBG_DUMP_FS(&osblock,
369 dbg_line);
370 }
371 /*
372 * ... read the cylinder group and dump whatever was requested.
373 */
369 DBG_DUMP_FS(&osblock,
370 dbg_line);
371 }
372 /*
373 * ... read the cylinder group and dump whatever was requested.
374 */
374 rdfs(fsbtodb(&sblock, cgtod(&sblock, cylno)), sblock.fs_cgsize,
375 (char *)&acg, fsi);
375 rdfs(fsbtodb(&sblock, cgtod(&sblock, cylno)),
376 (size_t)sblock.fs_cgsize, (void *)&acg, fsi);
376 if(cfg_lv & 0x008) {
377 DBG_DUMP_CG(&sblock,
378 dbg_line,
379 &acg);
380 }
381 if(cfg_lv & 0x010) {
382 DBG_DUMP_INMAP(&sblock,
383 dbg_line,

--- 63 unchanged lines hidden (view full) ---

447 if(ino->di_nlink==0) {
448 DBG_LEAVE;
449 return; /* inode not in use */
450 }
451
452 /*
453 * Dump the main inode structure.
454 */
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 */
455 snprintf(comment, 80, "Inode 0x%08x", inode);
456 snprintf(comment, sizeof(comment), "Inode 0x%08x", inode);
456 if (level & 0x100) {
457 DBG_DUMP_INO(&sblock,
458 comment,
459 ino);
460 }
461
462 if (!(level & 0x200)) {
463 DBG_LEAVE;
464 return;
465 }
466
467 /*
468 * Ok, now prepare for dumping all direct and indirect pointers.
469 */
470 rb=howmany(ino->di_size, sblock.fs_bsize)-NDADDR;
471 if(rb>0) {
472 /*
473 * Dump single indirect block.
474 */
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 */
475 rdfs(fsbtodb(&sblock, ino->di_ib[0]), sblock.fs_bsize, i1blk,
476 fsi);
477 snprintf(comment, 80, "Inode 0x%08x: indirect 0", inode);
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);
478 DBG_DUMP_IBLK(&sblock,
479 comment,
480 i1blk,
481 (size_t)rb);
482 rb-=howmany(sblock.fs_bsize, sizeof(ufs_daddr_t));
483 }
484 if(rb>0) {
485 /*
486 * Dump double indirect blocks.
487 */
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 */
488 rdfs(fsbtodb(&sblock, ino->di_ib[1]), sblock.fs_bsize, i2blk,
489 fsi);
490 snprintf(comment, 80, "Inode 0x%08x: indirect 1", inode);
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);
491 DBG_DUMP_IBLK(&sblock,
492 comment,
493 i2blk,
494 howmany(rb, howmany(sblock.fs_bsize, sizeof(ufs_daddr_t))));
495 for(ind2ctr=0; ((ind2ctr < howmany(sblock.fs_bsize,
496 sizeof(ufs_daddr_t)))&&(rb>0)); ind2ctr++) {
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++) {
497 ind2ptr=&((ufs_daddr_t *)&i2blk)[ind2ctr];
500 ind2ptr=&((ufs_daddr_t *)(void *)&i2blk)[ind2ctr];
498
501
499 rdfs(fsbtodb(&sblock, *ind2ptr), sblock.fs_bsize,
500 i1blk, fsi);
501 snprintf(comment, 80, "Inode 0x%08x: indirect 1->%d",
502 inode, ind2ctr);
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);
503 DBG_DUMP_IBLK(&sblock,
504 comment,
505 i1blk,
506 (size_t)rb);
507 rb-=howmany(sblock.fs_bsize, sizeof(ufs_daddr_t));
508 }
509 }
510 if(rb>0) {
511 /*
512 * Dump triple indirect blocks.
513 */
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 */
514 rdfs(fsbtodb(&sblock, ino->di_ib[2]), sblock.fs_bsize, i3blk,
515 fsi);
516 snprintf(comment, 80, "Inode 0x%08x: indirect 2", inode);
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);
517#define SQUARE(a) ((a)*(a))
518 DBG_DUMP_IBLK(&sblock,
519 comment,
520 i3blk,
521 howmany(rb,
522 SQUARE(howmany(sblock.fs_bsize, sizeof(ufs_daddr_t)))));
523#undef SQUARE
524 for(ind3ctr=0; ((ind3ctr < howmany(sblock.fs_bsize,
525 sizeof(ufs_daddr_t)))&&(rb>0)); ind3ctr ++) {
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 ++) {
526 ind3ptr=&((ufs_daddr_t *)&i3blk)[ind3ctr];
530 ind3ptr=&((ufs_daddr_t *)(void *)&i3blk)[ind3ctr];
527
531
528 rdfs(fsbtodb(&sblock, *ind3ptr), sblock.fs_bsize,
529 i2blk, fsi);
530 snprintf(comment, 80, "Inode 0x%08x: indirect 2->%d",
531 inode, ind3ctr);
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);
532 DBG_DUMP_IBLK(&sblock,
533 comment,
534 i2blk,
535 howmany(rb,
536 howmany(sblock.fs_bsize, sizeof(ufs_daddr_t))));
537 for(ind2ctr=0; ((ind2ctr < howmany(sblock.fs_bsize,
538 sizeof(ufs_daddr_t)))&&(rb>0)); ind2ctr ++) {
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 ++) {
539 ind2ptr=&((ufs_daddr_t *)&i2blk)[ind2ctr];
540
543 ind2ptr=&((ufs_daddr_t *)(void *)&i2blk)
544 [ind2ctr];
541 rdfs(fsbtodb(&sblock, *ind2ptr),
545 rdfs(fsbtodb(&sblock, *ind2ptr),
542 sblock.fs_bsize, i1blk, fsi);
543 snprintf(comment, 80,
546 (size_t)sblock.fs_bsize, (void *)&i1blk,
547 fsi);
548 snprintf(comment, sizeof(comment),
544 "Inode 0x%08x: indirect 2->%d->%d", inode,
545 ind3ctr, ind3ctr);
546 DBG_DUMP_IBLK(&sblock,
547 comment,
548 i1blk,
549 (size_t)rb);
550 rb-=howmany(sblock.fs_bsize,
551 sizeof(ufs_daddr_t));

--- 64 unchanged lines hidden (view full) ---

616{
617 DBG_FUNC("ginode")
618 ufs_daddr_t iblk;
619 static ino_t startinum=0; /* first inode in cached block */
620 struct dinode *pi;
621
622 DBG_ENTER;
623
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
624 pi=(struct dinode *)ablk;
629 pi=(struct dinode *)(void *)ablk;
625 if (startinum == 0 || inumber < startinum ||
626 inumber >= startinum + INOPB(&sblock)) {
627 /*
628 * The block needed is not cached, so we have to read it from
629 * disk now.
630 */
631 iblk = ino_to_fsba(&sblock, inumber);
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);
632 rdfs(fsbtodb(&sblock, iblk), sblock.fs_bsize, (char *)&ablk,
633 fsi);
637 rdfs(fsbtodb(&sblock, iblk), (size_t)sblock.fs_bsize,
638 (void *)&ablk, fsi);
634 startinum = (inumber / INOPB(&sblock)) * INOPB(&sblock);
635 }
636
637 DBG_LEAVE;
638 return (&(pi[inumber % INOPB(&sblock)]));
639}
640
639 startinum = (inumber / INOPB(&sblock)) * INOPB(&sblock);
640 }
641
642 DBG_LEAVE;
643 return (&(pi[inumber % INOPB(&sblock)]));
644}
645