/* @(#)test7a.c 1.3 90/01/03 NFS Rev 2 Testsuite
* 1.3 Lachman ONC Test Suite source
* Uses the following important system calls against the server:
* mkdir() (for initial directory creation if not -m)
#include <sys/fs/nfs/time.h>
int Tflag
= 0; /* print timing */
int Hflag
= 0; /* print help message */
int Fflag
= 0; /* test function only; set count to 1, negate -t */
int Nflag
= 0; /* Suppress directory operations */
#define NNAME "newfile." /* new filename for rename */
fprintf(stdout
, "usage: %s [-htfn] [files count fname nname]\n", Myname
);
fprintf(stdout
, " Flags: h Help - print this usage info\n");
fprintf(stdout
, " t Print execution time statistics\n");
fprintf(stdout
, " f Test function only (negate -t)\n");
fprintf(stdout
, " n Suppress test directory create operations\n");
int files
= 10; /* number of files in each dir */
int count
= 10; /* times to do each file */
while (argc
&& **argv
== '-') {
for (opts
= &argv
[0][1]; *opts
; opts
++) {
case 'f': /* funtionality */
case 'n': /* No Test Directory create */
error("unknown option '%c'", *opts
);
files
= getparm(*argv
, 1, "files");
count
= getparm(*argv
, 1, "count");
fprintf(stdout
, "%s: rename\n", Myname
);
dirtree(1, files
, 0, fname
, DNAME
, &totfiles
, &totdirs
);
for (ct
= 0; ct
< count
; ct
++) {
for (fi
= 0; fi
< files
; fi
++) {
sprintf(str
, "%s%d", fname
, fi
);
sprintf(new, "%s%d", nname
, fi
);
if (rename(str
, new) < 0) {
error("can't rename %s to %s", str
, new);
if (stat(str
, &statb
) == 0) {
error("%s exists after rename", str
);
if (stat(new, &statb
) < 0) {
error("can't stat %s after rename", new);
if (rename(new, str
) < 0) {
error("can't rename %s to %s", new, str
);
if (stat(new, &statb
) == 0) {
error("%s exists after rename", new);
if (stat(str
, &statb
) < 0) {
error("can't stat %s after rename", str
);
fprintf(stdout
, "\t%d renames on %d files",
files
* count
* 2, files
);
fprintf(stdout
, " in %d.%-2d seconds",
time
.tv_sec
, time
.tv_usec
/ 10000);
/* Cleanup files left around */
rmdirtree(1, files
, 0, fname
, DNAME
, &totfiles
, &totdirs
, 1);