ginode() succeeds or exits
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Tue, 12 Feb 1985 10:29:30 +0000 (02:29 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Tue, 12 Feb 1985 10:29:30 +0000 (02:29 -0800)
SCCS-vsn: sbin/fsck/dir.c 3.4
SCCS-vsn: sbin/fsck/inode.c 3.4
SCCS-vsn: sbin/fsck/pass1.c 3.4
SCCS-vsn: sbin/fsck/pass2.c 3.4
SCCS-vsn: sbin/fsck/pass3.c 3.3

usr/src/sbin/fsck/dir.c
usr/src/sbin/fsck/inode.c
usr/src/sbin/fsck/pass1.c
usr/src/sbin/fsck/pass2.c
usr/src/sbin/fsck/pass3.c

index d9f5136..d697dca 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char version[] = "@(#)dir.c     3.3 (Berkeley) %G%";
+static char version[] = "@(#)dir.c     3.4 (Berkeley) %G%";
 #endif
 
 #include <sys/param.h>
 #endif
 
 #include <sys/param.h>
@@ -28,8 +28,7 @@ descend(parentino, inumber)
        if (statemap[inumber] != DSTATE)
                errexit("BAD INODE %d TO DESCEND", statemap[inumber]);
        statemap[inumber] = DFOUND;
        if (statemap[inumber] != DSTATE)
                errexit("BAD INODE %d TO DESCEND", statemap[inumber]);
        statemap[inumber] = DFOUND;
-       if ((dp = ginode(inumber)) == NULL)
-               return;
+       dp = ginode(inumber);
        if (dp->di_size == 0) {
                direrr(inumber, "ZERO LENGTH DIRECTORY");
                if (reply("REMOVE") == 1)
        if (dp->di_size == 0) {
                direrr(inumber, "ZERO LENGTH DIRECTORY");
                if (reply("REMOVE") == 1)
@@ -176,7 +175,12 @@ direrr(ino, s)
        pwarn("%s ", s);
        pinode(ino);
        printf("\n");
        pwarn("%s ", s);
        pinode(ino);
        printf("\n");
-       if ((dp = ginode(ino)) != NULL && ftypeok(dp))
+       if (ino < ROOTINO || ino > imax) {
+               pfatal("NAME=%s\n", pathname);
+               return;
+       }
+       dp = ginode(ino);
+       if (ftypeok(dp))
                pfatal("%s=%s\n", DIRCT(dp) ? "DIR" : "FILE", pathname);
        else
                pfatal("NAME=%s\n", pathname);
                pfatal("%s=%s\n", DIRCT(dp) ? "DIR" : "FILE", pathname);
        else
                pfatal("NAME=%s\n", pathname);
@@ -188,8 +192,7 @@ adjust(idesc, lcnt)
 {
        register DINODE *dp;
 
 {
        register DINODE *dp;
 
-       if ((dp = ginode(idesc->id_number)) == NULL)
-               return;
+       dp = ginode(idesc->id_number);
        if (dp->di_nlink == lcnt) {
                if (linkup(idesc->id_number, (ino_t)0) == 0)
                        clri(idesc, "UNREF", 0);
        if (dp->di_nlink == lcnt) {
                if (linkup(idesc->id_number, (ino_t)0) == 0)
                        clri(idesc, "UNREF", 0);
@@ -259,8 +262,7 @@ linkup(orphan, pdir)
        struct inodesc idesc;
 
        bzero((char *)&idesc, sizeof(struct inodesc));
        struct inodesc idesc;
 
        bzero((char *)&idesc, sizeof(struct inodesc));
-       if ((dp = ginode(orphan)) == NULL)
-               return (0);
+       dp = ginode(orphan);
        lostdir = DIRCT(dp);
        pwarn("UNREF %s ", lostdir ? "DIR" : "FILE");
        pinode(orphan);
        lostdir = DIRCT(dp);
        pwarn("UNREF %s ", lostdir ? "DIR" : "FILE");
        pinode(orphan);
@@ -275,22 +277,24 @@ linkup(orphan, pdir)
        *pathp++ = '/';
        *pathp = '\0';
        if (lfdir == 0) {
        *pathp++ = '/';
        *pathp = '\0';
        if (lfdir == 0) {
-               if ((dp = ginode(ROOTINO)) == NULL)
-                       return (0);
+               dp = ginode(ROOTINO);
                idesc.id_name = lfname;
                idesc.id_type = DATA;
                idesc.id_func = findino;
                idesc.id_number = ROOTINO;
                idesc.id_filesize = dp->di_size;
                (void)ckinode(dp, &idesc);
                idesc.id_name = lfname;
                idesc.id_type = DATA;
                idesc.id_func = findino;
                idesc.id_number = ROOTINO;
                idesc.id_filesize = dp->di_size;
                (void)ckinode(dp, &idesc);
-               if ((lfdir = idesc.id_parent) == 0) {
+               lfdir = idesc.id_parent;
+               if (lfdir < ROOTINO || lfdir > imax)
+                       lfdir = 0;
+               if (lfdir == 0) {
                        pfatal("SORRY. NO lost+found DIRECTORY");
                        printf("\n\n");
                        return (0);
                }
        }
                        pfatal("SORRY. NO lost+found DIRECTORY");
                        printf("\n\n");
                        return (0);
                }
        }
-       if ((dp = ginode(lfdir)) == NULL ||
-            !DIRCT(dp) || statemap[lfdir] != DFOUND) {
+       dp = ginode(lfdir);
+       if (!DIRCT(dp) || statemap[lfdir] != DFOUND) {
                pfatal("SORRY. NO lost+found DIRECTORY");
                printf("\n\n");
                return (0);
                pfatal("SORRY. NO lost+found DIRECTORY");
                printf("\n\n");
                return (0);
@@ -324,11 +328,10 @@ linkup(orphan, pdir)
                idesc.id_filesize = dp->di_size;
                idesc.id_fix = DONTKNOW;
                (void)ckinode(dp, &idesc);
                idesc.id_filesize = dp->di_size;
                idesc.id_fix = DONTKNOW;
                (void)ckinode(dp, &idesc);
-               if ((dp = ginode(lfdir)) != NULL) {
-                       dp->di_nlink++;
-                       inodirty();
-                       lncntp[lfdir]++;
-               }
+               dp = ginode(lfdir);
+               dp->di_nlink++;
+               inodirty();
+               lncntp[lfdir]++;
                pwarn("DIR I=%u CONNECTED. ", orphan);
                printf("PARENT WAS I=%u\n", pdir);
                if (preen == 0)
                pwarn("DIR I=%u CONNECTED. ", orphan);
                printf("PARENT WAS I=%u\n", pdir);
                if (preen == 0)
index 2a5c070..77c8c64 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char version[] = "@(#)inode.c   3.3 (Berkeley) %G%";
+static char version[] = "@(#)inode.c   3.4 (Berkeley) %G%";
 #endif
 
 #include <sys/param.h>
 #endif
 
 #include <sys/param.h>
@@ -133,11 +133,8 @@ ginode(inumber)
        static ino_t startinum = 0;     /* blk num of first in raw area */
 
 
        static ino_t startinum = 0;     /* blk num of first in raw area */
 
 
-       if (inumber < ROOTINO || inumber > imax) {
-               if (debug && inumber > imax)
-                       printf("inumber out of range (%d)\n", inumber);
-               return (NULL);
-       }
+       if (inumber < ROOTINO || inumber > imax)
+               errexit("bad inode number %d to ginode\n", inumber);
        if (startinum == 0 ||
            inumber < startinum || inumber >= startinum + INOPB(&sblock)) {
                iblk = itod(&sblock, inumber);
        if (startinum == 0 ||
            inumber < startinum || inumber >= startinum + INOPB(&sblock)) {
                iblk = itod(&sblock, inumber);
@@ -156,8 +153,7 @@ clri(idesc, s, flg)
 {
        register DINODE *dp;
 
 {
        register DINODE *dp;
 
-       if ((dp = ginode(idesc->id_number)) == NULL)
-               return;
+       dp = ginode(idesc->id_number);
        if (flg == 1) {
                pwarn("%s %s", s, DIRCT(dp) ? "DIR" : "FILE");
                pinode(idesc->id_number);
        if (flg == 1) {
                pwarn("%s %s", s, DIRCT(dp) ? "DIR" : "FILE");
                pinode(idesc->id_number);
@@ -197,8 +193,9 @@ pinode(ino)
        char *ctime();
 
        printf(" I=%u ", ino);
        char *ctime();
 
        printf(" I=%u ", ino);
-       if ((dp = ginode(ino)) == NULL)
+       if (ino < ROOTINO || ino > imax)
                return;
                return;
+       dp = ginode(ino);
        printf(" OWNER=");
        if (getpw((int)dp->di_uid, uidbuf) == 0) {
                for (p = uidbuf; *p != ':'; p++);
        printf(" OWNER=");
        if (getpw((int)dp->di_uid, uidbuf) == 0) {
                for (p = uidbuf; *p != ':'; p++);
index 0260336..b34763f 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char version[] = "@(#)pass1.c   3.3 (Berkeley) %G%";
+static char version[] = "@(#)pass1.c   3.4 (Berkeley) %G%";
 #endif
 
 #include <sys/param.h>
 #endif
 
 #include <sys/param.h>
@@ -44,8 +44,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)) ||
index f2a10fc..1e0d7fc 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char version[] = "@(#)pass2.c   3.3 (Berkeley) %G%";
+static char version[] = "@(#)pass2.c   3.4 (Berkeley) %G%";
 #endif
 
 #include <sys/param.h>
 #endif
 
 #include <sys/param.h>
@@ -29,8 +29,9 @@ pass2()
        case FSTATE:
        case FCLEAR:
                pfatal("ROOT INODE NOT DIRECTORY");
        case FSTATE:
        case FCLEAR:
                pfatal("ROOT INODE NOT DIRECTORY");
-               if (reply("FIX") == 0 || (dp = ginode(ROOTINO)) == NULL)
+               if (reply("FIX") == 0)
                        errexit("");
                        errexit("");
+               dp = ginode(ROOTINO);
                dp->di_mode &= ~IFMT;
                dp->di_mode |= IFDIR;
                inodirty();
                dp->di_mode &= ~IFMT;
                dp->di_mode |= IFDIR;
                inodirty();
@@ -191,8 +192,7 @@ again:
                        direrr(dirp->d_ino, "DUP/BAD");
                        if ((n = reply("REMOVE")) == 1)
                                break;
                        direrr(dirp->d_ino, "DUP/BAD");
                        if ((n = reply("REMOVE")) == 1)
                                break;
-                       if ((dp = ginode(dirp->d_ino)) == NULL)
-                               break;
+                       dp = ginode(dirp->d_ino);
                        statemap[dirp->d_ino] = DIRCT(dp) ? DSTATE : FSTATE;
                        goto again;
 
                        statemap[dirp->d_ino] = DIRCT(dp) ? DSTATE : FSTATE;
                        goto again;
 
index f4d0e46..2e61fd7 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char version[] = "@(#)pass3.c   3.2 (Berkeley) %G%";
+static char version[] = "@(#)pass3.c   3.3 (Berkeley) %G%";
 #endif
 
 #include <sys/param.h>
 #endif
 
 #include <sys/param.h>
@@ -29,8 +29,9 @@ pass3()
                        loopcnt = 0;
                        do {
                                orphan = idesc.id_parent;
                        loopcnt = 0;
                        do {
                                orphan = idesc.id_parent;
-                               if ((dp = ginode(orphan)) == NULL)
+                               if (orphan < ROOTINO || orphan > imax)
                                        break;
                                        break;
+                               dp = ginode(orphan);
                                idesc.id_parent = 0;
                                idesc.id_filesize = dp->di_size;
                                idesc.id_number = orphan;
                                idesc.id_parent = 0;
                                idesc.id_filesize = dp->di_size;
                                idesc.id_number = orphan;