65 static void rename_file(
int old,
int new)
67 char new_path[BUFSIZ];
68 char old_path[BUFSIZ];
70 sprintf(new_path,
"%06d",
new);
71 sprintf(old_path,
"%06d", old);
72 if (rename(old_path, new_path))
73 msg_fatal(
"rename %s to %s: %m", old_path, new_path);
78 static void make_file(
int seqno,
int size)
85 sprintf(path,
"%06d", seqno);
86 if ((fp = fopen(path,
"w")) == 0)
88 memset(buf,
'x',
sizeof(buf));
89 for (i = 0; i < size; i++)
90 if (fwrite(buf, 1,
sizeof(buf), fp) !=
sizeof(buf))
92 if (fsync(fileno(fp)))
96 if ((fp = fopen(path,
"r")) == 0)
98 while (fgets(path,
sizeof(path), fp))
106 static void use_file(
int seqno)
112 sprintf(path,
"%06d", seqno);
113 if ((fp = fopen(path,
"w")) == 0)
115 for (i = 0; i < 400; i++)
116 fprintf(fp,
"hello");
117 if (fsync(fileno(fp)))
121 if ((fp = fopen(path,
"r+")) == 0)
123 while (fgets(path,
sizeof(path), fp))
125 if (ftruncate(fileno(fp), (off_t) 0))
133 static void remove_file(
int seq)
137 sprintf(path,
"%06d", seq);
144 static void remove_silent(
int seq)
148 sprintf(path,
"%06d", seq);
154 static void usage(
char *myname)
156 msg_fatal(
"usage: %s [-cr] [-s size] messages directory_entries", myname);
161 int main(
int argc,
char **argv)
165 struct timeval start, end;
178 while ((ch =
GETOPT(argc, argv,
"crs:")) != EOF) {
187 if ((size = atoi(optarg)) <= 0)
195 if (argc - optind != 2 || (do_rename && !do_create))
197 if ((op_count = atoi(argv[optind])) <= 0)
199 if ((max_file = atoi(argv[optind + 1])) <= 0)
205 for (seq = 0; seq < max_file; seq++)
206 make_file(seq, size);
211 GETTIMEOFDAY(&start);
212 while (op_count > 0) {
216 make_file(seq, size);
218 rename_file(seq, seq + max_file);
219 rename_file(seq + max_file, seq);
228 if (end.tv_usec < start.tv_usec) {
230 end.tv_usec += 1000000;
232 printf(
"elapsed time: %ld.%06ld\n",
233 (
long) (end.tv_sec - start.tv_sec),
234 (
long) (end.tv_usec - start.tv_usec));
239 for (seq = 0; seq < max_file; seq++)
#define MAIL_VERSION_STAMP_ALLOCATE
NORETURN msg_fatal(const char *fmt,...)
#define GETOPT(argc, argv, str)
int main(int argc, char **argv)
void msg_vstream_init(const char *name, VSTREAM *vp)
MAIL_VERSION_STAMP_DECLARE