|
|
1.1 ! root 1: /* @(#)test8.c 1.4 90/01/03 NFS Rev 2 Testsuite ! 2: * 1.4 Lachman ONC Test Suite source ! 3: * ! 4: * Test symlink, readlink ! 5: * ! 6: * Uses the following important system calls against the server: ! 7: * ! 8: * chdir() ! 9: * mkdir() (for initial directory creation if not -m) ! 10: * creat() ! 11: * symlink() ! 12: * readlink() ! 13: * lstat() ! 14: * unlink() ! 15: */ ! 16: ! 17: #include <sys/param.h> ! 18: #ifndef major ! 19: #include <sys/types.h> ! 20: #endif ! 21: #ifdef SVR3 ! 22: #include <sys/fs/nfs/time.h> ! 23: #else ! 24: #include <sys/time.h> ! 25: #endif ! 26: #include <sys/stat.h> ! 27: #include <sys/errno.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: #define SNAME "/this/is/a/symlink" /* symlink prefix */ ! 37: ! 38: usage() ! 39: { ! 40: fprintf(stdout, "usage: %s [-htfn] [files count fname sname]\n", Myname); ! 41: fprintf(stdout, " Flags: h Help - print this usage info\n"); ! 42: fprintf(stdout, " t Print execution time statistics\n"); ! 43: fprintf(stdout, " f Test function only (negate -t)\n"); ! 44: fprintf(stdout, " n Suppress test directory create operations\n"); ! 45: } ! 46: ! 47: main(argc, argv) ! 48: int argc; ! 49: char *argv[]; ! 50: { ! 51: int files = 10; /* number of files in each dir */ ! 52: int fi; ! 53: int count = 20; /* times to do each file */ ! 54: int ct; ! 55: int totfiles = 0; ! 56: int totdirs = 0; ! 57: char *fname = FNAME; ! 58: char *sname = SNAME; ! 59: struct timeval time; ! 60: char str[MAXPATHLEN]; ! 61: char new[MAXPATHLEN]; ! 62: char buf[MAXPATHLEN]; ! 63: int ret; ! 64: struct stat statb; ! 65: char *opts; ! 66: ! 67: umask(0); ! 68: setbuf(stdout, NULL); ! 69: Myname = *argv++; ! 70: argc--; ! 71: while (argc && **argv == '-') { ! 72: for (opts = &argv[0][1]; *opts; opts++) { ! 73: switch (*opts) { ! 74: case 'h': /* help */ ! 75: usage(); ! 76: exit(1); ! 77: ! 78: case 't': /* time */ ! 79: Tflag++; ! 80: break; ! 81: ! 82: case 'f': /* funtionality */ ! 83: Fflag++; ! 84: break; ! 85: ! 86: case 'n': /* No Test Directory create */ ! 87: Nflag++; ! 88: break; ! 89: ! 90: default: ! 91: error("unknown option '%c'", *opts); ! 92: usage(); ! 93: exit(1); ! 94: } ! 95: } ! 96: argc--; ! 97: argv++; ! 98: } ! 99: ! 100: if (argc) { ! 101: files = getparm(*argv, 1, "files"); ! 102: argv++; ! 103: argc--; ! 104: } ! 105: if (argc) { ! 106: count = getparm(*argv, 1, "count"); ! 107: argv++; ! 108: argc--; ! 109: } ! 110: if (argc) { ! 111: fname = *argv; ! 112: argv++; ! 113: argc--; ! 114: } ! 115: if (argc) { ! 116: sname = *argv; ! 117: argv++; ! 118: argc--; ! 119: } ! 120: if (argc) { ! 121: usage(); ! 122: exit(1); ! 123: } ! 124: ! 125: #ifndef S_IFLNK ! 126: fprintf(stdout, "\ ! 127: %s: symlink and readlink not supported on this client\n", Myname); ! 128: #else /* S_IFLNK */ ! 129: if (Fflag) { ! 130: Tflag = 0; ! 131: count = 1; ! 132: } ! 133: ! 134: if (!Nflag) ! 135: testdir(NULL); ! 136: else ! 137: mtestdir(NULL); ! 138: ! 139: fprintf(stdout, "%s: symlink and readlink\n", Myname); ! 140: ! 141: if (Tflag) { ! 142: starttime(); ! 143: } ! 144: ! 145: for (ct = 0; ct < count; ct++) { ! 146: for (fi = 0; fi < files; fi++) { ! 147: sprintf(str, "%s%d", fname, fi); ! 148: sprintf(new, "%s%d", sname, fi); ! 149: if (symlink(new, str) < 0) { ! 150: error("can't make symlink %s", str); ! 151: if (errno == EOPNOTSUPP) ! 152: complete(); ! 153: else ! 154: exit(1); ! 155: } ! 156: if (lstat(str, &statb) < 0) { ! 157: error("can't stat %s after symlink", str); ! 158: exit(1); ! 159: } ! 160: if ((statb.st_mode & S_IFMT) != S_IFLNK) { ! 161: error("mode of %s not symlink"); ! 162: exit(1); ! 163: } ! 164: if ((ret = readlink(str, buf, MAXPATHLEN)) ! 165: != strlen(new)) { ! 166: error("readlink %s ret %d, expect %d", ! 167: str, ret, strlen(new)); ! 168: exit(1); ! 169: } ! 170: if (strncmp(new, buf, ret) != NULL) { ! 171: error("readlink %s returned bad linkname", ! 172: str); ! 173: exit(1); ! 174: } ! 175: if (unlink(str) < 0) { ! 176: error("can't unlink %s", str); ! 177: exit(1); ! 178: } ! 179: } ! 180: } ! 181: ! 182: if (Tflag) { ! 183: endtime(&time); ! 184: } ! 185: fprintf(stdout, "\t%d symlinks and readlinks on %d files", ! 186: files * count * 2, files); ! 187: if (Tflag) { ! 188: fprintf(stdout, " in %d.%-2d seconds", ! 189: time.tv_sec, time.tv_usec / 10000); ! 190: } ! 191: fprintf(stdout, "\n"); ! 192: #endif /* S_IFLNK */ ! 193: complete(); ! 194: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.