Annotation of researchv10no/libc/gen/fstab.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * crack /etc/fstab; for mount, fsck, et al
        !             3:  */
        !             4: 
        !             5: #include <fstab.h>
        !             6: #include <stdio.h>
        !             7: #include <ctype.h>
        !             8: #include <string.h>
        !             9: 
        !            10: static struct  fstab fs;
        !            11: static FILE    *fs_file = 0;
        !            12: 
        !            13: static int
        !            14: fstabscan(fsp)
        !            15: register struct        fstab *fsp;
        !            16: {
        !            17:        char *args[FSTABNARGS];
        !            18:        char buf[256];
        !            19: 
        !            20: again:
        !            21:        if (fgets(buf, sizeof(buf), fs_file) == NULL)
        !            22:                return(0);
        !            23:        buf[strlen(buf)-1] = 0; /* discard \n */
        !            24:        setfields(":");
        !            25:        if (getfields(buf, args, FSTABNARGS) != FSTABNARGS)
        !            26:                goto again;
        !            27:        strcpy(fsp->fs_spec, args[0]);
        !            28:        strcpy(fsp->fs_file, args[1]);
        !            29:        if (isdigit(args[2][0]) || args[2][0] == '-') {
        !            30:                fsp->fs_ftype = atoi(args[2]);
        !            31:                fsp->fs_flags = atoi(args[3]);
        !            32:        } else if (strcmp(args[2], "rw") == 0) {
        !            33:                fsp->fs_ftype = 0;
        !            34:                fsp->fs_flags = 0;
        !            35:        } else if (strcmp(args[2], "ro") == 0) {
        !            36:                fsp->fs_ftype = 0;
        !            37:                fsp->fs_flags = 1;
        !            38:        } else if (strcmp(args[2], "sw") == 0) {
        !            39:                fsp->fs_ftype = FSSWAP;
        !            40:                fsp->fs_flags = 0;
        !            41:        } else {
        !            42:                fsp->fs_ftype = FSNONE;
        !            43:                fsp->fs_flags = 0;
        !            44:        }
        !            45:        fsp->fs_passno = atoi(args[4]);
        !            46:        return (1);
        !            47: }
        !            48:        
        !            49: int
        !            50: setfsent()
        !            51: {
        !            52:        if (fs_file)
        !            53:                endfsent();
        !            54:        if ((fs_file = fopen(FSTAB, "r")) == NULL)
        !            55:                return(0);
        !            56:        return(1);
        !            57: }
        !            58: 
        !            59: int endfsent()
        !            60: {
        !            61:        if (fs_file)
        !            62:                fclose(fs_file);
        !            63:        return(1);
        !            64: }
        !            65: 
        !            66: struct fstab *
        !            67: getfsent()
        !            68: {
        !            69: 
        !            70:        if ((fs_file == 0) && (setfsent() == 0))
        !            71:                return(0);
        !            72:        if (fstabscan(&fs) == 0)
        !            73:                return (0);
        !            74:        return (&fs);
        !            75: }
        !            76: 
        !            77: struct fstab *
        !            78: getfsspec(name)
        !            79: char   *name;
        !            80: {
        !            81:        register struct fstab *fsp;
        !            82: 
        !            83:        if (setfsent() == 0)    /* start from the beginning */
        !            84:                return(0);
        !            85:        while((fsp = getfsent()) != 0){
        !            86:                if (strcmp(fsp->fs_spec, name) == 0)
        !            87:                        return(fsp);
        !            88:        }
        !            89:        return(0);
        !            90: }
        !            91: 
        !            92: struct fstab *
        !            93: getfsfile(name)
        !            94:        char    *name;
        !            95: {
        !            96:        register struct fstab *fsp;
        !            97: 
        !            98:        if (setfsent() == 0)    /* start from the beginning */
        !            99:                return(0);
        !           100:        while ((fsp = getfsent()) != 0){
        !           101:                if (strcmp(fsp->fs_file, name) == 0)
        !           102:                        return(fsp);
        !           103:        }
        !           104:        return(0);
        !           105: }

unix.superglobalmegacorp.com

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