New API: fill-dir: Fill a directory with files (for testing).

This commit is contained in:
Richard W.M. Jones
2012-08-17 15:50:51 +01:00
parent 6952505694
commit 07eb702163
3 changed files with 40 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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<nr>
empty files in the directory C<dir> with names C<00000000>
through C<nr-1> (ie. each file name is 8 digits long padded
with zeroes)." };
]
(* Non-API meta-commands available only in guestfish.

View File

@@ -1 +1 @@
347
348