2000-12-09 15:27:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2000 Christoph Herrmann, Thomas-Henning von Kamptz
|
|
|
|
* Copyright (c) 1980, 1989, 1993 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Christoph Herrmann and Thomas-Henning von Kamptz, Munich and Frankfurt.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgment:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors, as well as Christoph
|
|
|
|
* Herrmann and Thomas-Henning von Kamptz.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
2000-12-12 20:03:17 +00:00
|
|
|
* $TSHeader: src/sbin/ffsinfo/ffsinfo.c,v 1.4 2000/12/12 19:30:55 tomsoft Exp $
|
2000-12-09 15:27:35 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
static const char copyright[] =
|
|
|
|
"@(#) Copyright (c) 2000 Christoph Herrmann, Thomas-Henning von Kamptz\n\
|
|
|
|
Copyright (c) 1980, 1989, 1993 The Regents of the University of California.\n\
|
|
|
|
All rights reserved.\n";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
static const char rcsid[] =
|
|
|
|
"$FreeBSD$";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
/* ********************************************************** INCLUDES ***** */
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/disklabel.h>
|
2003-08-14 18:55:31 +00:00
|
|
|
#include <sys/mount.h>
|
2000-12-09 15:27:35 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2003-08-14 18:55:31 +00:00
|
|
|
#include <ufs/ufs/ufsmount.h>
|
|
|
|
#include <ufs/ufs/dinode.h>
|
|
|
|
#include <ufs/ffs/fs.h>
|
|
|
|
|
2000-12-09 15:27:35 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <fcntl.h>
|
2003-08-14 18:55:31 +00:00
|
|
|
#include <libufs.h>
|
|
|
|
#include <paths.h>
|
|
|
|
#include <stdio.h>
|
2000-12-09 15:27:35 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
/* *********************************************************** GLOBALS ***** */
|
|
|
|
#ifdef FS_DEBUG
|
|
|
|
int _dbg_lvl_ = (DL_INFO); /* DL_TRC */
|
|
|
|
#endif /* FS_DEBUG */
|
|
|
|
|
2003-08-14 18:55:31 +00:00
|
|
|
struct uufsd disk;
|
|
|
|
|
|
|
|
#define sblock disk.d_fs
|
|
|
|
#define acg disk.d_cg
|
2000-12-09 15:27:35 +00:00
|
|
|
|
|
|
|
static union {
|
2003-08-14 18:55:31 +00:00
|
|
|
struct fs fs;
|
|
|
|
char pad[SBLOCKSIZE];
|
|
|
|
} fsun;
|
|
|
|
|
|
|
|
#define osblock fsun.fs
|
2000-12-09 15:27:35 +00:00
|
|
|
|
|
|
|
static char i1blk[MAXBSIZE];
|
|
|
|
static char i2blk[MAXBSIZE];
|
|
|
|
static char i3blk[MAXBSIZE];
|
|
|
|
|
|
|
|
static struct csum *fscs;
|
|
|
|
|
|
|
|
/* ******************************************************** PROTOTYPES ***** */
|
2000-12-12 20:03:17 +00:00
|
|
|
static void usage(void);
|
2003-08-14 18:55:31 +00:00
|
|
|
static void dump_whole_ufs1_inode(ino_t, int);
|
|
|
|
static void dump_whole_ufs2_inode(ino_t, int);
|
2000-12-09 15:27:35 +00:00
|
|
|
|
2003-08-14 18:55:31 +00:00
|
|
|
#define DUMP_WHOLE_INODE(A,B) \
|
|
|
|
( disk.d_ufs == 1 \
|
|
|
|
? dump_whole_ufs1_inode((A),(B)) : dump_whole_ufs2_inode((A),(B)) )
|
2000-12-09 15:27:35 +00:00
|
|
|
|
|
|
|
/* ************************************************************** main ***** */
|
|
|
|
/*
|
2002-08-21 18:11:48 +00:00
|
|
|
* ffsinfo(8) is a tool to dump all metadata of a file system. It helps to find
|
|
|
|
* errors is the file system much easier. You can run ffsinfo before and after
|
2000-12-09 15:27:35 +00:00
|
|
|
* an fsck(8), and compare the two ascii dumps easy with diff, and you see
|
|
|
|
* directly where the problem is. You can control how much detail you want to
|
|
|
|
* see with some command line arguments. You can also easy check the status
|
2002-08-21 18:11:48 +00:00
|
|
|
* of a file system, like is there is enough space for growing a file system,
|
2000-12-09 15:27:35 +00:00
|
|
|
* or how many active snapshots do we have. It provides much more detailed
|
|
|
|
* information then dumpfs. Snapshots, as they are very new, are not really
|
|
|
|
* supported. They are just mentioned currently, but it is planned to run
|
|
|
|
* also over active snapshots, to even get that output.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
DBG_FUNC("main")
|
2003-08-14 18:55:31 +00:00
|
|
|
char *device, *special;
|
2004-07-26 15:04:57 +00:00
|
|
|
int ch;
|
2000-12-09 15:27:35 +00:00
|
|
|
size_t len;
|
|
|
|
struct stat st;
|
|
|
|
struct csum *dbg_csp;
|
|
|
|
int dbg_csc;
|
|
|
|
char dbg_line[80];
|
|
|
|
int cylno,i;
|
|
|
|
int cfg_cg, cfg_in, cfg_lv;
|
|
|
|
int cg_start, cg_stop;
|
|
|
|
ino_t in;
|
|
|
|
char *out_file;
|
|
|
|
|
|
|
|
DBG_ENTER;
|
|
|
|
|
|
|
|
cfg_lv=0xff;
|
|
|
|
cfg_in=-2;
|
|
|
|
cfg_cg=-2;
|
|
|
|
out_file=strdup("/var/tmp/ffsinfo");
|
2000-12-12 20:03:17 +00:00
|
|
|
if(out_file == NULL) {
|
|
|
|
errx(1, "strdup failed");
|
|
|
|
}
|
|
|
|
|
2003-08-14 18:55:31 +00:00
|
|
|
while ((ch=getopt(argc, argv, "g:i:l:o:")) != -1) {
|
2000-12-09 15:27:35 +00:00
|
|
|
switch(ch) {
|
|
|
|
case 'g':
|
|
|
|
cfg_cg=atol(optarg);
|
|
|
|
if(cfg_cg < -1) {
|
2000-12-12 20:03:17 +00:00
|
|
|
usage();
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
cfg_in=atol(optarg);
|
|
|
|
if(cfg_in < 0) {
|
2000-12-12 20:03:17 +00:00
|
|
|
usage();
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
cfg_lv=atol(optarg);
|
|
|
|
if(cfg_lv < 0x1||cfg_lv > 0x3ff) {
|
2000-12-12 20:03:17 +00:00
|
|
|
usage();
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
free(out_file);
|
|
|
|
out_file=strdup(optarg);
|
2000-12-12 20:03:17 +00:00
|
|
|
if(out_file == NULL) {
|
|
|
|
errx(1, "strdup failed");
|
|
|
|
}
|
2000-12-09 15:27:35 +00:00
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
default:
|
2000-12-12 20:03:17 +00:00
|
|
|
usage();
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if(argc != 1) {
|
2000-12-12 20:03:17 +00:00
|
|
|
usage();
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
device=*argv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now we try to guess the (raw)device name.
|
|
|
|
*/
|
|
|
|
if (0 == strrchr(device, '/') && (stat(device, &st) == -1)) {
|
|
|
|
/*
|
|
|
|
* No path prefix was given, so try in that order:
|
|
|
|
* /dev/r%s
|
|
|
|
* /dev/%s
|
|
|
|
* /dev/vinum/r%s
|
|
|
|
* /dev/vinum/%s.
|
|
|
|
*
|
|
|
|
* FreeBSD now doesn't distinguish between raw and block
|
|
|
|
* devices any longer, but it should still work this way.
|
|
|
|
*/
|
|
|
|
len=strlen(device)+strlen(_PATH_DEV)+2+strlen("vinum/");
|
|
|
|
special=(char *)malloc(len);
|
2000-12-12 20:03:17 +00:00
|
|
|
if(special == NULL) {
|
|
|
|
errx(1, "malloc failed");
|
|
|
|
}
|
2000-12-09 15:27:35 +00:00
|
|
|
snprintf(special, len, "%sr%s", _PATH_DEV, device);
|
|
|
|
if (stat(special, &st) == -1) {
|
|
|
|
snprintf(special, len, "%s%s", _PATH_DEV, device);
|
|
|
|
if (stat(special, &st) == -1) {
|
|
|
|
snprintf(special, len, "%svinum/r%s",
|
|
|
|
_PATH_DEV, device);
|
|
|
|
if (stat(special, &st) == -1) {
|
|
|
|
/*
|
|
|
|
* For now this is the 'last resort'.
|
|
|
|
*/
|
|
|
|
snprintf(special, len, "%svinum/%s",
|
|
|
|
_PATH_DEV, device);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
device = special;
|
|
|
|
}
|
|
|
|
|
2003-08-14 18:55:31 +00:00
|
|
|
if (ufs_disk_fillout(&disk, device) == -1)
|
|
|
|
err(1, "ufs_disk_fillout(%s) failed: %s", device, disk.d_error);
|
2000-12-09 15:27:35 +00:00
|
|
|
|
|
|
|
DBG_OPEN(out_file); /* already here we need a superblock */
|
|
|
|
|
|
|
|
if(cfg_lv & 0x001) {
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_FS(&sblock,
|
|
|
|
"primary sblock");
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine here what cylinder groups to dump.
|
|
|
|
*/
|
|
|
|
if(cfg_cg==-2) {
|
|
|
|
cg_start=0;
|
|
|
|
cg_stop=sblock.fs_ncg;
|
|
|
|
} else if (cfg_cg==-1) {
|
|
|
|
cg_start=sblock.fs_ncg-1;
|
|
|
|
cg_stop=sblock.fs_ncg;
|
|
|
|
} else if (cfg_cg<sblock.fs_ncg) {
|
|
|
|
cg_start=cfg_cg;
|
|
|
|
cg_stop=cfg_cg+1;
|
|
|
|
} else {
|
|
|
|
cg_start=sblock.fs_ncg;
|
|
|
|
cg_stop=sblock.fs_ncg;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg_lv & 0x004) {
|
2001-06-07 20:43:00 +00:00
|
|
|
fscs = (struct csum *)calloc((size_t)1,
|
|
|
|
(size_t)sblock.fs_cssize);
|
2000-12-12 20:03:17 +00:00
|
|
|
if(fscs == NULL) {
|
|
|
|
errx(1, "calloc failed");
|
|
|
|
}
|
2000-12-09 15:27:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the cylinder summary into the memory ...
|
|
|
|
*/
|
|
|
|
for (i = 0; i < sblock.fs_cssize; i += sblock.fs_bsize) {
|
2003-08-14 18:55:31 +00:00
|
|
|
if (bread(&disk,
|
|
|
|
fsbtodb(&sblock, sblock.fs_csaddr + numfrags(&sblock, i)),
|
|
|
|
(void *)(((char *)fscs)+i),
|
|
|
|
(size_t)(sblock.fs_cssize-i < sblock.fs_bsize
|
|
|
|
? sblock.fs_cssize - i
|
|
|
|
: sblock.fs_bsize)) == -1) {
|
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dbg_csp=fscs;
|
|
|
|
/*
|
|
|
|
* ... and dump it.
|
|
|
|
*/
|
|
|
|
for(dbg_csc=0; dbg_csc<sblock.fs_ncg; dbg_csc++) {
|
2001-06-07 20:43:00 +00:00
|
|
|
snprintf(dbg_line, sizeof(dbg_line),
|
|
|
|
"%d. csum in fscs", dbg_csc);
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_CSUM(&sblock,
|
|
|
|
dbg_line,
|
|
|
|
dbg_csp++);
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For each requested cylinder group ...
|
|
|
|
*/
|
|
|
|
for(cylno=cg_start; cylno<cg_stop; cylno++) {
|
2001-06-07 20:43:00 +00:00
|
|
|
snprintf(dbg_line, sizeof(dbg_line), "cgr %d", cylno);
|
2000-12-09 15:27:35 +00:00
|
|
|
if(cfg_lv & 0x002) {
|
|
|
|
/*
|
|
|
|
* ... dump the superblock copies ...
|
|
|
|
*/
|
2003-08-14 18:55:31 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, cgsblock(&sblock, cylno)),
|
|
|
|
(void *)&osblock, SBLOCKSIZE) == -1) {
|
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_FS(&osblock,
|
|
|
|
dbg_line);
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* ... read the cylinder group and dump whatever was requested.
|
|
|
|
*/
|
2003-08-14 18:55:31 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, cgtod(&sblock, cylno)),
|
|
|
|
(void *)&acg, (size_t)sblock.fs_cgsize) == -1) {
|
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
2000-12-09 15:27:35 +00:00
|
|
|
if(cfg_lv & 0x008) {
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_CG(&sblock,
|
|
|
|
dbg_line,
|
|
|
|
&acg);
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
if(cfg_lv & 0x010) {
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_INMAP(&sblock,
|
|
|
|
dbg_line,
|
|
|
|
&acg);
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
if(cfg_lv & 0x020) {
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_FRMAP(&sblock,
|
|
|
|
dbg_line,
|
|
|
|
&acg);
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
if(cfg_lv & 0x040) {
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_CLMAP(&sblock,
|
|
|
|
dbg_line,
|
|
|
|
&acg);
|
|
|
|
DBG_DUMP_CLSUM(&sblock,
|
|
|
|
dbg_line,
|
|
|
|
&acg);
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
2003-08-14 18:55:31 +00:00
|
|
|
#ifdef NOT_CURRENTLY
|
|
|
|
/*
|
|
|
|
* See the comment in sbin/growfs/debug.c for why this
|
|
|
|
* is currently disabled, and what needs to be done to
|
|
|
|
* re-enable it.
|
|
|
|
*/
|
|
|
|
if(disk.d_ufs == 1 && cfg_lv & 0x080) {
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_SPTBL(&sblock,
|
|
|
|
dbg_line,
|
|
|
|
&acg);
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
2003-08-14 18:55:31 +00:00
|
|
|
#endif
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Dump the requested inode(s).
|
|
|
|
*/
|
|
|
|
if(cfg_in != -2) {
|
2003-08-14 18:55:31 +00:00
|
|
|
DUMP_WHOLE_INODE((ino_t)cfg_in, cfg_lv);
|
2000-12-09 15:27:35 +00:00
|
|
|
} else {
|
2003-08-14 18:55:31 +00:00
|
|
|
for(in=cg_start*sblock.fs_ipg; in<(ino_t)cg_stop*sblock.fs_ipg;
|
2000-12-09 15:27:35 +00:00
|
|
|
in++) {
|
2003-08-14 18:55:31 +00:00
|
|
|
DUMP_WHOLE_INODE(in, cfg_lv);
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DBG_CLOSE;
|
|
|
|
|
|
|
|
DBG_LEAVE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-08-14 18:55:31 +00:00
|
|
|
/* ********************************************** dump_whole_ufs1_inode ***** */
|
2000-12-09 15:27:35 +00:00
|
|
|
/*
|
|
|
|
* Here we dump a list of all blocks allocated by this inode. We follow
|
|
|
|
* all indirect blocks.
|
|
|
|
*/
|
|
|
|
void
|
2003-08-14 18:55:31 +00:00
|
|
|
dump_whole_ufs1_inode(ino_t inode, int level)
|
2000-12-09 15:27:35 +00:00
|
|
|
{
|
2003-08-14 18:55:31 +00:00
|
|
|
DBG_FUNC("dump_whole_ufs1_inode")
|
|
|
|
struct ufs1_dinode *ino;
|
|
|
|
int rb, mode;
|
2000-12-09 15:27:35 +00:00
|
|
|
unsigned int ind2ctr, ind3ctr;
|
2003-08-14 18:55:31 +00:00
|
|
|
ufs1_daddr_t *ind2ptr, *ind3ptr;
|
2000-12-09 15:27:35 +00:00
|
|
|
char comment[80];
|
|
|
|
|
|
|
|
DBG_ENTER;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the inode from disk/cache.
|
|
|
|
*/
|
2003-08-14 18:55:31 +00:00
|
|
|
if (getino(&disk, (void **)&ino, inode, &mode) == -1)
|
|
|
|
err(1, "getino: %s", disk.d_error);
|
2000-12-09 15:27:35 +00:00
|
|
|
|
|
|
|
if(ino->di_nlink==0) {
|
|
|
|
DBG_LEAVE;
|
|
|
|
return; /* inode not in use */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dump the main inode structure.
|
|
|
|
*/
|
2001-06-07 20:43:00 +00:00
|
|
|
snprintf(comment, sizeof(comment), "Inode 0x%08x", inode);
|
2000-12-09 15:27:35 +00:00
|
|
|
if (level & 0x100) {
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_INO(&sblock,
|
|
|
|
comment,
|
|
|
|
ino);
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(level & 0x200)) {
|
|
|
|
DBG_LEAVE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ok, now prepare for dumping all direct and indirect pointers.
|
|
|
|
*/
|
|
|
|
rb=howmany(ino->di_size, sblock.fs_bsize)-NDADDR;
|
|
|
|
if(rb>0) {
|
|
|
|
/*
|
|
|
|
* Dump single indirect block.
|
|
|
|
*/
|
2003-08-14 18:55:31 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, ino->di_ib[0]), (void *)&i1blk,
|
|
|
|
(size_t)sblock.fs_bsize) == -1) {
|
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
2001-06-07 20:43:00 +00:00
|
|
|
snprintf(comment, sizeof(comment), "Inode 0x%08x: indirect 0",
|
|
|
|
inode);
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_IBLK(&sblock,
|
|
|
|
comment,
|
|
|
|
i1blk,
|
|
|
|
(size_t)rb);
|
2003-08-14 18:55:31 +00:00
|
|
|
rb-=howmany(sblock.fs_bsize, sizeof(ufs1_daddr_t));
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
if(rb>0) {
|
|
|
|
/*
|
|
|
|
* Dump double indirect blocks.
|
|
|
|
*/
|
2003-08-14 18:55:31 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, ino->di_ib[1]), (void *)&i2blk,
|
|
|
|
(size_t)sblock.fs_bsize) == -1) {
|
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
2001-06-07 20:43:00 +00:00
|
|
|
snprintf(comment, sizeof(comment), "Inode 0x%08x: indirect 1",
|
|
|
|
inode);
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_IBLK(&sblock,
|
|
|
|
comment,
|
|
|
|
i2blk,
|
2003-08-14 18:55:31 +00:00
|
|
|
howmany(rb, howmany(sblock.fs_bsize, sizeof(ufs1_daddr_t))));
|
2000-12-09 15:27:35 +00:00
|
|
|
for(ind2ctr=0; ((ind2ctr < howmany(sblock.fs_bsize,
|
2003-08-14 18:55:31 +00:00
|
|
|
sizeof(ufs1_daddr_t))) && (rb>0)); ind2ctr++) {
|
|
|
|
ind2ptr=&((ufs1_daddr_t *)(void *)&i2blk)[ind2ctr];
|
2000-12-09 15:27:35 +00:00
|
|
|
|
2003-08-14 18:55:31 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, *ind2ptr), (void *)&i1blk,
|
|
|
|
(size_t)sblock.fs_bsize) == -1) {
|
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
2001-06-07 20:43:00 +00:00
|
|
|
snprintf(comment, sizeof(comment),
|
|
|
|
"Inode 0x%08x: indirect 1->%d", inode, ind2ctr);
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_IBLK(&sblock,
|
|
|
|
comment,
|
|
|
|
i1blk,
|
|
|
|
(size_t)rb);
|
2003-08-14 18:55:31 +00:00
|
|
|
rb-=howmany(sblock.fs_bsize, sizeof(ufs1_daddr_t));
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(rb>0) {
|
|
|
|
/*
|
|
|
|
* Dump triple indirect blocks.
|
|
|
|
*/
|
2003-08-14 18:55:31 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, ino->di_ib[2]), (void *)&i3blk,
|
|
|
|
(size_t)sblock.fs_bsize) == -1) {
|
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
2001-06-07 20:43:00 +00:00
|
|
|
snprintf(comment, sizeof(comment), "Inode 0x%08x: indirect 2",
|
|
|
|
inode);
|
2000-12-09 15:27:35 +00:00
|
|
|
#define SQUARE(a) ((a)*(a))
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_IBLK(&sblock,
|
|
|
|
comment,
|
|
|
|
i3blk,
|
|
|
|
howmany(rb,
|
2003-08-14 18:55:31 +00:00
|
|
|
SQUARE(howmany(sblock.fs_bsize, sizeof(ufs1_daddr_t)))));
|
2000-12-09 15:27:35 +00:00
|
|
|
#undef SQUARE
|
2003-08-14 18:55:31 +00:00
|
|
|
for(ind3ctr=0; ((ind3ctr<howmany(sblock.fs_bsize,
|
|
|
|
sizeof(ufs1_daddr_t)))&&(rb>0)); ind3ctr++) {
|
|
|
|
ind3ptr=&((ufs1_daddr_t *)(void *)&i3blk)[ind3ctr];
|
2000-12-09 15:27:35 +00:00
|
|
|
|
2003-08-14 18:55:31 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, *ind3ptr), (void *)&i2blk,
|
|
|
|
(size_t)sblock.fs_bsize) == -1) {
|
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
2001-06-07 20:43:00 +00:00
|
|
|
snprintf(comment, sizeof(comment),
|
|
|
|
"Inode 0x%08x: indirect 2->%d", inode, ind3ctr);
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_IBLK(&sblock,
|
|
|
|
comment,
|
|
|
|
i2blk,
|
|
|
|
howmany(rb,
|
2003-08-14 18:55:31 +00:00
|
|
|
howmany(sblock.fs_bsize, sizeof(ufs1_daddr_t))));
|
2000-12-09 15:27:35 +00:00
|
|
|
for(ind2ctr=0; ((ind2ctr < howmany(sblock.fs_bsize,
|
2003-08-14 18:55:31 +00:00
|
|
|
sizeof(ufs1_daddr_t)))&&(rb>0)); ind2ctr++) {
|
|
|
|
ind2ptr=&((ufs1_daddr_t *)(void *)&i2blk)
|
2001-06-07 20:43:00 +00:00
|
|
|
[ind2ctr];
|
2003-08-14 18:55:31 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, *ind2ptr),
|
|
|
|
(void *)&i1blk, (size_t)sblock.fs_bsize)
|
|
|
|
== -1) {
|
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
2001-06-07 20:43:00 +00:00
|
|
|
snprintf(comment, sizeof(comment),
|
2000-12-09 15:27:35 +00:00
|
|
|
"Inode 0x%08x: indirect 2->%d->%d", inode,
|
|
|
|
ind3ctr, ind3ctr);
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_IBLK(&sblock,
|
|
|
|
comment,
|
|
|
|
i1blk,
|
|
|
|
(size_t)rb);
|
2000-12-09 15:27:35 +00:00
|
|
|
rb-=howmany(sblock.fs_bsize,
|
2003-08-14 18:55:31 +00:00
|
|
|
sizeof(ufs1_daddr_t));
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DBG_LEAVE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-08-14 18:55:31 +00:00
|
|
|
/* ********************************************** dump_whole_ufs2_inode ***** */
|
2000-12-09 15:27:35 +00:00
|
|
|
/*
|
2003-08-14 18:55:31 +00:00
|
|
|
* Here we dump a list of all blocks allocated by this inode. We follow
|
|
|
|
* all indirect blocks.
|
2000-12-09 15:27:35 +00:00
|
|
|
*/
|
2003-08-14 18:55:31 +00:00
|
|
|
void
|
|
|
|
dump_whole_ufs2_inode(ino_t inode, int level)
|
2000-12-09 15:27:35 +00:00
|
|
|
{
|
2003-08-14 18:55:31 +00:00
|
|
|
DBG_FUNC("dump_whole_ufs2_inode")
|
|
|
|
struct ufs2_dinode *ino;
|
|
|
|
int rb, mode;
|
|
|
|
unsigned int ind2ctr, ind3ctr;
|
|
|
|
ufs2_daddr_t *ind2ptr, *ind3ptr;
|
|
|
|
char comment[80];
|
|
|
|
|
2000-12-09 15:27:35 +00:00
|
|
|
DBG_ENTER;
|
|
|
|
|
2003-08-14 18:55:31 +00:00
|
|
|
/*
|
|
|
|
* Read the inode from disk/cache.
|
|
|
|
*/
|
|
|
|
if (getino(&disk, (void **)&ino, inode, &mode) == -1)
|
|
|
|
err(1, "getino: %s", disk.d_error);
|
|
|
|
|
|
|
|
if (ino->di_nlink == 0) {
|
|
|
|
DBG_LEAVE;
|
|
|
|
return; /* inode not in use */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dump the main inode structure.
|
|
|
|
*/
|
|
|
|
snprintf(comment, sizeof(comment), "Inode 0x%08x", inode);
|
|
|
|
if (level & 0x100) {
|
|
|
|
DBG_DUMP_INO(&sblock, comment, ino);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(level & 0x200)) {
|
|
|
|
DBG_LEAVE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ok, now prepare for dumping all direct and indirect pointers.
|
|
|
|
*/
|
|
|
|
rb = howmany(ino->di_size, sblock.fs_bsize) - NDADDR;
|
|
|
|
if (rb > 0) {
|
|
|
|
/*
|
|
|
|
* Dump single indirect block.
|
|
|
|
*/
|
|
|
|
if (bread(&disk, fsbtodb(&sblock, ino->di_ib[0]), (void *)&i1blk,
|
|
|
|
(size_t)sblock.fs_bsize) == -1) {
|
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
|
|
|
snprintf(comment, sizeof(comment), "Inode 0x%08x: indirect 0", inode);
|
|
|
|
DBG_DUMP_IBLK(&sblock, comment, i1blk, (size_t)rb);
|
|
|
|
rb -= howmany(sblock.fs_bsize, sizeof(ufs2_daddr_t));
|
|
|
|
}
|
|
|
|
if (rb > 0) {
|
|
|
|
/*
|
|
|
|
* Dump double indirect blocks.
|
|
|
|
*/
|
|
|
|
if (bread(&disk, fsbtodb(&sblock, ino->di_ib[1]), (void *)&i2blk,
|
|
|
|
(size_t)sblock.fs_bsize) == -1) {
|
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
|
|
|
snprintf(comment, sizeof(comment), "Inode 0x%08x: indirect 1", inode);
|
|
|
|
DBG_DUMP_IBLK(&sblock,
|
|
|
|
comment,
|
|
|
|
i2blk,
|
|
|
|
howmany(rb, howmany(sblock.fs_bsize, sizeof(ufs2_daddr_t))));
|
|
|
|
for (ind2ctr = 0; ((ind2ctr < howmany(sblock.fs_bsize,
|
|
|
|
sizeof(ufs2_daddr_t))) && (rb>0)); ind2ctr++) {
|
|
|
|
ind2ptr = &((ufs2_daddr_t *)(void *)&i2blk)[ind2ctr];
|
|
|
|
|
|
|
|
if (bread(&disk, fsbtodb(&sblock, *ind2ptr), (void *)&i1blk,
|
|
|
|
(size_t)sblock.fs_bsize) == -1) {
|
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
|
|
|
snprintf(comment, sizeof(comment),
|
|
|
|
"Inode 0x%08x: indirect 1->%d", inode, ind2ctr);
|
|
|
|
DBG_DUMP_IBLK(&sblock, comment, i1blk, (size_t)rb);
|
|
|
|
rb -= howmany(sblock.fs_bsize, sizeof(ufs2_daddr_t));
|
|
|
|
}
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
2003-08-14 18:55:31 +00:00
|
|
|
if (rb > 0) {
|
|
|
|
/*
|
|
|
|
* Dump triple indirect blocks.
|
|
|
|
*/
|
|
|
|
if (bread(&disk, fsbtodb(&sblock, ino->di_ib[2]), (void *)&i3blk,
|
|
|
|
(size_t)sblock.fs_bsize) == -1) {
|
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
|
|
|
snprintf(comment, sizeof(comment), "Inode 0x%08x: indirect 2", inode);
|
|
|
|
#define SQUARE(a) ((a)*(a))
|
|
|
|
DBG_DUMP_IBLK(&sblock,
|
|
|
|
comment,
|
|
|
|
i3blk,
|
|
|
|
howmany(rb,
|
|
|
|
SQUARE(howmany(sblock.fs_bsize, sizeof(ufs2_daddr_t)))));
|
|
|
|
#undef SQUARE
|
|
|
|
for (ind3ctr = 0; ((ind3ctr < howmany(sblock.fs_bsize,
|
|
|
|
sizeof(ufs2_daddr_t))) && (rb > 0)); ind3ctr++) {
|
|
|
|
ind3ptr = &((ufs2_daddr_t *)(void *)&i3blk)[ind3ctr];
|
|
|
|
|
|
|
|
if (bread(&disk, fsbtodb(&sblock, *ind3ptr), (void *)&i2blk,
|
|
|
|
(size_t)sblock.fs_bsize) == -1) {
|
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
|
|
|
snprintf(comment, sizeof(comment),
|
|
|
|
"Inode 0x%08x: indirect 2->%d", inode, ind3ctr);
|
|
|
|
DBG_DUMP_IBLK(&sblock,
|
|
|
|
comment,
|
|
|
|
i2blk,
|
|
|
|
howmany(rb,
|
|
|
|
howmany(sblock.fs_bsize, sizeof(ufs2_daddr_t))));
|
|
|
|
for (ind2ctr = 0; ((ind2ctr < howmany(sblock.fs_bsize,
|
|
|
|
sizeof(ufs2_daddr_t))) && (rb > 0)); ind2ctr++) {
|
|
|
|
ind2ptr = &((ufs2_daddr_t *)(void *)&i2blk) [ind2ctr];
|
|
|
|
if (bread(&disk, fsbtodb(&sblock, *ind2ptr), (void *)&i1blk,
|
|
|
|
(size_t)sblock.fs_bsize) == -1) {
|
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
|
|
|
snprintf(comment, sizeof(comment),
|
|
|
|
"Inode 0x%08x: indirect 2->%d->%d", inode,
|
|
|
|
ind3ctr, ind3ctr);
|
|
|
|
DBG_DUMP_IBLK(&sblock, comment, i1blk, (size_t)rb);
|
|
|
|
rb -= howmany(sblock.fs_bsize, sizeof(ufs2_daddr_t));
|
|
|
|
}
|
|
|
|
}
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DBG_LEAVE;
|
2003-08-14 18:55:31 +00:00
|
|
|
return;
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ************************************************************* usage ***** */
|
|
|
|
/*
|
|
|
|
* Dump a line of usage.
|
|
|
|
*/
|
|
|
|
void
|
2000-12-12 20:03:17 +00:00
|
|
|
usage(void)
|
2000-12-09 15:27:35 +00:00
|
|
|
{
|
|
|
|
DBG_FUNC("usage")
|
|
|
|
|
|
|
|
DBG_ENTER;
|
|
|
|
|
|
|
|
fprintf(stderr,
|
2000-12-12 20:03:17 +00:00
|
|
|
"usage: ffsinfo [-L] [-g cylgrp] [-i inode] [-l level] "
|
|
|
|
"[-o outfile]\n"
|
|
|
|
" special | file\n");
|
2000-12-09 15:27:35 +00:00
|
|
|
|
|
|
|
DBG_LEAVE;
|
2000-12-12 20:03:17 +00:00
|
|
|
exit(1);
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|