14 char from[PATH_LENGTH];
18 unsigned int loop_count = 500;
19 int file_count = 1000;
33 void usage(const char *progname)
35 fprintf(stderr, "usage: %s [-n numfiles] [-s seed] [-v] [-x] [dir]\n"
36 "\t-c: only do the create step of first loop\n"
37 "\t-f: number of files to create/rename/unlink per loop\n"
38 "\t-n: number of test loops (0 to run forever)\n"
39 "\t-r: only do the rename step of first loop\n"
40 "\t-s: starting seed (equals loop number by default)\n"
42 "\t-x: don't exit on error\n", progname);
45 void handler(int sig) {
46 static long last_time;
49 signal(SIGINT, handler);
50 signal(SIGALRM, handler);
51 printf("%6lds %8d iterations %d/%d/%d errors",
52 now - start, loops, creat_errors, rename_errors, unlink_errors);
54 printf(" - use SIGQUIT (^\\) or ^C^C to kill\n");
60 else if (sig == SIGINT) {
61 if (now - last_time < 2)
71 int main(int argc, char *argv[])
74 char msg[100], c, *end = NULL;
78 while ((c = getopt(argc, argv, "cf:n:rs:vx")) != EOF) {
84 i = strtoul(optarg, &end, 0);
85 if (i && end != NULL && *end == '\0') {
88 fprintf(stderr, "bad file count '%s'\n",optarg);
94 i = strtoul(optarg, &end, 0);
95 if (i && end != NULL && *end == '\0') {
98 fprintf(stderr, "bad loop count '%s'\n",optarg);
107 i = strtoul(optarg, &end, 0);
108 if (end && *end == '\0') {
111 fprintf(stderr, "bad seed '%s'\n", optarg);
128 names = malloc(sizeof(struct names) * file_count);
134 h2 = sprintf(msg, "%x", file_count); /* just to figure length */
135 h1 = (PATH_LENGTH - h2 - 2) / 4;
137 n = (1ULL << h1 * 4) - 1;
139 //printf("h1 = %d, h2 = %d n = %lu\n", h1, h2, n);
143 signal(SIGQUIT, handler);
144 signal(SIGINT, handler);
145 signal(SIGALRM, handler);
146 signal(SIGUSR1, handler);
149 if (argc > optind + 1) {
150 fprintf(stderr, "too many extra args %d\n", argc - optind);
153 } else if (argv[optind] != NULL) {
154 if (chdir(argv[optind]) < 0) {
155 sprintf(msg, "chdir '%s'\n", argv[optind]);
161 while (!stop && loop_count != 0 && loops < loop_count) {
165 if (mkdir("tmp", S_IRWXU) == -1) {
169 if (chdir("tmp") == -1) {
174 for (i = 0; i < file_count ; i++) {
179 sprintf(names[i].from, "%0*x%0*x%0*x%0*x0%0*x",
180 h1, j, h1, k, h1, l, h1, m, h2, i);
181 sprintf(names[i].to, "%0*x%0*x%0*x%0*x1%0*x",
182 h1, j, h1, k, h1, l, h1, m, h2, i);
186 for (i = 0; i < file_count; i++) {
187 if (mknod(names[i].from, S_IFREG | S_IRWXU, 0) == -1) {
188 sprintf(msg, "loop %d.%d: creat %s",
189 loops, i, names[i].from);
192 if (!opt_exit_on_err)
200 for (i = 0; i < file_count; i++) {
201 if (rename(names[i].from, names[i].to) == -1) {
202 sprintf(msg, "loop %d.%d: rename %s to %s",
203 loops, i, names[i].from, names[i].to);
206 if (!opt_exit_on_err)
214 for (i = 0; i < file_count; i++) {
215 if (unlink(names[i].to) == -1) {
216 sprintf(msg, "loop %d.%d: unlink %s",
217 loops, i, names[i].to);
220 if (!opt_exit_on_err)
225 if (chdir("..") == -1) {
230 if (rmdir("tmp") == -1) {
231 if (chdir("tmp") == -1) {
232 perror("chdir tmp 2");
235 for (i = 0; i < file_count; i++) {
236 if (unlink(names[i].from) != -1) {
237 fprintf(stderr, "loop %d.%d: "
238 "unexpected file %s\n",
239 loops, i, names[i].to);
241 if (!opt_exit_on_err)
245 if (chdir("..") == -1) {
246 perror("chdir .. 2");
249 if (rmdir("tmp") == -1) {