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, [FishAlias "add"],
139 "add an image to examine or modify",
141 This function adds a virtual machine disk image C<filename> to the
142 guest. The first time you call this function, the disk appears as IDE
143 disk 0 (C</dev/sda>) in the guest, the second time as C</dev/sdb>, and
146 You don't necessarily need to be root when using libguestfs. However
147 you obviously do need sufficient permissions to access the filename
148 for whatever operations you want to perform (ie. read access if you
149 just want to read the image or write access if you want to modify the
152 This is equivalent to the qemu parameter
153 C<-drive file=filename,cache=off,if=...>.
155 C<cache=off> is omitted in cases where it is not supported by
156 the underlying filesystem.
158 C<if=...> is set at compile time by the configuration option
159 C<./configure --with-drive-if=...>. In the rare case where you
160 might need to change this at run time, use C<guestfs_add_drive_with_if>
161 or C<guestfs_add_drive_ro_with_if>.
163 Note that this call checks for the existence of C<filename>. This
164 stops you from specifying other types of drive which are supported
165 by qemu such as C<nbd:> and C<http:> URLs. To specify those, use
166 the general C<guestfs_config> call instead.");
168 ("add_cdrom", (RErr, [String "filename"]), -1, [FishAlias "cdrom"],
170 "add a CD-ROM disk image to examine",
172 This function adds a virtual CD-ROM disk image to the guest.
174 This is equivalent to the qemu parameter C<-cdrom filename>.
182 This call checks for the existence of C<filename>. This
183 stops you from specifying other types of drive which are supported
184 by qemu such as C<nbd:> and C<http:> URLs. To specify those, use
185 the general C<guestfs_config> call instead.
189 If you just want to add an ISO file (often you use this as an
190 efficient way to transfer large files into the guest), then you
191 should probably use C<guestfs_add_drive_ro> instead.
195 ("add_drive_ro", (RErr, [String "filename"]), -1, [FishAlias "add-ro"],
197 "add a drive in snapshot mode (read-only)",
199 This adds a drive in snapshot mode, making it effectively
202 Note that writes to the device are allowed, and will be seen for
203 the duration of the guestfs handle, but they are written
204 to a temporary file which is discarded as soon as the guestfs
205 handle is closed. We don't currently have any method to enable
206 changes to be committed, although qemu can support this.
208 This is equivalent to the qemu parameter
209 C<-drive file=filename,snapshot=on,if=...>.
211 C<if=...> is set at compile time by the configuration option
212 C<./configure --with-drive-if=...>. In the rare case where you
213 might need to change this at run time, use C<guestfs_add_drive_with_if>
214 or C<guestfs_add_drive_ro_with_if>.
216 Note that this call checks for the existence of C<filename>. This
217 stops you from specifying other types of drive which are supported
218 by qemu such as C<nbd:> and C<http:> URLs. To specify those, use
219 the general C<guestfs_config> call instead.");
221 ("config", (RErr, [String "qemuparam"; OptString "qemuvalue"]), -1, [],
223 "add qemu parameters",
225 This can be used to add arbitrary qemu command line parameters
226 of the form C<-param value>. Actually it's not quite arbitrary - we
227 prevent you from setting some parameters which would interfere with
228 parameters that we use.
230 The first character of C<param> string must be a C<-> (dash).
232 C<value> can be NULL.");
234 ("set_qemu", (RErr, [OptString "qemu"]), -1, [FishAlias "qemu"],
236 "set the qemu binary",
238 Set the qemu binary that we will use.
240 The default is chosen when the library was compiled by the
243 You can also override this by setting the C<LIBGUESTFS_QEMU>
244 environment variable.
246 Setting C<qemu> to C<NULL> restores the default qemu binary.
248 Note that you should call this function as early as possible
249 after creating the handle. This is because some pre-launch
250 operations depend on testing qemu features (by running C<qemu -help>).
251 If the qemu binary changes, we don't retest features, and
252 so you might see inconsistent results. Using the environment
253 variable C<LIBGUESTFS_QEMU> is safest of all since that picks
254 the qemu binary at the same time as the handle is created.");
256 ("get_qemu", (RConstString "qemu", []), -1, [],
257 [InitNone, Always, TestRun (
259 "get the qemu binary",
261 Return the current qemu binary.
263 This is always non-NULL. If it wasn't set already, then this will
264 return the default qemu binary name.");
266 ("set_path", (RErr, [OptString "searchpath"]), -1, [FishAlias "path"],
268 "set the search path",
270 Set the path that libguestfs searches for kernel and initrd.img.
272 The default is C<$libdir/guestfs> unless overridden by setting
273 C<LIBGUESTFS_PATH> environment variable.
275 Setting C<path> to C<NULL> restores the default path.");
277 ("get_path", (RConstString "path", []), -1, [],
278 [InitNone, Always, TestRun (
280 "get the search path",
282 Return the current search path.
284 This is always non-NULL. If it wasn't set already, then this will
285 return the default path.");
287 ("set_append", (RErr, [OptString "append"]), -1, [FishAlias "append"],
289 "add options to kernel command line",
291 This function is used to add additional options to the
292 guest kernel command line.
294 The default is C<NULL> unless overridden by setting
295 C<LIBGUESTFS_APPEND> environment variable.
297 Setting C<append> to C<NULL> means I<no> additional options
298 are passed (libguestfs always adds a few of its own).");
300 ("get_append", (RConstOptString "append", []), -1, [],
301 (* This cannot be tested with the current framework. The
302 * function can return NULL in normal operations, which the
303 * test framework interprets as an error.
306 "get the additional kernel options",
308 Return the additional kernel options which are added to the
309 guest kernel command line.
311 If C<NULL> then no options are added.");
313 ("set_autosync", (RErr, [Bool "autosync"]), -1, [FishAlias "autosync"],
317 If C<autosync> is true, this enables autosync. Libguestfs will make a
318 best effort attempt to run C<guestfs_umount_all> followed by
319 C<guestfs_sync> when the handle is closed
320 (also if the program exits without closing handles).
322 This is disabled by default (except in guestfish where it is
323 enabled by default).");
325 ("get_autosync", (RBool "autosync", []), -1, [],
326 [InitNone, Always, TestRun (
327 [["get_autosync"]])],
330 Get the autosync flag.");
332 ("set_verbose", (RErr, [Bool "verbose"]), -1, [FishAlias "verbose"],
336 If C<verbose> is true, this turns on verbose messages (to C<stderr>).
338 Verbose messages are disabled unless the environment variable
339 C<LIBGUESTFS_DEBUG> is defined and set to C<1>.");
341 ("get_verbose", (RBool "verbose", []), -1, [],
345 This returns the verbose messages flag.");
347 ("is_ready", (RBool "ready", []), -1, [],
348 [InitNone, Always, TestOutputTrue (
350 "is ready to accept commands",
352 This returns true iff this handle is ready to accept commands
353 (in the C<READY> state).
355 For more information on states, see L<guestfs(3)>.");
357 ("is_config", (RBool "config", []), -1, [],
358 [InitNone, Always, TestOutputFalse (
360 "is in configuration state",
362 This returns true iff this handle is being configured
363 (in the C<CONFIG> state).
365 For more information on states, see L<guestfs(3)>.");
367 ("is_launching", (RBool "launching", []), -1, [],
368 [InitNone, Always, TestOutputFalse (
369 [["is_launching"]])],
370 "is launching subprocess",
372 This returns true iff this handle is launching the subprocess
373 (in the C<LAUNCHING> state).
375 For more information on states, see L<guestfs(3)>.");
377 ("is_busy", (RBool "busy", []), -1, [],
378 [InitNone, Always, TestOutputFalse (
380 "is busy processing a command",
382 This returns true iff this handle is busy processing a command
383 (in the C<BUSY> state).
385 For more information on states, see L<guestfs(3)>.");
387 ("get_state", (RInt "state", []), -1, [],
389 "get the current state",
391 This returns the current state as an opaque integer. This is
392 only useful for printing debug and internal error messages.
394 For more information on states, see L<guestfs(3)>.");
396 ("set_memsize", (RErr, [Int "memsize"]), -1, [FishAlias "memsize"],
397 [InitNone, Always, TestOutputInt (
398 [["set_memsize"; "500"];
399 ["get_memsize"]], 500)],
400 "set memory allocated to the qemu subprocess",
402 This sets the memory size in megabytes allocated to the
403 qemu subprocess. This only has any effect if called before
406 You can also change this by setting the environment
407 variable C<LIBGUESTFS_MEMSIZE> before the handle is
410 For more information on the architecture of libguestfs,
411 see L<guestfs(3)>.");
413 ("get_memsize", (RInt "memsize", []), -1, [],
414 [InitNone, Always, TestOutputIntOp (
415 [["get_memsize"]], ">=", 256)],
416 "get memory allocated to the qemu subprocess",
418 This gets the memory size in megabytes allocated to the
421 If C<guestfs_set_memsize> was not called
422 on this handle, and if C<LIBGUESTFS_MEMSIZE> was not set,
423 then this returns the compiled-in default value for memsize.
425 For more information on the architecture of libguestfs,
426 see L<guestfs(3)>.");
428 ("get_pid", (RInt "pid", []), -1, [FishAlias "pid"],
429 [InitNone, Always, TestOutputIntOp (
430 [["get_pid"]], ">=", 1)],
431 "get PID of qemu subprocess",
433 Return the process ID of the qemu subprocess. If there is no
434 qemu subprocess, then this will return an error.
436 This is an internal call used for debugging and testing.");
438 ("version", (RStruct ("version", "version"), []), -1, [],
439 [InitNone, Always, TestOutputStruct (
440 [["version"]], [CompareWithInt ("major", 1)])],
441 "get the library version number",
443 Return the libguestfs version number that the program is linked
446 Note that because of dynamic linking this is not necessarily
447 the version of libguestfs that you compiled against. You can
448 compile the program, and then at runtime dynamically link
449 against a completely different C<libguestfs.so> library.
451 This call was added in version C<1.0.58>. In previous
452 versions of libguestfs there was no way to get the version
453 number. From C code you can use dynamic linker functions
454 to find out if this symbol exists (if it doesn't, then
455 it's an earlier version).
457 The call returns a structure with four elements. The first
458 three (C<major>, C<minor> and C<release>) are numbers and
459 correspond to the usual version triplet. The fourth element
460 (C<extra>) is a string and is normally empty, but may be
461 used for distro-specific information.
463 To construct the original version string:
464 C<$major.$minor.$release$extra>
466 See also: L<guestfs(3)/LIBGUESTFS VERSION NUMBERS>.
468 I<Note:> Don't use this call to test for availability
469 of features. In enterprise distributions we backport
470 features from later versions into earlier versions,
471 making this an unreliable way to test for features.
472 Use C<guestfs_available> instead.");
474 ("set_selinux", (RErr, [Bool "selinux"]), -1, [FishAlias "selinux"],
475 [InitNone, Always, TestOutputTrue (
476 [["set_selinux"; "true"];
478 "set SELinux enabled or disabled at appliance boot",
480 This sets the selinux flag that is passed to the appliance
481 at boot time. The default is C<selinux=0> (disabled).
483 Note that if SELinux is enabled, it is always in
484 Permissive mode (C<enforcing=0>).
486 For more information on the architecture of libguestfs,
487 see L<guestfs(3)>.");
489 ("get_selinux", (RBool "selinux", []), -1, [],
491 "get SELinux enabled flag",
493 This returns the current setting of the selinux flag which
494 is passed to the appliance at boot time. See C<guestfs_set_selinux>.
496 For more information on the architecture of libguestfs,
497 see L<guestfs(3)>.");
499 ("set_trace", (RErr, [Bool "trace"]), -1, [FishAlias "trace"],
500 [InitNone, Always, TestOutputFalse (
501 [["set_trace"; "false"];
503 "enable or disable command traces",
505 If the command trace flag is set to 1, then commands are
506 printed on stderr before they are executed in a format
507 which is very similar to the one used by guestfish. In
508 other words, you can run a program with this enabled, and
509 you will get out a script which you can feed to guestfish
510 to perform the same set of actions.
512 If you want to trace C API calls into libguestfs (and
513 other libraries) then possibly a better way is to use
514 the external ltrace(1) command.
516 Command traces are disabled unless the environment variable
517 C<LIBGUESTFS_TRACE> is defined and set to C<1>.");
519 ("get_trace", (RBool "trace", []), -1, [],
521 "get command trace enabled flag",
523 Return the command trace flag.");
525 ("set_direct", (RErr, [Bool "direct"]), -1, [FishAlias "direct"],
526 [InitNone, Always, TestOutputFalse (
527 [["set_direct"; "false"];
529 "enable or disable direct appliance mode",
531 If the direct appliance mode flag is enabled, then stdin and
532 stdout are passed directly through to the appliance once it
535 One consequence of this is that log messages aren't caught
536 by the library and handled by C<guestfs_set_log_message_callback>,
537 but go straight to stdout.
539 You probably don't want to use this unless you know what you
542 The default is disabled.");
544 ("get_direct", (RBool "direct", []), -1, [],
546 "get direct appliance mode flag",
548 Return the direct appliance mode flag.");
550 ("set_recovery_proc", (RErr, [Bool "recoveryproc"]), -1, [FishAlias "recovery-proc"],
551 [InitNone, Always, TestOutputTrue (
552 [["set_recovery_proc"; "true"];
553 ["get_recovery_proc"]])],
554 "enable or disable the recovery process",
556 If this is called with the parameter C<false> then
557 C<guestfs_launch> does not create a recovery process. The
558 purpose of the recovery process is to stop runaway qemu
559 processes in the case where the main program aborts abruptly.
561 This only has any effect if called before C<guestfs_launch>,
562 and the default is true.
564 About the only time when you would want to disable this is
565 if the main process will fork itself into the background
566 (\"daemonize\" itself). In this case the recovery process
567 thinks that the main program has disappeared and so kills
568 qemu, which is not very helpful.");
570 ("get_recovery_proc", (RBool "recoveryproc", []), -1, [],
572 "get recovery process enabled flag",
574 Return the recovery process enabled flag.");
576 ("add_drive_with_if", (RErr, [String "filename"; String "iface"]), -1, [],
578 "add a drive specifying the QEMU block emulation to use",
580 This is the same as C<guestfs_add_drive> but it allows you
581 to specify the QEMU interface emulation to use at run time.");
583 ("add_drive_ro_with_if", (RErr, [String "filename"; String "iface"]), -1, [],
585 "add a drive read-only specifying the QEMU block emulation to use",
587 This is the same as C<guestfs_add_drive_ro> but it allows you
588 to specify the QEMU interface emulation to use at run time.");
590 ("file_architecture", (RString "arch", [Pathname "filename"]), -1, [],
591 [InitISOFS, Always, TestOutput (
592 [["file_architecture"; "/bin-i586-dynamic"]], "i386");
593 InitISOFS, Always, TestOutput (
594 [["file_architecture"; "/bin-sparc-dynamic"]], "sparc");
595 InitISOFS, Always, TestOutput (
596 [["file_architecture"; "/bin-win32.exe"]], "i386");
597 InitISOFS, Always, TestOutput (
598 [["file_architecture"; "/bin-win64.exe"]], "x86_64");
599 InitISOFS, Always, TestOutput (
600 [["file_architecture"; "/bin-x86_64-dynamic"]], "x86_64");
601 InitISOFS, Always, TestOutput (
602 [["file_architecture"; "/lib-i586.so"]], "i386");
603 InitISOFS, Always, TestOutput (
604 [["file_architecture"; "/lib-sparc.so"]], "sparc");
605 InitISOFS, Always, TestOutput (
606 [["file_architecture"; "/lib-win32.dll"]], "i386");
607 InitISOFS, Always, TestOutput (
608 [["file_architecture"; "/lib-win64.dll"]], "x86_64");
609 InitISOFS, Always, TestOutput (
610 [["file_architecture"; "/lib-x86_64.so"]], "x86_64");
611 InitISOFS, Always, TestOutput (
612 [["file_architecture"; "/initrd-x86_64.img"]], "x86_64");
613 InitISOFS, Always, TestOutput (
614 [["file_architecture"; "/initrd-x86_64.img.gz"]], "x86_64");],
615 "detect the architecture of a binary file",
617 This detects the architecture of the binary C<filename>,
618 and returns it if known.
620 Currently defined architectures are:
626 This string is returned for all 32 bit i386, i486, i586, i686 binaries
627 irrespective of the precise processor requirements of the binary.
639 64 bit SPARC V9 and above.
655 Libguestfs may return other architecture strings in future.
657 The function works on at least the following types of files:
663 many types of Un*x and Linux binary
667 many types of Un*x and Linux shared library
671 Windows Win32 and Win64 binaries
675 Windows Win32 and Win64 DLLs
677 Win32 binaries and DLLs return C<i386>.
679 Win64 binaries and DLLs return C<x86_64>.
687 Linux new-style initrd images
691 some non-x86 Linux vmlinuz kernels
695 What it can't do currently:
701 static libraries (libfoo.a)
705 Linux old-style initrd as compressed ext2 filesystem (RHEL 3)
709 x86 Linux vmlinuz kernels
711 x86 vmlinuz images (bzImage format) consist of a mix of 16-, 32- and
712 compressed code, and are horribly hard to unpack. If you want to find
713 the architecture of a kernel, use the architecture of the associated
714 initrd or kernel module(s) instead.
718 ("inspect_os", (RStringList "roots", []), -1, [],
720 "inspect disk and return list of operating systems found",
722 This function uses other libguestfs functions and certain
723 heuristics to inspect the disk(s) (usually disks belonging to
724 a virtual machine), looking for operating systems.
726 The list returned is empty if no operating systems were found.
728 If one operating system was found, then this returns a list with
729 a single element, which is the name of the root filesystem of
730 this operating system. It is also possible for this function
731 to return a list containing more than one element, indicating
732 a dual-boot or multi-boot virtual machine, with each element being
733 the root filesystem of one of the operating systems.
735 You can pass the root string(s) returned to other
736 C<guestfs_inspect_get_*> functions in order to query further
737 information about each operating system, such as the name
740 This function uses other libguestfs features such as
741 C<guestfs_mount_ro> and C<guestfs_umount_all> in order to mount
742 and unmount filesystems and look at the contents. This should
743 be called with no disks currently mounted. The function may also
744 use Augeas, so any existing Augeas handle will be closed.
746 This function cannot decrypt encrypted disks. The caller
747 must do that first (supplying the necessary keys) if the
750 Please read L<guestfs(3)/INSPECTION> for more details.
752 See also C<guestfs_list_filesystems>.");
754 ("inspect_get_type", (RString "name", [Device "root"]), -1, [],
756 "get type of inspected operating system",
758 This function should only be called with a root device string
759 as returned by C<guestfs_inspect_os>.
761 This returns the type of the inspected operating system.
762 Currently defined types are:
768 Any Linux-based operating system.
772 Any Microsoft Windows operating system.
776 The operating system type could not be determined.
780 Future versions of libguestfs may return other strings here.
781 The caller should be prepared to handle any string.
783 Please read L<guestfs(3)/INSPECTION> for more details.");
785 ("inspect_get_arch", (RString "arch", [Device "root"]), -1, [],
787 "get architecture of inspected operating system",
789 This function should only be called with a root device string
790 as returned by C<guestfs_inspect_os>.
792 This returns the architecture of the inspected operating system.
793 The possible return values are listed under
794 C<guestfs_file_architecture>.
796 If the architecture could not be determined, then the
797 string C<unknown> is returned.
799 Please read L<guestfs(3)/INSPECTION> for more details.");
801 ("inspect_get_distro", (RString "distro", [Device "root"]), -1, [],
803 "get distro of inspected operating system",
805 This function should only be called with a root device string
806 as returned by C<guestfs_inspect_os>.
808 This returns the distro (distribution) of the inspected operating
811 Currently defined distros are:
817 Debian or a Debian-derived distro such as Ubuntu.
823 =item \"redhat-based\"
825 Some Red Hat-derived distro.
829 Red Hat Enterprise Linux and some derivatives.
833 Windows does not have distributions. This string is
834 returned if the OS type is Windows.
838 The distro could not be determined.
842 Future versions of libguestfs may return other strings here.
843 The caller should be prepared to handle any string.
845 Please read L<guestfs(3)/INSPECTION> for more details.");
847 ("inspect_get_major_version", (RInt "major", [Device "root"]), -1, [],
849 "get major version of inspected operating system",
851 This function should only be called with a root device string
852 as returned by C<guestfs_inspect_os>.
854 This returns the major version number of the inspected operating
857 Windows uses a consistent versioning scheme which is I<not>
858 reflected in the popular public names used by the operating system.
859 Notably the operating system known as \"Windows 7\" is really
860 version 6.1 (ie. major = 6, minor = 1). You can find out the
861 real versions corresponding to releases of Windows by consulting
864 If the version could not be determined, then C<0> is returned.
866 Please read L<guestfs(3)/INSPECTION> for more details.");
868 ("inspect_get_minor_version", (RInt "minor", [Device "root"]), -1, [],
870 "get minor version of inspected operating system",
872 This function should only be called with a root device string
873 as returned by C<guestfs_inspect_os>.
875 This returns the minor version number of the inspected operating
878 If the version could not be determined, then C<0> is returned.
880 Please read L<guestfs(3)/INSPECTION> for more details.
881 See also C<guestfs_inspect_get_major_version>.");
883 ("inspect_get_product_name", (RString "product", [Device "root"]), -1, [],
885 "get product name of inspected operating system",
887 This function should only be called with a root device string
888 as returned by C<guestfs_inspect_os>.
890 This returns the product name of the inspected operating
891 system. The product name is generally some freeform string
892 which can be displayed to the user, but should not be
895 If the product name could not be determined, then the
896 string C<unknown> is returned.
898 Please read L<guestfs(3)/INSPECTION> for more details.");
900 ("inspect_get_mountpoints", (RHashtable "mountpoints", [Device "root"]), -1, [],
902 "get mountpoints of inspected operating system",
904 This function should only be called with a root device string
905 as returned by C<guestfs_inspect_os>.
907 This returns a hash of where we think the filesystems
908 associated with this operating system should be mounted.
909 Callers should note that this is at best an educated guess
910 made by reading configuration files such as C</etc/fstab>.
912 Each element in the returned hashtable has a key which
913 is the path of the mountpoint (eg. C</boot>) and a value
914 which is the filesystem that would be mounted there
917 Non-mounted devices such as swap devices are I<not>
918 returned in this list.
920 Please read L<guestfs(3)/INSPECTION> for more details.
921 See also C<guestfs_inspect_get_filesystems>.");
923 ("inspect_get_filesystems", (RStringList "filesystems", [Device "root"]), -1, [],
925 "get filesystems associated with inspected operating system",
927 This function should only be called with a root device string
928 as returned by C<guestfs_inspect_os>.
930 This returns a list of all the filesystems that we think
931 are associated with this operating system. This includes
932 the root filesystem, other ordinary filesystems, and
933 non-mounted devices like swap partitions.
935 In the case of a multi-boot virtual machine, it is possible
936 for a filesystem to be shared between operating systems.
938 Please read L<guestfs(3)/INSPECTION> for more details.
939 See also C<guestfs_inspect_get_mountpoints>.");
941 ("set_network", (RErr, [Bool "network"]), -1, [FishAlias "network"],
943 "set enable network flag",
945 If C<network> is true, then the network is enabled in the
946 libguestfs appliance. The default is false.
948 This affects whether commands are able to access the network
949 (see L<guestfs(3)/RUNNING COMMANDS>).
951 You must call this before calling C<guestfs_launch>, otherwise
954 ("get_network", (RBool "network", []), -1, [],
956 "get enable network flag",
958 This returns the enable network flag.");
960 ("list_filesystems", (RHashtable "fses", []), -1, [],
964 This inspection command looks for filesystems on partitions,
965 block devices and logical volumes, returning a list of devices
966 containing filesystems and their type.
968 The return value is a hash, where the keys are the devices
969 containing filesystems, and the values are the filesystem types.
972 \"/dev/sda1\" => \"ntfs\"
973 \"/dev/sda2\" => \"ext2\"
974 \"/dev/vg_guest/lv_root\" => \"ext4\"
975 \"/dev/vg_guest/lv_swap\" => \"swap\"
977 The value can have the special value \"unknown\", meaning the
978 content of the device is undetermined or empty.
979 \"swap\" means a Linux swap partition.
981 This command runs other libguestfs commands, which might include
982 C<guestfs_mount> and C<guestfs_umount>, and therefore you should
983 use this soon after launch and only when nothing is mounted.
985 Not all of the filesystems returned will be mountable. In
986 particular, swap partitions are returned in the list. Also
987 this command does not check that each filesystem
988 found is valid and mountable, and some filesystems might
989 be mountable but require special options. Filesystems may
990 not all belong to a single logical operating system
991 (use C<guestfs_inspect_os> to look for OSes).");
995 (* daemon_functions are any functions which cause some action
996 * to take place in the daemon.
999 let daemon_functions = [
1000 ("mount", (RErr, [Device "device"; String "mountpoint"]), 1, [],
1001 [InitEmpty, Always, TestOutput (
1002 [["part_disk"; "/dev/sda"; "mbr"];
1003 ["mkfs"; "ext2"; "/dev/sda1"];
1004 ["mount"; "/dev/sda1"; "/"];
1005 ["write"; "/new"; "new file contents"];
1006 ["cat"; "/new"]], "new file contents")],
1007 "mount a guest disk at a position in the filesystem",
1009 Mount a guest disk at a position in the filesystem. Block devices
1010 are named C</dev/sda>, C</dev/sdb> and so on, as they were added to
1011 the guest. If those block devices contain partitions, they will have
1012 the usual names (eg. C</dev/sda1>). Also LVM C</dev/VG/LV>-style
1015 The rules are the same as for L<mount(2)>: A filesystem must
1016 first be mounted on C</> before others can be mounted. Other
1017 filesystems can only be mounted on directories which already
1020 The mounted filesystem is writable, if we have sufficient permissions
1021 on the underlying device.
1024 When you use this call, the filesystem options C<sync> and C<noatime>
1025 are set implicitly. This was originally done because we thought it
1026 would improve reliability, but it turns out that I<-o sync> has a
1027 very large negative performance impact and negligible effect on
1028 reliability. Therefore we recommend that you avoid using
1029 C<guestfs_mount> in any code that needs performance, and instead
1030 use C<guestfs_mount_options> (use an empty string for the first
1031 parameter if you don't want any options).");
1033 ("sync", (RErr, []), 2, [],
1034 [ InitEmpty, Always, TestRun [["sync"]]],
1035 "sync disks, writes are flushed through to the disk image",
1037 This syncs the disk, so that any writes are flushed through to the
1038 underlying disk image.
1040 You should always call this if you have modified a disk image, before
1041 closing the handle.");
1043 ("touch", (RErr, [Pathname "path"]), 3, [],
1044 [InitBasicFS, Always, TestOutputTrue (
1046 ["exists"; "/new"]])],
1047 "update file timestamps or create a new file",
1049 Touch acts like the L<touch(1)> command. It can be used to
1050 update the timestamps on a file, or, if the file does not exist,
1051 to create a new zero-length file.
1053 This command only works on regular files, and will fail on other
1054 file types such as directories, symbolic links, block special etc.");
1056 ("cat", (RString "content", [Pathname "path"]), 4, [ProtocolLimitWarning],
1057 [InitISOFS, Always, TestOutput (
1058 [["cat"; "/known-2"]], "abcdef\n")],
1059 "list the contents of a file",
1061 Return the contents of the file named C<path>.
1063 Note that this function cannot correctly handle binary files
1064 (specifically, files containing C<\\0> character which is treated
1065 as end of string). For those you need to use the C<guestfs_read_file>
1066 or C<guestfs_download> functions which have a more complex interface.");
1068 ("ll", (RString "listing", [Pathname "directory"]), 5, [],
1069 [], (* XXX Tricky to test because it depends on the exact format
1070 * of the 'ls -l' command, which changes between F10 and F11.
1072 "list the files in a directory (long format)",
1074 List the files in C<directory> (relative to the root directory,
1075 there is no cwd) in the format of 'ls -la'.
1077 This command is mostly useful for interactive sessions. It
1078 is I<not> intended that you try to parse the output string.");
1080 ("ls", (RStringList "listing", [Pathname "directory"]), 6, [],
1081 [InitBasicFS, Always, TestOutputList (
1083 ["touch"; "/newer"];
1084 ["touch"; "/newest"];
1085 ["ls"; "/"]], ["lost+found"; "new"; "newer"; "newest"])],
1086 "list the files in a directory",
1088 List the files in C<directory> (relative to the root directory,
1089 there is no cwd). The '.' and '..' entries are not returned, but
1090 hidden files are shown.
1092 This command is mostly useful for interactive sessions. Programs
1093 should probably use C<guestfs_readdir> instead.");
1095 ("list_devices", (RStringList "devices", []), 7, [],
1096 [InitEmpty, Always, TestOutputListOfDevices (
1097 [["list_devices"]], ["/dev/sda"; "/dev/sdb"; "/dev/sdc"; "/dev/sdd"])],
1098 "list the block devices",
1100 List all the block devices.
1102 The full block device names are returned, eg. C</dev/sda>.
1104 See also C<guestfs_list_filesystems>.");
1106 ("list_partitions", (RStringList "partitions", []), 8, [],
1107 [InitBasicFS, Always, TestOutputListOfDevices (
1108 [["list_partitions"]], ["/dev/sda1"]);
1109 InitEmpty, Always, TestOutputListOfDevices (
1110 [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1111 ["list_partitions"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])],
1112 "list the partitions",
1114 List all the partitions detected on all block devices.
1116 The full partition device names are returned, eg. C</dev/sda1>
1118 This does not return logical volumes. For that you will need to
1119 call C<guestfs_lvs>.
1121 See also C<guestfs_list_filesystems>.");
1123 ("pvs", (RStringList "physvols", []), 9, [Optional "lvm2"],
1124 [InitBasicFSonLVM, Always, TestOutputListOfDevices (
1125 [["pvs"]], ["/dev/sda1"]);
1126 InitEmpty, Always, TestOutputListOfDevices (
1127 [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1128 ["pvcreate"; "/dev/sda1"];
1129 ["pvcreate"; "/dev/sda2"];
1130 ["pvcreate"; "/dev/sda3"];
1131 ["pvs"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])],
1132 "list the LVM physical volumes (PVs)",
1134 List all the physical volumes detected. This is the equivalent
1135 of the L<pvs(8)> command.
1137 This returns a list of just the device names that contain
1138 PVs (eg. C</dev/sda2>).
1140 See also C<guestfs_pvs_full>.");
1142 ("vgs", (RStringList "volgroups", []), 10, [Optional "lvm2"],
1143 [InitBasicFSonLVM, Always, TestOutputList (
1145 InitEmpty, Always, TestOutputList (
1146 [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1147 ["pvcreate"; "/dev/sda1"];
1148 ["pvcreate"; "/dev/sda2"];
1149 ["pvcreate"; "/dev/sda3"];
1150 ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
1151 ["vgcreate"; "VG2"; "/dev/sda3"];
1152 ["vgs"]], ["VG1"; "VG2"])],
1153 "list the LVM volume groups (VGs)",
1155 List all the volumes groups detected. This is the equivalent
1156 of the L<vgs(8)> command.
1158 This returns a list of just the volume group names that were
1159 detected (eg. C<VolGroup00>).
1161 See also C<guestfs_vgs_full>.");
1163 ("lvs", (RStringList "logvols", []), 11, [Optional "lvm2"],
1164 [InitBasicFSonLVM, Always, TestOutputList (
1165 [["lvs"]], ["/dev/VG/LV"]);
1166 InitEmpty, Always, TestOutputList (
1167 [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1168 ["pvcreate"; "/dev/sda1"];
1169 ["pvcreate"; "/dev/sda2"];
1170 ["pvcreate"; "/dev/sda3"];
1171 ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
1172 ["vgcreate"; "VG2"; "/dev/sda3"];
1173 ["lvcreate"; "LV1"; "VG1"; "50"];
1174 ["lvcreate"; "LV2"; "VG1"; "50"];
1175 ["lvcreate"; "LV3"; "VG2"; "50"];
1176 ["lvs"]], ["/dev/VG1/LV1"; "/dev/VG1/LV2"; "/dev/VG2/LV3"])],
1177 "list the LVM logical volumes (LVs)",
1179 List all the logical volumes detected. This is the equivalent
1180 of the L<lvs(8)> command.
1182 This returns a list of the logical volume device names
1183 (eg. C</dev/VolGroup00/LogVol00>).
1185 See also C<guestfs_lvs_full>, C<guestfs_list_filesystems>.");
1187 ("pvs_full", (RStructList ("physvols", "lvm_pv"), []), 12, [Optional "lvm2"],
1188 [], (* XXX how to test? *)
1189 "list the LVM physical volumes (PVs)",
1191 List all the physical volumes detected. This is the equivalent
1192 of the L<pvs(8)> command. The \"full\" version includes all fields.");
1194 ("vgs_full", (RStructList ("volgroups", "lvm_vg"), []), 13, [Optional "lvm2"],
1195 [], (* XXX how to test? *)
1196 "list the LVM volume groups (VGs)",
1198 List all the volumes groups detected. This is the equivalent
1199 of the L<vgs(8)> command. The \"full\" version includes all fields.");
1201 ("lvs_full", (RStructList ("logvols", "lvm_lv"), []), 14, [Optional "lvm2"],
1202 [], (* XXX how to test? *)
1203 "list the LVM logical volumes (LVs)",
1205 List all the logical volumes detected. This is the equivalent
1206 of the L<lvs(8)> command. The \"full\" version includes all fields.");
1208 ("read_lines", (RStringList "lines", [Pathname "path"]), 15, [],
1209 [InitISOFS, Always, TestOutputList (
1210 [["read_lines"; "/known-4"]], ["abc"; "def"; "ghi"]);
1211 InitISOFS, Always, TestOutputList (
1212 [["read_lines"; "/empty"]], [])],
1213 "read file as lines",
1215 Return the contents of the file named C<path>.
1217 The file contents are returned as a list of lines. Trailing
1218 C<LF> and C<CRLF> character sequences are I<not> returned.
1220 Note that this function cannot correctly handle binary files
1221 (specifically, files containing C<\\0> character which is treated
1222 as end of line). For those you need to use the C<guestfs_read_file>
1223 function which has a more complex interface.");
1225 ("aug_init", (RErr, [Pathname "root"; Int "flags"]), 16, [Optional "augeas"],
1226 [], (* XXX Augeas code needs tests. *)
1227 "create a new Augeas handle",
1229 Create a new Augeas handle for editing configuration files.
1230 If there was any previous Augeas handle associated with this
1231 guestfs session, then it is closed.
1233 You must call this before using any other C<guestfs_aug_*>
1236 C<root> is the filesystem root. C<root> must not be NULL,
1239 The flags are the same as the flags defined in
1240 E<lt>augeas.hE<gt>, the logical I<or> of the following
1245 =item C<AUG_SAVE_BACKUP> = 1
1247 Keep the original file with a C<.augsave> extension.
1249 =item C<AUG_SAVE_NEWFILE> = 2
1251 Save changes into a file with extension C<.augnew>, and
1252 do not overwrite original. Overrides C<AUG_SAVE_BACKUP>.
1254 =item C<AUG_TYPE_CHECK> = 4
1256 Typecheck lenses (can be expensive).
1258 =item C<AUG_NO_STDINC> = 8
1260 Do not use standard load path for modules.
1262 =item C<AUG_SAVE_NOOP> = 16
1264 Make save a no-op, just record what would have been changed.
1266 =item C<AUG_NO_LOAD> = 32
1268 Do not load the tree in C<guestfs_aug_init>.
1272 To close the handle, you can call C<guestfs_aug_close>.
1274 To find out more about Augeas, see L<http://augeas.net/>.");
1276 ("aug_close", (RErr, []), 26, [Optional "augeas"],
1277 [], (* XXX Augeas code needs tests. *)
1278 "close the current Augeas handle",
1280 Close the current Augeas handle and free up any resources
1281 used by it. After calling this, you have to call
1282 C<guestfs_aug_init> again before you can use any other
1283 Augeas functions.");
1285 ("aug_defvar", (RInt "nrnodes", [String "name"; OptString "expr"]), 17, [Optional "augeas"],
1286 [], (* XXX Augeas code needs tests. *)
1287 "define an Augeas variable",
1289 Defines an Augeas variable C<name> whose value is the result
1290 of evaluating C<expr>. If C<expr> is NULL, then C<name> is
1293 On success this returns the number of nodes in C<expr>, or
1294 C<0> if C<expr> evaluates to something which is not a nodeset.");
1296 ("aug_defnode", (RStruct ("nrnodescreated", "int_bool"), [String "name"; String "expr"; String "val"]), 18, [Optional "augeas"],
1297 [], (* XXX Augeas code needs tests. *)
1298 "define an Augeas node",
1300 Defines a variable C<name> whose value is the result of
1303 If C<expr> evaluates to an empty nodeset, a node is created,
1304 equivalent to calling C<guestfs_aug_set> C<expr>, C<value>.
1305 C<name> will be the nodeset containing that single node.
1307 On success this returns a pair containing the
1308 number of nodes in the nodeset, and a boolean flag
1309 if a node was created.");
1311 ("aug_get", (RString "val", [String "augpath"]), 19, [Optional "augeas"],
1312 [], (* XXX Augeas code needs tests. *)
1313 "look up the value of an Augeas path",
1315 Look up the value associated with C<path>. If C<path>
1316 matches exactly one node, the C<value> is returned.");
1318 ("aug_set", (RErr, [String "augpath"; String "val"]), 20, [Optional "augeas"],
1319 [], (* XXX Augeas code needs tests. *)
1320 "set Augeas path to value",
1322 Set the value associated with C<path> to C<val>.
1324 In the Augeas API, it is possible to clear a node by setting
1325 the value to NULL. Due to an oversight in the libguestfs API
1326 you cannot do that with this call. Instead you must use the
1327 C<guestfs_aug_clear> call.");
1329 ("aug_insert", (RErr, [String "augpath"; String "label"; Bool "before"]), 21, [Optional "augeas"],
1330 [], (* XXX Augeas code needs tests. *)
1331 "insert a sibling Augeas node",
1333 Create a new sibling C<label> for C<path>, inserting it into
1334 the tree before or after C<path> (depending on the boolean
1337 C<path> must match exactly one existing node in the tree, and
1338 C<label> must be a label, ie. not contain C</>, C<*> or end
1339 with a bracketed index C<[N]>.");
1341 ("aug_rm", (RInt "nrnodes", [String "augpath"]), 22, [Optional "augeas"],
1342 [], (* XXX Augeas code needs tests. *)
1343 "remove an Augeas path",
1345 Remove C<path> and all of its children.
1347 On success this returns the number of entries which were removed.");
1349 ("aug_mv", (RErr, [String "src"; String "dest"]), 23, [Optional "augeas"],
1350 [], (* XXX Augeas code needs tests. *)
1353 Move the node C<src> to C<dest>. C<src> must match exactly
1354 one node. C<dest> is overwritten if it exists.");
1356 ("aug_match", (RStringList "matches", [String "augpath"]), 24, [Optional "augeas"],
1357 [], (* XXX Augeas code needs tests. *)
1358 "return Augeas nodes which match augpath",
1360 Returns a list of paths which match the path expression C<path>.
1361 The returned paths are sufficiently qualified so that they match
1362 exactly one node in the current tree.");
1364 ("aug_save", (RErr, []), 25, [Optional "augeas"],
1365 [], (* XXX Augeas code needs tests. *)
1366 "write all pending Augeas changes to disk",
1368 This writes all pending changes to disk.
1370 The flags which were passed to C<guestfs_aug_init> affect exactly
1371 how files are saved.");
1373 ("aug_load", (RErr, []), 27, [Optional "augeas"],
1374 [], (* XXX Augeas code needs tests. *)
1375 "load files into the tree",
1377 Load files into the tree.
1379 See C<aug_load> in the Augeas documentation for the full gory
1382 ("aug_ls", (RStringList "matches", [String "augpath"]), 28, [Optional "augeas"],
1383 [], (* XXX Augeas code needs tests. *)
1384 "list Augeas nodes under augpath",
1386 This is just a shortcut for listing C<guestfs_aug_match>
1387 C<path/*> and sorting the resulting nodes into alphabetical order.");
1389 ("rm", (RErr, [Pathname "path"]), 29, [],
1390 [InitBasicFS, Always, TestRun
1393 InitBasicFS, Always, TestLastFail
1395 InitBasicFS, Always, TestLastFail
1400 Remove the single file C<path>.");
1402 ("rmdir", (RErr, [Pathname "path"]), 30, [],
1403 [InitBasicFS, Always, TestRun
1406 InitBasicFS, Always, TestLastFail
1407 [["rmdir"; "/new"]];
1408 InitBasicFS, Always, TestLastFail
1410 ["rmdir"; "/new"]]],
1411 "remove a directory",
1413 Remove the single directory C<path>.");
1415 ("rm_rf", (RErr, [Pathname "path"]), 31, [],
1416 [InitBasicFS, Always, TestOutputFalse
1418 ["mkdir"; "/new/foo"];
1419 ["touch"; "/new/foo/bar"];
1421 ["exists"; "/new"]]],
1422 "remove a file or directory recursively",
1424 Remove the file or directory C<path>, recursively removing the
1425 contents if its a directory. This is like the C<rm -rf> shell
1428 ("mkdir", (RErr, [Pathname "path"]), 32, [],
1429 [InitBasicFS, Always, TestOutputTrue
1431 ["is_dir"; "/new"]];
1432 InitBasicFS, Always, TestLastFail
1433 [["mkdir"; "/new/foo/bar"]]],
1434 "create a directory",
1436 Create a directory named C<path>.");
1438 ("mkdir_p", (RErr, [Pathname "path"]), 33, [],
1439 [InitBasicFS, Always, TestOutputTrue
1440 [["mkdir_p"; "/new/foo/bar"];
1441 ["is_dir"; "/new/foo/bar"]];
1442 InitBasicFS, Always, TestOutputTrue
1443 [["mkdir_p"; "/new/foo/bar"];
1444 ["is_dir"; "/new/foo"]];
1445 InitBasicFS, Always, TestOutputTrue
1446 [["mkdir_p"; "/new/foo/bar"];
1447 ["is_dir"; "/new"]];
1448 (* Regression tests for RHBZ#503133: *)
1449 InitBasicFS, Always, TestRun
1451 ["mkdir_p"; "/new"]];
1452 InitBasicFS, Always, TestLastFail
1454 ["mkdir_p"; "/new"]]],
1455 "create a directory and parents",
1457 Create a directory named C<path>, creating any parent directories
1458 as necessary. This is like the C<mkdir -p> shell command.");
1460 ("chmod", (RErr, [Int "mode"; Pathname "path"]), 34, [],
1461 [], (* XXX Need stat command to test *)
1464 Change the mode (permissions) of C<path> to C<mode>. Only
1465 numeric modes are supported.
1467 I<Note>: When using this command from guestfish, C<mode>
1468 by default would be decimal, unless you prefix it with
1469 C<0> to get octal, ie. use C<0700> not C<700>.
1471 The mode actually set is affected by the umask.");
1473 ("chown", (RErr, [Int "owner"; Int "group"; Pathname "path"]), 35, [],
1474 [], (* XXX Need stat command to test *)
1475 "change file owner and group",
1477 Change the file owner to C<owner> and group to C<group>.
1479 Only numeric uid and gid are supported. If you want to use
1480 names, you will need to locate and parse the password file
1481 yourself (Augeas support makes this relatively easy).");
1483 ("exists", (RBool "existsflag", [Pathname "path"]), 36, [],
1484 [InitISOFS, Always, TestOutputTrue (
1485 [["exists"; "/empty"]]);
1486 InitISOFS, Always, TestOutputTrue (
1487 [["exists"; "/directory"]])],
1488 "test if file or directory exists",
1490 This returns C<true> if and only if there is a file, directory
1491 (or anything) with the given C<path> name.
1493 See also C<guestfs_is_file>, C<guestfs_is_dir>, C<guestfs_stat>.");
1495 ("is_file", (RBool "fileflag", [Pathname "path"]), 37, [],
1496 [InitISOFS, Always, TestOutputTrue (
1497 [["is_file"; "/known-1"]]);
1498 InitISOFS, Always, TestOutputFalse (
1499 [["is_file"; "/directory"]])],
1500 "test if a regular file",
1502 This returns C<true> if and only if there is a regular file
1503 with the given C<path> name. Note that it returns false for
1504 other objects like directories.
1506 See also C<guestfs_stat>.");
1508 ("is_dir", (RBool "dirflag", [Pathname "path"]), 38, [],
1509 [InitISOFS, Always, TestOutputFalse (
1510 [["is_dir"; "/known-3"]]);
1511 InitISOFS, Always, TestOutputTrue (
1512 [["is_dir"; "/directory"]])],
1513 "test if a directory",
1515 This returns C<true> if and only if there is a directory
1516 with the given C<path> name. Note that it returns false for
1517 other objects like files.
1519 See also C<guestfs_stat>.");
1521 ("pvcreate", (RErr, [Device "device"]), 39, [Optional "lvm2"],
1522 [InitEmpty, Always, TestOutputListOfDevices (
1523 [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1524 ["pvcreate"; "/dev/sda1"];
1525 ["pvcreate"; "/dev/sda2"];
1526 ["pvcreate"; "/dev/sda3"];
1527 ["pvs"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])],
1528 "create an LVM physical volume",
1530 This creates an LVM physical volume on the named C<device>,
1531 where C<device> should usually be a partition name such
1534 ("vgcreate", (RErr, [String "volgroup"; DeviceList "physvols"]), 40, [Optional "lvm2"],
1535 [InitEmpty, Always, TestOutputList (
1536 [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1537 ["pvcreate"; "/dev/sda1"];
1538 ["pvcreate"; "/dev/sda2"];
1539 ["pvcreate"; "/dev/sda3"];
1540 ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
1541 ["vgcreate"; "VG2"; "/dev/sda3"];
1542 ["vgs"]], ["VG1"; "VG2"])],
1543 "create an LVM volume group",
1545 This creates an LVM volume group called C<volgroup>
1546 from the non-empty list of physical volumes C<physvols>.");
1548 ("lvcreate", (RErr, [String "logvol"; String "volgroup"; Int "mbytes"]), 41, [Optional "lvm2"],
1549 [InitEmpty, Always, TestOutputList (
1550 [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1551 ["pvcreate"; "/dev/sda1"];
1552 ["pvcreate"; "/dev/sda2"];
1553 ["pvcreate"; "/dev/sda3"];
1554 ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
1555 ["vgcreate"; "VG2"; "/dev/sda3"];
1556 ["lvcreate"; "LV1"; "VG1"; "50"];
1557 ["lvcreate"; "LV2"; "VG1"; "50"];
1558 ["lvcreate"; "LV3"; "VG2"; "50"];
1559 ["lvcreate"; "LV4"; "VG2"; "50"];
1560 ["lvcreate"; "LV5"; "VG2"; "50"];
1562 ["/dev/VG1/LV1"; "/dev/VG1/LV2";
1563 "/dev/VG2/LV3"; "/dev/VG2/LV4"; "/dev/VG2/LV5"])],
1564 "create an LVM logical volume",
1566 This creates an LVM logical volume called C<logvol>
1567 on the volume group C<volgroup>, with C<size> megabytes.");
1569 ("mkfs", (RErr, [String "fstype"; Device "device"]), 42, [],
1570 [InitEmpty, Always, TestOutput (
1571 [["part_disk"; "/dev/sda"; "mbr"];
1572 ["mkfs"; "ext2"; "/dev/sda1"];
1573 ["mount_options"; ""; "/dev/sda1"; "/"];
1574 ["write"; "/new"; "new file contents"];
1575 ["cat"; "/new"]], "new file contents")],
1576 "make a filesystem",
1578 This creates a filesystem on C<device> (usually a partition
1579 or LVM logical volume). The filesystem type is C<fstype>, for
1582 ("sfdisk", (RErr, [Device "device";
1583 Int "cyls"; Int "heads"; Int "sectors";
1584 StringList "lines"]), 43, [DangerWillRobinson],
1586 "create partitions on a block device",
1588 This is a direct interface to the L<sfdisk(8)> program for creating
1589 partitions on block devices.
1591 C<device> should be a block device, for example C</dev/sda>.
1593 C<cyls>, C<heads> and C<sectors> are the number of cylinders, heads
1594 and sectors on the device, which are passed directly to sfdisk as
1595 the I<-C>, I<-H> and I<-S> parameters. If you pass C<0> for any
1596 of these, then the corresponding parameter is omitted. Usually for
1597 'large' disks, you can just pass C<0> for these, but for small
1598 (floppy-sized) disks, sfdisk (or rather, the kernel) cannot work
1599 out the right geometry and you will need to tell it.
1601 C<lines> is a list of lines that we feed to C<sfdisk>. For more
1602 information refer to the L<sfdisk(8)> manpage.
1604 To create a single partition occupying the whole disk, you would
1605 pass C<lines> as a single element list, when the single element being
1606 the string C<,> (comma).
1608 See also: C<guestfs_sfdisk_l>, C<guestfs_sfdisk_N>,
1609 C<guestfs_part_init>");
1611 ("write_file", (RErr, [Pathname "path"; String "content"; Int "size"]), 44, [ProtocolLimitWarning; DeprecatedBy "write"],
1612 (* Regression test for RHBZ#597135. *)
1613 [InitBasicFS, Always, TestLastFail
1614 [["write_file"; "/new"; "abc"; "10000"]]],
1617 This call creates a file called C<path>. The contents of the
1618 file is the string C<content> (which can contain any 8 bit data),
1619 with length C<size>.
1621 As a special case, if C<size> is C<0>
1622 then the length is calculated using C<strlen> (so in this case
1623 the content cannot contain embedded ASCII NULs).
1625 I<NB.> Owing to a bug, writing content containing ASCII NUL
1626 characters does I<not> work, even if the length is specified.");
1628 ("umount", (RErr, [String "pathordevice"]), 45, [FishAlias "unmount"],
1629 [InitEmpty, Always, TestOutputListOfDevices (
1630 [["part_disk"; "/dev/sda"; "mbr"];
1631 ["mkfs"; "ext2"; "/dev/sda1"];
1632 ["mount_options"; ""; "/dev/sda1"; "/"];
1633 ["mounts"]], ["/dev/sda1"]);
1634 InitEmpty, Always, TestOutputList (
1635 [["part_disk"; "/dev/sda"; "mbr"];
1636 ["mkfs"; "ext2"; "/dev/sda1"];
1637 ["mount_options"; ""; "/dev/sda1"; "/"];
1640 "unmount a filesystem",
1642 This unmounts the given filesystem. The filesystem may be
1643 specified either by its mountpoint (path) or the device which
1644 contains the filesystem.");
1646 ("mounts", (RStringList "devices", []), 46, [],
1647 [InitBasicFS, Always, TestOutputListOfDevices (
1648 [["mounts"]], ["/dev/sda1"])],
1649 "show mounted filesystems",
1651 This returns the list of currently mounted filesystems. It returns
1652 the list of devices (eg. C</dev/sda1>, C</dev/VG/LV>).
1654 Some internal mounts are not shown.
1656 See also: C<guestfs_mountpoints>");
1658 ("umount_all", (RErr, []), 47, [FishAlias "unmount-all"],
1659 [InitBasicFS, Always, TestOutputList (
1662 (* check that umount_all can unmount nested mounts correctly: *)
1663 InitEmpty, Always, TestOutputList (
1664 [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1665 ["mkfs"; "ext2"; "/dev/sda1"];
1666 ["mkfs"; "ext2"; "/dev/sda2"];
1667 ["mkfs"; "ext2"; "/dev/sda3"];
1668 ["mount_options"; ""; "/dev/sda1"; "/"];
1670 ["mount_options"; ""; "/dev/sda2"; "/mp1"];
1671 ["mkdir"; "/mp1/mp2"];
1672 ["mount_options"; ""; "/dev/sda3"; "/mp1/mp2"];
1673 ["mkdir"; "/mp1/mp2/mp3"];
1676 "unmount all filesystems",
1678 This unmounts all mounted filesystems.
1680 Some internal mounts are not unmounted by this call.");
1682 ("lvm_remove_all", (RErr, []), 48, [DangerWillRobinson; Optional "lvm2"],
1684 "remove all LVM LVs, VGs and PVs",
1686 This command removes all LVM logical volumes, volume groups
1687 and physical volumes.");
1689 ("file", (RString "description", [Dev_or_Path "path"]), 49, [],
1690 [InitISOFS, Always, TestOutput (
1691 [["file"; "/empty"]], "empty");
1692 InitISOFS, Always, TestOutput (
1693 [["file"; "/known-1"]], "ASCII text");
1694 InitISOFS, Always, TestLastFail (
1695 [["file"; "/notexists"]]);
1696 InitISOFS, Always, TestOutput (
1697 [["file"; "/abssymlink"]], "symbolic link");
1698 InitISOFS, Always, TestOutput (
1699 [["file"; "/directory"]], "directory")],
1700 "determine file type",
1702 This call uses the standard L<file(1)> command to determine
1703 the type or contents of the file.
1705 This call will also transparently look inside various types
1708 The exact command which runs is C<file -zb path>. Note in
1709 particular that the filename is not prepended to the output
1712 This command can also be used on C</dev/> devices
1713 (and partitions, LV names). You can for example use this
1714 to determine if a device contains a filesystem, although
1715 it's usually better to use C<guestfs_vfs_type>.
1717 If the C<path> does not begin with C</dev/> then
1718 this command only works for the content of regular files.
1719 For other file types (directory, symbolic link etc) it
1720 will just return the string C<directory> etc.");
1722 ("command", (RString "output", [StringList "arguments"]), 50, [ProtocolLimitWarning],
1723 [InitBasicFS, Always, TestOutput (
1724 [["upload"; "test-command"; "/test-command"];
1725 ["chmod"; "0o755"; "/test-command"];
1726 ["command"; "/test-command 1"]], "Result1");
1727 InitBasicFS, Always, TestOutput (
1728 [["upload"; "test-command"; "/test-command"];
1729 ["chmod"; "0o755"; "/test-command"];
1730 ["command"; "/test-command 2"]], "Result2\n");
1731 InitBasicFS, Always, TestOutput (
1732 [["upload"; "test-command"; "/test-command"];
1733 ["chmod"; "0o755"; "/test-command"];
1734 ["command"; "/test-command 3"]], "\nResult3");
1735 InitBasicFS, Always, TestOutput (
1736 [["upload"; "test-command"; "/test-command"];
1737 ["chmod"; "0o755"; "/test-command"];
1738 ["command"; "/test-command 4"]], "\nResult4\n");
1739 InitBasicFS, Always, TestOutput (
1740 [["upload"; "test-command"; "/test-command"];
1741 ["chmod"; "0o755"; "/test-command"];
1742 ["command"; "/test-command 5"]], "\nResult5\n\n");
1743 InitBasicFS, Always, TestOutput (
1744 [["upload"; "test-command"; "/test-command"];
1745 ["chmod"; "0o755"; "/test-command"];
1746 ["command"; "/test-command 6"]], "\n\nResult6\n\n");
1747 InitBasicFS, Always, TestOutput (
1748 [["upload"; "test-command"; "/test-command"];
1749 ["chmod"; "0o755"; "/test-command"];
1750 ["command"; "/test-command 7"]], "");
1751 InitBasicFS, Always, TestOutput (
1752 [["upload"; "test-command"; "/test-command"];
1753 ["chmod"; "0o755"; "/test-command"];
1754 ["command"; "/test-command 8"]], "\n");
1755 InitBasicFS, Always, TestOutput (
1756 [["upload"; "test-command"; "/test-command"];
1757 ["chmod"; "0o755"; "/test-command"];
1758 ["command"; "/test-command 9"]], "\n\n");
1759 InitBasicFS, Always, TestOutput (
1760 [["upload"; "test-command"; "/test-command"];
1761 ["chmod"; "0o755"; "/test-command"];
1762 ["command"; "/test-command 10"]], "Result10-1\nResult10-2\n");
1763 InitBasicFS, Always, TestOutput (
1764 [["upload"; "test-command"; "/test-command"];
1765 ["chmod"; "0o755"; "/test-command"];
1766 ["command"; "/test-command 11"]], "Result11-1\nResult11-2");
1767 InitBasicFS, Always, TestLastFail (
1768 [["upload"; "test-command"; "/test-command"];
1769 ["chmod"; "0o755"; "/test-command"];
1770 ["command"; "/test-command"]])],
1771 "run a command from the guest filesystem",
1773 This call runs a command from the guest filesystem. The
1774 filesystem must be mounted, and must contain a compatible
1775 operating system (ie. something Linux, with the same
1776 or compatible processor architecture).
1778 The single parameter is an argv-style list of arguments.
1779 The first element is the name of the program to run.
1780 Subsequent elements are parameters. The list must be
1781 non-empty (ie. must contain a program name). Note that
1782 the command runs directly, and is I<not> invoked via
1783 the shell (see C<guestfs_sh>).
1785 The return value is anything printed to I<stdout> by
1788 If the command returns a non-zero exit status, then
1789 this function returns an error message. The error message
1790 string is the content of I<stderr> from the command.
1792 The C<$PATH> environment variable will contain at least
1793 C</usr/bin> and C</bin>. If you require a program from
1794 another location, you should provide the full path in the
1797 Shared libraries and data files required by the program
1798 must be available on filesystems which are mounted in the
1799 correct places. It is the caller's responsibility to ensure
1800 all filesystems that are needed are mounted at the right
1803 ("command_lines", (RStringList "lines", [StringList "arguments"]), 51, [ProtocolLimitWarning],
1804 [InitBasicFS, Always, TestOutputList (
1805 [["upload"; "test-command"; "/test-command"];
1806 ["chmod"; "0o755"; "/test-command"];
1807 ["command_lines"; "/test-command 1"]], ["Result1"]);
1808 InitBasicFS, Always, TestOutputList (
1809 [["upload"; "test-command"; "/test-command"];
1810 ["chmod"; "0o755"; "/test-command"];
1811 ["command_lines"; "/test-command 2"]], ["Result2"]);
1812 InitBasicFS, Always, TestOutputList (
1813 [["upload"; "test-command"; "/test-command"];
1814 ["chmod"; "0o755"; "/test-command"];
1815 ["command_lines"; "/test-command 3"]], ["";"Result3"]);
1816 InitBasicFS, Always, TestOutputList (
1817 [["upload"; "test-command"; "/test-command"];
1818 ["chmod"; "0o755"; "/test-command"];
1819 ["command_lines"; "/test-command 4"]], ["";"Result4"]);
1820 InitBasicFS, Always, TestOutputList (
1821 [["upload"; "test-command"; "/test-command"];
1822 ["chmod"; "0o755"; "/test-command"];
1823 ["command_lines"; "/test-command 5"]], ["";"Result5";""]);
1824 InitBasicFS, Always, TestOutputList (
1825 [["upload"; "test-command"; "/test-command"];
1826 ["chmod"; "0o755"; "/test-command"];
1827 ["command_lines"; "/test-command 6"]], ["";"";"Result6";""]);
1828 InitBasicFS, Always, TestOutputList (
1829 [["upload"; "test-command"; "/test-command"];
1830 ["chmod"; "0o755"; "/test-command"];
1831 ["command_lines"; "/test-command 7"]], []);
1832 InitBasicFS, Always, TestOutputList (
1833 [["upload"; "test-command"; "/test-command"];
1834 ["chmod"; "0o755"; "/test-command"];
1835 ["command_lines"; "/test-command 8"]], [""]);
1836 InitBasicFS, Always, TestOutputList (
1837 [["upload"; "test-command"; "/test-command"];
1838 ["chmod"; "0o755"; "/test-command"];
1839 ["command_lines"; "/test-command 9"]], ["";""]);
1840 InitBasicFS, Always, TestOutputList (
1841 [["upload"; "test-command"; "/test-command"];
1842 ["chmod"; "0o755"; "/test-command"];
1843 ["command_lines"; "/test-command 10"]], ["Result10-1";"Result10-2"]);
1844 InitBasicFS, Always, TestOutputList (
1845 [["upload"; "test-command"; "/test-command"];
1846 ["chmod"; "0o755"; "/test-command"];
1847 ["command_lines"; "/test-command 11"]], ["Result11-1";"Result11-2"])],
1848 "run a command, returning lines",
1850 This is the same as C<guestfs_command>, but splits the
1851 result into a list of lines.
1853 See also: C<guestfs_sh_lines>");
1855 ("stat", (RStruct ("statbuf", "stat"), [Pathname "path"]), 52, [],
1856 [InitISOFS, Always, TestOutputStruct (
1857 [["stat"; "/empty"]], [CompareWithInt ("size", 0)])],
1858 "get file information",
1860 Returns file information for the given C<path>.
1862 This is the same as the C<stat(2)> system call.");
1864 ("lstat", (RStruct ("statbuf", "stat"), [Pathname "path"]), 53, [],
1865 [InitISOFS, Always, TestOutputStruct (
1866 [["lstat"; "/empty"]], [CompareWithInt ("size", 0)])],
1867 "get file information for a symbolic link",
1869 Returns file information for the given C<path>.
1871 This is the same as C<guestfs_stat> except that if C<path>
1872 is a symbolic link, then the link is stat-ed, not the file it
1875 This is the same as the C<lstat(2)> system call.");
1877 ("statvfs", (RStruct ("statbuf", "statvfs"), [Pathname "path"]), 54, [],
1878 [InitISOFS, Always, TestOutputStruct (
1879 [["statvfs"; "/"]], [CompareWithInt ("namemax", 255)])],
1880 "get file system statistics",
1882 Returns file system statistics for any mounted file system.
1883 C<path> should be a file or directory in the mounted file system
1884 (typically it is the mount point itself, but it doesn't need to be).
1886 This is the same as the C<statvfs(2)> system call.");
1888 ("tune2fs_l", (RHashtable "superblock", [Device "device"]), 55, [],
1890 "get ext2/ext3/ext4 superblock details",
1892 This returns the contents of the ext2, ext3 or ext4 filesystem
1893 superblock on C<device>.
1895 It is the same as running C<tune2fs -l device>. See L<tune2fs(8)>
1896 manpage for more details. The list of fields returned isn't
1897 clearly defined, and depends on both the version of C<tune2fs>
1898 that libguestfs was built against, and the filesystem itself.");
1900 ("blockdev_setro", (RErr, [Device "device"]), 56, [],
1901 [InitEmpty, Always, TestOutputTrue (
1902 [["blockdev_setro"; "/dev/sda"];
1903 ["blockdev_getro"; "/dev/sda"]])],
1904 "set block device to read-only",
1906 Sets the block device named C<device> to read-only.
1908 This uses the L<blockdev(8)> command.");
1910 ("blockdev_setrw", (RErr, [Device "device"]), 57, [],
1911 [InitEmpty, Always, TestOutputFalse (
1912 [["blockdev_setrw"; "/dev/sda"];
1913 ["blockdev_getro"; "/dev/sda"]])],
1914 "set block device to read-write",
1916 Sets the block device named C<device> to read-write.
1918 This uses the L<blockdev(8)> command.");
1920 ("blockdev_getro", (RBool "ro", [Device "device"]), 58, [],
1921 [InitEmpty, Always, TestOutputTrue (
1922 [["blockdev_setro"; "/dev/sda"];
1923 ["blockdev_getro"; "/dev/sda"]])],
1924 "is block device set to read-only",
1926 Returns a boolean indicating if the block device is read-only
1927 (true if read-only, false if not).
1929 This uses the L<blockdev(8)> command.");
1931 ("blockdev_getss", (RInt "sectorsize", [Device "device"]), 59, [],
1932 [InitEmpty, Always, TestOutputInt (
1933 [["blockdev_getss"; "/dev/sda"]], 512)],
1934 "get sectorsize of block device",
1936 This returns the size of sectors on a block device.
1937 Usually 512, but can be larger for modern devices.
1939 (Note, this is not the size in sectors, use C<guestfs_blockdev_getsz>
1942 This uses the L<blockdev(8)> command.");
1944 ("blockdev_getbsz", (RInt "blocksize", [Device "device"]), 60, [],
1945 [InitEmpty, Always, TestOutputInt (
1946 [["blockdev_getbsz"; "/dev/sda"]], 4096)],
1947 "get blocksize of block device",
1949 This returns the block size of a device.
1951 (Note this is different from both I<size in blocks> and
1952 I<filesystem block size>).
1954 This uses the L<blockdev(8)> command.");
1956 ("blockdev_setbsz", (RErr, [Device "device"; Int "blocksize"]), 61, [],
1958 "set blocksize of block device",
1960 This sets the block size of a device.
1962 (Note this is different from both I<size in blocks> and
1963 I<filesystem block size>).
1965 This uses the L<blockdev(8)> command.");
1967 ("blockdev_getsz", (RInt64 "sizeinsectors", [Device "device"]), 62, [],
1968 [InitEmpty, Always, TestOutputInt (
1969 [["blockdev_getsz"; "/dev/sda"]], 1024000)],
1970 "get total size of device in 512-byte sectors",
1972 This returns the size of the device in units of 512-byte sectors
1973 (even if the sectorsize isn't 512 bytes ... weird).
1975 See also C<guestfs_blockdev_getss> for the real sector size of
1976 the device, and C<guestfs_blockdev_getsize64> for the more
1977 useful I<size in bytes>.
1979 This uses the L<blockdev(8)> command.");
1981 ("blockdev_getsize64", (RInt64 "sizeinbytes", [Device "device"]), 63, [],
1982 [InitEmpty, Always, TestOutputInt (
1983 [["blockdev_getsize64"; "/dev/sda"]], 524288000)],
1984 "get total size of device in bytes",
1986 This returns the size of the device in bytes.
1988 See also C<guestfs_blockdev_getsz>.
1990 This uses the L<blockdev(8)> command.");
1992 ("blockdev_flushbufs", (RErr, [Device "device"]), 64, [],
1993 [InitEmpty, Always, TestRun
1994 [["blockdev_flushbufs"; "/dev/sda"]]],
1995 "flush device buffers",
1997 This tells the kernel to flush internal buffers associated
2000 This uses the L<blockdev(8)> command.");
2002 ("blockdev_rereadpt", (RErr, [Device "device"]), 65, [],
2003 [InitEmpty, Always, TestRun
2004 [["blockdev_rereadpt"; "/dev/sda"]]],
2005 "reread partition table",
2007 Reread the partition table on C<device>.
2009 This uses the L<blockdev(8)> command.");
2011 ("upload", (RErr, [FileIn "filename"; Dev_or_Path "remotefilename"]), 66, [],
2012 [InitBasicFS, Always, TestOutput (
2013 (* Pick a file from cwd which isn't likely to change. *)
2014 [["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
2015 ["checksum"; "md5"; "/COPYING.LIB"]],
2016 Digest.to_hex (Digest.file "COPYING.LIB"))],
2017 "upload a file from the local machine",
2019 Upload local file C<filename> to C<remotefilename> on the
2022 C<filename> can also be a named pipe.
2024 See also C<guestfs_download>.");
2026 ("download", (RErr, [Dev_or_Path "remotefilename"; FileOut "filename"]), 67, [Progress],
2027 [InitBasicFS, Always, TestOutput (
2028 (* Pick a file from cwd which isn't likely to change. *)
2029 [["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
2030 ["download"; "/COPYING.LIB"; "testdownload.tmp"];
2031 ["upload"; "testdownload.tmp"; "/upload"];
2032 ["checksum"; "md5"; "/upload"]],
2033 Digest.to_hex (Digest.file "COPYING.LIB"))],
2034 "download a file to the local machine",
2036 Download file C<remotefilename> and save it as C<filename>
2037 on the local machine.
2039 C<filename> can also be a named pipe.
2041 See also C<guestfs_upload>, C<guestfs_cat>.");
2043 ("checksum", (RString "checksum", [String "csumtype"; Pathname "path"]), 68, [],
2044 [InitISOFS, Always, TestOutput (
2045 [["checksum"; "crc"; "/known-3"]], "2891671662");
2046 InitISOFS, Always, TestLastFail (
2047 [["checksum"; "crc"; "/notexists"]]);
2048 InitISOFS, Always, TestOutput (
2049 [["checksum"; "md5"; "/known-3"]], "46d6ca27ee07cdc6fa99c2e138cc522c");
2050 InitISOFS, Always, TestOutput (
2051 [["checksum"; "sha1"; "/known-3"]], "b7ebccc3ee418311091c3eda0a45b83c0a770f15");
2052 InitISOFS, Always, TestOutput (
2053 [["checksum"; "sha224"; "/known-3"]], "d2cd1774b28f3659c14116be0a6dc2bb5c4b350ce9cd5defac707741");
2054 InitISOFS, Always, TestOutput (
2055 [["checksum"; "sha256"; "/known-3"]], "75bb71b90cd20cb13f86d2bea8dad63ac7194e7517c3b52b8d06ff52d3487d30");
2056 InitISOFS, Always, TestOutput (
2057 [["checksum"; "sha384"; "/known-3"]], "5fa7883430f357b5d7b7271d3a1d2872b51d73cba72731de6863d3dea55f30646af2799bef44d5ea776a5ec7941ac640");
2058 InitISOFS, Always, TestOutput (
2059 [["checksum"; "sha512"; "/known-3"]], "2794062c328c6b216dca90443b7f7134c5f40e56bd0ed7853123275a09982a6f992e6ca682f9d2fba34a4c5e870d8fe077694ff831e3032a004ee077e00603f6");
2060 (* Test for RHBZ#579608, absolute symbolic links. *)
2061 InitISOFS, Always, TestOutput (
2062 [["checksum"; "sha512"; "/abssymlink"]], "5f57d0639bc95081c53afc63a449403883818edc64da48930ad6b1a4fb49be90404686877743fbcd7c99811f3def7df7bc22635c885c6a8cf79c806b43451c1a")],
2063 "compute MD5, SHAx or CRC checksum of file",
2065 This call computes the MD5, SHAx or CRC checksum of the
2068 The type of checksum to compute is given by the C<csumtype>
2069 parameter which must have one of the following values:
2075 Compute the cyclic redundancy check (CRC) specified by POSIX
2076 for the C<cksum> command.
2080 Compute the MD5 hash (using the C<md5sum> program).
2084 Compute the SHA1 hash (using the C<sha1sum> program).
2088 Compute the SHA224 hash (using the C<sha224sum> program).
2092 Compute the SHA256 hash (using the C<sha256sum> program).
2096 Compute the SHA384 hash (using the C<sha384sum> program).
2100 Compute the SHA512 hash (using the C<sha512sum> program).
2104 The checksum is returned as a printable string.
2106 To get the checksum for a device, use C<guestfs_checksum_device>.
2108 To get the checksums for many files, use C<guestfs_checksums_out>.");
2110 ("tar_in", (RErr, [FileIn "tarfile"; Pathname "directory"]), 69, [],
2111 [InitBasicFS, Always, TestOutput (
2112 [["tar_in"; "../images/helloworld.tar"; "/"];
2113 ["cat"; "/hello"]], "hello\n")],
2114 "unpack tarfile to directory",
2116 This command uploads and unpacks local file C<tarfile> (an
2117 I<uncompressed> tar file) into C<directory>.
2119 To upload a compressed tarball, use C<guestfs_tgz_in>
2120 or C<guestfs_txz_in>.");
2122 ("tar_out", (RErr, [String "directory"; FileOut "tarfile"]), 70, [],
2124 "pack directory into tarfile",
2126 This command packs the contents of C<directory> and downloads
2127 it to local file C<tarfile>.
2129 To download a compressed tarball, use C<guestfs_tgz_out>
2130 or C<guestfs_txz_out>.");
2132 ("tgz_in", (RErr, [FileIn "tarball"; Pathname "directory"]), 71, [],
2133 [InitBasicFS, Always, TestOutput (
2134 [["tgz_in"; "../images/helloworld.tar.gz"; "/"];
2135 ["cat"; "/hello"]], "hello\n")],
2136 "unpack compressed tarball to directory",
2138 This command uploads and unpacks local file C<tarball> (a
2139 I<gzip compressed> tar file) into C<directory>.
2141 To upload an uncompressed tarball, use C<guestfs_tar_in>.");
2143 ("tgz_out", (RErr, [Pathname "directory"; FileOut "tarball"]), 72, [],
2145 "pack directory into compressed tarball",
2147 This command packs the contents of C<directory> and downloads
2148 it to local file C<tarball>.
2150 To download an uncompressed tarball, use C<guestfs_tar_out>.");
2152 ("mount_ro", (RErr, [Device "device"; String "mountpoint"]), 73, [],
2153 [InitBasicFS, Always, TestLastFail (
2155 ["mount_ro"; "/dev/sda1"; "/"];
2156 ["touch"; "/new"]]);
2157 InitBasicFS, Always, TestOutput (
2158 [["write"; "/new"; "data"];
2160 ["mount_ro"; "/dev/sda1"; "/"];
2161 ["cat"; "/new"]], "data")],
2162 "mount a guest disk, read-only",
2164 This is the same as the C<guestfs_mount> command, but it
2165 mounts the filesystem with the read-only (I<-o ro>) flag.");
2167 ("mount_options", (RErr, [String "options"; Device "device"; String "mountpoint"]), 74, [],
2169 "mount a guest disk with mount options",
2171 This is the same as the C<guestfs_mount> command, but it
2172 allows you to set the mount options as for the
2173 L<mount(8)> I<-o> flag.
2175 If the C<options> parameter is an empty string, then
2176 no options are passed (all options default to whatever
2177 the filesystem uses).");
2179 ("mount_vfs", (RErr, [String "options"; String "vfstype"; Device "device"; String "mountpoint"]), 75, [],
2181 "mount a guest disk with mount options and vfstype",
2183 This is the same as the C<guestfs_mount> command, but it
2184 allows you to set both the mount options and the vfstype
2185 as for the L<mount(8)> I<-o> and I<-t> flags.");
2187 ("debug", (RString "result", [String "subcmd"; StringList "extraargs"]), 76, [],
2189 "debugging and internals",
2191 The C<guestfs_debug> command exposes some internals of
2192 C<guestfsd> (the guestfs daemon) that runs inside the
2195 There is no comprehensive help for this command. You have
2196 to look at the file C<daemon/debug.c> in the libguestfs source
2197 to find out what you can do.");
2199 ("lvremove", (RErr, [Device "device"]), 77, [Optional "lvm2"],
2200 [InitEmpty, Always, TestOutputList (
2201 [["part_disk"; "/dev/sda"; "mbr"];
2202 ["pvcreate"; "/dev/sda1"];
2203 ["vgcreate"; "VG"; "/dev/sda1"];
2204 ["lvcreate"; "LV1"; "VG"; "50"];
2205 ["lvcreate"; "LV2"; "VG"; "50"];
2206 ["lvremove"; "/dev/VG/LV1"];
2207 ["lvs"]], ["/dev/VG/LV2"]);
2208 InitEmpty, Always, TestOutputList (
2209 [["part_disk"; "/dev/sda"; "mbr"];
2210 ["pvcreate"; "/dev/sda1"];
2211 ["vgcreate"; "VG"; "/dev/sda1"];
2212 ["lvcreate"; "LV1"; "VG"; "50"];
2213 ["lvcreate"; "LV2"; "VG"; "50"];
2214 ["lvremove"; "/dev/VG"];
2216 InitEmpty, Always, TestOutputList (
2217 [["part_disk"; "/dev/sda"; "mbr"];
2218 ["pvcreate"; "/dev/sda1"];
2219 ["vgcreate"; "VG"; "/dev/sda1"];
2220 ["lvcreate"; "LV1"; "VG"; "50"];
2221 ["lvcreate"; "LV2"; "VG"; "50"];
2222 ["lvremove"; "/dev/VG"];
2224 "remove an LVM logical volume",
2226 Remove an LVM logical volume C<device>, where C<device> is
2227 the path to the LV, such as C</dev/VG/LV>.
2229 You can also remove all LVs in a volume group by specifying
2230 the VG name, C</dev/VG>.");
2232 ("vgremove", (RErr, [String "vgname"]), 78, [Optional "lvm2"],
2233 [InitEmpty, Always, TestOutputList (
2234 [["part_disk"; "/dev/sda"; "mbr"];
2235 ["pvcreate"; "/dev/sda1"];
2236 ["vgcreate"; "VG"; "/dev/sda1"];
2237 ["lvcreate"; "LV1"; "VG"; "50"];
2238 ["lvcreate"; "LV2"; "VG"; "50"];
2241 InitEmpty, Always, TestOutputList (
2242 [["part_disk"; "/dev/sda"; "mbr"];
2243 ["pvcreate"; "/dev/sda1"];
2244 ["vgcreate"; "VG"; "/dev/sda1"];
2245 ["lvcreate"; "LV1"; "VG"; "50"];
2246 ["lvcreate"; "LV2"; "VG"; "50"];
2249 "remove an LVM volume group",
2251 Remove an LVM volume group C<vgname>, (for example C<VG>).
2253 This also forcibly removes all logical volumes in the volume
2256 ("pvremove", (RErr, [Device "device"]), 79, [Optional "lvm2"],
2257 [InitEmpty, Always, TestOutputListOfDevices (
2258 [["part_disk"; "/dev/sda"; "mbr"];
2259 ["pvcreate"; "/dev/sda1"];
2260 ["vgcreate"; "VG"; "/dev/sda1"];
2261 ["lvcreate"; "LV1"; "VG"; "50"];
2262 ["lvcreate"; "LV2"; "VG"; "50"];
2264 ["pvremove"; "/dev/sda1"];
2266 InitEmpty, Always, TestOutputListOfDevices (
2267 [["part_disk"; "/dev/sda"; "mbr"];
2268 ["pvcreate"; "/dev/sda1"];
2269 ["vgcreate"; "VG"; "/dev/sda1"];
2270 ["lvcreate"; "LV1"; "VG"; "50"];
2271 ["lvcreate"; "LV2"; "VG"; "50"];
2273 ["pvremove"; "/dev/sda1"];
2275 InitEmpty, Always, TestOutputListOfDevices (
2276 [["part_disk"; "/dev/sda"; "mbr"];
2277 ["pvcreate"; "/dev/sda1"];
2278 ["vgcreate"; "VG"; "/dev/sda1"];
2279 ["lvcreate"; "LV1"; "VG"; "50"];
2280 ["lvcreate"; "LV2"; "VG"; "50"];
2282 ["pvremove"; "/dev/sda1"];
2284 "remove an LVM physical volume",
2286 This wipes a physical volume C<device> so that LVM will no longer
2289 The implementation uses the C<pvremove> command which refuses to
2290 wipe physical volumes that contain any volume groups, so you have
2291 to remove those first.");
2293 ("set_e2label", (RErr, [Device "device"; String "label"]), 80, [],
2294 [InitBasicFS, Always, TestOutput (
2295 [["set_e2label"; "/dev/sda1"; "testlabel"];
2296 ["get_e2label"; "/dev/sda1"]], "testlabel")],
2297 "set the ext2/3/4 filesystem label",
2299 This sets the ext2/3/4 filesystem label of the filesystem on
2300 C<device> to C<label>. Filesystem labels are limited to
2303 You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2label>
2304 to return the existing label on a filesystem.");
2306 ("get_e2label", (RString "label", [Device "device"]), 81, [DeprecatedBy "vfs_label"],
2308 "get the ext2/3/4 filesystem label",
2310 This returns the ext2/3/4 filesystem label of the filesystem on
2313 ("set_e2uuid", (RErr, [Device "device"; String "uuid"]), 82, [],
2314 (let uuid = uuidgen () in
2315 [InitBasicFS, Always, TestOutput (
2316 [["set_e2uuid"; "/dev/sda1"; uuid];
2317 ["get_e2uuid"; "/dev/sda1"]], uuid);
2318 InitBasicFS, Always, TestOutput (
2319 [["set_e2uuid"; "/dev/sda1"; "clear"];
2320 ["get_e2uuid"; "/dev/sda1"]], "");
2321 (* We can't predict what UUIDs will be, so just check the commands run. *)
2322 InitBasicFS, Always, TestRun (
2323 [["set_e2uuid"; "/dev/sda1"; "random"]]);
2324 InitBasicFS, Always, TestRun (
2325 [["set_e2uuid"; "/dev/sda1"; "time"]])]),
2326 "set the ext2/3/4 filesystem UUID",
2328 This sets the ext2/3/4 filesystem UUID of the filesystem on
2329 C<device> to C<uuid>. The format of the UUID and alternatives
2330 such as C<clear>, C<random> and C<time> are described in the
2331 L<tune2fs(8)> manpage.
2333 You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2uuid>
2334 to return the existing UUID of a filesystem.");
2336 ("get_e2uuid", (RString "uuid", [Device "device"]), 83, [DeprecatedBy "vfs_uuid"],
2337 (* Regression test for RHBZ#597112. *)
2338 (let uuid = uuidgen () in
2339 [InitBasicFS, Always, TestOutput (
2340 [["mke2journal"; "1024"; "/dev/sdb"];
2341 ["set_e2uuid"; "/dev/sdb"; uuid];
2342 ["get_e2uuid"; "/dev/sdb"]], uuid)]),
2343 "get the ext2/3/4 filesystem UUID",
2345 This returns the ext2/3/4 filesystem UUID of the filesystem on
2348 ("fsck", (RInt "status", [String "fstype"; Device "device"]), 84, [FishOutput FishOutputHexadecimal],
2349 [InitBasicFS, Always, TestOutputInt (
2350 [["umount"; "/dev/sda1"];
2351 ["fsck"; "ext2"; "/dev/sda1"]], 0);
2352 InitBasicFS, Always, TestOutputInt (
2353 [["umount"; "/dev/sda1"];
2354 ["zero"; "/dev/sda1"];
2355 ["fsck"; "ext2"; "/dev/sda1"]], 8)],
2356 "run the filesystem checker",
2358 This runs the filesystem checker (fsck) on C<device> which
2359 should have filesystem type C<fstype>.
2361 The returned integer is the status. See L<fsck(8)> for the
2362 list of status codes from C<fsck>.
2370 Multiple status codes can be summed together.
2374 A non-zero return code can mean \"success\", for example if
2375 errors have been corrected on the filesystem.
2379 Checking or repairing NTFS volumes is not supported
2384 This command is entirely equivalent to running C<fsck -a -t fstype device>.");
2386 ("zero", (RErr, [Device "device"]), 85, [Progress],
2387 [InitBasicFS, Always, TestOutput (
2388 [["umount"; "/dev/sda1"];
2389 ["zero"; "/dev/sda1"];
2390 ["file"; "/dev/sda1"]], "data")],
2391 "write zeroes to the device",
2393 This command writes zeroes over the first few blocks of C<device>.
2395 How many blocks are zeroed isn't specified (but it's I<not> enough
2396 to securely wipe the device). It should be sufficient to remove
2397 any partition tables, filesystem superblocks and so on.
2399 See also: C<guestfs_zero_device>, C<guestfs_scrub_device>.");
2401 ("grub_install", (RErr, [Pathname "root"; Device "device"]), 86, [],
2403 * https://bugzilla.redhat.com/show_bug.cgi?id=484986
2404 * https://bugzilla.redhat.com/show_bug.cgi?id=479760
2406 [InitBasicFS, Always, TestOutputTrue (
2407 [["mkdir_p"; "/boot/grub"];
2408 ["write"; "/boot/grub/device.map"; "(hd0) /dev/vda"];
2409 ["grub_install"; "/"; "/dev/vda"];
2410 ["is_dir"; "/boot"]])],
2413 This command installs GRUB (the Grand Unified Bootloader) on
2414 C<device>, with the root directory being C<root>.
2416 Note: If grub-install reports the error
2417 \"No suitable drive was found in the generated device map.\"
2418 it may be that you need to create a C</boot/grub/device.map>
2419 file first that contains the mapping between grub device names
2420 and Linux device names. It is usually sufficient to create
2425 replacing C</dev/vda> with the name of the installation device.");
2427 ("cp", (RErr, [Pathname "src"; Pathname "dest"]), 87, [],
2428 [InitBasicFS, Always, TestOutput (
2429 [["write"; "/old"; "file content"];
2430 ["cp"; "/old"; "/new"];
2431 ["cat"; "/new"]], "file content");
2432 InitBasicFS, Always, TestOutputTrue (
2433 [["write"; "/old"; "file content"];
2434 ["cp"; "/old"; "/new"];
2435 ["is_file"; "/old"]]);
2436 InitBasicFS, Always, TestOutput (
2437 [["write"; "/old"; "file content"];
2439 ["cp"; "/old"; "/dir/new"];
2440 ["cat"; "/dir/new"]], "file content")],
2443 This copies a file from C<src> to C<dest> where C<dest> is
2444 either a destination filename or destination directory.");
2446 ("cp_a", (RErr, [Pathname "src"; Pathname "dest"]), 88, [],
2447 [InitBasicFS, Always, TestOutput (
2448 [["mkdir"; "/olddir"];
2449 ["mkdir"; "/newdir"];
2450 ["write"; "/olddir/file"; "file content"];
2451 ["cp_a"; "/olddir"; "/newdir"];
2452 ["cat"; "/newdir/olddir/file"]], "file content")],
2453 "copy a file or directory recursively",
2455 This copies a file or directory from C<src> to C<dest>
2456 recursively using the C<cp -a> command.");
2458 ("mv", (RErr, [Pathname "src"; Pathname "dest"]), 89, [],
2459 [InitBasicFS, Always, TestOutput (
2460 [["write"; "/old"; "file content"];
2461 ["mv"; "/old"; "/new"];
2462 ["cat"; "/new"]], "file content");
2463 InitBasicFS, Always, TestOutputFalse (
2464 [["write"; "/old"; "file content"];
2465 ["mv"; "/old"; "/new"];
2466 ["is_file"; "/old"]])],
2469 This moves a file from C<src> to C<dest> where C<dest> is
2470 either a destination filename or destination directory.");
2472 ("drop_caches", (RErr, [Int "whattodrop"]), 90, [],
2473 [InitEmpty, Always, TestRun (
2474 [["drop_caches"; "3"]])],
2475 "drop kernel page cache, dentries and inodes",
2477 This instructs the guest kernel to drop its page cache,
2478 and/or dentries and inode caches. The parameter C<whattodrop>
2479 tells the kernel what precisely to drop, see
2480 L<http://linux-mm.org/Drop_Caches>
2482 Setting C<whattodrop> to 3 should drop everything.
2484 This automatically calls L<sync(2)> before the operation,
2485 so that the maximum guest memory is freed.");
2487 ("dmesg", (RString "kmsgs", []), 91, [],
2488 [InitEmpty, Always, TestRun (
2490 "return kernel messages",
2492 This returns the kernel messages (C<dmesg> output) from
2493 the guest kernel. This is sometimes useful for extended
2494 debugging of problems.
2496 Another way to get the same information is to enable
2497 verbose messages with C<guestfs_set_verbose> or by setting
2498 the environment variable C<LIBGUESTFS_DEBUG=1> before
2499 running the program.");
2501 ("ping_daemon", (RErr, []), 92, [],
2502 [InitEmpty, Always, TestRun (
2503 [["ping_daemon"]])],
2504 "ping the guest daemon",
2506 This is a test probe into the guestfs daemon running inside
2507 the qemu subprocess. Calling this function checks that the
2508 daemon responds to the ping message, without affecting the daemon
2509 or attached block device(s) in any other way.");
2511 ("equal", (RBool "equality", [Pathname "file1"; Pathname "file2"]), 93, [],
2512 [InitBasicFS, Always, TestOutputTrue (
2513 [["write"; "/file1"; "contents of a file"];
2514 ["cp"; "/file1"; "/file2"];
2515 ["equal"; "/file1"; "/file2"]]);
2516 InitBasicFS, Always, TestOutputFalse (
2517 [["write"; "/file1"; "contents of a file"];
2518 ["write"; "/file2"; "contents of another file"];
2519 ["equal"; "/file1"; "/file2"]]);
2520 InitBasicFS, Always, TestLastFail (
2521 [["equal"; "/file1"; "/file2"]])],
2522 "test if two files have equal contents",
2524 This compares the two files C<file1> and C<file2> and returns
2525 true if their content is exactly equal, or false otherwise.
2527 The external L<cmp(1)> program is used for the comparison.");
2529 ("strings", (RStringList "stringsout", [Pathname "path"]), 94, [ProtocolLimitWarning],
2530 [InitISOFS, Always, TestOutputList (
2531 [["strings"; "/known-5"]], ["abcdefghi"; "jklmnopqr"]);
2532 InitISOFS, Always, TestOutputList (
2533 [["strings"; "/empty"]], []);
2534 (* Test for RHBZ#579608, absolute symbolic links. *)
2535 InitISOFS, Always, TestRun (
2536 [["strings"; "/abssymlink"]])],
2537 "print the printable strings in a file",
2539 This runs the L<strings(1)> command on a file and returns
2540 the list of printable strings found.");
2542 ("strings_e", (RStringList "stringsout", [String "encoding"; Pathname "path"]), 95, [ProtocolLimitWarning],
2543 [InitISOFS, Always, TestOutputList (
2544 [["strings_e"; "b"; "/known-5"]], []);
2545 InitBasicFS, Always, TestOutputList (
2546 [["write"; "/new"; "\000h\000e\000l\000l\000o\000\n\000w\000o\000r\000l\000d\000\n"];
2547 ["strings_e"; "b"; "/new"]], ["hello"; "world"])],
2548 "print the printable strings in a file",
2550 This is like the C<guestfs_strings> command, but allows you to
2551 specify the encoding of strings that are looked for in
2552 the source file C<path>.
2554 Allowed encodings are:
2560 Single 7-bit-byte characters like ASCII and the ASCII-compatible
2561 parts of ISO-8859-X (this is what C<guestfs_strings> uses).
2565 Single 8-bit-byte characters.
2569 16-bit big endian strings such as those encoded in
2570 UTF-16BE or UCS-2BE.
2572 =item l (lower case letter L)
2574 16-bit little endian such as UTF-16LE and UCS-2LE.
2575 This is useful for examining binaries in Windows guests.
2579 32-bit big endian such as UCS-4BE.
2583 32-bit little endian such as UCS-4LE.
2587 The returned strings are transcoded to UTF-8.");
2589 ("hexdump", (RString "dump", [Pathname "path"]), 96, [ProtocolLimitWarning],
2590 [InitISOFS, Always, TestOutput (
2591 [["hexdump"; "/known-4"]], "00000000 61 62 63 0a 64 65 66 0a 67 68 69 |abc.def.ghi|\n0000000b\n");
2592 (* Test for RHBZ#501888c2 regression which caused large hexdump
2593 * commands to segfault.
2595 InitISOFS, Always, TestRun (
2596 [["hexdump"; "/100krandom"]]);
2597 (* Test for RHBZ#579608, absolute symbolic links. *)
2598 InitISOFS, Always, TestRun (
2599 [["hexdump"; "/abssymlink"]])],
2600 "dump a file in hexadecimal",
2602 This runs C<hexdump -C> on the given C<path>. The result is
2603 the human-readable, canonical hex dump of the file.");
2605 ("zerofree", (RErr, [Device "device"]), 97, [Optional "zerofree"],
2606 [InitNone, Always, TestOutput (
2607 [["part_disk"; "/dev/sda"; "mbr"];
2608 ["mkfs"; "ext3"; "/dev/sda1"];
2609 ["mount_options"; ""; "/dev/sda1"; "/"];
2610 ["write"; "/new"; "test file"];
2611 ["umount"; "/dev/sda1"];
2612 ["zerofree"; "/dev/sda1"];
2613 ["mount_options"; ""; "/dev/sda1"; "/"];
2614 ["cat"; "/new"]], "test file")],
2615 "zero unused inodes and disk blocks on ext2/3 filesystem",
2617 This runs the I<zerofree> program on C<device>. This program
2618 claims to zero unused inodes and disk blocks on an ext2/3
2619 filesystem, thus making it possible to compress the filesystem
2622 You should B<not> run this program if the filesystem is
2625 It is possible that using this program can damage the filesystem
2626 or data on the filesystem.");
2628 ("pvresize", (RErr, [Device "device"]), 98, [Optional "lvm2"],
2630 "resize an LVM physical volume",
2632 This resizes (expands or shrinks) an existing LVM physical
2633 volume to match the new size of the underlying device.");
2635 ("sfdisk_N", (RErr, [Device "device"; Int "partnum";
2636 Int "cyls"; Int "heads"; Int "sectors";
2637 String "line"]), 99, [DangerWillRobinson],
2639 "modify a single partition on a block device",
2641 This runs L<sfdisk(8)> option to modify just the single
2642 partition C<n> (note: C<n> counts from 1).
2644 For other parameters, see C<guestfs_sfdisk>. You should usually
2645 pass C<0> for the cyls/heads/sectors parameters.
2647 See also: C<guestfs_part_add>");
2649 ("sfdisk_l", (RString "partitions", [Device "device"]), 100, [],
2651 "display the partition table",
2653 This displays the partition table on C<device>, in the
2654 human-readable output of the L<sfdisk(8)> command. It is
2655 not intended to be parsed.
2657 See also: C<guestfs_part_list>");
2659 ("sfdisk_kernel_geometry", (RString "partitions", [Device "device"]), 101, [],
2661 "display the kernel geometry",
2663 This displays the kernel's idea of the geometry of C<device>.
2665 The result is in human-readable format, and not designed to
2668 ("sfdisk_disk_geometry", (RString "partitions", [Device "device"]), 102, [],
2670 "display the disk geometry from the partition table",
2672 This displays the disk geometry of C<device> read from the
2673 partition table. Especially in the case where the underlying
2674 block device has been resized, this can be different from the
2675 kernel's idea of the geometry (see C<guestfs_sfdisk_kernel_geometry>).
2677 The result is in human-readable format, and not designed to
2680 ("vg_activate_all", (RErr, [Bool "activate"]), 103, [Optional "lvm2"],
2682 "activate or deactivate all volume groups",
2684 This command activates or (if C<activate> is false) deactivates
2685 all logical volumes in all volume groups.
2686 If activated, then they are made known to the
2687 kernel, ie. they appear as C</dev/mapper> devices. If deactivated,
2688 then those devices disappear.
2690 This command is the same as running C<vgchange -a y|n>");
2692 ("vg_activate", (RErr, [Bool "activate"; StringList "volgroups"]), 104, [Optional "lvm2"],
2694 "activate or deactivate some volume groups",
2696 This command activates or (if C<activate> is false) deactivates
2697 all logical volumes in the listed volume groups C<volgroups>.
2698 If activated, then they are made known to the
2699 kernel, ie. they appear as C</dev/mapper> devices. If deactivated,
2700 then those devices disappear.
2702 This command is the same as running C<vgchange -a y|n volgroups...>
2704 Note that if C<volgroups> is an empty list then B<all> volume groups
2705 are activated or deactivated.");
2707 ("lvresize", (RErr, [Device "device"; Int "mbytes"]), 105, [Optional "lvm2"],
2708 [InitNone, Always, TestOutput (
2709 [["part_disk"; "/dev/sda"; "mbr"];
2710 ["pvcreate"; "/dev/sda1"];
2711 ["vgcreate"; "VG"; "/dev/sda1"];
2712 ["lvcreate"; "LV"; "VG"; "10"];
2713 ["mkfs"; "ext2"; "/dev/VG/LV"];
2714 ["mount_options"; ""; "/dev/VG/LV"; "/"];
2715 ["write"; "/new"; "test content"];
2717 ["lvresize"; "/dev/VG/LV"; "20"];
2718 ["e2fsck_f"; "/dev/VG/LV"];
2719 ["resize2fs"; "/dev/VG/LV"];
2720 ["mount_options"; ""; "/dev/VG/LV"; "/"];
2721 ["cat"; "/new"]], "test content");
2722 InitNone, Always, TestRun (
2723 (* Make an LV smaller to test RHBZ#587484. *)
2724 [["part_disk"; "/dev/sda"; "mbr"];
2725 ["pvcreate"; "/dev/sda1"];
2726 ["vgcreate"; "VG"; "/dev/sda1"];
2727 ["lvcreate"; "LV"; "VG"; "20"];
2728 ["lvresize"; "/dev/VG/LV"; "10"]])],
2729 "resize an LVM logical volume",
2731 This resizes (expands or shrinks) an existing LVM logical
2732 volume to C<mbytes>. When reducing, data in the reduced part
2735 ("resize2fs", (RErr, [Device "device"]), 106, [],
2736 [], (* lvresize tests this *)
2737 "resize an ext2, ext3 or ext4 filesystem",
2739 This resizes an ext2, ext3 or ext4 filesystem to match the size of
2740 the underlying device.
2742 I<Note:> It is sometimes required that you run C<guestfs_e2fsck_f>
2743 on the C<device> before calling this command. For unknown reasons
2744 C<resize2fs> sometimes gives an error about this and sometimes not.
2745 In any case, it is always safe to call C<guestfs_e2fsck_f> before
2746 calling this function.");
2748 ("find", (RStringList "names", [Pathname "directory"]), 107, [ProtocolLimitWarning],
2749 [InitBasicFS, Always, TestOutputList (
2750 [["find"; "/"]], ["lost+found"]);
2751 InitBasicFS, Always, TestOutputList (
2755 ["find"; "/"]], ["a"; "b"; "b/c"; "lost+found"]);
2756 InitBasicFS, Always, TestOutputList (
2757 [["mkdir_p"; "/a/b/c"];
2758 ["touch"; "/a/b/c/d"];
2759 ["find"; "/a/b/"]], ["c"; "c/d"])],
2760 "find all files and directories",
2762 This command lists out all files and directories, recursively,
2763 starting at C<directory>. It is essentially equivalent to
2764 running the shell command C<find directory -print> but some
2765 post-processing happens on the output, described below.
2767 This returns a list of strings I<without any prefix>. Thus
2768 if the directory structure was:
2774 then the returned list from C<guestfs_find> C</tmp> would be
2782 If C<directory> is not a directory, then this command returns
2785 The returned list is sorted.
2787 See also C<guestfs_find0>.");
2789 ("e2fsck_f", (RErr, [Device "device"]), 108, [],
2790 [], (* lvresize tests this *)
2791 "check an ext2/ext3 filesystem",
2793 This runs C<e2fsck -p -f device>, ie. runs the ext2/ext3
2794 filesystem checker on C<device>, noninteractively (C<-p>),
2795 even if the filesystem appears to be clean (C<-f>).
2797 This command is only needed because of C<guestfs_resize2fs>
2798 (q.v.). Normally you should use C<guestfs_fsck>.");
2800 ("sleep", (RErr, [Int "secs"]), 109, [],
2801 [InitNone, Always, TestRun (
2803 "sleep for some seconds",
2805 Sleep for C<secs> seconds.");
2807 ("ntfs_3g_probe", (RInt "status", [Bool "rw"; Device "device"]), 110, [Optional "ntfs3g"],
2808 [InitNone, Always, TestOutputInt (
2809 [["part_disk"; "/dev/sda"; "mbr"];
2810 ["mkfs"; "ntfs"; "/dev/sda1"];
2811 ["ntfs_3g_probe"; "true"; "/dev/sda1"]], 0);
2812 InitNone, Always, TestOutputInt (
2813 [["part_disk"; "/dev/sda"; "mbr"];
2814 ["mkfs"; "ext2"; "/dev/sda1"];
2815 ["ntfs_3g_probe"; "true"; "/dev/sda1"]], 12)],
2816 "probe NTFS volume",
2818 This command runs the L<ntfs-3g.probe(8)> command which probes
2819 an NTFS C<device> for mountability. (Not all NTFS volumes can
2820 be mounted read-write, and some cannot be mounted at all).
2822 C<rw> is a boolean flag. Set it to true if you want to test
2823 if the volume can be mounted read-write. Set it to false if
2824 you want to test if the volume can be mounted read-only.
2826 The return value is an integer which C<0> if the operation
2827 would succeed, or some non-zero value documented in the
2828 L<ntfs-3g.probe(8)> manual page.");
2830 ("sh", (RString "output", [String "command"]), 111, [],
2831 [], (* XXX needs tests *)
2832 "run a command via the shell",
2834 This call runs a command from the guest filesystem via the
2837 This is like C<guestfs_command>, but passes the command to:
2839 /bin/sh -c \"command\"
2841 Depending on the guest's shell, this usually results in
2842 wildcards being expanded, shell expressions being interpolated
2845 All the provisos about C<guestfs_command> apply to this call.");
2847 ("sh_lines", (RStringList "lines", [String "command"]), 112, [],
2848 [], (* XXX needs tests *)
2849 "run a command via the shell returning lines",
2851 This is the same as C<guestfs_sh>, but splits the result
2852 into a list of lines.
2854 See also: C<guestfs_command_lines>");
2856 ("glob_expand", (RStringList "paths", [Pathname "pattern"]), 113, [],
2857 (* Use Pathname here, and hence ABS_PATH (pattern,... in generated
2858 * code in stubs.c, since all valid glob patterns must start with "/".
2859 * There is no concept of "cwd" in libguestfs, hence no "."-relative names.
2861 [InitBasicFS, Always, TestOutputList (
2862 [["mkdir_p"; "/a/b/c"];
2863 ["touch"; "/a/b/c/d"];
2864 ["touch"; "/a/b/c/e"];
2865 ["glob_expand"; "/a/b/c/*"]], ["/a/b/c/d"; "/a/b/c/e"]);
2866 InitBasicFS, Always, TestOutputList (
2867 [["mkdir_p"; "/a/b/c"];
2868 ["touch"; "/a/b/c/d"];
2869 ["touch"; "/a/b/c/e"];
2870 ["glob_expand"; "/a/*/c/*"]], ["/a/b/c/d"; "/a/b/c/e"]);
2871 InitBasicFS, Always, TestOutputList (
2872 [["mkdir_p"; "/a/b/c"];
2873 ["touch"; "/a/b/c/d"];
2874 ["touch"; "/a/b/c/e"];
2875 ["glob_expand"; "/a/*/x/*"]], [])],
2876 "expand a wildcard path",
2878 This command searches for all the pathnames matching
2879 C<pattern> according to the wildcard expansion rules
2882 If no paths match, then this returns an empty list
2883 (note: not an error).
2885 It is just a wrapper around the C L<glob(3)> function
2886 with flags C<GLOB_MARK|GLOB_BRACE>.
2887 See that manual page for more details.");
2889 ("scrub_device", (RErr, [Device "device"]), 114, [DangerWillRobinson; Optional "scrub"],
2890 [InitNone, Always, TestRun ( (* use /dev/sdc because it's smaller *)
2891 [["scrub_device"; "/dev/sdc"]])],
2892 "scrub (securely wipe) a device",
2894 This command writes patterns over C<device> to make data retrieval
2897 It is an interface to the L<scrub(1)> program. See that
2898 manual page for more details.");
2900 ("scrub_file", (RErr, [Pathname "file"]), 115, [Optional "scrub"],
2901 [InitBasicFS, Always, TestRun (
2902 [["write"; "/file"; "content"];
2903 ["scrub_file"; "/file"]])],
2904 "scrub (securely wipe) a file",
2906 This command writes patterns over a file to make data retrieval
2909 The file is I<removed> after scrubbing.
2911 It is an interface to the L<scrub(1)> program. See that
2912 manual page for more details.");
2914 ("scrub_freespace", (RErr, [Pathname "dir"]), 116, [Optional "scrub"],
2915 [], (* XXX needs testing *)
2916 "scrub (securely wipe) free space",
2918 This command creates the directory C<dir> and then fills it
2919 with files until the filesystem is full, and scrubs the files
2920 as for C<guestfs_scrub_file>, and deletes them.
2921 The intention is to scrub any free space on the partition
2924 It is an interface to the L<scrub(1)> program. See that
2925 manual page for more details.");
2927 ("mkdtemp", (RString "dir", [Pathname "template"]), 117, [],
2928 [InitBasicFS, Always, TestRun (
2930 ["mkdtemp"; "/tmp/tmpXXXXXX"]])],
2931 "create a temporary directory",
2933 This command creates a temporary directory. The
2934 C<template> parameter should be a full pathname for the
2935 temporary directory name with the final six characters being
2938 For example: \"/tmp/myprogXXXXXX\" or \"/Temp/myprogXXXXXX\",
2939 the second one being suitable for Windows filesystems.
2941 The name of the temporary directory that was created
2944 The temporary directory is created with mode 0700
2945 and is owned by root.
2947 The caller is responsible for deleting the temporary
2948 directory and its contents after use.
2950 See also: L<mkdtemp(3)>");
2952 ("wc_l", (RInt "lines", [Pathname "path"]), 118, [],
2953 [InitISOFS, Always, TestOutputInt (
2954 [["wc_l"; "/10klines"]], 10000);
2955 (* Test for RHBZ#579608, absolute symbolic links. *)
2956 InitISOFS, Always, TestOutputInt (
2957 [["wc_l"; "/abssymlink"]], 10000)],
2958 "count lines in a file",
2960 This command counts the lines in a file, using the
2961 C<wc -l> external command.");
2963 ("wc_w", (RInt "words", [Pathname "path"]), 119, [],
2964 [InitISOFS, Always, TestOutputInt (
2965 [["wc_w"; "/10klines"]], 10000)],
2966 "count words in a file",
2968 This command counts the words in a file, using the
2969 C<wc -w> external command.");
2971 ("wc_c", (RInt "chars", [Pathname "path"]), 120, [],
2972 [InitISOFS, Always, TestOutputInt (
2973 [["wc_c"; "/100kallspaces"]], 102400)],
2974 "count characters in a file",
2976 This command counts the characters in a file, using the
2977 C<wc -c> external command.");
2979 ("head", (RStringList "lines", [Pathname "path"]), 121, [ProtocolLimitWarning],
2980 [InitISOFS, Always, TestOutputList (
2981 [["head"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz";"3abcdefghijklmnopqrstuvwxyz";"4abcdefghijklmnopqrstuvwxyz";"5abcdefghijklmnopqrstuvwxyz";"6abcdefghijklmnopqrstuvwxyz";"7abcdefghijklmnopqrstuvwxyz";"8abcdefghijklmnopqrstuvwxyz";"9abcdefghijklmnopqrstuvwxyz"]);
2982 (* Test for RHBZ#579608, absolute symbolic links. *)
2983 InitISOFS, Always, TestOutputList (
2984 [["head"; "/abssymlink"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz";"3abcdefghijklmnopqrstuvwxyz";"4abcdefghijklmnopqrstuvwxyz";"5abcdefghijklmnopqrstuvwxyz";"6abcdefghijklmnopqrstuvwxyz";"7abcdefghijklmnopqrstuvwxyz";"8abcdefghijklmnopqrstuvwxyz";"9abcdefghijklmnopqrstuvwxyz"])],
2985 "return first 10 lines of a file",
2987 This command returns up to the first 10 lines of a file as
2988 a list of strings.");
2990 ("head_n", (RStringList "lines", [Int "nrlines"; Pathname "path"]), 122, [ProtocolLimitWarning],
2991 [InitISOFS, Always, TestOutputList (
2992 [["head_n"; "3"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz"]);
2993 InitISOFS, Always, TestOutputList (
2994 [["head_n"; "-9997"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz"]);
2995 InitISOFS, Always, TestOutputList (
2996 [["head_n"; "0"; "/10klines"]], [])],
2997 "return first N lines of a file",
2999 If the parameter C<nrlines> is a positive number, this returns the first
3000 C<nrlines> lines of the file C<path>.
3002 If the parameter C<nrlines> is a negative number, this returns lines
3003 from the file C<path>, excluding the last C<nrlines> lines.
3005 If the parameter C<nrlines> is zero, this returns an empty list.");
3007 ("tail", (RStringList "lines", [Pathname "path"]), 123, [ProtocolLimitWarning],
3008 [InitISOFS, Always, TestOutputList (
3009 [["tail"; "/10klines"]], ["9990abcdefghijklmnopqrstuvwxyz";"9991abcdefghijklmnopqrstuvwxyz";"9992abcdefghijklmnopqrstuvwxyz";"9993abcdefghijklmnopqrstuvwxyz";"9994abcdefghijklmnopqrstuvwxyz";"9995abcdefghijklmnopqrstuvwxyz";"9996abcdefghijklmnopqrstuvwxyz";"9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"])],
3010 "return last 10 lines of a file",
3012 This command returns up to the last 10 lines of a file as
3013 a list of strings.");
3015 ("tail_n", (RStringList "lines", [Int "nrlines"; Pathname "path"]), 124, [ProtocolLimitWarning],
3016 [InitISOFS, Always, TestOutputList (
3017 [["tail_n"; "3"; "/10klines"]], ["9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"]);
3018 InitISOFS, Always, TestOutputList (
3019 [["tail_n"; "-9998"; "/10klines"]], ["9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"]);
3020 InitISOFS, Always, TestOutputList (
3021 [["tail_n"; "0"; "/10klines"]], [])],
3022 "return last N lines of a file",
3024 If the parameter C<nrlines> is a positive number, this returns the last
3025 C<nrlines> lines of the file C<path>.
3027 If the parameter C<nrlines> is a negative number, this returns lines
3028 from the file C<path>, starting with the C<-nrlines>th line.
3030 If the parameter C<nrlines> is zero, this returns an empty list.");
3032 ("df", (RString "output", []), 125, [],
3033 [], (* XXX Tricky to test because it depends on the exact format
3034 * of the 'df' command and other imponderables.
3036 "report file system disk space usage",
3038 This command runs the C<df> command to report disk space used.
3040 This command is mostly useful for interactive sessions. It
3041 is I<not> intended that you try to parse the output string.
3042 Use C<statvfs> from programs.");
3044 ("df_h", (RString "output", []), 126, [],
3045 [], (* XXX Tricky to test because it depends on the exact format
3046 * of the 'df' command and other imponderables.
3048 "report file system disk space usage (human readable)",
3050 This command runs the C<df -h> command to report disk space used
3051 in human-readable format.
3053 This command is mostly useful for interactive sessions. It
3054 is I<not> intended that you try to parse the output string.
3055 Use C<statvfs> from programs.");
3057 ("du", (RInt64 "sizekb", [Pathname "path"]), 127, [],
3058 [InitISOFS, Always, TestOutputInt (
3059 [["du"; "/directory"]], 2 (* ISO fs blocksize is 2K *))],
3060 "estimate file space usage",
3062 This command runs the C<du -s> command to estimate file space
3065 C<path> can be a file or a directory. If C<path> is a directory
3066 then the estimate includes the contents of the directory and all
3067 subdirectories (recursively).
3069 The result is the estimated size in I<kilobytes>
3070 (ie. units of 1024 bytes).");
3072 ("initrd_list", (RStringList "filenames", [Pathname "path"]), 128, [],
3073 [InitISOFS, Always, TestOutputList (
3074 [["initrd_list"; "/initrd"]], ["empty";"known-1";"known-2";"known-3";"known-4"; "known-5"])],
3075 "list files in an initrd",
3077 This command lists out files contained in an initrd.
3079 The files are listed without any initial C</> character. The
3080 files are listed in the order they appear (not necessarily
3081 alphabetical). Directory names are listed as separate items.
3083 Old Linux kernels (2.4 and earlier) used a compressed ext2
3084 filesystem as initrd. We I<only> support the newer initramfs
3085 format (compressed cpio files).");
3087 ("mount_loop", (RErr, [Pathname "file"; Pathname "mountpoint"]), 129, [],
3089 "mount a file using the loop device",
3091 This command lets you mount C<file> (a filesystem image
3092 in a file) on a mount point. It is entirely equivalent to
3093 the command C<mount -o loop file mountpoint>.");
3095 ("mkswap", (RErr, [Device "device"]), 130, [],
3096 [InitEmpty, Always, TestRun (
3097 [["part_disk"; "/dev/sda"; "mbr"];
3098 ["mkswap"; "/dev/sda1"]])],
3099 "create a swap partition",
3101 Create a swap partition on C<device>.");
3103 ("mkswap_L", (RErr, [String "label"; Device "device"]), 131, [],
3104 [InitEmpty, Always, TestRun (
3105 [["part_disk"; "/dev/sda"; "mbr"];
3106 ["mkswap_L"; "hello"; "/dev/sda1"]])],
3107 "create a swap partition with a label",
3109 Create a swap partition on C<device> with label C<label>.
3111 Note that you cannot attach a swap label to a block device
3112 (eg. C</dev/sda>), just to a partition. This appears to be
3113 a limitation of the kernel or swap tools.");
3115 ("mkswap_U", (RErr, [String "uuid"; Device "device"]), 132, [Optional "linuxfsuuid"],
3116 (let uuid = uuidgen () in
3117 [InitEmpty, Always, TestRun (
3118 [["part_disk"; "/dev/sda"; "mbr"];
3119 ["mkswap_U"; uuid; "/dev/sda1"]])]),
3120 "create a swap partition with an explicit UUID",
3122 Create a swap partition on C<device> with UUID C<uuid>.");
3124 ("mknod", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"]), 133, [Optional "mknod"],
3125 [InitBasicFS, Always, TestOutputStruct (
3126 [["mknod"; "0o10777"; "0"; "0"; "/node"];
3127 (* NB: default umask 022 means 0777 -> 0755 in these tests *)
3128 ["stat"; "/node"]], [CompareWithInt ("mode", 0o10755)]);
3129 InitBasicFS, Always, TestOutputStruct (
3130 [["mknod"; "0o60777"; "66"; "99"; "/node"];
3131 ["stat"; "/node"]], [CompareWithInt ("mode", 0o60755)])],
3132 "make block, character or FIFO devices",
3134 This call creates block or character special devices, or
3135 named pipes (FIFOs).
3137 The C<mode> parameter should be the mode, using the standard
3138 constants. C<devmajor> and C<devminor> are the
3139 device major and minor numbers, only used when creating block
3140 and character special devices.
3142 Note that, just like L<mknod(2)>, the mode must be bitwise
3143 OR'd with S_IFBLK, S_IFCHR, S_IFIFO or S_IFSOCK (otherwise this call
3144 just creates a regular file). These constants are
3145 available in the standard Linux header files, or you can use
3146 C<guestfs_mknod_b>, C<guestfs_mknod_c> or C<guestfs_mkfifo>
3147 which are wrappers around this command which bitwise OR
3148 in the appropriate constant for you.
3150 The mode actually set is affected by the umask.");
3152 ("mkfifo", (RErr, [Int "mode"; Pathname "path"]), 134, [Optional "mknod"],
3153 [InitBasicFS, Always, TestOutputStruct (
3154 [["mkfifo"; "0o777"; "/node"];
3155 ["stat"; "/node"]], [CompareWithInt ("mode", 0o10755)])],
3156 "make FIFO (named pipe)",
3158 This call creates a FIFO (named pipe) called C<path> with
3159 mode C<mode>. It is just a convenient wrapper around
3162 The mode actually set is affected by the umask.");
3164 ("mknod_b", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"]), 135, [Optional "mknod"],
3165 [InitBasicFS, Always, TestOutputStruct (
3166 [["mknod_b"; "0o777"; "99"; "66"; "/node"];
3167 ["stat"; "/node"]], [CompareWithInt ("mode", 0o60755)])],
3168 "make block device node",
3170 This call creates a block device node called C<path> with
3171 mode C<mode> and device major/minor C<devmajor> and C<devminor>.
3172 It is just a convenient wrapper around C<guestfs_mknod>.
3174 The mode actually set is affected by the umask.");
3176 ("mknod_c", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"]), 136, [Optional "mknod"],
3177 [InitBasicFS, Always, TestOutputStruct (
3178 [["mknod_c"; "0o777"; "99"; "66"; "/node"];
3179 ["stat"; "/node"]], [CompareWithInt ("mode", 0o20755)])],
3180 "make char device node",
3182 This call creates a char device node called C<path> with
3183 mode C<mode> and device major/minor C<devmajor> and C<devminor>.
3184 It is just a convenient wrapper around C<guestfs_mknod>.
3186 The mode actually set is affected by the umask.");
3188 ("umask", (RInt "oldmask", [Int "mask"]), 137, [FishOutput FishOutputOctal],
3189 [InitEmpty, Always, TestOutputInt (
3190 [["umask"; "0o22"]], 0o22)],
3191 "set file mode creation mask (umask)",
3193 This function sets the mask used for creating new files and
3194 device nodes to C<mask & 0777>.
3196 Typical umask values would be C<022> which creates new files
3197 with permissions like \"-rw-r--r--\" or \"-rwxr-xr-x\", and
3198 C<002> which creates new files with permissions like
3199 \"-rw-rw-r--\" or \"-rwxrwxr-x\".
3201 The default umask is C<022>. This is important because it
3202 means that directories and device nodes will be created with
3203 C<0644> or C<0755> mode even if you specify C<0777>.
3205 See also C<guestfs_get_umask>,
3206 L<umask(2)>, C<guestfs_mknod>, C<guestfs_mkdir>.
3208 This call returns the previous umask.");
3210 ("readdir", (RStructList ("entries", "dirent"), [Pathname "dir"]), 138, [],
3212 "read directories entries",
3214 This returns the list of directory entries in directory C<dir>.
3216 All entries in the directory are returned, including C<.> and
3217 C<..>. The entries are I<not> sorted, but returned in the same
3218 order as the underlying filesystem.
3220 Also this call returns basic file type information about each
3221 file. The C<ftyp> field will contain one of the following characters:
3259 The L<readdir(3)> call returned a C<d_type> field with an
3264 This function is primarily intended for use by programs. To
3265 get a simple list of names, use C<guestfs_ls>. To get a printable
3266 directory for human consumption, use C<guestfs_ll>.");
3268 ("sfdiskM", (RErr, [Device "device"; StringList "lines"]), 139, [DangerWillRobinson],
3270 "create partitions on a block device",
3272 This is a simplified interface to the C<guestfs_sfdisk>
3273 command, where partition sizes are specified in megabytes
3274 only (rounded to the nearest cylinder) and you don't need
3275 to specify the cyls, heads and sectors parameters which
3276 were rarely if ever used anyway.
3278 See also: C<guestfs_sfdisk>, the L<sfdisk(8)> manpage
3279 and C<guestfs_part_disk>");
3281 ("zfile", (RString "description", [String "meth"; Pathname "path"]), 140, [DeprecatedBy "file"],
3283 "determine file type inside a compressed file",
3285 This command runs C<file> after first decompressing C<path>
3288 C<method> must be one of C<gzip>, C<compress> or C<bzip2>.
3290 Since 1.0.63, use C<guestfs_file> instead which can now
3291 process compressed files.");
3293 ("getxattrs", (RStructList ("xattrs", "xattr"), [Pathname "path"]), 141, [Optional "linuxxattrs"],
3295 "list extended attributes of a file or directory",
3297 This call lists the extended attributes of the file or directory
3300 At the system call level, this is a combination of the
3301 L<listxattr(2)> and L<getxattr(2)> calls.
3303 See also: C<guestfs_lgetxattrs>, L<attr(5)>.");
3305 ("lgetxattrs", (RStructList ("xattrs", "xattr"), [Pathname "path"]), 142, [Optional "linuxxattrs"],
3307 "list extended attributes of a file or directory",
3309 This is the same as C<guestfs_getxattrs>, but if C<path>
3310 is a symbolic link, then it returns the extended attributes
3311 of the link itself.");
3313 ("setxattr", (RErr, [String "xattr";
3314 String "val"; Int "vallen"; (* will be BufferIn *)
3315 Pathname "path"]), 143, [Optional "linuxxattrs"],
3317 "set extended attribute of a file or directory",
3319 This call sets the extended attribute named C<xattr>
3320 of the file C<path> to the value C<val> (of length C<vallen>).
3321 The value is arbitrary 8 bit data.
3323 See also: C<guestfs_lsetxattr>, L<attr(5)>.");
3325 ("lsetxattr", (RErr, [String "xattr";
3326 String "val"; Int "vallen"; (* will be BufferIn *)
3327 Pathname "path"]), 144, [Optional "linuxxattrs"],
3329 "set extended attribute of a file or directory",
3331 This is the same as C<guestfs_setxattr>, but if C<path>
3332 is a symbolic link, then it sets an extended attribute
3333 of the link itself.");
3335 ("removexattr", (RErr, [String "xattr"; Pathname "path"]), 145, [Optional "linuxxattrs"],
3337 "remove extended attribute of a file or directory",
3339 This call removes the extended attribute named C<xattr>
3340 of the file C<path>.
3342 See also: C<guestfs_lremovexattr>, L<attr(5)>.");
3344 ("lremovexattr", (RErr, [String "xattr"; Pathname "path"]), 146, [Optional "linuxxattrs"],
3346 "remove extended attribute of a file or directory",
3348 This is the same as C<guestfs_removexattr>, but if C<path>
3349 is a symbolic link, then it removes an extended attribute
3350 of the link itself.");
3352 ("mountpoints", (RHashtable "mps", []), 147, [],
3356 This call is similar to C<guestfs_mounts>. That call returns
3357 a list of devices. This one returns a hash table (map) of
3358 device name to directory where the device is mounted.");
3360 ("mkmountpoint", (RErr, [String "exemptpath"]), 148, [],
3361 (* This is a special case: while you would expect a parameter
3362 * of type "Pathname", that doesn't work, because it implies
3363 * NEED_ROOT in the generated calling code in stubs.c, and
3364 * this function cannot use NEED_ROOT.
3367 "create a mountpoint",
3369 C<guestfs_mkmountpoint> and C<guestfs_rmmountpoint> are
3370 specialized calls that can be used to create extra mountpoints
3371 before mounting the first filesystem.
3373 These calls are I<only> necessary in some very limited circumstances,
3374 mainly the case where you want to mount a mix of unrelated and/or
3375 read-only filesystems together.
3377 For example, live CDs often contain a \"Russian doll\" nest of
3378 filesystems, an ISO outer layer, with a squashfs image inside, with
3379 an ext2/3 image inside that. You can unpack this as follows
3382 add-ro Fedora-11-i686-Live.iso
3385 mkmountpoint /squash
3388 mount-loop /cd/LiveOS/squashfs.img /squash
3389 mount-loop /squash/LiveOS/ext3fs.img /ext3
3391 The inner filesystem is now unpacked under the /ext3 mountpoint.");
3393 ("rmmountpoint", (RErr, [String "exemptpath"]), 149, [],
3395 "remove a mountpoint",
3397 This calls removes a mountpoint that was previously created
3398 with C<guestfs_mkmountpoint>. See C<guestfs_mkmountpoint>
3399 for full details.");
3401 ("read_file", (RBufferOut "content", [Pathname "path"]), 150, [ProtocolLimitWarning],
3402 [InitISOFS, Always, TestOutputBuffer (
3403 [["read_file"; "/known-4"]], "abc\ndef\nghi");
3404 (* Test various near large, large and too large files (RHBZ#589039). *)
3405 InitBasicFS, Always, TestLastFail (
3407 ["truncate_size"; "/a"; "4194303"]; (* GUESTFS_MESSAGE_MAX - 1 *)
3408 ["read_file"; "/a"]]);
3409 InitBasicFS, Always, TestLastFail (
3411 ["truncate_size"; "/a"; "4194304"]; (* GUESTFS_MESSAGE_MAX *)
3412 ["read_file"; "/a"]]);
3413 InitBasicFS, Always, TestLastFail (
3415 ["truncate_size"; "/a"; "41943040"]; (* GUESTFS_MESSAGE_MAX * 10 *)
3416 ["read_file"; "/a"]])],
3419 This calls returns the contents of the file C<path> as a
3422 Unlike C<guestfs_cat>, this function can correctly
3423 handle files that contain embedded ASCII NUL characters.
3424 However unlike C<guestfs_download>, this function is limited
3425 in the total size of file that can be handled.");
3427 ("grep", (RStringList "lines", [String "regex"; Pathname "path"]), 151, [ProtocolLimitWarning],
3428 [InitISOFS, Always, TestOutputList (
3429 [["grep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"]);
3430 InitISOFS, Always, TestOutputList (
3431 [["grep"; "nomatch"; "/test-grep.txt"]], []);
3432 (* Test for RHBZ#579608, absolute symbolic links. *)
3433 InitISOFS, Always, TestOutputList (
3434 [["grep"; "nomatch"; "/abssymlink"]], [])],
3435 "return lines matching a pattern",
3437 This calls the external C<grep> program and returns the
3440 ("egrep", (RStringList "lines", [String "regex"; Pathname "path"]), 152, [ProtocolLimitWarning],
3441 [InitISOFS, Always, TestOutputList (
3442 [["egrep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"])],
3443 "return lines matching a pattern",
3445 This calls the external C<egrep> program and returns the
3448 ("fgrep", (RStringList "lines", [String "pattern"; Pathname "path"]), 153, [ProtocolLimitWarning],
3449 [InitISOFS, Always, TestOutputList (
3450 [["fgrep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"])],
3451 "return lines matching a pattern",
3453 This calls the external C<fgrep> program and returns the
3456 ("grepi", (RStringList "lines", [String "regex"; Pathname "path"]), 154, [ProtocolLimitWarning],
3457 [InitISOFS, Always, TestOutputList (
3458 [["grepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])],
3459 "return lines matching a pattern",
3461 This calls the external C<grep -i> program and returns the
3464 ("egrepi", (RStringList "lines", [String "regex"; Pathname "path"]), 155, [ProtocolLimitWarning],
3465 [InitISOFS, Always, TestOutputList (
3466 [["egrepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])],
3467 "return lines matching a pattern",
3469 This calls the external C<egrep -i> program and returns the
3472 ("fgrepi", (RStringList "lines", [String "pattern"; Pathname "path"]), 156, [ProtocolLimitWarning],
3473 [InitISOFS, Always, TestOutputList (
3474 [["fgrepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])],
3475 "return lines matching a pattern",
3477 This calls the external C<fgrep -i> program and returns the
3480 ("zgrep", (RStringList "lines", [String "regex"; Pathname "path"]), 157, [ProtocolLimitWarning],
3481 [InitISOFS, Always, TestOutputList (
3482 [["zgrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])],
3483 "return lines matching a pattern",
3485 This calls the external C<zgrep> program and returns the
3488 ("zegrep", (RStringList "lines", [String "regex"; Pathname "path"]), 158, [ProtocolLimitWarning],
3489 [InitISOFS, Always, TestOutputList (
3490 [["zegrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])],
3491 "return lines matching a pattern",
3493 This calls the external C<zegrep> program and returns the
3496 ("zfgrep", (RStringList "lines", [String "pattern"; Pathname "path"]), 159, [ProtocolLimitWarning],
3497 [InitISOFS, Always, TestOutputList (
3498 [["zfgrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])],
3499 "return lines matching a pattern",
3501 This calls the external C<zfgrep> program and returns the
3504 ("zgrepi", (RStringList "lines", [String "regex"; Pathname "path"]), 160, [ProtocolLimitWarning],
3505 [InitISOFS, Always, TestOutputList (
3506 [["zgrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])],
3507 "return lines matching a pattern",
3509 This calls the external C<zgrep -i> program and returns the
3512 ("zegrepi", (RStringList "lines", [String "regex"; Pathname "path"]), 161, [ProtocolLimitWarning],
3513 [InitISOFS, Always, TestOutputList (
3514 [["zegrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])],
3515 "return lines matching a pattern",
3517 This calls the external C<zegrep -i> program and returns the
3520 ("zfgrepi", (RStringList "lines", [String "pattern"; Pathname "path"]), 162, [ProtocolLimitWarning],
3521 [InitISOFS, Always, TestOutputList (
3522 [["zfgrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])],
3523 "return lines matching a pattern",
3525 This calls the external C<zfgrep -i> program and returns the
3528 ("realpath", (RString "rpath", [Pathname "path"]), 163, [Optional "realpath"],
3529 [InitISOFS, Always, TestOutput (
3530 [["realpath"; "/../directory"]], "/directory")],
3531 "canonicalized absolute pathname",
3533 Return the canonicalized absolute pathname of C<path>. The
3534 returned path has no C<.>, C<..> or symbolic link path elements.");
3536 ("ln", (RErr, [String "target"; Pathname "linkname"]), 164, [],
3537 [InitBasicFS, Always, TestOutputStruct (
3540 ["stat"; "/b"]], [CompareWithInt ("nlink", 2)])],
3541 "create a hard link",
3543 This command creates a hard link using the C<ln> command.");
3545 ("ln_f", (RErr, [String "target"; Pathname "linkname"]), 165, [],
3546 [InitBasicFS, Always, TestOutputStruct (
3549 ["ln_f"; "/a"; "/b"];
3550 ["stat"; "/b"]], [CompareWithInt ("nlink", 2)])],
3551 "create a hard link",
3553 This command creates a hard link using the C<ln -f> command.
3554 The C<-f> option removes the link (C<linkname>) if it exists already.");
3556 ("ln_s", (RErr, [String "target"; Pathname "linkname"]), 166, [],
3557 [InitBasicFS, Always, TestOutputStruct (
3559 ["ln_s"; "a"; "/b"];
3560 ["lstat"; "/b"]], [CompareWithInt ("mode", 0o120777)])],
3561 "create a symbolic link",
3563 This command creates a symbolic link using the C<ln -s> command.");
3565 ("ln_sf", (RErr, [String "target"; Pathname "linkname"]), 167, [],
3566 [InitBasicFS, Always, TestOutput (
3567 [["mkdir_p"; "/a/b"];
3568 ["touch"; "/a/b/c"];
3569 ["ln_sf"; "../d"; "/a/b/c"];
3570 ["readlink"; "/a/b/c"]], "../d")],
3571 "create a symbolic link",
3573 This command creates a symbolic link using the C<ln -sf> command,
3574 The C<-f> option removes the link (C<linkname>) if it exists already.");
3576 ("readlink", (RString "link", [Pathname "path"]), 168, [],
3577 [] (* XXX tested above *),
3578 "read the target of a symbolic link",
3580 This command reads the target of a symbolic link.");
3582 ("fallocate", (RErr, [Pathname "path"; Int "len"]), 169, [DeprecatedBy "fallocate64"],
3583 [InitBasicFS, Always, TestOutputStruct (
3584 [["fallocate"; "/a"; "1000000"];
3585 ["stat"; "/a"]], [CompareWithInt ("size", 1_000_000)])],
3586 "preallocate a file in the guest filesystem",
3588 This command preallocates a file (containing zero bytes) named
3589 C<path> of size C<len> bytes. If the file exists already, it
3592 Do not confuse this with the guestfish-specific
3593 C<alloc> command which allocates a file in the host and
3594 attaches it as a device.");
3596 ("swapon_device", (RErr, [Device "device"]), 170, [],
3597 [InitPartition, Always, TestRun (
3598 [["mkswap"; "/dev/sda1"];
3599 ["swapon_device"; "/dev/sda1"];
3600 ["swapoff_device"; "/dev/sda1"]])],
3601 "enable swap on device",
3603 This command enables the libguestfs appliance to use the
3604 swap device or partition named C<device>. The increased
3605 memory is made available for all commands, for example
3606 those run using C<guestfs_command> or C<guestfs_sh>.
3608 Note that you should not swap to existing guest swap
3609 partitions unless you know what you are doing. They may
3610 contain hibernation information, or other information that
3611 the guest doesn't want you to trash. You also risk leaking
3612 information about the host to the guest this way. Instead,
3613 attach a new host device to the guest and swap on that.");
3615 ("swapoff_device", (RErr, [Device "device"]), 171, [],
3616 [], (* XXX tested by swapon_device *)
3617 "disable swap on device",
3619 This command disables the libguestfs appliance swap
3620 device or partition named C<device>.
3621 See C<guestfs_swapon_device>.");
3623 ("swapon_file", (RErr, [Pathname "file"]), 172, [],
3624 [InitBasicFS, Always, TestRun (
3625 [["fallocate"; "/swap"; "8388608"];
3626 ["mkswap_file"; "/swap"];
3627 ["swapon_file"; "/swap"];
3628 ["swapoff_file"; "/swap"]])],
3629 "enable swap on file",
3631 This command enables swap to a file.
3632 See C<guestfs_swapon_device> for other notes.");
3634 ("swapoff_file", (RErr, [Pathname "file"]), 173, [],
3635 [], (* XXX tested by swapon_file *)
3636 "disable swap on file",
3638 This command disables the libguestfs appliance swap on file.");
3640 ("swapon_label", (RErr, [String "label"]), 174, [],
3641 [InitEmpty, Always, TestRun (
3642 [["part_disk"; "/dev/sdb"; "mbr"];
3643 ["mkswap_L"; "swapit"; "/dev/sdb1"];
3644 ["swapon_label"; "swapit"];
3645 ["swapoff_label"; "swapit"];
3646 ["zero"; "/dev/sdb"];
3647 ["blockdev_rereadpt"; "/dev/sdb"]])],
3648 "enable swap on labeled swap partition",
3650 This command enables swap to a labeled swap partition.
3651 See C<guestfs_swapon_device> for other notes.");
3653 ("swapoff_label", (RErr, [String "label"]), 175, [],
3654 [], (* XXX tested by swapon_label *)
3655 "disable swap on labeled swap partition",
3657 This command disables the libguestfs appliance swap on
3658 labeled swap partition.");
3660 ("swapon_uuid", (RErr, [String "uuid"]), 176, [Optional "linuxfsuuid"],
3661 (let uuid = uuidgen () in
3662 [InitEmpty, Always, TestRun (
3663 [["mkswap_U"; uuid; "/dev/sdb"];
3664 ["swapon_uuid"; uuid];
3665 ["swapoff_uuid"; uuid]])]),
3666 "enable swap on swap partition by UUID",
3668 This command enables swap to a swap partition with the given UUID.
3669 See C<guestfs_swapon_device> for other notes.");
3671 ("swapoff_uuid", (RErr, [String "uuid"]), 177, [Optional "linuxfsuuid"],
3672 [], (* XXX tested by swapon_uuid *)
3673 "disable swap on swap partition by UUID",
3675 This command disables the libguestfs appliance swap partition
3676 with the given UUID.");
3678 ("mkswap_file", (RErr, [Pathname "path"]), 178, [],
3679 [InitBasicFS, Always, TestRun (
3680 [["fallocate"; "/swap"; "8388608"];
3681 ["mkswap_file"; "/swap"]])],
3682 "create a swap file",
3686 This command just writes a swap file signature to an existing
3687 file. To create the file itself, use something like C<guestfs_fallocate>.");
3689 ("inotify_init", (RErr, [Int "maxevents"]), 179, [Optional "inotify"],
3690 [InitISOFS, Always, TestRun (
3691 [["inotify_init"; "0"]])],
3692 "create an inotify handle",
3694 This command creates a new inotify handle.
3695 The inotify subsystem can be used to notify events which happen to
3696 objects in the guest filesystem.
3698 C<maxevents> is the maximum number of events which will be
3699 queued up between calls to C<guestfs_inotify_read> or
3700 C<guestfs_inotify_files>.
3701 If this is passed as C<0>, then the kernel (or previously set)
3702 default is used. For Linux 2.6.29 the default was 16384 events.
3703 Beyond this limit, the kernel throws away events, but records
3704 the fact that it threw them away by setting a flag
3705 C<IN_Q_OVERFLOW> in the returned structure list (see
3706 C<guestfs_inotify_read>).
3708 Before any events are generated, you have to add some
3709 watches to the internal watch list. See:
3710 C<guestfs_inotify_add_watch>,
3711 C<guestfs_inotify_rm_watch> and
3712 C<guestfs_inotify_watch_all>.
3714 Queued up events should be read periodically by calling
3715 C<guestfs_inotify_read>
3716 (or C<guestfs_inotify_files> which is just a helpful
3717 wrapper around C<guestfs_inotify_read>). If you don't
3718 read the events out often enough then you risk the internal
3721 The handle should be closed after use by calling
3722 C<guestfs_inotify_close>. This also removes any
3723 watches automatically.
3725 See also L<inotify(7)> for an overview of the inotify interface
3726 as exposed by the Linux kernel, which is roughly what we expose
3727 via libguestfs. Note that there is one global inotify handle
3728 per libguestfs instance.");
3730 ("inotify_add_watch", (RInt64 "wd", [Pathname "path"; Int "mask"]), 180, [Optional "inotify"],
3731 [InitBasicFS, Always, TestOutputList (
3732 [["inotify_init"; "0"];
3733 ["inotify_add_watch"; "/"; "1073741823"];
3736 ["inotify_files"]], ["a"; "b"])],
3737 "add an inotify watch",
3739 Watch C<path> for the events listed in C<mask>.
3741 Note that if C<path> is a directory then events within that
3742 directory are watched, but this does I<not> happen recursively
3743 (in subdirectories).
3745 Note for non-C or non-Linux callers: the inotify events are
3746 defined by the Linux kernel ABI and are listed in
3747 C</usr/include/sys/inotify.h>.");
3749 ("inotify_rm_watch", (RErr, [Int(*XXX64*) "wd"]), 181, [Optional "inotify"],
3751 "remove an inotify watch",
3753 Remove a previously defined inotify watch.
3754 See C<guestfs_inotify_add_watch>.");
3756 ("inotify_read", (RStructList ("events", "inotify_event"), []), 182, [Optional "inotify"],
3758 "return list of inotify events",
3760 Return the complete queue of events that have happened
3761 since the previous read call.
3763 If no events have happened, this returns an empty list.
3765 I<Note>: In order to make sure that all events have been
3766 read, you must call this function repeatedly until it
3767 returns an empty list. The reason is that the call will
3768 read events up to the maximum appliance-to-host message
3769 size and leave remaining events in the queue.");
3771 ("inotify_files", (RStringList "paths", []), 183, [Optional "inotify"],
3773 "return list of watched files that had events",
3775 This function is a helpful wrapper around C<guestfs_inotify_read>
3776 which just returns a list of pathnames of objects that were
3777 touched. The returned pathnames are sorted and deduplicated.");
3779 ("inotify_close", (RErr, []), 184, [Optional "inotify"],
3781 "close the inotify handle",
3783 This closes the inotify handle which was previously
3784 opened by inotify_init. It removes all watches, throws
3785 away any pending events, and deallocates all resources.");
3787 ("setcon", (RErr, [String "context"]), 185, [Optional "selinux"],
3789 "set SELinux security context",
3791 This sets the SELinux security context of the daemon
3792 to the string C<context>.
3794 See the documentation about SELINUX in L<guestfs(3)>.");
3796 ("getcon", (RString "context", []), 186, [Optional "selinux"],
3798 "get SELinux security context",
3800 This gets the SELinux security context of the daemon.
3802 See the documentation about SELINUX in L<guestfs(3)>,
3803 and C<guestfs_setcon>");
3805 ("mkfs_b", (RErr, [String "fstype"; Int "blocksize"; Device "device"]), 187, [],
3806 [InitEmpty, Always, TestOutput (
3807 [["part_disk"; "/dev/sda"; "mbr"];
3808 ["mkfs_b"; "ext2"; "4096"; "/dev/sda1"];
3809 ["mount_options"; ""; "/dev/sda1"; "/"];
3810 ["write"; "/new"; "new file contents"];
3811 ["cat"; "/new"]], "new file contents");
3812 InitEmpty, Always, TestRun (
3813 [["part_disk"; "/dev/sda"; "mbr"];
3814 ["mkfs_b"; "vfat"; "32768"; "/dev/sda1"]]);
3815 InitEmpty, Always, TestLastFail (
3816 [["part_disk"; "/dev/sda"; "mbr"];
3817 ["mkfs_b"; "vfat"; "32769"; "/dev/sda1"]]);
3818 InitEmpty, Always, TestLastFail (
3819 [["part_disk"; "/dev/sda"; "mbr"];
3820 ["mkfs_b"; "vfat"; "33280"; "/dev/sda1"]]);
3821 InitEmpty, IfAvailable "ntfsprogs", TestRun (
3822 [["part_disk"; "/dev/sda"; "mbr"];
3823 ["mkfs_b"; "ntfs"; "32768"; "/dev/sda1"]])],
3824 "make a filesystem with block size",
3826 This call is similar to C<guestfs_mkfs>, but it allows you to
3827 control the block size of the resulting filesystem. Supported
3828 block sizes depend on the filesystem type, but typically they
3829 are C<1024>, C<2048> or C<4096> only.
3831 For VFAT and NTFS the C<blocksize> parameter is treated as
3832 the requested cluster size.");
3834 ("mke2journal", (RErr, [Int "blocksize"; Device "device"]), 188, [],
3835 [InitEmpty, Always, TestOutput (
3836 [["sfdiskM"; "/dev/sda"; ",100 ,"];
3837 ["mke2journal"; "4096"; "/dev/sda1"];
3838 ["mke2fs_J"; "ext2"; "4096"; "/dev/sda2"; "/dev/sda1"];
3839 ["mount_options"; ""; "/dev/sda2"; "/"];
3840 ["write"; "/new"; "new file contents"];
3841 ["cat"; "/new"]], "new file contents")],
3842 "make ext2/3/4 external journal",
3844 This creates an ext2 external journal on C<device>. It is equivalent
3847 mke2fs -O journal_dev -b blocksize device");
3849 ("mke2journal_L", (RErr, [Int "blocksize"; String "label"; Device "device"]), 189, [],
3850 [InitEmpty, Always, TestOutput (
3851 [["sfdiskM"; "/dev/sda"; ",100 ,"];
3852 ["mke2journal_L"; "4096"; "JOURNAL"; "/dev/sda1"];
3853 ["mke2fs_JL"; "ext2"; "4096"; "/dev/sda2"; "JOURNAL"];
3854 ["mount_options"; ""; "/dev/sda2"; "/"];
3855 ["write"; "/new"; "new file contents"];
3856 ["cat"; "/new"]], "new file contents")],
3857 "make ext2/3/4 external journal with label",
3859 This creates an ext2 external journal on C<device> with label C<label>.");
3861 ("mke2journal_U", (RErr, [Int "blocksize"; String "uuid"; Device "device"]), 190, [Optional "linuxfsuuid"],
3862 (let uuid = uuidgen () in
3863 [InitEmpty, Always, TestOutput (
3864 [["sfdiskM"; "/dev/sda"; ",100 ,"];
3865 ["mke2journal_U"; "4096"; uuid; "/dev/sda1"];
3866 ["mke2fs_JU"; "ext2"; "4096"; "/dev/sda2"; uuid];
3867 ["mount_options"; ""; "/dev/sda2"; "/"];
3868 ["write"; "/new"; "new file contents"];
3869 ["cat"; "/new"]], "new file contents")]),
3870 "make ext2/3/4 external journal with UUID",
3872 This creates an ext2 external journal on C<device> with UUID C<uuid>.");
3874 ("mke2fs_J", (RErr, [String "fstype"; Int "blocksize"; Device "device"; Device "journal"]), 191, [],
3876 "make ext2/3/4 filesystem with external journal",
3878 This creates an ext2/3/4 filesystem on C<device> with
3879 an external journal on C<journal>. It is equivalent
3882 mke2fs -t fstype -b blocksize -J device=<journal> <device>
3884 See also C<guestfs_mke2journal>.");
3886 ("mke2fs_JL", (RErr, [String "fstype"; Int "blocksize"; Device "device"; String "label"]), 192, [],
3888 "make ext2/3/4 filesystem with external journal",
3890 This creates an ext2/3/4 filesystem on C<device> with
3891 an external journal on the journal labeled C<label>.
3893 See also C<guestfs_mke2journal_L>.");
3895 ("mke2fs_JU", (RErr, [String "fstype"; Int "blocksize"; Device "device"; String "uuid"]), 193, [Optional "linuxfsuuid"],
3897 "make ext2/3/4 filesystem with external journal",
3899 This creates an ext2/3/4 filesystem on C<device> with
3900 an external journal on the journal with UUID C<uuid>.
3902 See also C<guestfs_mke2journal_U>.");
3904 ("modprobe", (RErr, [String "modulename"]), 194, [Optional "linuxmodules"],
3905 [InitNone, Always, TestRun [["modprobe"; "fat"]]],
3906 "load a kernel module",
3908 This loads a kernel module in the appliance.
3910 The kernel module must have been whitelisted when libguestfs
3911 was built (see C<appliance/kmod.whitelist.in> in the source).");
3913 ("echo_daemon", (RString "output", [StringList "words"]), 195, [],
3914 [InitNone, Always, TestOutput (
3915 [["echo_daemon"; "This is a test"]], "This is a test"
3917 "echo arguments back to the client",
3919 This command concatenates the list of C<words> passed with single spaces
3920 between them and returns the resulting string.
3922 You can use this command to test the connection through to the daemon.
3924 See also C<guestfs_ping_daemon>.");
3926 ("find0", (RErr, [Pathname "directory"; FileOut "files"]), 196, [],
3927 [], (* There is a regression test for this. *)
3928 "find all files and directories, returning NUL-separated list",
3930 This command lists out all files and directories, recursively,
3931 starting at C<directory>, placing the resulting list in the
3932 external file called C<files>.
3934 This command works the same way as C<guestfs_find> with the
3935 following exceptions:
3941 The resulting list is written to an external file.
3945 Items (filenames) in the result are separated
3946 by C<\\0> characters. See L<find(1)> option I<-print0>.
3950 This command is not limited in the number of names that it
3955 The result list is not sorted.
3959 ("case_sensitive_path", (RString "rpath", [Pathname "path"]), 197, [],
3960 [InitISOFS, Always, TestOutput (
3961 [["case_sensitive_path"; "/DIRECTORY"]], "/directory");
3962 InitISOFS, Always, TestOutput (
3963 [["case_sensitive_path"; "/DIRECTORY/"]], "/directory");
3964 InitISOFS, Always, TestOutput (
3965 [["case_sensitive_path"; "/Known-1"]], "/known-1");
3966 InitISOFS, Always, TestLastFail (
3967 [["case_sensitive_path"; "/Known-1/"]]);
3968 InitBasicFS, Always, TestOutput (
3970 ["mkdir"; "/a/bbb"];
3971 ["touch"; "/a/bbb/c"];
3972 ["case_sensitive_path"; "/A/bbB/C"]], "/a/bbb/c");
3973 InitBasicFS, Always, TestOutput (
3975 ["mkdir"; "/a/bbb"];
3976 ["touch"; "/a/bbb/c"];
3977 ["case_sensitive_path"; "/A////bbB/C"]], "/a/bbb/c");
3978 InitBasicFS, Always, TestLastFail (
3980 ["mkdir"; "/a/bbb"];
3981 ["touch"; "/a/bbb/c"];
3982 ["case_sensitive_path"; "/A/bbb/../bbb/C"]])],
3983 "return true path on case-insensitive filesystem",
3985 This can be used to resolve case insensitive paths on
3986 a filesystem which is case sensitive. The use case is
3987 to resolve paths which you have read from Windows configuration
3988 files or the Windows Registry, to the true path.
3990 The command handles a peculiarity of the Linux ntfs-3g
3991 filesystem driver (and probably others), which is that although
3992 the underlying filesystem is case-insensitive, the driver
3993 exports the filesystem to Linux as case-sensitive.
3995 One consequence of this is that special directories such
3996 as C<c:\\windows> may appear as C</WINDOWS> or C</windows>
3997 (or other things) depending on the precise details of how
3998 they were created. In Windows itself this would not be
4001 Bug or feature? You decide:
4002 L<http://www.tuxera.com/community/ntfs-3g-faq/#posixfilenames1>
4004 This function resolves the true case of each element in the
4005 path and returns the case-sensitive path.
4007 Thus C<guestfs_case_sensitive_path> (\"/Windows/System32\")
4008 might return C<\"/WINDOWS/system32\"> (the exact return value
4009 would depend on details of how the directories were originally
4010 created under Windows).
4013 This function does not handle drive names, backslashes etc.
4015 See also C<guestfs_realpath>.");
4017 ("vfs_type", (RString "fstype", [Device "device"]), 198, [],
4018 [InitBasicFS, Always, TestOutput (
4019 [["vfs_type"; "/dev/sda1"]], "ext2")],
4020 "get the Linux VFS type corresponding to a mounted device",
4022 This command gets the filesystem type corresponding to
4023 the filesystem on C<device>.
4025 For most filesystems, the result is the name of the Linux
4026 VFS module which would be used to mount this filesystem
4027 if you mounted it without specifying the filesystem type.
4028 For example a string such as C<ext3> or C<ntfs>.");
4030 ("truncate", (RErr, [Pathname "path"]), 199, [],
4031 [InitBasicFS, Always, TestOutputStruct (
4032 [["write"; "/test"; "some stuff so size is not zero"];
4033 ["truncate"; "/test"];
4034 ["stat"; "/test"]], [CompareWithInt ("size", 0)])],
4035 "truncate a file to zero size",
4037 This command truncates C<path> to a zero-length file. The
4038 file must exist already.");
4040 ("truncate_size", (RErr, [Pathname "path"; Int64 "size"]), 200, [],
4041 [InitBasicFS, Always, TestOutputStruct (
4042 [["touch"; "/test"];
4043 ["truncate_size"; "/test"; "1000"];
4044 ["stat"; "/test"]], [CompareWithInt ("size", 1000)])],
4045 "truncate a file to a particular size",
4047 This command truncates C<path> to size C<size> bytes. The file
4050 If the current file size is less than C<size> then
4051 the file is extended to the required size with zero bytes.
4052 This creates a sparse file (ie. disk blocks are not allocated
4053 for the file until you write to it). To create a non-sparse
4054 file of zeroes, use C<guestfs_fallocate64> instead.");
4056 ("utimens", (RErr, [Pathname "path"; Int64 "atsecs"; Int64 "atnsecs"; Int64 "mtsecs"; Int64 "mtnsecs"]), 201, [],
4057 [InitBasicFS, Always, TestOutputStruct (
4058 [["touch"; "/test"];
4059 ["utimens"; "/test"; "12345"; "67890"; "9876"; "5432"];
4060 ["stat"; "/test"]], [CompareWithInt ("mtime", 9876)])],
4061 "set timestamp of a file with nanosecond precision",
4063 This command sets the timestamps of a file with nanosecond
4066 C<atsecs, atnsecs> are the last access time (atime) in secs and
4067 nanoseconds from the epoch.
4069 C<mtsecs, mtnsecs> are the last modification time (mtime) in
4070 secs and nanoseconds from the epoch.
4072 If the C<*nsecs> field contains the special value C<-1> then
4073 the corresponding timestamp is set to the current time. (The
4074 C<*secs> field is ignored in this case).
4076 If the C<*nsecs> field contains the special value C<-2> then
4077 the corresponding timestamp is left unchanged. (The
4078 C<*secs> field is ignored in this case).");
4080 ("mkdir_mode", (RErr, [Pathname "path"; Int "mode"]), 202, [],
4081 [InitBasicFS, Always, TestOutputStruct (
4082 [["mkdir_mode"; "/test"; "0o111"];
4083 ["stat"; "/test"]], [CompareWithInt ("mode", 0o40111)])],
4084 "create a directory with a particular mode",
4086 This command creates a directory, setting the initial permissions
4087 of the directory to C<mode>.
4089 For common Linux filesystems, the actual mode which is set will
4090 be C<mode & ~umask & 01777>. Non-native-Linux filesystems may
4091 interpret the mode in other ways.
4093 See also C<guestfs_mkdir>, C<guestfs_umask>");
4095 ("lchown", (RErr, [Int "owner"; Int "group"; Pathname "path"]), 203, [],
4097 "change file owner and group",
4099 Change the file owner to C<owner> and group to C<group>.
4100 This is like C<guestfs_chown> but if C<path> is a symlink then
4101 the link itself is changed, not the target.
4103 Only numeric uid and gid are supported. If you want to use
4104 names, you will need to locate and parse the password file
4105 yourself (Augeas support makes this relatively easy).");
4107 ("lstatlist", (RStructList ("statbufs", "stat"), [Pathname "path"; StringList "names"]), 204, [],
4109 "lstat on multiple files",
4111 This call allows you to perform the C<guestfs_lstat> operation
4112 on multiple files, where all files are in the directory C<path>.
4113 C<names> is the list of files from this directory.
4115 On return you get a list of stat structs, with a one-to-one
4116 correspondence to the C<names> list. If any name did not exist
4117 or could not be lstat'd, then the C<ino> field of that structure
4120 This call is intended for programs that want to efficiently
4121 list a directory contents without making many round-trips.
4122 See also C<guestfs_lxattrlist> for a similarly efficient call
4123 for getting extended attributes. Very long directory listings
4124 might cause the protocol message size to be exceeded, causing
4125 this call to fail. The caller must split up such requests
4126 into smaller groups of names.");
4128 ("lxattrlist", (RStructList ("xattrs", "xattr"), [Pathname "path"; StringList "names"]), 205, [Optional "linuxxattrs"],
4130 "lgetxattr on multiple files",
4132 This call allows you to get the extended attributes
4133 of multiple files, where all files are in the directory C<path>.
4134 C<names> is the list of files from this directory.
4136 On return you get a flat list of xattr structs which must be
4137 interpreted sequentially. The first xattr struct always has a zero-length
4138 C<attrname>. C<attrval> in this struct is zero-length
4139 to indicate there was an error doing C<lgetxattr> for this
4140 file, I<or> is a C string which is a decimal number
4141 (the number of following attributes for this file, which could
4142 be C<\"0\">). Then after the first xattr struct are the
4143 zero or more attributes for the first named file.
4144 This repeats for the second and subsequent files.
4146 This call is intended for programs that want to efficiently
4147 list a directory contents without making many round-trips.
4148 See also C<guestfs_lstatlist> for a similarly efficient call
4149 for getting standard stats. Very long directory listings
4150 might cause the protocol message size to be exceeded, causing
4151 this call to fail. The caller must split up such requests
4152 into smaller groups of names.");
4154 ("readlinklist", (RStringList "links", [Pathname "path"; StringList "names"]), 206, [],
4156 "readlink on multiple files",
4158 This call allows you to do a C<readlink> operation
4159 on multiple files, where all files are in the directory C<path>.
4160 C<names> is the list of files from this directory.
4162 On return you get a list of strings, with a one-to-one
4163 correspondence to the C<names> list. Each string is the
4164 value of the symbolic link.
4166 If the C<readlink(2)> operation fails on any name, then
4167 the corresponding result string is the empty string C<\"\">.
4168 However the whole operation is completed even if there
4169 were C<readlink(2)> errors, and so you can call this
4170 function with names where you don't know if they are
4171 symbolic links already (albeit slightly less efficient).
4173 This call is intended for programs that want to efficiently
4174 list a directory contents without making many round-trips.
4175 Very long directory listings might cause the protocol
4176 message size to be exceeded, causing
4177 this call to fail. The caller must split up such requests
4178 into smaller groups of names.");
4180 ("pread", (RBufferOut "content", [Pathname "path"; Int "count"; Int64 "offset"]), 207, [ProtocolLimitWarning],
4181 [InitISOFS, Always, TestOutputBuffer (
4182 [["pread"; "/known-4"; "1"; "3"]], "\n");
4183 InitISOFS, Always, TestOutputBuffer (
4184 [["pread"; "/empty"; "0"; "100"]], "")],
4185 "read part of a file",
4187 This command lets you read part of a file. It reads C<count>
4188 bytes of the file, starting at C<offset>, from file C<path>.
4190 This may read fewer bytes than requested. For further details
4191 see the L<pread(2)> system call.
4193 See also C<guestfs_pwrite>.");
4195 ("part_init", (RErr, [Device "device"; String "parttype"]), 208, [],
4196 [InitEmpty, Always, TestRun (
4197 [["part_init"; "/dev/sda"; "gpt"]])],
4198 "create an empty partition table",
4200 This creates an empty partition table on C<device> of one of the
4201 partition types listed below. Usually C<parttype> should be
4202 either C<msdos> or C<gpt> (for large disks).
4204 Initially there are no partitions. Following this, you should
4205 call C<guestfs_part_add> for each partition required.
4207 Possible values for C<parttype> are:
4211 =item B<efi> | B<gpt>
4213 Intel EFI / GPT partition table.
4215 This is recommended for >= 2 TB partitions that will be accessed
4216 from Linux and Intel-based Mac OS X. It also has limited backwards
4217 compatibility with the C<mbr> format.
4219 =item B<mbr> | B<msdos>
4221 The standard PC \"Master Boot Record\" (MBR) format used
4222 by MS-DOS and Windows. This partition type will B<only> work
4223 for device sizes up to 2 TB. For large disks we recommend
4228 Other partition table types that may work but are not
4237 =item B<amiga> | B<rdb>
4239 Amiga \"Rigid Disk Block\" format.
4247 DASD, used on IBM mainframes.
4255 Old Mac partition format. Modern Macs use C<gpt>.
4259 NEC PC-98 format, common in Japan apparently.
4267 ("part_add", (RErr, [Device "device"; String "prlogex"; Int64 "startsect"; Int64 "endsect"]), 209, [],
4268 [InitEmpty, Always, TestRun (
4269 [["part_init"; "/dev/sda"; "mbr"];
4270 ["part_add"; "/dev/sda"; "primary"; "1"; "-1"]]);
4271 InitEmpty, Always, TestRun (
4272 [["part_init"; "/dev/sda"; "gpt"];
4273 ["part_add"; "/dev/sda"; "primary"; "34"; "127"];
4274 ["part_add"; "/dev/sda"; "primary"; "128"; "-34"]]);
4275 InitEmpty, Always, TestRun (
4276 [["part_init"; "/dev/sda"; "mbr"];
4277 ["part_add"; "/dev/sda"; "primary"; "32"; "127"];
4278 ["part_add"; "/dev/sda"; "primary"; "128"; "255"];
4279 ["part_add"; "/dev/sda"; "primary"; "256"; "511"];
4280 ["part_add"; "/dev/sda"; "primary"; "512"; "-1"]])],
4281 "add a partition to the device",
4283 This command adds a partition to C<device>. If there is no partition
4284 table on the device, call C<guestfs_part_init> first.
4286 The C<prlogex> parameter is the type of partition. Normally you
4287 should pass C<p> or C<primary> here, but MBR partition tables also
4288 support C<l> (or C<logical>) and C<e> (or C<extended>) partition
4291 C<startsect> and C<endsect> are the start and end of the partition
4292 in I<sectors>. C<endsect> may be negative, which means it counts
4293 backwards from the end of the disk (C<-1> is the last sector).
4295 Creating a partition which covers the whole disk is not so easy.
4296 Use C<guestfs_part_disk> to do that.");
4298 ("part_disk", (RErr, [Device "device"; String "parttype"]), 210, [DangerWillRobinson],
4299 [InitEmpty, Always, TestRun (
4300 [["part_disk"; "/dev/sda"; "mbr"]]);
4301 InitEmpty, Always, TestRun (
4302 [["part_disk"; "/dev/sda"; "gpt"]])],
4303 "partition whole disk with a single primary partition",
4305 This command is simply a combination of C<guestfs_part_init>
4306 followed by C<guestfs_part_add> to create a single primary partition
4307 covering the whole disk.
4309 C<parttype> is the partition table type, usually C<mbr> or C<gpt>,
4310 but other possible values are described in C<guestfs_part_init>.");
4312 ("part_set_bootable", (RErr, [Device "device"; Int "partnum"; Bool "bootable"]), 211, [],
4313 [InitEmpty, Always, TestRun (
4314 [["part_disk"; "/dev/sda"; "mbr"];
4315 ["part_set_bootable"; "/dev/sda"; "1"; "true"]])],
4316 "make a partition bootable",
4318 This sets the bootable flag on partition numbered C<partnum> on
4319 device C<device>. Note that partitions are numbered from 1.
4321 The bootable flag is used by some operating systems (notably
4322 Windows) to determine which partition to boot from. It is by
4323 no means universally recognized.");
4325 ("part_set_name", (RErr, [Device "device"; Int "partnum"; String "name"]), 212, [],
4326 [InitEmpty, Always, TestRun (
4327 [["part_disk"; "/dev/sda"; "gpt"];
4328 ["part_set_name"; "/dev/sda"; "1"; "thepartname"]])],
4329 "set partition name",
4331 This sets the partition name on partition numbered C<partnum> on
4332 device C<device>. Note that partitions are numbered from 1.
4334 The partition name can only be set on certain types of partition
4335 table. This works on C<gpt> but not on C<mbr> partitions.");
4337 ("part_list", (RStructList ("partitions", "partition"), [Device "device"]), 213, [],
4338 [], (* XXX Add a regression test for this. *)
4339 "list partitions on a device",
4341 This command parses the partition table on C<device> and
4342 returns the list of partitions found.
4344 The fields in the returned structure are:
4350 Partition number, counting from 1.
4354 Start of the partition I<in bytes>. To get sectors you have to
4355 divide by the device's sector size, see C<guestfs_blockdev_getss>.
4359 End of the partition in bytes.
4363 Size of the partition in bytes.
4367 ("part_get_parttype", (RString "parttype", [Device "device"]), 214, [],
4368 [InitEmpty, Always, TestOutput (
4369 [["part_disk"; "/dev/sda"; "gpt"];
4370 ["part_get_parttype"; "/dev/sda"]], "gpt")],
4371 "get the partition table type",
4373 This command examines the partition table on C<device> and
4374 returns the partition table type (format) being used.
4376 Common return values include: C<msdos> (a DOS/Windows style MBR
4377 partition table), C<gpt> (a GPT/EFI-style partition table). Other
4378 values are possible, although unusual. See C<guestfs_part_init>
4381 ("fill", (RErr, [Int "c"; Int "len"; Pathname "path"]), 215, [Progress],
4382 [InitBasicFS, Always, TestOutputBuffer (
4383 [["fill"; "0x63"; "10"; "/test"];
4384 ["read_file"; "/test"]], "cccccccccc")],
4385 "fill a file with octets",
4387 This command creates a new file called C<path>. The initial
4388 content of the file is C<len> octets of C<c>, where C<c>
4389 must be a number in the range C<[0..255]>.
4391 To fill a file with zero bytes (sparsely), it is
4392 much more efficient to use C<guestfs_truncate_size>.
4393 To create a file with a pattern of repeating bytes
4394 use C<guestfs_fill_pattern>.");
4396 ("available", (RErr, [StringList "groups"]), 216, [],
4397 [InitNone, Always, TestRun [["available"; ""]]],
4398 "test availability of some parts of the API",
4400 This command is used to check the availability of some
4401 groups of functionality in the appliance, which not all builds of
4402 the libguestfs appliance will be able to provide.
4404 The libguestfs groups, and the functions that those
4405 groups correspond to, are listed in L<guestfs(3)/AVAILABILITY>.
4406 You can also fetch this list at runtime by calling
4407 C<guestfs_available_all_groups>.
4409 The argument C<groups> is a list of group names, eg:
4410 C<[\"inotify\", \"augeas\"]> would check for the availability of
4411 the Linux inotify functions and Augeas (configuration file
4414 The command returns no error if I<all> requested groups are available.
4416 It fails with an error if one or more of the requested
4417 groups is unavailable in the appliance.
4419 If an unknown group name is included in the
4420 list of groups then an error is always returned.
4428 You must call C<guestfs_launch> before calling this function.
4430 The reason is because we don't know what groups are
4431 supported by the appliance/daemon until it is running and can
4436 If a group of functions is available, this does not necessarily
4437 mean that they will work. You still have to check for errors
4438 when calling individual API functions even if they are
4443 It is usually the job of distro packagers to build
4444 complete functionality into the libguestfs appliance.
4445 Upstream libguestfs, if built from source with all
4446 requirements satisfied, will support everything.
4450 This call was added in version C<1.0.80>. In previous
4451 versions of libguestfs all you could do would be to speculatively
4452 execute a command to find out if the daemon implemented it.
4453 See also C<guestfs_version>.
4457 ("dd", (RErr, [Dev_or_Path "src"; Dev_or_Path "dest"]), 217, [],
4458 [InitBasicFS, Always, TestOutputBuffer (
4459 [["write"; "/src"; "hello, world"];
4460 ["dd"; "/src"; "/dest"];
4461 ["read_file"; "/dest"]], "hello, world")],
4462 "copy from source to destination using dd",
4464 This command copies from one source device or file C<src>
4465 to another destination device or file C<dest>. Normally you
4466 would use this to copy to or from a device or partition, for
4467 example to duplicate a filesystem.
4469 If the destination is a device, it must be as large or larger
4470 than the source file or device, otherwise the copy will fail.
4471 This command cannot do partial copies (see C<guestfs_copy_size>).");
4473 ("filesize", (RInt64 "size", [Pathname "file"]), 218, [],
4474 [InitBasicFS, Always, TestOutputInt (
4475 [["write"; "/file"; "hello, world"];
4476 ["filesize"; "/file"]], 12)],
4477 "return the size of the file in bytes",
4479 This command returns the size of C<file> in bytes.
4481 To get other stats about a file, use C<guestfs_stat>, C<guestfs_lstat>,
4482 C<guestfs_is_dir>, C<guestfs_is_file> etc.
4483 To get the size of block devices, use C<guestfs_blockdev_getsize64>.");
4485 ("lvrename", (RErr, [String "logvol"; String "newlogvol"]), 219, [],
4486 [InitBasicFSonLVM, Always, TestOutputList (
4487 [["lvrename"; "/dev/VG/LV"; "/dev/VG/LV2"];
4488 ["lvs"]], ["/dev/VG/LV2"])],
4489 "rename an LVM logical volume",
4491 Rename a logical volume C<logvol> with the new name C<newlogvol>.");
4493 ("vgrename", (RErr, [String "volgroup"; String "newvolgroup"]), 220, [],
4494 [InitBasicFSonLVM, Always, TestOutputList (
4496 ["vg_activate"; "false"; "VG"];
4497 ["vgrename"; "VG"; "VG2"];
4498 ["vg_activate"; "true"; "VG2"];
4499 ["mount_options"; ""; "/dev/VG2/LV"; "/"];
4500 ["vgs"]], ["VG2"])],
4501 "rename an LVM volume group",
4503 Rename a volume group C<volgroup> with the new name C<newvolgroup>.");
4505 ("initrd_cat", (RBufferOut "content", [Pathname "initrdpath"; String "filename"]), 221, [ProtocolLimitWarning],
4506 [InitISOFS, Always, TestOutputBuffer (
4507 [["initrd_cat"; "/initrd"; "known-4"]], "abc\ndef\nghi")],
4508 "list the contents of a single file in an initrd",
4510 This command unpacks the file C<filename> from the initrd file
4511 called C<initrdpath>. The filename must be given I<without> the
4512 initial C</> character.
4514 For example, in guestfish you could use the following command
4515 to examine the boot script (usually called C</init>)
4516 contained in a Linux initrd or initramfs image:
4518 initrd-cat /boot/initrd-<version>.img init
4520 See also C<guestfs_initrd_list>.");
4522 ("pvuuid", (RString "uuid", [Device "device"]), 222, [],
4524 "get the UUID of a physical volume",
4526 This command returns the UUID of the LVM PV C<device>.");
4528 ("vguuid", (RString "uuid", [String "vgname"]), 223, [],
4530 "get the UUID of a volume group",
4532 This command returns the UUID of the LVM VG named C<vgname>.");
4534 ("lvuuid", (RString "uuid", [Device "device"]), 224, [],
4536 "get the UUID of a logical volume",
4538 This command returns the UUID of the LVM LV C<device>.");
4540 ("vgpvuuids", (RStringList "uuids", [String "vgname"]), 225, [],
4542 "get the PV UUIDs containing the volume group",
4544 Given a VG called C<vgname>, this returns the UUIDs of all
4545 the physical volumes that this volume group resides on.
4547 You can use this along with C<guestfs_pvs> and C<guestfs_pvuuid>
4548 calls to associate physical volumes and volume groups.
4550 See also C<guestfs_vglvuuids>.");
4552 ("vglvuuids", (RStringList "uuids", [String "vgname"]), 226, [],
4554 "get the LV UUIDs of all LVs in the volume group",
4556 Given a VG called C<vgname>, this returns the UUIDs of all
4557 the logical volumes created in this volume group.
4559 You can use this along with C<guestfs_lvs> and C<guestfs_lvuuid>
4560 calls to associate logical volumes and volume groups.
4562 See also C<guestfs_vgpvuuids>.");
4564 ("copy_size", (RErr, [Dev_or_Path "src"; Dev_or_Path "dest"; Int64 "size"]), 227, [Progress],
4565 [InitBasicFS, Always, TestOutputBuffer (
4566 [["write"; "/src"; "hello, world"];
4567 ["copy_size"; "/src"; "/dest"; "5"];
4568 ["read_file"; "/dest"]], "hello")],
4569 "copy size bytes from source to destination using dd",
4571 This command copies exactly C<size> bytes from one source device
4572 or file C<src> to another destination device or file C<dest>.
4574 Note this will fail if the source is too short or if the destination
4575 is not large enough.");
4577 ("zero_device", (RErr, [Device "device"]), 228, [DangerWillRobinson; Progress],
4578 [InitBasicFSonLVM, Always, TestRun (
4579 [["zero_device"; "/dev/VG/LV"]])],
4580 "write zeroes to an entire device",
4582 This command writes zeroes over the entire C<device>. Compare
4583 with C<guestfs_zero> which just zeroes the first few blocks of
4586 ("txz_in", (RErr, [FileIn "tarball"; Pathname "directory"]), 229, [Optional "xz"],
4587 [InitBasicFS, Always, TestOutput (
4588 [["txz_in"; "../images/helloworld.tar.xz"; "/"];
4589 ["cat"; "/hello"]], "hello\n")],
4590 "unpack compressed tarball to directory",
4592 This command uploads and unpacks local file C<tarball> (an
4593 I<xz compressed> tar file) into C<directory>.");
4595 ("txz_out", (RErr, [Pathname "directory"; FileOut "tarball"]), 230, [Optional "xz"],
4597 "pack directory into compressed tarball",
4599 This command packs the contents of C<directory> and downloads
4600 it to local file C<tarball> (as an xz compressed tar archive).");
4602 ("ntfsresize", (RErr, [Device "device"]), 231, [Optional "ntfsprogs"],
4604 "resize an NTFS filesystem",
4606 This command resizes an NTFS filesystem, expanding or
4607 shrinking it to the size of the underlying device.
4608 See also L<ntfsresize(8)>.");
4610 ("vgscan", (RErr, []), 232, [],
4611 [InitEmpty, Always, TestRun (
4613 "rescan for LVM physical volumes, volume groups and logical volumes",
4615 This rescans all block devices and rebuilds the list of LVM
4616 physical volumes, volume groups and logical volumes.");
4618 ("part_del", (RErr, [Device "device"; Int "partnum"]), 233, [],
4619 [InitEmpty, Always, TestRun (
4620 [["part_init"; "/dev/sda"; "mbr"];
4621 ["part_add"; "/dev/sda"; "primary"; "1"; "-1"];
4622 ["part_del"; "/dev/sda"; "1"]])],
4623 "delete a partition",
4625 This command deletes the partition numbered C<partnum> on C<device>.
4627 Note that in the case of MBR partitioning, deleting an
4628 extended partition also deletes any logical partitions
4631 ("part_get_bootable", (RBool "bootable", [Device "device"; Int "partnum"]), 234, [],
4632 [InitEmpty, Always, TestOutputTrue (
4633 [["part_init"; "/dev/sda"; "mbr"];
4634 ["part_add"; "/dev/sda"; "primary"; "1"; "-1"];
4635 ["part_set_bootable"; "/dev/sda"; "1"; "true"];
4636 ["part_get_bootable"; "/dev/sda"; "1"]])],
4637 "return true if a partition is bootable",
4639 This command returns true if the partition C<partnum> on
4640 C<device> has the bootable flag set.
4642 See also C<guestfs_part_set_bootable>.");
4644 ("part_get_mbr_id", (RInt "idbyte", [Device "device"; Int "partnum"]), 235, [FishOutput FishOutputHexadecimal],
4645 [InitEmpty, Always, TestOutputInt (
4646 [["part_init"; "/dev/sda"; "mbr"];
4647 ["part_add"; "/dev/sda"; "primary"; "1"; "-1"];
4648 ["part_set_mbr_id"; "/dev/sda"; "1"; "0x7f"];
4649 ["part_get_mbr_id"; "/dev/sda"; "1"]], 0x7f)],
4650 "get the MBR type byte (ID byte) from a partition",
4652 Returns the MBR type byte (also known as the ID byte) from
4653 the numbered partition C<partnum>.
4655 Note that only MBR (old DOS-style) partitions have type bytes.
4656 You will get undefined results for other partition table
4657 types (see C<guestfs_part_get_parttype>).");
4659 ("part_set_mbr_id", (RErr, [Device "device"; Int "partnum"; Int "idbyte"]), 236, [],
4660 [], (* tested by part_get_mbr_id *)
4661 "set the MBR type byte (ID byte) of a partition",
4663 Sets the MBR type byte (also known as the ID byte) of
4664 the numbered partition C<partnum> to C<idbyte>. Note
4665 that the type bytes quoted in most documentation are
4666 in fact hexadecimal numbers, but usually documented
4667 without any leading \"0x\" which might be confusing.
4669 Note that only MBR (old DOS-style) partitions have type bytes.
4670 You will get undefined results for other partition table
4671 types (see C<guestfs_part_get_parttype>).");
4673 ("checksum_device", (RString "checksum", [String "csumtype"; Device "device"]), 237, [],
4674 [InitISOFS, Always, TestOutputFileMD5 (
4675 [["checksum_device"; "md5"; "/dev/sdd"]],
4676 "../images/test.iso")],
4677 "compute MD5, SHAx or CRC checksum of the contents of a device",
4679 This call computes the MD5, SHAx or CRC checksum of the
4680 contents of the device named C<device>. For the types of
4681 checksums supported see the C<guestfs_checksum> command.");
4683 ("lvresize_free", (RErr, [Device "lv"; Int "percent"]), 238, [Optional "lvm2"],
4684 [InitNone, Always, TestRun (
4685 [["part_disk"; "/dev/sda"; "mbr"];
4686 ["pvcreate"; "/dev/sda1"];
4687 ["vgcreate"; "VG"; "/dev/sda1"];
4688 ["lvcreate"; "LV"; "VG"; "10"];
4689 ["lvresize_free"; "/dev/VG/LV"; "100"]])],
4690 "expand an LV to fill free space",
4692 This expands an existing logical volume C<lv> so that it fills
4693 C<pc>% of the remaining free space in the volume group. Commonly
4694 you would call this with pc = 100 which expands the logical volume
4695 as much as possible, using all remaining free space in the volume
4698 ("aug_clear", (RErr, [String "augpath"]), 239, [Optional "augeas"],
4699 [], (* XXX Augeas code needs tests. *)
4700 "clear Augeas path",
4702 Set the value associated with C<path> to C<NULL>. This
4703 is the same as the L<augtool(1)> C<clear> command.");
4705 ("get_umask", (RInt "mask", []), 240, [FishOutput FishOutputOctal],
4706 [InitEmpty, Always, TestOutputInt (
4707 [["get_umask"]], 0o22)],
4708 "get the current umask",
4710 Return the current umask. By default the umask is C<022>
4711 unless it has been set by calling C<guestfs_umask>.");
4713 ("debug_upload", (RErr, [FileIn "filename"; String "tmpname"; Int "mode"]), 241, [],
4715 "upload a file to the appliance (internal use only)",
4717 The C<guestfs_debug_upload> command uploads a file to
4718 the libguestfs appliance.
4720 There is no comprehensive help for this command. You have
4721 to look at the file C<daemon/debug.c> in the libguestfs source
4722 to find out what it is for.");
4724 ("base64_in", (RErr, [FileIn "base64file"; Pathname "filename"]), 242, [],
4725 [InitBasicFS, Always, TestOutput (
4726 [["base64_in"; "../images/hello.b64"; "/hello"];
4727 ["cat"; "/hello"]], "hello\n")],
4728 "upload base64-encoded data to file",
4730 This command uploads base64-encoded data from C<base64file>
4733 ("base64_out", (RErr, [Pathname "filename"; FileOut "base64file"]), 243, [],
4735 "download file and encode as base64",
4737 This command downloads the contents of C<filename>, writing
4738 it out to local file C<base64file> encoded as base64.");
4740 ("checksums_out", (RErr, [String "csumtype"; Pathname "directory"; FileOut "sumsfile"]), 244, [],
4742 "compute MD5, SHAx or CRC checksum of files in a directory",
4744 This command computes the checksums of all regular files in
4745 C<directory> and then emits a list of those checksums to
4746 the local output file C<sumsfile>.
4748 This can be used for verifying the integrity of a virtual
4749 machine. However to be properly secure you should pay
4750 attention to the output of the checksum command (it uses
4751 the ones from GNU coreutils). In particular when the
4752 filename is not printable, coreutils uses a special
4753 backslash syntax. For more information, see the GNU
4754 coreutils info file.");
4756 ("fill_pattern", (RErr, [String "pattern"; Int "len"; Pathname "path"]), 245, [Progress],
4757 [InitBasicFS, Always, TestOutputBuffer (
4758 [["fill_pattern"; "abcdefghijklmnopqrstuvwxyz"; "28"; "/test"];
4759 ["read_file"; "/test"]], "abcdefghijklmnopqrstuvwxyzab")],
4760 "fill a file with a repeating pattern of bytes",
4762 This function is like C<guestfs_fill> except that it creates
4763 a new file of length C<len> containing the repeating pattern
4764 of bytes in C<pattern>. The pattern is truncated if necessary
4765 to ensure the length of the file is exactly C<len> bytes.");
4767 ("write", (RErr, [Pathname "path"; BufferIn "content"]), 246, [ProtocolLimitWarning],
4768 [InitBasicFS, Always, TestOutput (
4769 [["write"; "/new"; "new file contents"];
4770 ["cat"; "/new"]], "new file contents");
4771 InitBasicFS, Always, TestOutput (
4772 [["write"; "/new"; "\nnew file contents\n"];
4773 ["cat"; "/new"]], "\nnew file contents\n");
4774 InitBasicFS, Always, TestOutput (
4775 [["write"; "/new"; "\n\n"];
4776 ["cat"; "/new"]], "\n\n");
4777 InitBasicFS, Always, TestOutput (
4778 [["write"; "/new"; ""];
4779 ["cat"; "/new"]], "");
4780 InitBasicFS, Always, TestOutput (
4781 [["write"; "/new"; "\n\n\n"];
4782 ["cat"; "/new"]], "\n\n\n");
4783 InitBasicFS, Always, TestOutput (
4784 [["write"; "/new"; "\n"];
4785 ["cat"; "/new"]], "\n")],
4786 "create a new file",
4788 This call creates a file called C<path>. The content of the
4789 file is the string C<content> (which can contain any 8 bit data).");
4791 ("pwrite", (RInt "nbytes", [Pathname "path"; BufferIn "content"; Int64 "offset"]), 247, [ProtocolLimitWarning],
4792 [InitBasicFS, Always, TestOutput (
4793 [["write"; "/new"; "new file contents"];
4794 ["pwrite"; "/new"; "data"; "4"];
4795 ["cat"; "/new"]], "new data contents");
4796 InitBasicFS, Always, TestOutput (
4797 [["write"; "/new"; "new file contents"];
4798 ["pwrite"; "/new"; "is extended"; "9"];
4799 ["cat"; "/new"]], "new file is extended");
4800 InitBasicFS, Always, TestOutput (
4801 [["write"; "/new"; "new file contents"];
4802 ["pwrite"; "/new"; ""; "4"];
4803 ["cat"; "/new"]], "new file contents")],
4804 "write to part of a file",
4806 This command writes to part of a file. It writes the data
4807 buffer C<content> to the file C<path> starting at offset C<offset>.
4809 This command implements the L<pwrite(2)> system call, and like
4810 that system call it may not write the full data requested. The
4811 return value is the number of bytes that were actually written
4812 to the file. This could even be 0, although short writes are
4813 unlikely for regular files in ordinary circumstances.
4815 See also C<guestfs_pread>, C<guestfs_pwrite_device>.");
4817 ("resize2fs_size", (RErr, [Device "device"; Int64 "size"]), 248, [],
4819 "resize an ext2, ext3 or ext4 filesystem (with size)",
4821 This command is the same as C<guestfs_resize2fs> except that it
4822 allows you to specify the new size (in bytes) explicitly.");
4824 ("pvresize_size", (RErr, [Device "device"; Int64 "size"]), 249, [Optional "lvm2"],
4826 "resize an LVM physical volume (with size)",
4828 This command is the same as C<guestfs_pvresize> except that it
4829 allows you to specify the new size (in bytes) explicitly.");
4831 ("ntfsresize_size", (RErr, [Device "device"; Int64 "size"]), 250, [Optional "ntfsprogs"],
4833 "resize an NTFS filesystem (with size)",
4835 This command is the same as C<guestfs_ntfsresize> except that it
4836 allows you to specify the new size (in bytes) explicitly.");
4838 ("available_all_groups", (RStringList "groups", []), 251, [],
4839 [InitNone, Always, TestRun [["available_all_groups"]]],
4840 "return a list of all optional groups",
4842 This command returns a list of all optional groups that this
4843 daemon knows about. Note this returns both supported and unsupported
4844 groups. To find out which ones the daemon can actually support
4845 you have to call C<guestfs_available> on each member of the
4848 See also C<guestfs_available> and L<guestfs(3)/AVAILABILITY>.");
4850 ("fallocate64", (RErr, [Pathname "path"; Int64 "len"]), 252, [],
4851 [InitBasicFS, Always, TestOutputStruct (
4852 [["fallocate64"; "/a"; "1000000"];
4853 ["stat"; "/a"]], [CompareWithInt ("size", 1_000_000)])],
4854 "preallocate a file in the guest filesystem",
4856 This command preallocates a file (containing zero bytes) named
4857 C<path> of size C<len> bytes. If the file exists already, it
4860 Note that this call allocates disk blocks for the file.
4861 To create a sparse file use C<guestfs_truncate_size> instead.
4863 The deprecated call C<guestfs_fallocate> does the same,
4864 but owing to an oversight it only allowed 30 bit lengths
4865 to be specified, effectively limiting the maximum size
4866 of files created through that call to 1GB.
4868 Do not confuse this with the guestfish-specific
4869 C<alloc> and C<sparse> commands which create
4870 a file in the host and attach it as a device.");
4872 ("vfs_label", (RString "label", [Device "device"]), 253, [],
4873 [InitBasicFS, Always, TestOutput (
4874 [["set_e2label"; "/dev/sda1"; "LTEST"];
4875 ["vfs_label"; "/dev/sda1"]], "LTEST")],
4876 "get the filesystem label",
4878 This returns the filesystem label of the filesystem on
4881 If the filesystem is unlabeled, this returns the empty string.
4883 To find a filesystem from the label, use C<guestfs_findfs_label>.");
4885 ("vfs_uuid", (RString "uuid", [Device "device"]), 254, [],
4886 (let uuid = uuidgen () in
4887 [InitBasicFS, Always, TestOutput (
4888 [["set_e2uuid"; "/dev/sda1"; uuid];
4889 ["vfs_uuid"; "/dev/sda1"]], uuid)]),
4890 "get the filesystem UUID",
4892 This returns the filesystem UUID of the filesystem on
4895 If the filesystem does not have a UUID, this returns the empty string.
4897 To find a filesystem from the UUID, use C<guestfs_findfs_uuid>.");
4899 ("lvm_set_filter", (RErr, [DeviceList "devices"]), 255, [Optional "lvm2"],
4900 (* Can't be tested with the current framework because
4901 * the VG is being used by the mounted filesystem, so
4902 * the vgchange -an command we do first will fail.
4905 "set LVM device filter",
4907 This sets the LVM device filter so that LVM will only be
4908 able to \"see\" the block devices in the list C<devices>,
4909 and will ignore all other attached block devices.
4911 Where disk image(s) contain duplicate PVs or VGs, this
4912 command is useful to get LVM to ignore the duplicates, otherwise
4913 LVM can get confused. Note also there are two types
4914 of duplication possible: either cloned PVs/VGs which have
4915 identical UUIDs; or VGs that are not cloned but just happen
4916 to have the same name. In normal operation you cannot
4917 create this situation, but you can do it outside LVM, eg.
4918 by cloning disk images or by bit twiddling inside the LVM
4921 This command also clears the LVM cache and performs a volume
4924 You can filter whole block devices or individual partitions.
4926 You cannot use this if any VG is currently in use (eg.
4927 contains a mounted filesystem), even if you are not
4928 filtering out that VG.");
4930 ("lvm_clear_filter", (RErr, []), 256, [],
4931 [], (* see note on lvm_set_filter *)
4932 "clear LVM device filter",
4934 This undoes the effect of C<guestfs_lvm_set_filter>. LVM
4935 will be able to see every block device.
4937 This command also clears the LVM cache and performs a volume
4940 ("luks_open", (RErr, [Device "device"; Key "key"; String "mapname"]), 257, [Optional "luks"],
4942 "open a LUKS-encrypted block device",
4944 This command opens a block device which has been encrypted
4945 according to the Linux Unified Key Setup (LUKS) standard.
4947 C<device> is the encrypted block device or partition.
4949 The caller must supply one of the keys associated with the
4950 LUKS block device, in the C<key> parameter.
4952 This creates a new block device called C</dev/mapper/mapname>.
4953 Reads and writes to this block device are decrypted from and
4954 encrypted to the underlying C<device> respectively.
4956 If this block device contains LVM volume groups, then
4957 calling C<guestfs_vgscan> followed by C<guestfs_vg_activate_all>
4958 will make them visible.");
4960 ("luks_open_ro", (RErr, [Device "device"; Key "key"; String "mapname"]), 258, [Optional "luks"],
4962 "open a LUKS-encrypted block device read-only",
4964 This is the same as C<guestfs_luks_open> except that a read-only
4965 mapping is created.");
4967 ("luks_close", (RErr, [Device "device"]), 259, [Optional "luks"],
4969 "close a LUKS device",
4971 This closes a LUKS device that was created earlier by
4972 C<guestfs_luks_open> or C<guestfs_luks_open_ro>. The
4973 C<device> parameter must be the name of the LUKS mapping
4974 device (ie. C</dev/mapper/mapname>) and I<not> the name
4975 of the underlying block device.");
4977 ("luks_format", (RErr, [Device "device"; Key "key"; Int "keyslot"]), 260, [Optional "luks"; DangerWillRobinson],
4979 "format a block device as a LUKS encrypted device",
4981 This command erases existing data on C<device> and formats
4982 the device as a LUKS encrypted device. C<key> is the
4983 initial key, which is added to key slot C<slot>. (LUKS
4984 supports 8 key slots, numbered 0-7).");
4986 ("luks_format_cipher", (RErr, [Device "device"; Key "key"; Int "keyslot"; String "cipher"]), 261, [Optional "luks"; DangerWillRobinson],
4988 "format a block device as a LUKS encrypted device",
4990 This command is the same as C<guestfs_luks_format> but
4991 it also allows you to set the C<cipher> used.");
4993 ("luks_add_key", (RErr, [Device "device"; Key "key"; Key "newkey"; Int "keyslot"]), 262, [Optional "luks"],
4995 "add a key on a LUKS encrypted device",
4997 This command adds a new key on LUKS device C<device>.
4998 C<key> is any existing key, and is used to access the device.
4999 C<newkey> is the new key to add. C<keyslot> is the key slot
5000 that will be replaced.
5002 Note that if C<keyslot> already contains a key, then this
5003 command will fail. You have to use C<guestfs_luks_kill_slot>
5004 first to remove that key.");
5006 ("luks_kill_slot", (RErr, [Device "device"; Key "key"; Int "keyslot"]), 263, [Optional "luks"],
5008 "remove a key from a LUKS encrypted device",
5010 This command deletes the key in key slot C<keyslot> from the
5011 encrypted LUKS device C<device>. C<key> must be one of the
5014 ("is_lv", (RBool "lvflag", [Device "device"]), 264, [Optional "lvm2"],
5015 [InitBasicFSonLVM, IfAvailable "lvm2", TestOutputTrue (
5016 [["is_lv"; "/dev/VG/LV"]]);
5017 InitBasicFSonLVM, IfAvailable "lvm2", TestOutputFalse (
5018 [["is_lv"; "/dev/sda1"]])],
5019 "test if device is a logical volume",
5021 This command tests whether C<device> is a logical volume, and
5022 returns true iff this is the case.");
5024 ("findfs_uuid", (RString "device", [String "uuid"]), 265, [],
5026 "find a filesystem by UUID",
5028 This command searches the filesystems and returns the one
5029 which has the given UUID. An error is returned if no such
5030 filesystem can be found.
5032 To find the UUID of a filesystem, use C<guestfs_vfs_uuid>.");
5034 ("findfs_label", (RString "device", [String "label"]), 266, [],
5036 "find a filesystem by label",
5038 This command searches the filesystems and returns the one
5039 which has the given label. An error is returned if no such
5040 filesystem can be found.
5042 To find the label of a filesystem, use C<guestfs_vfs_label>.");
5044 ("is_chardev", (RBool "flag", [Pathname "path"]), 267, [],
5045 [InitISOFS, Always, TestOutputFalse (
5046 [["is_chardev"; "/directory"]]);
5047 InitBasicFS, Always, TestOutputTrue (
5048 [["mknod_c"; "0o777"; "99"; "66"; "/test"];
5049 ["is_chardev"; "/test"]])],
5050 "test if character device",
5052 This returns C<true> if and only if there is a character device
5053 with the given C<path> name.
5055 See also C<guestfs_stat>.");
5057 ("is_blockdev", (RBool "flag", [Pathname "path"]), 268, [],
5058 [InitISOFS, Always, TestOutputFalse (
5059 [["is_blockdev"; "/directory"]]);
5060 InitBasicFS, Always, TestOutputTrue (
5061 [["mknod_b"; "0o777"; "99"; "66"; "/test"];
5062 ["is_blockdev"; "/test"]])],
5063 "test if block device",
5065 This returns C<true> if and only if there is a block device
5066 with the given C<path> name.
5068 See also C<guestfs_stat>.");
5070 ("is_fifo", (RBool "flag", [Pathname "path"]), 269, [],
5071 [InitISOFS, Always, TestOutputFalse (
5072 [["is_fifo"; "/directory"]]);
5073 InitBasicFS, Always, TestOutputTrue (
5074 [["mkfifo"; "0o777"; "/test"];
5075 ["is_fifo"; "/test"]])],
5076 "test if FIFO (named pipe)",
5078 This returns C<true> if and only if there is a FIFO (named pipe)
5079 with the given C<path> name.
5081 See also C<guestfs_stat>.");
5083 ("is_symlink", (RBool "flag", [Pathname "path"]), 270, [],
5084 [InitISOFS, Always, TestOutputFalse (
5085 [["is_symlink"; "/directory"]]);
5086 InitISOFS, Always, TestOutputTrue (
5087 [["is_symlink"; "/abssymlink"]])],
5088 "test if symbolic link",
5090 This returns C<true> if and only if there is a symbolic link
5091 with the given C<path> name.
5093 See also C<guestfs_stat>.");
5095 ("is_socket", (RBool "flag", [Pathname "path"]), 271, [],
5096 (* XXX Need a positive test for sockets. *)
5097 [InitISOFS, Always, TestOutputFalse (
5098 [["is_socket"; "/directory"]])],
5101 This returns C<true> if and only if there is a Unix domain socket
5102 with the given C<path> name.
5104 See also C<guestfs_stat>.");
5106 ("part_to_dev", (RString "device", [Device "partition"]), 272, [],
5107 [InitPartition, Always, TestOutputDevice (
5108 [["part_to_dev"; "/dev/sda1"]], "/dev/sda");
5109 InitEmpty, Always, TestLastFail (
5110 [["part_to_dev"; "/dev/sda"]])],
5111 "convert partition name to device name",
5113 This function takes a partition name (eg. \"/dev/sdb1\") and
5114 removes the partition number, returning the device name
5117 The named partition must exist, for example as a string returned
5118 from C<guestfs_list_partitions>.");
5120 ("upload_offset", (RErr, [FileIn "filename"; Dev_or_Path "remotefilename"; Int64 "offset"]), 273, [],
5121 (let md5 = Digest.to_hex (Digest.file "COPYING.LIB") in
5122 [InitBasicFS, Always, TestOutput (
5123 [["upload_offset"; "../COPYING.LIB"; "/COPYING.LIB"; "0"];
5124 ["checksum"; "md5"; "/COPYING.LIB"]], md5)]),
5125 "upload a file from the local machine with offset",
5127 Upload local file C<filename> to C<remotefilename> on the
5130 C<remotefilename> is overwritten starting at the byte C<offset>
5131 specified. The intention is to overwrite parts of existing
5132 files or devices, although if a non-existant file is specified
5133 then it is created with a \"hole\" before C<offset>. The
5134 size of the data written is implicit in the size of the
5137 Note that there is no limit on the amount of data that
5138 can be uploaded with this call, unlike with C<guestfs_pwrite>,
5139 and this call always writes the full amount unless an
5142 See also C<guestfs_upload>, C<guestfs_pwrite>.");
5144 ("download_offset", (RErr, [Dev_or_Path "remotefilename"; FileOut "filename"; Int64 "offset"; Int64 "size"]), 274, [Progress],
5145 (let md5 = Digest.to_hex (Digest.file "COPYING.LIB") in
5146 let offset = string_of_int 100 in
5147 let size = string_of_int ((Unix.stat "COPYING.LIB").Unix.st_size - 100) in
5148 [InitBasicFS, Always, TestOutput (
5149 (* Pick a file from cwd which isn't likely to change. *)
5150 [["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
5151 ["download_offset"; "/COPYING.LIB"; "testdownload.tmp"; offset; size];
5152 ["upload_offset"; "testdownload.tmp"; "/COPYING.LIB"; offset];
5153 ["checksum"; "md5"; "/COPYING.LIB"]], md5)]),
5154 "download a file to the local machine with offset and size",
5156 Download file C<remotefilename> and save it as C<filename>
5157 on the local machine.
5159 C<remotefilename> is read for C<size> bytes starting at C<offset>
5160 (this region must be within the file or device).
5162 Note that there is no limit on the amount of data that
5163 can be downloaded with this call, unlike with C<guestfs_pread>,
5164 and this call always reads the full amount unless an
5167 See also C<guestfs_download>, C<guestfs_pread>.");
5169 ("pwrite_device", (RInt "nbytes", [Device "device"; BufferIn "content"; Int64 "offset"]), 275, [ProtocolLimitWarning],
5170 [InitPartition, Always, TestOutputList (
5171 [["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"];
5172 ["blockdev_rereadpt"; "/dev/sda"];
5173 ["list_partitions"]], [])],
5174 "write to part of a device",
5176 This command writes to part of a device. It writes the data
5177 buffer C<content> to C<device> starting at offset C<offset>.
5179 This command implements the L<pwrite(2)> system call, and like
5180 that system call it may not write the full data requested
5181 (although short writes to disk devices and partitions are
5182 probably impossible with standard Linux kernels).
5184 See also C<guestfs_pwrite>.");
5188 let all_functions = non_daemon_functions @ daemon_functions
5190 (* In some places we want the functions to be displayed sorted
5191 * alphabetically, so this is useful:
5193 let all_functions_sorted = List.sort action_compare all_functions
5195 (* This is used to generate the src/MAX_PROC_NR file which
5196 * contains the maximum procedure number, a surrogate for the
5197 * ABI version number. See src/Makefile.am for the details.
5200 let proc_nrs = List.map (
5201 fun (_, _, proc_nr, _, _, _, _) -> proc_nr
5202 ) daemon_functions in
5203 List.fold_left max 0 proc_nrs
5205 (* Non-API meta-commands available only in guestfish.
5207 * Note (1): args/return value, proc_nr and tests fields are all
5208 * meaningless. The only fields which are actually used are the
5209 * shortname, FishAlias flags, shortdesc and longdesc.
5211 * Note (2): to refer to other commands, use L</shortname>.
5213 * Note (3): keep this list sorted by shortname.
5215 let fish_commands = [
5216 ("alloc", (RErr,[]), -1, [FishAlias "allocate"], [],
5217 "allocate and add a disk file",
5218 " alloc filename size
5220 This creates an empty (zeroed) file of the given size, and then adds
5221 so it can be further examined.
5223 For more advanced image creation, see L<qemu-img(1)> utility.
5225 Size can be specified using standard suffixes, eg. C<1M>.
5227 To create a sparse file, use L</sparse> instead. To create a
5228 prepared disk image, see L</PREPARED DISK IMAGES>.");
5230 ("copy_in", (RErr,[]), -1, [], [],
5231 "copy local files or directories into an image",
5232 " copy-in local [local ...] /remotedir
5234 C<copy-in> copies local files or directories recursively into the disk
5235 image, placing them in the directory called C</remotedir> (which must
5236 exist). This guestfish meta-command turns into a sequence of
5237 L</tar-in> and other commands as necessary.
5239 Multiple local files and directories can be specified, but the last
5240 parameter must always be a remote directory. Wildcards cannot be
5243 ("copy_out", (RErr,[]), -1, [], [],
5244 "copy remote files or directories out of an image",
5245 " copy-out remote [remote ...] localdir
5247 C<copy-out> copies remote files or directories recursively out of the
5248 disk image, placing them on the host disk in a local directory called
5249 C<localdir> (which must exist). This guestfish meta-command turns
5250 into a sequence of L</download>, L</tar-out> and other commands as
5253 Multiple remote files and directories can be specified, but the last
5254 parameter must always be a local directory. To download to the
5255 current directory, use C<.> as in:
5259 Wildcards cannot be used in the ordinary command, but you can use
5260 them with the help of L</glob> like this:
5262 glob copy-out /home/* .");
5264 ("echo", (RErr,[]), -1, [], [],
5265 "display a line of text",
5268 This echos the parameters to the terminal.");
5270 ("edit", (RErr,[]), -1, [FishAlias "vi"; FishAlias "emacs"], [],
5274 This is used to edit a file. It downloads the file, edits it
5275 locally using your editor, then uploads the result.
5277 The editor is C<$EDITOR>. However if you use the alternate
5278 commands C<vi> or C<emacs> you will get those corresponding
5281 ("glob", (RErr,[]), -1, [], [],
5282 "expand wildcards in command",
5283 " glob command args...
5285 Expand wildcards in any paths in the args list, and run C<command>
5286 repeatedly on each matching path.
5288 See L</WILDCARDS AND GLOBBING>.");
5290 ("hexedit", (RErr,[]), -1, [], [],
5291 "edit with a hex editor",
5292 " hexedit <filename|device>
5293 hexedit <filename|device> <max>
5294 hexedit <filename|device> <start> <max>
5296 Use hexedit (a hex editor) to edit all or part of a binary file
5299 This command works by downloading potentially the whole file or
5300 device, editing it locally, then uploading it. If the file or
5301 device is large, you have to specify which part you wish to edit
5302 by using C<max> and/or C<start> C<max> parameters.
5303 C<start> and C<max> are specified in bytes, with the usual
5304 modifiers allowed such as C<1M> (1 megabyte).
5306 For example to edit the first few sectors of a disk you
5311 which would allow you to edit anywhere within the first megabyte
5314 To edit the superblock of an ext2 filesystem on C</dev/sda1>, do:
5316 hexedit /dev/sda1 0x400 0x400
5318 (assuming the superblock is in the standard location).
5320 This command requires the external L<hexedit(1)> program. You
5321 can specify another program to use by setting the C<HEXEDITOR>
5322 environment variable.
5324 See also L</hexdump>.");
5326 ("lcd", (RErr,[]), -1, [], [],
5327 "change working directory",
5330 Change the local directory, ie. the current directory of guestfish
5333 Note that C<!cd> won't do what you might expect.");
5335 ("man", (RErr,[]), -1, [FishAlias "manual"], [],
5339 Opens the manual page for guestfish.");
5341 ("more", (RErr,[]), -1, [FishAlias "less"], [],
5347 This is used to view a file.
5349 The default viewer is C<$PAGER>. However if you use the alternate
5350 command C<less> you will get the C<less> command specifically.");
5352 ("reopen", (RErr,[]), -1, [], [],
5353 "close and reopen libguestfs handle",
5356 Close and reopen the libguestfs handle. It is not necessary to use
5357 this normally, because the handle is closed properly when guestfish
5358 exits. However this is occasionally useful for testing.");
5360 ("sparse", (RErr,[]), -1, [], [],
5361 "create a sparse disk image and add",
5362 " sparse filename size
5364 This creates an empty sparse file of the given size, and then adds
5365 so it can be further examined.
5367 In all respects it works the same as the L</alloc> command, except that
5368 the image file is allocated sparsely, which means that disk blocks are
5369 not assigned to the file until they are needed. Sparse disk files
5370 only use space when written to, but they are slower and there is a
5371 danger you could run out of real disk space during a write operation.
5373 For more advanced image creation, see L<qemu-img(1)> utility.
5375 Size can be specified using standard suffixes, eg. C<1M>.");
5377 ("supported", (RErr,[]), -1, [], [],
5378 "list supported groups of commands",
5381 This command returns a list of the optional groups
5382 known to the daemon, and indicates which ones are
5383 supported by this build of the libguestfs appliance.
5385 See also L<guestfs(3)/AVAILABILITY>.");
5387 ("time", (RErr,[]), -1, [], [],
5388 "print elapsed time taken to run a command",
5389 " time command args...
5391 Run the command as usual, but print the elapsed time afterwards. This
5392 can be useful for benchmarking operations.");