|
|
1.1 ! root 1: /* @(#)test7a.c 1.3 90/01/03 NFS Rev 2 Testsuite ! 2: * 1.3 Lachman ONC Test Suite source ! 3: * ! 4: * Test rename ! 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: * stat() ! 12: * rename() ! 13: * unlink() ! 14: */ ! 15: ! 16: #include <sys/param.h> ! 17: #ifndef major ! 18: #include <sys/types.h> ! 19: #endif ! 20: #ifdef SVR3 ! 21: #include <sys/fs/nfs/time.h> ! 22: #else ! 23: #include <sys/time.h> ! 24: #endif ! 25: #include <sys/stat.h> ! 26: #include <stdio.h> ! 27: #include "tests.h" ! 28: ! 29: int Tflag = 0; /* print timing */ ! 30: int Hflag = 0; /* print help message */ ! 31: int Fflag = 0; /* test function only; set count to 1, negate -t */ ! 32: int Nflag = 0; /* Suppress directory operations */ ! 33: ! 34: #define NNAME "newfile." /* new filename for rename */ ! 35: ! 36: usage() ! 37: { ! 38: fprintf(stdout, "usage: %s [-htfn] [files count fname nname]\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 = 10; /* times to do each file */ ! 52: int ct; ! 53: int totfiles = 0; ! 54: int totdirs = 0; ! 55: char *fname = FNAME; ! 56: char *nname = NNAME; ! 57: struct timeval time; ! 58: char str[MAXPATHLEN]; ! 59: char new[MAXPATHLEN]; ! 60: struct stat statb; ! 61: char *opts; ! 62: ! 63: umask(0); ! 64: setbuf(stdout, NULL); ! 65: Myname = *argv++; ! 66: argc--; ! 67: while (argc && **argv == '-') { ! 68: for (opts = &argv[0][1]; *opts; opts++) { ! 69: switch (*opts) { ! 70: case 'h': /* help */ ! 71: usage(); ! 72: exit(1); ! 73: ! 74: case 't': /* time */ ! 75: Tflag++; ! 76: break; ! 77: ! 78: case 'f': /* funtionality */ ! 79: Fflag++; ! 80: break; ! 81: ! 82: case 'n': /* No Test Directory create */ ! 83: Nflag++; ! 84: break; ! 85: ! 86: default: ! 87: error("unknown option '%c'", *opts); ! 88: usage(); ! 89: exit(1); ! 90: } ! 91: } ! 92: argc--; ! 93: argv++; ! 94: } ! 95: ! 96: if (argc) { ! 97: files = getparm(*argv, 1, "files"); ! 98: argv++; ! 99: argc--; ! 100: } ! 101: if (argc) { ! 102: count = getparm(*argv, 1, "count"); ! 103: argv++; ! 104: argc--; ! 105: } ! 106: if (argc) { ! 107: fname = *argv; ! 108: argv++; ! 109: argc--; ! 110: } ! 111: if (argc) { ! 112: nname = *argv; ! 113: argv++; ! 114: argc--; ! 115: } ! 116: if (argc) { ! 117: usage(); ! 118: exit(1); ! 119: } ! 120: ! 121: if (Fflag) { ! 122: Tflag = 0; ! 123: count = 1; ! 124: } ! 125: ! 126: fprintf(stdout, "%s: rename\n", Myname); ! 127: ! 128: if (!Nflag) ! 129: testdir(NULL); ! 130: else ! 131: mtestdir(NULL); ! 132: ! 133: dirtree(1, files, 0, fname, DNAME, &totfiles, &totdirs); ! 134: ! 135: if (Tflag) { ! 136: starttime(); ! 137: } ! 138: ! 139: for (ct = 0; ct < count; ct++) { ! 140: for (fi = 0; fi < files; fi++) { ! 141: sprintf(str, "%s%d", fname, fi); ! 142: sprintf(new, "%s%d", nname, fi); ! 143: if (rename(str, new) < 0) { ! 144: error("can't rename %s to %s", str, new); ! 145: exit(1); ! 146: } ! 147: if (stat(str, &statb) == 0) { ! 148: error("%s exists after rename", str); ! 149: exit(1); ! 150: } ! 151: if (stat(new, &statb) < 0) { ! 152: error("can't stat %s after rename", new); ! 153: exit(1); ! 154: } ! 155: if (rename(new, str) < 0) { ! 156: error("can't rename %s to %s", new, str); ! 157: exit(1); ! 158: } ! 159: if (stat(new, &statb) == 0) { ! 160: error("%s exists after rename", new); ! 161: exit(1); ! 162: } ! 163: if (stat(str, &statb) < 0) { ! 164: error("can't stat %s after rename", str); ! 165: exit(1); ! 166: } ! 167: } ! 168: } ! 169: ! 170: if (Tflag) { ! 171: endtime(&time); ! 172: } ! 173: fprintf(stdout, "\t%d renames on %d files", ! 174: files * count * 2, files); ! 175: if (Tflag) { ! 176: fprintf(stdout, " in %d.%-2d seconds", ! 177: time.tv_sec, time.tv_usec / 10000); ! 178: } ! 179: fprintf(stdout, "\n"); ! 180: ! 181: /* Cleanup files left around */ ! 182: rmdirtree(1, files, 0, fname, DNAME, &totfiles, &totdirs, 1); ! 183: ! 184: complete(); ! 185: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.