check for improper directory offsets; recover gracefully from read errors
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Fri, 31 May 1985 15:19:43 +0000 (07:19 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Fri, 31 May 1985 15:19:43 +0000 (07:19 -0800)
SCCS-vsn: sbin/fsck/Makefile 5.6
SCCS-vsn: sbin/fsck/dir.c 3.11
SCCS-vsn: sbin/fsck/fsck.h 3.4
SCCS-vsn: sbin/fsck/inode.c 3.11
SCCS-vsn: sbin/fsck/pass5.c 3.6
SCCS-vsn: sbin/fsck/setup.c 3.4
SCCS-vsn: sbin/fsck/utilities.c 3.6

usr/src/sbin/fsck/Makefile
usr/src/sbin/fsck/dir.c
usr/src/sbin/fsck/fsck.h
usr/src/sbin/fsck/inode.c
usr/src/sbin/fsck/pass5.c
usr/src/sbin/fsck/setup.c
usr/src/sbin/fsck/utilities.c

index 449bd96..6c9c22f 100644 (file)
@@ -1,8 +1,7 @@
-#      @(#)Makefile    5.5     (Berkeley)      85/02/08
+#      @(#)Makefile    5.6     (Berkeley)      85/05/31
 #
 DESTDIR=
 CFLAGS=        -O
 #
 DESTDIR=
 CFLAGS=        -O
-INCPATH= -I/usr/include/sys
 LFLAGS=        
 
 # The program itself
 LFLAGS=        
 
 # The program itself
@@ -30,13 +29,13 @@ ${PROG}: ${OBJS} ${HDRS}
        cc ${LFLAGS} -o ${PROG} ${OBJS}
 
 ${LOCOBJS}:
        cc ${LFLAGS} -o ${PROG} ${OBJS}
 
 ${LOCOBJS}:
-       cc ${CFLAGS} ${INCPATH} -c $*.c
+       cc ${CFLAGS} -c $*.c
 
 ufs_subr.o:
 
 ufs_subr.o:
-       cc ${CFLAGS} ${INCPATH} -c /sys/sys/ufs_subr.c
+       cc ${CFLAGS} -c /sys/sys/ufs_subr.c
 
 ufs_tables.o:
 
 ufs_tables.o:
-       cc ${CFLAGS} ${INCPATH} -c /sys/sys/ufs_tables.c
+       cc ${CFLAGS} -I/usr/include/sys -c /sys/sys/ufs_tables.c
 
 install: ${PROG}
        install ${PROG} ${DESTDIR}/etc/${PROG}
 
 install: ${PROG}
        install ${PROG} ${DESTDIR}/etc/${PROG}
index f9771ee..f1ec4b5 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char version[] = "@(#)dir.c     3.10 (Berkeley) %G%";
+static char version[] = "@(#)dir.c     3.11 (Berkeley) %G%";
 #endif
 
 #include <sys/param.h>
 #endif
 
 #include <sys/param.h>
index 44e4bf3..cdff7ec 100644 (file)
@@ -1,4 +1,4 @@
-/* @(#)fsck.h  3.3 (Berkeley) %G% */
+/* @(#)fsck.h  3.4 (Berkeley) %G% */
 
 #define        MAXDUP          10      /* limit on dup blks (per inode) */
 #define        MAXBAD          10      /* limit on bad blks (per inode) */
 
 #define        MAXDUP          10      /* limit on dup blks (per inode) */
 #define        MAXBAD          10      /* limit on bad blks (per inode) */
@@ -34,6 +34,7 @@ struct bufarea {
        struct bufarea  *b_next;                /* must be first */
        daddr_t b_bno;
        int     b_size;
        struct bufarea  *b_next;                /* must be first */
        daddr_t b_bno;
        int     b_size;
+       int     b_errs;
        union {
                char    b_buf[MAXBSIZE];        /* buffer space */
                short   b_lnks[SPERB];          /* link counts */
        union {
                char    b_buf[MAXBSIZE];        /* buffer space */
                short   b_lnks[SPERB];          /* link counts */
index a6c724f..990259c 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char version[] = "@(#)inode.c   3.10 (Berkeley) %G%";
+static char version[] = "@(#)inode.c   3.11 (Berkeley) %G%";
 #endif
 
 #include <pwd.h>
 #endif
 
 #include <pwd.h>
@@ -73,7 +73,8 @@ iblock(idesc, ilevel, isize)
        if (outrange(idesc->id_blkno, idesc->id_numfrags)) /* protect thyself */
                return (SKIP);
        initbarea(&ib);
        if (outrange(idesc->id_blkno, idesc->id_numfrags)) /* protect thyself */
                return (SKIP);
        initbarea(&ib);
-       if (getblk(&ib, idesc->id_blkno, sblock.fs_bsize) == NULL)
+       getblk(&ib, idesc->id_blkno, sblock.fs_bsize);
+       if (ib.b_errs != NULL)
                return (SKIP);
        ilevel--;
        for (sizepb = sblock.fs_bsize, i = 0; i < ilevel; i++)
                return (SKIP);
        ilevel--;
        for (sizepb = sblock.fs_bsize, i = 0; i < ilevel; i++)
@@ -147,15 +148,12 @@ ginode(inumber)
        daddr_t iblk;
        static ino_t startinum = 0;     /* blk num of first in raw area */
 
        daddr_t iblk;
        static ino_t startinum = 0;     /* blk num of first in raw area */
 
-
        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 (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 (getblk(&inoblk, iblk, sblock.fs_bsize) == NULL) {
-                       return (NULL);
-               }
+               getblk(&inoblk, iblk, sblock.fs_bsize);
                startinum = (inumber / INOPB(&sblock)) * INOPB(&sblock);
        }
        return (&inoblk.b_un.b_dinode[inumber % INOPB(&sblock)]);
                startinum = (inumber / INOPB(&sblock)) * INOPB(&sblock);
        }
        return (&inoblk.b_un.b_dinode[inumber % INOPB(&sblock)]);
index 7603e92..161c508 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char version[] = "@(#)pass5.c   3.5 (Berkeley) %G%";
+static char version[] = "@(#)pass5.c   3.6 (Berkeley) %G%";
 #endif
 
 #include <sys/param.h>
 #endif
 
 #include <sys/param.h>
@@ -29,8 +29,7 @@ pass5()
                (u_char *)cgrp.cg_iused;
        (void)time(&now);
        for (c = 0; c < sblock.fs_ncg; c++) {
                (u_char *)cgrp.cg_iused;
        (void)time(&now);
        for (c = 0; c < sblock.fs_ncg; c++) {
-               if (getblk(&cgblk, cgtod(&sblock, c), sblock.fs_cgsize) == 0)
-                       continue;
+               getblk(&cgblk, cgtod(&sblock, c), sblock.fs_cgsize);
                if (cgrp.cg_magic != CG_MAGIC)
                        pfatal("CG %d: BAD MAGIC NUMBER\n", c);
                dbase = cgbase(&sblock, c);
                if (cgrp.cg_magic != CG_MAGIC)
                        pfatal("CG %d: BAD MAGIC NUMBER\n", c);
                dbase = cgbase(&sblock, c);
index d851632..f5a3bd9 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char version[] = "@(#)setup.c   3.3 (Berkeley) %G%";
+static char version[] = "@(#)setup.c   3.4 (Berkeley) %G%";
 #endif
 
 #include <sys/param.h>
 #endif
 
 #include <sys/param.h>
@@ -65,7 +65,7 @@ setup(dev)
        /*
         * Read in the super block and its summary info.
         */
        /*
         * Read in the super block and its summary info.
         */
-       if (bread(&dfile, (char *)&sblock, super, (long)SBSIZE) == 0)
+       if (bread(&dfile, (char *)&sblock, super, (long)SBSIZE) != 0)
                return (0);
        sblk.b_bno = super;
        sblk.b_size = SBSIZE;
                return (0);
        sblk.b_bno = super;
        sblk.b_size = SBSIZE;
@@ -90,8 +90,8 @@ setup(dev)
         */
        if (bflag)
                goto sbok;
         */
        if (bflag)
                goto sbok;
-       if (getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1),
-           sblock.fs_sbsize) == 0)
+       getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
+       if (asblk.b_errs != NULL)
                return (0);
        altsblock.fs_link = sblock.fs_link;
        altsblock.fs_rlink = sblock.fs_rlink;
                return (0);
        altsblock.fs_link = sblock.fs_link;
        altsblock.fs_rlink = sblock.fs_rlink;
@@ -124,7 +124,7 @@ sbok:
                sblock.fs_csp[j] = (struct csum *)calloc(1, (unsigned)size);
                if (bread(&dfile, (char *)sblock.fs_csp[j],
                    fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
                sblock.fs_csp[j] = (struct csum *)calloc(1, (unsigned)size);
                if (bread(&dfile, (char *)sblock.fs_csp[j],
                    fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
-                   size) == 0)
+                   size) != 0)
                        return (0);
        }
        /*
                        return (0);
        }
        /*
index 45f0a65..82c7f75 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char version[] = "@(#)utilities.c       3.5 (Berkeley) %G%";
+static char version[] = "@(#)utilities.c       3.6 (Berkeley) %G%";
 #endif
 
 #include <stdio.h>
 #endif
 
 #include <stdio.h>
@@ -90,13 +90,10 @@ getblk(bp, blk, size)
        if (bp->b_bno == dblk)
                return (bp);
        flush(fcp, bp);
        if (bp->b_bno == dblk)
                return (bp);
        flush(fcp, bp);
-       if (bread(fcp, bp->b_un.b_buf, dblk, size) != 0) {
-               bp->b_bno = dblk;
-               bp->b_size = size;
-               return (bp);
-       }
-       bp->b_bno = (daddr_t)-1;
-       return (NULL);
+       bp->b_errs = bread(fcp, bp->b_un.b_buf, dblk, size);
+       bp->b_bno = dblk;
+       bp->b_size = size;
+       return (bp);
 }
 
 flush(fcp, bp)
 }
 
 flush(fcp, bp)
@@ -107,7 +104,10 @@ flush(fcp, bp)
 
        if (!bp->b_dirty)
                return;
 
        if (!bp->b_dirty)
                return;
+       if (bp->b_errs != 0)
+               pfatal("WRITING ZERO'ED BLOCK %d TO DISK\n", bp->b_bno);
        bp->b_dirty = 0;
        bp->b_dirty = 0;
+       bp->b_errs = 0;
        (void)bwrite(fcp, bp->b_un.b_buf, bp->b_bno, (long)bp->b_size);
        if (bp != &sblk)
                return;
        (void)bwrite(fcp, bp->b_un.b_buf, bp->b_bno, (long)bp->b_size);
        if (bp != &sblk)
                return;
@@ -153,12 +153,25 @@ bread(fcp, buf, blk, size)
        daddr_t blk;
        long size;
 {
        daddr_t blk;
        long size;
 {
+       char *cp;
+       int i, errs;
+
        if (lseek(fcp->rfdes, (long)dbtob(blk), 0) < 0)
                rwerr("SEEK", blk);
        else if (read(fcp->rfdes, buf, (int)size) == size)
        if (lseek(fcp->rfdes, (long)dbtob(blk), 0) < 0)
                rwerr("SEEK", blk);
        else if (read(fcp->rfdes, buf, (int)size) == size)
-               return (1);
+               return (0);
        rwerr("READ", blk);
        rwerr("READ", blk);
-       return (0);
+       if (lseek(fcp->rfdes, (long)dbtob(blk), 0) < 0)
+               rwerr("SEEK", blk);
+       errs = 0;
+       for (cp = buf, i = 0; i < size; i += DEV_BSIZE, cp += DEV_BSIZE) {
+               if (read(fcp->rfdes, cp, DEV_BSIZE) < 0) {
+                       bzero(cp, DEV_BSIZE);
+                       errs++;
+               }
+       }
+       pwarn("%d SECTORS REPLACED WITH ZERO'ED BLOCKS\n", errs);
+       return (errs);
 }
 
 bwrite(fcp, buf, blk, size)
 }
 
 bwrite(fcp, buf, blk, size)