Add progress notification messages to upload and upload-offset APIs.
[libguestfs.git] / generator / generator_actions.ml
index 49053a3..a405fd4 100644 (file)
@@ -738,6 +738,10 @@ Any Linux-based operating system.
 
 Any Microsoft Windows operating system.
 
+=item \"freebsd\"
+
+FreeBSD.
+
 =item \"unknown\"
 
 The operating system type could not be determined.
@@ -785,7 +789,7 @@ Arch Linux.
 
 =item \"debian\"
 
-Debian or a Debian-derived distro such as Ubuntu.
+Debian.
 
 =item \"fedora\"
 
@@ -795,6 +799,18 @@ Fedora.
 
 Gentoo.
 
+=item \"linuxmint\"
+
+Linux Mint.
+
+=item \"mandriva\"
+
+Mandriva.
+
+=item \"meego\"
+
+MeeGo.
+
 =item \"pardus\"
 
 Pardus.
@@ -807,11 +823,6 @@ Some Red Hat-derived distro.
 
 Red Hat Enterprise Linux and some derivatives.
 
-=item \"windows\"
-
-Windows does not have distributions.  This string is
-returned if the OS type is Windows.
-
 =item \"ubuntu\"
 
 Ubuntu.
@@ -820,6 +831,11 @@ Ubuntu.
 
 The distro could not be determined.
 
+=item \"windows\"
+
+Windows does not have distributions.  This string is
+returned if the OS type is Windows.
+
 =back
 
 Future versions of libguestfs may return other strings here.
@@ -1034,6 +1050,247 @@ the case then an error is returned.
 
 Please read L<guestfs(3)/INSPECTION> for more details.");
 
+  ("inspect_get_roots", (RStringList "roots", [], []), -1, [],
+   [],
+   "return list of operating systems found by last inspection",
+   "\
+This function is a convenient way to get the list of root
+devices, as returned from a previous call to C<guestfs_inspect_os>,
+but without redoing the whole inspection process.
+
+This returns an empty list if either no root devices were
+found or the caller has not called C<guestfs_inspect_os>.
+
+Please read L<guestfs(3)/INSPECTION> for more details.");
+
+  ("debug_cmdline", (RStringList "cmdline", [], []), -1, [NotInDocs],
+   [],
+   "debug the QEMU command line (internal use only)",
+   "\
+This returns the internal QEMU command line.  'debug' commands are
+not part of the formal API and can be removed or changed at any time.");
+
+  ("add_domain", (RInt "nrdisks", [String "dom"], [String "libvirturi"; Bool "readonly"; String "iface"]), -1, [FishAlias "domain"],
+   [],
+   "add the disk(s) from a named libvirt domain",
+   "\
+This function adds the disk(s) attached to the named libvirt
+domain C<dom>.  It works by connecting to libvirt, requesting
+the domain and domain XML from libvirt, parsing it for disks,
+and calling C<guestfs_add_drive_opts> on each one.
+
+The number of disks added is returned.  This operation is atomic:
+if an error is returned, then no disks are added.
+
+This function does some minimal checks to make sure the libvirt
+domain is not running (unless C<readonly> is true).  In a future
+version we will try to acquire the libvirt lock on each disk.
+
+Disks must be accessible locally.  This often means that adding disks
+from a remote libvirt connection (see L<http://libvirt.org/remote.html>)
+will fail unless those disks are accessible via the same device path
+locally too.
+
+The optional C<libvirturi> parameter sets the libvirt URI
+(see L<http://libvirt.org/uri.html>).  If this is not set then
+we connect to the default libvirt URI (or one set through an
+environment variable, see the libvirt documentation for full
+details).  If you are using the C API directly then it is more
+flexible to create the libvirt connection object yourself, get
+the domain object, and call C<guestfs_add_libvirt_dom>.
+
+The other optional parameters are passed directly through to
+C<guestfs_add_drive_opts>.");
+
+(*
+This interface is not quite baked yet. -- RWMJ 2010-11-11
+  ("add_libvirt_dom", (RInt "nrdisks", [Pointer ("virDomainPtr", "dom")], [Bool "readonly"; String "iface"]), -1, [NotInFish],
+   [],
+   "add the disk(s) from a libvirt domain",
+   "\
+This function adds the disk(s) attached to the libvirt domain C<dom>.
+It works by requesting the domain XML from libvirt, parsing it for
+disks, and calling C<guestfs_add_drive_opts> on each one.
+
+In the C API we declare C<void *dom>, but really it has type
+C<virDomainPtr dom>.  This is so we don't need E<lt>libvirt.hE<gt>.
+
+The number of disks added is returned.  This operation is atomic:
+if an error is returned, then no disks are added.
+
+This function does some minimal checks to make sure the libvirt
+domain is not running (unless C<readonly> is true).  In a future
+version we will try to acquire the libvirt lock on each disk.
+
+Disks must be accessible locally.  This often means that adding disks
+from a remote libvirt connection (see L<http://libvirt.org/remote.html>)
+will fail unless those disks are accessible via the same device path
+locally too.
+
+The optional parameters are passed directly through to
+C<guestfs_add_drive_opts>.");
+*)
+
+  ("inspect_get_package_format", (RString "packageformat", [Device "root"], []), -1, [],
+   [],
+   "get package format used by the operating system",
+   "\
+This function should only be called with a root device string
+as returned by C<guestfs_inspect_os>.
+
+This function and C<guestfs_inspect_get_package_management> return
+the package format and package management tool used by the
+inspected operating system.  For example for Fedora these
+functions would return C<rpm> (package format) and
+C<yum> (package management).
+
+This returns the string C<unknown> if we could not determine the
+package format I<or> if the operating system does not have
+a real packaging system (eg. Windows).
+
+Possible strings include: C<rpm>, C<deb>, C<ebuild>, C<pisi>, C<pacman>.
+Future versions of libguestfs may return other strings.
+
+Please read L<guestfs(3)/INSPECTION> for more details.");
+
+  ("inspect_get_package_management", (RString "packagemanagement", [Device "root"], []), -1, [],
+   [],
+   "get package management tool used by the operating system",
+   "\
+This function should only be called with a root device string
+as returned by C<guestfs_inspect_os>.
+
+C<guestfs_inspect_get_package_format> and this function return
+the package format and package management tool used by the
+inspected operating system.  For example for Fedora these
+functions would return C<rpm> (package format) and
+C<yum> (package management).
+
+This returns the string C<unknown> if we could not determine the
+package management tool I<or> if the operating system does not have
+a real packaging system (eg. Windows).
+
+Possible strings include: C<yum>, C<up2date>,
+C<apt> (for all Debian derivatives),
+C<portage>, C<pisi>, C<pacman>, C<urpmi>.
+Future versions of libguestfs may return other strings.
+
+Please read L<guestfs(3)/INSPECTION> for more details.");
+
+  ("inspect_list_applications", (RStructList ("applications", "application"), [Device "root"], []), -1, [],
+   [],
+   "get list of applications installed in the operating system",
+   "\
+This function should only be called with a root device string
+as returned by C<guestfs_inspect_os>.
+
+Return the list of applications installed in the operating system.
+
+I<Note:> This call works differently from other parts of the
+inspection API.  You have to call C<guestfs_inspect_os>, then
+C<guestfs_inspect_get_mountpoints>, then mount up the disks,
+before calling this.  Listing applications is a significantly
+more difficult operation which requires access to the full
+filesystem.  Also note that unlike the other
+C<guestfs_inspect_get_*> calls which are just returning
+data cached in the libguestfs handle, this call actually reads
+parts of the mounted filesystems during the call.
+
+This returns an empty list if the inspection code was not able
+to determine the list of applications.
+
+The application structure contains the following fields:
+
+=over 4
+
+=item C<app_name>
+
+The name of the application.  For Red Hat-derived and Debian-derived
+Linux guests, this is the package name.
+
+=item C<app_display_name>
+
+The display name of the application, sometimes localized to the
+install language of the guest operating system.
+
+If unavailable this is returned as an empty string C<\"\">.
+Callers needing to display something can use C<app_name> instead.
+
+=item C<app_epoch>
+
+For package managers which use epochs, this contains the epoch of
+the package (an integer).  If unavailable, this is returned as C<0>.
+
+=item C<app_version>
+
+The version string of the application or package.  If unavailable
+this is returned as an empty string C<\"\">.
+
+=item C<app_release>
+
+The release string of the application or package, for package
+managers that use this.  If unavailable this is returned as an
+empty string C<\"\">.
+
+=item C<app_install_path>
+
+The installation path of the application (on operating systems
+such as Windows which use installation paths).  This path is
+in the format used by the guest operating system, it is not
+a libguestfs path.
+
+If unavailable this is returned as an empty string C<\"\">.
+
+=item C<app_trans_path>
+
+The install path translated into a libguestfs path.
+If unavailable this is returned as an empty string C<\"\">.
+
+=item C<app_publisher>
+
+The name of the publisher of the application, for package
+managers that use this.  If unavailable this is returned
+as an empty string C<\"\">.
+
+=item C<app_url>
+
+The URL (eg. upstream URL) of the application.
+If unavailable this is returned as an empty string C<\"\">.
+
+=item C<app_source_package>
+
+For packaging systems which support this, the name of the source
+package.  If unavailable this is returned as an empty string C<\"\">.
+
+=item C<app_summary>
+
+A short (usually one line) description of the application or package.
+If unavailable this is returned as an empty string C<\"\">.
+
+=item C<app_description>
+
+A longer description of the application or package.
+If unavailable this is returned as an empty string C<\"\">.
+
+=back
+
+Please read L<guestfs(3)/INSPECTION> for more details.");
+
+  ("inspect_get_hostname", (RString "hostname", [Device "root"], []), -1, [],
+   [],
+   "get hostname of the operating system",
+   "\
+This function should only be called with a root device string
+as returned by C<guestfs_inspect_os>.
+
+This function returns the hostname of the operating system
+as found by inspection of the guest's configuration files.
+
+If the hostname could not be determined, then the
+string C<unknown> is returned.
+
+Please read L<guestfs(3)/INSPECTION> for more details.");
+
 ]
 
 (* daemon_functions are any functions which cause some action
@@ -1085,9 +1342,9 @@ You should always call this if you have modified a disk image, before
 closing the handle.");
 
   ("touch", (RErr, [Pathname "path"], []), 3, [],
-   [InitBasicFS, Always, TestOutputTrue (
-      [["touch"; "/new"];
-       ["exists"; "/new"]])],
+   [InitScratchFS, Always, TestOutputTrue (
+      [["touch"; "/touch"];
+       ["exists"; "/touch"]])],
    "update file timestamps or create a new file",
    "\
 Touch acts like the L<touch(1)> command.  It can be used to
@@ -1122,11 +1379,12 @@ This command is mostly useful for interactive sessions.  It
 is I<not> intended that you try to parse the output string.");
 
   ("ls", (RStringList "listing", [Pathname "directory"], []), 6, [],
-   [InitBasicFS, Always, TestOutputList (
-      [["touch"; "/new"];
-       ["touch"; "/newer"];
-       ["touch"; "/newest"];
-       ["ls"; "/"]], ["lost+found"; "new"; "newer"; "newest"])],
+   [InitScratchFS, Always, TestOutputList (
+      [["mkdir"; "/ls"];
+       ["touch"; "/ls/new"];
+       ["touch"; "/ls/newer"];
+       ["touch"; "/ls/newest"];
+       ["ls"; "/ls"]], ["new"; "newer"; "newest"])],
    "list the files in a directory",
    "\
 List the files in C<directory> (relative to the root directory,
@@ -1149,10 +1407,13 @@ See also C<guestfs_list_filesystems>.");
 
   ("list_partitions", (RStringList "partitions", [], []), 8, [],
    [InitBasicFS, Always, TestOutputListOfDevices (
-      [["list_partitions"]], ["/dev/sda1"]);
+      [["list_partitions"]], ["/dev/sda1"; "/dev/sdb1"]);
     InitEmpty, Always, TestOutputListOfDevices (
-      [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
-       ["list_partitions"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])],
+      [["part_init"; "/dev/sda"; "mbr"];
+       ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
+       ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
+       ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
+       ["list_partitions"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"; "/dev/sdb1"])],
    "list the partitions",
    "\
 List all the partitions detected on all block devices.
@@ -1168,7 +1429,10 @@ See also C<guestfs_list_filesystems>.");
    [InitBasicFSonLVM, Always, TestOutputListOfDevices (
       [["pvs"]], ["/dev/sda1"]);
     InitEmpty, Always, TestOutputListOfDevices (
-      [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
+      [["part_init"; "/dev/sda"; "mbr"];
+       ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
+       ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
+       ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
        ["pvcreate"; "/dev/sda1"];
        ["pvcreate"; "/dev/sda2"];
        ["pvcreate"; "/dev/sda3"];
@@ -1187,7 +1451,10 @@ See also C<guestfs_pvs_full>.");
    [InitBasicFSonLVM, Always, TestOutputList (
       [["vgs"]], ["VG"]);
     InitEmpty, Always, TestOutputList (
-      [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
+      [["part_init"; "/dev/sda"; "mbr"];
+       ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
+       ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
+       ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
        ["pvcreate"; "/dev/sda1"];
        ["pvcreate"; "/dev/sda2"];
        ["pvcreate"; "/dev/sda3"];
@@ -1208,7 +1475,10 @@ See also C<guestfs_vgs_full>.");
    [InitBasicFSonLVM, Always, TestOutputList (
       [["lvs"]], ["/dev/VG/LV"]);
     InitEmpty, Always, TestOutputList (
-      [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
+      [["part_init"; "/dev/sda"; "mbr"];
+       ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
+       ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
+       ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
        ["pvcreate"; "/dev/sda1"];
        ["pvcreate"; "/dev/sda2"];
        ["pvcreate"; "/dev/sda3"];
@@ -1431,38 +1701,40 @@ This is just a shortcut for listing C<guestfs_aug_match>
 C<path/*> and sorting the resulting nodes into alphabetical order.");
 
   ("rm", (RErr, [Pathname "path"], []), 29, [],
-   [InitBasicFS, Always, TestRun
-      [["touch"; "/new"];
-       ["rm"; "/new"]];
-    InitBasicFS, Always, TestLastFail
-      [["rm"; "/new"]];
-    InitBasicFS, Always, TestLastFail
-      [["mkdir"; "/new"];
-       ["rm"; "/new"]]],
+   [InitScratchFS, Always, TestRun
+      [["mkdir"; "/rm"];
+       ["touch"; "/rm/new"];
+       ["rm"; "/rm/new"]];
+    InitScratchFS, Always, TestLastFail
+      [["rm"; "/nosuchfile"]];
+    InitScratchFS, Always, TestLastFail
+      [["mkdir"; "/rm2"];
+       ["rm"; "/rm2"]]],
    "remove a file",
    "\
 Remove the single file C<path>.");
 
   ("rmdir", (RErr, [Pathname "path"], []), 30, [],
-   [InitBasicFS, Always, TestRun
-      [["mkdir"; "/new"];
-       ["rmdir"; "/new"]];
-    InitBasicFS, Always, TestLastFail
-      [["rmdir"; "/new"]];
-    InitBasicFS, Always, TestLastFail
-      [["touch"; "/new"];
-       ["rmdir"; "/new"]]],
+   [InitScratchFS, Always, TestRun
+      [["mkdir"; "/rmdir"];
+       ["rmdir"; "/rmdir"]];
+    InitScratchFS, Always, TestLastFail
+      [["rmdir"; "/rmdir2"]];
+    InitScratchFS, Always, TestLastFail
+      [["mkdir"; "/rmdir3"];
+       ["touch"; "/rmdir3/new"];
+       ["rmdir"; "/rmdir3/new"]]],
    "remove a directory",
    "\
 Remove the single directory C<path>.");
 
   ("rm_rf", (RErr, [Pathname "path"], []), 31, [],
-   [InitBasicFS, Always, TestOutputFalse
-      [["mkdir"; "/new"];
-       ["mkdir"; "/new/foo"];
-       ["touch"; "/new/foo/bar"];
-       ["rm_rf"; "/new"];
-       ["exists"; "/new"]]],
+   [InitScratchFS, Always, TestOutputFalse
+      [["mkdir"; "/rm_rf"];
+       ["mkdir"; "/rm_rf/foo"];
+       ["touch"; "/rm_rf/foo/bar"];
+       ["rm_rf"; "/rm_rf"];
+       ["exists"; "/rm_rf"]]],
    "remove a file or directory recursively",
    "\
 Remove the file or directory C<path>, recursively removing the
@@ -1470,32 +1742,32 @@ contents if its a directory.  This is like the C<rm -rf> shell
 command.");
 
   ("mkdir", (RErr, [Pathname "path"], []), 32, [],
-   [InitBasicFS, Always, TestOutputTrue
-      [["mkdir"; "/new"];
-       ["is_dir"; "/new"]];
-    InitBasicFS, Always, TestLastFail
-      [["mkdir"; "/new/foo/bar"]]],
+   [InitScratchFS, Always, TestOutputTrue
+      [["mkdir"; "/mkdir"];
+       ["is_dir"; "/mkdir"]];
+    InitScratchFS, Always, TestLastFail
+      [["mkdir"; "/mkdir2/foo/bar"]]],
    "create a directory",
    "\
 Create a directory named C<path>.");
 
   ("mkdir_p", (RErr, [Pathname "path"], []), 33, [],
-   [InitBasicFS, Always, TestOutputTrue
-      [["mkdir_p"; "/new/foo/bar"];
-       ["is_dir"; "/new/foo/bar"]];
-    InitBasicFS, Always, TestOutputTrue
-      [["mkdir_p"; "/new/foo/bar"];
-       ["is_dir"; "/new/foo"]];
-    InitBasicFS, Always, TestOutputTrue
-      [["mkdir_p"; "/new/foo/bar"];
-       ["is_dir"; "/new"]];
+   [InitScratchFS, Always, TestOutputTrue
+      [["mkdir_p"; "/mkdir_p/foo/bar"];
+       ["is_dir"; "/mkdir_p/foo/bar"]];
+    InitScratchFS, Always, TestOutputTrue
+      [["mkdir_p"; "/mkdir_p2/foo/bar"];
+       ["is_dir"; "/mkdir_p2/foo"]];
+    InitScratchFS, Always, TestOutputTrue
+      [["mkdir_p"; "/mkdir_p3/foo/bar"];
+       ["is_dir"; "/mkdir_p3"]];
     (* Regression tests for RHBZ#503133: *)
-    InitBasicFS, Always, TestRun
-      [["mkdir"; "/new"];
-       ["mkdir_p"; "/new"]];
-    InitBasicFS, Always, TestLastFail
-      [["touch"; "/new"];
-       ["mkdir_p"; "/new"]]],
+    InitScratchFS, Always, TestRun
+      [["mkdir"; "/mkdir_p4"];
+       ["mkdir_p"; "/mkdir_p4"]];
+    InitScratchFS, Always, TestLastFail
+      [["touch"; "/mkdir_p5"];
+       ["mkdir_p"; "/mkdir_p5"]]],
    "create a directory and parents",
    "\
 Create a directory named C<path>, creating any parent directories
@@ -1564,7 +1836,10 @@ See also C<guestfs_stat>.");
 
   ("pvcreate", (RErr, [Device "device"], []), 39, [Optional "lvm2"],
    [InitEmpty, Always, TestOutputListOfDevices (
-      [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
+      [["part_init"; "/dev/sda"; "mbr"];
+       ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
+       ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
+       ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
        ["pvcreate"; "/dev/sda1"];
        ["pvcreate"; "/dev/sda2"];
        ["pvcreate"; "/dev/sda3"];
@@ -1577,7 +1852,10 @@ as C</dev/sda1>.");
 
   ("vgcreate", (RErr, [String "volgroup"; DeviceList "physvols"], []), 40, [Optional "lvm2"],
    [InitEmpty, Always, TestOutputList (
-      [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
+      [["part_init"; "/dev/sda"; "mbr"];
+       ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
+       ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
+       ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
        ["pvcreate"; "/dev/sda1"];
        ["pvcreate"; "/dev/sda2"];
        ["pvcreate"; "/dev/sda3"];
@@ -1591,7 +1869,10 @@ from the non-empty list of physical volumes C<physvols>.");
 
   ("lvcreate", (RErr, [String "logvol"; String "volgroup"; Int "mbytes"], []), 41, [Optional "lvm2"],
    [InitEmpty, Always, TestOutputList (
-      [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
+      [["part_init"; "/dev/sda"; "mbr"];
+       ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
+       ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
+       ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
        ["pvcreate"; "/dev/sda1"];
        ["pvcreate"; "/dev/sda2"];
        ["pvcreate"; "/dev/sda3"];
@@ -1654,8 +1935,8 @@ C<guestfs_part_init>");
 
   ("write_file", (RErr, [Pathname "path"; String "content"; Int "size"], []), 44, [ProtocolLimitWarning; DeprecatedBy "write"],
    (* Regression test for RHBZ#597135. *)
-   [InitBasicFS, Always, TestLastFail
-      [["write_file"; "/new"; "abc"; "10000"]]],
+   [InitScratchFS, Always, TestLastFail
+      [["write_file"; "/write_file"; "abc"; "10000"]]],
    "create a file",
    "\
 This call creates a file called C<path>.  The contents of the
@@ -1688,8 +1969,8 @@ specified either by its mountpoint (path) or the device which
 contains the filesystem.");
 
   ("mounts", (RStringList "devices", [], []), 46, [],
-   [InitBasicFS, Always, TestOutputListOfDevices (
-      [["mounts"]], ["/dev/sda1"])],
+   [InitScratchFS, Always, TestOutputListOfDevices (
+      [["mounts"]], ["/dev/sdb1"])],
    "show mounted filesystems",
    "\
 This returns the list of currently mounted filesystems.  It returns
@@ -1700,12 +1981,15 @@ Some internal mounts are not shown.
 See also: C<guestfs_mountpoints>");
 
   ("umount_all", (RErr, [], []), 47, [FishAlias "unmount-all"],
-   [InitBasicFS, Always, TestOutputList (
+   [InitScratchFS, Always, TestOutputList (
       [["umount_all"];
        ["mounts"]], []);
     (* check that umount_all can unmount nested mounts correctly: *)
     InitEmpty, Always, TestOutputList (
-      [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
+      [["part_init"; "/dev/sda"; "mbr"];
+       ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
+       ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
+       ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
        ["mkfs"; "ext2"; "/dev/sda1"];
        ["mkfs"; "ext2"; "/dev/sda2"];
        ["mkfs"; "ext2"; "/dev/sda3"];
@@ -1764,54 +2048,66 @@ For other file types (directory, symbolic link etc) it
 will just return the string C<directory> etc.");
 
   ("command", (RString "output", [StringList "arguments"], []), 50, [ProtocolLimitWarning],
-   [InitBasicFS, Always, TestOutput (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command"; "/test-command 1"]], "Result1");
-    InitBasicFS, Always, TestOutput (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command"; "/test-command 2"]], "Result2\n");
-    InitBasicFS, Always, TestOutput (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command"; "/test-command 3"]], "\nResult3");
-    InitBasicFS, Always, TestOutput (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command"; "/test-command 4"]], "\nResult4\n");
-    InitBasicFS, Always, TestOutput (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command"; "/test-command 5"]], "\nResult5\n\n");
-    InitBasicFS, Always, TestOutput (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command"; "/test-command 6"]], "\n\nResult6\n\n");
-    InitBasicFS, Always, TestOutput (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command"; "/test-command 7"]], "");
-    InitBasicFS, Always, TestOutput (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command"; "/test-command 8"]], "\n");
-    InitBasicFS, Always, TestOutput (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command"; "/test-command 9"]], "\n\n");
-    InitBasicFS, Always, TestOutput (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command"; "/test-command 10"]], "Result10-1\nResult10-2\n");
-    InitBasicFS, Always, TestOutput (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command"; "/test-command 11"]], "Result11-1\nResult11-2");
-    InitBasicFS, Always, TestLastFail (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command"; "/test-command"]])],
+   [InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/command"];
+       ["upload"; "test-command"; "/command/test-command"];
+       ["chmod"; "0o755"; "/command/test-command"];
+       ["command"; "/command/test-command 1"]], "Result1");
+    InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/command2"];
+       ["upload"; "test-command"; "/command2/test-command"];
+       ["chmod"; "0o755"; "/command2/test-command"];
+       ["command"; "/command2/test-command 2"]], "Result2\n");
+    InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/command3"];
+       ["upload"; "test-command"; "/command3/test-command"];
+       ["chmod"; "0o755"; "/command3/test-command"];
+       ["command"; "/command3/test-command 3"]], "\nResult3");
+    InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/command4"];
+       ["upload"; "test-command"; "/command4/test-command"];
+       ["chmod"; "0o755"; "/command4/test-command"];
+       ["command"; "/command4/test-command 4"]], "\nResult4\n");
+    InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/command5"];
+       ["upload"; "test-command"; "/command5/test-command"];
+       ["chmod"; "0o755"; "/command5/test-command"];
+       ["command"; "/command5/test-command 5"]], "\nResult5\n\n");
+    InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/command6"];
+       ["upload"; "test-command"; "/command6/test-command"];
+       ["chmod"; "0o755"; "/command6/test-command"];
+       ["command"; "/command6/test-command 6"]], "\n\nResult6\n\n");
+    InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/command7"];
+       ["upload"; "test-command"; "/command7/test-command"];
+       ["chmod"; "0o755"; "/command7/test-command"];
+       ["command"; "/command7/test-command 7"]], "");
+    InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/command8"];
+       ["upload"; "test-command"; "/command8/test-command"];
+       ["chmod"; "0o755"; "/command8/test-command"];
+       ["command"; "/command8/test-command 8"]], "\n");
+    InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/command9"];
+       ["upload"; "test-command"; "/command9/test-command"];
+       ["chmod"; "0o755"; "/command9/test-command"];
+       ["command"; "/command9/test-command 9"]], "\n\n");
+    InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/command10"];
+       ["upload"; "test-command"; "/command10/test-command"];
+       ["chmod"; "0o755"; "/command10/test-command"];
+       ["command"; "/command10/test-command 10"]], "Result10-1\nResult10-2\n");
+    InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/command11"];
+       ["upload"; "test-command"; "/command11/test-command"];
+       ["chmod"; "0o755"; "/command11/test-command"];
+       ["command"; "/command11/test-command 11"]], "Result11-1\nResult11-2");
+    InitScratchFS, Always, TestLastFail (
+      [["mkdir"; "/command12"];
+       ["upload"; "test-command"; "/command12/test-command"];
+       ["chmod"; "0o755"; "/command12/test-command"];
+       ["command"; "/command12/test-command"]])],
    "run a command from the guest filesystem",
    "\
 This call runs a command from the guest filesystem.  The
@@ -1845,50 +2141,61 @@ all filesystems that are needed are mounted at the right
 locations.");
 
   ("command_lines", (RStringList "lines", [StringList "arguments"], []), 51, [ProtocolLimitWarning],
-   [InitBasicFS, Always, TestOutputList (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command_lines"; "/test-command 1"]], ["Result1"]);
-    InitBasicFS, Always, TestOutputList (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command_lines"; "/test-command 2"]], ["Result2"]);
-    InitBasicFS, Always, TestOutputList (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command_lines"; "/test-command 3"]], ["";"Result3"]);
-    InitBasicFS, Always, TestOutputList (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command_lines"; "/test-command 4"]], ["";"Result4"]);
-    InitBasicFS, Always, TestOutputList (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command_lines"; "/test-command 5"]], ["";"Result5";""]);
-    InitBasicFS, Always, TestOutputList (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command_lines"; "/test-command 6"]], ["";"";"Result6";""]);
-    InitBasicFS, Always, TestOutputList (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command_lines"; "/test-command 7"]], []);
-    InitBasicFS, Always, TestOutputList (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command_lines"; "/test-command 8"]], [""]);
-    InitBasicFS, Always, TestOutputList (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command_lines"; "/test-command 9"]], ["";""]);
-    InitBasicFS, Always, TestOutputList (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command_lines"; "/test-command 10"]], ["Result10-1";"Result10-2"]);
-    InitBasicFS, Always, TestOutputList (
-      [["upload"; "test-command"; "/test-command"];
-       ["chmod"; "0o755"; "/test-command"];
-       ["command_lines"; "/test-command 11"]], ["Result11-1";"Result11-2"])],
+   [InitScratchFS, Always, TestOutputList (
+      [["mkdir"; "/command_lines"];
+       ["upload"; "test-command"; "/command_lines/test-command"];
+       ["chmod"; "0o755"; "/command_lines/test-command"];
+       ["command_lines"; "/command_lines/test-command 1"]], ["Result1"]);
+    InitScratchFS, Always, TestOutputList (
+      [["mkdir"; "/command_lines2"];
+       ["upload"; "test-command"; "/command_lines2/test-command"];
+       ["chmod"; "0o755"; "/command_lines2/test-command"];
+       ["command_lines"; "/command_lines2/test-command 2"]], ["Result2"]);
+    InitScratchFS, Always, TestOutputList (
+      [["mkdir"; "/command_lines3"];
+       ["upload"; "test-command"; "/command_lines3/test-command"];
+       ["chmod"; "0o755"; "/command_lines3/test-command"];
+       ["command_lines"; "/command_lines3/test-command 3"]], ["";"Result3"]);
+    InitScratchFS, Always, TestOutputList (
+      [["mkdir"; "/command_lines4"];
+       ["upload"; "test-command"; "/command_lines4/test-command"];
+       ["chmod"; "0o755"; "/command_lines4/test-command"];
+       ["command_lines"; "/command_lines4/test-command 4"]], ["";"Result4"]);
+    InitScratchFS, Always, TestOutputList (
+      [["mkdir"; "/command_lines5"];
+       ["upload"; "test-command"; "/command_lines5/test-command"];
+       ["chmod"; "0o755"; "/command_lines5/test-command"];
+       ["command_lines"; "/command_lines5/test-command 5"]], ["";"Result5";""]);
+    InitScratchFS, Always, TestOutputList (
+      [["mkdir"; "/command_lines6"];
+       ["upload"; "test-command"; "/command_lines6/test-command"];
+       ["chmod"; "0o755"; "/command_lines6/test-command"];
+       ["command_lines"; "/command_lines6/test-command 6"]], ["";"";"Result6";""]);
+    InitScratchFS, Always, TestOutputList (
+      [["mkdir"; "/command_lines7"];
+       ["upload"; "test-command"; "/command_lines7/test-command"];
+       ["chmod"; "0o755"; "/command_lines7/test-command"];
+       ["command_lines"; "/command_lines7/test-command 7"]], []);
+    InitScratchFS, Always, TestOutputList (
+      [["mkdir"; "/command_lines8"];
+       ["upload"; "test-command"; "/command_lines8/test-command"];
+       ["chmod"; "0o755"; "/command_lines8/test-command"];
+       ["command_lines"; "/command_lines8/test-command 8"]], [""]);
+    InitScratchFS, Always, TestOutputList (
+      [["mkdir"; "/command_lines9"];
+       ["upload"; "test-command"; "/command_lines9/test-command"];
+       ["chmod"; "0o755"; "/command_lines9/test-command"];
+       ["command_lines"; "/command_lines9/test-command 9"]], ["";""]);
+    InitScratchFS, Always, TestOutputList (
+      [["mkdir"; "/command_lines10"];
+       ["upload"; "test-command"; "/command_lines10/test-command"];
+       ["chmod"; "0o755"; "/command_lines10/test-command"];
+       ["command_lines"; "/command_lines10/test-command 10"]], ["Result10-1";"Result10-2"]);
+    InitScratchFS, Always, TestOutputList (
+      [["mkdir"; "/command_lines11"];
+       ["upload"; "test-command"; "/command_lines11/test-command"];
+       ["chmod"; "0o755"; "/command_lines11/test-command"];
+       ["command_lines"; "/command_lines11/test-command 11"]], ["Result11-1";"Result11-2"])],
    "run a command, returning lines",
    "\
 This is the same as C<guestfs_command>, but splits the
@@ -2052,11 +2359,12 @@ Reread the partition table on C<device>.
 
 This uses the L<blockdev(8)> command.");
 
-  ("upload", (RErr, [FileIn "filename"; Dev_or_Path "remotefilename"], []), 66, [],
-   [InitBasicFS, Always, TestOutput (
+  ("upload", (RErr, [FileIn "filename"; Dev_or_Path "remotefilename"], []), 66, [Progress],
+   [InitScratchFS, Always, TestOutput (
       (* Pick a file from cwd which isn't likely to change. *)
-      [["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
-       ["checksum"; "md5"; "/COPYING.LIB"]],
+      [["mkdir"; "/upload"];
+       ["upload"; "../COPYING.LIB"; "/upload/COPYING.LIB"];
+       ["checksum"; "md5"; "/upload/COPYING.LIB"]],
       Digest.to_hex (Digest.file "COPYING.LIB"))],
    "upload a file from the local machine",
    "\
@@ -2068,12 +2376,13 @@ C<filename> can also be a named pipe.
 See also C<guestfs_download>.");
 
   ("download", (RErr, [Dev_or_Path "remotefilename"; FileOut "filename"], []), 67, [Progress],
-   [InitBasicFS, Always, TestOutput (
+   [InitScratchFS, Always, TestOutput (
       (* Pick a file from cwd which isn't likely to change. *)
-      [["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
-       ["download"; "/COPYING.LIB"; "testdownload.tmp"];
-       ["upload"; "testdownload.tmp"; "/upload"];
-       ["checksum"; "md5"; "/upload"]],
+      [["mkdir"; "/download"];
+       ["upload"; "../COPYING.LIB"; "/download/COPYING.LIB"];
+       ["download"; "/download/COPYING.LIB"; "testdownload.tmp"];
+       ["upload"; "testdownload.tmp"; "/download/upload"];
+       ["checksum"; "md5"; "/download/upload"]],
       Digest.to_hex (Digest.file "COPYING.LIB"))],
    "download a file to the local machine",
    "\
@@ -2152,9 +2461,10 @@ To get the checksum for a device, use C<guestfs_checksum_device>.
 To get the checksums for many files, use C<guestfs_checksums_out>.");
 
   ("tar_in", (RErr, [FileIn "tarfile"; Pathname "directory"], []), 69, [],
-   [InitBasicFS, Always, TestOutput (
-      [["tar_in"; "../images/helloworld.tar"; "/"];
-       ["cat"; "/hello"]], "hello\n")],
+   [InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/tar_in"];
+       ["tar_in"; "../images/helloworld.tar"; "/tar_in"];
+       ["cat"; "/tar_in/hello"]], "hello\n")],
    "unpack tarfile to directory",
    "\
 This command uploads and unpacks local file C<tarfile> (an
@@ -2174,9 +2484,10 @@ To download a compressed tarball, use C<guestfs_tgz_out>
 or C<guestfs_txz_out>.");
 
   ("tgz_in", (RErr, [FileIn "tarball"; Pathname "directory"], []), 71, [],
-   [InitBasicFS, Always, TestOutput (
-      [["tgz_in"; "../images/helloworld.tar.gz"; "/"];
-       ["cat"; "/hello"]], "hello\n")],
+   [InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/tgz_in"];
+       ["tgz_in"; "../images/helloworld.tar.gz"; "/tgz_in"];
+       ["cat"; "/tgz_in/hello"]], "hello\n")],
    "unpack compressed tarball to directory",
    "\
 This command uploads and unpacks local file C<tarball> (a
@@ -2228,7 +2539,7 @@ This is the same as the C<guestfs_mount> command, but it
 allows you to set both the mount options and the vfstype
 as for the L<mount(8)> I<-o> and I<-t> flags.");
 
-  ("debug", (RString "result", [String "subcmd"; StringList "extraargs"], []), 76, [],
+  ("debug", (RString "result", [String "subcmd"; StringList "extraargs"], []), 76, [NotInDocs],
    [],
    "debugging and internals",
    "\
@@ -2380,10 +2691,10 @@ to return the existing UUID of a filesystem.");
   ("get_e2uuid", (RString "uuid", [Device "device"], []), 83, [DeprecatedBy "vfs_uuid"],
    (* Regression test for RHBZ#597112. *)
    (let uuid = uuidgen () in
-    [InitBasicFS, Always, TestOutput (
-       [["mke2journal"; "1024"; "/dev/sdb"];
-        ["set_e2uuid"; "/dev/sdb"; uuid];
-        ["get_e2uuid"; "/dev/sdb"]], uuid)]),
+    [InitNone, Always, TestOutput (
+       [["mke2journal"; "1024"; "/dev/sdc"];
+        ["set_e2uuid"; "/dev/sdc"; uuid];
+        ["get_e2uuid"; "/dev/sdc"]], uuid)]),
    "get the ext2/3/4 filesystem UUID",
    "\
 This returns the ext2/3/4 filesystem UUID of the filesystem on
@@ -2469,45 +2780,50 @@ a file containing:
 replacing C</dev/vda> with the name of the installation device.");
 
   ("cp", (RErr, [Pathname "src"; Pathname "dest"], []), 87, [],
-   [InitBasicFS, Always, TestOutput (
-      [["write"; "/old"; "file content"];
-       ["cp"; "/old"; "/new"];
-       ["cat"; "/new"]], "file content");
-    InitBasicFS, Always, TestOutputTrue (
-      [["write"; "/old"; "file content"];
-       ["cp"; "/old"; "/new"];
-       ["is_file"; "/old"]]);
-    InitBasicFS, Always, TestOutput (
-      [["write"; "/old"; "file content"];
-       ["mkdir"; "/dir"];
-       ["cp"; "/old"; "/dir/new"];
-       ["cat"; "/dir/new"]], "file content")],
+   [InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/cp"];
+       ["write"; "/cp/old"; "file content"];
+       ["cp"; "/cp/old"; "/cp/new"];
+       ["cat"; "/cp/new"]], "file content");
+    InitScratchFS, Always, TestOutputTrue (
+      [["mkdir"; "/cp2"];
+       ["write"; "/cp2/old"; "file content"];
+       ["cp"; "/cp2/old"; "/cp2/new"];
+       ["is_file"; "/cp2/old"]]);
+    InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/cp3"];
+       ["write"; "/cp3/old"; "file content"];
+       ["mkdir"; "/cp3/dir"];
+       ["cp"; "/cp3/old"; "/cp3/dir/new"];
+       ["cat"; "/cp3/dir/new"]], "file content")],
    "copy a file",
    "\
 This copies a file from C<src> to C<dest> where C<dest> is
 either a destination filename or destination directory.");
 
   ("cp_a", (RErr, [Pathname "src"; Pathname "dest"], []), 88, [],
-   [InitBasicFS, Always, TestOutput (
-      [["mkdir"; "/olddir"];
-       ["mkdir"; "/newdir"];
-       ["write"; "/olddir/file"; "file content"];
-       ["cp_a"; "/olddir"; "/newdir"];
-       ["cat"; "/newdir/olddir/file"]], "file content")],
+   [InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/cp_a1"];
+       ["mkdir"; "/cp_a2"];
+       ["write"; "/cp_a1/file"; "file content"];
+       ["cp_a"; "/cp_a1"; "/cp_a2"];
+       ["cat"; "/cp_a2/cp_a1/file"]], "file content")],
    "copy a file or directory recursively",
    "\
 This copies a file or directory from C<src> to C<dest>
 recursively using the C<cp -a> command.");
 
   ("mv", (RErr, [Pathname "src"; Pathname "dest"], []), 89, [],
-   [InitBasicFS, Always, TestOutput (
-      [["write"; "/old"; "file content"];
-       ["mv"; "/old"; "/new"];
-       ["cat"; "/new"]], "file content");
-    InitBasicFS, Always, TestOutputFalse (
-      [["write"; "/old"; "file content"];
-       ["mv"; "/old"; "/new"];
-       ["is_file"; "/old"]])],
+   [InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/mv"];
+       ["write"; "/mv/old"; "file content"];
+       ["mv"; "/mv/old"; "/mv/new"];
+       ["cat"; "/mv/new"]], "file content");
+    InitScratchFS, Always, TestOutputFalse (
+      [["mkdir"; "/mv2"];
+       ["write"; "/mv2/old"; "file content"];
+       ["mv"; "/mv2/old"; "/mv2/new"];
+       ["is_file"; "/mv2/old"]])],
    "move a file",
    "\
 This moves a file from C<src> to C<dest> where C<dest> is
@@ -2553,16 +2869,19 @@ daemon responds to the ping message, without affecting the daemon
 or attached block device(s) in any other way.");
 
   ("equal", (RBool "equality", [Pathname "file1"; Pathname "file2"], []), 93, [],
-   [InitBasicFS, Always, TestOutputTrue (
-      [["write"; "/file1"; "contents of a file"];
-       ["cp"; "/file1"; "/file2"];
-       ["equal"; "/file1"; "/file2"]]);
-    InitBasicFS, Always, TestOutputFalse (
-      [["write"; "/file1"; "contents of a file"];
-       ["write"; "/file2"; "contents of another file"];
-       ["equal"; "/file1"; "/file2"]]);
-    InitBasicFS, Always, TestLastFail (
-      [["equal"; "/file1"; "/file2"]])],
+   [InitScratchFS, Always, TestOutputTrue (
+      [["mkdir"; "/equal"];
+       ["write"; "/equal/file1"; "contents of a file"];
+       ["cp"; "/equal/file1"; "/equal/file2"];
+       ["equal"; "/equal/file1"; "/equal/file2"]]);
+    InitScratchFS, Always, TestOutputFalse (
+      [["mkdir"; "/equal2"];
+       ["write"; "/equal2/file1"; "contents of a file"];
+       ["write"; "/equal2/file2"; "contents of another file"];
+       ["equal"; "/equal2/file1"; "/equal2/file2"]]);
+    InitScratchFS, Always, TestLastFail (
+      [["mkdir"; "/equal3"];
+       ["equal"; "/equal3/file1"; "/equal3/file2"]])],
    "test if two files have equal contents",
    "\
 This compares the two files C<file1> and C<file2> and returns
@@ -2586,9 +2905,9 @@ the list of printable strings found.");
   ("strings_e", (RStringList "stringsout", [String "encoding"; Pathname "path"], []), 95, [ProtocolLimitWarning],
    [InitISOFS, Always, TestOutputList (
       [["strings_e"; "b"; "/known-5"]], []);
-    InitBasicFS, Always, TestOutputList (
-      [["write"; "/new"; "\000h\000e\000l\000l\000o\000\n\000w\000o\000r\000l\000d\000\n"];
-       ["strings_e"; "b"; "/new"]], ["hello"; "world"])],
+    InitScratchFS, Always, TestOutputList (
+      [["write"; "/strings_e"; "\000h\000e\000l\000l\000o\000\n\000w\000o\000r\000l\000d\000\n"];
+       ["strings_e"; "b"; "/strings_e"]], ["hello"; "world"])],
    "print the printable strings in a file",
    "\
 This is like the C<guestfs_strings> command, but allows you to
@@ -2797,10 +3116,10 @@ calling this function.");
        ["mkdir"; "/b"];
        ["touch"; "/b/c"];
        ["find"; "/"]], ["a"; "b"; "b/c"; "lost+found"]);
-    InitBasicFS, Always, TestOutputList (
-      [["mkdir_p"; "/a/b/c"];
-       ["touch"; "/a/b/c/d"];
-       ["find"; "/a/b/"]], ["c"; "c/d"])],
+    InitScratchFS, Always, TestOutputList (
+      [["mkdir_p"; "/find/b/c"];
+       ["touch"; "/find/b/c/d"];
+       ["find"; "/find/b/"]], ["c"; "c/d"])],
    "find all files and directories",
    "\
 This command lists out all files and directories, recursively,
@@ -2902,21 +3221,21 @@ See also: C<guestfs_command_lines>");
     * code in stubs.c, since all valid glob patterns must start with "/".
     * There is no concept of "cwd" in libguestfs, hence no "."-relative names.
     *)
-   [InitBasicFS, Always, TestOutputList (
-      [["mkdir_p"; "/a/b/c"];
-       ["touch"; "/a/b/c/d"];
-       ["touch"; "/a/b/c/e"];
-       ["glob_expand"; "/a/b/c/*"]], ["/a/b/c/d"; "/a/b/c/e"]);
-    InitBasicFS, Always, TestOutputList (
-      [["mkdir_p"; "/a/b/c"];
-       ["touch"; "/a/b/c/d"];
-       ["touch"; "/a/b/c/e"];
-       ["glob_expand"; "/a/*/c/*"]], ["/a/b/c/d"; "/a/b/c/e"]);
-    InitBasicFS, Always, TestOutputList (
-      [["mkdir_p"; "/a/b/c"];
-       ["touch"; "/a/b/c/d"];
-       ["touch"; "/a/b/c/e"];
-       ["glob_expand"; "/a/*/x/*"]], [])],
+   [InitScratchFS, Always, TestOutputList (
+      [["mkdir_p"; "/glob_expand/b/c"];
+       ["touch"; "/glob_expand/b/c/d"];
+       ["touch"; "/glob_expand/b/c/e"];
+       ["glob_expand"; "/glob_expand/b/c/*"]], ["/glob_expand/b/c/d"; "/glob_expand/b/c/e"]);
+    InitScratchFS, Always, TestOutputList (
+      [["mkdir_p"; "/glob_expand2/b/c"];
+       ["touch"; "/glob_expand2/b/c/d"];
+       ["touch"; "/glob_expand2/b/c/e"];
+       ["glob_expand"; "/glob_expand2/*/c/*"]], ["/glob_expand2/b/c/d"; "/glob_expand2/b/c/e"]);
+    InitScratchFS, Always, TestOutputList (
+      [["mkdir_p"; "/glob_expand3/b/c"];
+       ["touch"; "/glob_expand3/b/c/d"];
+       ["touch"; "/glob_expand3/b/c/e"];
+       ["glob_expand"; "/glob_expand3/*/x/*"]], [])],
    "expand a wildcard path",
    "\
 This command searches for all the pathnames matching
@@ -2942,9 +3261,9 @@ It is an interface to the L<scrub(1)> program.  See that
 manual page for more details.");
 
   ("scrub_file", (RErr, [Pathname "file"], []), 115, [Optional "scrub"],
-   [InitBasicFS, Always, TestRun (
-      [["write"; "/file"; "content"];
-       ["scrub_file"; "/file"]])],
+   [InitScratchFS, Always, TestRun (
+      [["write"; "/scrub_file"; "content"];
+       ["scrub_file"; "/scrub_file"]])],
    "scrub (securely wipe) a file",
    "\
 This command writes patterns over a file to make data retrieval
@@ -2969,9 +3288,9 @@ It is an interface to the L<scrub(1)> program.  See that
 manual page for more details.");
 
   ("mkdtemp", (RString "dir", [Pathname "template"], []), 117, [],
-   [InitBasicFS, Always, TestRun (
-      [["mkdir"; "/tmp"];
-       ["mkdtemp"; "/tmp/tmpXXXXXX"]])],
+   [InitScratchFS, Always, TestRun (
+      [["mkdir"; "/mkdtemp"];
+       ["mkdtemp"; "/mkdtemp/tmpXXXXXX"]])],
    "create a temporary directory",
    "\
 This command creates a temporary directory.  The
@@ -3166,13 +3485,13 @@ a limitation of the kernel or swap tools.");
 Create a swap partition on C<device> with UUID C<uuid>.");
 
   ("mknod", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"], []), 133, [Optional "mknod"],
-   [InitBasicFS, Always, TestOutputStruct (
-      [["mknod"; "0o10777"; "0"; "0"; "/node"];
+   [InitScratchFS, Always, TestOutputStruct (
+      [["mknod"; "0o10777"; "0"; "0"; "/mknod"];
        (* NB: default umask 022 means 0777 -> 0755 in these tests *)
-       ["stat"; "/node"]], [CompareWithInt ("mode", 0o10755)]);
-    InitBasicFS, Always, TestOutputStruct (
-      [["mknod"; "0o60777"; "66"; "99"; "/node"];
-       ["stat"; "/node"]], [CompareWithInt ("mode", 0o60755)])],
+       ["stat"; "/mknod"]], [CompareWithInt ("mode", 0o10755)]);
+    InitScratchFS, Always, TestOutputStruct (
+      [["mknod"; "0o60777"; "66"; "99"; "/mknod2"];
+       ["stat"; "/mknod2"]], [CompareWithInt ("mode", 0o60755)])],
    "make block, character or FIFO devices",
    "\
 This call creates block or character special devices, or
@@ -3194,9 +3513,9 @@ in the appropriate constant for you.
 The mode actually set is affected by the umask.");
 
   ("mkfifo", (RErr, [Int "mode"; Pathname "path"], []), 134, [Optional "mknod"],
-   [InitBasicFS, Always, TestOutputStruct (
-      [["mkfifo"; "0o777"; "/node"];
-       ["stat"; "/node"]], [CompareWithInt ("mode", 0o10755)])],
+   [InitScratchFS, Always, TestOutputStruct (
+      [["mkfifo"; "0o777"; "/mkfifo"];
+       ["stat"; "/mkfifo"]], [CompareWithInt ("mode", 0o10755)])],
    "make FIFO (named pipe)",
    "\
 This call creates a FIFO (named pipe) called C<path> with
@@ -3206,9 +3525,9 @@ C<guestfs_mknod>.
 The mode actually set is affected by the umask.");
 
   ("mknod_b", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"], []), 135, [Optional "mknod"],
-   [InitBasicFS, Always, TestOutputStruct (
-      [["mknod_b"; "0o777"; "99"; "66"; "/node"];
-       ["stat"; "/node"]], [CompareWithInt ("mode", 0o60755)])],
+   [InitScratchFS, Always, TestOutputStruct (
+      [["mknod_b"; "0o777"; "99"; "66"; "/mknod_b"];
+       ["stat"; "/mknod_b"]], [CompareWithInt ("mode", 0o60755)])],
    "make block device node",
    "\
 This call creates a block device node called C<path> with
@@ -3218,9 +3537,9 @@ It is just a convenient wrapper around C<guestfs_mknod>.
 The mode actually set is affected by the umask.");
 
   ("mknod_c", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"], []), 136, [Optional "mknod"],
-   [InitBasicFS, Always, TestOutputStruct (
-      [["mknod_c"; "0o777"; "99"; "66"; "/node"];
-       ["stat"; "/node"]], [CompareWithInt ("mode", 0o20755)])],
+   [InitScratchFS, Always, TestOutputStruct (
+      [["mknod_c"; "0o777"; "99"; "66"; "/mknod_c"];
+       ["stat"; "/mknod_c"]], [CompareWithInt ("mode", 0o20755)])],
    "make char device node",
    "\
 This call creates a char device node called C<path> with
@@ -3461,18 +3780,18 @@ for full details.");
    [InitISOFS, Always, TestOutputBuffer (
       [["read_file"; "/known-4"]], "abc\ndef\nghi");
     (* Test various near large, large and too large files (RHBZ#589039). *)
-    InitBasicFS, Always, TestLastFail (
-      [["touch"; "/a"];
-       ["truncate_size"; "/a"; "4194303"]; (* GUESTFS_MESSAGE_MAX - 1 *)
-       ["read_file"; "/a"]]);
-    InitBasicFS, Always, TestLastFail (
-      [["touch"; "/a"];
-       ["truncate_size"; "/a"; "4194304"]; (* GUESTFS_MESSAGE_MAX *)
-       ["read_file"; "/a"]]);
-    InitBasicFS, Always, TestLastFail (
-      [["touch"; "/a"];
-       ["truncate_size"; "/a"; "41943040"]; (* GUESTFS_MESSAGE_MAX * 10 *)
-       ["read_file"; "/a"]])],
+    InitScratchFS, Always, TestLastFail (
+      [["touch"; "/read_file"];
+       ["truncate_size"; "/read_file"; "4194303"]; (* GUESTFS_MESSAGE_MAX - 1 *)
+       ["read_file"; "/read_file"]]);
+    InitScratchFS, Always, TestLastFail (
+      [["touch"; "/read_file2"];
+       ["truncate_size"; "/read_file2"; "4194304"]; (* GUESTFS_MESSAGE_MAX *)
+       ["read_file"; "/read_file2"]]);
+    InitScratchFS, Always, TestLastFail (
+      [["touch"; "/read_file3"];
+       ["truncate_size"; "/read_file3"; "41943040"]; (* GUESTFS_MESSAGE_MAX * 10 *)
+       ["read_file"; "/read_file3"]])],
    "read a file",
    "\
 This calls returns the contents of the file C<path> as a
@@ -3593,40 +3912,43 @@ Return the canonicalized absolute pathname of C<path>.  The
 returned path has no C<.>, C<..> or symbolic link path elements.");
 
   ("ln", (RErr, [String "target"; Pathname "linkname"], []), 164, [],
-   [InitBasicFS, Always, TestOutputStruct (
-      [["touch"; "/a"];
-       ["ln"; "/a"; "/b"];
-       ["stat"; "/b"]], [CompareWithInt ("nlink", 2)])],
+   [InitScratchFS, Always, TestOutputStruct (
+      [["mkdir"; "/ln"];
+       ["touch"; "/ln/a"];
+       ["ln"; "/ln/a"; "/ln/b"];
+       ["stat"; "/ln/b"]], [CompareWithInt ("nlink", 2)])],
    "create a hard link",
    "\
 This command creates a hard link using the C<ln> command.");
 
   ("ln_f", (RErr, [String "target"; Pathname "linkname"], []), 165, [],
-   [InitBasicFS, Always, TestOutputStruct (
-      [["touch"; "/a"];
-       ["touch"; "/b"];
-       ["ln_f"; "/a"; "/b"];
-       ["stat"; "/b"]], [CompareWithInt ("nlink", 2)])],
+   [InitScratchFS, Always, TestOutputStruct (
+      [["mkdir"; "/ln_f"];
+       ["touch"; "/ln_f/a"];
+       ["touch"; "/ln_f/b"];
+       ["ln_f"; "/ln_f/a"; "/ln_f/b"];
+       ["stat"; "/ln_f/b"]], [CompareWithInt ("nlink", 2)])],
    "create a hard link",
    "\
 This command creates a hard link using the C<ln -f> command.
 The C<-f> option removes the link (C<linkname>) if it exists already.");
 
   ("ln_s", (RErr, [String "target"; Pathname "linkname"], []), 166, [],
-   [InitBasicFS, Always, TestOutputStruct (
-      [["touch"; "/a"];
-       ["ln_s"; "a"; "/b"];
-       ["lstat"; "/b"]], [CompareWithInt ("mode", 0o120777)])],
+   [InitScratchFS, Always, TestOutputStruct (
+      [["mkdir"; "/ln_s"];
+       ["touch"; "/ln_s/a"];
+       ["ln_s"; "a"; "/ln_s/b"];
+       ["lstat"; "/ln_s/b"]], [CompareWithInt ("mode", 0o120777)])],
    "create a symbolic link",
    "\
 This command creates a symbolic link using the C<ln -s> command.");
 
   ("ln_sf", (RErr, [String "target"; Pathname "linkname"], []), 167, [],
-   [InitBasicFS, Always, TestOutput (
-      [["mkdir_p"; "/a/b"];
-       ["touch"; "/a/b/c"];
-       ["ln_sf"; "../d"; "/a/b/c"];
-       ["readlink"; "/a/b/c"]], "../d")],
+   [InitScratchFS, Always, TestOutput (
+      [["mkdir_p"; "/ln_sf/b"];
+       ["touch"; "/ln_sf/b/c"];
+       ["ln_sf"; "../d"; "/ln_sf/b/c"];
+       ["readlink"; "/ln_sf/b/c"]], "../d")],
    "create a symbolic link",
    "\
 This command creates a symbolic link using the C<ln -sf> command,
@@ -3639,9 +3961,9 @@ The C<-f> option removes the link (C<linkname>) if it exists already.");
 This command reads the target of a symbolic link.");
 
   ("fallocate", (RErr, [Pathname "path"; Int "len"], []), 169, [DeprecatedBy "fallocate64"],
-   [InitBasicFS, Always, TestOutputStruct (
-      [["fallocate"; "/a"; "1000000"];
-       ["stat"; "/a"]], [CompareWithInt ("size", 1_000_000)])],
+   [InitScratchFS, Always, TestOutputStruct (
+      [["fallocate"; "/fallocate"; "1000000"];
+       ["stat"; "/fallocate"]], [CompareWithInt ("size", 1_000_000)])],
    "preallocate a file in the guest filesystem",
    "\
 This command preallocates a file (containing zero bytes) named
@@ -3680,11 +4002,12 @@ device or partition named C<device>.
 See C<guestfs_swapon_device>.");
 
   ("swapon_file", (RErr, [Pathname "file"], []), 172, [],
-   [InitBasicFS, Always, TestRun (
-      [["fallocate"; "/swap"; "8388608"];
-       ["mkswap_file"; "/swap"];
-       ["swapon_file"; "/swap"];
-       ["swapoff_file"; "/swap"]])],
+   [InitScratchFS, Always, TestRun (
+      [["fallocate"; "/swapon_file"; "8388608"];
+       ["mkswap_file"; "/swapon_file"];
+       ["swapon_file"; "/swapon_file"];
+       ["swapoff_file"; "/swapon_file"];
+       ["rm"; "/swapon_file"]])],
    "enable swap on file",
    "\
 This command enables swap to a file.
@@ -3698,12 +4021,12 @@ This command disables the libguestfs appliance swap on file.");
 
   ("swapon_label", (RErr, [String "label"], []), 174, [],
    [InitEmpty, Always, TestRun (
-      [["part_disk"; "/dev/sdb"; "mbr"];
-       ["mkswap_L"; "swapit"; "/dev/sdb1"];
+      [["part_disk"; "/dev/sda"; "mbr"];
+       ["mkswap_L"; "swapit"; "/dev/sda1"];
        ["swapon_label"; "swapit"];
        ["swapoff_label"; "swapit"];
-       ["zero"; "/dev/sdb"];
-       ["blockdev_rereadpt"; "/dev/sdb"]])],
+       ["zero"; "/dev/sda"];
+       ["blockdev_rereadpt"; "/dev/sda"]])],
    "enable swap on labeled swap partition",
    "\
 This command enables swap to a labeled swap partition.
@@ -3719,7 +4042,7 @@ labeled swap partition.");
   ("swapon_uuid", (RErr, [String "uuid"], []), 176, [Optional "linuxfsuuid"],
    (let uuid = uuidgen () in
     [InitEmpty, Always, TestRun (
-       [["mkswap_U"; uuid; "/dev/sdb"];
+       [["mkswap_U"; uuid; "/dev/sdc"];
         ["swapon_uuid"; uuid];
         ["swapoff_uuid"; uuid]])]),
    "enable swap on swap partition by UUID",
@@ -3735,9 +4058,10 @@ This command disables the libguestfs appliance swap partition
 with the given UUID.");
 
   ("mkswap_file", (RErr, [Pathname "path"], []), 178, [],
-   [InitBasicFS, Always, TestRun (
-      [["fallocate"; "/swap"; "8388608"];
-       ["mkswap_file"; "/swap"]])],
+   [InitScratchFS, Always, TestRun (
+      [["fallocate"; "/mkswap_file"; "8388608"];
+       ["mkswap_file"; "/mkswap_file"];
+       ["rm"; "/mkswap_file"]])],
    "create a swap file",
    "\
 Create a swap file.
@@ -3787,11 +4111,12 @@ via libguestfs.  Note that there is one global inotify handle
 per libguestfs instance.");
 
   ("inotify_add_watch", (RInt64 "wd", [Pathname "path"; Int "mask"], []), 180, [Optional "inotify"],
-   [InitBasicFS, Always, TestOutputList (
-      [["inotify_init"; "0"];
-       ["inotify_add_watch"; "/"; "1073741823"];
-       ["touch"; "/a"];
-       ["touch"; "/b"];
+   [InitScratchFS, Always, TestOutputList (
+      [["mkdir"; "/inotify_add_watch"];
+       ["inotify_init"; "0"];
+       ["inotify_add_watch"; "/inotify_add_watch"; "1073741823"];
+       ["touch"; "/inotify_add_watch/a"];
+       ["touch"; "/inotify_add_watch/b"];
        ["inotify_files"]], ["a"; "b"])],
    "add an inotify watch",
    "\
@@ -3892,7 +4217,9 @@ the requested cluster size.");
 
   ("mke2journal", (RErr, [Int "blocksize"; Device "device"], []), 188, [],
    [InitEmpty, Always, TestOutput (
-      [["sfdiskM"; "/dev/sda"; ",100 ,"];
+      [["part_init"; "/dev/sda"; "mbr"];
+       ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
+       ["part_add"; "/dev/sda"; "p"; "204800"; "-64"];
        ["mke2journal"; "4096"; "/dev/sda1"];
        ["mke2fs_J"; "ext2"; "4096"; "/dev/sda2"; "/dev/sda1"];
        ["mount_options"; ""; "/dev/sda2"; "/"];
@@ -3907,7 +4234,9 @@ to the command:
 
   ("mke2journal_L", (RErr, [Int "blocksize"; String "label"; Device "device"], []), 189, [],
    [InitEmpty, Always, TestOutput (
-      [["sfdiskM"; "/dev/sda"; ",100 ,"];
+      [["part_init"; "/dev/sda"; "mbr"];
+       ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
+       ["part_add"; "/dev/sda"; "p"; "204800"; "-64"];
        ["mke2journal_L"; "4096"; "JOURNAL"; "/dev/sda1"];
        ["mke2fs_JL"; "ext2"; "4096"; "/dev/sda2"; "JOURNAL"];
        ["mount_options"; ""; "/dev/sda2"; "/"];
@@ -3920,7 +4249,9 @@ This creates an ext2 external journal on C<device> with label C<label>.");
   ("mke2journal_U", (RErr, [Int "blocksize"; String "uuid"; Device "device"], []), 190, [Optional "linuxfsuuid"],
    (let uuid = uuidgen () in
     [InitEmpty, Always, TestOutput (
-       [["sfdiskM"; "/dev/sda"; ",100 ,"];
+       [["part_init"; "/dev/sda"; "mbr"];
+        ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
+        ["part_add"; "/dev/sda"; "p"; "204800"; "-64"];
         ["mke2journal_U"; "4096"; uuid; "/dev/sda1"];
         ["mke2fs_JU"; "ext2"; "4096"; "/dev/sda2"; uuid];
         ["mount_options"; ""; "/dev/sda2"; "/"];
@@ -4024,21 +4355,21 @@ The result list is not sorted.
       [["case_sensitive_path"; "/Known-1"]], "/known-1");
     InitISOFS, Always, TestLastFail (
       [["case_sensitive_path"; "/Known-1/"]]);
-    InitBasicFS, Always, TestOutput (
-      [["mkdir"; "/a"];
-       ["mkdir"; "/a/bbb"];
-       ["touch"; "/a/bbb/c"];
-       ["case_sensitive_path"; "/A/bbB/C"]], "/a/bbb/c");
-    InitBasicFS, Always, TestOutput (
-      [["mkdir"; "/a"];
-       ["mkdir"; "/a/bbb"];
-       ["touch"; "/a/bbb/c"];
-       ["case_sensitive_path"; "/A////bbB/C"]], "/a/bbb/c");
-    InitBasicFS, Always, TestLastFail (
-      [["mkdir"; "/a"];
-       ["mkdir"; "/a/bbb"];
-       ["touch"; "/a/bbb/c"];
-       ["case_sensitive_path"; "/A/bbb/../bbb/C"]])],
+    InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/case_sensitive_path"];
+       ["mkdir"; "/case_sensitive_path/bbb"];
+       ["touch"; "/case_sensitive_path/bbb/c"];
+       ["case_sensitive_path"; "/CASE_SENSITIVE_path/bbB/C"]], "/case_sensitive_path/bbb/c");
+    InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/case_sensitive_path2"];
+       ["mkdir"; "/case_sensitive_path2/bbb"];
+       ["touch"; "/case_sensitive_path2/bbb/c"];
+       ["case_sensitive_path"; "/case_sensitive_PATH2////bbB/C"]], "/case_sensitive_path2/bbb/c");
+    InitScratchFS, Always, TestLastFail (
+      [["mkdir"; "/case_sensitive_path3"];
+       ["mkdir"; "/case_sensitive_path3/bbb"];
+       ["touch"; "/case_sensitive_path3/bbb/c"];
+       ["case_sensitive_path"; "/case_SENSITIVE_path3/bbb/../bbb/C"]])],
    "return true path on case-insensitive filesystem",
    "\
 This can be used to resolve case insensitive paths on
@@ -4074,8 +4405,8 @@ This function does not handle drive names, backslashes etc.
 See also C<guestfs_realpath>.");
 
   ("vfs_type", (RString "fstype", [Device "device"], []), 198, [],
-   [InitBasicFS, Always, TestOutput (
-      [["vfs_type"; "/dev/sda1"]], "ext2")],
+   [InitScratchFS, Always, TestOutput (
+      [["vfs_type"; "/dev/sdb1"]], "ext2")],
    "get the Linux VFS type corresponding to a mounted device",
    "\
 This command gets the filesystem type corresponding to
@@ -4087,20 +4418,20 @@ if you mounted it without specifying the filesystem type.
 For example a string such as C<ext3> or C<ntfs>.");
 
   ("truncate", (RErr, [Pathname "path"], []), 199, [],
-   [InitBasicFS, Always, TestOutputStruct (
-      [["write"; "/test"; "some stuff so size is not zero"];
-       ["truncate"; "/test"];
-       ["stat"; "/test"]], [CompareWithInt ("size", 0)])],
+   [InitScratchFS, Always, TestOutputStruct (
+      [["write"; "/truncate"; "some stuff so size is not zero"];
+       ["truncate"; "/truncate"];
+       ["stat"; "/truncate"]], [CompareWithInt ("size", 0)])],
    "truncate a file to zero size",
    "\
 This command truncates C<path> to a zero-length file.  The
 file must exist already.");
 
   ("truncate_size", (RErr, [Pathname "path"; Int64 "size"], []), 200, [],
-   [InitBasicFS, Always, TestOutputStruct (
-      [["touch"; "/test"];
-       ["truncate_size"; "/test"; "1000"];
-       ["stat"; "/test"]], [CompareWithInt ("size", 1000)])],
+   [InitScratchFS, Always, TestOutputStruct (
+      [["touch"; "/truncate_size"];
+       ["truncate_size"; "/truncate_size"; "1000"];
+       ["stat"; "/truncate_size"]], [CompareWithInt ("size", 1000)])],
    "truncate a file to a particular size",
    "\
 This command truncates C<path> to size C<size> bytes.  The file
@@ -4113,10 +4444,10 @@ for the file until you write to it).  To create a non-sparse
 file of zeroes, use C<guestfs_fallocate64> instead.");
 
   ("utimens", (RErr, [Pathname "path"; Int64 "atsecs"; Int64 "atnsecs"; Int64 "mtsecs"; Int64 "mtnsecs"], []), 201, [],
-   [InitBasicFS, Always, TestOutputStruct (
-      [["touch"; "/test"];
-       ["utimens"; "/test"; "12345"; "67890"; "9876"; "5432"];
-       ["stat"; "/test"]], [CompareWithInt ("mtime", 9876)])],
+   [InitScratchFS, Always, TestOutputStruct (
+      [["touch"; "/utimens"];
+       ["utimens"; "/utimens"; "12345"; "67890"; "9876"; "5432"];
+       ["stat"; "/utimens"]], [CompareWithInt ("mtime", 9876)])],
    "set timestamp of a file with nanosecond precision",
    "\
 This command sets the timestamps of a file with nanosecond
@@ -4137,9 +4468,9 @@ the corresponding timestamp is left unchanged.  (The
 C<*secs> field is ignored in this case).");
 
   ("mkdir_mode", (RErr, [Pathname "path"; Int "mode"], []), 202, [],
-   [InitBasicFS, Always, TestOutputStruct (
-      [["mkdir_mode"; "/test"; "0o111"];
-       ["stat"; "/test"]], [CompareWithInt ("mode", 0o40111)])],
+   [InitScratchFS, Always, TestOutputStruct (
+      [["mkdir_mode"; "/mkdir_mode"; "0o111"];
+       ["stat"; "/mkdir_mode"]], [CompareWithInt ("mode", 0o40111)])],
    "create a directory with a particular mode",
    "\
 This command creates a directory, setting the initial permissions
@@ -4438,9 +4769,9 @@ values are possible, although unusual.  See C<guestfs_part_init>
 for a full list.");
 
   ("fill", (RErr, [Int "c"; Int "len"; Pathname "path"], []), 215, [Progress],
-   [InitBasicFS, Always, TestOutputBuffer (
-      [["fill"; "0x63"; "10"; "/test"];
-       ["read_file"; "/test"]], "cccccccccc")],
+   [InitScratchFS, Always, TestOutputBuffer (
+      [["fill"; "0x63"; "10"; "/fill"];
+       ["read_file"; "/fill"]], "cccccccccc")],
    "fill a file with octets",
    "\
 This command creates a new file called C<path>.  The initial
@@ -4514,10 +4845,11 @@ See also C<guestfs_version>.
 =back");
 
   ("dd", (RErr, [Dev_or_Path "src"; Dev_or_Path "dest"], []), 217, [],
-   [InitBasicFS, Always, TestOutputBuffer (
-      [["write"; "/src"; "hello, world"];
-       ["dd"; "/src"; "/dest"];
-       ["read_file"; "/dest"]], "hello, world")],
+   [InitScratchFS, Always, TestOutputBuffer (
+      [["mkdir"; "/dd"];
+       ["write"; "/dd/src"; "hello, world"];
+       ["dd"; "/dd/src"; "/dd/dest"];
+       ["read_file"; "/dd/dest"]], "hello, world")],
    "copy from source to destination using dd",
    "\
 This command copies from one source device or file C<src>
@@ -4530,9 +4862,9 @@ than the source file or device, otherwise the copy will fail.
 This command cannot do partial copies (see C<guestfs_copy_size>).");
 
   ("filesize", (RInt64 "size", [Pathname "file"], []), 218, [],
-   [InitBasicFS, Always, TestOutputInt (
-      [["write"; "/file"; "hello, world"];
-       ["filesize"; "/file"]], 12)],
+   [InitScratchFS, Always, TestOutputInt (
+      [["write"; "/filesize"; "hello, world"];
+       ["filesize"; "/filesize"]], 12)],
    "return the size of the file in bytes",
    "\
 This command returns the size of C<file> in bytes.
@@ -4621,10 +4953,11 @@ calls to associate logical volumes and volume groups.
 See also C<guestfs_vgpvuuids>.");
 
   ("copy_size", (RErr, [Dev_or_Path "src"; Dev_or_Path "dest"; Int64 "size"], []), 227, [Progress],
-   [InitBasicFS, Always, TestOutputBuffer (
-      [["write"; "/src"; "hello, world"];
-       ["copy_size"; "/src"; "/dest"; "5"];
-       ["read_file"; "/dest"]], "hello")],
+   [InitScratchFS, Always, TestOutputBuffer (
+      [["mkdir"; "/copy_size"];
+       ["write"; "/copy_size/src"; "hello, world"];
+       ["copy_size"; "/copy_size/src"; "/copy_size/dest"; "5"];
+       ["read_file"; "/copy_size/dest"]], "hello")],
    "copy size bytes from source to destination using dd",
    "\
 This command copies exactly C<size> bytes from one source device
@@ -4643,9 +4976,10 @@ with C<guestfs_zero> which just zeroes the first few blocks of
 a device.");
 
   ("txz_in", (RErr, [FileIn "tarball"; Pathname "directory"], []), 229, [Optional "xz"],
-   [InitBasicFS, Always, TestOutput (
-      [["txz_in"; "../images/helloworld.tar.xz"; "/"];
-       ["cat"; "/hello"]], "hello\n")],
+   [InitScratchFS, Always, TestOutput (
+      [["mkdir"; "/txz_in"];
+       ["txz_in"; "../images/helloworld.tar.xz"; "/txz_in"];
+       ["cat"; "/txz_in/hello"]], "hello\n")],
    "unpack compressed tarball to directory",
    "\
 This command uploads and unpacks local file C<tarball> (an
@@ -4769,7 +5103,7 @@ is the same as the L<augtool(1)> C<clear> command.");
 Return the current umask.  By default the umask is C<022>
 unless it has been set by calling C<guestfs_umask>.");
 
-  ("debug_upload", (RErr, [FileIn "filename"; String "tmpname"; Int "mode"], []), 241, [],
+  ("debug_upload", (RErr, [FileIn "filename"; String "tmpname"; Int "mode"], []), 241, [NotInDocs],
    [],
    "upload a file to the appliance (internal use only)",
    "\
@@ -4781,9 +5115,9 @@ to look at the file C<daemon/debug.c> in the libguestfs source
 to find out what it is for.");
 
   ("base64_in", (RErr, [FileIn "base64file"; Pathname "filename"], []), 242, [],
-   [InitBasicFS, Always, TestOutput (
-      [["base64_in"; "../images/hello.b64"; "/hello"];
-       ["cat"; "/hello"]], "hello\n")],
+   [InitScratchFS, Always, TestOutput (
+      [["base64_in"; "../images/hello.b64"; "/base64_in"];
+       ["cat"; "/base64_in"]], "hello\n")],
    "upload base64-encoded data to file",
    "\
 This command uploads base64-encoded data from C<base64file>
@@ -4813,9 +5147,9 @@ backslash syntax.  For more information, see the GNU
 coreutils info file.");
 
   ("fill_pattern", (RErr, [String "pattern"; Int "len"; Pathname "path"], []), 245, [Progress],
-   [InitBasicFS, Always, TestOutputBuffer (
-      [["fill_pattern"; "abcdefghijklmnopqrstuvwxyz"; "28"; "/test"];
-       ["read_file"; "/test"]], "abcdefghijklmnopqrstuvwxyzab")],
+   [InitScratchFS, Always, TestOutputBuffer (
+      [["fill_pattern"; "abcdefghijklmnopqrstuvwxyz"; "28"; "/fill_pattern"];
+       ["read_file"; "/fill_pattern"]], "abcdefghijklmnopqrstuvwxyzab")],
    "fill a file with a repeating pattern of bytes",
    "\
 This function is like C<guestfs_fill> except that it creates
@@ -4824,42 +5158,42 @@ of bytes in C<pattern>.  The pattern is truncated if necessary
 to ensure the length of the file is exactly C<len> bytes.");
 
   ("write", (RErr, [Pathname "path"; BufferIn "content"], []), 246, [ProtocolLimitWarning],
-   [InitBasicFS, Always, TestOutput (
-      [["write"; "/new"; "new file contents"];
-       ["cat"; "/new"]], "new file contents");
-    InitBasicFS, Always, TestOutput (
-      [["write"; "/new"; "\nnew file contents\n"];
-       ["cat"; "/new"]], "\nnew file contents\n");
-    InitBasicFS, Always, TestOutput (
-      [["write"; "/new"; "\n\n"];
-       ["cat"; "/new"]], "\n\n");
-    InitBasicFS, Always, TestOutput (
-      [["write"; "/new"; ""];
-       ["cat"; "/new"]], "");
-    InitBasicFS, Always, TestOutput (
-      [["write"; "/new"; "\n\n\n"];
-       ["cat"; "/new"]], "\n\n\n");
-    InitBasicFS, Always, TestOutput (
-      [["write"; "/new"; "\n"];
-       ["cat"; "/new"]], "\n")],
+   [InitScratchFS, Always, TestOutput (
+      [["write"; "/write"; "new file contents"];
+       ["cat"; "/write"]], "new file contents");
+    InitScratchFS, Always, TestOutput (
+      [["write"; "/write2"; "\nnew file contents\n"];
+       ["cat"; "/write2"]], "\nnew file contents\n");
+    InitScratchFS, Always, TestOutput (
+      [["write"; "/write3"; "\n\n"];
+       ["cat"; "/write3"]], "\n\n");
+    InitScratchFS, Always, TestOutput (
+      [["write"; "/write4"; ""];
+       ["cat"; "/write4"]], "");
+    InitScratchFS, Always, TestOutput (
+      [["write"; "/write5"; "\n\n\n"];
+       ["cat"; "/write5"]], "\n\n\n");
+    InitScratchFS, Always, TestOutput (
+      [["write"; "/write6"; "\n"];
+       ["cat"; "/write6"]], "\n")],
    "create a new file",
    "\
 This call creates a file called C<path>.  The content of the
 file is the string C<content> (which can contain any 8 bit data).");
 
   ("pwrite", (RInt "nbytes", [Pathname "path"; BufferIn "content"; Int64 "offset"], []), 247, [ProtocolLimitWarning],
-   [InitBasicFS, Always, TestOutput (
-      [["write"; "/new"; "new file contents"];
-       ["pwrite"; "/new"; "data"; "4"];
-       ["cat"; "/new"]], "new data contents");
-    InitBasicFS, Always, TestOutput (
-      [["write"; "/new"; "new file contents"];
-       ["pwrite"; "/new"; "is extended"; "9"];
-       ["cat"; "/new"]], "new file is extended");
-    InitBasicFS, Always, TestOutput (
-      [["write"; "/new"; "new file contents"];
-       ["pwrite"; "/new"; ""; "4"];
-       ["cat"; "/new"]], "new file contents")],
+   [InitScratchFS, Always, TestOutput (
+      [["write"; "/pwrite"; "new file contents"];
+       ["pwrite"; "/pwrite"; "data"; "4"];
+       ["cat"; "/pwrite"]], "new data contents");
+    InitScratchFS, Always, TestOutput (
+      [["write"; "/pwrite2"; "new file contents"];
+       ["pwrite"; "/pwrite2"; "is extended"; "9"];
+       ["cat"; "/pwrite2"]], "new file is extended");
+    InitScratchFS, Always, TestOutput (
+      [["write"; "/pwrite3"; "new file contents"];
+       ["pwrite"; "/pwrite3"; ""; "4"];
+       ["cat"; "/pwrite3"]], "new file contents")],
    "write to part of a file",
    "\
 This command writes to part of a file.  It writes the data
@@ -4907,9 +5241,9 @@ returned list.
 See also C<guestfs_available> and L<guestfs(3)/AVAILABILITY>.");
 
   ("fallocate64", (RErr, [Pathname "path"; Int64 "len"], []), 252, [],
-   [InitBasicFS, Always, TestOutputStruct (
-      [["fallocate64"; "/a"; "1000000"];
-       ["stat"; "/a"]], [CompareWithInt ("size", 1_000_000)])],
+   [InitScratchFS, Always, TestOutputStruct (
+      [["fallocate64"; "/fallocate64"; "1000000"];
+       ["stat"; "/fallocate64"]], [CompareWithInt ("size", 1_000_000)])],
    "preallocate a file in the guest filesystem",
    "\
 This command preallocates a file (containing zero bytes) named
@@ -5103,9 +5437,9 @@ To find the label of a filesystem, use C<guestfs_vfs_label>.");
   ("is_chardev", (RBool "flag", [Pathname "path"], []), 267, [],
    [InitISOFS, Always, TestOutputFalse (
       [["is_chardev"; "/directory"]]);
-    InitBasicFS, Always, TestOutputTrue (
-      [["mknod_c"; "0o777"; "99"; "66"; "/test"];
-       ["is_chardev"; "/test"]])],
+    InitScratchFS, Always, TestOutputTrue (
+      [["mknod_c"; "0o777"; "99"; "66"; "/is_chardev"];
+       ["is_chardev"; "/is_chardev"]])],
    "test if character device",
    "\
 This returns C<true> if and only if there is a character device
@@ -5116,9 +5450,9 @@ See also C<guestfs_stat>.");
   ("is_blockdev", (RBool "flag", [Pathname "path"], []), 268, [],
    [InitISOFS, Always, TestOutputFalse (
       [["is_blockdev"; "/directory"]]);
-    InitBasicFS, Always, TestOutputTrue (
-      [["mknod_b"; "0o777"; "99"; "66"; "/test"];
-       ["is_blockdev"; "/test"]])],
+    InitScratchFS, Always, TestOutputTrue (
+      [["mknod_b"; "0o777"; "99"; "66"; "/is_blockdev"];
+       ["is_blockdev"; "/is_blockdev"]])],
    "test if block device",
    "\
 This returns C<true> if and only if there is a block device
@@ -5129,9 +5463,9 @@ See also C<guestfs_stat>.");
   ("is_fifo", (RBool "flag", [Pathname "path"], []), 269, [],
    [InitISOFS, Always, TestOutputFalse (
       [["is_fifo"; "/directory"]]);
-    InitBasicFS, Always, TestOutputTrue (
-      [["mkfifo"; "0o777"; "/test"];
-       ["is_fifo"; "/test"]])],
+    InitScratchFS, Always, TestOutputTrue (
+      [["mkfifo"; "0o777"; "/is_fifo"];
+       ["is_fifo"; "/is_fifo"]])],
    "test if FIFO (named pipe)",
    "\
 This returns C<true> if and only if there is a FIFO (named pipe)
@@ -5176,11 +5510,11 @@ removes the partition number, returning the device name
 The named partition must exist, for example as a string returned
 from C<guestfs_list_partitions>.");
 
-  ("upload_offset", (RErr, [FileIn "filename"; Dev_or_Path "remotefilename"; Int64 "offset"], []), 273, [],
+  ("upload_offset", (RErr, [FileIn "filename"; Dev_or_Path "remotefilename"; Int64 "offset"], []), 273, [Progress],
    (let md5 = Digest.to_hex (Digest.file "COPYING.LIB") in
-    [InitBasicFS, Always, TestOutput (
-       [["upload_offset"; "../COPYING.LIB"; "/COPYING.LIB"; "0"];
-        ["checksum"; "md5"; "/COPYING.LIB"]], md5)]),
+    [InitScratchFS, Always, TestOutput (
+       [["upload_offset"; "../COPYING.LIB"; "/upload_offset"; "0"];
+        ["checksum"; "md5"; "/upload_offset"]], md5)]),
    "upload a file from the local machine with offset",
    "\
 Upload local file C<filename> to C<remotefilename> on the
@@ -5204,12 +5538,13 @@ See also C<guestfs_upload>, C<guestfs_pwrite>.");
    (let md5 = Digest.to_hex (Digest.file "COPYING.LIB") in
     let offset = string_of_int 100 in
     let size = string_of_int ((Unix.stat "COPYING.LIB").Unix.st_size - 100) in
-    [InitBasicFS, Always, TestOutput (
+    [InitScratchFS, Always, TestOutput (
        (* Pick a file from cwd which isn't likely to change. *)
-       [["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
-        ["download_offset"; "/COPYING.LIB"; "testdownload.tmp"; offset; size];
-        ["upload_offset"; "testdownload.tmp"; "/COPYING.LIB"; offset];
-        ["checksum"; "md5"; "/COPYING.LIB"]], md5)]),
+       [["mkdir"; "/download_offset"];
+        ["upload"; "../COPYING.LIB"; "/download_offset/COPYING.LIB"];
+        ["download_offset"; "/download_offset/COPYING.LIB"; "testdownload.tmp"; offset; size];
+        ["upload_offset"; "testdownload.tmp"; "/download_offset/COPYING.LIB"; offset];
+        ["checksum"; "md5"; "/download_offset/COPYING.LIB"]], md5)]),
    "download a file to the local machine with offset and size",
    "\
 Download file C<remotefilename> and save it as C<filename>
@@ -5226,10 +5561,10 @@ error occurs.
 See also C<guestfs_download>, C<guestfs_pread>.");
 
   ("pwrite_device", (RInt "nbytes", [Device "device"; BufferIn "content"; Int64 "offset"], []), 275, [ProtocolLimitWarning],
-   [InitPartition, Always, TestOutputList (
+   [InitPartition, Always, TestOutputListOfDevices (
       [["pwrite_device"; "/dev/sda"; "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"; "446"];
        ["blockdev_rereadpt"; "/dev/sda"];
-       ["list_partitions"]], [])],
+       ["list_partitions"]], ["/dev/sdb1"])],
    "write to part of a device",
    "\
 This command writes to part of a device.  It writes the data