BSD 4_3_Tahoe release
[unix-history] / usr / src / etc / dump / dumptraverse.c
index 03d787c..e26da77 100644 (file)
@@ -1,27 +1,32 @@
-static char *sccsid = "@(#)dumptraverse.c      1.15 (Berkeley) 9/25/83";
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)dumptraverse.c     5.4 (Berkeley) 2/23/87";
+#endif not lint
 
 #include "dump.h"
 
 pass(fn, map)
 
 #include "dump.h"
 
 pass(fn, map)
-       int (*fn)();
-       char *map;
+       register int (*fn)();
+       register char *map;
 {
 {
-       struct dinode *dp;
-       int bits;
+       register int bits;
        ino_t maxino;
 
        maxino = sblock->fs_ipg * sblock->fs_ncg - 1;
        for (ino = 0; ino < maxino; ) {
        ino_t maxino;
 
        maxino = sblock->fs_ipg * sblock->fs_ncg - 1;
        for (ino = 0; ino < maxino; ) {
-               if((ino % NBBY) == 0) {
+               if ((ino % NBBY) == 0) {
                        bits = ~0;
                        bits = ~0;
-                       if(map != NULL)
+                       if (map != NULL)
                                bits = *map++;
                }
                ino++;
                                bits = *map++;
                }
                ino++;
-               if(bits & 1) {
-                       dp = getino(ino);
-                       (*fn)(dp);
-               }
+               if (bits & 1)
+                       (*fn)(getino(ino));
                bits >>= 1;
        }
 }
                bits >>= 1;
        }
 }
@@ -29,13 +34,14 @@ pass(fn, map)
 mark(ip)
        struct dinode *ip;
 {
 mark(ip)
        struct dinode *ip;
 {
-       register f;
+       register int f;
+       extern int anydskipped;
 
        f = ip->di_mode & IFMT;
 
        f = ip->di_mode & IFMT;
-       if(f == 0)
+       if (f == 0)
                return;
        BIS(ino, clrmap);
                return;
        BIS(ino, clrmap);
-       if(f == IFDIR)
+       if (f == IFDIR)
                BIS(ino, dirmap);
        if ((ip->di_mtime >= spcl.c_ddate || ip->di_ctime >= spcl.c_ddate) &&
            !BIT(ino, nodmap)) {
                BIS(ino, dirmap);
        if ((ip->di_mtime >= spcl.c_ddate || ip->di_ctime >= spcl.c_ddate) &&
            !BIT(ino, nodmap)) {
@@ -45,7 +51,8 @@ mark(ip)
                        return;
                }
                est(ip);
                        return;
                }
                est(ip);
-       }
+       } else if (f == IFDIR)
+               anydskipped = 1;
 }
 
 add(ip)
 }
 
 add(ip)
@@ -105,6 +112,15 @@ indir(d, n, filesize)
        }
 }
 
        }
 }
 
+dirdump(ip)
+       struct dinode *ip;
+{
+       /* watchout for dir inodes deleted and maybe reallocated */
+       if ((ip->di_mode & IFMT) != IFDIR)
+               return;
+       dump(ip);
+}
+
 dump(ip)
        struct dinode *ip;
 {
 dump(ip)
        struct dinode *ip;
 {
@@ -120,6 +136,8 @@ dump(ip)
        spcl.c_type = TS_INODE;
        spcl.c_count = 0;
        i = ip->di_mode & IFMT;
        spcl.c_type = TS_INODE;
        spcl.c_count = 0;
        i = ip->di_mode & IFMT;
+       if (i == 0) /* free inode */
+               return;
        if ((i != IFDIR && i != IFREG && i != IFLNK) || ip->di_size == 0) {
                spclrec();
                return;
        if ((i != IFDIR && i != IFREG && i != IFLNK) || ip->di_size == 0) {
                spclrec();
                return;
@@ -203,18 +221,11 @@ blksout(blkp, frags)
 bitmap(map, typ)
        char *map;
 {
 bitmap(map, typ)
        char *map;
 {
-       register i, n;
+       register i;
        char *cp;
 
        char *cp;
 
-       n = -1;
-       for (i = 0; i < msiz; i++)
-               if(map[i])
-                       n = i;
-       if (n < 0)
-               return;
-       n++;
        spcl.c_type = typ;
        spcl.c_type = typ;
-       spcl.c_count = howmany(n * sizeof(map[0]), TP_BSIZE);
+       spcl.c_count = howmany(msiz * sizeof(map[0]), TP_BSIZE);
        spclrec();
        for (i = 0, cp = map; i < spcl.c_count; i++, cp += TP_BSIZE)
                taprec(cp);
        spclrec();
        for (i = 0, cp = map; i < spcl.c_count; i++, cp += TP_BSIZE)
                taprec(cp);
@@ -229,8 +240,11 @@ spclrec()
        spcl.c_checksum = 0;
        ip = (int *)&spcl;
        s = 0;
        spcl.c_checksum = 0;
        ip = (int *)&spcl;
        s = 0;
-       for(i = 0; i < sizeof(union u_spcl)/sizeof(int); i++)
-               s += *ip++;
+       i = sizeof(union u_spcl) / (4*sizeof(int));
+       while (--i >= 0) {
+               s += *ip++; s += *ip++;
+               s += *ip++; s += *ip++;
+       }
        spcl.c_checksum = CHECKSUM - s;
        taprec((char *)&spcl);
 }
        spcl.c_checksum = CHECKSUM - s;
        taprec((char *)&spcl);
 }
@@ -299,24 +313,24 @@ bread(da, ba, cnt)
        int n;
 
 loop:
        int n;
 
 loop:
-       if (lseek(fi, (long)(da * DEV_BSIZE), 0) < 0){
+       if (lseek(fi, (long)(da * dev_bsize), 0) < 0){
                msg("bread: lseek fails\n");
        }
        n = read(fi, ba, cnt);
        if (n == cnt)
                return;
                msg("bread: lseek fails\n");
        }
        n = read(fi, ba, cnt);
        if (n == cnt)
                return;
-       if (da + (cnt / DEV_BSIZE) > fsbtodb(sblock, sblock->fs_size)) {
+       if (da + (cnt / dev_bsize) > fsbtodb(sblock, sblock->fs_size)) {
                /*
                 * Trying to read the final fragment.
                 *
                 * NB - dump only works in TP_BSIZE blocks, hence
                /*
                 * Trying to read the final fragment.
                 *
                 * NB - dump only works in TP_BSIZE blocks, hence
-                * rounds DEV_BSIZE fragments up to TP_BSIZE pieces.
+                * rounds `dev_bsize' fragments up to TP_BSIZE pieces.
                 * It should be smarter about not actually trying to
                 * read more than it can get, but for the time being
                 * we punt and scale back the read only when it gets
                 * us into trouble. (mkm 9/25/83)
                 */
                 * It should be smarter about not actually trying to
                 * read more than it can get, but for the time being
                 * we punt and scale back the read only when it gets
                 * us into trouble. (mkm 9/25/83)
                 */
-               cnt -= DEV_BSIZE;
+               cnt -= dev_bsize;
                goto loop;
        }
        msg("(This should not happen)bread from %s [block %d]: count=%d, got=%d\n",
                goto loop;
        }
        msg("(This should not happen)bread from %s [block %d]: count=%d, got=%d\n",