From b47528cc4bb7a308c74d4dae7c2adcf9f7392f4e Mon Sep 17 00:00:00 2001 From: Lakshmipathi Date: Fri, 8 Jul 2011 11:51:53 +0530 Subject: Added community provided scripts for lock and rename --- community-scripts/rename/atomic/bug1034/gt_init.c | 114 ++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 community-scripts/rename/atomic/bug1034/gt_init.c (limited to 'community-scripts/rename/atomic/bug1034/gt_init.c') diff --git a/community-scripts/rename/atomic/bug1034/gt_init.c b/community-scripts/rename/atomic/bug1034/gt_init.c new file mode 100644 index 0000000..f3dadf0 --- /dev/null +++ b/community-scripts/rename/atomic/bug1034/gt_init.c @@ -0,0 +1,114 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gt.h" + +static void +usage(char *progname) +{ + fprintf(stderr, "usage: %s node_count\n", progname); + exit(1); +} + +// rm -rf +static void +delete_tree(char *rootpath) +{ + int retval; + struct stat statbuf; + + retval = lstat(rootpath, &statbuf); + if (retval < 0) { + return; + } + + if (S_ISDIR(statbuf.st_mode)) { + DIR *dir; + struct dirent *dent; + char pathbuf[PATH_MAX]; + + dir = opendir(rootpath); + while ((dent = readdir(dir)) != NULL) { + if (0 == strcmp(".", dent->d_name)) { + continue; + } + if (0 == strcmp("..", dent->d_name)) { + continue; + } + snprintf(pathbuf, sizeof(pathbuf), + "%s/%s", rootpath, dent->d_name); + delete_tree(pathbuf); + } + closedir(dir); + + (void)rmdir(rootpath); + } else { + (void)unlink(rootpath); + } +} + +static void +create_subdir(char *dirpath) +{ + int i; + + mkdir(dirpath, 0775); + + for (i = 0; i < SUBDIR_FILES; i++) { + char pathbuf[PATH_MAX]; + int fd; + + snprintf(pathbuf, sizeof(pathbuf), + "%s/WA_RC_%d", dirpath, i); + fd = open(pathbuf, O_RDWR|O_CREAT, 0664); + write(fd, pathbuf, strlen(pathbuf)); + close(fd); + } +} + +static void +create_tree(char *rootpath, int node_count) +{ + int n; + + mkdir(rootpath, 0775); + + for (n = 1; n <= node_count; n++) { + char pathbuf[PATH_MAX]; + int fd; + + snprintf(pathbuf, sizeof(pathbuf), + "%s/%d", rootpath, n); + mkdir(pathbuf, 0775); + create_subdir(pathbuf); + } +} + +int +main(int argc, char **argv) +{ + char *arg_ptr; + long node_count; + + if (argc != 2) { + usage(argv[0]); + } + + node_count = strtol(argv[1], &arg_ptr, 10); + if (*arg_ptr != '\0') { + usage(argv[0]); + } + + delete_tree(BASE_PATH); + + create_tree(BASE_PATH, node_count); + + exit(0); +} -- cgit