#!/usr/bin/env ocaml
(* libguestfs
* Copyright (C) 2009-2010 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*)
(* This script generates a large amount of code and documentation for
* all the daemon actions.
*
* To add a new action there are only two files you need to change,
* this one to describe the interface (see the big table of
* 'daemon_functions' below), and daemon/<somefile>.c to write the
* implementation.
*
* After editing this file, run it (./src/generator.ml) to regenerate
* all the output files. 'make' will rerun this automatically when
* necessary. Note that if you are using a separate build directory
* you must run generator.ml from the _source_ directory.
*
* IMPORTANT: This script should NOT print any warnings. If it prints
* warnings, you should treat them as errors.
*
* OCaml tips:
* (1) In emacs, install tuareg-mode to display and format OCaml code
* correctly. 'vim' comes with a good OCaml editing mode by default.
* (2) Read the resources at http://ocaml-tutorial.org/
*)
#load "unix.cma";;
#load "str.cma";;
#directory "+xml-light";;
#directory "+../pkg-lib/xml-light";; (* for GODI users *)
#load "xml-light.cma";;
open Unix
open Printf
type style = ret * args
and ret =
(* "RErr" as a return value means an int used as a simple error
* indication, ie. 0 or -1.
*)
| RErr
(* "RInt" as a return value means an int which is -1 for error
* or any value >= 0 on success. Only use this for smallish
* positive ints (0 <= i < 2^30).
*)
| RInt of string
(* "RInt64" is the same as RInt, but is guaranteed to be able
* to return a full 64 bit value, _except_ that -1 means error
* (so -1 cannot be a valid, non-error return value).
*)
| RInt64 of string
(* "RBool" is a bool return value which can be true/false or
* -1 for error.
*)
| RBool of string
(* "RConstString" is a string that refers to a constant value.
* The return value must NOT be NULL (since NULL indicates
* an error).
*
* Try to avoid using this. In particular you cannot use this
* for values returned from the daemon, because there is no
* thread-safe way to return them in the C API.
*)
| RConstString of string
(* "RConstOptString" is an even more broken version of
* "RConstString". The returned string may be NULL and there
* is no way to return an error indication. Avoid using this!
*)
| RConstOptString of string
(* "RString" is a returned string. It must NOT be NULL, since
* a NULL return indicates an error. The caller frees this.
*)
| RString of string
(* "RStringList" is a list of strings. No string in the list
* can be NULL. The caller frees the strings and the array.
*)
| RStringList of string
(* "RStruct" is a function which returns a single named structure
* or an error indication (in C, a struct, and in other languages
* with varying representations, but usually very efficient). See
* after the function list below for the structures.
*)
| RStruct of string * string (* name of retval, name of struct *)
(* "RStructList" is a function which returns either a list/array
* of structures (could be zero-length), or an error indication.
*)
| RStructList of string * string (* name of retval, name of struct *)
(* Key-value pairs of untyped strings. Turns into a hashtable or
* dictionary in languages which support it. DON'T use this as a
* general "bucket" for results. Prefer a stronger typed return
* value if one is available, or write a custom struct. Don't use
* this if the list could potentially be very long, since it is
* inefficient. Keys should be unique. NULLs are not permitted.
*)
| RHashtable of string
(* "RBufferOut" is handled almost exactly like RString, but
* it allows the string to contain arbitrary 8 bit data including
* ASCII NUL. In the C API this causes an implicit extra parameter
* to be added of type <size_t *size_r>. The extra parameter
* returns the actual size of the return buffer in bytes.
*
* Other programming languages support strings with arbitrary 8 bit
* data.
*
* At the RPC layer we have to use the opaque<> type instead of
* string<>. Returned data is still limited to the max message
* size (ie. ~ 2 MB).
*)
| RBufferOut of string
and args = argt list (* Function parameters, guestfs handle is implicit. *)
(* Note in future we should allow a "variable args" parameter as
* the final parameter, to allow commands like
* chmod mode file [file(s)...]
* This is not implemented yet, but many commands (such as chmod)
* are currently defined with the argument order keeping this future
* possibility in mind.
*)
and argt =
| String of string (* const char *name, cannot be NULL *)
| Device of string (* /dev device name, cannot be NULL *)
| Pathname of string (* file name, cannot be NULL *)
| Dev_or_Path of string (* /dev device name or Pathname, cannot be NULL *)
| OptString of string (* const char *name, may be NULL *)
| StringList of string(* list of strings (each string cannot be NULL) *)
| DeviceList of string(* list of Device names (each cannot be NULL) *)
| Bool of string (* boolean *)
| Int of string (* int (smallish ints, signed, <= 31 bits) *)
| Int64 of string (* any 64 bit int *)
(* These are treated as filenames (simple string parameters) in
* the C API and bindings. But in the RPC protocol, we transfer
* the actual file content up to or down from the daemon.
* FileIn: local machine -> daemon (in request)
* FileOut: daemon -> local machine (in reply)
* In guestfish (only), the special name "-" means read from
* stdin or write to stdout.
*)
| FileIn of string
| FileOut of string
(* Opaque buffer which can contain arbitrary 8 bit data.
* In the C API, this is expressed as <const char *, size_t> pair.
* Most other languages have a string type which can contain
* ASCII NUL. We use whatever type is appropriate for each
* language.
* Buffers are limited by the total message size. To transfer
* large blocks of data, use FileIn/FileOut parameters instead.
* To return an arbitrary buffer, use RBufferOut.
*)
| BufferIn of string
type flags =
| ProtocolLimitWarning (* display warning about protocol size limits *)
| DangerWillRobinson (* flags particularly dangerous commands *)
| FishAlias of string (* provide an alias for this cmd in guestfish *)
| FishOutput of fish_output_t (* how to display output in guestfish *)
| NotInFish (* do not export via guestfish *)
| NotInDocs (* do not add this function to documentation *)
| DeprecatedBy of string (* function is deprecated, use .. instead *)
| Optional of string (* function is part of an optional group *)
and fish_output_t =
| FishOutputOctal (* for int return, print in octal *)
| FishOutputHexadecimal (* for int return, print in hex *)
(* You can supply zero or as many tests as you want per API call.
*
* Note that the test environment has 3 block devices, of size 500MB,
* 50MB and 10MB (respectively /dev/sda, /dev/sdb, /dev/sdc), and
* a fourth ISO block device with some known files on it (/dev/sdd).
*
* Note for partitioning purposes, the 500MB device has 1015 cylinders.
* Number of cylinders was 63 for IDE emulated disks with precisely
* the same size. How exactly this is calculated is a mystery.
*
* The ISO block device (/dev/sdd) comes from images/test.iso.
*
* To be able to run the tests in a reasonable amount of time,
* the virtual machine and block devices are reused between tests.
* So don't try testing kill_subprocess :-x
*
* Between each test we blockdev-setrw, umount-all, lvm-remove-all.
*
* Don't assume anything about the previous contents of the block
* devices. Use 'Init*' to create some initial scenarios.
*
* You can add a prerequisite clause to any individual test. This
* is a run-time check, which, if it fails, causes the test to be
* skipped. Useful if testing a command which might not work on
* all variations of libguestfs builds. A test that has prerequisite
* of 'Always' is run unconditionally.
*
* In addition, packagers can skip individual tests by setting the
* environment variables: eg:
* SKIP_TEST_<CMD>_<NUM>=1 SKIP_TEST_COMMAND_3=1 (skips test #3 of command)
* SKIP_TEST_<CMD>=1 SKIP_TEST_ZEROFREE=1 (skips all zerofree tests)
*)
type tests = (test_init * test_prereq * test) list
and test =
(* Run the command sequence and just expect nothing to fail. *)
| TestRun of seq
(* Run the command sequence and expect the output of the final
* command to be the string.
*)
| TestOutput of seq * string
(* Run the command sequence and expect the output of the final
* command to be the list of strings.
*)
| TestOutputList of seq * string list
(* Run the command sequence and expect the output of the final
* command to be the list of block devices (could be either
* "/dev/sd.." or "/dev/hd.." form - we don't check the 5th
* character of each string).
*)
| TestOutputListOfDevices of seq * string list
(* Run the command sequence and expect the output of the final
* command to be the integer.
*)
| TestOutputInt of seq * int
(* Run the command sequence and expect the output of the final
* command to be <op> <int>, eg. ">=", "1".
*)
| TestOutputIntOp of seq * string * int
(* Run the command sequence and expect the output of the final
* command to be a true value (!= 0 or != NULL).
*)
| TestOutputTrue of seq
(* Run the command sequence and expect the output of the final
* command to be a false value (== 0 or == NULL, but not an error).
*)
| TestOutputFalse of seq
(* Run the command sequence and expect the output of the final
* command to be a list of the given length (but don't care about
* content).
*)
| TestOutputLength of seq * int
(* Run the command sequence and expect the output of the final
* command to be a buffer (RBufferOut), ie. string + size.
*)
| TestOutputBuffer of seq * string
(* Run the command sequence and expect the output of the final
* command to be a structure.
*)
| TestOutputStruct of seq * test_field_compare list
(* Run the command sequence and expect the final command (only)
* to fail.
*)
| TestLastFail of seq
and test_field_compare =
| CompareWithInt of string * int
| CompareWithIntOp of string * string * int
| CompareWithString of string * string
| CompareFieldsIntEq of string * string
| CompareFieldsStrEq of string * string
(* Test prerequisites. *)
and test_prereq =
(* Test always runs. *)
| Always
(* Test is currently disabled - eg. it fails, or it tests some
* unimplemented feature.
*)
| Disabled
(* 'string' is some C code (a function body) that should return
* true or false. The test will run if the code returns true.
*)
| If of string
(* As for 'If' but the test runs _unless_ the code returns true. *)
| Unless of string
(* Some initial scenarios for testing. *)
and test_init =
(* Do nothing, block devices could contain random stuff including
* LVM PVs, and some filesystems might be mounted. This is usually
* a bad idea.
*)
| InitNone
(* Block devices are empty and no filesystems are mounted. *)
| InitEmpty
(* /dev/sda contains a single partition /dev/sda1, with random
* content. /dev/sdb and /dev/sdc may have random content.
* No LVM.
*)
| InitPartition
(* /dev/sda contains a single partition /dev/sda1, which is formatted
* as ext2, empty [except for lost+found] and mounted on /.
* /dev/sdb and /dev/sdc may have random content.
* No LVM.
*)
| InitBasicFS
(* /dev/sda:
* /dev/sda1 (is a PV):
* /dev/VG/LV (size 8MB):
* formatted as ext2, empty [except for lost+found], mounted on /
* /dev/sdb and /dev/sdc may have random content.
*)
| InitBasicFSonLVM
(* /dev/sdd (the ISO, see images/ directory in source)
* is mounted on /
*)
| InitISOFS
(* Sequence of commands for testing. *)
and seq = cmd list
and cmd = string list
(* Note about long descriptions: When referring to another
* action, use the format C<guestfs_other> (ie. the full name of
* the C function). This will be replaced as appropriate in other
* language bindings.
*
* Apart from that, long descriptions are just perldoc paragraphs.
*)
(* Generate a random UUID (used in tests). *)
let uuidgen () =
let chan = open_process_in "uuidgen" in
let uuid = input_line chan in
(match close_process_in chan with
| WEXITED 0 -> ()
| WEXITED _ ->
failwith "uuidgen: process exited with non-zero status"
| WSIGNALED _ | WSTOPPED _ ->
failwith "uuidgen: process signalled or stopped by signal"
);
uuid
(* These test functions are used in the language binding tests. *)
let test_all_args = [
String "str";
OptString "optstr";
StringList "strlist";
Bool "b";
Int "integer";
Int64 "integer64";
FileIn "filein";
FileOut "fileout";
BufferIn "bufferin";
]
let test_all_rets = [
(* except for RErr, which is tested thoroughly elsewhere *)
"test0rint", RInt "valout";
"test0rint64", RInt64 "valout";
"test0rbool", RBool "valout";
"test0rconststring", RConstString "valout";
"test0rconstoptstring", RConstOptString "valout";
"test0rstring", RString "valout";
"test0rstringlist", RStringList "valout";
"test0rstruct", RStruct ("valout", "lvm_pv");
"test0rstructlist", RStructList ("valout", "lvm_pv");
"test0rhashtable", RHashtable "valout";
]
let test_functions = [
("test0", (RErr, test_all_args), -1, [NotInFish; NotInDocs],
[],
"internal test function - do not use",
"\
This is an internal test function which is used to test whether
the automatically generated bindings can handle every possible
parameter type correctly.
It echos the contents of each parameter to stdout.
You probably don't want to call this function.");
] @ List.flatten (
List.map (
fun (name, ret) ->
[(name, (ret, [String "val"]), -1, [NotInFish; NotInDocs],
[],
"internal test function - do not use",
"\
This is an internal test function which is used to test whether
the automatically generated bindings can handle every possible
return type correctly.
It converts string C<val> to the return type.
You probably don't want to call this function.");
(name ^ "err", (ret, []), -1, [NotInFish; NotInDocs],
[],
"internal test function - do not use",
"\
This is an internal test function which is used to test whether
the automatically generated bindings can handle every possible
return type correctly.
This function always returns an error.
You probably don't want to call this function.")]
) test_all_rets
)
(* non_daemon_functions are any functions which don't get processed
* in the daemon, eg. functions for setting and getting local
* configuration values.
*)
let non_daemon_functions = test_functions @ [
("launch", (RErr, []), -1, [FishAlias "run"],
[],
"launch the qemu subprocess",
"\
Internally libguestfs is implemented by running a virtual machine
using L<qemu(1)>.
You should call this after configuring the handle
(eg. adding drives) but before performing any actions.");
("wait_ready", (RErr, []), -1, [NotInFish],
[],
"wait until the qemu subprocess launches (no op)",
"\
This function is a no op.
In versions of the API E<lt> 1.0.71 you had to call this function
just after calling C<guestfs_launch> to wait for the launch
to complete. However this is no longer necessary because
C<guestfs_launch> now does the waiting.
If you see any calls to this function in code then you can just
remove them, unless you want to retain compatibility with older
versions of the API.");
("kill_subprocess", (RErr, []), -1, [],
[],
"kill the qemu subprocess",
"\
This kills the qemu subprocess. You should never need to call this.");
("add_drive", (RErr, [String "filename"]), -1, [FishAlias "add"],
[],
"add an image to examine or modify",
"\
This function adds a virtual machine disk image C<filename> to the
guest. The first time you call this function, the disk appears as IDE
disk 0 (C</dev/sda>) in the guest, the second time as C</dev/sdb>, and
so on.
You don't necessarily need to be root when using libguestfs. However
you obviously do need sufficient permissions to access the filename
for whatever operations you want to perform (ie. read access if you
just want to read the image or write access if you want to modify the
image).
This is equivalent to the qemu parameter
C<-drive file=filename,cache=off,if=...>.
C<cache=off> is omitted in cases where it is not supported by
the underlying filesystem.
C<if=...> is set at compile time by the configuration option
C<./configure --with-drive-if=...>. In the rare case where you
might need to change this at run time, use C<guestfs_add_drive_with_if>
or C<guestfs_add_drive_ro_with_if>.
Note that this call checks for the existence of C<filename>. This
stops you from specifying other types of drive which are supported
by qemu such as C<nbd:> and C<http:> URLs. To specify those, use
the general C<guestfs_config> call instead.");
("add_cdrom", (RErr, [String "filename"]), -1, [FishAlias "cdrom"],
[],
"add a CD-ROM disk image to examine",
"\
This function adds a virtual CD-ROM disk image to the guest.
This is equivalent to the qemu parameter C<-cdrom filename>.
Notes:
=over 4
=item *
This call checks for the existence of C<filename>. This
stops you from specifying other types of drive which are supported
by qemu such as C<nbd:> and C<http:> URLs. To specify those, use
the general C<guestfs_config> call instead.
=item *
If you just want to add an ISO file (often you use this as an
efficient way to transfer large files into the guest), then you
should probably use C<guestfs_add_drive_ro> instead.
=back");
("add_drive_ro", (RErr, [String "filename"]), -1, [FishAlias "add-ro"],
[],
"add a drive in snapshot mode (read-only)",
"\
This adds a drive in snapshot mode, making it effectively
read-only.
Note that writes to the device are allowed, and will be seen for
the duration of the guestfs handle, but they are written
to a temporary file which is discarded as soon as the guestfs
handle is closed. We don't currently have any method to enable
changes to be committed, although qemu can support this.
This is equivalent to the qemu parameter
C<-drive file=filename,snapshot=on,readonly=on,if=...>.
C<if=...> is set at compile time by the configuration option
C<./configure --with-drive-if=...>. In the rare case where you
might need to change this at run time, use C<guestfs_add_drive_with_if>
or C<guestfs_add_drive_ro_with_if>.
C<readonly=on> is only added where qemu supports this option.
Note that this call checks for the existence of C<filename>. This
stops you from specifying other types of drive which are supported
by qemu such as C<nbd:> and C<http:> URLs. To specify those, use
the general C<guestfs_config> call instead.");
("config", (RErr, [String "qemuparam"; OptString "qemuvalue"]), -1, [],
[],
"add qemu parameters",
"\
This can be used to add arbitrary qemu command line parameters
of the form C<-param value>. Actually it's not quite arbitrary - we
prevent you from setting some parameters which would interfere with
parameters that we use.
The first character of C<param> string must be a C<-> (dash).
C<value> can be NULL.");
("set_qemu", (RErr, [OptString "qemu"]), -1, [FishAlias "qemu"],
[],
"set the qemu binary",
"\
Set the qemu binary that we will use.
The default is chosen when the library was compiled by the
configure script.
You can also override this by setting the C<LIBGUESTFS_QEMU>
environment variable.
Setting C<qemu> to C<NULL> restores the default qemu binary.
Note that you should call this function as early as possible
after creating the handle. This is because some pre-launch
operations depend on testing qemu features (by running C<qemu -help>).
If the qemu binary changes, we don't retest features, and
so you might see inconsistent results. Using the environment
variable C<LIBGUESTFS_QEMU> is safest of all since that picks
the qemu binary at the same time as the handle is created.");
("get_qemu", (RConstString "qemu", []), -1, [],
[InitNone, Always, TestRun (
[["get_qemu"]])],
"get the qemu binary",
"\
Return the current qemu binary.
This is always non-NULL. If it wasn't set already, then this will
return the default qemu binary name.");
("set_path", (RErr, [OptString "searchpath"]), -1, [FishAlias "path"],
[],
"set the search path",
"\
Set the path that libguestfs searches for kernel and initrd.img.
The default is C<$libdir/guestfs> unless overridden by setting
C<LIBGUESTFS_PATH> environment variable.
Setting C<path> to C<NULL> restores the default path.");
("get_path", (RConstString "path", []), -1, [],
[InitNone, Always, TestRun (
[["get_path"]])],
"get the search path",
"\
Return the current search path.
This is always non-NULL. If it wasn't set already, then this will
return the default path.");
("set_append", (RErr, [OptString "append"]), -1, [FishAlias "append"],
[],
"add options to kernel command line",
"\
This function is used to add additional options to the
guest kernel command line.
The default is C<NULL> unless overridden by setting
C<LIBGUESTFS_APPEND> environment variable.
Setting C<append> to C<NULL> means I<no> additional options
are passed (libguestfs always adds a few of its own).");
("get_append", (RConstOptString "append", []), -1, [],
(* This cannot be tested with the current framework. The
* function can return NULL in normal operations, which the
* test framework interprets as an error.
*)
[],
"get the additional kernel options",
"\
Return the additional kernel options which are added to the
guest kernel command line.
If C<NULL> then no options are added.");
("set_autosync", (RErr, [Bool "autosync"]), -1, [FishAlias "autosync"],
[],
"set autosync mode",
"\
If C<autosync> is true, this enables autosync. Libguestfs will make a
best effort attempt to run C<guestfs_umount_all> followed by
C<guestfs_sync> when the handle is closed
(also if the program exits without closing handles).
This is disabled by default (except in guestfish where it is
enabled by default).");
("get_autosync", (RBool "autosync", []), -1, [],
[InitNone, Always, TestRun (
[["get_autosync"]])],
"get autosync mode",
"\
Get the autosync flag.");
("set_verbose", (RErr, [Bool "verbose"]), -1, [FishAlias "verbose"],
[],
"set verbose mode",
"\
If C<verbose> is true, this turns on verbose messages (to C<stderr>).
Verbose messages are disabled unless the environment variable
C<LIBGUESTFS_DEBUG> is defined and set to C<1>.");
("get_verbose", (RBool "verbose", []), -1, [],
[],
"get verbose mode",
"\
This returns the verbose messages flag.");
("is_ready", (RBool "ready", []), -1, [],
[InitNone, Always, TestOutputTrue (
[["is_ready"]])],
"is ready to accept commands",
"\
This returns true iff this handle is ready to accept commands
(in the C<READY> state).
For more information on states, see L<guestfs(3)>.");
("is_config", (RBool "config", []), -1, [],
[InitNone, Always, TestOutputFalse (
[["is_config"]])],
"is in configuration state",
"\
This returns true iff this handle is being configured
(in the C<CONFIG> state).
For more information on states, see L<guestfs(3)>.");
("is_launching", (RBool "launching", []), -1, [],
[InitNone, Always, TestOutputFalse (
[["is_launching"]])],
"is launching subprocess",
"\
This returns true iff this handle is launching the subprocess
(in the C<LAUNCHING> state).
For more information on states, see L<guestfs(3)>.");
("is_busy", (RBool "busy", []), -1, [],
[InitNone, Always, TestOutputFalse (
[["is_busy"]])],
"is busy processing a command",
"\
This returns true iff this handle is busy processing a command
(in the C<BUSY> state).
For more information on states, see L<guestfs(3)>.");
("get_state", (RInt "state", []), -1, [],
[],
"get the current state",
"\
This returns the current state as an opaque integer. This is
only useful for printing debug and internal error messages.
For more information on states, see L<guestfs(3)>.");
("set_memsize", (RErr, [Int "memsize"]), -1, [FishAlias "memsize"],
[InitNone, Always, TestOutputInt (
[["set_memsize"; "500"];
["get_memsize"]], 500)],
"set memory allocated to the qemu subprocess",
"\
This sets the memory size in megabytes allocated to the
qemu subprocess. This only has any effect if called before
C<guestfs_launch>.
You can also change this by setting the environment
variable C<LIBGUESTFS_MEMSIZE> before the handle is
created.
For more information on the architecture of libguestfs,
see L<guestfs(3)>.");
("get_memsize", (RInt "memsize", []), -1, [],
[InitNone, Always, TestOutputIntOp (
[["get_memsize"]], ">=", 256)],
"get memory allocated to the qemu subprocess",
"\
This gets the memory size in megabytes allocated to the
qemu subprocess.
If C<guestfs_set_memsize> was not called
on this handle, and if C<LIBGUESTFS_MEMSIZE> was not set,
then this returns the compiled-in default value for memsize.
For more information on the architecture of libguestfs,
see L<guestfs(3)>.");
("get_pid", (RInt "pid", []), -1, [FishAlias "pid"],
[InitNone, Always, TestOutputIntOp (
[["get_pid"]], ">=", 1)],
"get PID of qemu subprocess",
"\
Return the process ID of the qemu subprocess. If there is no
qemu subprocess, then this will return an error.
This is an internal call used for debugging and testing.");
("version", (RStruct ("version", "version"), []), -1, [],
[InitNone, Always, TestOutputStruct (
[["version"]], [CompareWithInt ("major", 1)])],
"get the library version number",
"\
Return the libguestfs version number that the program is linked
against.
Note that because of dynamic linking this is not necessarily
the version of libguestfs that you compiled against. You can
compile the program, and then at runtime dynamically link
against a completely different C<libguestfs.so> library.
This call was added in version C<1.0.58>. In previous
versions of libguestfs there was no way to get the version
number. From C code you can use ELF weak linking tricks to find out if
this symbol exists (if it doesn't, then it's an earlier version).
The call returns a structure with four elements. The first
three (C<major>, C<minor> and C<release>) are numbers and
correspond to the usual version triplet. The fourth element
(C<extra>) is a string and is normally empty, but may be
used for distro-specific information.
To construct the original version string:
C<$major.$minor.$release$extra>
I<Note:> Don't use this call to test for availability
of features. Distro backports makes this unreliable. Use
C<guestfs_available> instead.");
("set_selinux", (RErr, [Bool "selinux"]), -1, [FishAlias "selinux"],
[InitNone, Always, TestOutputTrue (
[["set_selinux"; "true"];
["get_selinux"]])],
"set SELinux enabled or disabled at appliance boot",
"\
This sets the selinux flag that is passed to the appliance
at boot time. The default is C<selinux=0> (disabled).
Note that if SELinux is enabled, it is always in
Permissive mode (C<enforcing=0>).
For more information on the architecture of libguestfs,
see L<guestfs(3)>.");
("get_selinux", (RBool "selinux", []), -1, [],
[],
"get SELinux enabled flag",
"\
This returns the current setting of the selinux flag which
is passed to the appliance at boot time. See C<guestfs_set_selinux>.
For more information on the architecture of libguestfs,
see L<guestfs(3)>.");
("set_trace", (RErr, [Bool "trace"]), -1, [FishAlias "trace"],
[InitNone, Always, TestOutputFalse (
[["set_trace"; "false"];
["get_trace"]])],
"enable or disable command traces",
"\
If the command trace flag is set to 1, then commands are
printed on stdout before they are executed in a format
which is very similar to the one used by guestfish. In
other words, you can run a program with this enabled, and
you will get out a script which you can feed to guestfish
to perform the same set of actions.
If you want to trace C API calls into libguestfs (and
other libraries) then possibly a better way is to use
the external ltrace(1) command.
Command traces are disabled unless the environment variable
C<LIBGUESTFS_TRACE> is defined and set to C<1>.");
("get_trace", (RBool "trace", []), -1, [],
[],
"get command trace enabled flag",
"\
Return the command trace flag.");
("set_direct", (RErr, [Bool "direct"]), -1, [FishAlias "direct"],
[InitNone, Always, TestOutputFalse (
[["set_direct"; "false"];
["get_direct"]])],
"enable or disable direct appliance mode",
"\
If the direct appliance mode flag is enabled, then stdin and
stdout are passed directly through to the appliance once it
is launched.
One consequence of this is that log messages aren't caught
by the library and handled by C<guestfs_set_log_message_callback>,
but go straight to stdout.
You probably don't want to use this unless you know what you
are doing.
The default is disabled.");
("get_direct", (RBool "direct", []), -1, [],
[],
"get direct appliance mode flag",
"\
Return the direct appliance mode flag.");
("set_recovery_proc", (RErr, [Bool "recoveryproc"]), -1, [FishAlias "recovery-proc"],
[InitNone, Always, TestOutputTrue (
[["set_recovery_proc"; "true"];
["get_recovery_proc"]])],
"enable or disable the recovery process",
"\
If this is called with the parameter C<false> then
C<guestfs_launch> does not create a recovery process. The
purpose of the recovery process is to stop runaway qemu
processes in the case where the main program aborts abruptly.
This only has any effect if called before C<guestfs_launch>,
and the default is true.
About the only time when you would want to disable this is
if the main process will fork itself into the background
(\"daemonize\" itself). In this case the recovery process
thinks that the main program has disappeared and so kills
qemu, which is not very helpful.");
("get_recovery_proc", (RBool "recoveryproc", []), -1, [],
[],
"get recovery process enabled flag",
"\
Return the recovery process enabled flag.");
("add_drive_with_if", (RErr, [String "filename"; String "iface"]), -1, [],
[],
"add a drive specifying the QEMU block emulation to use",
"\
This is the same as C<guestfs_add_drive> but it allows you
to specify the QEMU interface emulation to use at run time.");
("add_drive_ro_with_if", (RErr, [String "filename"; String "iface"]), -1, [],
[],
"add a drive read-only specifying the QEMU block emulation to use",
"\
This is the same as C<guestfs_add_drive_ro> but it allows you
to specify the QEMU interface emulation to use at run time.");
]
(* daemon_functions are any functions which cause some action
* to take place in the daemon.
*)
let daemon_functions = [
("mount", (RErr, [Device "device"; String "mountpoint"]), 1, [],
[InitEmpty, Always, TestOutput (
[["part_disk"; "/dev/sda"; "mbr"];
["mkfs"; "ext2"; "/dev/sda1"];
["mount"; "/dev/sda1"; "/"];
["write"; "/new"; "new file contents"];
["cat"; "/new"]], "new file contents")],
"mount a guest disk at a position in the filesystem",
"\
Mount a guest disk at a position in the filesystem. Block devices
are named C</dev/sda>, C</dev/sdb> and so on, as they were added to
the guest. If those block devices contain partitions, they will have
the usual names (eg. C</dev/sda1>). Also LVM C</dev/VG/LV>-style
names can be used.
The rules are the same as for L<mount(2)>: A filesystem must
first be mounted on C</> before others can be mounted. Other
filesystems can only be mounted on directories which already
exist.
The mounted filesystem is writable, if we have sufficient permissions
on the underlying device.
B<Important note:>
When you use this call, the filesystem options C<sync> and C<noatime>
are set implicitly. This was originally done because we thought it
would improve reliability, but it turns out that I<-o sync> has a
very large negative performance impact and negligible effect on
reliability. Therefore we recommend that you avoid using
C<guestfs_mount> in any code that needs performance, and instead
use C<guestfs_mount_options> (use an empty string for the first
parameter if you don't want any options).");
("sync", (RErr, []), 2, [],
[ InitEmpty, Always, TestRun [["sync"]]],
"sync disks, writes are flushed through to the disk image",
"\
This syncs the disk, so that any writes are flushed through to the
underlying disk image.
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"]])],
"update file timestamps or create a new file",
"\
Touch acts like the L<touch(1)> command. It can be used to
update the timestamps on a file, or, if the file does not exist,
to create a new zero-length file.");
("cat", (RString "content", [Pathname "path"]), 4, [ProtocolLimitWarning],
[InitISOFS, Always, TestOutput (
[["cat"; "/known-2"]], "abcdef\n")],
"list the contents of a file",
"\
Return the contents of the file named C<path>.
Note that this function cannot correctly handle binary files
(specifically, files containing C<\\0> character which is treated
as end of string). For those you need to use the C<guestfs_read_file>
or C<guestfs_download> functions which have a more complex interface.");
("ll", (RString "listing", [Pathname "directory"]), 5, [],
[], (* XXX Tricky to test because it depends on the exact format
* of the 'ls -l' command, which changes between F10 and F11.
*)
"list the files in a directory (long format)",
"\
List the files in C<directory> (relative to the root directory,
there is no cwd) in the format of 'ls -la'.
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"])],
"list the files in a directory",
"\
List the files in C<directory> (relative to the root directory,
there is no cwd). The '.' and '..' entries are not returned, but
hidden files are shown.
This command is mostly useful for interactive sessions. Programs
should probably use C<guestfs_readdir> instead.");
("list_devices", (RStringList "devices", []), 7, [],
[InitEmpty, Always, TestOutputListOfDevices (
[["list_devices"]], ["/dev/sda"; "/dev/sdb"; "/dev/sdc"; "/dev/sdd"])],
"list the block devices",
"\
List all the block devices.
The full block device names are returned, eg. C</dev/sda>");
("list_partitions", (RStringList "partitions", []), 8, [],
[InitBasicFS, Always, TestOutputListOfDevices (
[["list_partitions"]], ["/dev/sda1"]);
InitEmpty, Always, TestOutputListOfDevices (
[["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
["list_partitions"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])],
"list the partitions",
"\
List all the partitions detected on all block devices.
The full partition device names are returned, eg. C</dev/sda1>
This does not return logical volumes. For that you will need to
call C<guestfs_lvs>.");
("pvs", (RStringList "physvols", []), 9, [Optional "lvm2"],
[InitBasicFSonLVM, Always, TestOutputListOfDevices (
[["pvs"]], ["/dev/sda1"]);
InitEmpty, Always, TestOutputListOfDevices (
[["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
["pvcreate"; "/dev/sda1"];
["pvcreate"; "/dev/sda2"];
["pvcreate"; "/dev/sda3"];
["pvs"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])],
"list the LVM physical volumes (PVs)",
"\
List all the physical volumes detected. This is the equivalent
of the L<pvs(8)> command.
This returns a list of just the device names that contain
PVs (eg. C</dev/sda2>).
See also C<guestfs_pvs_full>.");
("vgs", (RStringList "volgroups", []), 10, [Optional "lvm2"],
[InitBasicFSonLVM, Always, TestOutputList (
[["vgs"]], ["VG"]);
InitEmpty, Always, TestOutputList (
[["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
["pvcreate"; "/dev/sda1"];
["pvcreate"; "/dev/sda2"];
["pvcreate"; "/dev/sda3"];
["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
["vgcreate"; "VG2"; "/dev/sda3"];
["vgs"]], ["VG1"; "VG2"])],
"list the LVM volume groups (VGs)",
"\
List all the volumes groups detected. This is the equivalent
of the L<vgs(8)> command.
This returns a list of just the volume group names that were
detected (eg. C<VolGroup00>).
See also C<guestfs_vgs_full>.");
("lvs", (RStringList "logvols", []), 11, [Optional "lvm2"],
[InitBasicFSonLVM, Always, TestOutputList (
[["lvs"]], ["/dev/VG/LV"]);
InitEmpty, Always, TestOutputList (
[["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
["pvcreate"; "/dev/sda1"];
["pvcreate"; "/dev/sda2"];
["pvcreate"; "/dev/sda3"];
["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
["vgcreate"; "VG2"; "/dev/sda3"];
["lvcreate"; "LV1"; "VG1"; "50"];
["lvcreate"; "LV2"; "VG1"; "50"];
["lvcreate"; "LV3"; "VG2"; "50"];
["lvs"]], ["/dev/VG1/LV1"; "/dev/VG1/LV2"; "/dev/VG2/LV3"])],
"list the LVM logical volumes (LVs)",
"\
List all the logical volumes detected. This is the equivalent
of the L<lvs(8)> command.
This returns a list of the logical volume device names
(eg. C</dev/VolGroup00/LogVol00>).
See also C<guestfs_lvs_full>.");
("pvs_full", (RStructList ("physvols", "lvm_pv"), []), 12, [Optional "lvm2"],
[], (* XXX how to test? *)
"list the LVM physical volumes (PVs)",
"\
List all the physical volumes detected. This is the equivalent
of the L<pvs(8)> command. The \"full\" version includes all fields.");
("vgs_full", (RStructList ("volgroups", "lvm_vg"), []), 13, [Optional "lvm2"],
[], (* XXX how to test? *)
"list the LVM volume groups (VGs)",
"\
List all the volumes groups detected. This is the equivalent
of the L<vgs(8)> command. The \"full\" version includes all fields.");
("lvs_full", (RStructList ("logvols", "lvm_lv"), []), 14, [Optional "lvm2"],
[], (* XXX how to test? *)
"list the LVM logical volumes (LVs)",
"\
List all the logical volumes detected. This is the equivalent
of the L<lvs(8)> command. The \"full\" version includes all fields.");
("read_lines", (RStringList "lines", [Pathname "path"]), 15, [],
[InitISOFS, Always, TestOutputList (
[["read_lines"; "/known-4"]], ["abc"; "def"; "ghi"]);
InitISOFS, Always, TestOutputList (
[["read_lines"; "/empty"]], [])],
"read file as lines",
"\
Return the contents of the file named C<path>.
The file contents are returned as a list of lines. Trailing
C<LF> and C<CRLF> character sequences are I<not> returned.
Note that this function cannot correctly handle binary files
(specifically, files containing C<\\0> character which is treated
as end of line). For those you need to use the C<guestfs_read_file>
function which has a more complex interface.");
("aug_init", (RErr, [Pathname "root"; Int "flags"]), 16, [Optional "augeas"],
[], (* XXX Augeas code needs tests. *)
"create a new Augeas handle",
"\
Create a new Augeas handle for editing configuration files.
If there was any previous Augeas handle associated with this
guestfs session, then it is closed.
You must call this before using any other C<guestfs_aug_*>
commands.
C<root> is the filesystem root. C<root> must not be NULL,
use C</> instead.
The flags are the same as the flags defined in
E<lt>augeas.hE<gt>, the logical I<or> of the following
integers:
=over 4
=item C<AUG_SAVE_BACKUP> = 1
Keep the original file with a C<.augsave> extension.
=item C<AUG_SAVE_NEWFILE> = 2
Save changes into a file with extension C<.augnew>, and
do not overwrite original. Overrides C<AUG_SAVE_BACKUP>.
=item C<AUG_TYPE_CHECK> = 4
Typecheck lenses (can be expensive).
=item C<AUG_NO_STDINC> = 8
Do not use standard load path for modules.
=item C<AUG_SAVE_NOOP> = 16
Make save a no-op, just record what would have been changed.
=item C<AUG_NO_LOAD> = 32
Do not load the tree in C<guestfs_aug_init>.
=back
To close the handle, you can call C<guestfs_aug_close>.
To find out more about Augeas, see L<http://augeas.net/>.");
("aug_close", (RErr, []), 26, [Optional "augeas"],
[], (* XXX Augeas code needs tests. *)
"close the current Augeas handle",
"\
Close the current Augeas handle and free up any resources
used by it. After calling this, you have to call
C<guestfs_aug_init> again before you can use any other
Augeas functions.");
("aug_defvar", (RInt "nrnodes", [String "name"; OptString "expr"]), 17, [Optional "augeas"],
[], (* XXX Augeas code needs tests. *)
"define an Augeas variable",
"\
Defines an Augeas variable C<name> whose value is the result
of evaluating C<expr>. If C<expr> is NULL, then C<name> is
undefined.
On success this returns the number of nodes in C<expr>, or
C<0> if C<expr> evaluates to something which is not a nodeset.");
("aug_defnode", (RStruct ("nrnodescreated", "int_bool"), [String "name"; String "expr"; String "val"]), 18, [Optional "augeas"],
[], (* XXX Augeas code needs tests. *)
"define an Augeas node",
"\
Defines a variable C<name> whose value is the result of
evaluating C<expr>.
If C<expr> evaluates to an empty nodeset, a node is created,
equivalent to calling C<guestfs_aug_set> C<expr>, C<value>.
C<name> will be the nodeset containing that single node.
On success this returns a pair containing the
number of nodes in the nodeset, and a boolean flag
if a node was created.");
("aug_get", (RString "val", [String "augpath"]), 19, [Optional "augeas"],
[], (* XXX Augeas code needs tests. *)
"look up the value of an Augeas path",
"\
Look up the value associated with C<path>. If C<path>
matches exactly one node, the C<value> is returned.");
("aug_set", (RErr, [String "augpath"; String "val"]), 20, [Optional "augeas"],
[], (* XXX Augeas code needs tests. *)
"set Augeas path to value",
"\
Set the value associated with C<path> to C<val>.
In the Augeas API, it is possible to clear a node by setting
the value to NULL. Due to an oversight in the libguestfs API
you cannot do that with this call. Instead you must use the
C<guestfs_aug_clear> call.");
("aug_insert", (RErr, [String "augpath"; String "label"; Bool "before"]), 21, [Optional "augeas"],
[], (* XXX Augeas code needs tests. *)
"insert a sibling Augeas node",
"\
Create a new sibling C<label> for C<path>, inserting it into
the tree before or after C<path> (depending on the boolean
flag C<before>).
C<path> must match exactly one existing node in the tree, and
C<label> must be a label, ie. not contain C</>, C<*> or end
with a bracketed index C<[N]>.");
("aug_rm", (RInt "nrnodes", [String "augpath"]), 22, [Optional "augeas"],
[], (* XXX Augeas code needs tests. *)
"remove an Augeas path",
"\
Remove C<path> and all of its children.
On success this returns the number of entries which were removed.");
("aug_mv", (RErr, [String "src"; String "dest"]), 23, [Optional "augeas"],
[], (* XXX Augeas code needs tests. *)
"move Augeas node",
"\
Move the node C<src> to C<dest>. C<src> must match exactly
one node. C<dest> is overwritten if it exists.");
("aug_match", (RStringList "matches", [String "augpath"]), 24, [Optional "augeas"],
[], (* XXX Augeas code needs tests. *)
"return Augeas nodes which match augpath",
"\
Returns a list of paths which match the path expression C<path>.
The returned paths are sufficiently qualified so that they match
exactly one node in the current tree.");
("aug_save", (RErr, []), 25, [Optional "augeas"],
[], (* XXX Augeas code needs tests. *)
"write all pending Augeas changes to disk",
"\
This writes all pending changes to disk.
The flags which were passed to C<guestfs_aug_init> affect exactly
how files are saved.");
("aug_load", (RErr, []), 27, [Optional "augeas"],
[], (* XXX Augeas code needs tests. *)
"load files into the tree",
"\
Load files into the tree.
See C<aug_load> in the Augeas documentation for the full gory
details.");
("aug_ls", (RStringList "matches", [String "augpath"]), 28, [Optional "augeas"],
[], (* XXX Augeas code needs tests. *)
"list Augeas nodes under augpath",
"\
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"]]],
"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"]]],
"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"]]],
"remove a file or directory recursively",
"\
Remove the file or directory C<path>, recursively removing the
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"]]],
"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"]];
(* Regression tests for RHBZ#503133: *)
InitBasicFS, Always, TestRun
[["mkdir"; "/new"];
["mkdir_p"; "/new"]];
InitBasicFS, Always, TestLastFail
[["touch"; "/new"];
["mkdir_p"; "/new"]]],
"create a directory and parents",
"\
Create a directory named C<path>, creating any parent directories
as necessary. This is like the C<mkdir -p> shell command.");
("chmod", (RErr, [Int "mode"; Pathname "path"]), 34, [],
[], (* XXX Need stat command to test *)
"change file mode",
"\
Change the mode (permissions) of C<path> to C<mode>. Only
numeric modes are supported.
I<Note>: When using this command from guestfish, C<mode>
by default would be decimal, unless you prefix it with
C<0> to get octal, ie. use C<0700> not C<700>.
The mode actually set is affected by the umask.");
("chown", (RErr, [Int "owner"; Int "group"; Pathname "path"]), 35, [],
[], (* XXX Need stat command to test *)
"change file owner and group",
"\
Change the file owner to C<owner> and group to C<group>.
Only numeric uid and gid are supported. If you want to use
names, you will need to locate and parse the password file
yourself (Augeas support makes this relatively easy).");
("exists", (RBool "existsflag", [Pathname "path"]), 36, [],
[InitISOFS, Always, TestOutputTrue (
[["exists"; "/empty"]]);
InitISOFS, Always, TestOutputTrue (
[["exists"; "/directory"]])],
"test if file or directory exists",
"\
This returns C<true> if and only if there is a file, directory
(or anything) with the given C<path> name.
See also C<guestfs_is_file>, C<guestfs_is_dir>, C<guestfs_stat>.");
("is_file", (RBool "fileflag", [Pathname "path"]), 37, [],
[InitISOFS, Always, TestOutputTrue (
[["is_file"; "/known-1"]]);
InitISOFS, Always, TestOutputFalse (
[["is_file"; "/directory"]])],
"test if file exists",
"\
This returns C<true> if and only if there is a file
with the given C<path> name. Note that it returns false for
other objects like directories.
See also C<guestfs_stat>.");
("is_dir", (RBool "dirflag", [Pathname "path"]), 38, [],
[InitISOFS, Always, TestOutputFalse (
[["is_dir"; "/known-3"]]);
InitISOFS, Always, TestOutputTrue (
[["is_dir"; "/directory"]])],
"test if file exists",
"\
This returns C<true> if and only if there is a directory
with the given C<path> name. Note that it returns false for
other objects like files.
See also C<guestfs_stat>.");
("pvcreate", (RErr, [Device "device"]), 39, [Optional "lvm2"],
[InitEmpty, Always, TestOutputListOfDevices (
[["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
["pvcreate"; "/dev/sda1"];
["pvcreate"; "/dev/sda2"];
["pvcreate"; "/dev/sda3"];
["pvs"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])],
"create an LVM physical volume",
"\
This creates an LVM physical volume on the named C<device>,
where C<device> should usually be a partition name such
as C</dev/sda1>.");
("vgcreate", (RErr, [String "volgroup"; DeviceList "physvols"]), 40, [Optional "lvm2"],
[InitEmpty, Always, TestOutputList (
[["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
["pvcreate"; "/dev/sda1"];
["pvcreate"; "/dev/sda2"];
["pvcreate"; "/dev/sda3"];
["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
["vgcreate"; "VG2"; "/dev/sda3"];
["vgs"]], ["VG1"; "VG2"])],
"create an LVM volume group",
"\
This creates an LVM volume group called C<volgroup>
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 ,"];
["pvcreate"; "/dev/sda1"];
["pvcreate"; "/dev/sda2"];
["pvcreate"; "/dev/sda3"];
["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
["vgcreate"; "VG2"; "/dev/sda3"];
["lvcreate"; "LV1"; "VG1"; "50"];
["lvcreate"; "LV2"; "VG1"; "50"];
["lvcreate"; "LV3"; "VG2"; "50"];
["lvcreate"; "LV4"; "VG2"; "50"];
["lvcreate"; "LV5"; "VG2"; "50"];
["lvs"]],
["/dev/VG1/LV1"; "/dev/VG1/LV2";
"/dev/VG2/LV3"; "/dev/VG2/LV4"; "/dev/VG2/LV5"])],
"create an LVM logical volume",
"\
This creates an LVM logical volume called C<logvol>
on the volume group C<volgroup>, with C<size> megabytes.");
("mkfs", (RErr, [String "fstype"; Device "device"]), 42, [],
[InitEmpty, Always, TestOutput (
[["part_disk"; "/dev/sda"; "mbr"];
["mkfs"; "ext2"; "/dev/sda1"];
["mount_options"; ""; "/dev/sda1"; "/"];
["write"; "/new"; "new file contents"];
["cat"; "/new"]], "new file contents")],
"make a filesystem",
"\
This creates a filesystem on C<device> (usually a partition
or LVM logical volume). The filesystem type is C<fstype>, for
example C<ext3>.");
("sfdisk", (RErr, [Device "device";
Int "cyls"; Int "heads"; Int "sectors";
StringList "lines"]), 43, [DangerWillRobinson],
[],
"create partitions on a block device",
"\
This is a direct interface to the L<sfdisk(8)> program for creating
partitions on block devices.
C<device> should be a block device, for example C</dev/sda>.
C<cyls>, C<heads> and C<sectors> are the number of cylinders, heads
and sectors on the device, which are passed directly to sfdisk as
the I<-C>, I<-H> and I<-S> parameters. If you pass C<0> for any
of these, then the corresponding parameter is omitted. Usually for
'large' disks, you can just pass C<0> for these, but for small
(floppy-sized) disks, sfdisk (or rather, the kernel) cannot work
out the right geometry and you will need to tell it.
C<lines> is a list of lines that we feed to C<sfdisk>. For more
information refer to the L<sfdisk(8)> manpage.
To create a single partition occupying the whole disk, you would
pass C<lines> as a single element list, when the single element being
the string C<,> (comma).
See also: C<guestfs_sfdisk_l>, C<guestfs_sfdisk_N>,
C<guestfs_part_init>");
("write_file", (RErr, [Pathname "path"; String "content"; Int "size"]), 44, [ProtocolLimitWarning; DeprecatedBy "write"],
[],
"create a file",
"\
This call creates a file called C<path>. The contents of the
file is the string C<content> (which can contain any 8 bit data),
with length C<size>.
As a special case, if C<size> is C<0>
then the length is calculated using C<strlen> (so in this case
the content cannot contain embedded ASCII NULs).
I<NB.> Owing to a bug, writing content containing ASCII NUL
characters does I<not> work, even if the length is specified.");
("umount", (RErr, [String "pathordevice"]), 45, [FishAlias "unmount"],
[InitEmpty, Always, TestOutputListOfDevices (
[["part_disk"; "/dev/sda"; "mbr"];
["mkfs"; "ext2"; "/dev/sda1"];
["mount_options"; ""; "/dev/sda1"; "/"];
["mounts"]], ["/dev/sda1"]);
InitEmpty, Always, TestOutputList (
[["part_disk"; "/dev/sda"; "mbr"];
["mkfs"; "ext2"; "/dev/sda1"];
["mount_options"; ""; "/dev/sda1"; "/"];
["umount"; "/"];
["mounts"]], [])],
"unmount a filesystem",
"\
This unmounts the given filesystem. The filesystem may be
specified either by its mountpoint (path) or the device which
contains the filesystem.");
("mounts", (RStringList "devices", []), 46, [],
[InitBasicFS, Always, TestOutputListOfDevices (
[["mounts"]], ["/dev/sda1"])],
"show mounted filesystems",
"\
This returns the list of currently mounted filesystems. It returns
the list of devices (eg. C</dev/sda1>, C</dev/VG/LV>).
Some internal mounts are not shown.
See also: C<guestfs_mountpoints>");
("umount_all", (RErr, []), 47, [FishAlias "unmount-all"],
[InitBasicFS, Always, TestOutputList (
[["umount_all"];
["mounts"]], []);
(* check that umount_all can unmount nested mounts correctly: *)
InitEmpty, Always, TestOutputList (
[["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
["mkfs"; "ext2"; "/dev/sda1"];
["mkfs"; "ext2"; "/dev/sda2"];
["mkfs"; "ext2"; "/dev/sda3"];
["mount_options"; ""; "/dev/sda1"; "/"];
["mkdir"; "/mp1"];
["mount_options"; ""; "/dev/sda2"; "/mp1"];
["mkdir"; "/mp1/mp2"];
["mount_options"; ""; "/dev/sda3"; "/mp1/mp2"];
["mkdir"; "/mp1/mp2/mp3"];
["umount_all"];
["mounts"]], [])],
"unmount all filesystems",
"\
This unmounts all mounted filesystems.
Some internal mounts are not unmounted by this call.");
("lvm_remove_all", (RErr, []), 48, [DangerWillRobinson; Optional "lvm2"],
[],
"remove all LVM LVs, VGs and PVs",
"\
This command removes all LVM logical volumes, volume groups
and physical volumes.");
("file", (RString "description", [Dev_or_Path "path"]), 49, [],
[InitISOFS, Always, TestOutput (
[["file"; "/empty"]], "empty");
InitISOFS, Always, TestOutput (
[["file"; "/known-1"]], "ASCII text");
InitISOFS, Always, TestLastFail (
[["file"; "/notexists"]])],
"determine file type",
"\
This call uses the standard L<file(1)> command to determine
the type or contents of the file. This also works on devices,
for example to find out whether a partition contains a filesystem.
This call will also transparently look inside various types
of compressed file.
The exact command which runs is C<file -zbsL path>. Note in
particular that the filename is not prepended to the output
(the C<-b> option).");
("command", (RString "output", [StringList "arguments"]), 50, [ProtocolLimitWarning],
[InitBasicFS, Always, TestOutput (
|