2 * Copyright (C) 2009-2010 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 (* Please read generator/README first. *)
21 (* Note about long descriptions: When referring to another
22 * action, use the format C<guestfs_other> (ie. the full name of
23 * the C function). This will be replaced as appropriate in other
26 * Apart from that, long descriptions are just perldoc paragraphs.
32 (* These test functions are used in the language binding tests. *)
47 (* except for RErr, which is tested thoroughly elsewhere *)
48 "test0rint", RInt "valout";
49 "test0rint64", RInt64 "valout";
50 "test0rbool", RBool "valout";
51 "test0rconststring", RConstString "valout";
52 "test0rconstoptstring", RConstOptString "valout";
53 "test0rstring", RString "valout";
54 "test0rstringlist", RStringList "valout";
55 "test0rstruct", RStruct ("valout", "lvm_pv");
56 "test0rstructlist", RStructList ("valout", "lvm_pv");
57 "test0rhashtable", RHashtable "valout";
60 let test_functions = [
61 ("test0", (RErr, test_all_args, []), -1, [NotInFish; NotInDocs],
63 "internal test function - do not use",
65 This is an internal test function which is used to test whether
66 the automatically generated bindings can handle every possible
67 parameter type correctly.
69 It echos the contents of each parameter to stdout.
71 You probably don't want to call this function.");
75 [(name, (ret, [String "val"], []), -1, [NotInFish; NotInDocs],
77 "internal test function - do not use",
79 This is an internal test function which is used to test whether
80 the automatically generated bindings can handle every possible
81 return type correctly.
83 It converts string C<val> to the return type.
85 You probably don't want to call this function.");
86 (name ^ "err", (ret, [], []), -1, [NotInFish; NotInDocs],
88 "internal test function - do not use",
90 This is an internal test function which is used to test whether
91 the automatically generated bindings can handle every possible
92 return type correctly.
94 This function always returns an error.
96 You probably don't want to call this function.")]
100 (* non_daemon_functions are any functions which don't get processed
101 * in the daemon, eg. functions for setting and getting local
102 * configuration values.
105 let non_daemon_functions = test_functions @ [
106 ("launch", (RErr, [], []), -1, [FishAlias "run"],
108 "launch the qemu subprocess",
110 Internally libguestfs is implemented by running a virtual machine
113 You should call this after configuring the handle
114 (eg. adding drives) but before performing any actions.");
116 ("wait_ready", (RErr, [], []), -1, [NotInFish],
118 "wait until the qemu subprocess launches (no op)",
120 This function is a no op.
122 In versions of the API E<lt> 1.0.71 you had to call this function
123 just after calling C<guestfs_launch> to wait for the launch
124 to complete. However this is no longer necessary because
125 C<guestfs_launch> now does the waiting.
127 If you see any calls to this function in code then you can just
128 remove them, unless you want to retain compatibility with older
129 versions of the API.");
131 ("kill_subprocess", (RErr, [], []), -1, [],
133 "kill the qemu subprocess",
135 This kills the qemu subprocess. You should never need to call this.");
137 ("add_drive", (RErr, [String "filename"], []), -1, [],
139 "add an image to examine or modify",
141 This function is the equivalent of calling C<guestfs_add_drive_opts>
142 with no optional parameters, so the disk is added writable, with
143 the format being detected automatically.
145 Automatic detection of the format opens you up to a potential
146 security hole when dealing with untrusted raw-format images.
147 See CVE-2010-3851 and RHBZ#642934. Specifying the format closes
148 this security hole. Therefore you should think about replacing
149 calls to this function with calls to C<guestfs_add_drive_opts>,
150 and specifying the format.");
152 ("add_cdrom", (RErr, [String "filename"], []), -1, [DeprecatedBy "add_drive_opts"],
154 "add a CD-ROM disk image to examine",
156 This function adds a virtual CD-ROM disk image to the guest.
158 This is equivalent to the qemu parameter C<-cdrom filename>.
166 This call checks for the existence of C<filename>. This
167 stops you from specifying other types of drive which are supported
168 by qemu such as C<nbd:> and C<http:> URLs. To specify those, use
169 the general C<guestfs_config> call instead.
173 If you just want to add an ISO file (often you use this as an
174 efficient way to transfer large files into the guest), then you
175 should probably use C<guestfs_add_drive_ro> instead.
179 ("add_drive_ro", (RErr, [String "filename"], []), -1, [FishAlias "add-ro"],
181 "add a drive in snapshot mode (read-only)",
183 This function is the equivalent of calling C<guestfs_add_drive_opts>
184 with the optional parameter C<GUESTFS_ADD_DRIVE_OPTS_READONLY> set to 1,
185 so the disk is added read-only, with the format being detected
188 ("config", (RErr, [String "qemuparam"; OptString "qemuvalue"], []), -1, [],
190 "add qemu parameters",
192 This can be used to add arbitrary qemu command line parameters
193 of the form C<-param value>. Actually it's not quite arbitrary - we
194 prevent you from setting some parameters which would interfere with
195 parameters that we use.
197 The first character of C<param> string must be a C<-> (dash).
199 C<value> can be NULL.");
201 ("set_qemu", (RErr, [OptString "qemu"], []), -1, [FishAlias "qemu"],
203 "set the qemu binary",
205 Set the qemu binary that we will use.
207 The default is chosen when the library was compiled by the
210 You can also override this by setting the C<LIBGUESTFS_QEMU>
211 environment variable.
213 Setting C<qemu> to C<NULL> restores the default qemu binary.
215 Note that you should call this function as early as possible
216 after creating the handle. This is because some pre-launch
217 operations depend on testing qemu features (by running C<qemu -help>).
218 If the qemu binary changes, we don't retest features, and
219 so you might see inconsistent results. Using the environment
220 variable C<LIBGUESTFS_QEMU> is safest of all since that picks
221 the qemu binary at the same time as the handle is created.");
223 ("get_qemu", (RConstString "qemu", [], []), -1, [],
224 [InitNone, Always, TestRun (
226 "get the qemu binary",
228 Return the current qemu binary.
230 This is always non-NULL. If it wasn't set already, then this will
231 return the default qemu binary name.");
233 ("set_path", (RErr, [OptString "searchpath"], []), -1, [FishAlias "path"],
235 "set the search path",
237 Set the path that libguestfs searches for kernel and initrd.img.
239 The default is C<$libdir/guestfs> unless overridden by setting
240 C<LIBGUESTFS_PATH> environment variable.
242 Setting C<path> to C<NULL> restores the default path.");
244 ("get_path", (RConstString "path", [], []), -1, [],
245 [InitNone, Always, TestRun (
247 "get the search path",
249 Return the current search path.
251 This is always non-NULL. If it wasn't set already, then this will
252 return the default path.");
254 ("set_append", (RErr, [OptString "append"], []), -1, [FishAlias "append"],
256 "add options to kernel command line",
258 This function is used to add additional options to the
259 guest kernel command line.
261 The default is C<NULL> unless overridden by setting
262 C<LIBGUESTFS_APPEND> environment variable.
264 Setting C<append> to C<NULL> means I<no> additional options
265 are passed (libguestfs always adds a few of its own).");
267 ("get_append", (RConstOptString "append", [], []), -1, [],
268 (* This cannot be tested with the current framework. The
269 * function can return NULL in normal operations, which the
270 * test framework interprets as an error.
273 "get the additional kernel options",
275 Return the additional kernel options which are added to the
276 guest kernel command line.
278 If C<NULL> then no options are added.");
280 ("set_autosync", (RErr, [Bool "autosync"], []), -1, [FishAlias "autosync"],
284 If C<autosync> is true, this enables autosync. Libguestfs will make a
285 best effort attempt to run C<guestfs_umount_all> followed by
286 C<guestfs_sync> when the handle is closed
287 (also if the program exits without closing handles).
289 This is enabled by default (since libguestfs 1.5.24, previously it was
290 disabled by default).");
292 ("get_autosync", (RBool "autosync", [], []), -1, [],
293 [InitNone, Always, TestOutputTrue (
294 [["get_autosync"]])],
297 Get the autosync flag.");
299 ("set_verbose", (RErr, [Bool "verbose"], []), -1, [FishAlias "verbose"],
303 If C<verbose> is true, this turns on verbose messages (to C<stderr>).
305 Verbose messages are disabled unless the environment variable
306 C<LIBGUESTFS_DEBUG> is defined and set to C<1>.");
308 ("get_verbose", (RBool "verbose", [], []), -1, [],
312 This returns the verbose messages flag.");
314 ("is_ready", (RBool "ready", [], []), -1, [],
315 [InitNone, Always, TestOutputTrue (
317 "is ready to accept commands",
319 This returns true iff this handle is ready to accept commands
320 (in the C<READY> state).
322 For more information on states, see L<guestfs(3)>.");
324 ("is_config", (RBool "config", [], []), -1, [],
325 [InitNone, Always, TestOutputFalse (
327 "is in configuration state",
329 This returns true iff this handle is being configured
330 (in the C<CONFIG> state).
332 For more information on states, see L<guestfs(3)>.");
334 ("is_launching", (RBool "launching", [], []), -1, [],
335 [InitNone, Always, TestOutputFalse (
336 [["is_launching"]])],
337 "is launching subprocess",
339 This returns true iff this handle is launching the subprocess
340 (in the C<LAUNCHING> state).
342 For more information on states, see L<guestfs(3)>.");
344 ("is_busy", (RBool "busy", [], []), -1, [],
345 [InitNone, Always, TestOutputFalse (
347 "is busy processing a command",
349 This returns true iff this handle is busy processing a command
350 (in the C<BUSY> state).
352 For more information on states, see L<guestfs(3)>.");
354 ("get_state", (RInt "state", [], []), -1, [],
356 "get the current state",
358 This returns the current state as an opaque integer. This is
359 only useful for printing debug and internal error messages.
361 For more information on states, see L<guestfs(3)>.");
363 ("set_memsize", (RErr, [Int "memsize"], []), -1, [FishAlias "memsize"],
364 [InitNone, Always, TestOutputInt (
365 [["set_memsize"; "500"];
366 ["get_memsize"]], 500)],
367 "set memory allocated to the qemu subprocess",
369 This sets the memory size in megabytes allocated to the
370 qemu subprocess. This only has any effect if called before
373 You can also change this by setting the environment
374 variable C<LIBGUESTFS_MEMSIZE> before the handle is
377 For more information on the architecture of libguestfs,
378 see L<guestfs(3)>.");
380 ("get_memsize", (RInt "memsize", [], []), -1, [],
381 [InitNone, Always, TestOutputIntOp (
382 [["get_memsize"]], ">=", 256)],
383 "get memory allocated to the qemu subprocess",
385 This gets the memory size in megabytes allocated to the
388 If C<guestfs_set_memsize> was not called
389 on this handle, and if C<LIBGUESTFS_MEMSIZE> was not set,
390 then this returns the compiled-in default value for memsize.
392 For more information on the architecture of libguestfs,
393 see L<guestfs(3)>.");
395 ("get_pid", (RInt "pid", [], []), -1, [FishAlias "pid"],
396 [InitNone, Always, TestOutputIntOp (
397 [["get_pid"]], ">=", 1)],
398 "get PID of qemu subprocess",
400 Return the process ID of the qemu subprocess. If there is no
401 qemu subprocess, then this will return an error.
403 This is an internal call used for debugging and testing.");
405 ("version", (RStruct ("version", "version"), [], []), -1, [],
406 [InitNone, Always, TestOutputStruct (
407 [["version"]], [CompareWithInt ("major", 1)])],
408 "get the library version number",
410 Return the libguestfs version number that the program is linked
413 Note that because of dynamic linking this is not necessarily
414 the version of libguestfs that you compiled against. You can
415 compile the program, and then at runtime dynamically link
416 against a completely different C<libguestfs.so> library.
418 This call was added in version C<1.0.58>. In previous
419 versions of libguestfs there was no way to get the version
420 number. From C code you can use dynamic linker functions
421 to find out if this symbol exists (if it doesn't, then
422 it's an earlier version).
424 The call returns a structure with four elements. The first
425 three (C<major>, C<minor> and C<release>) are numbers and
426 correspond to the usual version triplet. The fourth element
427 (C<extra>) is a string and is normally empty, but may be
428 used for distro-specific information.
430 To construct the original version string:
431 C<$major.$minor.$release$extra>
433 See also: L<guestfs(3)/LIBGUESTFS VERSION NUMBERS>.
435 I<Note:> Don't use this call to test for availability
436 of features. In enterprise distributions we backport
437 features from later versions into earlier versions,
438 making this an unreliable way to test for features.
439 Use C<guestfs_available> instead.");
441 ("set_selinux", (RErr, [Bool "selinux"], []), -1, [FishAlias "selinux"],
442 [InitNone, Always, TestOutputTrue (
443 [["set_selinux"; "true"];
445 "set SELinux enabled or disabled at appliance boot",
447 This sets the selinux flag that is passed to the appliance
448 at boot time. The default is C<selinux=0> (disabled).
450 Note that if SELinux is enabled, it is always in
451 Permissive mode (C<enforcing=0>).
453 For more information on the architecture of libguestfs,
454 see L<guestfs(3)>.");
456 ("get_selinux", (RBool "selinux", [], []), -1, [],
458 "get SELinux enabled flag",
460 This returns the current setting of the selinux flag which
461 is passed to the appliance at boot time. See C<guestfs_set_selinux>.
463 For more information on the architecture of libguestfs,
464 see L<guestfs(3)>.");
466 ("set_trace", (RErr, [Bool "trace"], []), -1, [FishAlias "trace"],
467 [InitNone, Always, TestOutputFalse (
468 [["set_trace"; "false"];
470 "enable or disable command traces",
472 If the command trace flag is set to 1, then commands are
473 printed on stderr before they are executed in a format
474 which is very similar to the one used by guestfish. In
475 other words, you can run a program with this enabled, and
476 you will get out a script which you can feed to guestfish
477 to perform the same set of actions.
479 If you want to trace C API calls into libguestfs (and
480 other libraries) then possibly a better way is to use
481 the external ltrace(1) command.
483 Command traces are disabled unless the environment variable
484 C<LIBGUESTFS_TRACE> is defined and set to C<1>.");
486 ("get_trace", (RBool "trace", [], []), -1, [],
488 "get command trace enabled flag",
490 Return the command trace flag.");
492 ("set_direct", (RErr, [Bool "direct"], []), -1, [FishAlias "direct"],
493 [InitNone, Always, TestOutputFalse (
494 [["set_direct"; "false"];
496 "enable or disable direct appliance mode",
498 If the direct appliance mode flag is enabled, then stdin and
499 stdout are passed directly through to the appliance once it
502 One consequence of this is that log messages aren't caught
503 by the library and handled by C<guestfs_set_log_message_callback>,
504 but go straight to stdout.
506 You probably don't want to use this unless you know what you
509 The default is disabled.");
511 ("get_direct", (RBool "direct", [], []), -1, [],
513 "get direct appliance mode flag",
515 Return the direct appliance mode flag.");
517 ("set_recovery_proc", (RErr, [Bool "recoveryproc"], []), -1, [FishAlias "recovery-proc"],
518 [InitNone, Always, TestOutputTrue (
519 [["set_recovery_proc"; "true"];
520 ["get_recovery_proc"]])],
521 "enable or disable the recovery process",
523 If this is called with the parameter C<false> then
524 C<guestfs_launch> does not create a recovery process. The
525 purpose of the recovery process is to stop runaway qemu
526 processes in the case where the main program aborts abruptly.
528 This only has any effect if called before C<guestfs_launch>,
529 and the default is true.
531 About the only time when you would want to disable this is
532 if the main process will fork itself into the background
533 (\"daemonize\" itself). In this case the recovery process
534 thinks that the main program has disappeared and so kills
535 qemu, which is not very helpful.");
537 ("get_recovery_proc", (RBool "recoveryproc", [], []), -1, [],
539 "get recovery process enabled flag",
541 Return the recovery process enabled flag.");
543 ("add_drive_with_if", (RErr, [String "filename"; String "iface"], []), -1, [DeprecatedBy "add_drive_opts"],
545 "add a drive specifying the QEMU block emulation to use",
547 This is the same as C<guestfs_add_drive> but it allows you
548 to specify the QEMU interface emulation to use at run time.");
550 ("add_drive_ro_with_if", (RErr, [String "filename"; String "iface"], []), -1, [DeprecatedBy "add_drive_opts"],
552 "add a drive read-only specifying the QEMU block emulation to use",
554 This is the same as C<guestfs_add_drive_ro> but it allows you
555 to specify the QEMU interface emulation to use at run time.");
557 ("file_architecture", (RString "arch", [Pathname "filename"], []), -1, [],
558 [InitISOFS, Always, TestOutput (
559 [["file_architecture"; "/bin-i586-dynamic"]], "i386");
560 InitISOFS, Always, TestOutput (
561 [["file_architecture"; "/bin-sparc-dynamic"]], "sparc");
562 InitISOFS, Always, TestOutput (
563 [["file_architecture"; "/bin-win32.exe"]], "i386");
564 InitISOFS, Always, TestOutput (
565 [["file_architecture"; "/bin-win64.exe"]], "x86_64");
566 InitISOFS, Always, TestOutput (
567 [["file_architecture"; "/bin-x86_64-dynamic"]], "x86_64");
568 InitISOFS, Always, TestOutput (
569 [["file_architecture"; "/lib-i586.so"]], "i386");
570 InitISOFS, Always, TestOutput (
571 [["file_architecture"; "/lib-sparc.so"]], "sparc");
572 InitISOFS, Always, TestOutput (
573 [["file_architecture"; "/lib-win32.dll"]], "i386");
574 InitISOFS, Always, TestOutput (
575 [["file_architecture"; "/lib-win64.dll"]], "x86_64");
576 InitISOFS, Always, TestOutput (
577 [["file_architecture"; "/lib-x86_64.so"]], "x86_64");
578 InitISOFS, Always, TestOutput (
579 [["file_architecture"; "/initrd-x86_64.img"]], "x86_64");
580 InitISOFS, Always, TestOutput (
581 [["file_architecture"; "/initrd-x86_64.img.gz"]], "x86_64");],
582 "detect the architecture of a binary file",
584 This detects the architecture of the binary C<filename>,
585 and returns it if known.
587 Currently defined architectures are:
593 This string is returned for all 32 bit i386, i486, i586, i686 binaries
594 irrespective of the precise processor requirements of the binary.
606 64 bit SPARC V9 and above.
622 Libguestfs may return other architecture strings in future.
624 The function works on at least the following types of files:
630 many types of Un*x and Linux binary
634 many types of Un*x and Linux shared library
638 Windows Win32 and Win64 binaries
642 Windows Win32 and Win64 DLLs
644 Win32 binaries and DLLs return C<i386>.
646 Win64 binaries and DLLs return C<x86_64>.
654 Linux new-style initrd images
658 some non-x86 Linux vmlinuz kernels
662 What it can't do currently:
668 static libraries (libfoo.a)
672 Linux old-style initrd as compressed ext2 filesystem (RHEL 3)
676 x86 Linux vmlinuz kernels
678 x86 vmlinuz images (bzImage format) consist of a mix of 16-, 32- and
679 compressed code, and are horribly hard to unpack. If you want to find
680 the architecture of a kernel, use the architecture of the associated
681 initrd or kernel module(s) instead.
685 ("inspect_os", (RStringList "roots", [], []), -1, [],
687 "inspect disk and return list of operating systems found",
689 This function uses other libguestfs functions and certain
690 heuristics to inspect the disk(s) (usually disks belonging to
691 a virtual machine), looking for operating systems.
693 The list returned is empty if no operating systems were found.
695 If one operating system was found, then this returns a list with
696 a single element, which is the name of the root filesystem of
697 this operating system. It is also possible for this function
698 to return a list containing more than one element, indicating
699 a dual-boot or multi-boot virtual machine, with each element being
700 the root filesystem of one of the operating systems.
702 You can pass the root string(s) returned to other
703 C<guestfs_inspect_get_*> functions in order to query further
704 information about each operating system, such as the name
707 This function uses other libguestfs features such as
708 C<guestfs_mount_ro> and C<guestfs_umount_all> in order to mount
709 and unmount filesystems and look at the contents. This should
710 be called with no disks currently mounted. The function may also
711 use Augeas, so any existing Augeas handle will be closed.
713 This function cannot decrypt encrypted disks. The caller
714 must do that first (supplying the necessary keys) if the
717 Please read L<guestfs(3)/INSPECTION> for more details.
719 See also C<guestfs_list_filesystems>.");
721 ("inspect_get_type", (RString "name", [Device "root"], []), -1, [],
723 "get type of inspected operating system",
725 This function should only be called with a root device string
726 as returned by C<guestfs_inspect_os>.
728 This returns the type of the inspected operating system.
729 Currently defined types are:
735 Any Linux-based operating system.
739 Any Microsoft Windows operating system.
747 The operating system type could not be determined.
751 Future versions of libguestfs may return other strings here.
752 The caller should be prepared to handle any string.
754 Please read L<guestfs(3)/INSPECTION> for more details.");
756 ("inspect_get_arch", (RString "arch", [Device "root"], []), -1, [],
758 "get architecture of inspected operating system",
760 This function should only be called with a root device string
761 as returned by C<guestfs_inspect_os>.
763 This returns the architecture of the inspected operating system.
764 The possible return values are listed under
765 C<guestfs_file_architecture>.
767 If the architecture could not be determined, then the
768 string C<unknown> is returned.
770 Please read L<guestfs(3)/INSPECTION> for more details.");
772 ("inspect_get_distro", (RString "distro", [Device "root"], []), -1, [],
774 "get distro of inspected operating system",
776 This function should only be called with a root device string
777 as returned by C<guestfs_inspect_os>.
779 This returns the distro (distribution) of the inspected operating
782 Currently defined distros are:
792 Debian or a Debian-derived distro such as Ubuntu.
810 =item \"redhat-based\"
812 Some Red Hat-derived distro.
816 Red Hat Enterprise Linux and some derivatives.
820 Windows does not have distributions. This string is
821 returned if the OS type is Windows.
829 The distro could not be determined.
833 Future versions of libguestfs may return other strings here.
834 The caller should be prepared to handle any string.
836 Please read L<guestfs(3)/INSPECTION> for more details.");
838 ("inspect_get_major_version", (RInt "major", [Device "root"], []), -1, [],
840 "get major version of inspected operating system",
842 This function should only be called with a root device string
843 as returned by C<guestfs_inspect_os>.
845 This returns the major version number of the inspected operating
848 Windows uses a consistent versioning scheme which is I<not>
849 reflected in the popular public names used by the operating system.
850 Notably the operating system known as \"Windows 7\" is really
851 version 6.1 (ie. major = 6, minor = 1). You can find out the
852 real versions corresponding to releases of Windows by consulting
855 If the version could not be determined, then C<0> is returned.
857 Please read L<guestfs(3)/INSPECTION> for more details.");
859 ("inspect_get_minor_version", (RInt "minor", [Device "root"], []), -1, [],
861 "get minor version of inspected operating system",
863 This function should only be called with a root device string
864 as returned by C<guestfs_inspect_os>.
866 This returns the minor version number of the inspected operating
869 If the version could not be determined, then C<0> is returned.
871 Please read L<guestfs(3)/INSPECTION> for more details.
872 See also C<guestfs_inspect_get_major_version>.");
874 ("inspect_get_product_name", (RString "product", [Device "root"], []), -1, [],
876 "get product name of inspected operating system",
878 This function should only be called with a root device string
879 as returned by C<guestfs_inspect_os>.
881 This returns the product name of the inspected operating
882 system. The product name is generally some freeform string
883 which can be displayed to the user, but should not be
886 If the product name could not be determined, then the
887 string C<unknown> is returned.
889 Please read L<guestfs(3)/INSPECTION> for more details.");
891 ("inspect_get_mountpoints", (RHashtable "mountpoints", [Device "root"], []), -1, [],
893 "get mountpoints of inspected operating system",
895 This function should only be called with a root device string
896 as returned by C<guestfs_inspect_os>.
898 This returns a hash of where we think the filesystems
899 associated with this operating system should be mounted.
900 Callers should note that this is at best an educated guess
901 made by reading configuration files such as C</etc/fstab>.
903 Each element in the returned hashtable has a key which
904 is the path of the mountpoint (eg. C</boot>) and a value
905 which is the filesystem that would be mounted there
908 Non-mounted devices such as swap devices are I<not>
909 returned in this list.
911 Please read L<guestfs(3)/INSPECTION> for more details.
912 See also C<guestfs_inspect_get_filesystems>.");
914 ("inspect_get_filesystems", (RStringList "filesystems", [Device "root"], []), -1, [],
916 "get filesystems associated with inspected operating system",
918 This function should only be called with a root device string
919 as returned by C<guestfs_inspect_os>.
921 This returns a list of all the filesystems that we think
922 are associated with this operating system. This includes
923 the root filesystem, other ordinary filesystems, and
924 non-mounted devices like swap partitions.
926 In the case of a multi-boot virtual machine, it is possible
927 for a filesystem to be shared between operating systems.
929 Please read L<guestfs(3)/INSPECTION> for more details.
930 See also C<guestfs_inspect_get_mountpoints>.");
932 ("set_network", (RErr, [Bool "network"], []), -1, [FishAlias "network"],
934 "set enable network flag",
936 If C<network> is true, then the network is enabled in the
937 libguestfs appliance. The default is false.
939 This affects whether commands are able to access the network
940 (see L<guestfs(3)/RUNNING COMMANDS>).
942 You must call this before calling C<guestfs_launch>, otherwise
945 ("get_network", (RBool "network", [], []), -1, [],
947 "get enable network flag",
949 This returns the enable network flag.");
951 ("list_filesystems", (RHashtable "fses", [], []), -1, [],
955 This inspection command looks for filesystems on partitions,
956 block devices and logical volumes, returning a list of devices
957 containing filesystems and their type.
959 The return value is a hash, where the keys are the devices
960 containing filesystems, and the values are the filesystem types.
963 \"/dev/sda1\" => \"ntfs\"
964 \"/dev/sda2\" => \"ext2\"
965 \"/dev/vg_guest/lv_root\" => \"ext4\"
966 \"/dev/vg_guest/lv_swap\" => \"swap\"
968 The value can have the special value \"unknown\", meaning the
969 content of the device is undetermined or empty.
970 \"swap\" means a Linux swap partition.
972 This command runs other libguestfs commands, which might include
973 C<guestfs_mount> and C<guestfs_umount>, and therefore you should
974 use this soon after launch and only when nothing is mounted.
976 Not all of the filesystems returned will be mountable. In
977 particular, swap partitions are returned in the list. Also
978 this command does not check that each filesystem
979 found is valid and mountable, and some filesystems might
980 be mountable but require special options. Filesystems may
981 not all belong to a single logical operating system
982 (use C<guestfs_inspect_os> to look for OSes).");
984 ("add_drive_opts", (RErr, [String "filename"], [Bool "readonly"; String "format"; String "iface"]), -1, [FishAlias "add"],
986 "add an image to examine or modify",
988 This function adds a virtual machine disk image C<filename> to
989 libguestfs. The first time you call this function, the disk
990 appears as C</dev/sda>, the second time as C</dev/sdb>, and
993 You don't necessarily need to be root when using libguestfs. However
994 you obviously do need sufficient permissions to access the filename
995 for whatever operations you want to perform (ie. read access if you
996 just want to read the image or write access if you want to modify the
999 This call checks that C<filename> exists.
1001 The optional arguments are:
1007 If true then the image is treated as read-only. Writes are still
1008 allowed, but they are stored in a temporary snapshot overlay which
1009 is discarded at the end. The disk that you add is not modified.
1013 This forces the image format. If you omit this (or use C<guestfs_add_drive>
1014 or C<guestfs_add_drive_ro>) then the format is automatically detected.
1015 Possible formats include C<raw> and C<qcow2>.
1017 Automatic detection of the format opens you up to a potential
1018 security hole when dealing with untrusted raw-format images.
1019 See CVE-2010-3851 and RHBZ#642934. Specifying the format closes
1024 This rarely-used option lets you emulate the behaviour of the
1025 deprecated C<guestfs_add_drive_with_if> call (q.v.)
1029 ("inspect_get_windows_systemroot", (RString "systemroot", [Device "root"], []), -1, [],
1031 "get Windows systemroot of inspected operating system",
1033 This function should only be called with a root device string
1034 as returned by C<guestfs_inspect_os>.
1036 This returns the Windows systemroot of the inspected guest.
1037 The systemroot is a directory path such as C</WINDOWS>.
1039 This call assumes that the guest is Windows and that the
1040 systemroot could be determined by inspection. If this is not
1041 the case then an error is returned.
1043 Please read L<guestfs(3)/INSPECTION> for more details.");
1045 ("inspect_get_roots", (RStringList "roots", [], []), -1, [],
1047 "return list of operating systems found by last inspection",
1049 This function is a convenient way to get the list of root
1050 devices, as returned from a previous call to C<guestfs_inspect_os>,
1051 but without redoing the whole inspection process.
1053 This returns an empty list if either no root devices were
1054 found or the caller has not called C<guestfs_inspect_os>.
1056 Please read L<guestfs(3)/INSPECTION> for more details.");
1058 ("debug_cmdline", (RStringList "cmdline", [], []), -1, [NotInDocs],
1060 "debug the QEMU command line (internal use only)",
1062 This returns the internal QEMU command line. 'debug' commands are
1063 not part of the formal API and can be removed or changed at any time.");
1065 ("add_domain", (RInt "nrdisks", [String "dom"], [String "libvirturi"; Bool "readonly"; String "iface"]), -1, [FishAlias "domain"],
1067 "add the disk(s) from a named libvirt domain",
1069 This function adds the disk(s) attached to the named libvirt
1070 domain C<dom>. It works by connecting to libvirt, requesting
1071 the domain and domain XML from libvirt, parsing it for disks,
1072 and calling C<guestfs_add_drive_opts> on each one.
1074 The number of disks added is returned. This operation is atomic:
1075 if an error is returned, then no disks are added.
1077 This function does some minimal checks to make sure the libvirt
1078 domain is not running (unless C<readonly> is true). In a future
1079 version we will try to acquire the libvirt lock on each disk.
1081 Disks must be accessible locally. This often means that adding disks
1082 from a remote libvirt connection (see L<http://libvirt.org/remote.html>)
1083 will fail unless those disks are accessible via the same device path
1086 The optional C<libvirturi> parameter sets the libvirt URI
1087 (see L<http://libvirt.org/uri.html>). If this is not set then
1088 we connect to the default libvirt URI (or one set through an
1089 environment variable, see the libvirt documentation for full
1090 details). If you are using the C API directly then it is more
1091 flexible to create the libvirt connection object yourself, get
1092 the domain object, and call C<guestfs_add_libvirt_dom>.
1094 The other optional parameters are passed directly through to
1095 C<guestfs_add_drive_opts>.");
1098 This interface is not quite baked yet. -- RWMJ 2010-11-11
1099 ("add_libvirt_dom", (RInt "nrdisks", [Pointer ("virDomainPtr", "dom")], [Bool "readonly"; String "iface"]), -1, [NotInFish],
1101 "add the disk(s) from a libvirt domain",
1103 This function adds the disk(s) attached to the libvirt domain C<dom>.
1104 It works by requesting the domain XML from libvirt, parsing it for
1105 disks, and calling C<guestfs_add_drive_opts> on each one.
1107 In the C API we declare C<void *dom>, but really it has type
1108 C<virDomainPtr dom>. This is so we don't need E<lt>libvirt.hE<gt>.
1110 The number of disks added is returned. This operation is atomic:
1111 if an error is returned, then no disks are added.
1113 This function does some minimal checks to make sure the libvirt
1114 domain is not running (unless C<readonly> is true). In a future
1115 version we will try to acquire the libvirt lock on each disk.
1117 Disks must be accessible locally. This often means that adding disks
1118 from a remote libvirt connection (see L<http://libvirt.org/remote.html>)
1119 will fail unless those disks are accessible via the same device path
1122 The optional parameters are passed directly through to
1123 C<guestfs_add_drive_opts>.");
1126 ("inspect_get_package_format", (RString "packageformat", [Device "root"], []), -1, [],
1128 "get package format used by the operating system",
1130 This function should only be called with a root device string
1131 as returned by C<guestfs_inspect_os>.
1133 This function and C<guestfs_inspect_get_package_management> return
1134 the package format and package management tool used by the
1135 inspected operating system. For example for Fedora these
1136 functions would return C<rpm> (package format) and
1137 C<yum> (package management).
1139 This returns the string C<unknown> if we could not determine the
1140 package format I<or> if the operating system does not have
1141 a real packaging system (eg. Windows).
1143 Possible strings include: C<rpm>, C<deb>, C<ebuild>, C<pisi>, C<pacman>.
1144 Future versions of libguestfs may return other strings.
1146 Please read L<guestfs(3)/INSPECTION> for more details.");
1148 ("inspect_get_package_management", (RString "packagemanagement", [Device "root"], []), -1, [],
1150 "get package management tool used by the operating system",
1152 This function should only be called with a root device string
1153 as returned by C<guestfs_inspect_os>.
1155 C<guestfs_inspect_get_package_format> and this function return
1156 the package format and package management tool used by the
1157 inspected operating system. For example for Fedora these
1158 functions would return C<rpm> (package format) and
1159 C<yum> (package management).
1161 This returns the string C<unknown> if we could not determine the
1162 package management tool I<or> if the operating system does not have
1163 a real packaging system (eg. Windows).
1165 Possible strings include: C<yum>, C<up2date>,
1166 C<apt> (for all Debian derivatives),
1167 C<portage>, C<pisi>, C<pacman>.
1168 Future versions of libguestfs may return other strings.
1170 Please read L<guestfs(3)/INSPECTION> for more details.");
1174 (* daemon_functions are any functions which cause some action
1175 * to take place in the daemon.
1178 let daemon_functions = [
1179 ("mount", (RErr, [Device "device"; String "mountpoint"], []), 1, [],
1180 [InitEmpty, Always, TestOutput (
1181 [["part_disk"; "/dev/sda"; "mbr"];
1182 ["mkfs"; "ext2"; "/dev/sda1"];
1183 ["mount"; "/dev/sda1"; "/"];
1184 ["write"; "/new"; "new file contents"];
1185 ["cat"; "/new"]], "new file contents")],
1186 "mount a guest disk at a position in the filesystem",
1188 Mount a guest disk at a position in the filesystem. Block devices
1189 are named C</dev/sda>, C</dev/sdb> and so on, as they were added to
1190 the guest. If those block devices contain partitions, they will have
1191 the usual names (eg. C</dev/sda1>). Also LVM C</dev/VG/LV>-style
1194 The rules are the same as for L<mount(2)>: A filesystem must
1195 first be mounted on C</> before others can be mounted. Other
1196 filesystems can only be mounted on directories which already
1199 The mounted filesystem is writable, if we have sufficient permissions
1200 on the underlying device.
1203 When you use this call, the filesystem options C<sync> and C<noatime>
1204 are set implicitly. This was originally done because we thought it
1205 would improve reliability, but it turns out that I<-o sync> has a
1206 very large negative performance impact and negligible effect on
1207 reliability. Therefore we recommend that you avoid using
1208 C<guestfs_mount> in any code that needs performance, and instead
1209 use C<guestfs_mount_options> (use an empty string for the first
1210 parameter if you don't want any options).");
1212 ("sync", (RErr, [], []), 2, [],
1213 [ InitEmpty, Always, TestRun [["sync"]]],
1214 "sync disks, writes are flushed through to the disk image",
1216 This syncs the disk, so that any writes are flushed through to the
1217 underlying disk image.
1219 You should always call this if you have modified a disk image, before
1220 closing the handle.");
1222 ("touch", (RErr, [Pathname "path"], []), 3, [],
1223 [InitBasicFS, Always, TestOutputTrue (
1225 ["exists"; "/new"]])],
1226 "update file timestamps or create a new file",
1228 Touch acts like the L<touch(1)> command. It can be used to
1229 update the timestamps on a file, or, if the file does not exist,
1230 to create a new zero-length file.
1232 This command only works on regular files, and will fail on other
1233 file types such as directories, symbolic links, block special etc.");
1235 ("cat", (RString "content", [Pathname "path"], []), 4, [ProtocolLimitWarning],
1236 [InitISOFS, Always, TestOutput (
1237 [["cat"; "/known-2"]], "abcdef\n")],
1238 "list the contents of a file",
1240 Return the contents of the file named C<path>.
1242 Note that this function cannot correctly handle binary files
1243 (specifically, files containing C<\\0> character which is treated
1244 as end of string). For those you need to use the C<guestfs_read_file>
1245 or C<guestfs_download> functions which have a more complex interface.");
1247 ("ll", (RString "listing", [Pathname "directory"], []), 5, [],
1248 [], (* XXX Tricky to test because it depends on the exact format
1249 * of the 'ls -l' command, which changes between F10 and F11.
1251 "list the files in a directory (long format)",
1253 List the files in C<directory> (relative to the root directory,
1254 there is no cwd) in the format of 'ls -la'.
1256 This command is mostly useful for interactive sessions. It
1257 is I<not> intended that you try to parse the output string.");
1259 ("ls", (RStringList "listing", [Pathname "directory"], []), 6, [],
1260 [InitBasicFS, Always, TestOutputList (
1262 ["touch"; "/newer"];
1263 ["touch"; "/newest"];
1264 ["ls"; "/"]], ["lost+found"; "new"; "newer"; "newest"])],
1265 "list the files in a directory",
1267 List the files in C<directory> (relative to the root directory,
1268 there is no cwd). The '.' and '..' entries are not returned, but
1269 hidden files are shown.
1271 This command is mostly useful for interactive sessions. Programs
1272 should probably use C<guestfs_readdir> instead.");
1274 ("list_devices", (RStringList "devices", [], []), 7, [],
1275 [InitEmpty, Always, TestOutputListOfDevices (
1276 [["list_devices"]], ["/dev/sda"; "/dev/sdb"; "/dev/sdc"; "/dev/sdd"])],
1277 "list the block devices",
1279 List all the block devices.
1281 The full block device names are returned, eg. C</dev/sda>.
1283 See also C<guestfs_list_filesystems>.");
1285 ("list_partitions", (RStringList "partitions", [], []), 8, [],
1286 [InitBasicFS, Always, TestOutputListOfDevices (
1287 [["list_partitions"]], ["/dev/sda1"]);
1288 InitEmpty, Always, TestOutputListOfDevices (
1289 [["part_init"; "/dev/sda"; "mbr"];
1290 ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
1291 ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
1292 ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
1293 ["list_partitions"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])],
1294 "list the partitions",
1296 List all the partitions detected on all block devices.
1298 The full partition device names are returned, eg. C</dev/sda1>
1300 This does not return logical volumes. For that you will need to
1301 call C<guestfs_lvs>.
1303 See also C<guestfs_list_filesystems>.");
1305 ("pvs", (RStringList "physvols", [], []), 9, [Optional "lvm2"],
1306 [InitBasicFSonLVM, Always, TestOutputListOfDevices (
1307 [["pvs"]], ["/dev/sda1"]);
1308 InitEmpty, Always, TestOutputListOfDevices (
1309 [["part_init"; "/dev/sda"; "mbr"];
1310 ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
1311 ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
1312 ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
1313 ["pvcreate"; "/dev/sda1"];
1314 ["pvcreate"; "/dev/sda2"];
1315 ["pvcreate"; "/dev/sda3"];
1316 ["pvs"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])],
1317 "list the LVM physical volumes (PVs)",
1319 List all the physical volumes detected. This is the equivalent
1320 of the L<pvs(8)> command.
1322 This returns a list of just the device names that contain
1323 PVs (eg. C</dev/sda2>).
1325 See also C<guestfs_pvs_full>.");
1327 ("vgs", (RStringList "volgroups", [], []), 10, [Optional "lvm2"],
1328 [InitBasicFSonLVM, Always, TestOutputList (
1330 InitEmpty, Always, TestOutputList (
1331 [["part_init"; "/dev/sda"; "mbr"];
1332 ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
1333 ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
1334 ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
1335 ["pvcreate"; "/dev/sda1"];
1336 ["pvcreate"; "/dev/sda2"];
1337 ["pvcreate"; "/dev/sda3"];
1338 ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
1339 ["vgcreate"; "VG2"; "/dev/sda3"];
1340 ["vgs"]], ["VG1"; "VG2"])],
1341 "list the LVM volume groups (VGs)",
1343 List all the volumes groups detected. This is the equivalent
1344 of the L<vgs(8)> command.
1346 This returns a list of just the volume group names that were
1347 detected (eg. C<VolGroup00>).
1349 See also C<guestfs_vgs_full>.");
1351 ("lvs", (RStringList "logvols", [], []), 11, [Optional "lvm2"],
1352 [InitBasicFSonLVM, Always, TestOutputList (
1353 [["lvs"]], ["/dev/VG/LV"]);
1354 InitEmpty, Always, TestOutputList (
1355 [["part_init"; "/dev/sda"; "mbr"];
1356 ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
1357 ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
1358 ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
1359 ["pvcreate"; "/dev/sda1"];
1360 ["pvcreate"; "/dev/sda2"];
1361 ["pvcreate"; "/dev/sda3"];
1362 ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
1363 ["vgcreate"; "VG2"; "/dev/sda3"];
1364 ["lvcreate"; "LV1"; "VG1"; "50"];
1365 ["lvcreate"; "LV2"; "VG1"; "50"];
1366 ["lvcreate"; "LV3"; "VG2"; "50"];
1367 ["lvs"]], ["/dev/VG1/LV1"; "/dev/VG1/LV2"; "/dev/VG2/LV3"])],
1368 "list the LVM logical volumes (LVs)",
1370 List all the logical volumes detected. This is the equivalent
1371 of the L<lvs(8)> command.
1373 This returns a list of the logical volume device names
1374 (eg. C</dev/VolGroup00/LogVol00>).
1376 See also C<guestfs_lvs_full>, C<guestfs_list_filesystems>.");
1378 ("pvs_full", (RStructList ("physvols", "lvm_pv"), [], []), 12, [Optional "lvm2"],
1379 [], (* XXX how to test? *)
1380 "list the LVM physical volumes (PVs)",
1382 List all the physical volumes detected. This is the equivalent
1383 of the L<pvs(8)> command. The \"full\" version includes all fields.");
1385 ("vgs_full", (RStructList ("volgroups", "lvm_vg"), [], []), 13, [Optional "lvm2"],
1386 [], (* XXX how to test? *)
1387 "list the LVM volume groups (VGs)",
1389 List all the volumes groups detected. This is the equivalent
1390 of the L<vgs(8)> command. The \"full\" version includes all fields.");
1392 ("lvs_full", (RStructList ("logvols", "lvm_lv"), [], []), 14, [Optional "lvm2"],
1393 [], (* XXX how to test? *)
1394 "list the LVM logical volumes (LVs)",
1396 List all the logical volumes detected. This is the equivalent
1397 of the L<lvs(8)> command. The \"full\" version includes all fields.");
1399 ("read_lines", (RStringList "lines", [Pathname "path"], []), 15, [],
1400 [InitISOFS, Always, TestOutputList (
1401 [["read_lines"; "/known-4"]], ["abc"; "def"; "ghi"]);
1402 InitISOFS, Always, TestOutputList (
1403 [["read_lines"; "/empty"]], [])],
1404 "read file as lines",
1406 Return the contents of the file named C<path>.
1408 The file contents are returned as a list of lines. Trailing
1409 C<LF> and C<CRLF> character sequences are I<not> returned.
1411 Note that this function cannot correctly handle binary files
1412 (specifically, files containing C<\\0> character which is treated
1413 as end of line). For those you need to use the C<guestfs_read_file>
1414 function which has a more complex interface.");
1416 ("aug_init", (RErr, [Pathname "root"; Int "flags"], []), 16, [Optional "augeas"],
1417 [], (* XXX Augeas code needs tests. *)
1418 "create a new Augeas handle",
1420 Create a new Augeas handle for editing configuration files.
1421 If there was any previous Augeas handle associated with this
1422 guestfs session, then it is closed.
1424 You must call this before using any other C<guestfs_aug_*>
1427 C<root> is the filesystem root. C<root> must not be NULL,
1430 The flags are the same as the flags defined in
1431 E<lt>augeas.hE<gt>, the logical I<or> of the following
1436 =item C<AUG_SAVE_BACKUP> = 1
1438 Keep the original file with a C<.augsave> extension.
1440 =item C<AUG_SAVE_NEWFILE> = 2
1442 Save changes into a file with extension C<.augnew>, and
1443 do not overwrite original. Overrides C<AUG_SAVE_BACKUP>.
1445 =item C<AUG_TYPE_CHECK> = 4
1447 Typecheck lenses (can be expensive).
1449 =item C<AUG_NO_STDINC> = 8
1451 Do not use standard load path for modules.
1453 =item C<AUG_SAVE_NOOP> = 16
1455 Make save a no-op, just record what would have been changed.
1457 =item C<AUG_NO_LOAD> = 32
1459 Do not load the tree in C<guestfs_aug_init>.
1463 To close the handle, you can call C<guestfs_aug_close>.
1465 To find out more about Augeas, see L<http://augeas.net/>.");
1467 ("aug_close", (RErr, [], []), 26, [Optional "augeas"],
1468 [], (* XXX Augeas code needs tests. *)
1469 "close the current Augeas handle",
1471 Close the current Augeas handle and free up any resources
1472 used by it. After calling this, you have to call
1473 C<guestfs_aug_init> again before you can use any other
1474 Augeas functions.");
1476 ("aug_defvar", (RInt "nrnodes", [String "name"; OptString "expr"], []), 17, [Optional "augeas"],
1477 [], (* XXX Augeas code needs tests. *)
1478 "define an Augeas variable",
1480 Defines an Augeas variable C<name> whose value is the result
1481 of evaluating C<expr>. If C<expr> is NULL, then C<name> is
1484 On success this returns the number of nodes in C<expr>, or
1485 C<0> if C<expr> evaluates to something which is not a nodeset.");
1487 ("aug_defnode", (RStruct ("nrnodescreated", "int_bool"), [String "name"; String "expr"; String "val"], []), 18, [Optional "augeas"],
1488 [], (* XXX Augeas code needs tests. *)
1489 "define an Augeas node",
1491 Defines a variable C<name> whose value is the result of
1494 If C<expr> evaluates to an empty nodeset, a node is created,
1495 equivalent to calling C<guestfs_aug_set> C<expr>, C<value>.
1496 C<name> will be the nodeset containing that single node.
1498 On success this returns a pair containing the
1499 number of nodes in the nodeset, and a boolean flag
1500 if a node was created.");
1502 ("aug_get", (RString "val", [String "augpath"], []), 19, [Optional "augeas"],
1503 [], (* XXX Augeas code needs tests. *)
1504 "look up the value of an Augeas path",
1506 Look up the value associated with C<path>. If C<path>
1507 matches exactly one node, the C<value> is returned.");
1509 ("aug_set", (RErr, [String "augpath"; String "val"], []), 20, [Optional "augeas"],
1510 [], (* XXX Augeas code needs tests. *)
1511 "set Augeas path to value",
1513 Set the value associated with C<path> to C<val>.
1515 In the Augeas API, it is possible to clear a node by setting
1516 the value to NULL. Due to an oversight in the libguestfs API
1517 you cannot do that with this call. Instead you must use the
1518 C<guestfs_aug_clear> call.");
1520 ("aug_insert", (RErr, [String "augpath"; String "label"; Bool "before"], []), 21, [Optional "augeas"],
1521 [], (* XXX Augeas code needs tests. *)
1522 "insert a sibling Augeas node",
1524 Create a new sibling C<label> for C<path>, inserting it into
1525 the tree before or after C<path> (depending on the boolean
1528 C<path> must match exactly one existing node in the tree, and
1529 C<label> must be a label, ie. not contain C</>, C<*> or end
1530 with a bracketed index C<[N]>.");
1532 ("aug_rm", (RInt "nrnodes", [String "augpath"], []), 22, [Optional "augeas"],
1533 [], (* XXX Augeas code needs tests. *)
1534 "remove an Augeas path",
1536 Remove C<path> and all of its children.
1538 On success this returns the number of entries which were removed.");
1540 ("aug_mv", (RErr, [String "src"; String "dest"], []), 23, [Optional "augeas"],
1541 [], (* XXX Augeas code needs tests. *)
1544 Move the node C<src> to C<dest>. C<src> must match exactly
1545 one node. C<dest> is overwritten if it exists.");
1547 ("aug_match", (RStringList "matches", [String "augpath"], []), 24, [Optional "augeas"],
1548 [], (* XXX Augeas code needs tests. *)
1549 "return Augeas nodes which match augpath",
1551 Returns a list of paths which match the path expression C<path>.
1552 The returned paths are sufficiently qualified so that they match
1553 exactly one node in the current tree.");
1555 ("aug_save", (RErr, [], []), 25, [Optional "augeas"],
1556 [], (* XXX Augeas code needs tests. *)
1557 "write all pending Augeas changes to disk",
1559 This writes all pending changes to disk.
1561 The flags which were passed to C<guestfs_aug_init> affect exactly
1562 how files are saved.");
1564 ("aug_load", (RErr, [], []), 27, [Optional "augeas"],
1565 [], (* XXX Augeas code needs tests. *)
1566 "load files into the tree",
1568 Load files into the tree.
1570 See C<aug_load> in the Augeas documentation for the full gory
1573 ("aug_ls", (RStringList "matches", [String "augpath"], []), 28, [Optional "augeas"],
1574 [], (* XXX Augeas code needs tests. *)
1575 "list Augeas nodes under augpath",
1577 This is just a shortcut for listing C<guestfs_aug_match>
1578 C<path/*> and sorting the resulting nodes into alphabetical order.");
1580 ("rm", (RErr, [Pathname "path"], []), 29, [],
1581 [InitBasicFS, Always, TestRun
1584 InitBasicFS, Always, TestLastFail
1586 InitBasicFS, Always, TestLastFail
1591 Remove the single file C<path>.");
1593 ("rmdir", (RErr, [Pathname "path"], []), 30, [],
1594 [InitBasicFS, Always, TestRun
1597 InitBasicFS, Always, TestLastFail
1598 [["rmdir"; "/new"]];
1599 InitBasicFS, Always, TestLastFail
1601 ["rmdir"; "/new"]]],
1602 "remove a directory",
1604 Remove the single directory C<path>.");
1606 ("rm_rf", (RErr, [Pathname "path"], []), 31, [],
1607 [InitBasicFS, Always, TestOutputFalse
1609 ["mkdir"; "/new/foo"];
1610 ["touch"; "/new/foo/bar"];
1612 ["exists"; "/new"]]],
1613 "remove a file or directory recursively",
1615 Remove the file or directory C<path>, recursively removing the
1616 contents if its a directory. This is like the C<rm -rf> shell
1619 ("mkdir", (RErr, [Pathname "path"], []), 32, [],
1620 [InitBasicFS, Always, TestOutputTrue
1622 ["is_dir"; "/new"]];
1623 InitBasicFS, Always, TestLastFail
1624 [["mkdir"; "/new/foo/bar"]]],
1625 "create a directory",
1627 Create a directory named C<path>.");
1629 ("mkdir_p", (RErr, [Pathname "path"], []), 33, [],
1630 [InitBasicFS, Always, TestOutputTrue
1631 [["mkdir_p"; "/new/foo/bar"];
1632 ["is_dir"; "/new/foo/bar"]];
1633 InitBasicFS, Always, TestOutputTrue
1634 [["mkdir_p"; "/new/foo/bar"];
1635 ["is_dir"; "/new/foo"]];
1636 InitBasicFS, Always, TestOutputTrue
1637 [["mkdir_p"; "/new/foo/bar"];
1638 ["is_dir"; "/new"]];
1639 (* Regression tests for RHBZ#503133: *)
1640 InitBasicFS, Always, TestRun
1642 ["mkdir_p"; "/new"]];
1643 InitBasicFS, Always, TestLastFail
1645 ["mkdir_p"; "/new"]]],
1646 "create a directory and parents",
1648 Create a directory named C<path>, creating any parent directories
1649 as necessary. This is like the C<mkdir -p> shell command.");
1651 ("chmod", (RErr, [Int "mode"; Pathname "path"], []), 34, [],
1652 [], (* XXX Need stat command to test *)
1655 Change the mode (permissions) of C<path> to C<mode>. Only
1656 numeric modes are supported.
1658 I<Note>: When using this command from guestfish, C<mode>
1659 by default would be decimal, unless you prefix it with
1660 C<0> to get octal, ie. use C<0700> not C<700>.
1662 The mode actually set is affected by the umask.");
1664 ("chown", (RErr, [Int "owner"; Int "group"; Pathname "path"], []), 35, [],
1665 [], (* XXX Need stat command to test *)
1666 "change file owner and group",
1668 Change the file owner to C<owner> and group to C<group>.
1670 Only numeric uid and gid are supported. If you want to use
1671 names, you will need to locate and parse the password file
1672 yourself (Augeas support makes this relatively easy).");
1674 ("exists", (RBool "existsflag", [Pathname "path"], []), 36, [],
1675 [InitISOFS, Always, TestOutputTrue (
1676 [["exists"; "/empty"]]);
1677 InitISOFS, Always, TestOutputTrue (
1678 [["exists"; "/directory"]])],
1679 "test if file or directory exists",
1681 This returns C<true> if and only if there is a file, directory
1682 (or anything) with the given C<path> name.
1684 See also C<guestfs_is_file>, C<guestfs_is_dir>, C<guestfs_stat>.");
1686 ("is_file", (RBool "fileflag", [Pathname "path"], []), 37, [],
1687 [InitISOFS, Always, TestOutputTrue (
1688 [["is_file"; "/known-1"]]);
1689 InitISOFS, Always, TestOutputFalse (
1690 [["is_file"; "/directory"]])],
1691 "test if a regular file",
1693 This returns C<true> if and only if there is a regular file
1694 with the given C<path> name. Note that it returns false for
1695 other objects like directories.
1697 See also C<guestfs_stat>.");
1699 ("is_dir", (RBool "dirflag", [Pathname "path"], []), 38, [],
1700 [InitISOFS, Always, TestOutputFalse (
1701 [["is_dir"; "/known-3"]]);
1702 InitISOFS, Always, TestOutputTrue (
1703 [["is_dir"; "/directory"]])],
1704 "test if a directory",
1706 This returns C<true> if and only if there is a directory
1707 with the given C<path> name. Note that it returns false for
1708 other objects like files.
1710 See also C<guestfs_stat>.");
1712 ("pvcreate", (RErr, [Device "device"], []), 39, [Optional "lvm2"],
1713 [InitEmpty, Always, TestOutputListOfDevices (
1714 [["part_init"; "/dev/sda"; "mbr"];
1715 ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
1716 ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
1717 ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
1718 ["pvcreate"; "/dev/sda1"];
1719 ["pvcreate"; "/dev/sda2"];
1720 ["pvcreate"; "/dev/sda3"];
1721 ["pvs"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])],
1722 "create an LVM physical volume",
1724 This creates an LVM physical volume on the named C<device>,
1725 where C<device> should usually be a partition name such
1728 ("vgcreate", (RErr, [String "volgroup"; DeviceList "physvols"], []), 40, [Optional "lvm2"],
1729 [InitEmpty, Always, TestOutputList (
1730 [["part_init"; "/dev/sda"; "mbr"];
1731 ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
1732 ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
1733 ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
1734 ["pvcreate"; "/dev/sda1"];
1735 ["pvcreate"; "/dev/sda2"];
1736 ["pvcreate"; "/dev/sda3"];
1737 ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
1738 ["vgcreate"; "VG2"; "/dev/sda3"];
1739 ["vgs"]], ["VG1"; "VG2"])],
1740 "create an LVM volume group",
1742 This creates an LVM volume group called C<volgroup>
1743 from the non-empty list of physical volumes C<physvols>.");
1745 ("lvcreate", (RErr, [String "logvol"; String "volgroup"; Int "mbytes"], []), 41, [Optional "lvm2"],
1746 [InitEmpty, Always, TestOutputList (
1747 [["part_init"; "/dev/sda"; "mbr"];
1748 ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
1749 ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
1750 ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
1751 ["pvcreate"; "/dev/sda1"];
1752 ["pvcreate"; "/dev/sda2"];
1753 ["pvcreate"; "/dev/sda3"];
1754 ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
1755 ["vgcreate"; "VG2"; "/dev/sda3"];
1756 ["lvcreate"; "LV1"; "VG1"; "50"];
1757 ["lvcreate"; "LV2"; "VG1"; "50"];
1758 ["lvcreate"; "LV3"; "VG2"; "50"];
1759 ["lvcreate"; "LV4"; "VG2"; "50"];
1760 ["lvcreate"; "LV5"; "VG2"; "50"];
1762 ["/dev/VG1/LV1"; "/dev/VG1/LV2";
1763 "/dev/VG2/LV3"; "/dev/VG2/LV4"; "/dev/VG2/LV5"])],
1764 "create an LVM logical volume",
1766 This creates an LVM logical volume called C<logvol>
1767 on the volume group C<volgroup>, with C<size> megabytes.");
1769 ("mkfs", (RErr, [String "fstype"; Device "device"], []), 42, [],
1770 [InitEmpty, Always, TestOutput (
1771 [["part_disk"; "/dev/sda"; "mbr"];
1772 ["mkfs"; "ext2"; "/dev/sda1"];
1773 ["mount_options"; ""; "/dev/sda1"; "/"];
1774 ["write"; "/new"; "new file contents"];
1775 ["cat"; "/new"]], "new file contents")],
1776 "make a filesystem",
1778 This creates a filesystem on C<device> (usually a partition
1779 or LVM logical volume). The filesystem type is C<fstype>, for
1782 ("sfdisk", (RErr, [Device "device";
1783 Int "cyls"; Int "heads"; Int "sectors";
1784 StringList "lines"], []), 43, [DangerWillRobinson],
1786 "create partitions on a block device",
1788 This is a direct interface to the L<sfdisk(8)> program for creating
1789 partitions on block devices.
1791 C<device> should be a block device, for example C</dev/sda>.
1793 C<cyls>, C<heads> and C<sectors> are the number of cylinders, heads
1794 and sectors on the device, which are passed directly to sfdisk as
1795 the I<-C>, I<-H> and I<-S> parameters. If you pass C<0> for any
1796 of these, then the corresponding parameter is omitted. Usually for
1797 'large' disks, you can just pass C<0> for these, but for small
1798 (floppy-sized) disks, sfdisk (or rather, the kernel) cannot work
1799 out the right geometry and you will need to tell it.
1801 C<lines> is a list of lines that we feed to C<sfdisk>. For more
1802 information refer to the L<sfdisk(8)> manpage.
1804 To create a single partition occupying the whole disk, you would
1805 pass C<lines> as a single element list, when the single element being
1806 the string C<,> (comma).
1808 See also: C<guestfs_sfdisk_l>, C<guestfs_sfdisk_N>,
1809 C<guestfs_part_init>");
1811 ("write_file", (RErr, [Pathname "path"; String "content"; Int "size"], []), 44, [ProtocolLimitWarning; DeprecatedBy "write"],
1812 (* Regression test for RHBZ#597135. *)
1813 [InitBasicFS, Always, TestLastFail
1814 [["write_file"; "/new"; "abc"; "10000"]]],
1817 This call creates a file called C<path>. The contents of the
1818 file is the string C<content> (which can contain any 8 bit data),
1819 with length C<size>.
1821 As a special case, if C<size> is C<0>
1822 then the length is calculated using C<strlen> (so in this case
1823 the content cannot contain embedded ASCII NULs).
1825 I<NB.> Owing to a bug, writing content containing ASCII NUL
1826 characters does I<not> work, even if the length is specified.");
1828 ("umount", (RErr, [String "pathordevice"], []), 45, [FishAlias "unmount"],
1829 [InitEmpty, Always, TestOutputListOfDevices (
1830 [["part_disk"; "/dev/sda"; "mbr"];
1831 ["mkfs"; "ext2"; "/dev/sda1"];
1832 ["mount_options"; ""; "/dev/sda1"; "/"];
1833 ["mounts"]], ["/dev/sda1"]);
1834 InitEmpty, Always, TestOutputList (
1835 [["part_disk"; "/dev/sda"; "mbr"];
1836 ["mkfs"; "ext2"; "/dev/sda1"];
1837 ["mount_options"; ""; "/dev/sda1"; "/"];
1840 "unmount a filesystem",
1842 This unmounts the given filesystem. The filesystem may be
1843 specified either by its mountpoint (path) or the device which
1844 contains the filesystem.");
1846 ("mounts", (RStringList "devices", [], []), 46, [],
1847 [InitBasicFS, Always, TestOutputListOfDevices (
1848 [["mounts"]], ["/dev/sda1"])],
1849 "show mounted filesystems",
1851 This returns the list of currently mounted filesystems. It returns
1852 the list of devices (eg. C</dev/sda1>, C</dev/VG/LV>).
1854 Some internal mounts are not shown.
1856 See also: C<guestfs_mountpoints>");
1858 ("umount_all", (RErr, [], []), 47, [FishAlias "unmount-all"],
1859 [InitBasicFS, Always, TestOutputList (
1862 (* check that umount_all can unmount nested mounts correctly: *)
1863 InitEmpty, Always, TestOutputList (
1864 [["part_init"; "/dev/sda"; "mbr"];
1865 ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
1866 ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
1867 ["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
1868 ["mkfs"; "ext2"; "/dev/sda1"];
1869 ["mkfs"; "ext2"; "/dev/sda2"];
1870 ["mkfs"; "ext2"; "/dev/sda3"];
1871 ["mount_options"; ""; "/dev/sda1"; "/"];
1873 ["mount_options"; ""; "/dev/sda2"; "/mp1"];
1874 ["mkdir"; "/mp1/mp2"];
1875 ["mount_options"; ""; "/dev/sda3"; "/mp1/mp2"];
1876 ["mkdir"; "/mp1/mp2/mp3"];
1879 "unmount all filesystems",
1881 This unmounts all mounted filesystems.
1883 Some internal mounts are not unmounted by this call.");
1885 ("lvm_remove_all", (RErr, [], []), 48, [DangerWillRobinson; Optional "lvm2"],
1887 "remove all LVM LVs, VGs and PVs",
1889 This command removes all LVM logical volumes, volume groups
1890 and physical volumes.");
1892 ("file", (RString "description", [Dev_or_Path "path"], []), 49, [],
1893 [InitISOFS, Always, TestOutput (
1894 [["file"; "/empty"]], "empty");
1895 InitISOFS, Always, TestOutput (
1896 [["file"; "/known-1"]], "ASCII text");
1897 InitISOFS, Always, TestLastFail (
1898 [["file"; "/notexists"]]);
1899 InitISOFS, Always, TestOutput (
1900 [["file"; "/abssymlink"]], "symbolic link");
1901 InitISOFS, Always, TestOutput (
1902 [["file"; "/directory"]], "directory")],
1903 "determine file type",
1905 This call uses the standard L<file(1)> command to determine
1906 the type or contents of the file.
1908 This call will also transparently look inside various types
1911 The exact command which runs is C<file -zb path>. Note in
1912 particular that the filename is not prepended to the output
1915 This command can also be used on C</dev/> devices
1916 (and partitions, LV names). You can for example use this
1917 to determine if a device contains a filesystem, although
1918 it's usually better to use C<guestfs_vfs_type>.
1920 If the C<path> does not begin with C</dev/> then
1921 this command only works for the content of regular files.
1922 For other file types (directory, symbolic link etc) it
1923 will just return the string C<directory> etc.");
1925 ("command", (RString "output", [StringList "arguments"], []), 50, [ProtocolLimitWarning],
1926 [InitBasicFS, Always, TestOutput (
1927 [["upload"; "test-command"; "/test-command"];
1928 ["chmod"; "0o755"; "/test-command"];
1929 ["command"; "/test-command 1"]], "Result1");
1930 InitBasicFS, Always, TestOutput (
1931 [["upload"; "test-command"; "/test-command"];
1932 ["chmod"; "0o755"; "/test-command"];
1933 ["command"; "/test-command 2"]], "Result2\n");
1934 InitBasicFS, Always, TestOutput (
1935 [["upload"; "test-command"; "/test-command"];
1936 ["chmod"; "0o755"; "/test-command"];
1937 ["command"; "/test-command 3"]], "\nResult3");
1938 InitBasicFS, Always, TestOutput (
1939 [["upload"; "test-command"; "/test-command"];
1940 ["chmod"; "0o755"; "/test-command"];
1941 ["command"; "/test-command 4"]], "\nResult4\n");
1942 InitBasicFS, Always, TestOutput (
1943 [["upload"; "test-command"; "/test-command"];
1944 ["chmod"; "0o755"; "/test-command"];
1945 ["command"; "/test-command 5"]], "\nResult5\n\n");
1946 InitBasicFS, Always, TestOutput (
1947 [["upload"; "test-command"; "/test-command"];
1948 ["chmod"; "0o755"; "/test-command"];
1949 ["command"; "/test-command 6"]], "\n\nResult6\n\n");
1950 InitBasicFS, Always, TestOutput (
1951 [["upload"; "test-command"; "/test-command"];
1952 ["chmod"; "0o755"; "/test-command"];
1953 ["command"; "/test-command 7"]], "");
1954 InitBasicFS, Always, TestOutput (
1955 [["upload"; "test-command"; "/test-command"];
1956 ["chmod"; "0o755"; "/test-command"];
1957 ["command"; "/test-command 8"]], "\n");
1958 InitBasicFS, Always, TestOutput (
1959 [["upload"; "test-command"; "/test-command"];
1960 ["chmod"; "0o755"; "/test-command"];
1961 ["command"; "/test-command 9"]], "\n\n");
1962 InitBasicFS, Always, TestOutput (
1963 [["upload"; "test-command"; "/test-command"];
1964 ["chmod"; "0o755"; "/test-command"];
1965 ["command"; "/test-command 10"]], "Result10-1\nResult10-2\n");
1966 InitBasicFS, Always, TestOutput (
1967 [["upload"; "test-command"; "/test-command"];
1968 ["chmod"; "0o755"; "/test-command"];
1969 ["command"; "/test-command 11"]], "Result11-1\nResult11-2");
1970 InitBasicFS, Always, TestLastFail (
1971 [["upload"; "test-command"; "/test-command"];
1972 ["chmod"; "0o755"; "/test-command"];
1973 ["command"; "/test-command"]])],
1974 "run a command from the guest filesystem",
1976 This call runs a command from the guest filesystem. The
1977 filesystem must be mounted, and must contain a compatible
1978 operating system (ie. something Linux, with the same
1979 or compatible processor architecture).
1981 The single parameter is an argv-style list of arguments.
1982 The first element is the name of the program to run.
1983 Subsequent elements are parameters. The list must be
1984 non-empty (ie. must contain a program name). Note that
1985 the command runs directly, and is I<not> invoked via
1986 the shell (see C<guestfs_sh>).
1988 The return value is anything printed to I<stdout> by
1991 If the command returns a non-zero exit status, then
1992 this function returns an error message. The error message
1993 string is the content of I<stderr> from the command.
1995 The C<$PATH> environment variable will contain at least
1996 C</usr/bin> and C</bin>. If you require a program from
1997 another location, you should provide the full path in the
2000 Shared libraries and data files required by the program
2001 must be available on filesystems which are mounted in the
2002 correct places. It is the caller's responsibility to ensure
2003 all filesystems that are needed are mounted at the right
2006 ("command_lines", (RStringList "lines", [StringList "arguments"], []), 51, [ProtocolLimitWarning],
2007 [InitBasicFS, Always, TestOutputList (
2008 [["upload"; "test-command"; "/test-command"];
2009 ["chmod"; "0o755"; "/test-command"];
2010 ["command_lines"; "/test-command 1"]], ["Result1"]);
2011 InitBasicFS, Always, TestOutputList (
2012 [["upload"; "test-command"; "/test-command"];
2013 ["chmod"; "0o755"; "/test-command"];
2014 ["command_lines"; "/test-command 2"]], ["Result2"]);
2015 InitBasicFS, Always, TestOutputList (
2016 [["upload"; "test-command"; "/test-command"];
2017 ["chmod"; "0o755"; "/test-command"];
2018 ["command_lines"; "/test-command 3"]], ["";"Result3"]);
2019 InitBasicFS, Always, TestOutputList (
2020 [["upload"; "test-command"; "/test-command"];
2021 ["chmod"; "0o755"; "/test-command"];
2022 ["command_lines"; "/test-command 4"]], ["";"Result4"]);
2023 InitBasicFS, Always, TestOutputList (
2024 [["upload"; "test-command"; "/test-command"];
2025 ["chmod"; "0o755"; "/test-command"];
2026 ["command_lines"; "/test-command 5"]], ["";"Result5";""]);
2027 InitBasicFS, Always, TestOutputList (
2028 [["upload"; "test-command"; "/test-command"];
2029 ["chmod"; "0o755"; "/test-command"];
2030 ["command_lines"; "/test-command 6"]], ["";"";"Result6";""]);
2031 InitBasicFS, Always, TestOutputList (
2032 [["upload"; "test-command"; "/test-command"];
2033 ["chmod"; "0o755"; "/test-command"];
2034 ["command_lines"; "/test-command 7"]], []);
2035 InitBasicFS, Always, TestOutputList (
2036 [["upload"; "test-command"; "/test-command"];
2037 ["chmod"; "0o755"; "/test-command"];
2038 ["command_lines"; "/test-command 8"]], [""]);
2039 InitBasicFS, Always, TestOutputList (
2040 [["upload"; "test-command"; "/test-command"];
2041 ["chmod"; "0o755"; "/test-command"];
2042 ["command_lines"; "/test-command 9"]], ["";""]);
2043 InitBasicFS, Always, TestOutputList (
2044 [["upload"; "test-command"; "/test-command"];
2045 ["chmod"; "0o755"; "/test-command"];
2046 ["command_lines"; "/test-command 10"]], ["Result10-1";"Result10-2"]);
2047 InitBasicFS, Always, TestOutputList (
2048 [["upload"; "test-command"; "/test-command"];
2049 ["chmod"; "0o755"; "/test-command"];
2050 ["command_lines"; "/test-command 11"]], ["Result11-1";"Result11-2"])],
2051 "run a command, returning lines",
2053 This is the same as C<guestfs_command>, but splits the
2054 result into a list of lines.
2056 See also: C<guestfs_sh_lines>");
2058 ("stat", (RStruct ("statbuf", "stat"), [Pathname "path"], []), 52, [],
2059 [InitISOFS, Always, TestOutputStruct (
2060 [["stat"; "/empty"]], [CompareWithInt ("size", 0)])],
2061 "get file information",
2063 Returns file information for the given C<path>.
2065 This is the same as the C<stat(2)> system call.");
2067 ("lstat", (RStruct ("statbuf", "stat"), [Pathname "path"], []), 53, [],
2068 [InitISOFS, Always, TestOutputStruct (
2069 [["lstat"; "/empty"]], [CompareWithInt ("size", 0)])],
2070 "get file information for a symbolic link",
2072 Returns file information for the given C<path>.
2074 This is the same as C<guestfs_stat> except that if C<path>
2075 is a symbolic link, then the link is stat-ed, not the file it
2078 This is the same as the C<lstat(2)> system call.");
2080 ("statvfs", (RStruct ("statbuf", "statvfs"), [Pathname "path"], []), 54, [],
2081 [InitISOFS, Always, TestOutputStruct (
2082 [["statvfs"; "/"]], [CompareWithInt ("namemax", 255)])],
2083 "get file system statistics",
2085 Returns file system statistics for any mounted file system.
2086 C<path> should be a file or directory in the mounted file system
2087 (typically it is the mount point itself, but it doesn't need to be).
2089 This is the same as the C<statvfs(2)> system call.");
2091 ("tune2fs_l", (RHashtable "superblock", [Device "device"], []), 55, [],
2093 "get ext2/ext3/ext4 superblock details",
2095 This returns the contents of the ext2, ext3 or ext4 filesystem
2096 superblock on C<device>.
2098 It is the same as running C<tune2fs -l device>. See L<tune2fs(8)>
2099 manpage for more details. The list of fields returned isn't
2100 clearly defined, and depends on both the version of C<tune2fs>
2101 that libguestfs was built against, and the filesystem itself.");
2103 ("blockdev_setro", (RErr, [Device "device"], []), 56, [],
2104 [InitEmpty, Always, TestOutputTrue (
2105 [["blockdev_setro"; "/dev/sda"];
2106 ["blockdev_getro"; "/dev/sda"]])],
2107 "set block device to read-only",
2109 Sets the block device named C<device> to read-only.
2111 This uses the L<blockdev(8)> command.");
2113 ("blockdev_setrw", (RErr, [Device "device"], []), 57, [],
2114 [InitEmpty, Always, TestOutputFalse (
2115 [["blockdev_setrw"; "/dev/sda"];
2116 ["blockdev_getro"; "/dev/sda"]])],
2117 "set block device to read-write",
2119 Sets the block device named C<device> to read-write.
2121 This uses the L<blockdev(8)> command.");
2123 ("blockdev_getro", (RBool "ro", [Device "device"], []), 58, [],
2124 [InitEmpty, Always, TestOutputTrue (
2125 [["blockdev_setro"; "/dev/sda"];
2126 ["blockdev_getro"; "/dev/sda"]])],
2127 "is block device set to read-only",
2129 Returns a boolean indicating if the block device is read-only
2130 (true if read-only, false if not).
2132 This uses the L<blockdev(8)> command.");
2134 ("blockdev_getss", (RInt "sectorsize", [Device "device"], []), 59, [],
2135 [InitEmpty, Always, TestOutputInt (
2136 [["blockdev_getss"; "/dev/sda"]], 512)],
2137 "get sectorsize of block device",
2139 This returns the size of sectors on a block device.
2140 Usually 512, but can be larger for modern devices.
2142 (Note, this is not the size in sectors, use C<guestfs_blockdev_getsz>
2145 This uses the L<blockdev(8)> command.");
2147 ("blockdev_getbsz", (RInt "blocksize", [Device "device"], []), 60, [],
2148 [InitEmpty, Always, TestOutputInt (
2149 [["blockdev_getbsz"; "/dev/sda"]], 4096)],
2150 "get blocksize of block device",
2152 This returns the block size of a device.
2154 (Note this is different from both I<size in blocks> and
2155 I<filesystem block size>).
2157 This uses the L<blockdev(8)> command.");
2159 ("blockdev_setbsz", (RErr, [Device "device"; Int "blocksize"], []), 61, [],
2161 "set blocksize of block device",
2163 This sets the block size of a device.
2165 (Note this is different from both I<size in blocks> and
2166 I<filesystem block size>).
2168 This uses the L<blockdev(8)> command.");
2170 ("blockdev_getsz", (RInt64 "sizeinsectors", [Device "device"], []), 62, [],
2171 [InitEmpty, Always, TestOutputInt (
2172 [["blockdev_getsz"; "/dev/sda"]], 1024000)],
2173 "get total size of device in 512-byte sectors",
2175 This returns the size of the device in units of 512-byte sectors
2176 (even if the sectorsize isn't 512 bytes ... weird).
2178 See also C<guestfs_blockdev_getss> for the real sector size of
2179 the device, and C<guestfs_blockdev_getsize64> for the more
2180 useful I<size in bytes>.
2182 This uses the L<blockdev(8)> command.");
2184 ("blockdev_getsize64", (RInt64 "sizeinbytes", [Device "device"], []), 63, [],
2185 [InitEmpty, Always, TestOutputInt (
2186 [["blockdev_getsize64"; "/dev/sda"]], 524288000)],
2187 "get total size of device in bytes",
2189 This returns the size of the device in bytes.
2191 See also C<guestfs_blockdev_getsz>.
2193 This uses the L<blockdev(8)> command.");
2195 ("blockdev_flushbufs", (RErr, [Device "device"], []), 64, [],
2196 [InitEmpty, Always, TestRun
2197 [["blockdev_flushbufs"; "/dev/sda"]]],
2198 "flush device buffers",
2200 This tells the kernel to flush internal buffers associated
2203 This uses the L<blockdev(8)> command.");
2205 ("blockdev_rereadpt", (RErr, [Device "device"], []), 65, [],
2206 [InitEmpty, Always, TestRun
2207 [["blockdev_rereadpt"; "/dev/sda"]]],
2208 "reread partition table",
2210 Reread the partition table on C<device>.
2212 This uses the L<blockdev(8)> command.");
2214 ("upload", (RErr, [FileIn "filename"; Dev_or_Path "remotefilename"], []), 66, [],
2215 [InitBasicFS, Always, TestOutput (
2216 (* Pick a file from cwd which isn't likely to change. *)
2217 [["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
2218 ["checksum"; "md5"; "/COPYING.LIB"]],
2219 Digest.to_hex (Digest.file "COPYING.LIB"))],
2220 "upload a file from the local machine",
2222 Upload local file C<filename> to C<remotefilename> on the
2225 C<filename> can also be a named pipe.
2227 See also C<guestfs_download>.");
2229 ("download", (RErr, [Dev_or_Path "remotefilename"; FileOut "filename"], []), 67, [Progress],
2230 [InitBasicFS, Always, TestOutput (
2231 (* Pick a file from cwd which isn't likely to change. *)
2232 [["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
2233 ["download"; "/COPYING.LIB"; "testdownload.tmp"];
2234 ["upload"; "testdownload.tmp"; "/upload"];
2235 ["checksum"; "md5"; "/upload"]],
2236 Digest.to_hex (Digest.file "COPYING.LIB"))],
2237 "download a file to the local machine",
2239 Download file C<remotefilename> and save it as C<filename>
2240 on the local machine.
2242 C<filename> can also be a named pipe.
2244 See also C<guestfs_upload>, C<guestfs_cat>.");
2246 ("checksum", (RString "checksum", [String "csumtype"; Pathname "path"], []), 68, [],
2247 [InitISOFS, Always, TestOutput (
2248 [["checksum"; "crc"; "/known-3"]], "2891671662");
2249 InitISOFS, Always, TestLastFail (
2250 [["checksum"; "crc"; "/notexists"]]);
2251 InitISOFS, Always, TestOutput (
2252 [["checksum"; "md5"; "/known-3"]], "46d6ca27ee07cdc6fa99c2e138cc522c");
2253 InitISOFS, Always, TestOutput (
2254 [["checksum"; "sha1"; "/known-3"]], "b7ebccc3ee418311091c3eda0a45b83c0a770f15");
2255 InitISOFS, Always, TestOutput (
2256 [["checksum"; "sha224"; "/known-3"]], "d2cd1774b28f3659c14116be0a6dc2bb5c4b350ce9cd5defac707741");
2257 InitISOFS, Always, TestOutput (
2258 [["checksum"; "sha256"; "/known-3"]], "75bb71b90cd20cb13f86d2bea8dad63ac7194e7517c3b52b8d06ff52d3487d30");
2259 InitISOFS, Always, TestOutput (
2260 [["checksum"; "sha384"; "/known-3"]], "5fa7883430f357b5d7b7271d3a1d2872b51d73cba72731de6863d3dea55f30646af2799bef44d5ea776a5ec7941ac640");
2261 InitISOFS, Always, TestOutput (
2262 [["checksum"; "sha512"; "/known-3"]], "2794062c328c6b216dca90443b7f7134c5f40e56bd0ed7853123275a09982a6f992e6ca682f9d2fba34a4c5e870d8fe077694ff831e3032a004ee077e00603f6");
2263 (* Test for RHBZ#579608, absolute symbolic links. *)
2264 InitISOFS, Always, TestOutput (
2265 [["checksum"; "sha512"; "/abssymlink"]], "5f57d0639bc95081c53afc63a449403883818edc64da48930ad6b1a4fb49be90404686877743fbcd7c99811f3def7df7bc22635c885c6a8cf79c806b43451c1a")],
2266 "compute MD5, SHAx or CRC checksum of file",
2268 This call computes the MD5, SHAx or CRC checksum of the
2271 The type of checksum to compute is given by the C<csumtype>
2272 parameter which must have one of the following values:
2278 Compute the cyclic redundancy check (CRC) specified by POSIX
2279 for the C<cksum> command.
2283 Compute the MD5 hash (using the C<md5sum> program).
2287 Compute the SHA1 hash (using the C<sha1sum> program).
2291 Compute the SHA224 hash (using the C<sha224sum> program).
2295 Compute the SHA256 hash (using the C<sha256sum> program).
2299 Compute the SHA384 hash (using the C<sha384sum> program).
2303 Compute the SHA512 hash (using the C<sha512sum> program).
2307 The checksum is returned as a printable string.
2309 To get the checksum for a device, use C<guestfs_checksum_device>.
2311 To get the checksums for many files, use C<guestfs_checksums_out>.");
2313 ("tar_in", (RErr, [FileIn "tarfile"; Pathname "directory"], []), 69, [],
2314 [InitBasicFS, Always, TestOutput (
2315 [["tar_in"; "../images/helloworld.tar"; "/"];
2316 ["cat"; "/hello"]], "hello\n")],
2317 "unpack tarfile to directory",
2319 This command uploads and unpacks local file C<tarfile> (an
2320 I<uncompressed> tar file) into C<directory>.
2322 To upload a compressed tarball, use C<guestfs_tgz_in>
2323 or C<guestfs_txz_in>.");
2325 ("tar_out", (RErr, [String "directory"; FileOut "tarfile"], []), 70, [],
2327 "pack directory into tarfile",
2329 This command packs the contents of C<directory> and downloads
2330 it to local file C<tarfile>.
2332 To download a compressed tarball, use C<guestfs_tgz_out>
2333 or C<guestfs_txz_out>.");
2335 ("tgz_in", (RErr, [FileIn "tarball"; Pathname "directory"], []), 71, [],
2336 [InitBasicFS, Always, TestOutput (
2337 [["tgz_in"; "../images/helloworld.tar.gz"; "/"];
2338 ["cat"; "/hello"]], "hello\n")],
2339 "unpack compressed tarball to directory",
2341 This command uploads and unpacks local file C<tarball> (a
2342 I<gzip compressed> tar file) into C<directory>.
2344 To upload an uncompressed tarball, use C<guestfs_tar_in>.");
2346 ("tgz_out", (RErr, [Pathname "directory"; FileOut "tarball"], []), 72, [],
2348 "pack directory into compressed tarball",
2350 This command packs the contents of C<directory> and downloads
2351 it to local file C<tarball>.
2353 To download an uncompressed tarball, use C<guestfs_tar_out>.");
2355 ("mount_ro", (RErr, [Device "device"; String "mountpoint"], []), 73, [],
2356 [InitBasicFS, Always, TestLastFail (
2358 ["mount_ro"; "/dev/sda1"; "/"];
2359 ["touch"; "/new"]]);
2360 InitBasicFS, Always, TestOutput (
2361 [["write"; "/new"; "data"];
2363 ["mount_ro"; "/dev/sda1"; "/"];
2364 ["cat"; "/new"]], "data")],
2365 "mount a guest disk, read-only",
2367 This is the same as the C<guestfs_mount> command, but it
2368 mounts the filesystem with the read-only (I<-o ro>) flag.");
2370 ("mount_options", (RErr, [String "options"; Device "device"; String "mountpoint"], []), 74, [],
2372 "mount a guest disk with mount options",
2374 This is the same as the C<guestfs_mount> command, but it
2375 allows you to set the mount options as for the
2376 L<mount(8)> I<-o> flag.
2378 If the C<options> parameter is an empty string, then
2379 no options are passed (all options default to whatever
2380 the filesystem uses).");
2382 ("mount_vfs", (RErr, [String "options"; String "vfstype"; Device "device"; String "mountpoint"], []), 75, [],
2384 "mount a guest disk with mount options and vfstype",
2386 This is the same as the C<guestfs_mount> command, but it
2387 allows you to set both the mount options and the vfstype
2388 as for the L<mount(8)> I<-o> and I<-t> flags.");
2390 ("debug", (RString "result", [String "subcmd"; StringList "extraargs"], []), 76, [NotInDocs],
2392 "debugging and internals",
2394 The C<guestfs_debug> command exposes some internals of
2395 C<guestfsd> (the guestfs daemon) that runs inside the
2398 There is no comprehensive help for this command. You have
2399 to look at the file C<daemon/debug.c> in the libguestfs source
2400 to find out what you can do.");
2402 ("lvremove", (RErr, [Device "device"], []), 77, [Optional "lvm2"],
2403 [InitEmpty, Always, TestOutputList (
2404 [["part_disk"; "/dev/sda"; "mbr"];
2405 ["pvcreate"; "/dev/sda1"];
2406 ["vgcreate"; "VG"; "/dev/sda1"];
2407 ["lvcreate"; "LV1"; "VG"; "50"];
2408 ["lvcreate"; "LV2"; "VG"; "50"];
2409 ["lvremove"; "/dev/VG/LV1"];
2410 ["lvs"]], ["/dev/VG/LV2"]);
2411 InitEmpty, Always, TestOutputList (
2412 [["part_disk"; "/dev/sda"; "mbr"];
2413 ["pvcreate"; "/dev/sda1"];
2414 ["vgcreate"; "VG"; "/dev/sda1"];
2415 ["lvcreate"; "LV1"; "VG"; "50"];
2416 ["lvcreate"; "LV2"; "VG"; "50"];
2417 ["lvremove"; "/dev/VG"];
2419 InitEmpty, Always, TestOutputList (
2420 [["part_disk"; "/dev/sda"; "mbr"];
2421 ["pvcreate"; "/dev/sda1"];
2422 ["vgcreate"; "VG"; "/dev/sda1"];
2423 ["lvcreate"; "LV1"; "VG"; "50"];
2424 ["lvcreate"; "LV2"; "VG"; "50"];
2425 ["lvremove"; "/dev/VG"];
2427 "remove an LVM logical volume",
2429 Remove an LVM logical volume C<device>, where C<device> is
2430 the path to the LV, such as C</dev/VG/LV>.
2432 You can also remove all LVs in a volume group by specifying
2433 the VG name, C</dev/VG>.");
2435 ("vgremove", (RErr, [String "vgname"], []), 78, [Optional "lvm2"],
2436 [InitEmpty, Always, TestOutputList (
2437 [["part_disk"; "/dev/sda"; "mbr"];
2438 ["pvcreate"; "/dev/sda1"];
2439 ["vgcreate"; "VG"; "/dev/sda1"];
2440 ["lvcreate"; "LV1"; "VG"; "50"];
2441 ["lvcreate"; "LV2"; "VG"; "50"];
2444 InitEmpty, Always, TestOutputList (
2445 [["part_disk"; "/dev/sda"; "mbr"];
2446 ["pvcreate"; "/dev/sda1"];
2447 ["vgcreate"; "VG"; "/dev/sda1"];
2448 ["lvcreate"; "LV1"; "VG"; "50"];
2449 ["lvcreate"; "LV2"; "VG"; "50"];
2452 "remove an LVM volume group",
2454 Remove an LVM volume group C<vgname>, (for example C<VG>).
2456 This also forcibly removes all logical volumes in the volume
2459 ("pvremove", (RErr, [Device "device"], []), 79, [Optional "lvm2"],
2460 [InitEmpty, Always, TestOutputListOfDevices (
2461 [["part_disk"; "/dev/sda"; "mbr"];
2462 ["pvcreate"; "/dev/sda1"];
2463 ["vgcreate"; "VG"; "/dev/sda1"];
2464 ["lvcreate"; "LV1"; "VG"; "50"];
2465 ["lvcreate"; "LV2"; "VG"; "50"];
2467 ["pvremove"; "/dev/sda1"];
2469 InitEmpty, Always, TestOutputListOfDevices (
2470 [["part_disk"; "/dev/sda"; "mbr"];
2471 ["pvcreate"; "/dev/sda1"];
2472 ["vgcreate"; "VG"; "/dev/sda1"];
2473 ["lvcreate"; "LV1"; "VG"; "50"];
2474 ["lvcreate"; "LV2"; "VG"; "50"];
2476 ["pvremove"; "/dev/sda1"];
2478 InitEmpty, Always, TestOutputListOfDevices (
2479 [["part_disk"; "/dev/sda"; "mbr"];
2480 ["pvcreate"; "/dev/sda1"];
2481 ["vgcreate"; "VG"; "/dev/sda1"];
2482 ["lvcreate"; "LV1"; "VG"; "50"];
2483 ["lvcreate"; "LV2"; "VG"; "50"];
2485 ["pvremove"; "/dev/sda1"];
2487 "remove an LVM physical volume",
2489 This wipes a physical volume C<device> so that LVM will no longer
2492 The implementation uses the C<pvremove> command which refuses to
2493 wipe physical volumes that contain any volume groups, so you have
2494 to remove those first.");
2496 ("set_e2label", (RErr, [Device "device"; String "label"], []), 80, [],
2497 [InitBasicFS, Always, TestOutput (
2498 [["set_e2label"; "/dev/sda1"; "testlabel"];
2499 ["get_e2label"; "/dev/sda1"]], "testlabel")],
2500 "set the ext2/3/4 filesystem label",
2502 This sets the ext2/3/4 filesystem label of the filesystem on
2503 C<device> to C<label>. Filesystem labels are limited to
2506 You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2label>
2507 to return the existing label on a filesystem.");
2509 ("get_e2label", (RString "label", [Device "device"], []), 81, [DeprecatedBy "vfs_label"],
2511 "get the ext2/3/4 filesystem label",
2513 This returns the ext2/3/4 filesystem label of the filesystem on
2516 ("set_e2uuid", (RErr, [Device "device"; String "uuid"], []), 82, [],
2517 (let uuid = uuidgen () in
2518 [InitBasicFS, Always, TestOutput (
2519 [["set_e2uuid"; "/dev/sda1"; uuid];
2520 ["get_e2uuid"; "/dev/sda1"]], uuid);
2521 InitBasicFS, Always, TestOutput (
2522 [["set_e2uuid"; "/dev/sda1"; "clear"];
2523 ["get_e2uuid"; "/dev/sda1"]], "");
2524 (* We can't predict what UUIDs will be, so just check the commands run. *)
2525 InitBasicFS, Always, TestRun (
2526 [["set_e2uuid"; "/dev/sda1"; "random"]]);
2527 InitBasicFS, Always, TestRun (
2528 [["set_e2uuid"; "/dev/sda1"; "time"]])]),
2529 "set the ext2/3/4 filesystem UUID",
2531 This sets the ext2/3/4 filesystem UUID of the filesystem on
2532 C<device> to C<uuid>. The format of the UUID and alternatives
2533 such as C<clear>, C<random> and C<time> are described in the
2534 L<tune2fs(8)> manpage.
2536 You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2uuid>
2537 to return the existing UUID of a filesystem.");
2539 ("get_e2uuid", (RString "uuid", [Device "device"], []), 83, [DeprecatedBy "vfs_uuid"],
2540 (* Regression test for RHBZ#597112. *)
2541 (let uuid = uuidgen () in
2542 [InitBasicFS, Always, TestOutput (
2543 [["mke2journal"; "1024"; "/dev/sdb"];
2544 ["set_e2uuid"; "/dev/sdb"; uuid];
2545 ["get_e2uuid"; "/dev/sdb"]], uuid)]),
2546 "get the ext2/3/4 filesystem UUID",
2548 This returns the ext2/3/4 filesystem UUID of the filesystem on
2551 ("fsck", (RInt "status", [String "fstype"; Device "device"], []), 84, [FishOutput FishOutputHexadecimal],
2552 [InitBasicFS, Always, TestOutputInt (
2553 [["umount"; "/dev/sda1"];
2554 ["fsck"; "ext2"; "/dev/sda1"]], 0);
2555 InitBasicFS, Always, TestOutputInt (
2556 [["umount"; "/dev/sda1"];
2557 ["zero"; "/dev/sda1"];
2558 ["fsck"; "ext2"; "/dev/sda1"]], 8)],
2559 "run the filesystem checker",
2561 This runs the filesystem checker (fsck) on C<device> which
2562 should have filesystem type C<fstype>.
2564 The returned integer is the status. See L<fsck(8)> for the
2565 list of status codes from C<fsck>.
2573 Multiple status codes can be summed together.
2577 A non-zero return code can mean \"success\", for example if
2578 errors have been corrected on the filesystem.
2582 Checking or repairing NTFS volumes is not supported
2587 This command is entirely equivalent to running C<fsck -a -t fstype device>.");
2589 ("zero", (RErr, [Device "device"], []), 85, [Progress],
2590 [InitBasicFS, Always, TestOutput (
2591 [["umount"; "/dev/sda1"];
2592 ["zero"; "/dev/sda1"];
2593 ["file"; "/dev/sda1"]], "data")],
2594 "write zeroes to the device",
2596 This command writes zeroes over the first few blocks of C<device>.
2598 How many blocks are zeroed isn't specified (but it's I<not> enough
2599 to securely wipe the device). It should be sufficient to remove
2600 any partition tables, filesystem superblocks and so on.
2602 See also: C<guestfs_zero_device>, C<guestfs_scrub_device>.");
2604 ("grub_install", (RErr, [Pathname "root"; Device "device"], []), 86, [],
2606 * https://bugzilla.redhat.com/show_bug.cgi?id=484986
2607 * https://bugzilla.redhat.com/show_bug.cgi?id=479760
2609 [InitBasicFS, Always, TestOutputTrue (
2610 [["mkdir_p"; "/boot/grub"];
2611 ["write"; "/boot/grub/device.map"; "(hd0) /dev/vda"];
2612 ["grub_install"; "/"; "/dev/vda"];
2613 ["is_dir"; "/boot"]])],
2616 This command installs GRUB (the Grand Unified Bootloader) on
2617 C<device>, with the root directory being C<root>.
2619 Note: If grub-install reports the error
2620 \"No suitable drive was found in the generated device map.\"
2621 it may be that you need to create a C</boot/grub/device.map>
2622 file first that contains the mapping between grub device names
2623 and Linux device names. It is usually sufficient to create
2628 replacing C</dev/vda> with the name of the installation device.");
2630 ("cp", (RErr, [Pathname "src"; Pathname "dest"], []), 87, [],
2631 [InitBasicFS, Always, TestOutput (
2632 [["write"; "/old"; "file content"];
2633 ["cp"; "/old"; "/new"];
2634 ["cat"; "/new"]], "file content");
2635 InitBasicFS, Always, TestOutputTrue (
2636 [["write"; "/old"; "file content"];
2637 ["cp"; "/old"; "/new"];
2638 ["is_file"; "/old"]]);
2639 InitBasicFS, Always, TestOutput (
2640 [["write"; "/old"; "file content"];
2642 ["cp"; "/old"; "/dir/new"];
2643 ["cat"; "/dir/new"]], "file content")],
2646 This copies a file from C<src> to C<dest> where C<dest> is
2647 either a destination filename or destination directory.");
2649 ("cp_a", (RErr, [Pathname "src"; Pathname "dest"], []), 88, [],
2650 [InitBasicFS, Always, TestOutput (
2651 [["mkdir"; "/olddir"];
2652 ["mkdir"; "/newdir"];
2653 ["write"; "/olddir/file"; "file content"];
2654 ["cp_a"; "/olddir"; "/newdir"];
2655 ["cat"; "/newdir/olddir/file"]], "file content")],
2656 "copy a file or directory recursively",
2658 This copies a file or directory from C<src> to C<dest>
2659 recursively using the C<cp -a> command.");
2661 ("mv", (RErr, [Pathname "src"; Pathname "dest"], []), 89, [],
2662 [InitBasicFS, Always, TestOutput (
2663 [["write"; "/old"; "file content"];
2664 ["mv"; "/old"; "/new"];
2665 ["cat"; "/new"]], "file content");
2666 InitBasicFS, Always, TestOutputFalse (
2667 [["write"; "/old"; "file content"];
2668 ["mv"; "/old"; "/new"];
2669 ["is_file"; "/old"]])],
2672 This moves a file from C<src> to C<dest> where C<dest> is
2673 either a destination filename or destination directory.");
2675 ("drop_caches", (RErr, [Int "whattodrop"], []), 90, [],
2676 [InitEmpty, Always, TestRun (
2677 [["drop_caches"; "3"]])],
2678 "drop kernel page cache, dentries and inodes",
2680 This instructs the guest kernel to drop its page cache,
2681 and/or dentries and inode caches. The parameter C<whattodrop>
2682 tells the kernel what precisely to drop, see
2683 L<http://linux-mm.org/Drop_Caches>
2685 Setting C<whattodrop> to 3 should drop everything.
2687 This automatically calls L<sync(2)> before the operation,
2688 so that the maximum guest memory is freed.");
2690 ("dmesg", (RString "kmsgs", [], []), 91, [],
2691 [InitEmpty, Always, TestRun (
2693 "return kernel messages",
2695 This returns the kernel messages (C<dmesg> output) from
2696 the guest kernel. This is sometimes useful for extended
2697 debugging of problems.
2699 Another way to get the same information is to enable
2700 verbose messages with C<guestfs_set_verbose> or by setting
2701 the environment variable C<LIBGUESTFS_DEBUG=1> before
2702 running the program.");
2704 ("ping_daemon", (RErr, [], []), 92, [],
2705 [InitEmpty, Always, TestRun (
2706 [["ping_daemon"]])],
2707 "ping the guest daemon",
2709 This is a test probe into the guestfs daemon running inside
2710 the qemu subprocess. Calling this function checks that the
2711 daemon responds to the ping message, without affecting the daemon
2712 or attached block device(s) in any other way.");
2714 ("equal", (RBool "equality", [Pathname "file1"; Pathname "file2"], []), 93, [],
2715 [InitBasicFS, Always, TestOutputTrue (
2716 [["write"; "/file1"; "contents of a file"];
2717 ["cp"; "/file1"; "/file2"];
2718 ["equal"; "/file1"; "/file2"]]);
2719 InitBasicFS, Always, TestOutputFalse (
2720 [["write"; "/file1"; "contents of a file"];
2721 ["write"; "/file2"; "contents of another file"];
2722 ["equal"; "/file1"; "/file2"]]);
2723 InitBasicFS, Always, TestLastFail (
2724 [["equal"; "/file1"; "/file2"]])],
2725 "test if two files have equal contents",
2727 This compares the two files C<file1> and C<file2> and returns
2728 true if their content is exactly equal, or false otherwise.
2730 The external L<cmp(1)> program is used for the comparison.");
2732 ("strings", (RStringList "stringsout", [Pathname "path"], []), 94, [ProtocolLimitWarning],
2733 [InitISOFS, Always, TestOutputList (
2734 [["strings"; "/known-5"]], ["abcdefghi"; "jklmnopqr"]);
2735 InitISOFS, Always, TestOutputList (
2736 [["strings"; "/empty"]], []);
2737 (* Test for RHBZ#579608, absolute symbolic links. *)
2738 InitISOFS, Always, TestRun (
2739 [["strings"; "/abssymlink"]])],
2740 "print the printable strings in a file",
2742 This runs the L<strings(1)> command on a file and returns
2743 the list of printable strings found.");
2745 ("strings_e", (RStringList "stringsout", [String "encoding"; Pathname "path"], []), 95, [ProtocolLimitWarning],
2746 [InitISOFS, Always, TestOutputList (
2747 [["strings_e"; "b"; "/known-5"]], []);
2748 InitBasicFS, Always, TestOutputList (
2749 [["write"; "/new"; "\000h\000e\000l\000l\000o\000\n\000w\000o\000r\000l\000d\000\n"];
2750 ["strings_e"; "b"; "/new"]], ["hello"; "world"])],
2751 "print the printable strings in a file",
2753 This is like the C<guestfs_strings> command, but allows you to
2754 specify the encoding of strings that are looked for in
2755 the source file C<path>.
2757 Allowed encodings are:
2763 Single 7-bit-byte characters like ASCII and the ASCII-compatible
2764 parts of ISO-8859-X (this is what C<guestfs_strings> uses).
2768 Single 8-bit-byte characters.
2772 16-bit big endian strings such as those encoded in
2773 UTF-16BE or UCS-2BE.
2775 =item l (lower case letter L)
2777 16-bit little endian such as UTF-16LE and UCS-2LE.
2778 This is useful for examining binaries in Windows guests.
2782 32-bit big endian such as UCS-4BE.
2786 32-bit little endian such as UCS-4LE.
2790 The returned strings are transcoded to UTF-8.");
2792 ("hexdump", (RString "dump", [Pathname "path"], []), 96, [ProtocolLimitWarning],
2793 [InitISOFS, Always, TestOutput (
2794 [["hexdump"; "/known-4"]], "00000000 61 62 63 0a 64 65 66 0a 67 68 69 |abc.def.ghi|\n0000000b\n");
2795 (* Test for RHBZ#501888c2 regression which caused large hexdump
2796 * commands to segfault.
2798 InitISOFS, Always, TestRun (
2799 [["hexdump"; "/100krandom"]]);
2800 (* Test for RHBZ#579608, absolute symbolic links. *)
2801 InitISOFS, Always, TestRun (
2802 [["hexdump"; "/abssymlink"]])],
2803 "dump a file in hexadecimal",
2805 This runs C<hexdump -C> on the given C<path>. The result is
2806 the human-readable, canonical hex dump of the file.");
2808 ("zerofree", (RErr, [Device "device"], []), 97, [Optional "zerofree"],
2809 [InitNone, Always, TestOutput (
2810 [["part_disk"; "/dev/sda"; "mbr"];
2811 ["mkfs"; "ext3"; "/dev/sda1"];
2812 ["mount_options"; ""; "/dev/sda1"; "/"];
2813 ["write"; "/new"; "test file"];
2814 ["umount"; "/dev/sda1"];
2815 ["zerofree"; "/dev/sda1"];
2816 ["mount_options"; ""; "/dev/sda1"; "/"];
2817 ["cat"; "/new"]], "test file")],
2818 "zero unused inodes and disk blocks on ext2/3 filesystem",
2820 This runs the I<zerofree> program on C<device>. This program
2821 claims to zero unused inodes and disk blocks on an ext2/3
2822 filesystem, thus making it possible to compress the filesystem
2825 You should B<not> run this program if the filesystem is
2828 It is possible that using this program can damage the filesystem
2829 or data on the filesystem.");
2831 ("pvresize", (RErr, [Device "device"], []), 98, [Optional "lvm2"],
2833 "resize an LVM physical volume",
2835 This resizes (expands or shrinks) an existing LVM physical
2836 volume to match the new size of the underlying device.");
2838 ("sfdisk_N", (RErr, [Device "device"; Int "partnum";
2839 Int "cyls"; Int "heads"; Int "sectors";
2840 String "line"], []), 99, [DangerWillRobinson],
2842 "modify a single partition on a block device",
2844 This runs L<sfdisk(8)> option to modify just the single
2845 partition C<n> (note: C<n> counts from 1).
2847 For other parameters, see C<guestfs_sfdisk>. You should usually
2848 pass C<0> for the cyls/heads/sectors parameters.
2850 See also: C<guestfs_part_add>");
2852 ("sfdisk_l", (RString "partitions", [Device "device"], []), 100, [],
2854 "display the partition table",
2856 This displays the partition table on C<device>, in the
2857 human-readable output of the L<sfdisk(8)> command. It is
2858 not intended to be parsed.
2860 See also: C<guestfs_part_list>");
2862 ("sfdisk_kernel_geometry", (RString "partitions", [Device "device"], []), 101, [],
2864 "display the kernel geometry",
2866 This displays the kernel's idea of the geometry of C<device>.
2868 The result is in human-readable format, and not designed to
2871 ("sfdisk_disk_geometry", (RString "partitions", [Device "device"], []), 102, [],
2873 "display the disk geometry from the partition table",
2875 This displays the disk geometry of C<device> read from the
2876 partition table. Especially in the case where the underlying
2877 block device has been resized, this can be different from the
2878 kernel's idea of the geometry (see C<guestfs_sfdisk_kernel_geometry>).
2880 The result is in human-readable format, and not designed to
2883 ("vg_activate_all", (RErr, [Bool "activate"], []), 103, [Optional "lvm2"],
2885 "activate or deactivate all volume groups",
2887 This command activates or (if C<activate> is false) deactivates
2888 all logical volumes in all volume groups.
2889 If activated, then they are made known to the
2890 kernel, ie. they appear as C</dev/mapper> devices. If deactivated,
2891 then those devices disappear.
2893 This command is the same as running C<vgchange -a y|n>");
2895 ("vg_activate", (RErr, [Bool "activate"; StringList "volgroups"], []), 104, [Optional "lvm2"],
2897 "activate or deactivate some volume groups",
2899 This command activates or (if C<activate> is false) deactivates
2900 all logical volumes in the listed volume groups C<volgroups>.
2901 If activated, then they are made known to the
2902 kernel, ie. they appear as C</dev/mapper> devices. If deactivated,
2903 then those devices disappear.
2905 This command is the same as running C<vgchange -a y|n volgroups...>
2907 Note that if C<volgroups> is an empty list then B<all> volume groups
2908 are activated or deactivated.");
2910 ("lvresize", (RErr, [Device "device"; Int "mbytes"], []), 105, [Optional "lvm2"],
2911 [InitNone, Always, TestOutput (
2912 [["part_disk"; "/dev/sda"; "mbr"];
2913 ["pvcreate"; "/dev/sda1"];
2914 ["vgcreate"; "VG"; "/dev/sda1"];
2915 ["lvcreate"; "LV"; "VG"; "10"];
2916 ["mkfs"; "ext2"; "/dev/VG/LV"];
2917 ["mount_options"; ""; "/dev/VG/LV"; "/"];
2918 ["write"; "/new"; "test content"];
2920 ["lvresize"; "/dev/VG/LV"; "20"];
2921 ["e2fsck_f"; "/dev/VG/LV"];
2922 ["resize2fs"; "/dev/VG/LV"];
2923 ["mount_options"; ""; "/dev/VG/LV"; "/"];
2924 ["cat"; "/new"]], "test content");
2925 InitNone, Always, TestRun (
2926 (* Make an LV smaller to test RHBZ#587484. *)
2927 [["part_disk"; "/dev/sda"; "mbr"];
2928 ["pvcreate"; "/dev/sda1"];
2929 ["vgcreate"; "VG"; "/dev/sda1"];
2930 ["lvcreate"; "LV"; "VG"; "20"];
2931 ["lvresize"; "/dev/VG/LV"; "10"]])],
2932 "resize an LVM logical volume",
2934 This resizes (expands or shrinks) an existing LVM logical
2935 volume to C<mbytes>. When reducing, data in the reduced part
2938 ("resize2fs", (RErr, [Device "device"], []), 106, [],
2939 [], (* lvresize tests this *)
2940 "resize an ext2, ext3 or ext4 filesystem",
2942 This resizes an ext2, ext3 or ext4 filesystem to match the size of
2943 the underlying device.
2945 I<Note:> It is sometimes required that you run C<guestfs_e2fsck_f>
2946 on the C<device> before calling this command. For unknown reasons
2947 C<resize2fs> sometimes gives an error about this and sometimes not.
2948 In any case, it is always safe to call C<guestfs_e2fsck_f> before
2949 calling this function.");
2951 ("find", (RStringList "names", [Pathname "directory"], []), 107, [ProtocolLimitWarning],
2952 [InitBasicFS, Always, TestOutputList (
2953 [["find"; "/"]], ["lost+found"]);
2954 InitBasicFS, Always, TestOutputList (
2958 ["find"; "/"]], ["a"; "b"; "b/c"; "lost+found"]);
2959 InitBasicFS, Always, TestOutputList (
2960 [["mkdir_p"; "/a/b/c"];
2961 ["touch"; "/a/b/c/d"];
2962 ["find"; "/a/b/"]], ["c"; "c/d"])],
2963 "find all files and directories",
2965 This command lists out all files and directories, recursively,
2966 starting at C<directory>. It is essentially equivalent to
2967 running the shell command C<find directory -print> but some
2968 post-processing happens on the output, described below.
2970 This returns a list of strings I<without any prefix>. Thus
2971 if the directory structure was:
2977 then the returned list from C<guestfs_find> C</tmp> would be
2985 If C<directory> is not a directory, then this command returns
2988 The returned list is sorted.
2990 See also C<guestfs_find0>.");
2992 ("e2fsck_f", (RErr, [Device "device"], []), 108, [],
2993 [], (* lvresize tests this *)
2994 "check an ext2/ext3 filesystem",
2996 This runs C<e2fsck -p -f device>, ie. runs the ext2/ext3
2997 filesystem checker on C<device>, noninteractively (C<-p>),
2998 even if the filesystem appears to be clean (C<-f>).
3000 This command is only needed because of C<guestfs_resize2fs>
3001 (q.v.). Normally you should use C<guestfs_fsck>.");
3003 ("sleep", (RErr, [Int "secs"], []), 109, [],
3004 [InitNone, Always, TestRun (
3006 "sleep for some seconds",
3008 Sleep for C<secs> seconds.");
3010 ("ntfs_3g_probe", (RInt "status", [Bool "rw"; Device "device"], []), 110, [Optional "ntfs3g"],
3011 [InitNone, Always, TestOutputInt (
3012 [["part_disk"; "/dev/sda"; "mbr"];
3013 ["mkfs"; "ntfs"; "/dev/sda1"];
3014 ["ntfs_3g_probe"; "true"; "/dev/sda1"]], 0);
3015 InitNone, Always, TestOutputInt (
3016 [["part_disk"; "/dev/sda"; "mbr"];
3017 ["mkfs"; "ext2"; "/dev/sda1"];
3018 ["ntfs_3g_probe"; "true"; "/dev/sda1"]], 12)],
3019 "probe NTFS volume",
3021 This command runs the L<ntfs-3g.probe(8)> command which probes
3022 an NTFS C<device> for mountability. (Not all NTFS volumes can
3023 be mounted read-write, and some cannot be mounted at all).
3025 C<rw> is a boolean flag. Set it to true if you want to test
3026 if the volume can be mounted read-write. Set it to false if
3027 you want to test if the volume can be mounted read-only.
3029 The return value is an integer which C<0> if the operation
3030 would succeed, or some non-zero value documented in the
3031 L<ntfs-3g.probe(8)> manual page.");
3033 ("sh", (RString "output", [String "command"], []), 111, [],
3034 [], (* XXX needs tests *)
3035 "run a command via the shell",
3037 This call runs a command from the guest filesystem via the
3040 This is like C<guestfs_command>, but passes the command to:
3042 /bin/sh -c \"command\"
3044 Depending on the guest's shell, this usually results in
3045 wildcards being expanded, shell expressions being interpolated
3048 All the provisos about C<guestfs_command> apply to this call.");
3050 ("sh_lines", (RStringList "lines", [String "command"], []), 112, [],
3051 [], (* XXX needs tests *)
3052 "run a command via the shell returning lines",
3054 This is the same as C<guestfs_sh>, but splits the result
3055 into a list of lines.
3057 See also: C<guestfs_command_lines>");
3059 ("glob_expand", (RStringList "paths", [Pathname "pattern"], []), 113, [],
3060 (* Use Pathname here, and hence ABS_PATH (pattern,... in generated
3061 * code in stubs.c, since all valid glob patterns must start with "/".
3062 * There is no concept of "cwd" in libguestfs, hence no "."-relative names.
3064 [InitBasicFS, Always, TestOutputList (
3065 [["mkdir_p"; "/a/b/c"];
3066 ["touch"; "/a/b/c/d"];
3067 ["touch"; "/a/b/c/e"];
3068 ["glob_expand"; "/a/b/c/*"]], ["/a/b/c/d"; "/a/b/c/e"]);
3069 InitBasicFS, Always, TestOutputList (
3070 [["mkdir_p"; "/a/b/c"];
3071 ["touch"; "/a/b/c/d"];
3072 ["touch"; "/a/b/c/e"];
3073 ["glob_expand"; "/a/*/c/*"]], ["/a/b/c/d"; "/a/b/c/e"]);
3074 InitBasicFS, Always, TestOutputList (
3075 [["mkdir_p"; "/a/b/c"];
3076 ["touch"; "/a/b/c/d"];
3077 ["touch"; "/a/b/c/e"];
3078 ["glob_expand"; "/a/*/x/*"]], [])],
3079 "expand a wildcard path",
3081 This command searches for all the pathnames matching
3082 C<pattern> according to the wildcard expansion rules
3085 If no paths match, then this returns an empty list
3086 (note: not an error).
3088 It is just a wrapper around the C L<glob(3)> function
3089 with flags C<GLOB_MARK|GLOB_BRACE>.
3090 See that manual page for more details.");
3092 ("scrub_device", (RErr, [Device "device"], []), 114, [DangerWillRobinson; Optional "scrub"],
3093 [InitNone, Always, TestRun ( (* use /dev/sdc because it's smaller *)
3094 [["scrub_device"; "/dev/sdc"]])],
3095 "scrub (securely wipe) a device",
3097 This command writes patterns over C<device> to make data retrieval
3100 It is an interface to the L<scrub(1)> program. See that
3101 manual page for more details.");
3103 ("scrub_file", (RErr, [Pathname "file"], []), 115, [Optional "scrub"],
3104 [InitBasicFS, Always, TestRun (
3105 [["write"; "/file"; "content"];
3106 ["scrub_file"; "/file"]])],
3107 "scrub (securely wipe) a file",
3109 This command writes patterns over a file to make data retrieval
3112 The file is I<removed> after scrubbing.
3114 It is an interface to the L<scrub(1)> program. See that
3115 manual page for more details.");
3117 ("scrub_freespace", (RErr, [Pathname "dir"], []), 116, [Optional "scrub"],
3118 [], (* XXX needs testing *)
3119 "scrub (securely wipe) free space",
3121 This command creates the directory C<dir> and then fills it
3122 with files until the filesystem is full, and scrubs the files
3123 as for C<guestfs_scrub_file>, and deletes them.
3124 The intention is to scrub any free space on the partition
3127 It is an interface to the L<scrub(1)> program. See that
3128 manual page for more details.");
3130 ("mkdtemp", (RString "dir", [Pathname "template"], []), 117, [],
3131 [InitBasicFS, Always, TestRun (
3133 ["mkdtemp"; "/tmp/tmpXXXXXX"]])],
3134 "create a temporary directory",
3136 This command creates a temporary directory. The
3137 C<template> parameter should be a full pathname for the
3138 temporary directory name with the final six characters being
3141 For example: \"/tmp/myprogXXXXXX\" or \"/Temp/myprogXXXXXX\",
3142 the second one being suitable for Windows filesystems.
3144 The name of the temporary directory that was created
3147 The temporary directory is created with mode 0700
3148 and is owned by root.
3150 The caller is responsible for deleting the temporary
3151 directory and its contents after use.
3153 See also: L<mkdtemp(3)>");
3155 ("wc_l", (RInt "lines", [Pathname "path"], []), 118, [],
3156 [InitISOFS, Always, TestOutputInt (
3157 [["wc_l"; "/10klines"]], 10000);
3158 (* Test for RHBZ#579608, absolute symbolic links. *)
3159 InitISOFS, Always, TestOutputInt (
3160 [["wc_l"; "/abssymlink"]], 10000)],
3161 "count lines in a file",
3163 This command counts the lines in a file, using the
3164 C<wc -l> external command.");
3166 ("wc_w", (RInt "words", [Pathname "path"], []), 119, [],
3167 [InitISOFS, Always, TestOutputInt (
3168 [["wc_w"; "/10klines"]], 10000)],
3169 "count words in a file",
3171 This command counts the words in a file, using the
3172 C<wc -w> external command.");
3174 ("wc_c", (RInt "chars", [Pathname "path"], []), 120, [],
3175 [InitISOFS, Always, TestOutputInt (
3176 [["wc_c"; "/100kallspaces"]], 102400)],
3177 "count characters in a file",
3179 This command counts the characters in a file, using the
3180 C<wc -c> external command.");
3182 ("head", (RStringList "lines", [Pathname "path"], []), 121, [ProtocolLimitWarning],
3183 [InitISOFS, Always, TestOutputList (
3184 [["head"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz";"3abcdefghijklmnopqrstuvwxyz";"4abcdefghijklmnopqrstuvwxyz";"5abcdefghijklmnopqrstuvwxyz";"6abcdefghijklmnopqrstuvwxyz";"7abcdefghijklmnopqrstuvwxyz";"8abcdefghijklmnopqrstuvwxyz";"9abcdefghijklmnopqrstuvwxyz"]);
3185 (* Test for RHBZ#579608, absolute symbolic links. *)
3186 InitISOFS, Always, TestOutputList (
3187 [["head"; "/abssymlink"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz";"3abcdefghijklmnopqrstuvwxyz";"4abcdefghijklmnopqrstuvwxyz";"5abcdefghijklmnopqrstuvwxyz";"6abcdefghijklmnopqrstuvwxyz";"7abcdefghijklmnopqrstuvwxyz";"8abcdefghijklmnopqrstuvwxyz";"9abcdefghijklmnopqrstuvwxyz"])],
3188 "return first 10 lines of a file",
3190 This command returns up to the first 10 lines of a file as
3191 a list of strings.");
3193 ("head_n", (RStringList "lines", [Int "nrlines"; Pathname "path"], []), 122, [ProtocolLimitWarning],
3194 [InitISOFS, Always, TestOutputList (
3195 [["head_n"; "3"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz"]);
3196 InitISOFS, Always, TestOutputList (
3197 [["head_n"; "-9997"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz"]);
3198 InitISOFS, Always, TestOutputList (
3199 [["head_n"; "0"; "/10klines"]], [])],
3200 "return first N lines of a file",
3202 If the parameter C<nrlines> is a positive number, this returns the first
3203 C<nrlines> lines of the file C<path>.
3205 If the parameter C<nrlines> is a negative number, this returns lines
3206 from the file C<path>, excluding the last C<nrlines> lines.
3208 If the parameter C<nrlines> is zero, this returns an empty list.");
3210 ("tail", (RStringList "lines", [Pathname "path"], []), 123, [ProtocolLimitWarning],
3211 [InitISOFS, Always, TestOutputList (
3212 [["tail"; "/10klines"]], ["9990abcdefghijklmnopqrstuvwxyz";"9991abcdefghijklmnopqrstuvwxyz";"9992abcdefghijklmnopqrstuvwxyz";"9993abcdefghijklmnopqrstuvwxyz";"9994abcdefghijklmnopqrstuvwxyz";"9995abcdefghijklmnopqrstuvwxyz";"9996abcdefghijklmnopqrstuvwxyz";"9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"])],
3213 "return last 10 lines of a file",
3215 This command returns up to the last 10 lines of a file as
3216 a list of strings.");
3218 ("tail_n", (RStringList "lines", [Int "nrlines"; Pathname "path"], []), 124, [ProtocolLimitWarning],
3219 [InitISOFS, Always, TestOutputList (
3220 [["tail_n"; "3"; "/10klines"]], ["9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"]);
3221 InitISOFS, Always, TestOutputList (
3222 [["tail_n"; "-9998"; "/10klines"]], ["9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"]);
3223 InitISOFS, Always, TestOutputList (
3224 [["tail_n"; "0"; "/10klines"]], [])],
3225 "return last N lines of a file",
3227 If the parameter C<nrlines> is a positive number, this returns the last
3228 C<nrlines> lines of the file C<path>.
3230 If the parameter C<nrlines> is a negative number, this returns lines
3231 from the file C<path>, starting with the C<-nrlines>th line.
3233 If the parameter C<nrlines> is zero, this returns an empty list.");
3235 ("df", (RString "output", [], []), 125, [],
3236 [], (* XXX Tricky to test because it depends on the exact format
3237 * of the 'df' command and other imponderables.
3239 "report file system disk space usage",
3241 This command runs the C<df> command to report disk space used.
3243 This command is mostly useful for interactive sessions. It
3244 is I<not> intended that you try to parse the output string.
3245 Use C<statvfs> from programs.");
3247 ("df_h", (RString "output", [], []), 126, [],
3248 [], (* XXX Tricky to test because it depends on the exact format
3249 * of the 'df' command and other imponderables.
3251 "report file system disk space usage (human readable)",
3253 This command runs the C<df -h> command to report disk space used
3254 in human-readable format.
3256 This command is mostly useful for interactive sessions. It
3257 is I<not> intended that you try to parse the output string.
3258 Use C<statvfs> from programs.");
3260 ("du", (RInt64 "sizekb", [Pathname "path"], []), 127, [],
3261 [InitISOFS, Always, TestOutputInt (
3262 [["du"; "/directory"]], 2 (* ISO fs blocksize is 2K *))],
3263 "estimate file space usage",
3265 This command runs the C<du -s> command to estimate file space
3268 C<path> can be a file or a directory. If C<path> is a directory
3269 then the estimate includes the contents of the directory and all
3270 subdirectories (recursively).
3272 The result is the estimated size in I<kilobytes>
3273 (ie. units of 1024 bytes).");
3275 ("initrd_list", (RStringList "filenames", [Pathname "path"], []), 128, [],
3276 [InitISOFS, Always, TestOutputList (
3277 [["initrd_list"; "/initrd"]], ["empty";"known-1";"known-2";"known-3";"known-4"; "known-5"])],
3278 "list files in an initrd",
3280 This command lists out files contained in an initrd.
3282 The files are listed without any initial C</> character. The
3283 files are listed in the order they appear (not necessarily
3284 alphabetical). Directory names are listed as separate items.
3286 Old Linux kernels (2.4 and earlier) used a compressed ext2
3287 filesystem as initrd. We I<only> support the newer initramfs
3288 format (compressed cpio files).");
3290 ("mount_loop", (RErr, [Pathname "file"; Pathname "mountpoint"], []), 129, [],
3292 "mount a file using the loop device",
3294 This command lets you mount C<file> (a filesystem image
3295 in a file) on a mount point. It is entirely equivalent to
3296 the command C<mount -o loop file mountpoint>.");
3298 ("mkswap", (RErr, [Device "device"], []), 130, [],
3299 [InitEmpty, Always, TestRun (
3300 [["part_disk"; "/dev/sda"; "mbr"];
3301 ["mkswap"; "/dev/sda1"]])],
3302 "create a swap partition",
3304 Create a swap partition on C<device>.");
3306 ("mkswap_L", (RErr, [String "label"; Device "device"], []), 131, [],
3307 [InitEmpty, Always, TestRun (
3308 [["part_disk"; "/dev/sda"; "mbr"];
3309 ["mkswap_L"; "hello"; "/dev/sda1"]])],
3310 "create a swap partition with a label",
3312 Create a swap partition on C<device> with label C<label>.
3314 Note that you cannot attach a swap label to a block device
3315 (eg. C</dev/sda>), just to a partition. This appears to be
3316 a limitation of the kernel or swap tools.");
3318 ("mkswap_U", (RErr, [String "uuid"; Device "device"], []), 132, [Optional "linuxfsuuid"],
3319 (let uuid = uuidgen () in
3320 [InitEmpty, Always, TestRun (
3321 [["part_disk"; "/dev/sda"; "mbr"];
3322 ["mkswap_U"; uuid; "/dev/sda1"]])]),
3323 "create a swap partition with an explicit UUID",
3325 Create a swap partition on C<device> with UUID C<uuid>.");
3327 ("mknod", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"], []), 133, [Optional "mknod"],
3328 [InitBasicFS, Always, TestOutputStruct (
3329 [["mknod"; "0o10777"; "0"; "0"; "/node"];
3330 (* NB: default umask 022 means 0777 -> 0755 in these tests *)
3331 ["stat"; "/node"]], [CompareWithInt ("mode", 0o10755)]);
3332 InitBasicFS, Always, TestOutputStruct (
3333 [["mknod"; "0o60777"; "66"; "99"; "/node"];
3334 ["stat"; "/node"]], [CompareWithInt ("mode", 0o60755)])],
3335 "make block, character or FIFO devices",
3337 This call creates block or character special devices, or
3338 named pipes (FIFOs).
3340 The C<mode> parameter should be the mode, using the standard
3341 constants. C<devmajor> and C<devminor> are the
3342 device major and minor numbers, only used when creating block
3343 and character special devices.
3345 Note that, just like L<mknod(2)>, the mode must be bitwise
3346 OR'd with S_IFBLK, S_IFCHR, S_IFIFO or S_IFSOCK (otherwise this call
3347 just creates a regular file). These constants are
3348 available in the standard Linux header files, or you can use
3349 C<guestfs_mknod_b>, C<guestfs_mknod_c> or C<guestfs_mkfifo>
3350 which are wrappers around this command which bitwise OR
3351 in the appropriate constant for you.
3353 The mode actually set is affected by the umask.");
3355 ("mkfifo", (RErr, [Int "mode"; Pathname "path"], []), 134, [Optional "mknod"],
3356 [InitBasicFS, Always, TestOutputStruct (
3357 [["mkfifo"; "0o777"; "/node"];
3358 ["stat"; "/node"]], [CompareWithInt ("mode", 0o10755)])],
3359 "make FIFO (named pipe)",
3361 This call creates a FIFO (named pipe) called C<path> with
3362 mode C<mode>. It is just a convenient wrapper around
3365 The mode actually set is affected by the umask.");
3367 ("mknod_b", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"], []), 135, [Optional "mknod"],
3368 [InitBasicFS, Always, TestOutputStruct (
3369 [["mknod_b"; "0o777"; "99"; "66"; "/node"];
3370 ["stat"; "/node"]], [CompareWithInt ("mode", 0o60755)])],
3371 "make block device node",
3373 This call creates a block device node called C<path> with
3374 mode C<mode> and device major/minor C<devmajor> and C<devminor>.
3375 It is just a convenient wrapper around C<guestfs_mknod>.
3377 The mode actually set is affected by the umask.");
3379 ("mknod_c", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"], []), 136, [Optional "mknod"],
3380 [InitBasicFS, Always, TestOutputStruct (
3381 [["mknod_c"; "0o777"; "99"; "66"; "/node"];
3382 ["stat"; "/node"]], [CompareWithInt ("mode", 0o20755)])],
3383 "make char device node",
3385 This call creates a char device node called C<path> with
3386 mode C<mode> and device major/minor C<devmajor> and C<devminor>.
3387 It is just a convenient wrapper around C<guestfs_mknod>.
3389 The mode actually set is affected by the umask.");
3391 ("umask", (RInt "oldmask", [Int "mask"], []), 137, [FishOutput FishOutputOctal],
3392 [InitEmpty, Always, TestOutputInt (
3393 [["umask"; "0o22"]], 0o22)],
3394 "set file mode creation mask (umask)",
3396 This function sets the mask used for creating new files and
3397 device nodes to C<mask & 0777>.
3399 Typical umask values would be C<022> which creates new files
3400 with permissions like \"-rw-r--r--\" or \"-rwxr-xr-x\", and
3401 C<002> which creates new files with permissions like
3402 \"-rw-rw-r--\" or \"-rwxrwxr-x\".
3404 The default umask is C<022>. This is important because it
3405 means that directories and device nodes will be created with
3406 C<0644> or C<0755> mode even if you specify C<0777>.
3408 See also C<guestfs_get_umask>,
3409 L<umask(2)>, C<guestfs_mknod>, C<guestfs_mkdir>.
3411 This call returns the previous umask.");
3413 ("readdir", (RStructList ("entries", "dirent"), [Pathname "dir"], []), 138, [],
3415 "read directories entries",
3417 This returns the list of directory entries in directory C<dir>.
3419 All entries in the directory are returned, including C<.> and
3420 C<..>. The entries are I<not> sorted, but returned in the same
3421 order as the underlying filesystem.
3423 Also this call returns basic file type information about each
3424 file. The C<ftyp> field will contain one of the following characters:
3462 The L<readdir(3)> call returned a C<d_type> field with an
3467 This function is primarily intended for use by programs. To
3468 get a simple list of names, use C<guestfs_ls>. To get a printable
3469 directory for human consumption, use C<guestfs_ll>.");
3471 ("sfdiskM", (RErr, [Device "device"; StringList "lines"], []), 139, [DangerWillRobinson],
3473 "create partitions on a block device",
3475 This is a simplified interface to the C<guestfs_sfdisk>
3476 command, where partition sizes are specified in megabytes
3477 only (rounded to the nearest cylinder) and you don't need
3478 to specify the cyls, heads and sectors parameters which
3479 were rarely if ever used anyway.
3481 See also: C<guestfs_sfdisk>, the L<sfdisk(8)> manpage
3482 and C<guestfs_part_disk>");
3484 ("zfile", (RString "description", [String "meth"; Pathname "path"], []), 140, [DeprecatedBy "file"],
3486 "determine file type inside a compressed file",
3488 This command runs C<file> after first decompressing C<path>
3491 C<method> must be one of C<gzip>, C<compress> or C<bzip2>.
3493 Since 1.0.63, use C<guestfs_file> instead which can now
3494 process compressed files.");
3496 ("getxattrs", (RStructList ("xattrs", "xattr"), [Pathname "path"], []), 141, [Optional "linuxxattrs"],
3498 "list extended attributes of a file or directory",
3500 This call lists the extended attributes of the file or directory
3503 At the system call level, this is a combination of the
3504 L<listxattr(2)> and L<getxattr(2)> calls.
3506 See also: C<guestfs_lgetxattrs>, L<attr(5)>.");
3508 ("lgetxattrs", (RStructList ("xattrs", "xattr"), [Pathname "path"], []), 142, [Optional "linuxxattrs"],
3510 "list extended attributes of a file or directory",
3512 This is the same as C<guestfs_getxattrs>, but if C<path>
3513 is a symbolic link, then it returns the extended attributes
3514 of the link itself.");
3516 ("setxattr", (RErr, [String "xattr";
3517 String "val"; Int "vallen"; (* will be BufferIn *)
3518 Pathname "path"], []), 143, [Optional "linuxxattrs"],
3520 "set extended attribute of a file or directory",
3522 This call sets the extended attribute named C<xattr>
3523 of the file C<path> to the value C<val> (of length C<vallen>).
3524 The value is arbitrary 8 bit data.
3526 See also: C<guestfs_lsetxattr>, L<attr(5)>.");
3528 ("lsetxattr", (RErr, [String "xattr";
3529 String "val"; Int "vallen"; (* will be BufferIn *)
3530 Pathname "path"], []), 144, [Optional "linuxxattrs"],
3532 "set extended attribute of a file or directory",
3534 This is the same as C<guestfs_setxattr>, but if C<path>
3535 is a symbolic link, then it sets an extended attribute
3536 of the link itself.");
3538 ("removexattr", (RErr, [String "xattr"; Pathname "path"], []), 145, [Optional "linuxxattrs"],
3540 "remove extended attribute of a file or directory",
3542 This call removes the extended attribute named C<xattr>
3543 of the file C<path>.
3545 See also: C<guestfs_lremovexattr>, L<attr(5)>.");
3547 ("lremovexattr", (RErr, [String "xattr"; Pathname "path"], []), 146, [Optional "linuxxattrs"],
3549 "remove extended attribute of a file or directory",
3551 This is the same as C<guestfs_removexattr>, but if C<path>
3552 is a symbolic link, then it removes an extended attribute
3553 of the link itself.");
3555 ("mountpoints", (RHashtable "mps", [], []), 147, [],
3559 This call is similar to C<guestfs_mounts>. That call returns
3560 a list of devices. This one returns a hash table (map) of
3561 device name to directory where the device is mounted.");
3563 ("mkmountpoint", (RErr, [String "exemptpath"], []), 148, [],
3564 (* This is a special case: while you would expect a parameter
3565 * of type "Pathname", that doesn't work, because it implies
3566 * NEED_ROOT in the generated calling code in stubs.c, and
3567 * this function cannot use NEED_ROOT.
3570 "create a mountpoint",
3572 C<guestfs_mkmountpoint> and C<guestfs_rmmountpoint> are
3573 specialized calls that can be used to create extra mountpoints
3574 before mounting the first filesystem.
3576 These calls are I<only> necessary in some very limited circumstances,
3577 mainly the case where you want to mount a mix of unrelated and/or
3578 read-only filesystems together.
3580 For example, live CDs often contain a \"Russian doll\" nest of
3581 filesystems, an ISO outer layer, with a squashfs image inside, with
3582 an ext2/3 image inside that. You can unpack this as follows
3585 add-ro Fedora-11-i686-Live.iso
3589 mkmountpoint /ext3fs
3591 mount-loop /cd/LiveOS/squashfs.img /sqsh
3592 mount-loop /sqsh/LiveOS/ext3fs.img /ext3fs
3594 The inner filesystem is now unpacked under the /ext3fs mountpoint.
3596 C<guestfs_mkmountpoint> is not compatible with C<guestfs_umount_all>.
3597 You may get unexpected errors if you try to mix these calls. It is
3598 safest to manually unmount filesystems and remove mountpoints after use.
3600 C<guestfs_umount_all> unmounts filesystems by sorting the paths
3601 longest first, so for this to work for manual mountpoints, you
3602 must ensure that the innermost mountpoints have the longest
3603 pathnames, as in the example code above.
3605 For more details see L<https://bugzilla.redhat.com/show_bug.cgi?id=599503>
3607 Autosync [see C<guestfs_set_autosync>, this is set by default on
3608 handles] means that C<guestfs_umount_all> is called when the handle
3609 is closed which can also trigger these issues.");
3611 ("rmmountpoint", (RErr, [String "exemptpath"], []), 149, [],
3613 "remove a mountpoint",
3615 This calls removes a mountpoint that was previously created
3616 with C<guestfs_mkmountpoint>. See C<guestfs_mkmountpoint>
3617 for full details.");
3619 ("read_file", (RBufferOut "content", [Pathname "path"], []), 150, [ProtocolLimitWarning],
3620 [InitISOFS, Always, TestOutputBuffer (
3621 [["read_file"; "/known-4"]], "abc\ndef\nghi");
3622 (* Test various near large, large and too large files (RHBZ#589039). *)
3623 InitBasicFS, Always, TestLastFail (
3625 ["truncate_size"; "/a"; "4194303"]; (* GUESTFS_MESSAGE_MAX - 1 *)
3626 ["read_file"; "/a"]]);
3627 InitBasicFS, Always, TestLastFail (
3629 ["truncate_size"; "/a"; "4194304"]; (* GUESTFS_MESSAGE_MAX *)
3630 ["read_file"; "/a"]]);
3631 InitBasicFS, Always, TestLastFail (
3633 ["truncate_size"; "/a"; "41943040"]; (* GUESTFS_MESSAGE_MAX * 10 *)
3634 ["read_file"; "/a"]])],
3637 This calls returns the contents of the file C<path> as a
3640 Unlike C<guestfs_cat>, this function can correctly
3641 handle files that contain embedded ASCII NUL characters.
3642 However unlike C<guestfs_download>, this function is limited
3643 in the total size of file that can be handled.");
3645 ("grep", (RStringList "lines", [String "regex"; Pathname "path"], []), 151, [ProtocolLimitWarning],
3646 [InitISOFS, Always, TestOutputList (
3647 [["grep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"]);
3648 InitISOFS, Always, TestOutputList (
3649 [["grep"; "nomatch"; "/test-grep.txt"]], []);
3650 (* Test for RHBZ#579608, absolute symbolic links. *)
3651 InitISOFS, Always, TestOutputList (
3652 [["grep"; "nomatch"; "/abssymlink"]], [])],
3653 "return lines matching a pattern",
3655 This calls the external C<grep> program and returns the
3658 ("egrep", (RStringList "lines", [String "regex"; Pathname "path"], []), 152, [ProtocolLimitWarning],
3659 [InitISOFS, Always, TestOutputList (
3660 [["egrep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"])],
3661 "return lines matching a pattern",
3663 This calls the external C<egrep> program and returns the
3666 ("fgrep", (RStringList "lines", [String "pattern"; Pathname "path"], []), 153, [ProtocolLimitWarning],
3667 [InitISOFS, Always, TestOutputList (
3668 [["fgrep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"])],
3669 "return lines matching a pattern",
3671 This calls the external C<fgrep> program and returns the
3674 ("grepi", (RStringList "lines", [String "regex"; Pathname "path"], []), 154, [ProtocolLimitWarning],
3675 [InitISOFS, Always, TestOutputList (
3676 [["grepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])],
3677 "return lines matching a pattern",
3679 This calls the external C<grep -i> program and returns the
3682 ("egrepi", (RStringList "lines", [String "regex"; Pathname "path"], []), 155, [ProtocolLimitWarning],
3683 [InitISOFS, Always, TestOutputList (
3684 [["egrepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])],
3685 "return lines matching a pattern",
3687 This calls the external C<egrep -i> program and returns the
3690 ("fgrepi", (RStringList "lines", [String "pattern"; Pathname "path"], []), 156, [ProtocolLimitWarning],
3691 [InitISOFS, Always, TestOutputList (
3692 [["fgrepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])],
3693 "return lines matching a pattern",
3695 This calls the external C<fgrep -i> program and returns the
3698 ("zgrep", (RStringList "lines", [String "regex"; Pathname "path"], []), 157, [ProtocolLimitWarning],
3699 [InitISOFS, Always, TestOutputList (
3700 [["zgrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])],
3701 "return lines matching a pattern",
3703 This calls the external C<zgrep> program and returns the
3706 ("zegrep", (RStringList "lines", [String "regex"; Pathname "path"], []), 158, [ProtocolLimitWarning],
3707 [InitISOFS, Always, TestOutputList (
3708 [["zegrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])],
3709 "return lines matching a pattern",
3711 This calls the external C<zegrep> program and returns the
3714 ("zfgrep", (RStringList "lines", [String "pattern"; Pathname "path"], []), 159, [ProtocolLimitWarning],
3715 [InitISOFS, Always, TestOutputList (
3716 [["zfgrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])],
3717 "return lines matching a pattern",
3719 This calls the external C<zfgrep> program and returns the
3722 ("zgrepi", (RStringList "lines", [String "regex"; Pathname "path"], []), 160, [ProtocolLimitWarning],
3723 [InitISOFS, Always, TestOutputList (
3724 [["zgrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])],
3725 "return lines matching a pattern",
3727 This calls the external C<zgrep -i> program and returns the
3730 ("zegrepi", (RStringList "lines", [String "regex"; Pathname "path"], []), 161, [ProtocolLimitWarning],
3731 [InitISOFS, Always, TestOutputList (
3732 [["zegrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])],
3733 "return lines matching a pattern",
3735 This calls the external C<zegrep -i> program and returns the
3738 ("zfgrepi", (RStringList "lines", [String "pattern"; Pathname "path"], []), 162, [ProtocolLimitWarning],
3739 [InitISOFS, Always, TestOutputList (
3740 [["zfgrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])],
3741 "return lines matching a pattern",
3743 This calls the external C<zfgrep -i> program and returns the
3746 ("realpath", (RString "rpath", [Pathname "path"], []), 163, [Optional "realpath"],
3747 [InitISOFS, Always, TestOutput (
3748 [["realpath"; "/../directory"]], "/directory")],
3749 "canonicalized absolute pathname",
3751 Return the canonicalized absolute pathname of C<path>. The
3752 returned path has no C<.>, C<..> or symbolic link path elements.");
3754 ("ln", (RErr, [String "target"; Pathname "linkname"], []), 164, [],
3755 [InitBasicFS, Always, TestOutputStruct (
3758 ["stat"; "/b"]], [CompareWithInt ("nlink", 2)])],
3759 "create a hard link",
3761 This command creates a hard link using the C<ln> command.");
3763 ("ln_f", (RErr, [String "target"; Pathname "linkname"], []), 165, [],
3764 [InitBasicFS, Always, TestOutputStruct (
3767 ["ln_f"; "/a"; "/b"];
3768 ["stat"; "/b"]], [CompareWithInt ("nlink", 2)])],
3769 "create a hard link",
3771 This command creates a hard link using the C<ln -f> command.
3772 The C<-f> option removes the link (C<linkname>) if it exists already.");
3774 ("ln_s", (RErr, [String "target"; Pathname "linkname"], []), 166, [],
3775 [InitBasicFS, Always, TestOutputStruct (
3777 ["ln_s"; "a"; "/b"];
3778 ["lstat"; "/b"]], [CompareWithInt ("mode", 0o120777)])],
3779 "create a symbolic link",
3781 This command creates a symbolic link using the C<ln -s> command.");
3783 ("ln_sf", (RErr, [String "target"; Pathname "linkname"], []), 167, [],
3784 [InitBasicFS, Always, TestOutput (
3785 [["mkdir_p"; "/a/b"];
3786 ["touch"; "/a/b/c"];
3787 ["ln_sf"; "../d"; "/a/b/c"];
3788 ["readlink"; "/a/b/c"]], "../d")],
3789 "create a symbolic link",
3791 This command creates a symbolic link using the C<ln -sf> command,
3792 The C<-f> option removes the link (C<linkname>) if it exists already.");
3794 ("readlink", (RString "link", [Pathname "path"], []), 168, [],
3795 [] (* XXX tested above *),
3796 "read the target of a symbolic link",
3798 This command reads the target of a symbolic link.");
3800 ("fallocate", (RErr, [Pathname "path"; Int "len"], []), 169, [DeprecatedBy "fallocate64"],
3801 [InitBasicFS, Always, TestOutputStruct (
3802 [["fallocate"; "/a"; "1000000"];
3803 ["stat"; "/a"]], [CompareWithInt ("size", 1_000_000)])],
3804 "preallocate a file in the guest filesystem",
3806 This command preallocates a file (containing zero bytes) named
3807 C<path> of size C<len> bytes. If the file exists already, it
3810 Do not confuse this with the guestfish-specific
3811 C<alloc> command which allocates a file in the host and
3812 attaches it as a device.");
3814 ("swapon_device", (RErr, [Device "device"], []), 170, [],
3815 [InitPartition, Always, TestRun (
3816 [["mkswap"; "/dev/sda1"];
3817 ["swapon_device"; "/dev/sda1"];
3818 ["swapoff_device"; "/dev/sda1"]])],
3819 "enable swap on device",
3821 This command enables the libguestfs appliance to use the
3822 swap device or partition named C<device>. The increased
3823 memory is made available for all commands, for example
3824 those run using C<guestfs_command> or C<guestfs_sh>.
3826 Note that you should not swap to existing guest swap
3827 partitions unless you know what you are doing. They may
3828 contain hibernation information, or other information that
3829 the guest doesn't want you to trash. You also risk leaking
3830 information about the host to the guest this way. Instead,
3831 attach a new host device to the guest and swap on that.");
3833 ("swapoff_device", (RErr, [Device "device"], []), 171, [],
3834 [], (* XXX tested by swapon_device *)
3835 "disable swap on device",
3837 This command disables the libguestfs appliance swap
3838 device or partition named C<device>.
3839 See C<guestfs_swapon_device>.");
3841 ("swapon_file", (RErr, [Pathname "file"], []), 172, [],
3842 [InitBasicFS, Always, TestRun (
3843 [["fallocate"; "/swap"; "8388608"];
3844 ["mkswap_file"; "/swap"];
3845 ["swapon_file"; "/swap"];
3846 ["swapoff_file"; "/swap"]])],
3847 "enable swap on file",
3849 This command enables swap to a file.
3850 See C<guestfs_swapon_device> for other notes.");
3852 ("swapoff_file", (RErr, [Pathname "file"], []), 173, [],
3853 [], (* XXX tested by swapon_file *)
3854 "disable swap on file",
3856 This command disables the libguestfs appliance swap on file.");
3858 ("swapon_label", (RErr, [String "label"], []), 174, [],
3859 [InitEmpty, Always, TestRun (
3860 [["part_disk"; "/dev/sdb"; "mbr"];
3861 ["mkswap_L"; "swapit"; "/dev/sdb1"];
3862 ["swapon_label"; "swapit"];
3863 ["swapoff_label"; "swapit"];
3864 ["zero"; "/dev/sdb"];
3865 ["blockdev_rereadpt"; "/dev/sdb"]])],
3866 "enable swap on labeled swap partition",
3868 This command enables swap to a labeled swap partition.
3869 See C<guestfs_swapon_device> for other notes.");
3871 ("swapoff_label", (RErr, [String "label"], []), 175, [],
3872 [], (* XXX tested by swapon_label *)
3873 "disable swap on labeled swap partition",
3875 This command disables the libguestfs appliance swap on
3876 labeled swap partition.");
3878 ("swapon_uuid", (RErr, [String "uuid"], []), 176, [Optional "linuxfsuuid"],
3879 (let uuid = uuidgen () in
3880 [InitEmpty, Always, TestRun (
3881 [["mkswap_U"; uuid; "/dev/sdb"];
3882 ["swapon_uuid"; uuid];
3883 ["swapoff_uuid"; uuid]])]),
3884 "enable swap on swap partition by UUID",
3886 This command enables swap to a swap partition with the given UUID.
3887 See C<guestfs_swapon_device> for other notes.");
3889 ("swapoff_uuid", (RErr, [String "uuid"], []), 177, [Optional "linuxfsuuid"],
3890 [], (* XXX tested by swapon_uuid *)
3891 "disable swap on swap partition by UUID",
3893 This command disables the libguestfs appliance swap partition
3894 with the given UUID.");
3896 ("mkswap_file", (RErr, [Pathname "path"], []), 178, [],
3897 [InitBasicFS, Always, TestRun (
3898 [["fallocate"; "/swap"; "8388608"];
3899 ["mkswap_file"; "/swap"]])],
3900 "create a swap file",
3904 This command just writes a swap file signature to an existing
3905 file. To create the file itself, use something like C<guestfs_fallocate>.");
3907 ("inotify_init", (RErr, [Int "maxevents"], []), 179, [Optional "inotify"],
3908 [InitISOFS, Always, TestRun (
3909 [["inotify_init"; "0"]])],
3910 "create an inotify handle",
3912 This command creates a new inotify handle.
3913 The inotify subsystem can be used to notify events which happen to
3914 objects in the guest filesystem.
3916 C<maxevents> is the maximum number of events which will be
3917 queued up between calls to C<guestfs_inotify_read> or
3918 C<guestfs_inotify_files>.
3919 If this is passed as C<0>, then the kernel (or previously set)
3920 default is used. For Linux 2.6.29 the default was 16384 events.
3921 Beyond this limit, the kernel throws away events, but records
3922 the fact that it threw them away by setting a flag
3923 C<IN_Q_OVERFLOW> in the returned structure list (see
3924 C<guestfs_inotify_read>).
3926 Before any events are generated, you have to add some
3927 watches to the internal watch list. See:
3928 C<guestfs_inotify_add_watch>,
3929 C<guestfs_inotify_rm_watch> and
3930 C<guestfs_inotify_watch_all>.
3932 Queued up events should be read periodically by calling
3933 C<guestfs_inotify_read>
3934 (or C<guestfs_inotify_files> which is just a helpful
3935 wrapper around C<guestfs_inotify_read>). If you don't
3936 read the events out often enough then you risk the internal
3939 The handle should be closed after use by calling
3940 C<guestfs_inotify_close>. This also removes any
3941 watches automatically.
3943 See also L<inotify(7)> for an overview of the inotify interface
3944 as exposed by the Linux kernel, which is roughly what we expose
3945 via libguestfs. Note that there is one global inotify handle
3946 per libguestfs instance.");
3948 ("inotify_add_watch", (RInt64 "wd", [Pathname "path"; Int "mask"], []), 180, [Optional "inotify"],
3949 [InitBasicFS, Always, TestOutputList (
3950 [["inotify_init"; "0"];
3951 ["inotify_add_watch"; "/"; "1073741823"];
3954 ["inotify_files"]], ["a"; "b"])],
3955 "add an inotify watch",
3957 Watch C<path> for the events listed in C<mask>.
3959 Note that if C<path> is a directory then events within that
3960 directory are watched, but this does I<not> happen recursively
3961 (in subdirectories).
3963 Note for non-C or non-Linux callers: the inotify events are
3964 defined by the Linux kernel ABI and are listed in
3965 C</usr/include/sys/inotify.h>.");
3967 ("inotify_rm_watch", (RErr, [Int(*XXX64*) "wd"], []), 181, [Optional "inotify"],
3969 "remove an inotify watch",
3971 Remove a previously defined inotify watch.
3972 See C<guestfs_inotify_add_watch>.");
3974 ("inotify_read", (RStructList ("events", "inotify_event"), [], []), 182, [Optional "inotify"],
3976 "return list of inotify events",
3978 Return the complete queue of events that have happened
3979 since the previous read call.
3981 If no events have happened, this returns an empty list.
3983 I<Note>: In order to make sure that all events have been
3984 read, you must call this function repeatedly until it
3985 returns an empty list. The reason is that the call will
3986 read events up to the maximum appliance-to-host message
3987 size and leave remaining events in the queue.");
3989 ("inotify_files", (RStringList "paths", [], []), 183, [Optional "inotify"],
3991 "return list of watched files that had events",
3993 This function is a helpful wrapper around C<guestfs_inotify_read>
3994 which just returns a list of pathnames of objects that were
3995 touched. The returned pathnames are sorted and deduplicated.");
3997 ("inotify_close", (RErr, [], []), 184, [Optional "inotify"],
3999 "close the inotify handle",
4001 This closes the inotify handle which was previously
4002 opened by inotify_init. It removes all watches, throws
4003 away any pending events, and deallocates all resources.");
4005 ("setcon", (RErr, [String "context"], []), 185, [Optional "selinux"],
4007 "set SELinux security context",
4009 This sets the SELinux security context of the daemon
4010 to the string C<context>.
4012 See the documentation about SELINUX in L<guestfs(3)>.");
4014 ("getcon", (RString "context", [], []), 186, [Optional "selinux"],
4016 "get SELinux security context",
4018 This gets the SELinux security context of the daemon.
4020 See the documentation about SELINUX in L<guestfs(3)>,
4021 and C<guestfs_setcon>");
4023 ("mkfs_b", (RErr, [String "fstype"; Int "blocksize"; Device "device"], []), 187, [],
4024 [InitEmpty, Always, TestOutput (
4025 [["part_disk"; "/dev/sda"; "mbr"];
4026 ["mkfs_b"; "ext2"; "4096"; "/dev/sda1"];
4027 ["mount_options"; ""; "/dev/sda1"; "/"];
4028 ["write"; "/new"; "new file contents"];
4029 ["cat"; "/new"]], "new file contents");
4030 InitEmpty, Always, TestRun (
4031 [["part_disk"; "/dev/sda"; "mbr"];
4032 ["mkfs_b"; "vfat"; "32768"; "/dev/sda1"]]);
4033 InitEmpty, Always, TestLastFail (
4034 [["part_disk"; "/dev/sda"; "mbr"];
4035 ["mkfs_b"; "vfat"; "32769"; "/dev/sda1"]]);
4036 InitEmpty, Always, TestLastFail (
4037 [["part_disk"; "/dev/sda"; "mbr"];
4038 ["mkfs_b"; "vfat"; "33280"; "/dev/sda1"]]);
4039 InitEmpty, IfAvailable "ntfsprogs", TestRun (
4040 [["part_disk"; "/dev/sda"; "mbr"];
4041 ["mkfs_b"; "ntfs"; "32768"; "/dev/sda1"]])],
4042 "make a filesystem with block size",
4044 This call is similar to C<guestfs_mkfs>, but it allows you to
4045 control the block size of the resulting filesystem. Supported
4046 block sizes depend on the filesystem type, but typically they
4047 are C<1024>, C<2048> or C<4096> only.
4049 For VFAT and NTFS the C<blocksize> parameter is treated as
4050 the requested cluster size.");
4052 ("mke2journal", (RErr, [Int "blocksize"; Device "device"], []), 188, [],
4053 [InitEmpty, Always, TestOutput (
4054 [["part_init"; "/dev/sda"; "mbr"];
4055 ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
4056 ["part_add"; "/dev/sda"; "p"; "204800"; "-64"];
4057 ["mke2journal"; "4096"; "/dev/sda1"];
4058 ["mke2fs_J"; "ext2"; "4096"; "/dev/sda2"; "/dev/sda1"];
4059 ["mount_options"; ""; "/dev/sda2"; "/"];
4060 ["write"; "/new"; "new file contents"];
4061 ["cat"; "/new"]], "new file contents")],
4062 "make ext2/3/4 external journal",
4064 This creates an ext2 external journal on C<device>. It is equivalent
4067 mke2fs -O journal_dev -b blocksize device");
4069 ("mke2journal_L", (RErr, [Int "blocksize"; String "label"; Device "device"], []), 189, [],
4070 [InitEmpty, Always, TestOutput (
4071 [["part_init"; "/dev/sda"; "mbr"];
4072 ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
4073 ["part_add"; "/dev/sda"; "p"; "204800"; "-64"];
4074 ["mke2journal_L"; "4096"; "JOURNAL"; "/dev/sda1"];
4075 ["mke2fs_JL"; "ext2"; "4096"; "/dev/sda2"; "JOURNAL"];
4076 ["mount_options"; ""; "/dev/sda2"; "/"];
4077 ["write"; "/new"; "new file contents"];
4078 ["cat"; "/new"]], "new file contents")],
4079 "make ext2/3/4 external journal with label",
4081 This creates an ext2 external journal on C<device> with label C<label>.");
4083 ("mke2journal_U", (RErr, [Int "blocksize"; String "uuid"; Device "device"], []), 190, [Optional "linuxfsuuid"],
4084 (let uuid = uuidgen () in
4085 [InitEmpty, Always, TestOutput (
4086 [["part_init"; "/dev/sda"; "mbr"];
4087 ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
4088 ["part_add"; "/dev/sda"; "p"; "204800"; "-64"];
4089 ["mke2journal_U"; "4096"; uuid; "/dev/sda1"];
4090 ["mke2fs_JU"; "ext2"; "4096"; "/dev/sda2"; uuid];
4091 ["mount_options"; ""; "/dev/sda2"; "/"];
4092 ["write"; "/new"; "new file contents"];
4093 ["cat"; "/new"]], "new file contents")]),
4094 "make ext2/3/4 external journal with UUID",
4096 This creates an ext2 external journal on C<device> with UUID C<uuid>.");
4098 ("mke2fs_J", (RErr, [String "fstype"; Int "blocksize"; Device "device"; Device "journal"], []), 191, [],
4100 "make ext2/3/4 filesystem with external journal",
4102 This creates an ext2/3/4 filesystem on C<device> with
4103 an external journal on C<journal>. It is equivalent
4106 mke2fs -t fstype -b blocksize -J device=<journal> <device>
4108 See also C<guestfs_mke2journal>.");
4110 ("mke2fs_JL", (RErr, [String "fstype"; Int "blocksize"; Device "device"; String "label"], []), 192, [],
4112 "make ext2/3/4 filesystem with external journal",
4114 This creates an ext2/3/4 filesystem on C<device> with
4115 an external journal on the journal labeled C<label>.
4117 See also C<guestfs_mke2journal_L>.");
4119 ("mke2fs_JU", (RErr, [String "fstype"; Int "blocksize"; Device "device"; String "uuid"], []), 193, [Optional "linuxfsuuid"],
4121 "make ext2/3/4 filesystem with external journal",
4123 This creates an ext2/3/4 filesystem on C<device> with
4124 an external journal on the journal with UUID C<uuid>.
4126 See also C<guestfs_mke2journal_U>.");
4128 ("modprobe", (RErr, [String "modulename"], []), 194, [Optional "linuxmodules"],
4129 [InitNone, Always, TestRun [["modprobe"; "fat"]]],
4130 "load a kernel module",
4132 This loads a kernel module in the appliance.
4134 The kernel module must have been whitelisted when libguestfs
4135 was built (see C<appliance/kmod.whitelist.in> in the source).");
4137 ("echo_daemon", (RString "output", [StringList "words"], []), 195, [],
4138 [InitNone, Always, TestOutput (
4139 [["echo_daemon"; "This is a test"]], "This is a test"
4141 "echo arguments back to the client",
4143 This command concatenates the list of C<words> passed with single spaces
4144 between them and returns the resulting string.
4146 You can use this command to test the connection through to the daemon.
4148 See also C<guestfs_ping_daemon>.");
4150 ("find0", (RErr, [Pathname "directory"; FileOut "files"], []), 196, [],
4151 [], (* There is a regression test for this. *)
4152 "find all files and directories, returning NUL-separated list",
4154 This command lists out all files and directories, recursively,
4155 starting at C<directory>, placing the resulting list in the
4156 external file called C<files>.
4158 This command works the same way as C<guestfs_find> with the
4159 following exceptions:
4165 The resulting list is written to an external file.
4169 Items (filenames) in the result are separated
4170 by C<\\0> characters. See L<find(1)> option I<-print0>.
4174 This command is not limited in the number of names that it
4179 The result list is not sorted.
4183 ("case_sensitive_path", (RString "rpath", [Pathname "path"], []), 197, [],
4184 [InitISOFS, Always, TestOutput (
4185 [["case_sensitive_path"; "/DIRECTORY"]], "/directory");
4186 InitISOFS, Always, TestOutput (
4187 [["case_sensitive_path"; "/DIRECTORY/"]], "/directory");
4188 InitISOFS, Always, TestOutput (
4189 [["case_sensitive_path"; "/Known-1"]], "/known-1");
4190 InitISOFS, Always, TestLastFail (
4191 [["case_sensitive_path"; "/Known-1/"]]);
4192 InitBasicFS, Always, TestOutput (
4194 ["mkdir"; "/a/bbb"];
4195 ["touch"; "/a/bbb/c"];
4196 ["case_sensitive_path"; "/A/bbB/C"]], "/a/bbb/c");
4197 InitBasicFS, Always, TestOutput (
4199 ["mkdir"; "/a/bbb"];
4200 ["touch"; "/a/bbb/c"];
4201 ["case_sensitive_path"; "/A////bbB/C"]], "/a/bbb/c");
4202 InitBasicFS, Always, TestLastFail (
4204 ["mkdir"; "/a/bbb"];
4205 ["touch"; "/a/bbb/c"];
4206 ["case_sensitive_path"; "/A/bbb/../bbb/C"]])],
4207 "return true path on case-insensitive filesystem",
4209 This can be used to resolve case insensitive paths on
4210 a filesystem which is case sensitive. The use case is
4211 to resolve paths which you have read from Windows configuration
4212 files or the Windows Registry, to the true path.
4214 The command handles a peculiarity of the Linux ntfs-3g
4215 filesystem driver (and probably others), which is that although
4216 the underlying filesystem is case-insensitive, the driver
4217 exports the filesystem to Linux as case-sensitive.
4219 One consequence of this is that special directories such
4220 as C<c:\\windows> may appear as C</WINDOWS> or C</windows>
4221 (or other things) depending on the precise details of how
4222 they were created. In Windows itself this would not be
4225 Bug or feature? You decide:
4226 L<http://www.tuxera.com/community/ntfs-3g-faq/#posixfilenames1>
4228 This function resolves the true case of each element in the
4229 path and returns the case-sensitive path.
4231 Thus C<guestfs_case_sensitive_path> (\"/Windows/System32\")
4232 might return C<\"/WINDOWS/system32\"> (the exact return value
4233 would depend on details of how the directories were originally
4234 created under Windows).
4237 This function does not handle drive names, backslashes etc.
4239 See also C<guestfs_realpath>.");
4241 ("vfs_type", (RString "fstype", [Device "device"], []), 198, [],
4242 [InitBasicFS, Always, TestOutput (
4243 [["vfs_type"; "/dev/sda1"]], "ext2")],
4244 "get the Linux VFS type corresponding to a mounted device",
4246 This command gets the filesystem type corresponding to
4247 the filesystem on C<device>.
4249 For most filesystems, the result is the name of the Linux
4250 VFS module which would be used to mount this filesystem
4251 if you mounted it without specifying the filesystem type.
4252 For example a string such as C<ext3> or C<ntfs>.");
4254 ("truncate", (RErr, [Pathname "path"], []), 199, [],
4255 [InitBasicFS, Always, TestOutputStruct (
4256 [["write"; "/test"; "some stuff so size is not zero"];
4257 ["truncate"; "/test"];
4258 ["stat"; "/test"]], [CompareWithInt ("size", 0)])],
4259 "truncate a file to zero size",
4261 This command truncates C<path> to a zero-length file. The
4262 file must exist already.");
4264 ("truncate_size", (RErr, [Pathname "path"; Int64 "size"], []), 200, [],
4265 [InitBasicFS, Always, TestOutputStruct (
4266 [["touch"; "/test"];
4267 ["truncate_size"; "/test"; "1000"];
4268 ["stat"; "/test"]], [CompareWithInt ("size", 1000)])],
4269 "truncate a file to a particular size",
4271 This command truncates C<path> to size C<size> bytes. The file
4274 If the current file size is less than C<size> then
4275 the file is extended to the required size with zero bytes.
4276 This creates a sparse file (ie. disk blocks are not allocated
4277 for the file until you write to it). To create a non-sparse
4278 file of zeroes, use C<guestfs_fallocate64> instead.");
4280 ("utimens", (RErr, [Pathname "path"; Int64 "atsecs"; Int64 "atnsecs"; Int64 "mtsecs"; Int64 "mtnsecs"], []), 201, [],
4281 [InitBasicFS, Always, TestOutputStruct (
4282 [["touch"; "/test"];
4283 ["utimens"; "/test"; "12345"; "67890"; "9876"; "5432"];
4284 ["stat"; "/test"]], [CompareWithInt ("mtime", 9876)])],
4285 "set timestamp of a file with nanosecond precision",
4287 This command sets the timestamps of a file with nanosecond
4290 C<atsecs, atnsecs> are the last access time (atime) in secs and
4291 nanoseconds from the epoch.
4293 C<mtsecs, mtnsecs> are the last modification time (mtime) in
4294 secs and nanoseconds from the epoch.
4296 If the C<*nsecs> field contains the special value C<-1> then
4297 the corresponding timestamp is set to the current time. (The
4298 C<*secs> field is ignored in this case).
4300 If the C<*nsecs> field contains the special value C<-2> then
4301 the corresponding timestamp is left unchanged. (The
4302 C<*secs> field is ignored in this case).");
4304 ("mkdir_mode", (RErr, [Pathname "path"; Int "mode"], []), 202, [],
4305 [InitBasicFS, Always, TestOutputStruct (
4306 [["mkdir_mode"; "/test"; "0o111"];
4307 ["stat"; "/test"]], [CompareWithInt ("mode", 0o40111)])],
4308 "create a directory with a particular mode",
4310 This command creates a directory, setting the initial permissions
4311 of the directory to C<mode>.
4313 For common Linux filesystems, the actual mode which is set will
4314 be C<mode & ~umask & 01777>. Non-native-Linux filesystems may
4315 interpret the mode in other ways.
4317 See also C<guestfs_mkdir>, C<guestfs_umask>");
4319 ("lchown", (RErr, [Int "owner"; Int "group"; Pathname "path"], []), 203, [],
4321 "change file owner and group",
4323 Change the file owner to C<owner> and group to C<group>.
4324 This is like C<guestfs_chown> but if C<path> is a symlink then
4325 the link itself is changed, not the target.
4327 Only numeric uid and gid are supported. If you want to use
4328 names, you will need to locate and parse the password file
4329 yourself (Augeas support makes this relatively easy).");
4331 ("lstatlist", (RStructList ("statbufs", "stat"), [Pathname "path"; StringList "names"], []), 204, [],
4333 "lstat on multiple files",
4335 This call allows you to perform the C<guestfs_lstat> operation
4336 on multiple files, where all files are in the directory C<path>.
4337 C<names> is the list of files from this directory.
4339 On return you get a list of stat structs, with a one-to-one
4340 correspondence to the C<names> list. If any name did not exist
4341 or could not be lstat'd, then the C<ino> field of that structure
4344 This call is intended for programs that want to efficiently
4345 list a directory contents without making many round-trips.
4346 See also C<guestfs_lxattrlist> for a similarly efficient call
4347 for getting extended attributes. Very long directory listings
4348 might cause the protocol message size to be exceeded, causing
4349 this call to fail. The caller must split up such requests
4350 into smaller groups of names.");
4352 ("lxattrlist", (RStructList ("xattrs", "xattr"), [Pathname "path"; StringList "names"], []), 205, [Optional "linuxxattrs"],
4354 "lgetxattr on multiple files",
4356 This call allows you to get the extended attributes
4357 of multiple files, where all files are in the directory C<path>.
4358 C<names> is the list of files from this directory.
4360 On return you get a flat list of xattr structs which must be
4361 interpreted sequentially. The first xattr struct always has a zero-length
4362 C<attrname>. C<attrval> in this struct is zero-length
4363 to indicate there was an error doing C<lgetxattr> for this
4364 file, I<or> is a C string which is a decimal number
4365 (the number of following attributes for this file, which could
4366 be C<\"0\">). Then after the first xattr struct are the
4367 zero or more attributes for the first named file.
4368 This repeats for the second and subsequent files.
4370 This call is intended for programs that want to efficiently
4371 list a directory contents without making many round-trips.
4372 See also C<guestfs_lstatlist> for a similarly efficient call
4373 for getting standard stats. Very long directory listings
4374 might cause the protocol message size to be exceeded, causing
4375 this call to fail. The caller must split up such requests
4376 into smaller groups of names.");
4378 ("readlinklist", (RStringList "links", [Pathname "path"; StringList "names"], []), 206, [],
4380 "readlink on multiple files",
4382 This call allows you to do a C<readlink> operation
4383 on multiple files, where all files are in the directory C<path>.
4384 C<names> is the list of files from this directory.
4386 On return you get a list of strings, with a one-to-one
4387 correspondence to the C<names> list. Each string is the
4388 value of the symbolic link.
4390 If the C<readlink(2)> operation fails on any name, then
4391 the corresponding result string is the empty string C<\"\">.
4392 However the whole operation is completed even if there
4393 were C<readlink(2)> errors, and so you can call this
4394 function with names where you don't know if they are
4395 symbolic links already (albeit slightly less efficient).
4397 This call is intended for programs that want to efficiently
4398 list a directory contents without making many round-trips.
4399 Very long directory listings might cause the protocol
4400 message size to be exceeded, causing
4401 this call to fail. The caller must split up such requests
4402 into smaller groups of names.");
4404 ("pread", (RBufferOut "content", [Pathname "path"; Int "count"; Int64 "offset"], []), 207, [ProtocolLimitWarning],
4405 [InitISOFS, Always, TestOutputBuffer (
4406 [["pread"; "/known-4"; "1"; "3"]], "\n");
4407 InitISOFS, Always, TestOutputBuffer (
4408 [["pread"; "/empty"; "0"; "100"]], "")],
4409 "read part of a file",
4411 This command lets you read part of a file. It reads C<count>
4412 bytes of the file, starting at C<offset>, from file C<path>.
4414 This may read fewer bytes than requested. For further details
4415 see the L<pread(2)> system call.
4417 See also C<guestfs_pwrite>, C<guestfs_pread_device>.");
4419 ("part_init", (RErr, [Device "device"; String "parttype"], []), 208, [],
4420 [InitEmpty, Always, TestRun (
4421 [["part_init"; "/dev/sda"; "gpt"]])],
4422 "create an empty partition table",
4424 This creates an empty partition table on C<device> of one of the
4425 partition types listed below. Usually C<parttype> should be
4426 either C<msdos> or C<gpt> (for large disks).
4428 Initially there are no partitions. Following this, you should
4429 call C<guestfs_part_add> for each partition required.
4431 Possible values for C<parttype> are:
4435 =item B<efi> | B<gpt>
4437 Intel EFI / GPT partition table.
4439 This is recommended for >= 2 TB partitions that will be accessed
4440 from Linux and Intel-based Mac OS X. It also has limited backwards
4441 compatibility with the C<mbr> format.
4443 =item B<mbr> | B<msdos>
4445 The standard PC \"Master Boot Record\" (MBR) format used
4446 by MS-DOS and Windows. This partition type will B<only> work
4447 for device sizes up to 2 TB. For large disks we recommend
4452 Other partition table types that may work but are not
4461 =item B<amiga> | B<rdb>
4463 Amiga \"Rigid Disk Block\" format.
4471 DASD, used on IBM mainframes.
4479 Old Mac partition format. Modern Macs use C<gpt>.
4483 NEC PC-98 format, common in Japan apparently.
4491 ("part_add", (RErr, [Device "device"; String "prlogex"; Int64 "startsect"; Int64 "endsect"], []), 209, [],
4492 [InitEmpty, Always, TestRun (
4493 [["part_init"; "/dev/sda"; "mbr"];
4494 ["part_add"; "/dev/sda"; "primary"; "1"; "-1"]]);
4495 InitEmpty, Always, TestRun (
4496 [["part_init"; "/dev/sda"; "gpt"];
4497 ["part_add"; "/dev/sda"; "primary"; "34"; "127"];
4498 ["part_add"; "/dev/sda"; "primary"; "128"; "-34"]]);
4499 InitEmpty, Always, TestRun (
4500 [["part_init"; "/dev/sda"; "mbr"];
4501 ["part_add"; "/dev/sda"; "primary"; "32"; "127"];
4502 ["part_add"; "/dev/sda"; "primary"; "128"; "255"];
4503 ["part_add"; "/dev/sda"; "primary"; "256"; "511"];
4504 ["part_add"; "/dev/sda"; "primary"; "512"; "-1"]])],
4505 "add a partition to the device",
4507 This command adds a partition to C<device>. If there is no partition
4508 table on the device, call C<guestfs_part_init> first.
4510 The C<prlogex> parameter is the type of partition. Normally you
4511 should pass C<p> or C<primary> here, but MBR partition tables also
4512 support C<l> (or C<logical>) and C<e> (or C<extended>) partition
4515 C<startsect> and C<endsect> are the start and end of the partition
4516 in I<sectors>. C<endsect> may be negative, which means it counts
4517 backwards from the end of the disk (C<-1> is the last sector).
4519 Creating a partition which covers the whole disk is not so easy.
4520 Use C<guestfs_part_disk> to do that.");
4522 ("part_disk", (RErr, [Device "device"; String "parttype"], []), 210, [DangerWillRobinson],
4523 [InitEmpty, Always, TestRun (
4524 [["part_disk"; "/dev/sda"; "mbr"]]);
4525 InitEmpty, Always, TestRun (
4526 [["part_disk"; "/dev/sda"; "gpt"]])],
4527 "partition whole disk with a single primary partition",
4529 This command is simply a combination of C<guestfs_part_init>
4530 followed by C<guestfs_part_add> to create a single primary partition
4531 covering the whole disk.
4533 C<parttype> is the partition table type, usually C<mbr> or C<gpt>,
4534 but other possible values are described in C<guestfs_part_init>.");
4536 ("part_set_bootable", (RErr, [Device "device"; Int "partnum"; Bool "bootable"], []), 211, [],
4537 [InitEmpty, Always, TestRun (
4538 [["part_disk"; "/dev/sda"; "mbr"];
4539 ["part_set_bootable"; "/dev/sda"; "1"; "true"]])],
4540 "make a partition bootable",
4542 This sets the bootable flag on partition numbered C<partnum> on
4543 device C<device>. Note that partitions are numbered from 1.
4545 The bootable flag is used by some operating systems (notably
4546 Windows) to determine which partition to boot from. It is by
4547 no means universally recognized.");
4549 ("part_set_name", (RErr, [Device "device"; Int "partnum"; String "name"], []), 212, [],
4550 [InitEmpty, Always, TestRun (
4551 [["part_disk"; "/dev/sda"; "gpt"];
4552 ["part_set_name"; "/dev/sda"; "1"; "thepartname"]])],
4553 "set partition name",
4555 This sets the partition name on partition numbered C<partnum> on
4556 device C<device>. Note that partitions are numbered from 1.
4558 The partition name can only be set on certain types of partition
4559 table. This works on C<gpt> but not on C<mbr> partitions.");
4561 ("part_list", (RStructList ("partitions", "partition"), [Device "device"], []), 213, [],
4562 [], (* XXX Add a regression test for this. *)
4563 "list partitions on a device",
4565 This command parses the partition table on C<device> and
4566 returns the list of partitions found.
4568 The fields in the returned structure are:
4574 Partition number, counting from 1.
4578 Start of the partition I<in bytes>. To get sectors you have to
4579 divide by the device's sector size, see C<guestfs_blockdev_getss>.
4583 End of the partition in bytes.
4587 Size of the partition in bytes.
4591 ("part_get_parttype", (RString "parttype", [Device "device"], []), 214, [],
4592 [InitEmpty, Always, TestOutput (
4593 [["part_disk"; "/dev/sda"; "gpt"];
4594 ["part_get_parttype"; "/dev/sda"]], "gpt")],
4595 "get the partition table type",
4597 This command examines the partition table on C<device> and
4598 returns the partition table type (format) being used.
4600 Common return values include: C<msdos> (a DOS/Windows style MBR
4601 partition table), C<gpt> (a GPT/EFI-style partition table). Other
4602 values are possible, although unusual. See C<guestfs_part_init>
4605 ("fill", (RErr, [Int "c"; Int "len"; Pathname "path"], []), 215, [Progress],
4606 [InitBasicFS, Always, TestOutputBuffer (
4607 [["fill"; "0x63"; "10"; "/test"];
4608 ["read_file"; "/test"]], "cccccccccc")],
4609 "fill a file with octets",
4611 This command creates a new file called C<path>. The initial
4612 content of the file is C<len> octets of C<c>, where C<c>
4613 must be a number in the range C<[0..255]>.
4615 To fill a file with zero bytes (sparsely), it is
4616 much more efficient to use C<guestfs_truncate_size>.
4617 To create a file with a pattern of repeating bytes
4618 use C<guestfs_fill_pattern>.");
4620 ("available", (RErr, [StringList "groups"], []), 216, [],
4621 [InitNone, Always, TestRun [["available"; ""]]],
4622 "test availability of some parts of the API",
4624 This command is used to check the availability of some
4625 groups of functionality in the appliance, which not all builds of
4626 the libguestfs appliance will be able to provide.
4628 The libguestfs groups, and the functions that those
4629 groups correspond to, are listed in L<guestfs(3)/AVAILABILITY>.
4630 You can also fetch this list at runtime by calling
4631 C<guestfs_available_all_groups>.
4633 The argument C<groups> is a list of group names, eg:
4634 C<[\"inotify\", \"augeas\"]> would check for the availability of
4635 the Linux inotify functions and Augeas (configuration file
4638 The command returns no error if I<all> requested groups are available.
4640 It fails with an error if one or more of the requested
4641 groups is unavailable in the appliance.
4643 If an unknown group name is included in the
4644 list of groups then an error is always returned.
4652 You must call C<guestfs_launch> before calling this function.
4654 The reason is because we don't know what groups are
4655 supported by the appliance/daemon until it is running and can
4660 If a group of functions is available, this does not necessarily
4661 mean that they will work. You still have to check for errors
4662 when calling individual API functions even if they are
4667 It is usually the job of distro packagers to build
4668 complete functionality into the libguestfs appliance.
4669 Upstream libguestfs, if built from source with all
4670 requirements satisfied, will support everything.
4674 This call was added in version C<1.0.80>. In previous
4675 versions of libguestfs all you could do would be to speculatively
4676 execute a command to find out if the daemon implemented it.
4677 See also C<guestfs_version>.
4681 ("dd", (RErr, [Dev_or_Path "src"; Dev_or_Path "dest"], []), 217, [],
4682 [InitBasicFS, Always, TestOutputBuffer (
4683 [["write"; "/src"; "hello, world"];
4684 ["dd"; "/src"; "/dest"];
4685 ["read_file"; "/dest"]], "hello, world")],
4686 "copy from source to destination using dd",
4688 This command copies from one source device or file C<src>
4689 to another destination device or file C<dest>. Normally you
4690 would use this to copy to or from a device or partition, for
4691 example to duplicate a filesystem.
4693 If the destination is a device, it must be as large or larger
4694 than the source file or device, otherwise the copy will fail.
4695 This command cannot do partial copies (see C<guestfs_copy_size>).");
4697 ("filesize", (RInt64 "size", [Pathname "file"], []), 218, [],
4698 [InitBasicFS, Always, TestOutputInt (
4699 [["write"; "/file"; "hello, world"];
4700 ["filesize"; "/file"]], 12)],
4701 "return the size of the file in bytes",
4703 This command returns the size of C<file> in bytes.
4705 To get other stats about a file, use C<guestfs_stat>, C<guestfs_lstat>,
4706 C<guestfs_is_dir>, C<guestfs_is_file> etc.
4707 To get the size of block devices, use C<guestfs_blockdev_getsize64>.");
4709 ("lvrename", (RErr, [String "logvol"; String "newlogvol"], []), 219, [],
4710 [InitBasicFSonLVM, Always, TestOutputList (
4711 [["lvrename"; "/dev/VG/LV"; "/dev/VG/LV2"];
4712 ["lvs"]], ["/dev/VG/LV2"])],
4713 "rename an LVM logical volume",
4715 Rename a logical volume C<logvol> with the new name C<newlogvol>.");
4717 ("vgrename", (RErr, [String "volgroup"; String "newvolgroup"], []), 220, [],
4718 [InitBasicFSonLVM, Always, TestOutputList (
4720 ["vg_activate"; "false"; "VG"];
4721 ["vgrename"; "VG"; "VG2"];
4722 ["vg_activate"; "true"; "VG2"];
4723 ["mount_options"; ""; "/dev/VG2/LV"; "/"];
4724 ["vgs"]], ["VG2"])],
4725 "rename an LVM volume group",
4727 Rename a volume group C<volgroup> with the new name C<newvolgroup>.");
4729 ("initrd_cat", (RBufferOut "content", [Pathname "initrdpath"; String "filename"], []), 221, [ProtocolLimitWarning],
4730 [InitISOFS, Always, TestOutputBuffer (
4731 [["initrd_cat"; "/initrd"; "known-4"]], "abc\ndef\nghi")],
4732 "list the contents of a single file in an initrd",
4734 This command unpacks the file C<filename> from the initrd file
4735 called C<initrdpath>. The filename must be given I<without> the
4736 initial C</> character.
4738 For example, in guestfish you could use the following command
4739 to examine the boot script (usually called C</init>)
4740 contained in a Linux initrd or initramfs image:
4742 initrd-cat /boot/initrd-<version>.img init
4744 See also C<guestfs_initrd_list>.");
4746 ("pvuuid", (RString "uuid", [Device "device"], []), 222, [],
4748 "get the UUID of a physical volume",
4750 This command returns the UUID of the LVM PV C<device>.");
4752 ("vguuid", (RString "uuid", [String "vgname"], []), 223, [],
4754 "get the UUID of a volume group",
4756 This command returns the UUID of the LVM VG named C<vgname>.");
4758 ("lvuuid", (RString "uuid", [Device "device"], []), 224, [],
4760 "get the UUID of a logical volume",
4762 This command returns the UUID of the LVM LV C<device>.");
4764 ("vgpvuuids", (RStringList "uuids", [String "vgname"], []), 225, [],
4766 "get the PV UUIDs containing the volume group",
4768 Given a VG called C<vgname>, this returns the UUIDs of all
4769 the physical volumes that this volume group resides on.
4771 You can use this along with C<guestfs_pvs> and C<guestfs_pvuuid>
4772 calls to associate physical volumes and volume groups.
4774 See also C<guestfs_vglvuuids>.");
4776 ("vglvuuids", (RStringList "uuids", [String "vgname"], []), 226, [],
4778 "get the LV UUIDs of all LVs in the volume group",
4780 Given a VG called C<vgname>, this returns the UUIDs of all
4781 the logical volumes created in this volume group.
4783 You can use this along with C<guestfs_lvs> and C<guestfs_lvuuid>
4784 calls to associate logical volumes and volume groups.
4786 See also C<guestfs_vgpvuuids>.");
4788 ("copy_size", (RErr, [Dev_or_Path "src"; Dev_or_Path "dest"; Int64 "size"], []), 227, [Progress],
4789 [InitBasicFS, Always, TestOutputBuffer (
4790 [["write"; "/src"; "hello, world"];
4791 ["copy_size"; "/src"; "/dest"; "5"];
4792 ["read_file"; "/dest"]], "hello")],
4793 "copy size bytes from source to destination using dd",
4795 This command copies exactly C<size> bytes from one source device
4796 or file C<src> to another destination device or file C<dest>.
4798 Note this will fail if the source is too short or if the destination
4799 is not large enough.");
4801 ("zero_device", (RErr, [Device "device"], []), 228, [DangerWillRobinson; Progress],
4802 [InitBasicFSonLVM, Always, TestRun (
4803 [["zero_device"; "/dev/VG/LV"]])],
4804 "write zeroes to an entire device",
4806 This command writes zeroes over the entire C<device>. Compare
4807 with C<guestfs_zero> which just zeroes the first few blocks of
4810 ("txz_in", (RErr, [FileIn "tarball"; Pathname "directory"], []), 229, [Optional "xz"],
4811 [InitBasicFS, Always, TestOutput (
4812 [["txz_in"; "../images/helloworld.tar.xz"; "/"];
4813 ["cat"; "/hello"]], "hello\n")],
4814 "unpack compressed tarball to directory",
4816 This command uploads and unpacks local file C<tarball> (an
4817 I<xz compressed> tar file) into C<directory>.");
4819 ("txz_out", (RErr, [Pathname "directory"; FileOut "tarball"], []), 230, [Optional "xz"],
4821 "pack directory into compressed tarball",
4823 This command packs the contents of C<directory> and downloads
4824 it to local file C<tarball> (as an xz compressed tar archive).");
4826 ("ntfsresize", (RErr, [Device "device"], []), 231, [Optional "ntfsprogs"],
4828 "resize an NTFS filesystem",
4830 This command resizes an NTFS filesystem, expanding or
4831 shrinking it to the size of the underlying device.
4832 See also L<ntfsresize(8)>.");
4834 ("vgscan", (RErr, [], []), 232, [],
4835 [InitEmpty, Always, TestRun (
4837 "rescan for LVM physical volumes, volume groups and logical volumes",
4839 This rescans all block devices and rebuilds the list of LVM
4840 physical volumes, volume groups and logical volumes.");
4842 ("part_del", (RErr, [Device "device"; Int "partnum"], []), 233, [],
4843 [InitEmpty, Always, TestRun (
4844 [["part_init"; "/dev/sda"; "mbr"];
4845 ["part_add"; "/dev/sda"; "primary"; "1"; "-1"];
4846 ["part_del"; "/dev/sda"; "1"]])],
4847 "delete a partition",
4849 This command deletes the partition numbered C<partnum> on C<device>.
4851 Note that in the case of MBR partitioning, deleting an
4852 extended partition also deletes any logical partitions
4855 ("part_get_bootable", (RBool "bootable", [Device "device"; Int "partnum"], []), 234, [],
4856 [InitEmpty, Always, TestOutputTrue (
4857 [["part_init"; "/dev/sda"; "mbr"];
4858 ["part_add"; "/dev/sda"; "primary"; "1"; "-1"];
4859 ["part_set_bootable"; "/dev/sda"; "1"; "true"];
4860 ["part_get_bootable"; "/dev/sda"; "1"]])],
4861 "return true if a partition is bootable",
4863 This command returns true if the partition C<partnum> on
4864 C<device> has the bootable flag set.
4866 See also C<guestfs_part_set_bootable>.");
4868 ("part_get_mbr_id", (RInt "idbyte", [Device "device"; Int "partnum"], []), 235, [FishOutput FishOutputHexadecimal],
4869 [InitEmpty, Always, TestOutputInt (
4870 [["part_init"; "/dev/sda"; "mbr"];
4871 ["part_add"; "/dev/sda"; "primary"; "1"; "-1"];
4872 ["part_set_mbr_id"; "/dev/sda"; "1"; "0x7f"];
4873 ["part_get_mbr_id"; "/dev/sda"; "1"]], 0x7f)],
4874 "get the MBR type byte (ID byte) from a partition",
4876 Returns the MBR type byte (also known as the ID byte) from
4877 the numbered partition C<partnum>.
4879 Note that only MBR (old DOS-style) partitions have type bytes.
4880 You will get undefined results for other partition table
4881 types (see C<guestfs_part_get_parttype>).");
4883 ("part_set_mbr_id", (RErr, [Device "device"; Int "partnum"; Int "idbyte"], []), 236, [],
4884 [], (* tested by part_get_mbr_id *)
4885 "set the MBR type byte (ID byte) of a partition",
4887 Sets the MBR type byte (also known as the ID byte) of
4888 the numbered partition C<partnum> to C<idbyte>. Note
4889 that the type bytes quoted in most documentation are
4890 in fact hexadecimal numbers, but usually documented
4891 without any leading \"0x\" which might be confusing.
4893 Note that only MBR (old DOS-style) partitions have type bytes.
4894 You will get undefined results for other partition table
4895 types (see C<guestfs_part_get_parttype>).");
4897 ("checksum_device", (RString "checksum", [String "csumtype"; Device "device"], []), 237, [],
4898 [InitISOFS, Always, TestOutputFileMD5 (
4899 [["checksum_device"; "md5"; "/dev/sdd"]],
4900 "../images/test.iso")],
4901 "compute MD5, SHAx or CRC checksum of the contents of a device",
4903 This call computes the MD5, SHAx or CRC checksum of the
4904 contents of the device named C<device>. For the types of
4905 checksums supported see the C<guestfs_checksum> command.");
4907 ("lvresize_free", (RErr, [Device "lv"; Int "percent"], []), 238, [Optional "lvm2"],
4908 [InitNone, Always, TestRun (
4909 [["part_disk"; "/dev/sda"; "mbr"];
4910 ["pvcreate"; "/dev/sda1"];
4911 ["vgcreate"; "VG"; "/dev/sda1"];
4912 ["lvcreate"; "LV"; "VG"; "10"];
4913 ["lvresize_free"; "/dev/VG/LV"; "100"]])],
4914 "expand an LV to fill free space",
4916 This expands an existing logical volume C<lv> so that it fills
4917 C<pc>% of the remaining free space in the volume group. Commonly
4918 you would call this with pc = 100 which expands the logical volume
4919 as much as possible, using all remaining free space in the volume
4922 ("aug_clear", (RErr, [String "augpath"], []), 239, [Optional "augeas"],
4923 [], (* XXX Augeas code needs tests. *)
4924 "clear Augeas path",
4926 Set the value associated with C<path> to C<NULL>. This
4927 is the same as the L<augtool(1)> C<clear> command.");
4929 ("get_umask", (RInt "mask", [], []), 240, [FishOutput FishOutputOctal],
4930 [InitEmpty, Always, TestOutputInt (
4931 [["get_umask"]], 0o22)],
4932 "get the current umask",
4934 Return the current umask. By default the umask is C<022>
4935 unless it has been set by calling C<guestfs_umask>.");
4937 ("debug_upload", (RErr, [FileIn "filename"; String "tmpname"; Int "mode"], []), 241, [NotInDocs],
4939 "upload a file to the appliance (internal use only)",
4941 The C<guestfs_debug_upload> command uploads a file to
4942 the libguestfs appliance.
4944 There is no comprehensive help for this command. You have
4945 to look at the file C<daemon/debug.c> in the libguestfs source
4946 to find out what it is for.");
4948 ("base64_in", (RErr, [FileIn "base64file"; Pathname "filename"], []), 242, [],
4949 [InitBasicFS, Always, TestOutput (
4950 [["base64_in"; "../images/hello.b64"; "/hello"];
4951 ["cat"; "/hello"]], "hello\n")],
4952 "upload base64-encoded data to file",
4954 This command uploads base64-encoded data from C<base64file>
4957 ("base64_out", (RErr, [Pathname "filename"; FileOut "base64file"], []), 243, [],
4959 "download file and encode as base64",
4961 This command downloads the contents of C<filename>, writing
4962 it out to local file C<base64file> encoded as base64.");
4964 ("checksums_out", (RErr, [String "csumtype"; Pathname "directory"; FileOut "sumsfile"], []), 244, [],
4966 "compute MD5, SHAx or CRC checksum of files in a directory",
4968 This command computes the checksums of all regular files in
4969 C<directory> and then emits a list of those checksums to
4970 the local output file C<sumsfile>.
4972 This can be used for verifying the integrity of a virtual
4973 machine. However to be properly secure you should pay
4974 attention to the output of the checksum command (it uses
4975 the ones from GNU coreutils). In particular when the
4976 filename is not printable, coreutils uses a special
4977 backslash syntax. For more information, see the GNU
4978 coreutils info file.");
4980 ("fill_pattern", (RErr, [String "pattern"; Int "len"; Pathname "path"], []), 245, [Progress],
4981 [InitBasicFS, Always, TestOutputBuffer (
4982 [["fill_pattern"; "abcdefghijklmnopqrstuvwxyz"; "28"; "/test"];
4983 ["read_file"; "/test"]], "abcdefghijklmnopqrstuvwxyzab")],
4984 "fill a file with a repeating pattern of bytes",
4986 This function is like C<guestfs_fill> except that it creates
4987 a new file of length C<len> containing the repeating pattern
4988 of bytes in C<pattern>. The pattern is truncated if necessary
4989 to ensure the length of the file is exactly C<len> bytes.");
4991 ("write", (RErr, [Pathname "path"; BufferIn "content"], []), 246, [ProtocolLimitWarning],
4992 [InitBasicFS, Always, TestOutput (
4993 [["write"; "/new"; "new file contents"];
4994 ["cat"; "/new"]], "new file contents");
4995 InitBasicFS, Always, TestOutput (
4996 [["write"; "/new"; "\nnew file contents\n"];
4997 ["cat"; "/new"]], "\nnew file contents\n");
4998 InitBasicFS, Always, TestOutput (
4999 [["write"; "/new"; "\n\n"];
5000 ["cat"; "/new"]], "\n\n");
5001 InitBasicFS, Always, TestOutput (
5002 [["write"; "/new"; ""];
5003 ["cat"; "/new"]], "");
5004 InitBasicFS, Always, TestOutput (
5005 [["write"; "/new"; "\n\n\n"];
5006 ["cat"; "/new"]], "\n\n\n");
5007 InitBasicFS, Always, TestOutput (
5008 [["write"; "/new"; "\n"];
5009 ["cat"; "/new"]], "\n")],
5010 "create a new file",
5012 This call creates a file called C<path>. The content of the
5013 file is the string C<content> (which can contain any 8 bit data).");
5015 ("pwrite", (RInt "nbytes", [Pathname "path"; BufferIn "content"; Int64 "offset"], []), 247, [ProtocolLimitWarning],
5016 [InitBasicFS, Always, TestOutput (
5017 [["write"; "/new"; "new file contents"];
5018 ["pwrite"; "/new"; "data"; "4"];
5019 ["cat"; "/new"]], "new data contents");
5020 InitBasicFS, Always, TestOutput (
5021 [["write"; "/new"; "new file contents"];
5022 ["pwrite"; "/new"; "is extended"; "9"];
5023 ["cat"; "/new"]], "new file is extended");
5024 InitBasicFS, Always, TestOutput (
5025 [["write"; "/new"; "new file contents"];
5026 ["pwrite"; "/new"; ""; "4"];
5027 ["cat"; "/new"]], "new file contents")],
5028 "write to part of a file",
5030 This command writes to part of a file. It writes the data
5031 buffer C<content> to the file C<path> starting at offset C<offset>.
5033 This command implements the L<pwrite(2)> system call, and like
5034 that system call it may not write the full data requested. The
5035 return value is the number of bytes that were actually written
5036 to the file. This could even be 0, although short writes are
5037 unlikely for regular files in ordinary circumstances.
5039 See also C<guestfs_pread>, C<guestfs_pwrite_device>.");
5041 ("resize2fs_size", (RErr, [Device "device"; Int64 "size"], []), 248, [],
5043 "resize an ext2, ext3 or ext4 filesystem (with size)",
5045 This command is the same as C<guestfs_resize2fs> except that it
5046 allows you to specify the new size (in bytes) explicitly.");
5048 ("pvresize_size", (RErr, [Device "device"; Int64 "size"], []), 249, [Optional "lvm2"],
5050 "resize an LVM physical volume (with size)",
5052 This command is the same as C<guestfs_pvresize> except that it
5053 allows you to specify the new size (in bytes) explicitly.");
5055 ("ntfsresize_size", (RErr, [Device "device"; Int64 "size"], []), 250, [Optional "ntfsprogs"],
5057 "resize an NTFS filesystem (with size)",
5059 This command is the same as C<guestfs_ntfsresize> except that it
5060 allows you to specify the new size (in bytes) explicitly.");
5062 ("available_all_groups", (RStringList "groups", [], []), 251, [],
5063 [InitNone, Always, TestRun [["available_all_groups"]]],
5064 "return a list of all optional groups",
5066 This command returns a list of all optional groups that this
5067 daemon knows about. Note this returns both supported and unsupported
5068 groups. To find out which ones the daemon can actually support
5069 you have to call C<guestfs_available> on each member of the
5072 See also C<guestfs_available> and L<guestfs(3)/AVAILABILITY>.");
5074 ("fallocate64", (RErr, [Pathname "path"; Int64 "len"], []), 252, [],
5075 [InitBasicFS, Always, TestOutputStruct (
5076 [["fallocate64"; "/a"; "1000000"];
5077 ["stat"; "/a"]], [CompareWithInt ("size", 1_000_000)])],
5078 "preallocate a file in the guest filesystem",
5080 This command preallocates a file (containing zero bytes) named
5081 C<path> of size C<len> bytes. If the file exists already, it
5084 Note that this call allocates disk blocks for the file.
5085 To create a sparse file use C<guestfs_truncate_size> instead.
5087 The deprecated call C<guestfs_fallocate> does the same,
5088 but owing to an oversight it only allowed 30 bit lengths
5089 to be specified, effectively limiting the maximum size
5090 of files created through that call to 1GB.
5092 Do not confuse this with the guestfish-specific
5093 C<alloc> and C<sparse> commands which create
5094 a file in the host and attach it as a device.");
5096 ("vfs_label", (RString "label", [Device "device"], []), 253, [],
5097 [InitBasicFS, Always, TestOutput (
5098 [["set_e2label"; "/dev/sda1"; "LTEST"];
5099 ["vfs_label"; "/dev/sda1"]], "LTEST")],
5100 "get the filesystem label",
5102 This returns the filesystem label of the filesystem on
5105 If the filesystem is unlabeled, this returns the empty string.
5107 To find a filesystem from the label, use C<guestfs_findfs_label>.");
5109 ("vfs_uuid", (RString "uuid", [Device "device"], []), 254, [],
5110 (let uuid = uuidgen () in
5111 [InitBasicFS, Always, TestOutput (
5112 [["set_e2uuid"; "/dev/sda1"; uuid];
5113 ["vfs_uuid"; "/dev/sda1"]], uuid)]),
5114 "get the filesystem UUID",
5116 This returns the filesystem UUID of the filesystem on
5119 If the filesystem does not have a UUID, this returns the empty string.
5121 To find a filesystem from the UUID, use C<guestfs_findfs_uuid>.");
5123 ("lvm_set_filter", (RErr, [DeviceList "devices"], []), 255, [Optional "lvm2"],
5124 (* Can't be tested with the current framework because
5125 * the VG is being used by the mounted filesystem, so
5126 * the vgchange -an command we do first will fail.
5129 "set LVM device filter",
5131 This sets the LVM device filter so that LVM will only be
5132 able to \"see\" the block devices in the list C<devices>,
5133 and will ignore all other attached block devices.
5135 Where disk image(s) contain duplicate PVs or VGs, this
5136 command is useful to get LVM to ignore the duplicates, otherwise
5137 LVM can get confused. Note also there are two types
5138 of duplication possible: either cloned PVs/VGs which have
5139 identical UUIDs; or VGs that are not cloned but just happen
5140 to have the same name. In normal operation you cannot
5141 create this situation, but you can do it outside LVM, eg.
5142 by cloning disk images or by bit twiddling inside the LVM
5145 This command also clears the LVM cache and performs a volume
5148 You can filter whole block devices or individual partitions.
5150 You cannot use this if any VG is currently in use (eg.
5151 contains a mounted filesystem), even if you are not
5152 filtering out that VG.");
5154 ("lvm_clear_filter", (RErr, [], []), 256, [],
5155 [], (* see note on lvm_set_filter *)
5156 "clear LVM device filter",
5158 This undoes the effect of C<guestfs_lvm_set_filter>. LVM
5159 will be able to see every block device.
5161 This command also clears the LVM cache and performs a volume
5164 ("luks_open", (RErr, [Device "device"; Key "key"; String "mapname"], []), 257, [Optional "luks"],
5166 "open a LUKS-encrypted block device",
5168 This command opens a block device which has been encrypted
5169 according to the Linux Unified Key Setup (LUKS) standard.
5171 C<device> is the encrypted block device or partition.
5173 The caller must supply one of the keys associated with the
5174 LUKS block device, in the C<key> parameter.
5176 This creates a new block device called C</dev/mapper/mapname>.
5177 Reads and writes to this block device are decrypted from and
5178 encrypted to the underlying C<device> respectively.
5180 If this block device contains LVM volume groups, then
5181 calling C<guestfs_vgscan> followed by C<guestfs_vg_activate_all>
5182 will make them visible.");
5184 ("luks_open_ro", (RErr, [Device "device"; Key "key"; String "mapname"], []), 258, [Optional "luks"],
5186 "open a LUKS-encrypted block device read-only",
5188 This is the same as C<guestfs_luks_open> except that a read-only
5189 mapping is created.");
5191 ("luks_close", (RErr, [Device "device"], []), 259, [Optional "luks"],
5193 "close a LUKS device",
5195 This closes a LUKS device that was created earlier by
5196 C<guestfs_luks_open> or C<guestfs_luks_open_ro>. The
5197 C<device> parameter must be the name of the LUKS mapping
5198 device (ie. C</dev/mapper/mapname>) and I<not> the name
5199 of the underlying block device.");
5201 ("luks_format", (RErr, [Device "device"; Key "key"; Int "keyslot"], []), 260, [Optional "luks"; DangerWillRobinson],
5203 "format a block device as a LUKS encrypted device",
5205 This command erases existing data on C<device> and formats
5206 the device as a LUKS encrypted device. C<key> is the
5207 initial key, which is added to key slot C<slot>. (LUKS
5208 supports 8 key slots, numbered 0-7).");
5210 ("luks_format_cipher", (RErr, [Device "device"; Key "key"; Int "keyslot"; String "cipher"], []), 261, [Optional "luks"; DangerWillRobinson],
5212 "format a block device as a LUKS encrypted device",
5214 This command is the same as C<guestfs_luks_format> but
5215 it also allows you to set the C<cipher> used.");
5217 ("luks_add_key", (RErr, [Device "device"; Key "key"; Key "newkey"; Int "keyslot"], []), 262, [Optional "luks"],
5219 "add a key on a LUKS encrypted device",
5221 This command adds a new key on LUKS device C<device>.
5222 C<key> is any existing key, and is used to access the device.
5223 C<newkey> is the new key to add. C<keyslot> is the key slot
5224 that will be replaced.
5226 Note that if C<keyslot> already contains a key, then this
5227 command will fail. You have to use C<guestfs_luks_kill_slot>
5228 first to remove that key.");
5230 ("luks_kill_slot", (RErr, [Device "device"; Key "key"; Int "keyslot"], []), 263, [Optional "luks"],
5232 "remove a key from a LUKS encrypted device",
5234 This command deletes the key in key slot C<keyslot> from the
5235 encrypted LUKS device C<device>. C<key> must be one of the
5238 ("is_lv", (RBool "lvflag", [Device "device"], []), 264, [Optional "lvm2"],
5239 [InitBasicFSonLVM, IfAvailable "lvm2", TestOutputTrue (
5240 [["is_lv"; "/dev/VG/LV"]]);
5241 InitBasicFSonLVM, IfAvailable "lvm2", TestOutputFalse (
5242 [["is_lv"; "/dev/sda1"]])],
5243 "test if device is a logical volume",
5245 This command tests whether C<device> is a logical volume, and
5246 returns true iff this is the case.");
5248 ("findfs_uuid", (RString "device", [String "uuid"], []), 265, [],
5250 "find a filesystem by UUID",
5252 This command searches the filesystems and returns the one
5253 which has the given UUID. An error is returned if no such
5254 filesystem can be found.
5256 To find the UUID of a filesystem, use C<guestfs_vfs_uuid>.");
5258 ("findfs_label", (RString "device", [String "label"], []), 266, [],
5260 "find a filesystem by label",
5262 This command searches the filesystems and returns the one
5263 which has the given label. An error is returned if no such
5264 filesystem can be found.
5266 To find the label of a filesystem, use C<guestfs_vfs_label>.");
5268 ("is_chardev", (RBool "flag", [Pathname "path"], []), 267, [],
5269 [InitISOFS, Always, TestOutputFalse (
5270 [["is_chardev"; "/directory"]]);
5271 InitBasicFS, Always, TestOutputTrue (
5272 [["mknod_c"; "0o777"; "99"; "66"; "/test"];
5273 ["is_chardev"; "/test"]])],
5274 "test if character device",
5276 This returns C<true> if and only if there is a character device
5277 with the given C<path> name.
5279 See also C<guestfs_stat>.");
5281 ("is_blockdev", (RBool "flag", [Pathname "path"], []), 268, [],
5282 [InitISOFS, Always, TestOutputFalse (
5283 [["is_blockdev"; "/directory"]]);
5284 InitBasicFS, Always, TestOutputTrue (
5285 [["mknod_b"; "0o777"; "99"; "66"; "/test"];
5286 ["is_blockdev"; "/test"]])],
5287 "test if block device",
5289 This returns C<true> if and only if there is a block device
5290 with the given C<path> name.
5292 See also C<guestfs_stat>.");
5294 ("is_fifo", (RBool "flag", [Pathname "path"], []), 269, [],
5295 [InitISOFS, Always, TestOutputFalse (
5296 [["is_fifo"; "/directory"]]);
5297 InitBasicFS, Always, TestOutputTrue (
5298 [["mkfifo"; "0o777"; "/test"];
5299 ["is_fifo"; "/test"]])],
5300 "test if FIFO (named pipe)",
5302 This returns C<true> if and only if there is a FIFO (named pipe)
5303 with the given C<path> name.
5305 See also C<guestfs_stat>.");
5307 ("is_symlink", (RBool "flag", [Pathname "path"], []), 270, [],
5308 [InitISOFS, Always, TestOutputFalse (
5309 [["is_symlink"; "/directory"]]);
5310 InitISOFS, Always, TestOutputTrue (
5311 [["is_symlink"; "/abssymlink"]])],
5312 "test if symbolic link",
5314 This returns C<true> if and only if there is a symbolic link
5315 with the given C<path> name.
5317 See also C<guestfs_stat>.");
5319 ("is_socket", (RBool "flag", [Pathname "path"], []), 271, [],
5320 (* XXX Need a positive test for sockets. *)
5321 [InitISOFS, Always, TestOutputFalse (
5322 [["is_socket"; "/directory"]])],
5325 This returns C<true> if and only if there is a Unix domain socket
5326 with the given C<path> name.
5328 See also C<guestfs_stat>.");
5330 ("part_to_dev", (RString "device", [Device "partition"], []), 272, [],
5331 [InitPartition, Always, TestOutputDevice (
5332 [["part_to_dev"; "/dev/sda1"]], "/dev/sda");
5333 InitEmpty, Always, TestLastFail (
5334 [["part_to_dev"; "/dev/sda"]])],
5335 "convert partition name to device name",
5337 This function takes a partition name (eg. \"/dev/sdb1\") and
5338 removes the partition number, returning the device name
5341 The named partition must exist, for example as a string returned
5342 from C<guestfs_list_partitions>.");
5344 ("upload_offset", (RErr, [FileIn "filename"; Dev_or_Path "remotefilename"; Int64 "offset"], []), 273, [],
5345 (let md5 = Digest.to_hex (Digest.file "COPYING.LIB") in
5346 [InitBasicFS, Always, TestOutput (
5347 [["upload_offset"; "../COPYING.LIB"; "/COPYING.LIB"; "0"];
5348 ["checksum"; "md5"; "/COPYING.LIB"]], md5)]),
5349 "upload a file from the local machine with offset",
5351 Upload local file C<filename> to C<remotefilename> on the
5354 C<remotefilename> is overwritten starting at the byte C<offset>
5355 specified. The intention is to overwrite parts of existing
5356 files or devices, although if a non-existant file is specified
5357 then it is created with a \"hole\" before C<offset>. The
5358 size of the data written is implicit in the size of the
5361 Note that there is no limit on the amount of data that
5362 can be uploaded with this call, unlike with C<guestfs_pwrite>,
5363 and this call always writes the full amount unless an
5366 See also C<guestfs_upload>, C<guestfs_pwrite>.");
5368 ("download_offset", (RErr, [Dev_or_Path "remotefilename"; FileOut "filename"; Int64 "offset"; Int64 "size"], []), 274, [Progress],
5369 (let md5 = Digest.to_hex (Digest.file "COPYING.LIB") in
5370 let offset = string_of_int 100 in
5371 let size = string_of_int ((Unix.stat "COPYING.LIB").Unix.st_size - 100) in
5372 [InitBasicFS, Always, TestOutput (
5373 (* Pick a file from cwd which isn't likely to change. *)
5374 [["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
5375 ["download_offset"; "/COPYING.LIB"; "testdownload.tmp"; offset; size];
5376 ["upload_offset"; "testdownload.tmp"; "/COPYING.LIB"; offset];
5377 ["checksum"; "md5"; "/COPYING.LIB"]], md5)]),
5378 "download a file to the local machine with offset and size",
5380 Download file C<remotefilename> and save it as C<filename>
5381 on the local machine.
5383 C<remotefilename> is read for C<size> bytes starting at C<offset>
5384 (this region must be within the file or device).
5386 Note that there is no limit on the amount of data that
5387 can be downloaded with this call, unlike with C<guestfs_pread>,
5388 and this call always reads the full amount unless an
5391 See also C<guestfs_download>, C<guestfs_pread>.");
5393 ("pwrite_device", (RInt "nbytes", [Device "device"; BufferIn "content"; Int64 "offset"], []), 275, [ProtocolLimitWarning],
5394 [InitPartition, Always, TestOutputList (
5395 [["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"];
5396 ["blockdev_rereadpt"; "/dev/sda"];
5397 ["list_partitions"]], [])],
5398 "write to part of a device",
5400 This command writes to part of a device. It writes the data
5401 buffer C<content> to C<device> starting at offset C<offset>.
5403 This command implements the L<pwrite(2)> system call, and like
5404 that system call it may not write the full data requested
5405 (although short writes to disk devices and partitions are
5406 probably impossible with standard Linux kernels).
5408 See also C<guestfs_pwrite>.");
5410 ("pread_device", (RBufferOut "content", [Device "device"; Int "count"; Int64 "offset"], []), 276, [ProtocolLimitWarning],
5411 [InitEmpty, Always, TestOutputBuffer (
5412 [["pread_device"; "/dev/sdd"; "8"; "32768"]], "\001CD001\001\000")],
5413 "read part of a device",
5415 This command lets you read part of a file. It reads C<count>
5416 bytes of C<device>, starting at C<offset>.
5418 This may read fewer bytes than requested. For further details
5419 see the L<pread(2)> system call.
5421 See also C<guestfs_pread>.");
5423 ("lvm_canonical_lv_name", (RString "lv", [Device "lvname"], []), 277, [],
5424 [InitBasicFSonLVM, IfAvailable "lvm2", TestOutput (
5425 [["lvm_canonical_lv_name"; "/dev/mapper/VG-LV"]], "/dev/VG/LV");
5426 InitBasicFSonLVM, IfAvailable "lvm2", TestOutput (
5427 [["lvm_canonical_lv_name"; "/dev/VG/LV"]], "/dev/VG/LV")],
5428 "get canonical name of an LV",
5430 This converts alternative naming schemes for LVs that you
5431 might find to the canonical name. For example, C</dev/mapper/VG-LV>
5432 is converted to C</dev/VG/LV>.
5434 This command returns an error if the C<lvname> parameter does
5435 not refer to a logical volume.
5437 See also C<guestfs_is_lv>.");
5441 let all_functions = non_daemon_functions @ daemon_functions
5443 (* In some places we want the functions to be displayed sorted
5444 * alphabetically, so this is useful:
5446 let all_functions_sorted = List.sort action_compare all_functions
5448 (* This is used to generate the src/MAX_PROC_NR file which
5449 * contains the maximum procedure number, a surrogate for the
5450 * ABI version number. See src/Makefile.am for the details.
5453 let proc_nrs = List.map (
5454 fun (_, _, proc_nr, _, _, _, _) -> proc_nr
5455 ) daemon_functions in
5456 List.fold_left max 0 proc_nrs
5458 (* Non-API meta-commands available only in guestfish.
5460 * Note (1): style, proc_nr and tests fields are all meaningless.
5461 * The only fields which are actually used are the shortname,
5462 * FishAlias flags, shortdesc and longdesc.
5464 * Note (2): to refer to other commands, use L</shortname>.
5466 * Note (3): keep this list sorted by shortname.
5468 let fish_commands = [
5469 ("alloc", (RErr,[], []), -1, [FishAlias "allocate"], [],
5470 "allocate and add a disk file",
5471 " alloc filename size
5473 This creates an empty (zeroed) file of the given size, and then adds
5474 so it can be further examined.
5476 For more advanced image creation, see L<qemu-img(1)> utility.
5478 Size can be specified using standard suffixes, eg. C<1M>.
5480 To create a sparse file, use L</sparse> instead. To create a
5481 prepared disk image, see L</PREPARED DISK IMAGES>.");
5483 ("copy_in", (RErr,[], []), -1, [], [],
5484 "copy local files or directories into an image",
5485 " copy-in local [local ...] /remotedir
5487 C<copy-in> copies local files or directories recursively into the disk
5488 image, placing them in the directory called C</remotedir> (which must
5489 exist). This guestfish meta-command turns into a sequence of
5490 L</tar-in> and other commands as necessary.
5492 Multiple local files and directories can be specified, but the last
5493 parameter must always be a remote directory. Wildcards cannot be
5496 ("copy_out", (RErr,[], []), -1, [], [],
5497 "copy remote files or directories out of an image",
5498 " copy-out remote [remote ...] localdir
5500 C<copy-out> copies remote files or directories recursively out of the
5501 disk image, placing them on the host disk in a local directory called
5502 C<localdir> (which must exist). This guestfish meta-command turns
5503 into a sequence of L</download>, L</tar-out> and other commands as
5506 Multiple remote files and directories can be specified, but the last
5507 parameter must always be a local directory. To download to the
5508 current directory, use C<.> as in:
5512 Wildcards cannot be used in the ordinary command, but you can use
5513 them with the help of L</glob> like this:
5515 glob copy-out /home/* .");
5517 ("echo", (RErr,[], []), -1, [], [],
5518 "display a line of text",
5521 This echos the parameters to the terminal.");
5523 ("edit", (RErr,[], []), -1, [FishAlias "vi"; FishAlias "emacs"], [],
5527 This is used to edit a file. It downloads the file, edits it
5528 locally using your editor, then uploads the result.
5530 The editor is C<$EDITOR>. However if you use the alternate
5531 commands C<vi> or C<emacs> you will get those corresponding
5534 ("glob", (RErr,[], []), -1, [], [],
5535 "expand wildcards in command",
5536 " glob command args...
5538 Expand wildcards in any paths in the args list, and run C<command>
5539 repeatedly on each matching path.
5541 See L</WILDCARDS AND GLOBBING>.");
5543 ("hexedit", (RErr,[], []), -1, [], [],
5544 "edit with a hex editor",
5545 " hexedit <filename|device>
5546 hexedit <filename|device> <max>
5547 hexedit <filename|device> <start> <max>
5549 Use hexedit (a hex editor) to edit all or part of a binary file
5552 This command works by downloading potentially the whole file or
5553 device, editing it locally, then uploading it. If the file or
5554 device is large, you have to specify which part you wish to edit
5555 by using C<max> and/or C<start> C<max> parameters.
5556 C<start> and C<max> are specified in bytes, with the usual
5557 modifiers allowed such as C<1M> (1 megabyte).
5559 For example to edit the first few sectors of a disk you
5564 which would allow you to edit anywhere within the first megabyte
5567 To edit the superblock of an ext2 filesystem on C</dev/sda1>, do:
5569 hexedit /dev/sda1 0x400 0x400
5571 (assuming the superblock is in the standard location).
5573 This command requires the external L<hexedit(1)> program. You
5574 can specify another program to use by setting the C<HEXEDITOR>
5575 environment variable.
5577 See also L</hexdump>.");
5579 ("lcd", (RErr,[], []), -1, [], [],
5580 "change working directory",
5583 Change the local directory, ie. the current directory of guestfish
5586 Note that C<!cd> won't do what you might expect.");
5588 ("man", (RErr,[], []), -1, [FishAlias "manual"], [],
5592 Opens the manual page for guestfish.");
5594 ("more", (RErr,[], []), -1, [FishAlias "less"], [],
5600 This is used to view a file.
5602 The default viewer is C<$PAGER>. However if you use the alternate
5603 command C<less> you will get the C<less> command specifically.");
5605 ("reopen", (RErr,[], []), -1, [], [],
5606 "close and reopen libguestfs handle",
5609 Close and reopen the libguestfs handle. It is not necessary to use
5610 this normally, because the handle is closed properly when guestfish
5611 exits. However this is occasionally useful for testing.");
5613 ("sparse", (RErr,[], []), -1, [], [],
5614 "create a sparse disk image and add",
5615 " sparse filename size
5617 This creates an empty sparse file of the given size, and then adds
5618 so it can be further examined.
5620 In all respects it works the same as the L</alloc> command, except that
5621 the image file is allocated sparsely, which means that disk blocks are
5622 not assigned to the file until they are needed. Sparse disk files
5623 only use space when written to, but they are slower and there is a
5624 danger you could run out of real disk space during a write operation.
5626 For more advanced image creation, see L<qemu-img(1)> utility.
5628 Size can be specified using standard suffixes, eg. C<1M>.");
5630 ("supported", (RErr,[], []), -1, [], [],
5631 "list supported groups of commands",
5634 This command returns a list of the optional groups
5635 known to the daemon, and indicates which ones are
5636 supported by this build of the libguestfs appliance.
5638 See also L<guestfs(3)/AVAILABILITY>.");
5640 ("time", (RErr,[], []), -1, [], [],
5641 "print elapsed time taken to run a command",
5642 " time command args...
5644 Run the command as usual, but print the elapsed time afterwards. This
5645 can be useful for benchmarking operations.");