Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/dumpfs restore traditional output for older filesys...



details:   https://anonhg.NetBSD.org/src/rev/6ce94f6d9355
branches:  trunk
changeset: 557176:6ce94f6d9355
user:      dbj <dbj%NetBSD.org@localhost>
date:      Sat Jan 03 19:32:58 2004 +0000

description:
restore traditional output for older filesystems
add byte swapping support for inode printing

diffstat:

 usr.sbin/dumpfs/Makefile |    5 +-
 usr.sbin/dumpfs/dumpfs.8 |    4 +-
 usr.sbin/dumpfs/dumpfs.c |  257 ++++++++++++++++++++++++++++++++++------------
 3 files changed, 195 insertions(+), 71 deletions(-)

diffs (truncated from 550 to 300 lines):

diff -r d5dd848fc55d -r 6ce94f6d9355 usr.sbin/dumpfs/Makefile
--- a/usr.sbin/dumpfs/Makefile  Sat Jan 03 19:31:09 2004 +0000
+++ b/usr.sbin/dumpfs/Makefile  Sat Jan 03 19:32:58 2004 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.13 2003/12/28 06:04:23 dbj Exp $
+#      $NetBSD: Makefile,v 1.14 2004/01/03 19:32:58 dbj Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/5/93
 
 .include <bsd.own.mk>
@@ -6,8 +6,11 @@
 PROG=  dumpfs
 MAN=   dumpfs.8
 SRCS=  dumpfs.c ffs_bswap.c
+
+.ifndef HOSTPROG
 LDADD+=        -lutil
 DPADD+=        ${LIBUTIL}
+.endif
 
 WARNS= 2
 
diff -r d5dd848fc55d -r 6ce94f6d9355 usr.sbin/dumpfs/dumpfs.8
--- a/usr.sbin/dumpfs/dumpfs.8  Sat Jan 03 19:31:09 2004 +0000
+++ b/usr.sbin/dumpfs/dumpfs.8  Sat Jan 03 19:32:58 2004 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: dumpfs.8,v 1.16 2003/09/26 07:02:43 dsl Exp $
+.\"    $NetBSD: dumpfs.8,v 1.17 2004/01/03 19:32:58 dbj Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -72,7 +72,7 @@
 are given, then
 .Nm
 defaults to
-.Fl cms .
+.Fl cmsv .
 .Pp
 .Nm
 is useful mostly for finding out certain file system
diff -r d5dd848fc55d -r 6ce94f6d9355 usr.sbin/dumpfs/dumpfs.c
--- a/usr.sbin/dumpfs/dumpfs.c  Sat Jan 03 19:31:09 2004 +0000
+++ b/usr.sbin/dumpfs/dumpfs.c  Sat Jan 03 19:32:58 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dumpfs.c,v 1.41 2003/12/29 14:25:07 dbj Exp $  */
+/*     $NetBSD: dumpfs.c,v 1.42 2004/01/03 19:32:58 dbj Exp $  */
 
 /*
  * Copyright (c) 1983, 1992, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)dumpfs.c   8.5 (Berkeley) 4/29/95";
 #else
-__RCSID("$NetBSD: dumpfs.c,v 1.41 2003/12/29 14:25:07 dbj Exp $");
+__RCSID("$NetBSD: dumpfs.c,v 1.42 2004/01/03 19:32:58 dbj Exp $");
 #endif
 #endif /* not lint */
 
@@ -67,6 +67,8 @@
 } fsun;
 #define        afs     fsun.fs
 
+uint16_t opostblsave[32*8];
+
 union {
        struct cg cg;
        char pad[MAXBSIZE];
@@ -82,8 +84,8 @@
 #define opt_inodes     OPT_FLAG('i')
 #define opt_verbose    OPT_FLAG('v')
 #define DFLT_CHECK (opt_alt_super | opt_cg_info | opt_inodes | \
-       opt_cg_summary | opt_superblock)
-#define DFLT_OPTS      (opt_superblock | opt_cg_summary | opt_cg_info)
+    opt_cg_summary | opt_superblock)
+#define DFLT_OPTS      (opt_superblock | opt_cg_summary | opt_cg_info | opt_verbose)
 
 long   dev_bsize = 512;
 int    needswap, printold, is_ufs2;
@@ -92,29 +94,28 @@
 uint   opt_flags;
 
 int    dumpfs(const char *);
-int    print_superblock(struct fs *, const char *, int, off_t);
+int    print_superblock(struct fs *, uint16_t *, const char *, int, off_t);
 int    print_cgsum(const char *, int);
 int    print_cginfo(const char *, int);
-int    print_inodes(const char *, int);
+int    print_inodes(const char *, int, int, int);
 int    print_alt_super(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 *);
-void   fix_superblock(struct fs *);
+void   fix_superblock(struct fs *, uint16_t *);
 
 int
 main(int argc, char *argv[])
 {
        int ch, eval;
 
-       while ((ch = getopt(argc, argv, "Facimsv")) != -1)
+       while ((ch = getopt(argc, argv, "acimsvF")) != -1)
                switch(ch) {
-               case 'a':       /* alternate suberblocks */
+               case 'a':       /* alternate superblocks */
                case 'c':       /* cylinder group info */
                case 'i':       /* actual inodes */
                case 'm':       /* cylinder group summary */
@@ -140,7 +141,6 @@
 
        for (eval = 0; *argv; ++argv) {
                eval |= dumpfs(*argv);
-               printf("\n");
        }
 
        exit(eval);
@@ -192,7 +192,7 @@
                break;
        }
 
-       fix_superblock(&afs);
+       fix_superblock(&afs, opostblsave);
 
        dev_bsize = afs.fs_fsize / fsbtodb(&afs, 1);
 
@@ -200,15 +200,15 @@
        printf("file system: %s\n", name);
 
        if (ISOPT(opt_superblock))
-               rval = print_superblock(&afs, name, fd, sblock_try[i]);
-       if (rval == 0 && ISOPT(opt_alt_super))
-               rval = print_alt_super(name, fd);
+               rval = print_superblock(&afs, opostblsave, name, fd, sblock_try[i]);
        if (rval == 0 && ISOPT(opt_cg_summary))
                rval = print_cgsum(name, fd);
+       if (rval == 0 && ISOPT(opt_alt_super))
+               rval = print_alt_super(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);
+       else if (rval == 0 && ISOPT(opt_inodes))
+               rval = print_inodes(name, fd, 0, afs.fs_ncg);
 
     err:
        if (fd != -1)
@@ -219,8 +219,20 @@
 }
 
 void
-fix_superblock(struct fs *fs)
+fix_superblock(struct fs *fs, uint16_t *opostbl)
 {
+       if (needswap &&
+           ((bswap32(fs->fs_old_postblformat) == FS_42POSTBLFMT) ||
+            (bswap32(fs->fs_old_postbloff) == offsetof(struct fs, fs_old_postbl_start)))) {
+               int i;
+               memcpy(opostbl, &fs->fs_old_postbl_start, 512);
+               for(i=0;i<256;i++)
+                       opostbl[i] = bswap16(opostbl[i]);
+       } else if (!needswap &&
+          ((fs->fs_old_postblformat == FS_42POSTBLFMT) ||
+           (fs->fs_old_postbloff == offsetof(struct fs, fs_old_postbl_start)))) {
+               memcpy(opostbl, &fs->fs_old_postbl_start, 512);
+       }
 
        if (needswap)
                ffs_sb_swap(fs, fs);
@@ -228,6 +240,7 @@
        printold = (fs->fs_magic == FS_UFS1_MAGIC &&
                    (fs->fs_old_flags & FS_FLAGS_UPDATED) == 0);
        if (printold) {
+               fs->fs_sblockloc = SBLOCK_UFS1;
                fs->fs_flags = fs->fs_old_flags;
                fs->fs_maxbsize = fs->fs_bsize;
                fs->fs_time = fs->fs_old_time;
@@ -245,10 +258,12 @@
 }
 
 int
-print_superblock(struct fs *fs, const char *name, int fd, off_t sblock)
+print_superblock(struct fs *fs, uint16_t *opostbl,
+    const char *name, int fd, off_t sblock)
 {
        int i, size;
        time_t t;
+       int32_t fsflags;
 
 #if BYTE_ORDER == LITTLE_ENDIAN
        if (needswap)
@@ -259,14 +274,17 @@
        else
                printf("endian\tlittle-endian\n");
        t = fs->fs_time;
-       printf("location%lld\tmagic\t%x\ttime\t%s", (long long)sblock,
-           fs->fs_magic, ctime(&t));
+       if ((sblock != SBLOCK_UFS1) || ISOPT(opt_alt_super))
+               printf("location %lld\t(-b %lld)\n",
+                   (long long)sblock, (long long)(sblock/dev_bsize));
+       printf("magic\t%x (UFS%d)\ttime\t%s",
+           fs->fs_magic, is_ufs2+1, ctime(&t));
 
        if (is_ufs2)
-               i = 4;
+               i = 5;
        else {
                i = 0;
-               if (!printold && fs->fs_old_postblformat != FS_42POSTBLFMT) {
+               if (fs->fs_old_postblformat != FS_42POSTBLFMT) {
                        i++;
                        if (fs->fs_old_inodefmt >= FS_44INODEFMT) {
                                int max;
@@ -278,70 +296,130 @@
                                    || (max > 1 && size >= MIN(max, FS_MAXCONTIG)))
                                        i++;
                        }
+                       if (fs->fs_old_flags & FS_FLAGS_UPDATED) {
+                               i = 4;
+                       }
                }
        }
-       printf("id\t[ %x %x ]\n", fs->fs_id[0], fs->fs_id[1]);
-       printf("cylgrp\t%s\tinodes\t%s\tfslevel %d\tsoftdep %sabled\n",
+       if (!printold || fs->fs_sblockloc != SBLOCK_UFS1 ||
+           fs->fs_id[0] || fs->fs_id[1])
+               printf("superblock location\t%jd\tid\t[ %x %x ]\n",
+                   (intmax_t)fs->fs_sblockloc, fs->fs_id[0], fs->fs_id[1]);
+       printf("cylgrp\t%s\tinodes\t%s\tsblock\t%s\tfslevel %d\n",
            i < 1 ? "static" : "dynamic",
-           i < 2 ? "4.2/4.3BSD" : i < 4 ? "4.4BSD" : "FFSv2", i,
-           (fs->fs_flags & FS_DOSOFTDEP) ? "en" : "dis");
+           i < 2 ? "4.2/4.3BSD" : i < 5 ? "4.4BSD" : "FFSv2",
+                       i < 4 ? "FFSv1" : "FFSv2", i);
        printf("nbfree\t%lld\tndir\t%lld\tnifree\t%lld\tnffree\t%lld\n",
            (long long)fs->fs_cstotal.cs_nbfree,
            (long long)fs->fs_cstotal.cs_ndir,
            (long long)fs->fs_cstotal.cs_nifree,
            (long long)fs->fs_cstotal.cs_nffree);
-       printf("ncg\t%d\tsize\t%lld\tblocks\t%lld\n",
-           fs->fs_ncg, (long long)fs->fs_size, (long long)fs->fs_dsize);
        if (printold)
-               printf("ncyl\t%d\n", fs->fs_old_ncyl);
+               printf("ncg\t%d\tncyl\t%d\tsize\t%lld\tblocks\t%lld\n",
+                   fs->fs_ncg, fs->fs_old_ncyl, (long long)fs->fs_size, (long long)fs->fs_dsize);
+       else
+               printf("ncg\t%d\tsize\t%lld\tblocks\t%lld\n",
+                   fs->fs_ncg, (long long)fs->fs_size, (long long)fs->fs_dsize);
        printf("bsize\t%d\tshift\t%d\tmask\t0x%08x\n",
            fs->fs_bsize, fs->fs_bshift, fs->fs_bmask);
        printf("fsize\t%d\tshift\t%d\tmask\t0x%08x\n",
            fs->fs_fsize, fs->fs_fshift, fs->fs_fmask);
        printf("frag\t%d\tshift\t%d\tfsbtodb\t%d\n",
            fs->fs_frag, fs->fs_fragshift, fs->fs_fsbtodb);
+       if (printold)
+               printf("cpg\t%d\t", fs->fs_old_cpg);
        printf("bpg\t%d\tfpg\t%d\tipg\t%d\n",
            fs->fs_fpg / fs->fs_frag, fs->fs_fpg, fs->fs_ipg);
        printf("minfree\t%d%%\toptim\t%s\tmaxcontig %d\tmaxbpg\t%d\n",
            fs->fs_minfree, fs->fs_optim == FS_OPTSPACE ? "space" : "time",
            fs->fs_maxcontig, fs->fs_maxbpg);
        if (printold) {
-               printf("cpg\t%d\trotdelay %dms\trps\t%d\n",
-                   fs->fs_old_cpg, fs->fs_old_rotdelay, fs->fs_old_rps);
+               printf("rotdelay %dms\theadswitch %dus\ttrackseek %dus\trps\t%d\n",
+                   fs->fs_old_rotdelay, fs->fs_old_headswitch,
+                   fs->fs_old_trkseek, fs->fs_old_rps);
                printf("ntrak\t%d\tnsect\t%d\tnpsect\t%d\tspc\t%d\n",
                    fs->fs_spare2, fs->fs_old_nsect, fs->fs_old_npsect,
                    fs->fs_old_spc);
-               printf("trackskew %d\tinterleave %d\n",
+       }
+       printf("symlinklen %d\t", fs->fs_maxsymlinklen);
+       if (printold)
+               printf("trackskew %d\tinterleave %d\t",
                    fs->fs_old_trackskew, fs->fs_old_interleave);
-       }
-       printf("symlinklen %d\tcontigsumsize %d\n",
-           fs->fs_maxsymlinklen, fs->fs_contigsumsize);
+       printf("contigsumsize %d\n", fs->fs_contigsumsize);
        printf("maxfilesize 0x%016llx\n",
            (unsigned long long)fs->fs_maxfilesize);
-       printf("nindir\t%d\tinopb\t%d\n", fs->fs_nindir, fs->fs_inopb);
        if (printold)
-               printf("nspf\t%d\n", fs->fs_old_nspf);
-       printf("avgfilesize %d\tavgfpdir %d\n",
-           fs->fs_avgfilesize, fs->fs_avgfpdir);
+               printf("nindir\t%d\tinopb\t%d\tnspf\t%d\n", fs->fs_nindir,
+                   fs->fs_inopb, fs->fs_old_nspf);
+       else 
+               printf("nindir\t%d\tinopb\t%d\n", fs->fs_nindir, fs->fs_inopb);
+       if (!printold || (fs->fs_avgfilesize > 0) || (fs->fs_avgfpdir > 0))
+               printf("avgfilesize %d\tavgfpdir %d\n",
+                   fs->fs_avgfilesize, fs->fs_avgfpdir);
        printf("sblkno\t%d\tcblkno\t%d\tiblkno\t%d\tdblkno\t%d\n",
            fs->fs_sblkno, fs->fs_cblkno, fs->fs_iblkno, fs->fs_dblkno);
-       printf("sbsize\t%d\tcgsize\t%d\n", fs->fs_sbsize, fs->fs_cgsize);



Home | Main Index | Thread Index | Old Index