Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/dumplfs Assorted changes/fixes to dumplfs:



details:   https://anonhg.NetBSD.org/src/rev/2b113b2452e3
branches:  trunk
changeset: 487856:2b113b2452e3
user:      perseant <perseant%NetBSD.org@localhost>
date:      Wed Jun 14 01:55:37 2000 +0000

description:
Assorted changes/fixes to dumplfs:

Add flags "-b" and "-I" to dumplfs, to allow the user to specify the
location of the superblock and Ifile inode, respectively.

Don't print "corrupt segment header" any more for leftover slivers of
space too close to the next segment to write a partial-segment.  In the
event that there was no such sliver, the segment still ends; recognize
this and print out the segment number, and superblock if asked.

Document all the flags in the man page.

Print the partial-segment write flags (SS_DIROP, SS_CONT).

Make the "-a" flag output look slightly better.

Change all hex numbers to lowercase, instead of having some upper and
some lower.

diffstat:

 usr.sbin/dumplfs/dumplfs.8 |   29 +++++++++-
 usr.sbin/dumplfs/dumplfs.c |  132 ++++++++++++++++++++++++++++----------------
 2 files changed, 111 insertions(+), 50 deletions(-)

diffs (truncated from 375 to 300 lines):

diff -r cf34254d3418 -r 2b113b2452e3 usr.sbin/dumplfs/dumplfs.8
--- a/usr.sbin/dumplfs/dumplfs.8        Wed Jun 14 01:52:41 2000 +0000
+++ b/usr.sbin/dumplfs/dumplfs.8        Wed Jun 14 01:55:37 2000 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: dumplfs.8,v 1.5 1999/04/20 07:15:38 mrg Exp $
+.\"    $NetBSD: dumplfs.8,v 1.6 2000/06/14 01:55:37 perseant Exp $
 .\"
 .\" Copyright (c) 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -33,7 +33,7 @@
 .\"
 .\"     @(#)dumplfs.8  8.1 (Berkeley) 6/18/93
 .\"
-.Dd June 18, 1993
+.Dd June 13, 2000
 .Dt DUMPLFS 8
 .Os
 .Sh NAME
@@ -41,6 +41,11 @@
 .Nd dump file system information
 .Sh SYNOPSIS
 .Nm dumplfs
+.Op Fl a
+.Op Fl b Ar blkno
+.Op Fl I Ar blkno
+.Op Fl i
+.Op Fl s Ar segno
 .Op Ar filesys No \&| Ar device
 .Sh DESCRIPTION
 .Nm Dumplfs
@@ -49,6 +54,26 @@
 The listing is very long and detailed.
 This command is useful mostly for finding out certain file system
 information such as the file system block size.
+.Pp
+The following flags are interpreted by
+.Nm dumplfs .
+.Bl -tag -width indent
+.It Fl a
+Dump the contents of all superblocks, not just the first.  Superblocks
+appear in the dumplfs output with the segment containing them.
+.It Fl b
+Use the block specified immediately after the flag as the super block for the
+filesystem.
+.It Fl I
+Use the block specified immediately after the flag as the inode block
+containing the index file inode.
+.It Fl i
+Dump information about the inode free list.
+.It Fl s
+Add the segment number immediately following the flag to a list of segments to
+dump.  This flag may be specified more than once to dump more than one segment.
+The default is to dump all segments.
+.El
 .Sh SEE ALSO
 .Xr fs 5 ,
 .Xr disktab 5 ,
diff -r cf34254d3418 -r 2b113b2452e3 usr.sbin/dumplfs/dumplfs.c
--- a/usr.sbin/dumplfs/dumplfs.c        Wed Jun 14 01:52:41 2000 +0000
+++ b/usr.sbin/dumplfs/dumplfs.c        Wed Jun 14 01:55:37 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dumplfs.c,v 1.13 1999/05/02 00:26:01 perseant Exp $    */
+/*     $NetBSD: dumplfs.c,v 1.14 2000/06/14 01:55:37 perseant Exp $    */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -45,7 +45,7 @@
 #if 0
 static char sccsid[] = "@(#)dumplfs.c  8.5 (Berkeley) 5/24/95";
 #else
-__RCSID("$NetBSD: dumplfs.c,v 1.13 1999/05/02 00:26:01 perseant Exp $");
+__RCSID("$NetBSD: dumplfs.c,v 1.14 2000/06/14 01:55:37 perseant Exp $");
 #endif
 #endif /* not lint */
 
@@ -70,7 +70,7 @@
 static void    addseg __P((char *));
 static void    dump_cleaner_info __P((struct lfs *, void *));
 static void    dump_dinode __P((struct dinode *));
-static void    dump_ifile __P((int, struct lfs *, int));
+static void    dump_ifile __P((int, struct lfs *, int, int));
 static int     dump_ipage_ifile __P((int, IFILE *, int));
 static int     dump_ipage_segusage __P((struct lfs *, int, IFILE *, int));
 static void    dump_segment __P((int, int, daddr_t, struct lfs *, int));
@@ -121,19 +121,27 @@
        char *argv[];
 {
        struct lfs lfs_sb1, lfs_sb2, *lfs_master;
-       daddr_t seg_addr;
+       daddr_t seg_addr, idaddr, sbdaddr;
        int ch, do_allsb, do_ientries, fd, segnum;
 
        do_allsb = 0;
        do_ientries = 0;
-       while ((ch = getopt(argc, argv, "ais:")) != -1)
+       idaddr = 0x0;
+       sbdaddr = 0x0;
+       while ((ch = getopt(argc, argv, "ab:iI:s:")) != -1)
                switch(ch) {
                case 'a':               /* Dump all superblocks */
                        do_allsb = 1;
                        break;
+               case 'b':               /* Use this superblock */
+                       sbdaddr = strtol(optarg, NULL, 0);
+                       break;
                case 'i':               /* Dump ifile entries */
                        do_ientries = 1;
                        break;
+               case 'I':               /* Use this ifile inode */
+                       idaddr = strtol(optarg, NULL, 0);
+                       break;
                case 's':               /* Dump out these segments */
                        addseg(optarg);
                        break;
@@ -150,26 +158,35 @@
        if ((fd = open(special, O_RDONLY, 0)) < 0)
                err(1, "%s", special);
 
-       /* Read the first superblock */
-       get(fd, LFS_LABELPAD, &(lfs_sb1.lfs_dlfs), sizeof(struct dlfs));
-       daddr_shift = lfs_sb1.lfs_bshift - lfs_sb1.lfs_fsbtodb;
-
-       /*
-        * Read the second superblock and figure out which check point is
-        * most up to date.
-        */
-       get(fd,
-           lfs_sb1.lfs_sboffs[1] << daddr_shift, &(lfs_sb2.lfs_dlfs), sizeof(struct dlfs));
-
-       lfs_master = &lfs_sb1;
-       if (lfs_sb1.lfs_tstamp > lfs_sb2.lfs_tstamp) {
-               lfs_master = &lfs_sb2;
+       if (sbdaddr == 0x0) {
+               /* Read the first superblock */
+               get(fd, LFS_LABELPAD, &(lfs_sb1.lfs_dlfs), sizeof(struct dlfs));
+               daddr_shift = lfs_sb1.lfs_bshift - lfs_sb1.lfs_fsbtodb;
+       
+               /*
+               * Read the second superblock and figure out which check point is
+               * most up to date.
+               */
+               get(fd,
+               lfs_sb1.lfs_sboffs[1] << daddr_shift, &(lfs_sb2.lfs_dlfs), sizeof(struct dlfs));
+       
+               lfs_master = &lfs_sb1;
+               if (lfs_sb1.lfs_tstamp > lfs_sb2.lfs_tstamp) {
+                       lfs_master = &lfs_sb2;
+                       sbdaddr = lfs_sb1.lfs_sboffs[1] << daddr_shift;
+               } else
+                       sbdaddr = btodb(LFS_LABELPAD);
+       } else {
+               /* Read the first superblock */
+               get(fd, dbtob(sbdaddr), &(lfs_sb1.lfs_dlfs), sizeof(struct dlfs));
+               daddr_shift = lfs_sb1.lfs_bshift - lfs_sb1.lfs_fsbtodb;
+               lfs_master = &lfs_sb1;
        }
 
-       (void)printf("Master Superblock at 0x%x:\n", (lfs_master==&lfs_sb1 ? (LFS_LABELPAD>>daddr_shift) : lfs_sb1.lfs_sboffs[1]));
+       (void)printf("Master Superblock at 0x%x:\n", sbdaddr);
        dump_super(lfs_master);
 
-       dump_ifile(fd, lfs_master, do_ientries);
+       dump_ifile(fd, lfs_master, do_ientries, idaddr);
 
        if (seglist != NULL)
                for (; seglist != NULL; seglist = seglist->next) {
@@ -195,18 +212,20 @@
  * printed out rather than making this code incredibly efficient.
  */
 static void
-dump_ifile(fd, lfsp, do_ientries)
+dump_ifile(fd, lfsp, do_ientries, addr)
        int fd;
        struct lfs *lfsp;
        int do_ientries;
+       daddr_t addr;
 {
        IFILE *ipage;
        struct dinode *dip, *dpage;
-       daddr_t addr, *addrp, *dindir, *iaddrp, *indir;
+       daddr_t *addrp, *dindir, *iaddrp, *indir;
        int block_limit, i, inum, j, nblocks, psize;
 
        psize = lfsp->lfs_bsize;
-       addr = lfsp->lfs_idaddr;
+       if (!addr)
+               addr = lfsp->lfs_idaddr;
 
        if (!(dpage = malloc(psize)))
                err(1, "malloc");
@@ -217,7 +236,8 @@
                        break;
 
        if (dip < dpage)
-               errx(1, "unable to locate ifile inode");
+               errx(1, "unable to locate ifile inode at disk address 0x%x",
+                    addr);
 
        (void)printf("\nIFILE inode\n");
        dump_dinode(dip);
@@ -385,12 +405,12 @@
        (void)printf("inum  %d\n", dip->di_inumber);
        (void)printf("Direct Addresses\n");
        for (i = 0; i < NDADDR; i++) {
-               (void)printf("\t0x%X", dip->di_db[i]);
+               (void)printf("\t0x%x", dip->di_db[i]);
                if ((i % 6) == 5)
                        (void)printf("\n");
        }
        for (i = 0; i < NIADDR; i++)
-               (void)printf("\t0x%X", dip->di_ib[i]);
+               (void)printf("\t0x%x", dip->di_ib[i]);
        (void)printf("\n");
 }
 
@@ -411,16 +431,22 @@
        if (sp->ss_magic != SS_MAGIC || 
            sp->ss_sumsum != (ck = cksum(&sp->ss_datasum, 
            LFS_SUMMARY_SIZE - sizeof(sp->ss_sumsum)))) {
-               (void)printf("dumplfs: %s %d address 0x%x\n",
-                   "corrupt summary block; segment", segnum, addr);
+               /* Don't print "corrupt" if we're just too close to the edge */
+               if (datosn(lfsp, addr + fsbtodb(lfsp, lfsp->lfs_bsize)) ==
+                   datosn(lfsp, addr))
+                       (void)printf("dumplfs: %s %d address 0x%x\n",
+                                    "corrupt summary block; segment", segnum,
+                                    addr);
                return(0);
        }
 
        (void)printf("Segment Summary Info at 0x%x\n", addr);
-       (void)printf("    %s0x%X\t%s%d\t%s%d\n    %s0x%X\t%s0x%X",
+       (void)printf("    %s0x%x\t%s%d\t%s%d\t%s%c%c\n    %s0x%x\t%s0x%x",
                "next     ", sp->ss_next,
                "nfinfo   ", sp->ss_nfinfo,
                "ninos    ", sp->ss_ninos,
+               "flags    ", (sp->ss_flags & SS_DIROP) ? 'D' : '-',
+                            (sp->ss_flags & SS_CONT)  ? 'C' : '-',
                "sumsum   ", sp->ss_sumsum,
                "datasum  ", sp->ss_datasum );
        (void)printf("\tcreate   %s", ctime((time_t *)&sp->ss_create));
@@ -433,7 +459,7 @@
        numbytes = 0;
        for (dp--, i = 0; i < sp->ss_ninos; dp--) {
                numbytes += lfsp->lfs_bsize;    /* add bytes for inode block */
-               printf("\t0x%X {", *dp);
+               printf("\t0x%x {", *dp);
                get(fd, *dp << (lfsp->lfs_bshift - lfsp->lfs_fsbtodb), inop, 
                    (1 << lfsp->lfs_bshift));
                for (j = 0; i < sp->ss_ninos && j < INOPB(lfsp); j++, i++) {
@@ -480,10 +506,13 @@
        SEGSUM *sump;
        char sumblock[LFS_SUMMARY_SIZE];
        int did_one, nbytes, sb;
-       off_t sum_offset, super_off = 0;
+       off_t sum_offset;
+       daddr_t new_addr;
 
-       (void)printf("\nSEGMENT %d (Disk Address 0x%X)\n",
-           addr >> (lfsp->lfs_segshift - daddr_shift), addr);
+       (void)printf("\nSEGMENT %d (Disk Address 0x%x)\n",
+           /* addr >> (lfsp->lfs_segshift - daddr_shift), */
+               datosn(lfsp, addr),
+               addr);
        sum_offset = (addr << (lfsp->lfs_bshift - lfsp->lfs_fsbtodb));
 
        sb = 0;
@@ -495,12 +524,19 @@
                        LFS_SUMMARY_SIZE - sizeof(sump->ss_sumsum))) {
                        sbp = (struct lfs *)sump;
                        if ((sb = (sbp->lfs_magic == LFS_MAGIC))) {
-                               super_off = sum_offset;
+                               if (dump_sb)  {
+                                       get(fd, sum_offset, &(lfs_sb.lfs_dlfs),
+                                           sizeof(struct dlfs));
+                                       (void)printf("\nSuperblock at 0x%x:\n",
+                                                  (unsigned)btodb(sum_offset));
+                                       dump_super(&lfs_sb);
+                                       (void)printf("%s","\n");
+                               }
                                sum_offset += LFS_SBPAD;
                        } else if (did_one)
                                break;
                        else {
-                               printf("Segment at 0x%X corrupt\n", addr);
+                               printf("Segment at 0x%x corrupt\n", addr);
                                break;
                        }
                } else {
@@ -512,12 +548,12 @@
                                sum_offset = 0;
                        did_one = 1;
                }
+               /* If the segment ends right on a boundary, it still ends */
+               new_addr = sum_offset >> (lfsp->lfs_bshift - lfsp->lfs_fsbtodb);
+               if (datosn(lfsp, new_addr) != datosn(lfsp, addr))
+                       break;
        } while (sum_offset);
 
-       if (dump_sb && sb)  {



Home | Main Index | Thread Index | Old Index