Annotation of 43BSDReno/sys/nfs/TEST/unix-tests/basic/test4.c, revision 1.1.1.1

1.1       root        1: /*     @(#)test4.c     1.4 90/01/03 NFS Rev 2 Testsuite
                      2:  *     1.4 Lachman ONC Test Suite source
                      3:  *
                      4:  * Test setattr, getattr and lookup
                      5:  *
                      6:  * Creates the files in the test directory - does not create a directory
                      7:  * tree.
                      8:  *
                      9:  * Uses the following important system calls against the server:
                     10:  *
                     11:  *     chdir()
                     12:  *     mkdir()         (for initial directory creation if not -m)
                     13:  *     creat()
                     14:  *     chmod()
                     15:  *     stat()
                     16:  */
                     17: 
                     18: #include <sys/param.h>
                     19: #ifndef major
                     20: #include <sys/types.h>
                     21: #endif
                     22: #ifdef SVR3
                     23: #include <sys/fs/nfs/time.h>
                     24: #else
                     25: #include <sys/time.h>
                     26: #endif
                     27: #include <sys/stat.h>
                     28: #include <stdio.h>
                     29: #include "tests.h"
                     30: 
                     31: int Tflag = 0;         /* print timing */
                     32: int Hflag = 0;         /* print help message */
                     33: int Fflag = 0;         /* test function only;  set count to 1, negate -t */
                     34: int Nflag = 0;         /* Suppress directory operations */
                     35: 
                     36: usage()
                     37: {
                     38:        fprintf(stdout, "usage: %s [-htfn] [files count]\n", Myname);
                     39:        fprintf(stdout, "  Flags:  h    Help - print this usage info\n");
                     40:        fprintf(stdout, "          t    Print execution time statistics\n");
                     41:        fprintf(stdout, "          f    Test function only (negate -t)\n");
                     42:        fprintf(stdout, "          n    Suppress test directory create operations\n");
                     43: }
                     44: 
                     45: main(argc, argv)
                     46:        int argc;
                     47:        char *argv[];
                     48: {
                     49:        int files = 10;         /* number of files in each dir */
                     50:        int fi;
                     51:        int count = 50; /* times to do each file */
                     52:        int ct;
                     53:        int totfiles = 0;
                     54:        int totdirs = 0;
                     55:        char *fname = FNAME;
                     56:        struct timeval time;
                     57:        char str[MAXPATHLEN];
                     58:        struct stat statb;
                     59:        char *opts;
                     60: 
                     61:        umask(0);
                     62:        setbuf(stdout, NULL);
                     63:        Myname = *argv++;
                     64:        argc--;
                     65:        while (argc && **argv == '-') {
                     66:                for (opts = &argv[0][1]; *opts; opts++) {
                     67:                        switch (*opts) {
                     68:                                case 'h':       /* help */
                     69:                                        usage();
                     70:                                        exit(1);
                     71: 
                     72:                                case 't':       /* time */
                     73:                                        Tflag++;
                     74:                                        break;
                     75:                                
                     76:                                case 'f':       /* funtionality */
                     77:                                        Fflag++;
                     78:                                        break;
                     79:                                
                     80:                                case 'n':       /* suppress initial directory */
                     81:                                        Nflag++;
                     82:                                        break;
                     83:                                
                     84:                                default:
                     85:                                        error("unknown option '%c'", *opts);
                     86:                                        usage();
                     87:                                        exit(1);
                     88:                        }
                     89:                }
                     90:                argc--;
                     91:                argv++;
                     92:        }
                     93: 
                     94:        if (argc) {
                     95:                files = getparm(*argv, 1, "files");
                     96:                argv++;
                     97:                argc--;
                     98:        }
                     99:        if (argc) {
                    100:                count = getparm(*argv, 1, "count");
                    101:                argv++;
                    102:                argc--;
                    103:        }
                    104:        if (argc) {
                    105:                fname = *argv;
                    106:                argc--;
                    107:                argv++;
                    108:        }
                    109:        if (argc) {
                    110:                usage();
                    111:                exit(1);
                    112:        }
                    113: 
                    114:        if (Fflag) {
                    115:                Tflag = 0;
                    116:                count = 1;
                    117:        }
                    118: 
                    119:        if (!Nflag)
                    120:                testdir(NULL);
                    121:        else
                    122:                mtestdir(NULL);
                    123: 
                    124:        dirtree(1, files, 0, fname, DNAME, &totfiles, &totdirs);
                    125: 
                    126:        fprintf(stdout, "%s: setattr, getattr, and lookup\n", Myname);
                    127: 
                    128:        if (Tflag) {
                    129:                starttime();
                    130:        }
                    131: 
                    132:        for (ct = 0; ct < count; ct++) {
                    133:                for (fi = 0; fi < files; fi++) {
                    134:                        sprintf(str, "%s%d", fname, fi);
                    135:                        if (chmod(str, 0) < 0) {
                    136:                                error("can't chmod 0 %s", str);
                    137:                                exit(0);
                    138:                        }
                    139:                        if (stat(str, &statb) < 0) {
                    140:                                error("can't stat %s", str);
                    141:                                exit(1);
                    142:                        }
                    143:                        if ((statb.st_mode & 0777) != 0) {
                    144:                                error("%s has mode %o after chmod 0",
                    145:                                    str, (statb.st_mode & 0777));
                    146:                                exit(1);
                    147:                        }
                    148:                        if (chmod(str, 0666) < 0) {
                    149:                                error("can't chmod 0666 %s", str);
                    150:                                exit(0);
                    151:                        }
                    152:                        if (stat(str, &statb) < 0) {
                    153:                                error("can't stat %s", str);
                    154:                                exit(1);
                    155:                        }
                    156:                        if ((statb.st_mode & 0777) != 0666) {
                    157:                                error("%s has mode %o after chmod 0666",
                    158:                                    str, (statb.st_mode & 0777));
                    159:                                exit(1);
                    160:                        }
                    161:                }
                    162:        }
                    163: 
                    164:        if (Tflag) {
                    165:                endtime(&time);
                    166:        }
                    167:        fprintf(stdout, "\t%d chmods and stats on %d files",
                    168:                files * count * 2, files);
                    169:        if (Tflag) {
                    170:                fprintf(stdout, " in %d.%-2d seconds",
                    171:                    time.tv_sec, time.tv_usec / 10000);
                    172:        }
                    173:        fprintf(stdout, "\n");
                    174:        /* XXX REMOVE DIRECTORY TREE? */
                    175:        complete();
                    176: }

unix.superglobalmegacorp.com

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