DF-2645 / mkfiles.c
/* mkfiles: create files listed in namefile under dir, batch of batchsz * with a sync per batch (lets the flusher build indirect blocks * incrementally, producing nested INDIRECT topology). */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> int main(int argc, char **argv) { const char *dir = argv[1]; const char *list = argv[2]; int batch = argc > 3 ? atoi(argv[3]) : 512; char line[512], path[1024]; FILE *f; int n = 0; if ((f = fopen(list, "r")) == NULL) { perror(list); exit(1); } while (fgets(line, sizeof(line), f)) { int len = strlen(line); char dat[64]; int fd; if (len && line[len-1] == '\n') line[--len] = 0; if (len == 0) continue; snprintf(path, sizeof(path), "%s/%s", dir, line); fd = open(path, O_CREAT|O_RDWR|O_TRUNC, 0644); if (fd < 0) { perror(path); continue; } memset(dat, 'Z', sizeof(dat)); write(fd, dat, sizeof(dat)); close(fd); if (++n % batch == 0) sync(); } fclose(f); fprintf(stderr, "created %d files\n", n); return 0; } |