+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ */
+
#define PATH_LENGTH 35
#include <math.h>
#include <signal.h>
int rename_errors;
int unlink_errors;
-void usage(const char *progname)
+static void usage(const char *progname)
{
fprintf(stderr, "usage: %s [-n numfiles] [-s seed] [-v] [-x] [dir]\n"
"\t-c: only do the create step of first loop\n"
"\t-x: don't exit on error\n", progname);
}
-void handler(int sig) {
+static void handler(int sig)
+{
static long last_time;
long now = time(0);
int main(int argc, char *argv[])
{
unsigned long n;
- char msg[100], c, *end = NULL;
+ char msg[100], *end = NULL;
int h1, h2;
- int i;
+ int i, c;
while ((c = getopt(argc, argv, "cf:n:rs:vx")) != EOF) {
- switch(c) {
+ switch (c) {
case 'c':
++opt_create_only;
break;
if (i && end != NULL && *end == '\0') {
file_count = i;
} else {
- fprintf(stderr, "bad file count '%s'\n",optarg);
+ fprintf(stderr, "bad file count '%s'\n",
+ optarg);
usage(argv[0]);
return 1;
}
if (i && end != NULL && *end == '\0') {
loop_count = i;
} else {
- fprintf(stderr, "bad loop count '%s'\n",optarg);
+ fprintf(stderr, "bad loop count '%s'\n",
+ optarg);
usage(argv[0]);
return 1;
}
if (end && *end == '\0') {
seed = i;
} else {
- fprintf(stderr, "bad seed '%s'\n", optarg);
- usage(argv[0]);
- return 1;
+ seed = random();
+ fprintf(stderr, "using random seed %u\n", seed);
}
break;
case 'v':
names = malloc(sizeof(struct names) * file_count);
if (names == NULL) {
perror("calloc");
- return(1);
+ return 1;
}
h2 = sprintf(msg, "%x", file_count); /* just to figure length */
return 1;
} else if (argv[optind] != NULL) {
if (chdir(argv[optind]) < 0) {
- sprintf(msg, "chdir '%s'\n", argv[optind]);
+ snprintf(msg, sizeof(msg),
+ "chdir '%s'\n", argv[optind]);
perror(msg);
return 2;
}
}
while (!stop && loop_count != 0 && loops < loop_count) {
- int j,k,l,m;
+ int j, k, l, m;
srand(seed + loops);
- if (mkdir("tmp", S_IRWXU) == -1) {
+ if (mkdir("tmp", 0700) == -1) {
perror("mkdir tmp");
- return(1);
+ return 1;
}
if (chdir("tmp") == -1) {
perror("chdir tmp");
- return(1);
+ return 1;
}
for (i = 0; i < file_count ; i++) {
}
for (i = 0; i < file_count; i++) {
- if (mknod(names[i].from, S_IFREG | S_IRWXU, 0) == -1) {
+ if (mknod(names[i].from, S_IFREG | 0700, 0) == -1) {
sprintf(msg, "loop %d.%d: creat %s",
loops, i, names[i].from);
perror(msg);
if (chdir("..") == -1) {
perror("chdir ..");
- return(1);
+ return 1;
}
if (rmdir("tmp") == -1) {
if (chdir("tmp") == -1) {
perror("chdir tmp 2");
- return(1);
+ return 1;
}
for (i = 0; i < file_count; i++) {
if (unlink(names[i].from) != -1) {
- fprintf(stderr, "loop %d.%d: "
- "unexpected file %s\n",
+ fprintf(stderr,
+ "loop %d.%d: unexpected file %s\n",
loops, i, names[i].to);
unlink_errors++;
if (!opt_exit_on_err)
}
if (chdir("..") == -1) {
perror("chdir .. 2");
- return(1);
+ return 1;
}
if (rmdir("tmp") == -1) {
perror("rmdir tmp");
- return(1);
+ return 1;
}
}
if (!opt_verbose)
handler(0);
- return(0);
+ return 0;
}