add firewall check for bad entry in state map
[unix-history] / usr / src / sbin / fsck / pass1.c
index 0260336..c7ef655 100644 (file)
@@ -1,6 +1,12 @@
+/*
+ * 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
 #ifndef lint
-static char version[] = "@(#)pass1.c   3.3 (Berkeley) %G%";
-#endif
+static char sccsid[] = "@(#)pass1.c    5.1 (Berkeley) %G%";
+#endif not lint
 
 #include <sys/param.h>
 #include <sys/inode.h>
 
 #include <sys/param.h>
 #include <sys/inode.h>
@@ -15,6 +21,7 @@ pass1()
 {
        register int c, i, j;
        register DINODE *dp;
 {
        register int c, i, j;
        register DINODE *dp;
+       struct zlncnt *zlnp;
        int ndb, partial, cgd;
        struct inodesc idesc;
        ino_t inumber;
        int ndb, partial, cgd;
        struct inodesc idesc;
        ino_t inumber;
@@ -44,8 +51,7 @@ pass1()
                for (i = 0; i < sblock.fs_ipg; i++, inumber++) {
                        if (inumber < ROOTINO)
                                continue;
                for (i = 0; i < sblock.fs_ipg; i++, inumber++) {
                        if (inumber < ROOTINO)
                                continue;
-                       if ((dp = ginode(inumber)) == NULL)
-                               continue;
+                       dp = ginode(inumber);
                        if (!ALLOC(dp)) {
                                if (bcmp((char *)dp->di_db, (char *)zino.di_db,
                                        NDADDR * sizeof(daddr_t)) ||
                        if (!ALLOC(dp)) {
                                if (bcmp((char *)dp->di_db, (char *)zino.di_db,
                                        NDADDR * sizeof(daddr_t)) ||
@@ -97,28 +103,30 @@ pass1()
                        n_files++;
                        lncntp[inumber] = dp->di_nlink;
                        if (dp->di_nlink <= 0) {
                        n_files++;
                        lncntp[inumber] = dp->di_nlink;
                        if (dp->di_nlink <= 0) {
-                               if (badlnp < &badlncnt[MAXLNCNT])
-                                       *badlnp++ = inumber;
-                               else {
+                               zlnp = (struct zlncnt *)malloc(sizeof *zlnp);
+                               if (zlnp == NULL) {
                                        pfatal("LINK COUNT TABLE OVERFLOW");
                                        if (reply("CONTINUE") == 0)
                                                errexit("");
                                        pfatal("LINK COUNT TABLE OVERFLOW");
                                        if (reply("CONTINUE") == 0)
                                                errexit("");
+                               } else {
+                                       zlnp->zlncnt = inumber;
+                                       zlnp->next = zlnhead;
+                                       zlnhead = zlnp;
                                }
                        }
                        statemap[inumber] = DIRCT(dp) ? DSTATE : FSTATE;
                        badblk = dupblk = 0; maxblk = 0;
                        idesc.id_number = inumber;
                                }
                        }
                        statemap[inumber] = DIRCT(dp) ? DSTATE : FSTATE;
                        badblk = dupblk = 0; maxblk = 0;
                        idesc.id_number = inumber;
-                       idesc.id_filesize = 0;
                        (void)ckinode(dp, &idesc);
                        (void)ckinode(dp, &idesc);
-                       idesc.id_filesize *= btodb(sblock.fs_fsize);
-                       if (dp->di_blocks != idesc.id_filesize) {
+                       idesc.id_entryno *= btodb(sblock.fs_fsize);
+                       if (dp->di_blocks != idesc.id_entryno) {
                                pwarn("INCORRECT BLOCK COUNT I=%u (%ld should be %ld)",
                                pwarn("INCORRECT BLOCK COUNT I=%u (%ld should be %ld)",
-                                   inumber, dp->di_blocks, idesc.id_filesize);
+                                   inumber, dp->di_blocks, idesc.id_entryno);
                                if (preen)
                                        printf(" (CORRECTED)\n");
                                else if (reply("CORRECT") == 0)
                                        continue;
                                if (preen)
                                        printf(" (CORRECTED)\n");
                                else if (reply("CORRECT") == 0)
                                        continue;
-                               dp->di_blocks = idesc.id_filesize;
+                               dp->di_blocks = idesc.id_entryno;
                                inodirty();
                        }
                        continue;
                                inodirty();
                        }
                        continue;
@@ -135,10 +143,11 @@ pass1()
 pass1check(idesc)
        register struct inodesc *idesc;
 {
 pass1check(idesc)
        register struct inodesc *idesc;
 {
-       register daddr_t *dlp;
        int res = KEEPON;
        int anyout, nfrags;
        daddr_t blkno = idesc->id_blkno;
        int res = KEEPON;
        int anyout, nfrags;
        daddr_t blkno = idesc->id_blkno;
+       register struct dups *dlp;
+       struct dups *new;
 
        if ((anyout = outrange(blkno, idesc->id_numfrags)) != 0) {
                blkerr(idesc->id_number, "BAD", blkno);
 
        if ((anyout = outrange(blkno, idesc->id_numfrags)) != 0) {
                blkerr(idesc->id_number, "BAD", blkno);
@@ -169,23 +178,31 @@ pass1check(idesc)
                                        errexit("");
                                return (STOP);
                        }
                                        errexit("");
                                return (STOP);
                        }
-                       if (enddup >= &duplist[DUPTBLSIZE]) {
+                       new = (struct dups *)malloc(sizeof(struct dups));
+                       if (new == NULL) {
                                pfatal("DUP TABLE OVERFLOW.");
                                if (reply("CONTINUE") == 0)
                                        errexit("");
                                return (STOP);
                        }
                                pfatal("DUP TABLE OVERFLOW.");
                                if (reply("CONTINUE") == 0)
                                        errexit("");
                                return (STOP);
                        }
-                       for (dlp = duplist; dlp < muldup; dlp++)
-                               if (*dlp == blkno) {
-                                       *enddup++ = blkno;
-                                       break;
-                               }
-                       if (dlp >= muldup) {
-                               *enddup++ = *muldup;
-                               *muldup++ = blkno;
+                       new->dup = blkno;
+                       if (muldup == 0) {
+                               duplist = muldup = new;
+                               new->next = 0;
+                       } else {
+                               new->next = muldup->next;
+                               muldup->next = new;
                        }
                        }
+                       for (dlp = duplist; dlp != muldup; dlp = dlp->next)
+                               if (dlp->dup == blkno)
+                                       break;
+                       if (dlp == muldup && dlp->dup != blkno)
+                               muldup = new;
                }
                }
-               idesc->id_filesize++;
+               /*
+                * count the number of blocks found in id_entryno
+                */
+               idesc->id_entryno++;
        }
        return (res);
 }
        }
        return (res);
 }