NetBSD/usr.sbin/dumpfs/dumpfs.c

564 lines
15 KiB
C
Raw Normal View History

2003-08-30 16:48:11 +04:00
/* $NetBSD: dumpfs.c,v 1.38 2003/08/30 12:48:11 wiz Exp $ */
1993-03-21 12:45:37 +03:00
/*
* Copyright (c) 1983, 1992, 1993
* The Regents of the University of California. All rights reserved.
1993-03-21 12:45:37 +03:00
*
* 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. Neither the name of the University nor the names of its contributors
1993-03-21 12:45:37 +03:00
* 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.
*/
1997-10-17 04:16:55 +04:00
#include <sys/cdefs.h>
1993-03-21 12:45:37 +03:00
#ifndef lint
1997-10-17 04:16:55 +04:00
__COPYRIGHT("@(#) Copyright (c) 1983, 1992, 1993\n\
The Regents of the University of California. All rights reserved.\n");
1993-03-21 12:45:37 +03:00
#endif /* not lint */
#ifndef lint
#if 0
1997-09-16 07:13:18 +04:00
static char sccsid[] = "@(#)dumpfs.c 8.5 (Berkeley) 4/29/95";
#else
2003-08-30 16:48:11 +04:00
__RCSID("$NetBSD: dumpfs.c,v 1.38 2003/08/30 12:48:11 wiz Exp $");
#endif
1993-03-21 12:45:37 +03:00
#endif /* not lint */
#include <sys/param.h>
1994-04-25 22:23:19 +04:00
#include <sys/time.h>
1993-03-21 12:45:37 +03:00
2002-01-08 08:32:45 +03:00
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/ufs_bswap.h>
#include <ufs/ffs/fs.h>
#include <ufs/ffs/ffs_extern.h>
1993-03-21 12:45:37 +03:00
1994-09-23 06:18:30 +04:00
#include <err.h>
#include <errno.h>
1994-09-23 06:18:30 +04:00
#include <fcntl.h>
#include <fstab.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
1994-09-23 06:18:30 +04:00
#include <unistd.h>
#include <util.h>
1993-03-21 12:45:37 +03:00
union {
struct fs fs;
char pad[MAXBSIZE];
} fsun;
#define afs fsun.fs
union {
struct cg cg;
char pad[MAXBSIZE];
} cgun;
#define acg cgun.cg
#define OPT_FLAG(ch) (1 << ((ch) & 31))
#define ISOPT(opt) (opt_flags & (opt))
#define opt_superblock OPT_FLAG('s')
#define opt_cg_summary OPT_FLAG('m')
#define opt_cg_info OPT_FLAG('c')
#define opt_inodes OPT_FLAG('i')
#define opt_verbose OPT_FLAG('v')
#define DFLT_OPTS (opt_superblock | opt_cg_summary | opt_cg_info)
1993-03-21 12:45:37 +03:00
long dev_bsize = 1;
int needswap, printold, is_ufs2;
int Fflag;
uint opt_flags;
1993-03-21 12:45:37 +03:00
int dumpfs(const char *);
int print_superblock(const char *, int, off_t);
int print_cgsum(const char *, int);
int print_cginfo(const char *, int);
int print_inodes(const char *, int);
int dumpcg(const char *, int, int);
int main(int, char **);
int openpartition(const char *, int, char *, size_t);
void pbits(int, void *, int);
void usage(void);
void swap_cg(struct cg *);
void print_ufs1_inode(int, int, void *);
void print_ufs2_inode(int, int, void *);
int
main(int argc, char *argv[])
1993-03-21 12:45:37 +03:00
{
int ch, eval;
1993-03-21 12:45:37 +03:00
while ((ch = getopt(argc, argv, "Fcimsv")) != -1)
switch(ch) {
case 'c': /* cylinder group info */
case 'i': /* actual inodes */
case 'm': /* cylinder group summary */
case 's': /* superblock */
case 'v': /* more verbose */
opt_flags |= OPT_FLAG(ch);
break;
case 'F': /* File (not device) */
Fflag = 1;
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
if (opt_flags == 0)
opt_flags = DFLT_OPTS;
if (argc < 1)
usage();
for (eval = 0; *argv; ++argv) {
eval |= dumpfs(*argv);
printf("\n");
}
exit(eval);
1993-03-21 12:45:37 +03:00
}
int
dumpfs(const char *name)
1993-03-21 12:45:37 +03:00
{
const static off_t sblock_try[] = SBLOCKSEARCH;
char device[MAXPATHLEN];
int fd, i;
int rval = 1;
if (Fflag)
fd = open(name, O_RDONLY);
else {
fd = openpartition(name, O_RDONLY, device, sizeof(device));
name = device;
}
if (fd == -1)
goto err;
for (i = 0; ; i++) {
if (sblock_try[i] == -1) {
warnx("%s: could not find superblock, skipped", name);
return 1;
}
if (lseek(fd, sblock_try[i], SEEK_SET) == (off_t)-1)
continue;
if (read(fd, &afs, SBLOCKSIZE) != SBLOCKSIZE)
continue;
switch(afs.fs_magic) {
case FS_UFS2_MAGIC:
is_ufs2 = 1;
break;
case FS_UFS1_MAGIC:
break;
case FS_UFS2_MAGIC_SWAPPED:
is_ufs2 = 1;
needswap = 1;
break;
case FS_UFS1_MAGIC_SWAPPED:
needswap = 1;
break;
default:
continue;
}
break;
}
if (needswap)
ffs_sb_swap(&afs, &afs);
printold = (afs.fs_magic == FS_UFS1_MAGIC &&
(afs.fs_old_flags & FS_FLAGS_UPDATED) == 0);
if (printold) {
afs.fs_flags = afs.fs_old_flags;
afs.fs_maxbsize = afs.fs_bsize;
afs.fs_time = afs.fs_old_time;
afs.fs_size = afs.fs_old_size;
afs.fs_dsize = afs.fs_old_dsize;
afs.fs_csaddr = afs.fs_old_csaddr;
afs.fs_cstotal.cs_ndir = afs.fs_old_cstotal.cs_ndir;
afs.fs_cstotal.cs_nbfree = afs.fs_old_cstotal.cs_nbfree;
afs.fs_cstotal.cs_nifree = afs.fs_old_cstotal.cs_nifree;
afs.fs_cstotal.cs_nffree = afs.fs_old_cstotal.cs_nffree;
}
if (printold && afs.fs_old_postblformat == FS_42POSTBLFMT)
afs.fs_old_nrpos = 8;
dev_bsize = afs.fs_fsize / fsbtodb(&afs, 1);
rval = 0;
printf("file system: %s\n", name);
if (ISOPT(opt_superblock))
rval = print_superblock(name, fd, sblock_try[i]);
if (rval == 0 && ISOPT(opt_cg_summary))
rval = print_cgsum(name, fd);
if (rval == 0 && ISOPT(opt_cg_info))
rval = print_cginfo(name, fd);
if (rval == 0 && ISOPT(opt_inodes))
rval = print_inodes(name, fd);
err:
if (fd != -1)
(void)close(fd);
if (rval)
warn("%s", name);
return rval;
}
int
print_superblock(const char *name, int fd, off_t sblock)
{
int i, size;
time_t t;
#if BYTE_ORDER == LITTLE_ENDIAN
if (needswap)
#else
if (!needswap)
#endif
printf("endian\tbig-endian\n");
else
printf("endian\tlittle-endian\n");
t = afs.fs_time;
printf("location%lld\tmagic\t%x\ttime\t%s", (long long)sblock,
afs.fs_magic, ctime(&t));
if (is_ufs2)
i = 4;
else {
i = 0;
if (!printold && afs.fs_old_postblformat != FS_42POSTBLFMT) {
i++;
if (afs.fs_old_inodefmt >= FS_44INODEFMT) {
int max;
i++;
max = afs.fs_maxcontig;
size = afs.fs_contigsumsize;
if ((max < 2 && size == 0)
|| (max > 1 && size >= MIN(max, FS_MAXCONTIG)))
i++;
}
}
}
printf("id\t[ %x %x ]\n", afs.fs_id[0], afs.fs_id[1]);
2000-01-18 23:24:19 +03:00
printf("cylgrp\t%s\tinodes\t%s\tfslevel %d\tsoftdep %sabled\n",
i < 1 ? "static" : "dynamic",
i < 2 ? "4.2/4.3BSD" : i < 4 ? "4.4BSD" : "FFSv2", i,
2000-01-18 23:24:19 +03:00
(afs.fs_flags & FS_DOSOFTDEP) ? "en" : "dis");
printf("nbfree\t%lld\tndir\t%lld\tnifree\t%lld\tnffree\t%lld\n",
(long long)afs.fs_cstotal.cs_nbfree,
(long long)afs.fs_cstotal.cs_ndir,
(long long)afs.fs_cstotal.cs_nifree,
(long long)afs.fs_cstotal.cs_nffree);
printf("ncg\t%d\tsize\t%lld\tblocks\t%lld\n",
afs.fs_ncg, (long long)afs.fs_size, (long long)afs.fs_dsize);
if (printold)
printf("ncyl\t%d\n", afs.fs_old_ncyl);
1993-03-21 12:45:37 +03:00
printf("bsize\t%d\tshift\t%d\tmask\t0x%08x\n",
afs.fs_bsize, afs.fs_bshift, afs.fs_bmask);
printf("fsize\t%d\tshift\t%d\tmask\t0x%08x\n",
afs.fs_fsize, afs.fs_fshift, afs.fs_fmask);
printf("frag\t%d\tshift\t%d\tfsbtodb\t%d\n",
afs.fs_frag, afs.fs_fragshift, afs.fs_fsbtodb);
printf("bpg\t%d\tfpg\t%d\tipg\t%d\n",
afs.fs_fpg / afs.fs_frag, afs.fs_fpg, afs.fs_ipg);
1993-03-21 12:45:37 +03:00
printf("minfree\t%d%%\toptim\t%s\tmaxcontig %d\tmaxbpg\t%d\n",
afs.fs_minfree, afs.fs_optim == FS_OPTSPACE ? "space" : "time",
afs.fs_maxcontig, afs.fs_maxbpg);
if (printold) {
printf("cpg\t%d\trotdelay %dms\trps\t%d\n",
afs.fs_old_cpg, afs.fs_old_rotdelay, afs.fs_old_rps);
printf("ntrak\t%d\tnsect\t%d\tnpsect\t%d\tspc\t%d\n",
afs.fs_spare2, afs.fs_old_nsect, afs.fs_old_npsect,
afs.fs_old_spc);
printf("trackskew %d\tinterleave %d\n",
afs.fs_old_trackskew, afs.fs_old_interleave);
}
printf("symlinklen %d\tcontigsumsize %d\n",
afs.fs_maxsymlinklen, afs.fs_contigsumsize);
printf("maxfilesize 0x%016llx\n",
(unsigned long long)afs.fs_maxfilesize);
printf("nindir\t%d\tinopb\t%d\n", afs.fs_nindir, afs.fs_inopb);
if (printold)
printf("nspf\t%d\n", afs.fs_old_nspf);
Incorporate the enhanced ffs_dirpref() by Grigoriy Orlov, as found in FreeBSD (three commits; the initial work, man page updates, and a fix to ffs_reload()), with the following differences: - Be consistent between newfs(8) and tunefs(8) as to the options which set and control the tuning parameters for this work (avgfilesize & avgfpdir) - Use u_int16_t instead of u_int8_t to keep track of the number of contiguous directories (suggested by Chuck Silvers) - Work within our FFS_EI framework - Ensure that fs->fs_maxclusters and fs->fs_contigdirs don't point to the same area of memory The new algorithm has a marked performance increase, especially when performing tasks such as untarring pkgsrc.tar.gz, etc. The original FreeBSD commit messages are attached: ===== mckusick 2001/04/10 01:39:00 PDT Directory layout preference improvements from Grigoriy Orlov <gluk@ptci.ru>. His description of the problem and solution follow. My own tests show speedups on typical filesystem intensive workloads of 5% to 12% which is very impressive considering the small amount of code change involved. ------ One day I noticed that some file operations run much faster on small file systems then on big ones. I've looked at the ffs algorithms, thought about them, and redesigned the dirpref algorithm. First I want to describe the results of my tests. These results are old and I have improved the algorithm after these tests were done. Nevertheless they show how big the perfomance speedup may be. I have done two file/directory intensive tests on a two OpenBSD systems with old and new dirpref algorithm. The first test is "tar -xzf ports.tar.gz", the second is "rm -rf ports". The ports.tar.gz file is the ports collection from the OpenBSD 2.8 release. It contains 6596 directories and 13868 files. The test systems are: 1. Celeron-450, 128Mb, two IDE drives, the system at wd0, file system for test is at wd1. Size of test file system is 8 Gb, number of cg=991, size of cg is 8m, block size = 8k, fragment size = 1k OpenBSD-current from Dec 2000 with BUFCACHEPERCENT=35 2. PIII-600, 128Mb, two IBM DTLA-307045 IDE drives at i815e, the system at wd0, file system for test is at wd1. Size of test file system is 40 Gb, number of cg=5324, size of cg is 8m, block size = 8k, fragment size = 1k OpenBSD-current from Dec 2000 with BUFCACHEPERCENT=50 You can get more info about the test systems and methods at: http://www.ptci.ru/gluk/dirpref/old/dirpref.html Test Results tar -xzf ports.tar.gz rm -rf ports mode old dirpref new dirpref speedup old dirprefnew dirpref speedup First system normal 667 472 1.41 477 331 1.44 async 285 144 1.98 130 14 9.29 sync 768 616 1.25 477 334 1.43 softdep 413 252 1.64 241 38 6.34 Second system normal 329 81 4.06 263.5 93.5 2.81 async 302 25.7 11.75 112 2.26 49.56 sync 281 57.0 4.93 263 90.5 2.9 softdep 341 40.6 8.4 284 4.76 59.66 "old dirpref" and "new dirpref" columns give a test time in seconds. speedup - speed increasement in times, ie. old dirpref / new dirpref. ------ Algorithm description The old dirpref algorithm is described in comments: /* * Find a cylinder to place a directory. * * The policy implemented by this algorithm is to select from * among those cylinder groups with above the average number of * free inodes, the one with the smallest number of directories. */ A new directory is allocated in a different cylinder groups than its parent directory resulting in a directory tree that is spreaded across all the cylinder groups. This spreading out results in a non-optimal access to the directories and files. When we have a small filesystem it is not a problem but when the filesystem is big then perfomance degradation becomes very apparent. What I mean by a big file system ? 1. A big filesystem is a filesystem which occupy 20-30 or more percent of total drive space, i.e. first and last cylinder are physically located relatively far from each other. 2. It has a relatively large number of cylinder groups, for example more cylinder groups than 50% of the buffers in the buffer cache. The first results in long access times, while the second results in many buffers being used by metadata operations. Such operations use cylinder group blocks and on-disk inode blocks. The cylinder group block (fs->fs_cblkno) contains struct cg, inode and block bit maps. It is 2k in size for the default filesystem parameters. If new and parent directories are located in different cylinder groups then the system performs more input/output operations and uses more buffers. On filesystems with many cylinder groups, lots of cache buffers are used for metadata operations. My solution for this problem is very simple. I allocate many directories in one cylinder group. I also do some things, so that the new allocation method does not cause excessive fragmentation and all directory inodes will not be located at a location far from its file's inodes and data. The algorithm is: /* * Find a cylinder group to place a directory. * * The policy implemented by this algorithm is to allocate a * directory inode in the same cylinder group as its parent * directory, but also to reserve space for its files inodes * and data. Restrict the number of directories which may be * allocated one after another in the same cylinder group * without intervening allocation of files. * * If we allocate a first level directory then force allocation * in another cylinder group. */ My early versions of dirpref give me a good results for a wide range of file operations and different filesystem capacities except one case: those applications that create their entire directory structure first and only later fill this structure with files. My solution for such and similar cases is to limit a number of directories which may be created one after another in the same cylinder group without intervening file creations. For this purpose, I allocate an array of counters at mount time. This array is linked to the superblock fs->fs_contigdirs[cg]. Each time a directory is created the counter increases and each time a file is created the counter decreases. A 60Gb filesystem with 8mb/cg requires 10kb of memory for the counters array. The maxcontigdirs is a maximum number of directories which may be created without an intervening file creation. I found in my tests that the best performance occurs when I restrict the number of directories in one cylinder group such that all its files may be located in the same cylinder group. There may be some deterioration in performance if all the file inodes are in the same cylinder group as its containing directory, but their data partially resides in a different cylinder group. The maxcontigdirs value is calculated to try to prevent this condition. Since there is no way to know how many files and directories will be allocated later I added two optimization parameters in superblock/tunefs. They are: int32_t fs_avgfilesize; /* expected average file size */ int32_t fs_avgfpdir; /* expected # of files per directory */ These parameters have reasonable defaults but may be tweeked for special uses of a filesystem. They are only necessary in rare cases like better tuning a filesystem being used to store a squid cache. I have been using this algorithm for about 3 months. I have done a lot of testing on filesystems with different capacities, average filesize, average number of files per directory, and so on. I think this algorithm has no negative impact on filesystem perfomance. It works better than the default one in all cases. The new dirpref will greatly improve untarring/removing/coping of big directories, decrease load on cvs servers and much more. The new dirpref doesn't speedup a compilation process, but also doesn't slow it down. Obtained from: Grigoriy Orlov <gluk@ptci.ru> ===== ===== iedowse 2001/04/23 17:37:17 PDT Pre-dirpref versions of fsck may zero out the new superblock fields fs_contigdirs, fs_avgfilesize and fs_avgfpdir. This could cause panics if these fields were zeroed while a filesystem was mounted read-only, and then remounted read-write. Add code to ffs_reload() which copies the fs_contigdirs pointer from the previous superblock, and reinitialises fs_avgf* if necessary. Reviewed by: mckusick ===== ===== nik 2001/04/10 03:36:44 PDT Add information about the new options to newfs and tunefs which set the expected average file size and number of files per directory. Could do with some fleshing out. =====
2001-09-06 06:16:00 +04:00
printf("avgfilesize %d\tavgfpdir %d\n",
afs.fs_avgfilesize, afs.fs_avgfpdir);
1993-03-21 12:45:37 +03:00
printf("sblkno\t%d\tcblkno\t%d\tiblkno\t%d\tdblkno\t%d\n",
afs.fs_sblkno, afs.fs_cblkno, afs.fs_iblkno, afs.fs_dblkno);
printf("sbsize\t%d\tcgsize\t%d\n", afs.fs_sbsize, afs.fs_cgsize);
if (printold)
printf("offset\t%d\tmask\t0x%08x\n",
afs.fs_old_cgoffset, afs.fs_old_cgmask);
printf("csaddr\t%lld\tcssize %d\n",
(long long)afs.fs_csaddr, afs.fs_cssize);
if (printold)
printf("shift\t%d\tmask\t0x%08x\n",
afs.fs_spare1[0], afs.fs_spare1[1]);
1995-04-13 01:23:24 +04:00
printf("cgrotor\t%d\tfmod\t%d\tronly\t%d\tclean\t0x%02x\n",
afs.fs_cgrotor, afs.fs_fmod, afs.fs_ronly, afs.fs_clean);
if (printold) {
if (afs.fs_old_cpc != 0)
printf("blocks available in each of %d rotational "
"positions", afs.fs_old_nrpos);
else
printf("(no rotational position table)\n");
1993-03-21 12:45:37 +03:00
}
return 0;
}
int
print_cgsum(const char *name, int fd)
{
struct csum *ccsp;
int i, j, size;
afs.fs_csp = calloc(1, afs.fs_cssize);
1993-03-21 12:45:37 +03:00
for (i = 0, j = 0; i < afs.fs_cssize; i += afs.fs_bsize, j++) {
size = afs.fs_cssize - i < afs.fs_bsize ?
afs.fs_cssize - i : afs.fs_bsize;
ccsp = (struct csum *)((char *)afs.fs_csp + i);
if (lseek(fd,
(off_t)(fsbtodb(&afs, (afs.fs_csaddr + j * afs.fs_frag))) *
dev_bsize, SEEK_SET) == (off_t)-1)
return 1;
if (read(fd, ccsp, size) != size)
return 1;
if (needswap)
ffs_csum_swap(ccsp, ccsp, size);
1993-03-21 12:45:37 +03:00
}
printf("\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
1993-03-21 12:45:37 +03:00
for (i = 0; i < afs.fs_ncg; i++) {
struct csum *cs = &afs.fs_cs(&afs, i);
if (i && i % 4 == 0)
printf("\n\t");
printf("(%d,%d,%d,%d) ",
cs->cs_nbfree, cs->cs_ndir, cs->cs_nifree, cs->cs_nffree);
}
if (i % 4 == 0)
printf("\n");
if (printold && (afs.fs_old_ncyl % afs.fs_old_cpg)) {
1993-03-21 12:45:37 +03:00
printf("cylinders in last group %d\n",
i = afs.fs_old_ncyl % afs.fs_old_cpg);
1993-03-21 12:45:37 +03:00
printf("blocks in last group %d\n",
i * afs.fs_old_spc / (afs.fs_old_nspf << afs.fs_fragshift));
1993-03-21 12:45:37 +03:00
}
printf("\n");
free(afs.fs_csp);
afs.fs_csp = NULL;
return 0;
}
int
print_cginfo(const char *name, int fd)
{
int i;
1993-03-21 12:45:37 +03:00
for (i = 0; i < afs.fs_ncg; i++)
if (dumpcg(name, fd, i))
return 1;
return 0;
}
int
print_inodes(const char *name, int fd)
{
void *ino_buf = malloc(afs.fs_bsize);
void (*print_inode)(int, int, void *);
int i, inum;
if (ino_buf == 0)
return 1;
print_inode = is_ufs2 ? print_ufs2_inode : print_ufs1_inode;
for (inum = 0; inum < afs.fs_ncg * afs.fs_ipg; inum += afs.fs_inopb) {
if (pread(fd, ino_buf, afs.fs_bsize,
ino_to_fsba(&afs, inum) * afs.fs_fsize) != afs.fs_bsize)
return 1;
for (i = 0; i < afs.fs_inopb; i++)
print_inode(inum + i, i, ino_buf);
}
free(ino_buf);
return 0;
}
1993-03-21 12:45:37 +03:00
int
dumpcg(const char *name, int fd, int c)
1993-03-21 12:45:37 +03:00
{
off_t cur;
int i, j;
2001-02-23 11:52:00 +03:00
time_t t;
1993-03-21 12:45:37 +03:00
printf("\ncg %d:\n", c);
if ((cur = lseek(fd, (off_t)(fsbtodb(&afs, cgtod(&afs, c))) * dev_bsize,
SEEK_SET)) == (off_t)-1)
return (1);
if (read(fd, &acg, afs.fs_bsize) != afs.fs_bsize) {
1994-09-23 06:18:30 +04:00
warnx("%s: error reading cg", name);
return (1);
1993-03-21 12:45:37 +03:00
}
if (needswap)
ffs_cg_swap(&acg, &acg, &afs);
t = acg.cg_time;
printf("magic\t%x\ttell\t%llx\ttime\t%s",
afs.fs_old_postblformat == FS_42POSTBLFMT ?
1993-03-21 12:45:37 +03:00
((struct ocg *)&acg)->cg_magic : acg.cg_magic,
2001-02-23 11:52:00 +03:00
(long long)cur, ctime(&t));
printf("cgx\t%d\tniblk\t%d\tndblk\t%d\n",
acg.cg_cgx, acg.cg_niblk, acg.cg_ndblk);
1993-03-21 12:45:37 +03:00
printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
acg.cg_cs.cs_nbfree, acg.cg_cs.cs_ndir,
acg.cg_cs.cs_nifree, acg.cg_cs.cs_nffree);
printf("rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum",
acg.cg_rotor, acg.cg_irotor, acg.cg_frotor);
for (i = 1, j = 0; i < afs.fs_frag; i++) {
printf("\t%d", acg.cg_frsum[i]);
j += i * acg.cg_frsum[i];
}
printf("\nsum of frsum: %d", j);
if (afs.fs_contigsumsize > 0) {
for (i = 1; i < afs.fs_contigsumsize; i++) {
if ((i - 1) % 8 == 0)
printf("\nclusters %d-%d:", i,
afs.fs_contigsumsize - 1 < i + 7 ?
afs.fs_contigsumsize - 1 : i + 7);
printf("\t%d", cg_clustersum(&acg, 0)[i]);
}
printf("\nclusters size %d and over: %d\n",
afs.fs_contigsumsize,
cg_clustersum(&acg, 0)[afs.fs_contigsumsize]);
printf("clusters free:\t");
pbits(0, cg_clustersfree(&acg, 0), acg.cg_nclusterblks);
} else
printf("\n");
printf("iused:\t");
pbits(c * afs.fs_ipg, cg_inosused(&acg, 0), afs.fs_ipg);
1993-03-21 12:45:37 +03:00
printf("free:\t");
pbits(0, cg_blksfree(&acg, 0), afs.fs_fpg);
return (0);
}
void
print_ufs1_inode(int inum, int i_off, void *ibuf)
{
struct ufs1_dinode *i = ibuf;
i += i_off;
if (inum == 0)
printf("\n inode: mode nlink size"
" ctime.nsec flags blocks"
" generation uid gid\n");
if (i->di_mode == 0 && i->di_nlink == 0 && !ISOPT(opt_verbose))
return;
printf("%8u: %6o %6d %20" PRIu64 " %10u.%09u %8x %10u %8x %10u %10u\n",
inum, i->di_mode, i->di_nlink, i->di_size,
i->di_ctime, i->di_ctimensec, i->di_flags, i->di_blocks,
i->di_gen, i->di_uid, i->di_gid);
}
void
print_ufs2_inode(int inum, int i_off, void *ibuf)
{
struct ufs2_dinode *i = ibuf;
i += i_off;
if (inum == 0)
printf("\n inode: mode nlink size"
" ctime.nsec flags blocks"
" generation uid gid\n");
if (i->di_mode == 0 && i->di_nlink == 0 && !ISOPT(opt_verbose))
return;
printf("%8u: %6o %6d %20" PRIu64 " %10" PRIu64 ".%09u %8x %10" PRIu64 " %8x %10u %10u\n",
inum, i->di_mode, i->di_nlink, i->di_size,
i->di_ctime, i->di_ctimensec, i->di_flags, i->di_blocks,
i->di_gen, i->di_uid, i->di_gid);
}
1993-03-21 12:45:37 +03:00
void
pbits(int offset, void *vp, int max)
1993-03-21 12:45:37 +03:00
{
1997-10-17 04:16:55 +04:00
int i;
char *p;
int count, j;
1993-03-21 12:45:37 +03:00
for (count = i = 0, p = vp; i < max; i++)
if (isset(p, i)) {
1993-03-21 12:45:37 +03:00
if (count)
printf(",%s", count % 6 ? " " : "\n\t");
count++;
printf("%d", offset + i);
1993-03-21 12:45:37 +03:00
j = i;
while ((i+1)<max && isset(p, i+1))
1993-03-21 12:45:37 +03:00
i++;
if (i != j)
printf("-%d", offset + i);
1993-03-21 12:45:37 +03:00
}
printf("\n");
}
void
usage(void)
{
1994-09-23 06:18:30 +04:00
2003-08-30 16:48:11 +04:00
(void)fprintf(stderr, "usage: dumpfs [-cFimsv] filesys | device [...]\n");
exit(1);
}
int
openpartition(const char *name, int flags, char *device, size_t devicelen)
{
char rawspec[MAXPATHLEN], *p;
struct fstab *fs;
int fd, oerrno;
fs = getfsfile(name);
if (fs) {
if ((p = strrchr(fs->fs_spec, '/')) != NULL) {
snprintf(rawspec, sizeof(rawspec), "%.*s/r%s",
(int)(p - fs->fs_spec), fs->fs_spec, p + 1);
name = rawspec;
} else
name = fs->fs_spec;
}
fd = opendisk(name, flags, device, devicelen, 0);
if (fd == -1 && errno == ENOENT) {
oerrno = errno;
strlcpy(device, name, devicelen);
errno = oerrno;
}
return (fd);
}