2017-11-18 14:26:50 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-4-Clause
|
|
|
|
*
|
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>
|
2005-01-03 18:59:04 +00:00
|
|
|
#include <errno.h>
|
2000-12-09 15:27:35 +00:00
|
|
|
#include <fcntl.h>
|
2003-08-14 18:55:31 +00:00
|
|
|
#include <libufs.h>
|
|
|
|
#include <paths.h>
|
2014-12-17 07:10:48 +00:00
|
|
|
#include <stdint.h>
|
2003-08-14 18:55:31 +00:00
|
|
|
#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 */
|
|
|
|
|
2011-11-04 13:36:02 +00:00
|
|
|
static struct uufsd disk;
|
2003-08-14 18:55:31 +00:00
|
|
|
|
|
|
|
#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;
|
|
|
|
|
2007-02-14 23:12:32 +00:00
|
|
|
cfg_lv = 0xff;
|
|
|
|
cfg_in = -2;
|
|
|
|
cfg_cg = -2;
|
2008-01-29 00:20:00 +00:00
|
|
|
out_file = strdup("-");
|
2000-12-12 20:03:17 +00:00
|
|
|
|
2007-02-14 23:12:32 +00:00
|
|
|
while ((ch = getopt(argc, argv, "g:i:l:o:")) != -1) {
|
|
|
|
switch (ch) {
|
2000-12-09 15:27:35 +00:00
|
|
|
case 'g':
|
2007-02-14 23:12:32 +00:00
|
|
|
cfg_cg = strtol(optarg, NULL, 0);
|
|
|
|
if (errno == EINVAL || errno == ERANGE)
|
2005-01-03 18:59:04 +00:00
|
|
|
err(1, "%s", optarg);
|
2007-02-14 23:12:32 +00:00
|
|
|
if (cfg_cg < -1)
|
2000-12-12 20:03:17 +00:00
|
|
|
usage();
|
2000-12-09 15:27:35 +00:00
|
|
|
break;
|
|
|
|
case 'i':
|
2007-02-14 23:12:32 +00:00
|
|
|
cfg_in = strtol(optarg, NULL, 0);
|
|
|
|
if (errno == EINVAL || errno == ERANGE)
|
2005-01-03 18:59:04 +00:00
|
|
|
err(1, "%s", optarg);
|
2007-02-14 23:12:32 +00:00
|
|
|
if (cfg_in < 0)
|
2000-12-12 20:03:17 +00:00
|
|
|
usage();
|
2000-12-09 15:27:35 +00:00
|
|
|
break;
|
|
|
|
case 'l':
|
2007-02-14 23:12:32 +00:00
|
|
|
cfg_lv = strtol(optarg, NULL, 0);
|
|
|
|
if (errno == EINVAL||errno == ERANGE)
|
2005-01-03 18:59:04 +00:00
|
|
|
err(1, "%s", optarg);
|
2007-02-14 23:12:32 +00:00
|
|
|
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);
|
2007-02-14 23:12:32 +00:00
|
|
|
out_file = strdup(optarg);
|
|
|
|
if (out_file == NULL)
|
2000-12-12 20:03:17 +00:00
|
|
|
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;
|
|
|
|
|
2007-02-14 23:12:32 +00:00
|
|
|
if (argc != 1)
|
2000-12-12 20:03:17 +00:00
|
|
|
usage();
|
2007-02-14 23:12:32 +00:00
|
|
|
device = *argv;
|
2007-02-14 23:20:30 +00:00
|
|
|
|
2000-12-09 15:27:35 +00:00
|
|
|
/*
|
|
|
|
* Now we try to guess the (raw)device name.
|
|
|
|
*/
|
2007-02-14 23:12:32 +00:00
|
|
|
if (0 == strrchr(device, '/') && stat(device, &st) == -1) {
|
|
|
|
/*-
|
|
|
|
* No path prefix was given, so try in this order:
|
2000-12-09 15:27:35 +00:00
|
|
|
* /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.
|
|
|
|
*/
|
2007-02-14 23:12:32 +00:00
|
|
|
len = strlen(device) + strlen(_PATH_DEV) + 2 + strlen("vinum/");
|
|
|
|
special = (char *)malloc(len);
|
|
|
|
if (special == NULL)
|
2000-12-12 20:03:17 +00:00
|
|
|
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);
|
2007-02-14 23:12:32 +00:00
|
|
|
if (stat(special, &st) == -1)
|
|
|
|
/* For now this is the 'last resort' */
|
2000-12-09 15:27:35 +00:00
|
|
|
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
|
|
|
|
2007-02-14 23:12:32 +00:00
|
|
|
DBG_OPEN(out_file); /* already here we need a superblock */
|
|
|
|
|
|
|
|
if (cfg_lv & 0x001)
|
|
|
|
DBG_DUMP_FS(&sblock, "primary sblock");
|
|
|
|
|
|
|
|
/* 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;
|
2000-12-09 15:27:35 +00:00
|
|
|
} else {
|
2007-02-14 23:12:32 +00:00
|
|
|
cg_start = sblock.fs_ncg;
|
|
|
|
cg_stop = sblock.fs_ncg;
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg_lv & 0x004) {
|
2001-06-07 20:43:00 +00:00
|
|
|
fscs = (struct csum *)calloc((size_t)1,
|
|
|
|
(size_t)sblock.fs_cssize);
|
2007-02-14 23:12:32 +00:00
|
|
|
if (fscs == NULL)
|
2000-12-12 20:03:17 +00:00
|
|
|
errx(1, "calloc failed");
|
2000-12-09 15:27:35 +00:00
|
|
|
|
2007-02-14 23:12:32 +00:00
|
|
|
/* get the cylinder summary into the memory ... */
|
2000-12-09 15:27:35 +00:00
|
|
|
for (i = 0; i < sblock.fs_cssize; i += sblock.fs_bsize) {
|
2007-02-14 23:12:32 +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)
|
2003-08-14 18:55:31 +00:00
|
|
|
err(1, "bread: %s", disk.d_error);
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
|
2007-02-14 23:12:32 +00:00
|
|
|
dbg_csp = fscs;
|
|
|
|
/* ... and dump it */
|
2018-11-13 21:40:56 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-14 23:20:30 +00:00
|
|
|
if (cfg_lv & 0xf8) {
|
|
|
|
/* for each requested cylinder group ... */
|
|
|
|
for (cylno = cg_start; cylno < cg_stop; cylno++) {
|
|
|
|
snprintf(dbg_line, sizeof(dbg_line), "cgr %d", cylno);
|
|
|
|
if (cfg_lv & 0x002) {
|
|
|
|
/* dump the superblock copies */
|
|
|
|
if (bread(&disk, fsbtodb(&sblock,
|
|
|
|
cgsblock(&sblock, cylno)),
|
|
|
|
(void *)&osblock, SBLOCKSIZE) == -1)
|
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
DBG_DUMP_FS(&osblock, dbg_line);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the cylinder group and dump whatever was
|
|
|
|
* requested.
|
|
|
|
*/
|
2007-02-14 23:12:32 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock,
|
2007-02-14 23:20:30 +00:00
|
|
|
cgtod(&sblock, cylno)), (void *)&acg,
|
|
|
|
(size_t)sblock.fs_cgsize) == -1)
|
2003-08-14 18:55:31 +00:00
|
|
|
err(1, "bread: %s", disk.d_error);
|
2007-02-14 23:12:32 +00:00
|
|
|
|
2007-02-14 23:20:30 +00:00
|
|
|
if (cfg_lv & 0x008)
|
|
|
|
DBG_DUMP_CG(&sblock, dbg_line, &acg);
|
|
|
|
if (cfg_lv & 0x010)
|
|
|
|
DBG_DUMP_INMAP(&sblock, dbg_line, &acg);
|
|
|
|
if (cfg_lv & 0x020)
|
|
|
|
DBG_DUMP_FRMAP(&sblock, dbg_line, &acg);
|
|
|
|
if (cfg_lv & 0x040) {
|
|
|
|
DBG_DUMP_CLMAP(&sblock, dbg_line, &acg);
|
|
|
|
DBG_DUMP_CLSUM(&sblock, dbg_line, &acg);
|
|
|
|
}
|
|
|
|
#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)
|
|
|
|
DBG_DUMP_SPTBL(&sblock, dbg_line, &acg);
|
|
|
|
#endif
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-14 23:12:32 +00:00
|
|
|
|
2007-02-14 23:20:30 +00:00
|
|
|
if (cfg_lv & 0x300) {
|
|
|
|
/* Dump the requested inode(s) */
|
|
|
|
if (cfg_in != -2)
|
|
|
|
DUMP_WHOLE_INODE((ino_t)cfg_in, cfg_lv);
|
|
|
|
else {
|
|
|
|
for (in = cg_start * sblock.fs_ipg;
|
|
|
|
in < (ino_t)cg_stop * sblock.fs_ipg;
|
|
|
|
in++)
|
|
|
|
DUMP_WHOLE_INODE(in, cfg_lv);
|
|
|
|
}
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DBG_CLOSE;
|
|
|
|
DBG_LEAVE;
|
2007-02-14 23:12:32 +00:00
|
|
|
|
2000-12-09 15:27:35 +00:00
|
|
|
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")
|
2018-11-13 21:40:56 +00:00
|
|
|
union dinodep dp;
|
|
|
|
int rb;
|
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.
|
|
|
|
*/
|
2018-11-13 21:40:56 +00:00
|
|
|
if (getinode(&disk, &dp, inode) == -1)
|
|
|
|
err(1, "getinode: %s", disk.d_error);
|
2000-12-09 15:27:35 +00:00
|
|
|
|
2018-11-13 21:40:56 +00:00
|
|
|
if (dp.dp1->di_nlink == 0) {
|
2000-12-09 15:27:35 +00:00
|
|
|
DBG_LEAVE;
|
|
|
|
return; /* inode not in use */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dump the main inode structure.
|
|
|
|
*/
|
2014-12-17 07:10:48 +00:00
|
|
|
snprintf(comment, sizeof(comment), "Inode 0x%08jx", (uintmax_t)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,
|
2018-11-13 21:40:56 +00:00
|
|
|
dp.dp1);
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(level & 0x200)) {
|
|
|
|
DBG_LEAVE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ok, now prepare for dumping all direct and indirect pointers.
|
|
|
|
*/
|
2018-11-13 21:40:56 +00:00
|
|
|
rb = howmany(dp.dp1->di_size, sblock.fs_bsize) - UFS_NDADDR;
|
|
|
|
if (rb > 0) {
|
2000-12-09 15:27:35 +00:00
|
|
|
/*
|
|
|
|
* Dump single indirect block.
|
|
|
|
*/
|
2018-11-13 21:40:56 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, dp.dp1->di_ib[0]),
|
|
|
|
(void *)&i1blk, (size_t)sblock.fs_bsize) == -1) {
|
2003-08-14 18:55:31 +00:00
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
2014-12-17 07:10:48 +00:00
|
|
|
snprintf(comment, sizeof(comment), "Inode 0x%08jx: indirect 0",
|
|
|
|
(uintmax_t)inode);
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_IBLK(&sblock,
|
|
|
|
comment,
|
|
|
|
i1blk,
|
|
|
|
(size_t)rb);
|
2018-11-13 21:40:56 +00:00
|
|
|
rb -= howmany(sblock.fs_bsize, sizeof(ufs1_daddr_t));
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
2018-11-13 21:40:56 +00:00
|
|
|
if (rb > 0) {
|
2000-12-09 15:27:35 +00:00
|
|
|
/*
|
|
|
|
* Dump double indirect blocks.
|
|
|
|
*/
|
2018-11-13 21:40:56 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, dp.dp1->di_ib[1]),
|
|
|
|
(void *)&i2blk, (size_t)sblock.fs_bsize) == -1) {
|
2003-08-14 18:55:31 +00:00
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
2014-12-17 07:10:48 +00:00
|
|
|
snprintf(comment, sizeof(comment), "Inode 0x%08jx: indirect 1",
|
|
|
|
(uintmax_t)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))));
|
2018-11-13 21:40:56 +00:00
|
|
|
for (ind2ctr = 0; ((ind2ctr < howmany(sblock.fs_bsize,
|
|
|
|
sizeof(ufs1_daddr_t))) && (rb > 0)); ind2ctr++) {
|
|
|
|
ind2ptr = &((ufs1_daddr_t *)(void *)&i2blk)[ind2ctr];
|
2000-12-09 15:27:35 +00:00
|
|
|
|
2018-11-13 21:40:56 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, *ind2ptr),
|
|
|
|
(void *)&i1blk, (size_t)sblock.fs_bsize) == -1) {
|
2003-08-14 18:55:31 +00:00
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
2001-06-07 20:43:00 +00:00
|
|
|
snprintf(comment, sizeof(comment),
|
2014-12-17 07:10:48 +00:00
|
|
|
"Inode 0x%08jx: indirect 1->%d", (uintmax_t)inode,
|
|
|
|
ind2ctr);
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_IBLK(&sblock,
|
|
|
|
comment,
|
|
|
|
i1blk,
|
|
|
|
(size_t)rb);
|
2018-11-13 21:40:56 +00:00
|
|
|
rb -= howmany(sblock.fs_bsize, sizeof(ufs1_daddr_t));
|
2000-12-09 15:27:35 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-13 21:40:56 +00:00
|
|
|
if (rb > 0) {
|
2000-12-09 15:27:35 +00:00
|
|
|
/*
|
|
|
|
* Dump triple indirect blocks.
|
|
|
|
*/
|
2018-11-13 21:40:56 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, dp.dp1->di_ib[2]),
|
|
|
|
(void *)&i3blk, (size_t)sblock.fs_bsize) == -1) {
|
2003-08-14 18:55:31 +00:00
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
2014-12-17 07:10:48 +00:00
|
|
|
snprintf(comment, sizeof(comment), "Inode 0x%08jx: indirect 2",
|
|
|
|
(uintmax_t)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
|
2018-11-13 21:40:56 +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
|
|
|
|
2018-11-13 21:40:56 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, *ind3ptr),
|
|
|
|
(void *)&i2blk, (size_t)sblock.fs_bsize) == -1) {
|
2003-08-14 18:55:31 +00:00
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
2001-06-07 20:43:00 +00:00
|
|
|
snprintf(comment, sizeof(comment),
|
2014-12-17 07:10:48 +00:00
|
|
|
"Inode 0x%08jx: indirect 2->%d", (uintmax_t)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))));
|
2018-11-13 21:40:56 +00:00
|
|
|
for (ind2ctr = 0; ((ind2ctr < howmany(sblock.fs_bsize,
|
|
|
|
sizeof(ufs1_daddr_t))) && (rb > 0)); ind2ctr++) {
|
2003-08-14 18:55:31 +00:00
|
|
|
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),
|
2014-12-17 07:10:48 +00:00
|
|
|
"Inode 0x%08jx: indirect 2->%d->%d",
|
|
|
|
(uintmax_t)inode, ind3ctr, ind3ctr);
|
2000-12-12 20:03:17 +00:00
|
|
|
DBG_DUMP_IBLK(&sblock,
|
|
|
|
comment,
|
|
|
|
i1blk,
|
|
|
|
(size_t)rb);
|
2018-11-13 21:40:56 +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")
|
2018-11-13 21:40:56 +00:00
|
|
|
union dinodep dp;
|
|
|
|
int rb;
|
2003-08-14 18:55:31 +00:00
|
|
|
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.
|
|
|
|
*/
|
2018-11-13 21:40:56 +00:00
|
|
|
if (getinode(&disk, &dp, inode) == -1)
|
|
|
|
err(1, "getinode: %s", disk.d_error);
|
2003-08-14 18:55:31 +00:00
|
|
|
|
2018-11-13 21:40:56 +00:00
|
|
|
if (dp.dp2->di_nlink == 0) {
|
2003-08-14 18:55:31 +00:00
|
|
|
DBG_LEAVE;
|
|
|
|
return; /* inode not in use */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dump the main inode structure.
|
|
|
|
*/
|
2014-12-17 07:10:48 +00:00
|
|
|
snprintf(comment, sizeof(comment), "Inode 0x%08jx", (uintmax_t)inode);
|
2003-08-14 18:55:31 +00:00
|
|
|
if (level & 0x100) {
|
2018-11-13 21:40:56 +00:00
|
|
|
DBG_DUMP_INO(&sblock, comment, dp.dp2);
|
2003-08-14 18:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(level & 0x200)) {
|
|
|
|
DBG_LEAVE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ok, now prepare for dumping all direct and indirect pointers.
|
|
|
|
*/
|
2018-11-13 21:40:56 +00:00
|
|
|
rb = howmany(dp.dp2->di_size, sblock.fs_bsize) - UFS_NDADDR;
|
2003-08-14 18:55:31 +00:00
|
|
|
if (rb > 0) {
|
|
|
|
/*
|
|
|
|
* Dump single indirect block.
|
|
|
|
*/
|
2018-11-13 21:40:56 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, dp.dp2->di_ib[0]),
|
|
|
|
(void *)&i1blk, (size_t)sblock.fs_bsize) == -1) {
|
2003-08-14 18:55:31 +00:00
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
2014-12-17 07:10:48 +00:00
|
|
|
snprintf(comment, sizeof(comment), "Inode 0x%08jx: indirect 0",
|
|
|
|
(uintmax_t)inode);
|
2003-08-14 18:55:31 +00:00
|
|
|
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.
|
|
|
|
*/
|
2018-11-13 21:40:56 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, dp.dp2->di_ib[1]),
|
|
|
|
(void *)&i2blk, (size_t)sblock.fs_bsize) == -1) {
|
2003-08-14 18:55:31 +00:00
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
2014-12-17 07:10:48 +00:00
|
|
|
snprintf(comment, sizeof(comment), "Inode 0x%08jx: indirect 1",
|
|
|
|
(uintmax_t)inode);
|
2003-08-14 18:55:31 +00:00
|
|
|
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];
|
|
|
|
|
2018-11-13 21:40:56 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, *ind2ptr),
|
|
|
|
(void *)&i1blk, (size_t)sblock.fs_bsize) == -1) {
|
2003-08-14 18:55:31 +00:00
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
|
|
|
snprintf(comment, sizeof(comment),
|
2014-12-17 07:10:48 +00:00
|
|
|
"Inode 0x%08jx: indirect 1->%d",
|
|
|
|
(uintmax_t)inode, ind2ctr);
|
2003-08-14 18:55:31 +00:00
|
|
|
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.
|
|
|
|
*/
|
2018-11-13 21:40:56 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, dp.dp2->di_ib[2]),
|
|
|
|
(void *)&i3blk, (size_t)sblock.fs_bsize) == -1) {
|
2003-08-14 18:55:31 +00:00
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
2014-12-17 07:10:48 +00:00
|
|
|
snprintf(comment, sizeof(comment), "Inode 0x%08jx: indirect 2",
|
|
|
|
(uintmax_t)inode);
|
2003-08-14 18:55:31 +00:00
|
|
|
#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];
|
|
|
|
|
2018-11-13 21:40:56 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, *ind3ptr),
|
|
|
|
(void *)&i2blk, (size_t)sblock.fs_bsize) == -1) {
|
2003-08-14 18:55:31 +00:00
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
|
|
|
snprintf(comment, sizeof(comment),
|
2014-12-17 07:10:48 +00:00
|
|
|
"Inode 0x%08jx: indirect 2->%d",
|
|
|
|
(uintmax_t)inode, ind3ctr);
|
2003-08-14 18:55:31 +00:00
|
|
|
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];
|
2018-11-13 21:40:56 +00:00
|
|
|
if (bread(&disk, fsbtodb(&sblock, *ind2ptr),
|
|
|
|
(void *)&i1blk, (size_t)sblock.fs_bsize)
|
|
|
|
== -1) {
|
2003-08-14 18:55:31 +00:00
|
|
|
err(1, "bread: %s", disk.d_error);
|
|
|
|
}
|
|
|
|
snprintf(comment, sizeof(comment),
|
2014-12-17 07:10:48 +00:00
|
|
|
"Inode 0x%08jx: indirect 2->%d->%d",
|
|
|
|
(uintmax_t)inode, ind3ctr, ind3ctr);
|
2003-08-14 18:55:31 +00:00
|
|
|
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,
|
2005-02-10 09:19:34 +00:00
|
|
|
"usage: ffsinfo [-g cylinder_group] [-i inode] [-l level] "
|
2000-12-12 20:03:17 +00:00
|
|
|
"[-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
|
|
|
}
|