Annotation of coherent/b/etc/fsck/main.c, revision 1.1.1.1

1.1       root        1: /*                                     
                      2:  * fsck  --  File System Check Program
                      3:  * an interactive file system check and repair program.
                      4:  *
                      5:  * Usage:
                      6:  *     /etc/fsck [-y] [-n] [-q] [-f] [-{sS}] [-t TMPFILE] [filesystem ...]
                      7:  *     audit and interactively repair inconsistent conditions for
                      8:  *     file systems.  Options -y and -n indicate an assumed response
                      9:  *     to all questions asked by fsck.  Default is to prompt operator
                     10:  *     for yes/no response.  Option -q is to quiet fsck from printing
                     11:  *     certain messages, i.e. no size check messages, unreferenced
                     12:  *     pipes will be silently removed, and counts in the superblock
                     13:  *     will be automatically fixed and free list salvaged, if necessary.
                     14:  *     Option -f is for a 'fast' check of the file system, i.e. only
                     15:  *     check blocks, sizes, superblock counts, and the free list.
                     16:  *     (-f) does not check pathnames, connectivity, or reference
                     17:  *     counts.  Option -s forces the reconstruction (or salvaging) of
                     18:  *     both the free inode list and the free block list, even if there
                     19:  *     are no file system problems.  This will reorder the free block
                     20:  *     list in the best order to limit additional fragmentation (respecting
                     21:  *     interleaving as well).  Note: Option -s will be ignored on mounted
                     22:  *     file systems.  The option -S acts in the same manner as -s except
                     23:  *     that it will not be ignored on mounted file systems.  Beware: -S
                     24:  *     on mounted file systems should only be used if you intend to reboot
                     25:  *     NO SYNC immediately afterwards.  Option -t sets the temporary file
                     26:  *     to use for disk caching of necessary tables on filesystems which are
                     27:  *     too big to do in core. The temporary file defaults to "/dev/rram1",
                     28:  *     which must be there.
                     29:  */
                     30: 
                     31: #include "fsck.h"
                     32: 
                     33: int    errflag;
                     34: 
                     35: int    mdaction;                       /* default action for invocation */
                     36: int    daction;                        /* default action for file system */
                     37: int    gSflag=FALSE;                   /* force salvage flag ignored mounted */
                     38: int    gsflag=FALSE;                   /* force salvage flag ignored mounted */
                     39: int    sflag=FALSE;                    /* force salvage flag   */
                     40: int    qflag=FALSE;                    /* fsck quiet flag      */
                     41: int    fflag=FALSE;                    /* fsck fast flag       */
                     42: 
                     43: char *tempFile = NULL;                 /* TMP file for virtual.c */
                     44: char *checklistfile = "/etc/checklist";        /* default file for list of file */
                     45:                                        /* systems to fsck. */
                     46: char *filelist[NFILSYS];               /* list of filesystems */
                     47: char word[MAXCH];                      /* hold single words */
                     48: char *fsname;                          /* file system name */
                     49: 
                     50: dev_t  rootdev;                        /* root device number */
                     51: dev_t  fsysrdev;                       /* file system real device number */
                     52: int    mounted;                        /* flag for mounted file system */
                     53: 
                     54: int    changeflg;                      /* file system modified flag */
                     55: 
                     56: main(argc, argv)
                     57: char *argv[];
                     58: {
                     59:        int yflag=0, nflag=0;
                     60:        int retval;
                     61: 
                     62:        while (argc>1 && *argv[1]=='-') {
                     63:                switch (argv[1][1]) {
                     64:                case 'q':
                     65:                        qflag = TRUE;
                     66:                        break;
                     67:                case 'y':
                     68:                        yflag = 1;
                     69:                        break;
                     70:                case 'n':
                     71:                        nflag = 1;
                     72:                        break;
                     73:                case 'f':
                     74:                        fflag = TRUE;
                     75:                        break;
                     76:                case 'S':
                     77:                        gSflag = TRUE;
                     78:                        break;
                     79:                case 's':
                     80:                        gsflag = TRUE;
                     81:                        break;
                     82:                case 't':
                     83:                        tempFile = argv[2];
                     84:                        argc--;
                     85:                        argv++;
                     86:                        break;
                     87:                default:
                     88:                        usage();
                     89:                        break;
                     90:                }
                     91:        
                     92:                argc--;
                     93:                argv++;
                     94:        }
                     95:        
                     96:        if ( yflag+nflag > 1 )
                     97:                usage();
                     98: 
                     99:        mdaction = ( yflag ? YES :
                    100:                    nflag ? NO : ASK );
                    101: 
                    102:        if ( argc > 1 )
                    103:                retval = allfsck(argv+1);
                    104:        else {
                    105:                getlist();
                    106:                retval = allfsck(filelist);
                    107:        }
                    108:        exit(retval);
                    109: }
                    110: 
                    111: 
                    112: /*
                    113:  *     perform fsck on each of the individual filesystem in list
                    114:  */
                    115: 
                    116: allfsck(fsl)
                    117: register char **fsl;
                    118: {
                    119:        int fatal();
                    120:        int retval = 0;
                    121: 
                    122:        sync();
                    123:        statit("/", fatal);
                    124:        rootdev = stats.st_dev;
                    125:        while (*fsl != NULL)
                    126:                retval |= fsck(*fsl++);
                    127:        return(retval);
                    128: }
                    129: 
                    130: /* 
                    131:  *     get the names of the filesystems from the default file
                    132:  *     checklistfile  (e.g. /etc/checklist)
                    133:  */
                    134: 
                    135: getlist()
                    136: {
                    137:        int fd;
                    138:        int index, size;
                    139: 
                    140:        if ( (fd = open(checklistfile, 0)) == (-1) )
                    141:                fatal("Can't open checklist file: %s", checklistfile);
                    142: 
                    143:        index = 0;
                    144:        while ( ((size = getword(fd)) != 0) && (index < NFILSYS) ) {
                    145:                 filelist[index] = malloc( size );
                    146:                strcpy(filelist[index++], word);
                    147:        }
                    148: 
                    149:        if (size != 0) 
                    150:                fatal("Too many file systems in checklist file: %s",
                    151:                                                        checklistfile);
                    152: 
                    153:        filelist[index] = NULL;
                    154: 
                    155:        close(fd);
                    156: }
                    157: 
                    158: /*
                    159:  *     read in the next "word" from file with descriptor fd
                    160:  *     return the length of the word.
                    161:  */
                    162: 
                    163: getword(fd)
                    164: int fd;
                    165: {
                    166:        int n = 0, num;
                    167:        char *cp = word;
                    168:        char ch;
                    169: 
                    170:        while ( ( (num=read(fd, &ch, 1)) == 1 ) &&
                    171:                ( (ch==' ')||(ch=='\t')||(ch=='\n')||(ch=='\r') ) );
                    172: 
                    173:        if (num != 1)
                    174:                return(0);
                    175: 
                    176:        do {
                    177:                *cp++ = ch;
                    178:        } while (  (++n < MAXCH) && (read(fd, &ch, 1) == 1) &&
                    179:                (ch != ' ') && (ch != '\t') && (ch != '\n') && (ch != '\r') );
                    180:        
                    181:        *cp = '\0';
                    182: 
                    183:        return(n+1);
                    184: }
                    185:        
                    186: /*
                    187:  *     perform fsck on the given filesystem
                    188:  */
                    189: fsck(name)
                    190: char *name;
                    191: {
                    192:        int retval = 1;
                    193:        int nonfatal();
                    194: 
                    195:        fsname = name;          /* file system name */
                    196:        errflag = FALSE;
                    197:        statit(fsname, nonfatal);
                    198:        fsysrdev = stats.st_rdev;
                    199:        if ( errflag )
                    200:                return(retval);
                    201:        changeflg = FALSE;
                    202:        init();
                    203:        if ( sflag = ((gsflag && !mounted) || gSflag) )
                    204:                printf("Switch \"-s\" selected to automatically rebuild free lists\n");
                    205:        if (!sflag && gsflag)
                    206:                printf("Ignoring \"-s\" on mounted file system\n");
                    207:        if ( !errflag ) {
                    208:                phase1();       /* check blocks and sizes */
                    209:                if ( !fflag ) {
                    210:                        phase2();       /* check pathnames        */
                    211:                        phase3();       /* check connectivity     */
                    212:                        phase4();       /* check reference counts */
                    213:                }
                    214:                phase5();       /* check free list        */
                    215:                phase6();       /* salvage free list      */
                    216:                retval = cleanup();
                    217:        }
                    218:        return(retval);
                    219: }
                    220: 
                    221: usage()
                    222: {
                    223:        printf("\
                    224: Usage: /etc/fsck [-y] [-n] [-q] [-f] [-{sS}] [-t TMPFILE] [filesystem ...]\n");
                    225:        _exit(1);
                    226: }

unix.superglobalmegacorp.com

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