|
|
1.1 ! root 1: /* @(#)test7.c 1.4 90/01/03 NFS Rev 2 Testsuite ! 2: * 1.4 Lachman ONC Test Suite source ! 3: * ! 4: * Test rename, link ! 5: * ! 6: * Uses the following important system calls against the server: ! 7: * ! 8: * chdir() ! 9: * creat() ! 10: * stat() ! 11: * rename() ! 12: * link() ! 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 and link */ ! 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: link and 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 (statb.st_nlink != 1) { ! 156: error("%s has %d links after rename (expect 1)", ! 157: new, statb.st_nlink); ! 158: exit(1); ! 159: } ! 160: if (link(new, str) < 0) { ! 161: error("can't link %s to %s", new, str); ! 162: exit(1); ! 163: } ! 164: if (stat(new, &statb) < 0) { ! 165: error("can't stat %s after link", new); ! 166: exit(1); ! 167: } ! 168: if (statb.st_nlink != 2) { ! 169: error("%s has %d links after link (expect 2)", ! 170: new, statb.st_nlink); ! 171: exit(1); ! 172: } ! 173: if (stat(str, &statb) < 0) { ! 174: error("can't stat %s after link", str); ! 175: exit(1); ! 176: } ! 177: if (statb.st_nlink != 2) { ! 178: error("%s has %d links after link (expect 2)", ! 179: str, statb.st_nlink); ! 180: exit(1); ! 181: } ! 182: if (unlink(new) < 0) { ! 183: error("can't unlink %s", new); ! 184: exit(1); ! 185: } ! 186: if (stat(str, &statb) < 0) { ! 187: error("can't stat %s after unlink %s", ! 188: str, new); ! 189: exit(1); ! 190: } ! 191: if (statb.st_nlink != 1) { ! 192: error("%s has %d links after unlink (expect 1)", ! 193: str, statb.st_nlink); ! 194: exit(1); ! 195: } ! 196: } ! 197: } ! 198: ! 199: if (Tflag) { ! 200: endtime(&time); ! 201: } ! 202: fprintf(stdout, "\t%d renames and links on %d files", ! 203: files * count * 2, files); ! 204: if (Tflag) { ! 205: fprintf(stdout, " in %d.%-2d seconds", ! 206: time.tv_sec, time.tv_usec / 10000); ! 207: } ! 208: fprintf(stdout, "\n"); ! 209: ! 210: /* Cleanup files left around */ ! 211: rmdirtree(1, files, 0, fname, DNAME, &totfiles, &totdirs, 1); ! 212: ! 213: complete(); ! 214: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.