From 07eb7021638140c4dfc2b5b99bbb4c129d21e03f Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 17 Aug 2012 15:50:51 +0100 Subject: New API: fill-dir: Fill a directory with files (for testing). --- daemon/fill.c | 28 ++++++++++++++++++++++++++++ generator/generator_actions.ml | 11 +++++++++++ src/MAX_PROC_NR | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/daemon/fill.c b/daemon/fill.c index 9ea00ab3..a9a3aa78 100644 --- a/daemon/fill.c +++ b/daemon/fill.c @@ -123,3 +123,31 @@ do_fill_pattern (const char *pattern, int len, const char *path) return 0; } + +int +do_fill_dir (const char *dir, int n) +{ + size_t len = strlen (dir); + char filename[len+10]; + int fd; + int i; + + for (i = 0; i < n; ++i) { + snprintf (filename, len+10, "%s/%08d", dir, i); + + CHROOT_IN; + fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_CLOEXEC, 0666); + CHROOT_OUT; + + if (fd == -1) { + reply_with_perror ("create: %s", filename); + return -1; + } + if (close (fd) == -1) { + reply_with_perror ("close: %s", filename); + return -1; + } + } + + return 0; +} diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index e7cfb6da..1b10b04a 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -9436,6 +9436,17 @@ In the output file, the filenames are separated by C<\\0> characters. C<.> and C<..> are not returned. The filenames are not sorted." }; + { defaults with + name = "fill_dir"; + style = RErr, [Pathname "dir"; Int "nr"], []; + proc_nr = Some 348; + shortdesc = "fill a directory with empty files"; + longdesc = "\ +This function, useful for testing filesystems, creates C +empty files in the directory C with names C<00000000> +through C (ie. each file name is 8 digits long padded +with zeroes)." }; + ] (* Non-API meta-commands available only in guestfish. diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 538ad4bc..71627d71 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -347 +348 -- cgit