missing fsbtodb!
[unix-history] / usr / src / sbin / fsck / pass1.c
index b34763f..3ecc82a 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.4 (Berkeley) %G%";
-#endif
+static char sccsid[] = "@(#)pass1.c    5.4 (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;
@@ -62,11 +69,18 @@ pass1()
                                continue;
                        }
                        lastino = inumber;
                                continue;
                        }
                        lastino = inumber;
-                       if (dp->di_size < 0) {
+                       if (dp->di_size < 0 ||
+                           dp->di_size + sblock.fs_bsize - 1 < 0) {
                                if (debug)
                                        printf("bad size %d:", dp->di_size);
                                goto unknown;
                        }
                                if (debug)
                                        printf("bad size %d:", dp->di_size);
                                goto unknown;
                        }
+                       if (!preen && (dp->di_mode & IFMT) == IFMT &&
+                           reply("HOLD BAD BLOCK") == 1) {
+                               dp->di_size = sblock.fs_fsize;
+                               dp->di_mode = IFREG|0600;
+                               inodirty();
+                       }
                        ndb = howmany(dp->di_size, sblock.fs_bsize);
                        if (SPECIAL(dp))
                                ndb++;
                        ndb = howmany(dp->di_size, sblock.fs_bsize);
                        if (SPECIAL(dp))
                                ndb++;
@@ -86,44 +100,43 @@ pass1()
                                                        dp->di_ib[j]);
                                        goto unknown;
                                }
                                                        dp->di_ib[j]);
                                        goto unknown;
                                }
-                       if (!preen && (dp->di_mode & IFMT) == IFMT &&
-                           reply("HOLD BAD BLOCK") == 1) {
-                               dp->di_size = sblock.fs_fsize;
-                               dp->di_mode = IFREG|0600;
-                               inodirty();
-                       } else if (ftypeok(dp) == 0)
+                       if (ftypeok(dp) == 0)
                                goto unknown;
                        n_files++;
                        lncntp[inumber] = dp->di_nlink;
                        if (dp->di_nlink <= 0) {
                                goto unknown;
                        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;
        unknown:
                        pfatal("UNKNOWN FILE TYPE I=%u", inumber);
                                inodirty();
                        }
                        continue;
        unknown:
                        pfatal("UNKNOWN FILE TYPE I=%u", inumber);
+                       statemap[inumber] = FCLEAR;
                        if (reply("CLEAR") == 1) {
                        if (reply("CLEAR") == 1) {
+                               statemap[inumber] = USTATE;
                                zapino(dp);
                                inodirty();
                        }
                                zapino(dp);
                                inodirty();
                        }
@@ -134,10 +147,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);
@@ -168,23 +182,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);
 }