mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
New API: fill-dir: Fill a directory with files (for testing).
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -1 +1 @@
|
||||
347
|
||||
348
|
||||
|
||||
Reference in New Issue
Block a user