Annotation of 3BSD/cmd/mount.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: 
                      3: #define        NMOUNT  16
                      4: #define        NAMSIZ  32
                      5: 
                      6: struct mtab {
                      7:        char    file[NAMSIZ];
                      8:        char    spec[NAMSIZ];
                      9: } mtab[NMOUNT];
                     10: 
                     11: main(argc, argv)
                     12: char **argv;
                     13: {
                     14:        register int ro;
                     15:        register struct mtab *mp;
                     16:        register char *np;
                     17:        int mf;
                     18: 
                     19:        mf = open("/etc/mtab", 0);
                     20:        read(mf, (char *)mtab, NMOUNT*2*NAMSIZ);
                     21:        if (argc==1) {
                     22:                for (mp = mtab; mp < &mtab[NMOUNT]; mp++)
                     23:                        if (mp->file[0])
                     24:                                printf("%s on %s\n", mp->spec, mp->file);
                     25:                exit(0);
                     26:        }
                     27:        if(argc < 3) {
                     28:                fprintf(stderr,"arg count\n");
                     29:                exit(1);
                     30:        }
                     31:        ro = 0;
                     32:        if(argc > 3)
                     33:                ro++;
                     34:        if(mount(argv[1], argv[2], ro) < 0) {
                     35:                perror("mount");
                     36:                exit(1);
                     37:        }
                     38:        np = argv[1];
                     39:        while(*np++)
                     40:                ;
                     41:        np--;
                     42:        while(*--np == '/')
                     43:                *np = '\0';
                     44:        while(np > argv[1] && *--np != '/')
                     45:                ;
                     46:        if(*np == '/')
                     47:                np++;
                     48:        argv[1] = np;
                     49:        for (mp = mtab; mp < &mtab[NMOUNT]; mp++) {
                     50:                if (mp->file[0] == 0) {
                     51:                        for (np = mp->spec; np < &mp->spec[NAMSIZ-1];)
                     52:                                if ((*np++ = *argv[1]++) == 0)
                     53:                                        argv[1]--;
                     54:                        for (np = mp->file; np < &mp->file[NAMSIZ-1];)
                     55:                                if ((*np++ = *argv[2]++) == 0)
                     56:                                        argv[2]--;
                     57:                        mp = &mtab[NMOUNT];
                     58:                        while ((--mp)->file[0] == 0);
                     59:                        mf = creat("/etc/mtab", 0644);
                     60:                        write(mf, (char *)mtab, (mp-mtab+1)*2*NAMSIZ);
                     61:                        exit(0);
                     62:                }
                     63:        }
                     64:        exit(0);
                     65: }

unix.superglobalmegacorp.com

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