1c85e6a35d
filesystem expands the inode to 256 bytes to make space for 64-bit block pointers. It also adds a file-creation time field, an ability to use jumbo blocks per inode to allow extent like pointer density, and space for extended attributes (up to twice the filesystem block size worth of attributes, e.g., on a 16K filesystem, there is space for 32K of attributes). UFS2 fully supports and runs existing UFS1 filesystems. New filesystems built using newfs can be built in either UFS1 or UFS2 format using the -O option. In this commit UFS1 is the default format, so if you want to build UFS2 format filesystems, you must specify -O 2. This default will be changed to UFS2 when UFS2 proves itself to be stable. In this commit the boot code for reading UFS2 filesystems is not compiled (see /sys/boot/common/ufsread.c) as there is insufficient space in the boot block. Once the size of the boot block is increased, this code can be defined. Things to note: the definition of SBSIZE has changed to SBLOCKSIZE. The header file <ufs/ufs/dinode.h> must be included before <ufs/ffs/fs.h> so as to get the definitions of ufs2_daddr_t and ufs_lbn_t. Still TODO: Verify that the first level bootstraps work for all the architectures. Convert the utility ffsinfo to understand UFS2 and test growfs. Add support for the extended attribute storage. Update soft updates to ensure integrity of extended attribute storage. Switch the current extended attribute interfaces to use the extended attribute storage. Add the extent like functionality (framework is there, but is currently never used). Sponsored by: DARPA & NAI Labs. Reviewed by: Poul-Henning Kamp <phk@freebsd.org>
359 lines
11 KiB
C
359 lines
11 KiB
C
/*
|
|
* Copyright (c) 2002 Networks Associates Technology, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This software was developed for the FreeBSD Project by Marshall
|
|
* Kirk McKusick and Network Associates Laboratories, the Security
|
|
* Research Division of Network Associates, Inc. under DARPA/SPAWAR
|
|
* contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
|
|
* research program
|
|
*
|
|
* Copyright (c) 1982, 1989, 1993
|
|
* The Regents of the University of California. All rights reserved.
|
|
* (c) UNIX System Laboratories, Inc.
|
|
* Copyright (c) 1983, 1992, 1993
|
|
* The Regents of the University of California. All rights reserved.
|
|
*
|
|
* 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 acknowledgement:
|
|
* This product includes software developed by the University of
|
|
* California, Berkeley and its contributors.
|
|
* 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.
|
|
*/
|
|
|
|
#ifndef lint
|
|
static const char copyright[] =
|
|
"@(#) Copyright (c) 1983, 1992, 1993\n\
|
|
The Regents of the University of California. All rights reserved.\n";
|
|
#endif /* not lint */
|
|
|
|
#ifndef lint
|
|
#if 0
|
|
static char sccsid[] = "@(#)dumpfs.c 8.5 (Berkeley) 4/29/95";
|
|
#endif
|
|
static const char rcsid[] =
|
|
"$FreeBSD$";
|
|
#endif /* not lint */
|
|
|
|
#include <sys/param.h>
|
|
#include <sys/time.h>
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <ufs/ufs/dinode.h>
|
|
#include <ufs/ffs/fs.h>
|
|
|
|
#include <err.h>
|
|
#include <fcntl.h>
|
|
#include <fstab.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
union {
|
|
struct fs fs;
|
|
char pad[MAXBSIZE];
|
|
} fsun;
|
|
#define afs fsun.fs
|
|
|
|
union {
|
|
struct cg cg;
|
|
char pad[MAXBSIZE];
|
|
} cgun;
|
|
#define acg cgun.cg
|
|
|
|
long dev_bsize = 1;
|
|
|
|
/*
|
|
* Possible superblock locations ordered from most to least likely.
|
|
*/
|
|
static int sblock_try[] = SBLOCKSEARCH;
|
|
|
|
int dumpfs(const char *);
|
|
int dumpcg(const char *, int, int);
|
|
void pbits(void *, int);
|
|
void usage(void) __dead2;
|
|
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
struct fstab *fs;
|
|
int ch, eval;
|
|
|
|
while ((ch = getopt(argc, argv, "")) != -1)
|
|
switch(ch) {
|
|
case '?':
|
|
default:
|
|
usage();
|
|
}
|
|
argc -= optind;
|
|
argv += optind;
|
|
|
|
if (argc < 1)
|
|
usage();
|
|
|
|
for (eval = 0; *argv; ++argv)
|
|
if ((fs = getfsfile(*argv)) == NULL)
|
|
eval |= dumpfs(*argv);
|
|
else
|
|
eval |= dumpfs(fs->fs_spec);
|
|
exit(eval);
|
|
}
|
|
|
|
int
|
|
dumpfs(const char *name)
|
|
{
|
|
ssize_t n;
|
|
time_t time;
|
|
int64_t fssize;
|
|
int fd, c, i, j, k, size;
|
|
|
|
if ((fd = open(name, O_RDONLY, 0)) < 0)
|
|
goto err;
|
|
for (i = 0; sblock_try[i] != -1; i++) {
|
|
if (lseek(fd, (off_t)sblock_try[i], SEEK_SET) == (off_t)-1)
|
|
goto err;
|
|
if ((n = read(fd, &afs, SBLOCKSIZE)) == -1)
|
|
goto err;
|
|
if ((afs.fs_magic == FS_UFS1_MAGIC ||
|
|
(afs.fs_magic == FS_UFS2_MAGIC &&
|
|
afs.fs_sblockloc == numfrags(&afs, sblock_try[i]))) &&
|
|
afs.fs_bsize <= MAXBSIZE &&
|
|
afs.fs_bsize >= sizeof(struct fs))
|
|
break;
|
|
}
|
|
if (sblock_try[i] == -1) {
|
|
fprintf(stderr, "Cannot find filesystem superblock\n");
|
|
return (1);
|
|
}
|
|
|
|
dev_bsize = afs.fs_fsize / fsbtodb(&afs, 1);
|
|
if (afs.fs_magic == FS_UFS2_MAGIC) {
|
|
fssize = afs.fs_size;
|
|
time = afs.fs_time;
|
|
printf("magic\t%x (UFS2)\ttime\t%s",
|
|
afs.fs_magic, ctime(&time));
|
|
printf("offset\t%qd\tid\t[ %x %x ]\n",
|
|
afs.fs_sblockloc, afs.fs_id[0], afs.fs_id[1]);
|
|
printf("ncg\t%d\tsize\t%qd\tblocks\t%d\n",
|
|
afs.fs_ncg, fssize, afs.fs_dsize);
|
|
} else {
|
|
fssize = afs.fs_old_size;
|
|
printf("magic\t%x (UFS1)\ttime\t%s",
|
|
afs.fs_magic, ctime(&afs.fs_old_time));
|
|
printf("id\t[ %x %x ]\n", afs.fs_id[0], afs.fs_id[1]);
|
|
printf("ncg\t%d\tsize\t%qd\tblocks\t%d\n",
|
|
afs.fs_ncg, fssize, afs.fs_dsize);
|
|
}
|
|
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("minfree\t%d%%\toptim\t%s\tsymlinklen %d\n",
|
|
afs.fs_minfree, afs.fs_optim == FS_OPTSPACE ? "space" : "time",
|
|
afs.fs_maxsymlinklen);
|
|
if (afs.fs_magic == FS_UFS2_MAGIC) {
|
|
printf("%s %d\tmaxbpg\t%d\tmaxcontig %d\tcontigsumsize %d\n",
|
|
"maxbsize", afs.fs_maxbsize, afs.fs_maxbpg,
|
|
afs.fs_maxcontig, afs.fs_contigsumsize);
|
|
printf("nbfree\t%qd\tndir\t%qd\tnifree\t%qd\tnffree\t%qd\n",
|
|
afs.fs_cstotal.cs_nbfree, afs.fs_cstotal.cs_ndir,
|
|
afs.fs_cstotal.cs_nifree, afs.fs_cstotal.cs_nffree);
|
|
printf("bpg\t%d\tfpg\t%d\tipg\t%d\n",
|
|
afs.fs_fpg / afs.fs_frag, afs.fs_fpg, afs.fs_ipg);
|
|
printf("nindir\t%d\tinopb\t%d\tmaxfilesize\t%qu\n",
|
|
afs.fs_nindir, afs.fs_inopb, afs.fs_maxfilesize);
|
|
printf("sbsize\t%d\tcgsize\t%d\tcsaddr\t%d\tcssize\t%d\n",
|
|
afs.fs_sbsize, afs.fs_cgsize, afs.fs_csaddr, afs.fs_cssize);
|
|
} else {
|
|
printf("maxbpg\t%d\tmaxcontig %d\tcontigsumsize %d\n",
|
|
afs.fs_maxbpg, afs.fs_maxcontig, afs.fs_contigsumsize);
|
|
printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
|
|
afs.fs_old_cstotal.cs_nbfree, afs.fs_old_cstotal.cs_ndir,
|
|
afs.fs_old_cstotal.cs_nifree, afs.fs_old_cstotal.cs_nffree);
|
|
printf("cpg\t%d\tbpg\t%d\tfpg\t%d\tipg\t%d\n",
|
|
afs.fs_old_cpg, afs.fs_fpg / afs.fs_frag, afs.fs_fpg,
|
|
afs.fs_ipg);
|
|
printf("nindir\t%d\tinopb\t%d\tnspf\t%d\tmaxfilesize\t%qu\n",
|
|
afs.fs_nindir, afs.fs_inopb, afs.fs_old_nspf,
|
|
afs.fs_maxfilesize);
|
|
printf("sbsize\t%d\tcgsize\t%d\tcgoffset %d\tcgmask\t0x%08x\n",
|
|
afs.fs_sbsize, afs.fs_cgsize, afs.fs_old_cgoffset,
|
|
afs.fs_old_cgmask);
|
|
printf("csaddr\t%d\tcssize\t%d\n",
|
|
afs.fs_old_csaddr, afs.fs_cssize);
|
|
printf("rotdelay %dms\trps\t%d\ttrackskew %d\tinterleave %d\n",
|
|
afs.fs_old_rotdelay, afs.fs_old_rps, afs.fs_old_trackskew,
|
|
afs.fs_old_interleave);
|
|
printf("nsect\t%d\tnpsect\t%d\tspc\t%d\n",
|
|
afs.fs_old_nsect, afs.fs_old_npsect, afs.fs_old_spc);
|
|
}
|
|
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("cgrotor\t%d\tfmod\t%d\tronly\t%d\tclean\t%d\n",
|
|
afs.fs_cgrotor, afs.fs_fmod, afs.fs_ronly, afs.fs_clean);
|
|
printf("flags\t");
|
|
if (afs.fs_flags == 0)
|
|
printf("none");
|
|
if (afs.fs_flags & FS_UNCLEAN)
|
|
printf("unclean ");
|
|
if (afs.fs_flags & FS_DOSOFTDEP)
|
|
printf("soft-updates ");
|
|
if (afs.fs_flags & FS_NEEDSFSCK)
|
|
printf("needs fsck run ");
|
|
if (afs.fs_flags & FS_INDEXDIRS)
|
|
printf("indexed directories ");
|
|
if ((afs.fs_flags &
|
|
~(FS_UNCLEAN | FS_DOSOFTDEP | FS_NEEDSFSCK | FS_INDEXDIRS)) != 0)
|
|
printf("unknown flags (%#x)", afs.fs_flags &
|
|
~(FS_UNCLEAN | FS_DOSOFTDEP |
|
|
FS_NEEDSFSCK | FS_INDEXDIRS));
|
|
putchar('\n');
|
|
printf("\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
|
|
afs.fs_csp = calloc(1, afs.fs_cssize);
|
|
if (lseek(fd,
|
|
(off_t)(fsbtodb(&afs, afs.fs_csaddr)) * (off_t)dev_bsize,
|
|
SEEK_SET) == (off_t)-1)
|
|
goto err;
|
|
if (read(fd, (char *)afs.fs_csp, afs.fs_cssize) != afs.fs_cssize)
|
|
goto err;
|
|
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);
|
|
}
|
|
printf("\n");
|
|
if (fssize % afs.fs_fpg) {
|
|
if (afs.fs_magic == FS_UFS1_MAGIC)
|
|
printf("cylinders in last group %d\n",
|
|
howmany(afs.fs_old_size % afs.fs_fpg,
|
|
afs.fs_old_spc / afs.fs_old_nspf));
|
|
printf("blocks in last group %d\n\n",
|
|
(fssize % afs.fs_fpg) / afs.fs_frag);
|
|
}
|
|
for (i = 0; i < afs.fs_ncg; i++)
|
|
if (dumpcg(name, fd, i))
|
|
goto err;
|
|
(void)close(fd);
|
|
return (0);
|
|
|
|
err: if (fd != -1)
|
|
(void)close(fd);
|
|
warn("%s", name);
|
|
return (1);
|
|
};
|
|
|
|
int
|
|
dumpcg(const char *name, int fd, int c)
|
|
{
|
|
time_t time;
|
|
off_t cur;
|
|
int i, j;
|
|
|
|
printf("\ncg %d:\n", c);
|
|
if ((cur = lseek(fd, (off_t)(fsbtodb(&afs, cgtod(&afs, c))) *
|
|
(off_t)dev_bsize, SEEK_SET)) == (off_t)-1)
|
|
return (1);
|
|
if (read(fd, &acg, afs.fs_bsize) != afs.fs_bsize) {
|
|
warnx("%s: error reading cg", name);
|
|
return (1);
|
|
}
|
|
if (afs.fs_magic == FS_UFS2_MAGIC) {
|
|
time = acg.cg_time;
|
|
printf("magic\t%x\ttell\t%qx\ttime\t%s",
|
|
acg.cg_magic, cur, ctime(&time));
|
|
printf("cgx\t%d\tndblk\t%d\tniblk\t%d\tinitiblk %d\n",
|
|
acg.cg_cgx, acg.cg_ndblk, acg.cg_niblk, acg.cg_initediblk);
|
|
} else {
|
|
printf("magic\t%x\ttell\t%qx\ttime\t%s",
|
|
acg.cg_magic, cur, ctime(&acg.cg_old_time));
|
|
printf("cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n",
|
|
acg.cg_cgx, acg.cg_old_ncyl, acg.cg_old_niblk,
|
|
acg.cg_ndblk);
|
|
}
|
|
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)[i]);
|
|
}
|
|
printf("\nclusters size %d and over: %d\n",
|
|
afs.fs_contigsumsize,
|
|
cg_clustersum(&acg)[afs.fs_contigsumsize]);
|
|
printf("clusters free:\t");
|
|
pbits(cg_clustersfree(&acg), acg.cg_nclusterblks);
|
|
} else
|
|
printf("\n");
|
|
printf("inodes used:\t");
|
|
pbits(cg_inosused(&acg), afs.fs_ipg);
|
|
printf("blks free:\t");
|
|
pbits(cg_blksfree(&acg), afs.fs_fpg);
|
|
return (0);
|
|
};
|
|
|
|
void
|
|
pbits(void *vp, int max)
|
|
{
|
|
int i;
|
|
char *p;
|
|
int count, j;
|
|
|
|
for (count = i = 0, p = vp; i < max; i++)
|
|
if (isset(p, i)) {
|
|
if (count)
|
|
printf(",%s", count % 6 ? " " : "\n\t");
|
|
count++;
|
|
printf("%d", i);
|
|
j = i;
|
|
while ((i+1)<max && isset(p, i+1))
|
|
i++;
|
|
if (i != j)
|
|
printf("-%d", i);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
void
|
|
usage(void)
|
|
{
|
|
(void)fprintf(stderr, "usage: dumpfs filesys | device\n");
|
|
exit(1);
|
|
}
|