Annotation of coherent/b/etc/fsck/phase5.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *     phase 5 of fsck - Check Free List
        !             3:  */
        !             4: 
        !             5: #include "fsck.h"
        !             6: 
        !             7: daddr_t        badcnt;                 /* Number of bad blocks in free list */
        !             8: daddr_t dupcnt;                        /* Number of dup blocks in free list */
        !             9: int    badflag;                /* Bad free list flag */
        !            10: int    fixerup;                /* Flag to salvage free list */
        !            11: 
        !            12: phase5()
        !            13: {
        !            14:        struct fblk *fbp;
        !            15:        unsigned size;
        !            16:        
        !            17:        if (!qflag)
        !            18:                printf("Phase 5 : Check Free List\n");
        !            19:        fbp = (struct fblk *) &sbp->s_nfree;
        !            20:        size = (unsigned) ((fsize+NBPC-1)/NBPC) * sizeof(char);
        !            21: #if SMALLMODEL
        !            22:        copyV(size);
        !            23: #else
        !            24:        memcpy(dupPtr, blockPtr, size);
        !            25: #endif
        !            26:        badcnt = dupcnt = 0;
        !            27:        badflag = FALSE;
        !            28:        freetrav(fbp);
        !            29:        fixerup = FALSE;
        !            30:        if (badflag || sflag) 
        !            31:                asksalvage();
        !            32: }
        !            33: 
        !            34: 
        !            35: #define        IGNORE  3               /* Return Possibilities from chk() */
        !            36: #define        ABORT   4               /* as well as perhaps GOOD and BAD */
        !            37: 
        !            38: freetrav(fbp)
        !            39: struct fblk *fbp;
        !            40: {
        !            41:        daddr_t total=0;
        !            42:        int i, flag;
        !            43: 
        !            44:        while ( fbp->df_nfree != 0 ) {
        !            45:                if ( (unsigned) fbp->df_nfree > NICFREE ) {
        !            46:                        badflag = TRUE;
        !            47:                        printf("Bad freeblock count.\n");
        !            48:                        break;
        !            49:                }
        !            50:                for (i=1; i<fbp->df_nfree; i++) {
        !            51:                        if ( (flag=chk(fbp->df_free[i])) == GOOD ) {
        !            52:                                total++;
        !            53:                                continue;
        !            54:                        }
        !            55:                        if (flag == BAD)
        !            56:                                continue;
        !            57:                        break;          /* break for IGNORE or ABORT    */
        !            58:                }
        !            59:                if ( (flag == IGNORE) || (flag == ABORT) )
        !            60:                        break;
        !            61:                if ( chk(fbp->df_free[0]) != GOOD )
        !            62:                        break;
        !            63:                total++;
        !            64:                bread(fbp->df_free[0], databuf);
        !            65:                fbp = (struct fblk *) databuf;
        !            66:                if ( !canfblk(fbp) ) {
        !            67:                        badflag = TRUE;
        !            68:                        printf("Bad freeblock count.\n");
        !            69:                        break;
        !            70:                }
        !            71:        }
        !            72: 
        !            73: #if 0
        !            74:        printf("Total traversed free blocks     = %lu\n", total);
        !            75:        printf("Total free blocks by Superblock = %lu\n", sbp->s_tfree);
        !            76:        printf("Running total free blocks       = %lu\n", totfree);
        !            77: #endif
        !            78: 
        !            79:        if ( flag == ABORT ) {          /* To Terminate fsck on this    */
        !            80:                badflag = FALSE;        /* File System, because of      */
        !            81:                return;                 /* excessive dup or bad blocks  */
        !            82:        }
        !            83: 
        !            84:        if ( sbp->s_tfree != totfree )
        !            85:                if ( !qflag || (daction==NO) ) {
        !            86:                        printf("Free Block count wrong in superblock.  ");
        !            87:                        if ( action(fixit) == TRUE ) {
        !            88:                                sbp->s_tfree = totfree;
        !            89:                                sbpfix = TRUE;
        !            90:                        }
        !            91:                } else if ( daction != NO ) {
        !            92:                        sbp->s_tfree = totfree;
        !            93:                        sbpfix = TRUE;
        !            94:                }
        !            95: 
        !            96:        report("%U Bad Block%s in Free List\n", badcnt);
        !            97:        report("%U Dup Block%s in Free List\n", dupcnt);
        !            98:        report("%U Block%s missing\n", totfree - total);
        !            99: 
        !           100: }
        !           101: 
        !           102: report(message, num)
        !           103: char *message;
        !           104: daddr_t num;
        !           105: {
        !           106:        if ( num != 0 ) {
        !           107:                if ( !qflag )
        !           108:                        printf(message, num, ( (num>1) ? "s" : "" ) );
        !           109:                badflag = TRUE;
        !           110:        }
        !           111: }
        !           112: 
        !           113: chk(bn)
        !           114: register daddr_t bn;
        !           115: {
        !           116:        if ( (bn<isize) || (bn>=fsize) ) {
        !           117:                badflag = TRUE;
        !           118:                if (++badcnt > MAXBADFREE) 
        !           119:                        return( stopit("bad") );
        !           120:                return(BAD);
        !           121:        }
        !           122: 
        !           123:        if ( testdup(bn) ) {
        !           124:                badflag = TRUE;
        !           125:                if (++dupcnt > MAXDUPFREE)
        !           126:                        return( stopit("dup") );
        !           127:                return(BAD);
        !           128:        } else {
        !           129:                markdup(bn);
        !           130:                return(GOOD);
        !           131:        }
        !           132: }
        !           133:                        
        !           134: stopit(type)
        !           135: char *type;
        !           136: {
        !           137:        printf("Excessive %s blocks in free list ", type);
        !           138:        if ( query("(Continue)") == YES )
        !           139:                return(IGNORE);
        !           140:        else
        !           141:                return(ABORT);
        !           142: }
        !           143:                
        !           144:                
        !           145: canfblk(fbp)
        !           146: register struct fblk *fbp;
        !           147: {
        !           148:        register short i;
        !           149: 
        !           150:        canshort(fbp->df_nfree);
        !           151:        if ( (unsigned) fbp->df_nfree > NICFREE )
        !           152:                return(FALSE);
        !           153: 
        !           154:        for (i=0; i<fbp->df_nfree; i++)
        !           155:                candaddr(fbp->df_free[i]);
        !           156:        return(TRUE);
        !           157: }
        !           158: 
        !           159: asksalvage()
        !           160: {
        !           161:        if ( (daction!=NO) && (qflag || sflag) ) {
        !           162:                fixerup = TRUE;
        !           163:                return;
        !           164:        }
        !           165:        if ( action("Bad Free List (SALVAGE)") )
        !           166:                fixerup = TRUE;
        !           167: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.