Annotation of coherent/d/bin/check/check.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * check -- check all of the normally-used filesystems
        !             3:  * or those specified by calling `icheck' and `dcheck'.
        !             4:  * If `-s' is specified, also try to correct any
        !             5:  * problems encountered in any of these filesystems.
        !             6:  */
        !             7: 
        !             8: /*
        !             9: 
        !            10: return '-2' (254) if an internal error occurred; '-1' (255) if
        !            11: there are unfixed errors; '0' if no errors were found; and '1'
        !            12: if errors were found, but fixed (system should then be rebooted).
        !            13: 
        !            14: */
        !            15: 
        !            16: #include <stdio.h>
        !            17: #include "check.h"
        !            18: 
        !            19: char   icheck[] = "/bin/icheck";
        !            20: char   dcheck[] = "/bin/dcheck";
        !            21: char   fixopt[] = "-s";
        !            22: 
        !            23: int    sflag;
        !            24: 
        !            25: main(argc, argv)
        !            26: char *argv[];
        !            27: {
        !            28:        register estat = 0;
        !            29:        register char **fsp;
        !            30: 
        !            31:        if (argc>1 && *argv[1]=='-') {
        !            32:                if (argv[1][1]=='s' && argv[1][2]=='\0')
        !            33:                        sflag = 1;
        !            34:                else
        !            35:                        usage();
        !            36:                argv++;
        !            37:                argc--;
        !            38:        }
        !            39:        if (argc > 1)
        !            40:                fsp = &argv[1];
        !            41:        else
        !            42:                usage();
        !            43:        while (*fsp != NULL)
        !            44:                estat |= check(*fsp++);
        !            45:        exit(estat);
        !            46: }
        !            47: 
        !            48: /*
        !            49:  * Do check for a single filesystem.
        !            50:  */
        !            51: check(fs)
        !            52: char *fs;
        !            53: {
        !            54:        register int ierror, derror;
        !            55:        register int bad = 0;
        !            56: 
        !            57:        if (ierror = run(icheck, fs, NULL))
        !            58:                bad |= 1;
        !            59:        if (derror = run(dcheck, fs, NULL))
        !            60:                bad |= 1;
        !            61:        if (sflag) {
        !            62:                if ((ierror & ~IC_FIX) == 0) {
        !            63:                        if (derror & ~DC_FIX)
        !            64:                                return(-1);
        !            65:                        if (derror & DC_FIX) {
        !            66:                                if (derror = run(dcheck, fixopt, fs, NULL))
        !            67:                                        return(-1);
        !            68:                                ierror = IC_MISS;       /*force fixup icheck*/
        !            69:                        }
        !            70:                        if (ierror & IC_FIX)
        !            71:                                if (ierror = run(icheck, fixopt, fs, NULL))
        !            72:                                        return(-1);
        !            73:                } else
        !            74:                        return(-1);
        !            75:        }
        !            76:        return (bad);
        !            77: }
        !            78: 
        !            79: /*
        !            80:  * Do a command -- either icheck or dcheck normally.
        !            81:  */
        !            82: /* VARARGS */
        !            83: run(command, args)
        !            84: char *command;
        !            85: {
        !            86:        register int pid;
        !            87:        int status;
        !            88: 
        !            89:        if ((pid = fork()) < 0) {
        !            90:                fprintf(stderr, "check: try again\n");
        !            91:                exit(-2);
        !            92:        }
        !            93:        if (pid) {
        !            94:                wait(&status);
        !            95:                if ((status&0377) != 0)
        !            96:                        return(-2);
        !            97:                return ((status>>8)&0377);
        !            98:        } else {
        !            99:                execv(command, &command);
        !           100:                fprintf(stderr, "check: someone moved %s\n", command);
        !           101:                exit(-2);
        !           102:        }
        !           103:        /* NOTREACHED */
        !           104: }
        !           105: 
        !           106: usage()
        !           107: {
        !           108:        fprintf(stderr, "Usage: check [-s] filesystem [ ... ]\n");
        !           109:        exit(-2);
        !           110: }

unix.superglobalmegacorp.com

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