3 * Copyright (C) 2009 Red Hat Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 (* This script generates a large amount of code and documentation for
21 * all the daemon actions.
23 * To add a new action there are only two files you need to change,
24 * this one to describe the interface (see the big table below), and
25 * daemon/<somefile>.c to write the implementation.
27 * After editing this file, run it (./src/generator.ml) to regenerate all the
28 * output files. Note that if you are using a separate build directory you
29 * must run generator.ml from the _source_ directory.
31 * IMPORTANT: This script should NOT print any warnings. If it prints
32 * warnings, you should treat them as errors.
40 type style = ret * args
42 (* "RErr" as a return value means an int used as a simple error
43 * indication, ie. 0 or -1.
47 (* "RInt" as a return value means an int which is -1 for error
48 * or any value >= 0 on success. Only use this for smallish
49 * positive ints (0 <= i < 2^30).
53 (* "RInt64" is the same as RInt, but is guaranteed to be able
54 * to return a full 64 bit value, _except_ that -1 means error
55 * (so -1 cannot be a valid, non-error return value).
59 (* "RBool" is a bool return value which can be true/false or
64 (* "RConstString" is a string that refers to a constant value.
65 * The return value must NOT be NULL (since NULL indicates
68 * Try to avoid using this. In particular you cannot use this
69 * for values returned from the daemon, because there is no
70 * thread-safe way to return them in the C API.
72 | RConstString of string
74 (* "RConstOptString" is an even more broken version of
75 * "RConstString". The returned string may be NULL and there
76 * is no way to return an error indication. Avoid using this!
78 | RConstOptString of string
80 (* "RString" is a returned string. It must NOT be NULL, since
81 * a NULL return indicates an error. The caller frees this.
85 (* "RStringList" is a list of strings. No string in the list
86 * can be NULL. The caller frees the strings and the array.
88 | RStringList of string
90 (* "RStruct" is a function which returns a single named structure
91 * or an error indication (in C, a struct, and in other languages
92 * with varying representations, but usually very efficient). See
93 * after the function list below for the structures.
95 | RStruct of string * string (* name of retval, name of struct *)
97 (* "RStructList" is a function which returns either a list/array
98 * of structures (could be zero-length), or an error indication.
100 | RStructList of string * string (* name of retval, name of struct *)
102 (* Key-value pairs of untyped strings. Turns into a hashtable or
103 * dictionary in languages which support it. DON'T use this as a
104 * general "bucket" for results. Prefer a stronger typed return
105 * value if one is available, or write a custom struct. Don't use
106 * this if the list could potentially be very long, since it is
107 * inefficient. Keys should be unique. NULLs are not permitted.
109 | RHashtable of string
111 (* "RBufferOut" is handled almost exactly like RString, but
112 * it allows the string to contain arbitrary 8 bit data including
113 * ASCII NUL. In the C API this causes an implicit extra parameter
114 * to be added of type <size_t *size_r>. The extra parameter
115 * returns the actual size of the return buffer in bytes.
117 * Other programming languages support strings with arbitrary 8 bit
120 * At the RPC layer we have to use the opaque<> type instead of
121 * string<>. Returned data is still limited to the max message
124 | RBufferOut of string
126 and args = argt list (* Function parameters, guestfs handle is implicit. *)
128 (* Note in future we should allow a "variable args" parameter as
129 * the final parameter, to allow commands like
130 * chmod mode file [file(s)...]
131 * This is not implemented yet, but many commands (such as chmod)
132 * are currently defined with the argument order keeping this future
133 * possibility in mind.
136 | String of string (* const char *name, cannot be NULL *)
137 | Device of string (* /dev device name, cannot be NULL *)
138 | Pathname of string (* file name, cannot be NULL *)
139 | Dev_or_Path of string (* /dev device name or Pathname, cannot be NULL *)
140 | OptString of string (* const char *name, may be NULL *)
141 | StringList of string(* list of strings (each string cannot be NULL) *)
142 | DeviceList of string(* list of Device names (each cannot be NULL) *)
143 | Bool of string (* boolean *)
144 | Int of string (* int (smallish ints, signed, <= 31 bits) *)
145 | Int64 of string (* any 64 bit int *)
146 (* These are treated as filenames (simple string parameters) in
147 * the C API and bindings. But in the RPC protocol, we transfer
148 * the actual file content up to or down from the daemon.
149 * FileIn: local machine -> daemon (in request)
150 * FileOut: daemon -> local machine (in reply)
151 * In guestfish (only), the special name "-" means read from
152 * stdin or write to stdout.
157 (* Opaque buffer which can contain arbitrary 8 bit data.
158 * In the C API, this is expressed as <char *, int> pair.
159 * Most other languages have a string type which can contain
160 * ASCII NUL. We use whatever type is appropriate for each
162 * Buffers are limited by the total message size. To transfer
163 * large blocks of data, use FileIn/FileOut parameters instead.
164 * To return an arbitrary buffer, use RBufferOut.
170 | ProtocolLimitWarning (* display warning about protocol size limits *)
171 | DangerWillRobinson (* flags particularly dangerous commands *)
172 | FishAlias of string (* provide an alias for this cmd in guestfish *)
173 | FishAction of string (* call this function in guestfish *)
174 | NotInFish (* do not export via guestfish *)
175 | NotInDocs (* do not add this function to documentation *)
176 | DeprecatedBy of string (* function is deprecated, use .. instead *)
178 (* You can supply zero or as many tests as you want per API call.
180 * Note that the test environment has 3 block devices, of size 500MB,
181 * 50MB and 10MB (respectively /dev/sda, /dev/sdb, /dev/sdc), and
182 * a fourth ISO block device with some known files on it (/dev/sdd).
184 * Note for partitioning purposes, the 500MB device has 1015 cylinders.
185 * Number of cylinders was 63 for IDE emulated disks with precisely
186 * the same size. How exactly this is calculated is a mystery.
188 * The ISO block device (/dev/sdd) comes from images/test.iso.
190 * To be able to run the tests in a reasonable amount of time,
191 * the virtual machine and block devices are reused between tests.
192 * So don't try testing kill_subprocess :-x
194 * Between each test we blockdev-setrw, umount-all, lvm-remove-all.
196 * Don't assume anything about the previous contents of the block
197 * devices. Use 'Init*' to create some initial scenarios.
199 * You can add a prerequisite clause to any individual test. This
200 * is a run-time check, which, if it fails, causes the test to be
201 * skipped. Useful if testing a command which might not work on
202 * all variations of libguestfs builds. A test that has prerequisite
203 * of 'Always' is run unconditionally.
205 * In addition, packagers can skip individual tests by setting the
206 * environment variables: eg:
207 * SKIP_TEST_<CMD>_<NUM>=1 SKIP_TEST_COMMAND_3=1 (skips test #3 of command)
208 * SKIP_TEST_<CMD>=1 SKIP_TEST_ZEROFREE=1 (skips all zerofree tests)
210 type tests = (test_init * test_prereq * test) list
212 (* Run the command sequence and just expect nothing to fail. *)
215 (* Run the command sequence and expect the output of the final
216 * command to be the string.
218 | TestOutput of seq * string
220 (* Run the command sequence and expect the output of the final
221 * command to be the list of strings.
223 | TestOutputList of seq * string list
225 (* Run the command sequence and expect the output of the final
226 * command to be the list of block devices (could be either
227 * "/dev/sd.." or "/dev/hd.." form - we don't check the 5th
228 * character of each string).
230 | TestOutputListOfDevices of seq * string list
232 (* Run the command sequence and expect the output of the final
233 * command to be the integer.
235 | TestOutputInt of seq * int
237 (* Run the command sequence and expect the output of the final
238 * command to be <op> <int>, eg. ">=", "1".
240 | TestOutputIntOp of seq * string * int
242 (* Run the command sequence and expect the output of the final
243 * command to be a true value (!= 0 or != NULL).
245 | TestOutputTrue of seq
247 (* Run the command sequence and expect the output of the final
248 * command to be a false value (== 0 or == NULL, but not an error).
250 | TestOutputFalse of seq
252 (* Run the command sequence and expect the output of the final
253 * command to be a list of the given length (but don't care about
256 | TestOutputLength of seq * int
258 (* Run the command sequence and expect the output of the final
259 * command to be a buffer (RBufferOut), ie. string + size.
261 | TestOutputBuffer of seq * string
263 (* Run the command sequence and expect the output of the final
264 * command to be a structure.
266 | TestOutputStruct of seq * test_field_compare list
268 (* Run the command sequence and expect the final command (only)
271 | TestLastFail of seq
273 and test_field_compare =
274 | CompareWithInt of string * int
275 | CompareWithIntOp of string * string * int
276 | CompareWithString of string * string
277 | CompareFieldsIntEq of string * string
278 | CompareFieldsStrEq of string * string
280 (* Test prerequisites. *)
282 (* Test always runs. *)
285 (* Test is currently disabled - eg. it fails, or it tests some
286 * unimplemented feature.
290 (* 'string' is some C code (a function body) that should return
291 * true or false. The test will run if the code returns true.
295 (* As for 'If' but the test runs _unless_ the code returns true. *)
298 (* Some initial scenarios for testing. *)
300 (* Do nothing, block devices could contain random stuff including
301 * LVM PVs, and some filesystems might be mounted. This is usually
306 (* Block devices are empty and no filesystems are mounted. *)
309 (* /dev/sda contains a single partition /dev/sda1, with random
310 * content. /dev/sdb and /dev/sdc may have random content.
315 (* /dev/sda contains a single partition /dev/sda1, which is formatted
316 * as ext2, empty [except for lost+found] and mounted on /.
317 * /dev/sdb and /dev/sdc may have random content.
323 * /dev/sda1 (is a PV):
324 * /dev/VG/LV (size 8MB):
325 * formatted as ext2, empty [except for lost+found], mounted on /
326 * /dev/sdb and /dev/sdc may have random content.
330 (* /dev/sdd (the ISO, see images/ directory in source)
335 (* Sequence of commands for testing. *)
337 and cmd = string list
339 (* Note about long descriptions: When referring to another
340 * action, use the format C<guestfs_other> (ie. the full name of
341 * the C function). This will be replaced as appropriate in other
344 * Apart from that, long descriptions are just perldoc paragraphs.
347 (* Generate a random UUID (used in tests). *)
349 let chan = Unix.open_process_in "uuidgen" in
350 let uuid = input_line chan in
351 (match Unix.close_process_in chan with
352 | Unix.WEXITED 0 -> ()
354 failwith "uuidgen: process exited with non-zero status"
355 | Unix.WSIGNALED _ | Unix.WSTOPPED _ ->
356 failwith "uuidgen: process signalled or stopped by signal"
360 (* These test functions are used in the language binding tests. *)
362 let test_all_args = [
365 StringList "strlist";
373 let test_all_rets = [
374 (* except for RErr, which is tested thoroughly elsewhere *)
375 "test0rint", RInt "valout";
376 "test0rint64", RInt64 "valout";
377 "test0rbool", RBool "valout";
378 "test0rconststring", RConstString "valout";
379 "test0rconstoptstring", RConstOptString "valout";
380 "test0rstring", RString "valout";
381 "test0rstringlist", RStringList "valout";
382 "test0rstruct", RStruct ("valout", "lvm_pv");
383 "test0rstructlist", RStructList ("valout", "lvm_pv");
384 "test0rhashtable", RHashtable "valout";
387 let test_functions = [
388 ("test0", (RErr, test_all_args), -1, [NotInFish; NotInDocs],
390 "internal test function - do not use",
392 This is an internal test function which is used to test whether
393 the automatically generated bindings can handle every possible
394 parameter type correctly.
396 It echos the contents of each parameter to stdout.
398 You probably don't want to call this function.");
402 [(name, (ret, [String "val"]), -1, [NotInFish; NotInDocs],
404 "internal test function - do not use",
406 This is an internal test function which is used to test whether
407 the automatically generated bindings can handle every possible
408 return type correctly.
410 It converts string C<val> to the return type.
412 You probably don't want to call this function.");
413 (name ^ "err", (ret, []), -1, [NotInFish; NotInDocs],
415 "internal test function - do not use",
417 This is an internal test function which is used to test whether
418 the automatically generated bindings can handle every possible
419 return type correctly.
421 This function always returns an error.
423 You probably don't want to call this function.")]
427 (* non_daemon_functions are any functions which don't get processed
428 * in the daemon, eg. functions for setting and getting local
429 * configuration values.
432 let non_daemon_functions = test_functions @ [
433 ("launch", (RErr, []), -1, [FishAlias "run"; FishAction "launch"],
435 "launch the qemu subprocess",
437 Internally libguestfs is implemented by running a virtual machine
440 You should call this after configuring the handle
441 (eg. adding drives) but before performing any actions.");
443 ("wait_ready", (RErr, []), -1, [NotInFish],
445 "wait until the qemu subprocess launches (no op)",
447 This function is a no op.
449 In versions of the API E<lt> 1.0.71 you had to call this function
450 just after calling C<guestfs_launch> to wait for the launch
451 to complete. However this is no longer necessary because
452 C<guestfs_launch> now does the waiting.
454 If you see any calls to this function in code then you can just
455 remove them, unless you want to retain compatibility with older
456 versions of the API.");
458 ("kill_subprocess", (RErr, []), -1, [],
460 "kill the qemu subprocess",
462 This kills the qemu subprocess. You should never need to call this.");
464 ("add_drive", (RErr, [String "filename"]), -1, [FishAlias "add"],
466 "add an image to examine or modify",
468 This function adds a virtual machine disk image C<filename> to the
469 guest. The first time you call this function, the disk appears as IDE
470 disk 0 (C</dev/sda>) in the guest, the second time as C</dev/sdb>, and
473 You don't necessarily need to be root when using libguestfs. However
474 you obviously do need sufficient permissions to access the filename
475 for whatever operations you want to perform (ie. read access if you
476 just want to read the image or write access if you want to modify the
479 This is equivalent to the qemu parameter
480 C<-drive file=filename,cache=off,if=...>.
481 C<cache=off> is omitted in cases where it is not supported by
482 the underlying filesystem.
484 Note that this call checks for the existence of C<filename>. This
485 stops you from specifying other types of drive which are supported
486 by qemu such as C<nbd:> and C<http:> URLs. To specify those, use
487 the general C<guestfs_config> call instead.");
489 ("add_cdrom", (RErr, [String "filename"]), -1, [FishAlias "cdrom"],
491 "add a CD-ROM disk image to examine",
493 This function adds a virtual CD-ROM disk image to the guest.
495 This is equivalent to the qemu parameter C<-cdrom filename>.
497 Note that this call checks for the existence of C<filename>. This
498 stops you from specifying other types of drive which are supported
499 by qemu such as C<nbd:> and C<http:> URLs. To specify those, use
500 the general C<guestfs_config> call instead.");
502 ("add_drive_ro", (RErr, [String "filename"]), -1, [FishAlias "add-ro"],
504 "add a drive in snapshot mode (read-only)",
506 This adds a drive in snapshot mode, making it effectively
509 Note that writes to the device are allowed, and will be seen for
510 the duration of the guestfs handle, but they are written
511 to a temporary file which is discarded as soon as the guestfs
512 handle is closed. We don't currently have any method to enable
513 changes to be committed, although qemu can support this.
515 This is equivalent to the qemu parameter
516 C<-drive file=filename,snapshot=on,if=...>.
518 Note that this call checks for the existence of C<filename>. This
519 stops you from specifying other types of drive which are supported
520 by qemu such as C<nbd:> and C<http:> URLs. To specify those, use
521 the general C<guestfs_config> call instead.");
523 ("config", (RErr, [String "qemuparam"; OptString "qemuvalue"]), -1, [],
525 "add qemu parameters",
527 This can be used to add arbitrary qemu command line parameters
528 of the form C<-param value>. Actually it's not quite arbitrary - we
529 prevent you from setting some parameters which would interfere with
530 parameters that we use.
532 The first character of C<param> string must be a C<-> (dash).
534 C<value> can be NULL.");
536 ("set_qemu", (RErr, [String "qemu"]), -1, [FishAlias "qemu"],
538 "set the qemu binary",
540 Set the qemu binary that we will use.
542 The default is chosen when the library was compiled by the
545 You can also override this by setting the C<LIBGUESTFS_QEMU>
546 environment variable.
548 Setting C<qemu> to C<NULL> restores the default qemu binary.");
550 ("get_qemu", (RConstString "qemu", []), -1, [],
551 [InitNone, Always, TestRun (
553 "get the qemu binary",
555 Return the current qemu binary.
557 This is always non-NULL. If it wasn't set already, then this will
558 return the default qemu binary name.");
560 ("set_path", (RErr, [String "searchpath"]), -1, [FishAlias "path"],
562 "set the search path",
564 Set the path that libguestfs searches for kernel and initrd.img.
566 The default is C<$libdir/guestfs> unless overridden by setting
567 C<LIBGUESTFS_PATH> environment variable.
569 Setting C<path> to C<NULL> restores the default path.");
571 ("get_path", (RConstString "path", []), -1, [],
572 [InitNone, Always, TestRun (
574 "get the search path",
576 Return the current search path.
578 This is always non-NULL. If it wasn't set already, then this will
579 return the default path.");
581 ("set_append", (RErr, [OptString "append"]), -1, [FishAlias "append"],
583 "add options to kernel command line",
585 This function is used to add additional options to the
586 guest kernel command line.
588 The default is C<NULL> unless overridden by setting
589 C<LIBGUESTFS_APPEND> environment variable.
591 Setting C<append> to C<NULL> means I<no> additional options
592 are passed (libguestfs always adds a few of its own).");
594 ("get_append", (RConstOptString "append", []), -1, [],
595 (* This cannot be tested with the current framework. The
596 * function can return NULL in normal operations, which the
597 * test framework interprets as an error.
600 "get the additional kernel options",
602 Return the additional kernel options which are added to the
603 guest kernel command line.
605 If C<NULL> then no options are added.");
607 ("set_autosync", (RErr, [Bool "autosync"]), -1, [FishAlias "autosync"],
611 If C<autosync> is true, this enables autosync. Libguestfs will make a
612 best effort attempt to run C<guestfs_umount_all> followed by
613 C<guestfs_sync> when the handle is closed
614 (also if the program exits without closing handles).
616 This is disabled by default (except in guestfish where it is
617 enabled by default).");
619 ("get_autosync", (RBool "autosync", []), -1, [],
620 [InitNone, Always, TestRun (
621 [["get_autosync"]])],
624 Get the autosync flag.");
626 ("set_verbose", (RErr, [Bool "verbose"]), -1, [FishAlias "verbose"],
630 If C<verbose> is true, this turns on verbose messages (to C<stderr>).
632 Verbose messages are disabled unless the environment variable
633 C<LIBGUESTFS_DEBUG> is defined and set to C<1>.");
635 ("get_verbose", (RBool "verbose", []), -1, [],
639 This returns the verbose messages flag.");
641 ("is_ready", (RBool "ready", []), -1, [],
642 [InitNone, Always, TestOutputTrue (
644 "is ready to accept commands",
646 This returns true iff this handle is ready to accept commands
647 (in the C<READY> state).
649 For more information on states, see L<guestfs(3)>.");
651 ("is_config", (RBool "config", []), -1, [],
652 [InitNone, Always, TestOutputFalse (
654 "is in configuration state",
656 This returns true iff this handle is being configured
657 (in the C<CONFIG> state).
659 For more information on states, see L<guestfs(3)>.");
661 ("is_launching", (RBool "launching", []), -1, [],
662 [InitNone, Always, TestOutputFalse (
663 [["is_launching"]])],
664 "is launching subprocess",
666 This returns true iff this handle is launching the subprocess
667 (in the C<LAUNCHING> state).
669 For more information on states, see L<guestfs(3)>.");
671 ("is_busy", (RBool "busy", []), -1, [],
672 [InitNone, Always, TestOutputFalse (
674 "is busy processing a command",
676 This returns true iff this handle is busy processing a command
677 (in the C<BUSY> state).
679 For more information on states, see L<guestfs(3)>.");
681 ("get_state", (RInt "state", []), -1, [],
683 "get the current state",
685 This returns the current state as an opaque integer. This is
686 only useful for printing debug and internal error messages.
688 For more information on states, see L<guestfs(3)>.");
690 ("set_memsize", (RErr, [Int "memsize"]), -1, [FishAlias "memsize"],
691 [InitNone, Always, TestOutputInt (
692 [["set_memsize"; "500"];
693 ["get_memsize"]], 500)],
694 "set memory allocated to the qemu subprocess",
696 This sets the memory size in megabytes allocated to the
697 qemu subprocess. This only has any effect if called before
700 You can also change this by setting the environment
701 variable C<LIBGUESTFS_MEMSIZE> before the handle is
704 For more information on the architecture of libguestfs,
705 see L<guestfs(3)>.");
707 ("get_memsize", (RInt "memsize", []), -1, [],
708 [InitNone, Always, TestOutputIntOp (
709 [["get_memsize"]], ">=", 256)],
710 "get memory allocated to the qemu subprocess",
712 This gets the memory size in megabytes allocated to the
715 If C<guestfs_set_memsize> was not called
716 on this handle, and if C<LIBGUESTFS_MEMSIZE> was not set,
717 then this returns the compiled-in default value for memsize.
719 For more information on the architecture of libguestfs,
720 see L<guestfs(3)>.");
722 ("get_pid", (RInt "pid", []), -1, [FishAlias "pid"],
723 [InitNone, Always, TestOutputIntOp (
724 [["get_pid"]], ">=", 1)],
725 "get PID of qemu subprocess",
727 Return the process ID of the qemu subprocess. If there is no
728 qemu subprocess, then this will return an error.
730 This is an internal call used for debugging and testing.");
732 ("version", (RStruct ("version", "version"), []), -1, [],
733 [InitNone, Always, TestOutputStruct (
734 [["version"]], [CompareWithInt ("major", 1)])],
735 "get the library version number",
737 Return the libguestfs version number that the program is linked
740 Note that because of dynamic linking this is not necessarily
741 the version of libguestfs that you compiled against. You can
742 compile the program, and then at runtime dynamically link
743 against a completely different C<libguestfs.so> library.
745 This call was added in version C<1.0.58>. In previous
746 versions of libguestfs there was no way to get the version
747 number. From C code you can use ELF weak linking tricks to find out if
748 this symbol exists (if it doesn't, then it's an earlier version).
750 The call returns a structure with four elements. The first
751 three (C<major>, C<minor> and C<release>) are numbers and
752 correspond to the usual version triplet. The fourth element
753 (C<extra>) is a string and is normally empty, but may be
754 used for distro-specific information.
756 To construct the original version string:
757 C<$major.$minor.$release$extra>
759 I<Note:> Don't use this call to test for availability
760 of features. Distro backports makes this unreliable.");
762 ("set_selinux", (RErr, [Bool "selinux"]), -1, [FishAlias "selinux"],
763 [InitNone, Always, TestOutputTrue (
764 [["set_selinux"; "true"];
766 "set SELinux enabled or disabled at appliance boot",
768 This sets the selinux flag that is passed to the appliance
769 at boot time. The default is C<selinux=0> (disabled).
771 Note that if SELinux is enabled, it is always in
772 Permissive mode (C<enforcing=0>).
774 For more information on the architecture of libguestfs,
775 see L<guestfs(3)>.");
777 ("get_selinux", (RBool "selinux", []), -1, [],
779 "get SELinux enabled flag",
781 This returns the current setting of the selinux flag which
782 is passed to the appliance at boot time. See C<guestfs_set_selinux>.
784 For more information on the architecture of libguestfs,
785 see L<guestfs(3)>.");
787 ("set_trace", (RErr, [Bool "trace"]), -1, [FishAlias "trace"],
788 [InitNone, Always, TestOutputFalse (
789 [["set_trace"; "false"];
791 "enable or disable command traces",
793 If the command trace flag is set to 1, then commands are
794 printed on stdout before they are executed in a format
795 which is very similar to the one used by guestfish. In
796 other words, you can run a program with this enabled, and
797 you will get out a script which you can feed to guestfish
798 to perform the same set of actions.
800 If you want to trace C API calls into libguestfs (and
801 other libraries) then possibly a better way is to use
802 the external ltrace(1) command.
804 Command traces are disabled unless the environment variable
805 C<LIBGUESTFS_TRACE> is defined and set to C<1>.");
807 ("get_trace", (RBool "trace", []), -1, [],
809 "get command trace enabled flag",
811 Return the command trace flag.");
813 ("set_direct", (RErr, [Bool "direct"]), -1, [FishAlias "direct"],
814 [InitNone, Always, TestOutputFalse (
815 [["set_direct"; "false"];
817 "enable or disable direct appliance mode",
819 If the direct appliance mode flag is enabled, then stdin and
820 stdout are passed directly through to the appliance once it
823 One consequence of this is that log messages aren't caught
824 by the library and handled by C<guestfs_set_log_message_callback>,
825 but go straight to stdout.
827 You probably don't want to use this unless you know what you
830 The default is disabled.");
832 ("get_direct", (RBool "direct", []), -1, [],
834 "get direct appliance mode flag",
836 Return the direct appliance mode flag.");
838 ("set_recovery_proc", (RErr, [Bool "recoveryproc"]), -1, [FishAlias "recovery-proc"],
839 [InitNone, Always, TestOutputTrue (
840 [["set_recovery_proc"; "true"];
841 ["get_recovery_proc"]])],
842 "enable or disable the recovery process",
844 If this is called with the parameter C<false> then
845 C<guestfs_launch> does not create a recovery process. The
846 purpose of the recovery process is to stop runaway qemu
847 processes in the case where the main program aborts abruptly.
849 This only has any effect if called before C<guestfs_launch>,
850 and the default is true.
852 About the only time when you would want to disable this is
853 if the main process will fork itself into the background
854 (\"daemonize\" itself). In this case the recovery process
855 thinks that the main program has disappeared and so kills
856 qemu, which is not very helpful.");
858 ("get_recovery_proc", (RBool "recoveryproc", []), -1, [],
860 "get recovery process enabled flag",
862 Return the recovery process enabled flag.");
866 (* daemon_functions are any functions which cause some action
867 * to take place in the daemon.
870 let daemon_functions = [
871 ("mount", (RErr, [Device "device"; String "mountpoint"]), 1, [],
872 [InitEmpty, Always, TestOutput (
873 [["sfdiskM"; "/dev/sda"; ","];
874 ["mkfs"; "ext2"; "/dev/sda1"];
875 ["mount"; "/dev/sda1"; "/"];
876 ["write_file"; "/new"; "new file contents"; "0"];
877 ["cat"; "/new"]], "new file contents")],
878 "mount a guest disk at a position in the filesystem",
880 Mount a guest disk at a position in the filesystem. Block devices
881 are named C</dev/sda>, C</dev/sdb> and so on, as they were added to
882 the guest. If those block devices contain partitions, they will have
883 the usual names (eg. C</dev/sda1>). Also LVM C</dev/VG/LV>-style
886 The rules are the same as for L<mount(2)>: A filesystem must
887 first be mounted on C</> before others can be mounted. Other
888 filesystems can only be mounted on directories which already
891 The mounted filesystem is writable, if we have sufficient permissions
892 on the underlying device.
894 The filesystem options C<sync> and C<noatime> are set with this
895 call, in order to improve reliability.");
897 ("sync", (RErr, []), 2, [],
898 [ InitEmpty, Always, TestRun [["sync"]]],
899 "sync disks, writes are flushed through to the disk image",
901 This syncs the disk, so that any writes are flushed through to the
902 underlying disk image.
904 You should always call this if you have modified a disk image, before
905 closing the handle.");
907 ("touch", (RErr, [Pathname "path"]), 3, [],
908 [InitBasicFS, Always, TestOutputTrue (
910 ["exists"; "/new"]])],
911 "update file timestamps or create a new file",
913 Touch acts like the L<touch(1)> command. It can be used to
914 update the timestamps on a file, or, if the file does not exist,
915 to create a new zero-length file.");
917 ("cat", (RString "content", [Pathname "path"]), 4, [ProtocolLimitWarning],
918 [InitISOFS, Always, TestOutput (
919 [["cat"; "/known-2"]], "abcdef\n")],
920 "list the contents of a file",
922 Return the contents of the file named C<path>.
924 Note that this function cannot correctly handle binary files
925 (specifically, files containing C<\\0> character which is treated
926 as end of string). For those you need to use the C<guestfs_read_file>
927 or C<guestfs_download> functions which have a more complex interface.");
929 ("ll", (RString "listing", [Pathname "directory"]), 5, [],
930 [], (* XXX Tricky to test because it depends on the exact format
931 * of the 'ls -l' command, which changes between F10 and F11.
933 "list the files in a directory (long format)",
935 List the files in C<directory> (relative to the root directory,
936 there is no cwd) in the format of 'ls -la'.
938 This command is mostly useful for interactive sessions. It
939 is I<not> intended that you try to parse the output string.");
941 ("ls", (RStringList "listing", [Pathname "directory"]), 6, [],
942 [InitBasicFS, Always, TestOutputList (
945 ["touch"; "/newest"];
946 ["ls"; "/"]], ["lost+found"; "new"; "newer"; "newest"])],
947 "list the files in a directory",
949 List the files in C<directory> (relative to the root directory,
950 there is no cwd). The '.' and '..' entries are not returned, but
951 hidden files are shown.
953 This command is mostly useful for interactive sessions. Programs
954 should probably use C<guestfs_readdir> instead.");
956 ("list_devices", (RStringList "devices", []), 7, [],
957 [InitEmpty, Always, TestOutputListOfDevices (
958 [["list_devices"]], ["/dev/sda"; "/dev/sdb"; "/dev/sdc"; "/dev/sdd"])],
959 "list the block devices",
961 List all the block devices.
963 The full block device names are returned, eg. C</dev/sda>");
965 ("list_partitions", (RStringList "partitions", []), 8, [],
966 [InitBasicFS, Always, TestOutputListOfDevices (
967 [["list_partitions"]], ["/dev/sda1"]);
968 InitEmpty, Always, TestOutputListOfDevices (
969 [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
970 ["list_partitions"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])],
971 "list the partitions",
973 List all the partitions detected on all block devices.
975 The full partition device names are returned, eg. C</dev/sda1>
977 This does not return logical volumes. For that you will need to
978 call C<guestfs_lvs>.");
980 ("pvs", (RStringList "physvols", []), 9, [],
981 [InitBasicFSonLVM, Always, TestOutputListOfDevices (
982 [["pvs"]], ["/dev/sda1"]);
983 InitEmpty, Always, TestOutputListOfDevices (
984 [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
985 ["pvcreate"; "/dev/sda1"];
986 ["pvcreate"; "/dev/sda2"];
987 ["pvcreate"; "/dev/sda3"];
988 ["pvs"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])],
989 "list the LVM physical volumes (PVs)",
991 List all the physical volumes detected. This is the equivalent
992 of the L<pvs(8)> command.
994 This returns a list of just the device names that contain
995 PVs (eg. C</dev/sda2>).
997 See also C<guestfs_pvs_full>.");
999 ("vgs", (RStringList "volgroups", []), 10, [],
1000 [InitBasicFSonLVM, Always, TestOutputList (
1002 InitEmpty, Always, TestOutputList (
1003 [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1004 ["pvcreate"; "/dev/sda1"];
1005 ["pvcreate"; "/dev/sda2"];
1006 ["pvcreate"; "/dev/sda3"];
1007 ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
1008 ["vgcreate"; "VG2"; "/dev/sda3"];
1009 ["vgs"]], ["VG1"; "VG2"])],
1010 "list the LVM volume groups (VGs)",
1012 List all the volumes groups detected. This is the equivalent
1013 of the L<vgs(8)> command.
1015 This returns a list of just the volume group names that were
1016 detected (eg. C<VolGroup00>).
1018 See also C<guestfs_vgs_full>.");
1020 ("lvs", (RStringList "logvols", []), 11, [],
1021 [InitBasicFSonLVM, Always, TestOutputList (
1022 [["lvs"]], ["/dev/VG/LV"]);
1023 InitEmpty, Always, TestOutputList (
1024 [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1025 ["pvcreate"; "/dev/sda1"];
1026 ["pvcreate"; "/dev/sda2"];
1027 ["pvcreate"; "/dev/sda3"];
1028 ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
1029 ["vgcreate"; "VG2"; "/dev/sda3"];
1030 ["lvcreate"; "LV1"; "VG1"; "50"];
1031 ["lvcreate"; "LV2"; "VG1"; "50"];
1032 ["lvcreate"; "LV3"; "VG2"; "50"];
1033 ["lvs"]], ["/dev/VG1/LV1"; "/dev/VG1/LV2"; "/dev/VG2/LV3"])],
1034 "list the LVM logical volumes (LVs)",
1036 List all the logical volumes detected. This is the equivalent
1037 of the L<lvs(8)> command.
1039 This returns a list of the logical volume device names
1040 (eg. C</dev/VolGroup00/LogVol00>).
1042 See also C<guestfs_lvs_full>.");
1044 ("pvs_full", (RStructList ("physvols", "lvm_pv"), []), 12, [],
1045 [], (* XXX how to test? *)
1046 "list the LVM physical volumes (PVs)",
1048 List all the physical volumes detected. This is the equivalent
1049 of the L<pvs(8)> command. The \"full\" version includes all fields.");
1051 ("vgs_full", (RStructList ("volgroups", "lvm_vg"), []), 13, [],
1052 [], (* XXX how to test? *)
1053 "list the LVM volume groups (VGs)",
1055 List all the volumes groups detected. This is the equivalent
1056 of the L<vgs(8)> command. The \"full\" version includes all fields.");
1058 ("lvs_full", (RStructList ("logvols", "lvm_lv"), []), 14, [],
1059 [], (* XXX how to test? *)
1060 "list the LVM logical volumes (LVs)",
1062 List all the logical volumes detected. This is the equivalent
1063 of the L<lvs(8)> command. The \"full\" version includes all fields.");
1065 ("read_lines", (RStringList "lines", [Pathname "path"]), 15, [],
1066 [InitISOFS, Always, TestOutputList (
1067 [["read_lines"; "/known-4"]], ["abc"; "def"; "ghi"]);
1068 InitISOFS, Always, TestOutputList (
1069 [["read_lines"; "/empty"]], [])],
1070 "read file as lines",
1072 Return the contents of the file named C<path>.
1074 The file contents are returned as a list of lines. Trailing
1075 C<LF> and C<CRLF> character sequences are I<not> returned.
1077 Note that this function cannot correctly handle binary files
1078 (specifically, files containing C<\\0> character which is treated
1079 as end of line). For those you need to use the C<guestfs_read_file>
1080 function which has a more complex interface.");
1082 ("aug_init", (RErr, [Pathname "root"; Int "flags"]), 16, [],
1083 [], (* XXX Augeas code needs tests. *)
1084 "create a new Augeas handle",
1086 Create a new Augeas handle for editing configuration files.
1087 If there was any previous Augeas handle associated with this
1088 guestfs session, then it is closed.
1090 You must call this before using any other C<guestfs_aug_*>
1093 C<root> is the filesystem root. C<root> must not be NULL,
1096 The flags are the same as the flags defined in
1097 E<lt>augeas.hE<gt>, the logical I<or> of the following
1102 =item C<AUG_SAVE_BACKUP> = 1
1104 Keep the original file with a C<.augsave> extension.
1106 =item C<AUG_SAVE_NEWFILE> = 2
1108 Save changes into a file with extension C<.augnew>, and
1109 do not overwrite original. Overrides C<AUG_SAVE_BACKUP>.
1111 =item C<AUG_TYPE_CHECK> = 4
1113 Typecheck lenses (can be expensive).
1115 =item C<AUG_NO_STDINC> = 8
1117 Do not use standard load path for modules.
1119 =item C<AUG_SAVE_NOOP> = 16
1121 Make save a no-op, just record what would have been changed.
1123 =item C<AUG_NO_LOAD> = 32
1125 Do not load the tree in C<guestfs_aug_init>.
1129 To close the handle, you can call C<guestfs_aug_close>.
1131 To find out more about Augeas, see L<http://augeas.net/>.");
1133 ("aug_close", (RErr, []), 26, [],
1134 [], (* XXX Augeas code needs tests. *)
1135 "close the current Augeas handle",
1137 Close the current Augeas handle and free up any resources
1138 used by it. After calling this, you have to call
1139 C<guestfs_aug_init> again before you can use any other
1140 Augeas functions.");
1142 ("aug_defvar", (RInt "nrnodes", [String "name"; OptString "expr"]), 17, [],
1143 [], (* XXX Augeas code needs tests. *)
1144 "define an Augeas variable",
1146 Defines an Augeas variable C<name> whose value is the result
1147 of evaluating C<expr>. If C<expr> is NULL, then C<name> is
1150 On success this returns the number of nodes in C<expr>, or
1151 C<0> if C<expr> evaluates to something which is not a nodeset.");
1153 ("aug_defnode", (RStruct ("nrnodescreated", "int_bool"), [String "name"; String "expr"; String "val"]), 18, [],
1154 [], (* XXX Augeas code needs tests. *)
1155 "define an Augeas node",
1157 Defines a variable C<name> whose value is the result of
1160 If C<expr> evaluates to an empty nodeset, a node is created,
1161 equivalent to calling C<guestfs_aug_set> C<expr>, C<value>.
1162 C<name> will be the nodeset containing that single node.
1164 On success this returns a pair containing the
1165 number of nodes in the nodeset, and a boolean flag
1166 if a node was created.");
1168 ("aug_get", (RString "val", [String "augpath"]), 19, [],
1169 [], (* XXX Augeas code needs tests. *)
1170 "look up the value of an Augeas path",
1172 Look up the value associated with C<path>. If C<path>
1173 matches exactly one node, the C<value> is returned.");
1175 ("aug_set", (RErr, [String "augpath"; String "val"]), 20, [],
1176 [], (* XXX Augeas code needs tests. *)
1177 "set Augeas path to value",
1179 Set the value associated with C<path> to C<value>.");
1181 ("aug_insert", (RErr, [String "augpath"; String "label"; Bool "before"]), 21, [],
1182 [], (* XXX Augeas code needs tests. *)
1183 "insert a sibling Augeas node",
1185 Create a new sibling C<label> for C<path>, inserting it into
1186 the tree before or after C<path> (depending on the boolean
1189 C<path> must match exactly one existing node in the tree, and
1190 C<label> must be a label, ie. not contain C</>, C<*> or end
1191 with a bracketed index C<[N]>.");
1193 ("aug_rm", (RInt "nrnodes", [String "augpath"]), 22, [],
1194 [], (* XXX Augeas code needs tests. *)
1195 "remove an Augeas path",
1197 Remove C<path> and all of its children.
1199 On success this returns the number of entries which were removed.");
1201 ("aug_mv", (RErr, [String "src"; String "dest"]), 23, [],
1202 [], (* XXX Augeas code needs tests. *)
1205 Move the node C<src> to C<dest>. C<src> must match exactly
1206 one node. C<dest> is overwritten if it exists.");
1208 ("aug_match", (RStringList "matches", [String "augpath"]), 24, [],
1209 [], (* XXX Augeas code needs tests. *)
1210 "return Augeas nodes which match augpath",
1212 Returns a list of paths which match the path expression C<path>.
1213 The returned paths are sufficiently qualified so that they match
1214 exactly one node in the current tree.");
1216 ("aug_save", (RErr, []), 25, [],
1217 [], (* XXX Augeas code needs tests. *)
1218 "write all pending Augeas changes to disk",
1220 This writes all pending changes to disk.
1222 The flags which were passed to C<guestfs_aug_init> affect exactly
1223 how files are saved.");
1225 ("aug_load", (RErr, []), 27, [],
1226 [], (* XXX Augeas code needs tests. *)
1227 "load files into the tree",
1229 Load files into the tree.
1231 See C<aug_load> in the Augeas documentation for the full gory
1234 ("aug_ls", (RStringList "matches", [String "augpath"]), 28, [],
1235 [], (* XXX Augeas code needs tests. *)
1236 "list Augeas nodes under augpath",
1238 This is just a shortcut for listing C<guestfs_aug_match>
1239 C<path/*> and sorting the resulting nodes into alphabetical order.");
1241 ("rm", (RErr, [Pathname "path"]), 29, [],
1242 [InitBasicFS, Always, TestRun
1245 InitBasicFS, Always, TestLastFail
1247 InitBasicFS, Always, TestLastFail
1252 Remove the single file C<path>.");
1254 ("rmdir", (RErr, [Pathname "path"]), 30, [],
1255 [InitBasicFS, Always, TestRun
1258 InitBasicFS, Always, TestLastFail
1259 [["rmdir"; "/new"]];
1260 InitBasicFS, Always, TestLastFail
1262 ["rmdir"; "/new"]]],
1263 "remove a directory",
1265 Remove the single directory C<path>.");
1267 ("rm_rf", (RErr, [Pathname "path"]), 31, [],
1268 [InitBasicFS, Always, TestOutputFalse
1270 ["mkdir"; "/new/foo"];
1271 ["touch"; "/new/foo/bar"];
1273 ["exists"; "/new"]]],
1274 "remove a file or directory recursively",
1276 Remove the file or directory C<path>, recursively removing the
1277 contents if its a directory. This is like the C<rm -rf> shell
1280 ("mkdir", (RErr, [Pathname "path"]), 32, [],
1281 [InitBasicFS, Always, TestOutputTrue
1283 ["is_dir"; "/new"]];
1284 InitBasicFS, Always, TestLastFail
1285 [["mkdir"; "/new/foo/bar"]]],
1286 "create a directory",
1288 Create a directory named C<path>.");
1290 ("mkdir_p", (RErr, [Pathname "path"]), 33, [],
1291 [InitBasicFS, Always, TestOutputTrue
1292 [["mkdir_p"; "/new/foo/bar"];
1293 ["is_dir"; "/new/foo/bar"]];
1294 InitBasicFS, Always, TestOutputTrue
1295 [["mkdir_p"; "/new/foo/bar"];
1296 ["is_dir"; "/new/foo"]];
1297 InitBasicFS, Always, TestOutputTrue
1298 [["mkdir_p"; "/new/foo/bar"];
1299 ["is_dir"; "/new"]];
1300 (* Regression tests for RHBZ#503133: *)
1301 InitBasicFS, Always, TestRun
1303 ["mkdir_p"; "/new"]];
1304 InitBasicFS, Always, TestLastFail
1306 ["mkdir_p"; "/new"]]],
1307 "create a directory and parents",
1309 Create a directory named C<path>, creating any parent directories
1310 as necessary. This is like the C<mkdir -p> shell command.");
1312 ("chmod", (RErr, [Int "mode"; Pathname "path"]), 34, [],
1313 [], (* XXX Need stat command to test *)
1316 Change the mode (permissions) of C<path> to C<mode>. Only
1317 numeric modes are supported.");
1319 ("chown", (RErr, [Int "owner"; Int "group"; Pathname "path"]), 35, [],
1320 [], (* XXX Need stat command to test *)
1321 "change file owner and group",
1323 Change the file owner to C<owner> and group to C<group>.
1325 Only numeric uid and gid are supported. If you want to use
1326 names, you will need to locate and parse the password file
1327 yourself (Augeas support makes this relatively easy).");
1329 ("exists", (RBool "existsflag", [Pathname "path"]), 36, [],
1330 [InitISOFS, Always, TestOutputTrue (
1331 [["exists"; "/empty"]]);
1332 InitISOFS, Always, TestOutputTrue (
1333 [["exists"; "/directory"]])],
1334 "test if file or directory exists",
1336 This returns C<true> if and only if there is a file, directory
1337 (or anything) with the given C<path> name.
1339 See also C<guestfs_is_file>, C<guestfs_is_dir>, C<guestfs_stat>.");
1341 ("is_file", (RBool "fileflag", [Pathname "path"]), 37, [],
1342 [InitISOFS, Always, TestOutputTrue (
1343 [["is_file"; "/known-1"]]);
1344 InitISOFS, Always, TestOutputFalse (
1345 [["is_file"; "/directory"]])],
1346 "test if file exists",
1348 This returns C<true> if and only if there is a file
1349 with the given C<path> name. Note that it returns false for
1350 other objects like directories.
1352 See also C<guestfs_stat>.");
1354 ("is_dir", (RBool "dirflag", [Pathname "path"]), 38, [],
1355 [InitISOFS, Always, TestOutputFalse (
1356 [["is_dir"; "/known-3"]]);
1357 InitISOFS, Always, TestOutputTrue (
1358 [["is_dir"; "/directory"]])],
1359 "test if file exists",
1361 This returns C<true> if and only if there is a directory
1362 with the given C<path> name. Note that it returns false for
1363 other objects like files.
1365 See also C<guestfs_stat>.");
1367 ("pvcreate", (RErr, [Device "device"]), 39, [],
1368 [InitEmpty, Always, TestOutputListOfDevices (
1369 [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1370 ["pvcreate"; "/dev/sda1"];
1371 ["pvcreate"; "/dev/sda2"];
1372 ["pvcreate"; "/dev/sda3"];
1373 ["pvs"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])],
1374 "create an LVM physical volume",
1376 This creates an LVM physical volume on the named C<device>,
1377 where C<device> should usually be a partition name such
1380 ("vgcreate", (RErr, [String "volgroup"; DeviceList "physvols"]), 40, [],
1381 [InitEmpty, Always, TestOutputList (
1382 [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1383 ["pvcreate"; "/dev/sda1"];
1384 ["pvcreate"; "/dev/sda2"];
1385 ["pvcreate"; "/dev/sda3"];
1386 ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
1387 ["vgcreate"; "VG2"; "/dev/sda3"];
1388 ["vgs"]], ["VG1"; "VG2"])],
1389 "create an LVM volume group",
1391 This creates an LVM volume group called C<volgroup>
1392 from the non-empty list of physical volumes C<physvols>.");
1394 ("lvcreate", (RErr, [String "logvol"; String "volgroup"; Int "mbytes"]), 41, [],
1395 [InitEmpty, Always, TestOutputList (
1396 [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1397 ["pvcreate"; "/dev/sda1"];
1398 ["pvcreate"; "/dev/sda2"];
1399 ["pvcreate"; "/dev/sda3"];
1400 ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
1401 ["vgcreate"; "VG2"; "/dev/sda3"];
1402 ["lvcreate"; "LV1"; "VG1"; "50"];
1403 ["lvcreate"; "LV2"; "VG1"; "50"];
1404 ["lvcreate"; "LV3"; "VG2"; "50"];
1405 ["lvcreate"; "LV4"; "VG2"; "50"];
1406 ["lvcreate"; "LV5"; "VG2"; "50"];
1408 ["/dev/VG1/LV1"; "/dev/VG1/LV2";
1409 "/dev/VG2/LV3"; "/dev/VG2/LV4"; "/dev/VG2/LV5"])],
1410 "create an LVM volume group",
1412 This creates an LVM volume group called C<logvol>
1413 on the volume group C<volgroup>, with C<size> megabytes.");
1415 ("mkfs", (RErr, [String "fstype"; Device "device"]), 42, [],
1416 [InitEmpty, Always, TestOutput (
1417 [["sfdiskM"; "/dev/sda"; ","];
1418 ["mkfs"; "ext2"; "/dev/sda1"];
1419 ["mount"; "/dev/sda1"; "/"];
1420 ["write_file"; "/new"; "new file contents"; "0"];
1421 ["cat"; "/new"]], "new file contents")],
1422 "make a filesystem",
1424 This creates a filesystem on C<device> (usually a partition
1425 or LVM logical volume). The filesystem type is C<fstype>, for
1428 ("sfdisk", (RErr, [Device "device";
1429 Int "cyls"; Int "heads"; Int "sectors";
1430 StringList "lines"]), 43, [DangerWillRobinson],
1432 "create partitions on a block device",
1434 This is a direct interface to the L<sfdisk(8)> program for creating
1435 partitions on block devices.
1437 C<device> should be a block device, for example C</dev/sda>.
1439 C<cyls>, C<heads> and C<sectors> are the number of cylinders, heads
1440 and sectors on the device, which are passed directly to sfdisk as
1441 the I<-C>, I<-H> and I<-S> parameters. If you pass C<0> for any
1442 of these, then the corresponding parameter is omitted. Usually for
1443 'large' disks, you can just pass C<0> for these, but for small
1444 (floppy-sized) disks, sfdisk (or rather, the kernel) cannot work
1445 out the right geometry and you will need to tell it.
1447 C<lines> is a list of lines that we feed to C<sfdisk>. For more
1448 information refer to the L<sfdisk(8)> manpage.
1450 To create a single partition occupying the whole disk, you would
1451 pass C<lines> as a single element list, when the single element being
1452 the string C<,> (comma).
1454 See also: C<guestfs_sfdisk_l>, C<guestfs_sfdisk_N>");
1456 ("write_file", (RErr, [Pathname "path"; String "content"; Int "size"]), 44, [ProtocolLimitWarning],
1457 [InitBasicFS, Always, TestOutput (
1458 [["write_file"; "/new"; "new file contents"; "0"];
1459 ["cat"; "/new"]], "new file contents");
1460 InitBasicFS, Always, TestOutput (
1461 [["write_file"; "/new"; "\nnew file contents\n"; "0"];
1462 ["cat"; "/new"]], "\nnew file contents\n");
1463 InitBasicFS, Always, TestOutput (
1464 [["write_file"; "/new"; "\n\n"; "0"];
1465 ["cat"; "/new"]], "\n\n");
1466 InitBasicFS, Always, TestOutput (
1467 [["write_file"; "/new"; ""; "0"];
1468 ["cat"; "/new"]], "");
1469 InitBasicFS, Always, TestOutput (
1470 [["write_file"; "/new"; "\n\n\n"; "0"];
1471 ["cat"; "/new"]], "\n\n\n");
1472 InitBasicFS, Always, TestOutput (
1473 [["write_file"; "/new"; "\n"; "0"];
1474 ["cat"; "/new"]], "\n")],
1477 This call creates a file called C<path>. The contents of the
1478 file is the string C<content> (which can contain any 8 bit data),
1479 with length C<size>.
1481 As a special case, if C<size> is C<0>
1482 then the length is calculated using C<strlen> (so in this case
1483 the content cannot contain embedded ASCII NULs).
1485 I<NB.> Owing to a bug, writing content containing ASCII NUL
1486 characters does I<not> work, even if the length is specified.
1487 We hope to resolve this bug in a future version. In the meantime
1488 use C<guestfs_upload>.");
1490 ("umount", (RErr, [String "pathordevice"]), 45, [FishAlias "unmount"],
1491 [InitEmpty, Always, TestOutputListOfDevices (
1492 [["sfdiskM"; "/dev/sda"; ","];
1493 ["mkfs"; "ext2"; "/dev/sda1"];
1494 ["mount"; "/dev/sda1"; "/"];
1495 ["mounts"]], ["/dev/sda1"]);
1496 InitEmpty, Always, TestOutputList (
1497 [["sfdiskM"; "/dev/sda"; ","];
1498 ["mkfs"; "ext2"; "/dev/sda1"];
1499 ["mount"; "/dev/sda1"; "/"];
1502 "unmount a filesystem",
1504 This unmounts the given filesystem. The filesystem may be
1505 specified either by its mountpoint (path) or the device which
1506 contains the filesystem.");
1508 ("mounts", (RStringList "devices", []), 46, [],
1509 [InitBasicFS, Always, TestOutputListOfDevices (
1510 [["mounts"]], ["/dev/sda1"])],
1511 "show mounted filesystems",
1513 This returns the list of currently mounted filesystems. It returns
1514 the list of devices (eg. C</dev/sda1>, C</dev/VG/LV>).
1516 Some internal mounts are not shown.
1518 See also: C<guestfs_mountpoints>");
1520 ("umount_all", (RErr, []), 47, [FishAlias "unmount-all"],
1521 [InitBasicFS, Always, TestOutputList (
1524 (* check that umount_all can unmount nested mounts correctly: *)
1525 InitEmpty, Always, TestOutputList (
1526 [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1527 ["mkfs"; "ext2"; "/dev/sda1"];
1528 ["mkfs"; "ext2"; "/dev/sda2"];
1529 ["mkfs"; "ext2"; "/dev/sda3"];
1530 ["mount"; "/dev/sda1"; "/"];
1532 ["mount"; "/dev/sda2"; "/mp1"];
1533 ["mkdir"; "/mp1/mp2"];
1534 ["mount"; "/dev/sda3"; "/mp1/mp2"];
1535 ["mkdir"; "/mp1/mp2/mp3"];
1538 "unmount all filesystems",
1540 This unmounts all mounted filesystems.
1542 Some internal mounts are not unmounted by this call.");
1544 ("lvm_remove_all", (RErr, []), 48, [DangerWillRobinson],
1546 "remove all LVM LVs, VGs and PVs",
1548 This command removes all LVM logical volumes, volume groups
1549 and physical volumes.");
1551 ("file", (RString "description", [Dev_or_Path "path"]), 49, [],
1552 [InitISOFS, Always, TestOutput (
1553 [["file"; "/empty"]], "empty");
1554 InitISOFS, Always, TestOutput (
1555 [["file"; "/known-1"]], "ASCII text");
1556 InitISOFS, Always, TestLastFail (
1557 [["file"; "/notexists"]])],
1558 "determine file type",
1560 This call uses the standard L<file(1)> command to determine
1561 the type or contents of the file. This also works on devices,
1562 for example to find out whether a partition contains a filesystem.
1564 This call will also transparently look inside various types
1567 The exact command which runs is C<file -zbsL path>. Note in
1568 particular that the filename is not prepended to the output
1569 (the C<-b> option).");
1571 ("command", (RString "output", [StringList "arguments"]), 50, [ProtocolLimitWarning],
1572 [InitBasicFS, Always, TestOutput (
1573 [["upload"; "test-command"; "/test-command"];
1574 ["chmod"; "0o755"; "/test-command"];
1575 ["command"; "/test-command 1"]], "Result1");
1576 InitBasicFS, Always, TestOutput (
1577 [["upload"; "test-command"; "/test-command"];
1578 ["chmod"; "0o755"; "/test-command"];
1579 ["command"; "/test-command 2"]], "Result2\n");
1580 InitBasicFS, Always, TestOutput (
1581 [["upload"; "test-command"; "/test-command"];
1582 ["chmod"; "0o755"; "/test-command"];
1583 ["command"; "/test-command 3"]], "\nResult3");
1584 InitBasicFS, Always, TestOutput (
1585 [["upload"; "test-command"; "/test-command"];
1586 ["chmod"; "0o755"; "/test-command"];
1587 ["command"; "/test-command 4"]], "\nResult4\n");
1588 InitBasicFS, Always, TestOutput (
1589 [["upload"; "test-command"; "/test-command"];
1590 ["chmod"; "0o755"; "/test-command"];
1591 ["command"; "/test-command 5"]], "\nResult5\n\n");
1592 InitBasicFS, Always, TestOutput (
1593 [["upload"; "test-command"; "/test-command"];
1594 ["chmod"; "0o755"; "/test-command"];
1595 ["command"; "/test-command 6"]], "\n\nResult6\n\n");
1596 InitBasicFS, Always, TestOutput (
1597 [["upload"; "test-command"; "/test-command"];
1598 ["chmod"; "0o755"; "/test-command"];
1599 ["command"; "/test-command 7"]], "");
1600 InitBasicFS, Always, TestOutput (
1601 [["upload"; "test-command"; "/test-command"];
1602 ["chmod"; "0o755"; "/test-command"];
1603 ["command"; "/test-command 8"]], "\n");
1604 InitBasicFS, Always, TestOutput (
1605 [["upload"; "test-command"; "/test-command"];
1606 ["chmod"; "0o755"; "/test-command"];
1607 ["command"; "/test-command 9"]], "\n\n");
1608 InitBasicFS, Always, TestOutput (
1609 [["upload"; "test-command"; "/test-command"];
1610 ["chmod"; "0o755"; "/test-command"];
1611 ["command"; "/test-command 10"]], "Result10-1\nResult10-2\n");
1612 InitBasicFS, Always, TestOutput (
1613 [["upload"; "test-command"; "/test-command"];
1614 ["chmod"; "0o755"; "/test-command"];
1615 ["command"; "/test-command 11"]], "Result11-1\nResult11-2");
1616 InitBasicFS, Always, TestLastFail (
1617 [["upload"; "test-command"; "/test-command"];
1618 ["chmod"; "0o755"; "/test-command"];
1619 ["command"; "/test-command"]])],
1620 "run a command from the guest filesystem",
1622 This call runs a command from the guest filesystem. The
1623 filesystem must be mounted, and must contain a compatible
1624 operating system (ie. something Linux, with the same
1625 or compatible processor architecture).
1627 The single parameter is an argv-style list of arguments.
1628 The first element is the name of the program to run.
1629 Subsequent elements are parameters. The list must be
1630 non-empty (ie. must contain a program name). Note that
1631 the command runs directly, and is I<not> invoked via
1632 the shell (see C<guestfs_sh>).
1634 The return value is anything printed to I<stdout> by
1637 If the command returns a non-zero exit status, then
1638 this function returns an error message. The error message
1639 string is the content of I<stderr> from the command.
1641 The C<$PATH> environment variable will contain at least
1642 C</usr/bin> and C</bin>. If you require a program from
1643 another location, you should provide the full path in the
1646 Shared libraries and data files required by the program
1647 must be available on filesystems which are mounted in the
1648 correct places. It is the caller's responsibility to ensure
1649 all filesystems that are needed are mounted at the right
1652 ("command_lines", (RStringList "lines", [StringList "arguments"]), 51, [ProtocolLimitWarning],
1653 [InitBasicFS, Always, TestOutputList (
1654 [["upload"; "test-command"; "/test-command"];
1655 ["chmod"; "0o755"; "/test-command"];
1656 ["command_lines"; "/test-command 1"]], ["Result1"]);
1657 InitBasicFS, Always, TestOutputList (
1658 [["upload"; "test-command"; "/test-command"];
1659 ["chmod"; "0o755"; "/test-command"];
1660 ["command_lines"; "/test-command 2"]], ["Result2"]);
1661 InitBasicFS, Always, TestOutputList (
1662 [["upload"; "test-command"; "/test-command"];
1663 ["chmod"; "0o755"; "/test-command"];
1664 ["command_lines"; "/test-command 3"]], ["";"Result3"]);
1665 InitBasicFS, Always, TestOutputList (
1666 [["upload"; "test-command"; "/test-command"];
1667 ["chmod"; "0o755"; "/test-command"];
1668 ["command_lines"; "/test-command 4"]], ["";"Result4"]);
1669 InitBasicFS, Always, TestOutputList (
1670 [["upload"; "test-command"; "/test-command"];
1671 ["chmod"; "0o755"; "/test-command"];
1672 ["command_lines"; "/test-command 5"]], ["";"Result5";""]);
1673 InitBasicFS, Always, TestOutputList (
1674 [["upload"; "test-command"; "/test-command"];
1675 ["chmod"; "0o755"; "/test-command"];
1676 ["command_lines"; "/test-command 6"]], ["";"";"Result6";""]);
1677 InitBasicFS, Always, TestOutputList (
1678 [["upload"; "test-command"; "/test-command"];
1679 ["chmod"; "0o755"; "/test-command"];
1680 ["command_lines"; "/test-command 7"]], []);
1681 InitBasicFS, Always, TestOutputList (
1682 [["upload"; "test-command"; "/test-command"];
1683 ["chmod"; "0o755"; "/test-command"];
1684 ["command_lines"; "/test-command 8"]], [""]);
1685 InitBasicFS, Always, TestOutputList (
1686 [["upload"; "test-command"; "/test-command"];
1687 ["chmod"; "0o755"; "/test-command"];
1688 ["command_lines"; "/test-command 9"]], ["";""]);
1689 InitBasicFS, Always, TestOutputList (
1690 [["upload"; "test-command"; "/test-command"];
1691 ["chmod"; "0o755"; "/test-command"];
1692 ["command_lines"; "/test-command 10"]], ["Result10-1";"Result10-2"]);
1693 InitBasicFS, Always, TestOutputList (
1694 [["upload"; "test-command"; "/test-command"];
1695 ["chmod"; "0o755"; "/test-command"];
1696 ["command_lines"; "/test-command 11"]], ["Result11-1";"Result11-2"])],
1697 "run a command, returning lines",
1699 This is the same as C<guestfs_command>, but splits the
1700 result into a list of lines.
1702 See also: C<guestfs_sh_lines>");
1704 ("stat", (RStruct ("statbuf", "stat"), [Pathname "path"]), 52, [],
1705 [InitISOFS, Always, TestOutputStruct (
1706 [["stat"; "/empty"]], [CompareWithInt ("size", 0)])],
1707 "get file information",
1709 Returns file information for the given C<path>.
1711 This is the same as the C<stat(2)> system call.");
1713 ("lstat", (RStruct ("statbuf", "stat"), [Pathname "path"]), 53, [],
1714 [InitISOFS, Always, TestOutputStruct (
1715 [["lstat"; "/empty"]], [CompareWithInt ("size", 0)])],
1716 "get file information for a symbolic link",
1718 Returns file information for the given C<path>.
1720 This is the same as C<guestfs_stat> except that if C<path>
1721 is a symbolic link, then the link is stat-ed, not the file it
1724 This is the same as the C<lstat(2)> system call.");
1726 ("statvfs", (RStruct ("statbuf", "statvfs"), [Pathname "path"]), 54, [],
1727 [InitISOFS, Always, TestOutputStruct (
1728 [["statvfs"; "/"]], [CompareWithInt ("namemax", 255)])],
1729 "get file system statistics",
1731 Returns file system statistics for any mounted file system.
1732 C<path> should be a file or directory in the mounted file system
1733 (typically it is the mount point itself, but it doesn't need to be).
1735 This is the same as the C<statvfs(2)> system call.");
1737 ("tune2fs_l", (RHashtable "superblock", [Device "device"]), 55, [],
1739 "get ext2/ext3/ext4 superblock details",
1741 This returns the contents of the ext2, ext3 or ext4 filesystem
1742 superblock on C<device>.
1744 It is the same as running C<tune2fs -l device>. See L<tune2fs(8)>
1745 manpage for more details. The list of fields returned isn't
1746 clearly defined, and depends on both the version of C<tune2fs>
1747 that libguestfs was built against, and the filesystem itself.");
1749 ("blockdev_setro", (RErr, [Device "device"]), 56, [],
1750 [InitEmpty, Always, TestOutputTrue (
1751 [["blockdev_setro"; "/dev/sda"];
1752 ["blockdev_getro"; "/dev/sda"]])],
1753 "set block device to read-only",
1755 Sets the block device named C<device> to read-only.
1757 This uses the L<blockdev(8)> command.");
1759 ("blockdev_setrw", (RErr, [Device "device"]), 57, [],
1760 [InitEmpty, Always, TestOutputFalse (
1761 [["blockdev_setrw"; "/dev/sda"];
1762 ["blockdev_getro"; "/dev/sda"]])],
1763 "set block device to read-write",
1765 Sets the block device named C<device> to read-write.
1767 This uses the L<blockdev(8)> command.");
1769 ("blockdev_getro", (RBool "ro", [Device "device"]), 58, [],
1770 [InitEmpty, Always, TestOutputTrue (
1771 [["blockdev_setro"; "/dev/sda"];
1772 ["blockdev_getro"; "/dev/sda"]])],
1773 "is block device set to read-only",
1775 Returns a boolean indicating if the block device is read-only
1776 (true if read-only, false if not).
1778 This uses the L<blockdev(8)> command.");
1780 ("blockdev_getss", (RInt "sectorsize", [Device "device"]), 59, [],
1781 [InitEmpty, Always, TestOutputInt (
1782 [["blockdev_getss"; "/dev/sda"]], 512)],
1783 "get sectorsize of block device",
1785 This returns the size of sectors on a block device.
1786 Usually 512, but can be larger for modern devices.
1788 (Note, this is not the size in sectors, use C<guestfs_blockdev_getsz>
1791 This uses the L<blockdev(8)> command.");
1793 ("blockdev_getbsz", (RInt "blocksize", [Device "device"]), 60, [],
1794 [InitEmpty, Always, TestOutputInt (
1795 [["blockdev_getbsz"; "/dev/sda"]], 4096)],
1796 "get blocksize of block device",
1798 This returns the block size of a device.
1800 (Note this is different from both I<size in blocks> and
1801 I<filesystem block size>).
1803 This uses the L<blockdev(8)> command.");
1805 ("blockdev_setbsz", (RErr, [Device "device"; Int "blocksize"]), 61, [],
1807 "set blocksize of block device",
1809 This sets the block size of a device.
1811 (Note this is different from both I<size in blocks> and
1812 I<filesystem block size>).
1814 This uses the L<blockdev(8)> command.");
1816 ("blockdev_getsz", (RInt64 "sizeinsectors", [Device "device"]), 62, [],
1817 [InitEmpty, Always, TestOutputInt (
1818 [["blockdev_getsz"; "/dev/sda"]], 1024000)],
1819 "get total size of device in 512-byte sectors",
1821 This returns the size of the device in units of 512-byte sectors
1822 (even if the sectorsize isn't 512 bytes ... weird).
1824 See also C<guestfs_blockdev_getss> for the real sector size of
1825 the device, and C<guestfs_blockdev_getsize64> for the more
1826 useful I<size in bytes>.
1828 This uses the L<blockdev(8)> command.");
1830 ("blockdev_getsize64", (RInt64 "sizeinbytes", [Device "device"]), 63, [],
1831 [InitEmpty, Always, TestOutputInt (
1832 [["blockdev_getsize64"; "/dev/sda"]], 524288000)],
1833 "get total size of device in bytes",
1835 This returns the size of the device in bytes.
1837 See also C<guestfs_blockdev_getsz>.
1839 This uses the L<blockdev(8)> command.");
1841 ("blockdev_flushbufs", (RErr, [Device "device"]), 64, [],
1842 [InitEmpty, Always, TestRun
1843 [["blockdev_flushbufs"; "/dev/sda"]]],
1844 "flush device buffers",
1846 This tells the kernel to flush internal buffers associated
1849 This uses the L<blockdev(8)> command.");
1851 ("blockdev_rereadpt", (RErr, [Device "device"]), 65, [],
1852 [InitEmpty, Always, TestRun
1853 [["blockdev_rereadpt"; "/dev/sda"]]],
1854 "reread partition table",
1856 Reread the partition table on C<device>.
1858 This uses the L<blockdev(8)> command.");
1860 ("upload", (RErr, [FileIn "filename"; String "remotefilename"]), 66, [],
1861 [InitBasicFS, Always, TestOutput (
1862 (* Pick a file from cwd which isn't likely to change. *)
1863 [["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
1864 ["checksum"; "md5"; "/COPYING.LIB"]],
1865 Digest.to_hex (Digest.file "COPYING.LIB"))],
1866 "upload a file from the local machine",
1868 Upload local file C<filename> to C<remotefilename> on the
1871 C<filename> can also be a named pipe.
1873 See also C<guestfs_download>.");
1875 ("download", (RErr, [Dev_or_Path "remotefilename"; FileOut "filename"]), 67, [],
1876 [InitBasicFS, Always, TestOutput (
1877 (* Pick a file from cwd which isn't likely to change. *)
1878 [["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
1879 ["download"; "/COPYING.LIB"; "testdownload.tmp"];
1880 ["upload"; "testdownload.tmp"; "/upload"];
1881 ["checksum"; "md5"; "/upload"]],
1882 Digest.to_hex (Digest.file "COPYING.LIB"))],
1883 "download a file to the local machine",
1885 Download file C<remotefilename> and save it as C<filename>
1886 on the local machine.
1888 C<filename> can also be a named pipe.
1890 See also C<guestfs_upload>, C<guestfs_cat>.");
1892 ("checksum", (RString "checksum", [String "csumtype"; Pathname "path"]), 68, [],
1893 [InitISOFS, Always, TestOutput (
1894 [["checksum"; "crc"; "/known-3"]], "2891671662");
1895 InitISOFS, Always, TestLastFail (
1896 [["checksum"; "crc"; "/notexists"]]);
1897 InitISOFS, Always, TestOutput (
1898 [["checksum"; "md5"; "/known-3"]], "46d6ca27ee07cdc6fa99c2e138cc522c");
1899 InitISOFS, Always, TestOutput (
1900 [["checksum"; "sha1"; "/known-3"]], "b7ebccc3ee418311091c3eda0a45b83c0a770f15");
1901 InitISOFS, Always, TestOutput (
1902 [["checksum"; "sha224"; "/known-3"]], "d2cd1774b28f3659c14116be0a6dc2bb5c4b350ce9cd5defac707741");
1903 InitISOFS, Always, TestOutput (
1904 [["checksum"; "sha256"; "/known-3"]], "75bb71b90cd20cb13f86d2bea8dad63ac7194e7517c3b52b8d06ff52d3487d30");
1905 InitISOFS, Always, TestOutput (
1906 [["checksum"; "sha384"; "/known-3"]], "5fa7883430f357b5d7b7271d3a1d2872b51d73cba72731de6863d3dea55f30646af2799bef44d5ea776a5ec7941ac640");
1907 InitISOFS, Always, TestOutput (
1908 [["checksum"; "sha512"; "/known-3"]], "2794062c328c6b216dca90443b7f7134c5f40e56bd0ed7853123275a09982a6f992e6ca682f9d2fba34a4c5e870d8fe077694ff831e3032a004ee077e00603f6")],
1909 "compute MD5, SHAx or CRC checksum of file",
1911 This call computes the MD5, SHAx or CRC checksum of the
1914 The type of checksum to compute is given by the C<csumtype>
1915 parameter which must have one of the following values:
1921 Compute the cyclic redundancy check (CRC) specified by POSIX
1922 for the C<cksum> command.
1926 Compute the MD5 hash (using the C<md5sum> program).
1930 Compute the SHA1 hash (using the C<sha1sum> program).
1934 Compute the SHA224 hash (using the C<sha224sum> program).
1938 Compute the SHA256 hash (using the C<sha256sum> program).
1942 Compute the SHA384 hash (using the C<sha384sum> program).
1946 Compute the SHA512 hash (using the C<sha512sum> program).
1950 The checksum is returned as a printable string.");
1952 ("tar_in", (RErr, [FileIn "tarfile"; String "directory"]), 69, [],
1953 [InitBasicFS, Always, TestOutput (
1954 [["tar_in"; "../images/helloworld.tar"; "/"];
1955 ["cat"; "/hello"]], "hello\n")],
1956 "unpack tarfile to directory",
1958 This command uploads and unpacks local file C<tarfile> (an
1959 I<uncompressed> tar file) into C<directory>.
1961 To upload a compressed tarball, use C<guestfs_tgz_in>.");
1963 ("tar_out", (RErr, [String "directory"; FileOut "tarfile"]), 70, [],
1965 "pack directory into tarfile",
1967 This command packs the contents of C<directory> and downloads
1968 it to local file C<tarfile>.
1970 To download a compressed tarball, use C<guestfs_tgz_out>.");
1972 ("tgz_in", (RErr, [FileIn "tarball"; String "directory"]), 71, [],
1973 [InitBasicFS, Always, TestOutput (
1974 [["tgz_in"; "../images/helloworld.tar.gz"; "/"];
1975 ["cat"; "/hello"]], "hello\n")],
1976 "unpack compressed tarball to directory",
1978 This command uploads and unpacks local file C<tarball> (a
1979 I<gzip compressed> tar file) into C<directory>.
1981 To upload an uncompressed tarball, use C<guestfs_tar_in>.");
1983 ("tgz_out", (RErr, [Pathname "directory"; FileOut "tarball"]), 72, [],
1985 "pack directory into compressed tarball",
1987 This command packs the contents of C<directory> and downloads
1988 it to local file C<tarball>.
1990 To download an uncompressed tarball, use C<guestfs_tar_out>.");
1992 ("mount_ro", (RErr, [Device "device"; String "mountpoint"]), 73, [],
1993 [InitBasicFS, Always, TestLastFail (
1995 ["mount_ro"; "/dev/sda1"; "/"];
1996 ["touch"; "/new"]]);
1997 InitBasicFS, Always, TestOutput (
1998 [["write_file"; "/new"; "data"; "0"];
2000 ["mount_ro"; "/dev/sda1"; "/"];
2001 ["cat"; "/new"]], "data")],
2002 "mount a guest disk, read-only",
2004 This is the same as the C<guestfs_mount> command, but it
2005 mounts the filesystem with the read-only (I<-o ro>) flag.");
2007 ("mount_options", (RErr, [String "options"; Device "device"; String "mountpoint"]), 74, [],
2009 "mount a guest disk with mount options",
2011 This is the same as the C<guestfs_mount> command, but it
2012 allows you to set the mount options as for the
2013 L<mount(8)> I<-o> flag.");
2015 ("mount_vfs", (RErr, [String "options"; String "vfstype"; Device "device"; String "mountpoint"]), 75, [],
2017 "mount a guest disk with mount options and vfstype",
2019 This is the same as the C<guestfs_mount> command, but it
2020 allows you to set both the mount options and the vfstype
2021 as for the L<mount(8)> I<-o> and I<-t> flags.");
2023 ("debug", (RString "result", [String "subcmd"; StringList "extraargs"]), 76, [],
2025 "debugging and internals",
2027 The C<guestfs_debug> command exposes some internals of
2028 C<guestfsd> (the guestfs daemon) that runs inside the
2031 There is no comprehensive help for this command. You have
2032 to look at the file C<daemon/debug.c> in the libguestfs source
2033 to find out what you can do.");
2035 ("lvremove", (RErr, [Device "device"]), 77, [],
2036 [InitEmpty, Always, TestOutputList (
2037 [["sfdiskM"; "/dev/sda"; ","];
2038 ["pvcreate"; "/dev/sda1"];
2039 ["vgcreate"; "VG"; "/dev/sda1"];
2040 ["lvcreate"; "LV1"; "VG"; "50"];
2041 ["lvcreate"; "LV2"; "VG"; "50"];
2042 ["lvremove"; "/dev/VG/LV1"];
2043 ["lvs"]], ["/dev/VG/LV2"]);
2044 InitEmpty, Always, TestOutputList (
2045 [["sfdiskM"; "/dev/sda"; ","];
2046 ["pvcreate"; "/dev/sda1"];
2047 ["vgcreate"; "VG"; "/dev/sda1"];
2048 ["lvcreate"; "LV1"; "VG"; "50"];
2049 ["lvcreate"; "LV2"; "VG"; "50"];
2050 ["lvremove"; "/dev/VG"];
2052 InitEmpty, Always, TestOutputList (
2053 [["sfdiskM"; "/dev/sda"; ","];
2054 ["pvcreate"; "/dev/sda1"];
2055 ["vgcreate"; "VG"; "/dev/sda1"];
2056 ["lvcreate"; "LV1"; "VG"; "50"];
2057 ["lvcreate"; "LV2"; "VG"; "50"];
2058 ["lvremove"; "/dev/VG"];
2060 "remove an LVM logical volume",
2062 Remove an LVM logical volume C<device>, where C<device> is
2063 the path to the LV, such as C</dev/VG/LV>.
2065 You can also remove all LVs in a volume group by specifying
2066 the VG name, C</dev/VG>.");
2068 ("vgremove", (RErr, [String "vgname"]), 78, [],
2069 [InitEmpty, Always, TestOutputList (
2070 [["sfdiskM"; "/dev/sda"; ","];
2071 ["pvcreate"; "/dev/sda1"];
2072 ["vgcreate"; "VG"; "/dev/sda1"];
2073 ["lvcreate"; "LV1"; "VG"; "50"];
2074 ["lvcreate"; "LV2"; "VG"; "50"];
2077 InitEmpty, Always, TestOutputList (
2078 [["sfdiskM"; "/dev/sda"; ","];
2079 ["pvcreate"; "/dev/sda1"];
2080 ["vgcreate"; "VG"; "/dev/sda1"];
2081 ["lvcreate"; "LV1"; "VG"; "50"];
2082 ["lvcreate"; "LV2"; "VG"; "50"];
2085 "remove an LVM volume group",
2087 Remove an LVM volume group C<vgname>, (for example C<VG>).
2089 This also forcibly removes all logical volumes in the volume
2092 ("pvremove", (RErr, [Device "device"]), 79, [],
2093 [InitEmpty, Always, TestOutputListOfDevices (
2094 [["sfdiskM"; "/dev/sda"; ","];
2095 ["pvcreate"; "/dev/sda1"];
2096 ["vgcreate"; "VG"; "/dev/sda1"];
2097 ["lvcreate"; "LV1"; "VG"; "50"];
2098 ["lvcreate"; "LV2"; "VG"; "50"];
2100 ["pvremove"; "/dev/sda1"];
2102 InitEmpty, Always, TestOutputListOfDevices (
2103 [["sfdiskM"; "/dev/sda"; ","];
2104 ["pvcreate"; "/dev/sda1"];
2105 ["vgcreate"; "VG"; "/dev/sda1"];
2106 ["lvcreate"; "LV1"; "VG"; "50"];
2107 ["lvcreate"; "LV2"; "VG"; "50"];
2109 ["pvremove"; "/dev/sda1"];
2111 InitEmpty, Always, TestOutputListOfDevices (
2112 [["sfdiskM"; "/dev/sda"; ","];
2113 ["pvcreate"; "/dev/sda1"];
2114 ["vgcreate"; "VG"; "/dev/sda1"];
2115 ["lvcreate"; "LV1"; "VG"; "50"];
2116 ["lvcreate"; "LV2"; "VG"; "50"];
2118 ["pvremove"; "/dev/sda1"];
2120 "remove an LVM physical volume",
2122 This wipes a physical volume C<device> so that LVM will no longer
2125 The implementation uses the C<pvremove> command which refuses to
2126 wipe physical volumes that contain any volume groups, so you have
2127 to remove those first.");
2129 ("set_e2label", (RErr, [Device "device"; String "label"]), 80, [],
2130 [InitBasicFS, Always, TestOutput (
2131 [["set_e2label"; "/dev/sda1"; "testlabel"];
2132 ["get_e2label"; "/dev/sda1"]], "testlabel")],
2133 "set the ext2/3/4 filesystem label",
2135 This sets the ext2/3/4 filesystem label of the filesystem on
2136 C<device> to C<label>. Filesystem labels are limited to
2139 You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2label>
2140 to return the existing label on a filesystem.");
2142 ("get_e2label", (RString "label", [Device "device"]), 81, [],
2144 "get the ext2/3/4 filesystem label",
2146 This returns the ext2/3/4 filesystem label of the filesystem on
2149 ("set_e2uuid", (RErr, [Device "device"; String "uuid"]), 82, [],
2150 (let uuid = uuidgen () in
2151 [InitBasicFS, Always, TestOutput (
2152 [["set_e2uuid"; "/dev/sda1"; uuid];
2153 ["get_e2uuid"; "/dev/sda1"]], uuid);
2154 InitBasicFS, Always, TestOutput (
2155 [["set_e2uuid"; "/dev/sda1"; "clear"];
2156 ["get_e2uuid"; "/dev/sda1"]], "");
2157 (* We can't predict what UUIDs will be, so just check the commands run. *)
2158 InitBasicFS, Always, TestRun (
2159 [["set_e2uuid"; "/dev/sda1"; "random"]]);
2160 InitBasicFS, Always, TestRun (
2161 [["set_e2uuid"; "/dev/sda1"; "time"]])]),
2162 "set the ext2/3/4 filesystem UUID",
2164 This sets the ext2/3/4 filesystem UUID of the filesystem on
2165 C<device> to C<uuid>. The format of the UUID and alternatives
2166 such as C<clear>, C<random> and C<time> are described in the
2167 L<tune2fs(8)> manpage.
2169 You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2uuid>
2170 to return the existing UUID of a filesystem.");
2172 ("get_e2uuid", (RString "uuid", [Device "device"]), 83, [],
2174 "get the ext2/3/4 filesystem UUID",
2176 This returns the ext2/3/4 filesystem UUID of the filesystem on
2179 ("fsck", (RInt "status", [String "fstype"; Device "device"]), 84, [],
2180 [InitBasicFS, Always, TestOutputInt (
2181 [["umount"; "/dev/sda1"];
2182 ["fsck"; "ext2"; "/dev/sda1"]], 0);
2183 InitBasicFS, Always, TestOutputInt (
2184 [["umount"; "/dev/sda1"];
2185 ["zero"; "/dev/sda1"];
2186 ["fsck"; "ext2"; "/dev/sda1"]], 8)],
2187 "run the filesystem checker",
2189 This runs the filesystem checker (fsck) on C<device> which
2190 should have filesystem type C<fstype>.
2192 The returned integer is the status. See L<fsck(8)> for the
2193 list of status codes from C<fsck>.
2201 Multiple status codes can be summed together.
2205 A non-zero return code can mean \"success\", for example if
2206 errors have been corrected on the filesystem.
2210 Checking or repairing NTFS volumes is not supported
2215 This command is entirely equivalent to running C<fsck -a -t fstype device>.");
2217 ("zero", (RErr, [Device "device"]), 85, [],
2218 [InitBasicFS, Always, TestOutput (
2219 [["umount"; "/dev/sda1"];
2220 ["zero"; "/dev/sda1"];
2221 ["file"; "/dev/sda1"]], "data")],
2222 "write zeroes to the device",
2224 This command writes zeroes over the first few blocks of C<device>.
2226 How many blocks are zeroed isn't specified (but it's I<not> enough
2227 to securely wipe the device). It should be sufficient to remove
2228 any partition tables, filesystem superblocks and so on.
2230 See also: C<guestfs_scrub_device>.");
2232 ("grub_install", (RErr, [Pathname "root"; Device "device"]), 86, [],
2233 (* Test disabled because grub-install incompatible with virtio-blk driver.
2234 * See also: https://bugzilla.redhat.com/show_bug.cgi?id=479760
2236 [InitBasicFS, Disabled, TestOutputTrue (
2237 [["grub_install"; "/"; "/dev/sda1"];
2238 ["is_dir"; "/boot"]])],
2241 This command installs GRUB (the Grand Unified Bootloader) on
2242 C<device>, with the root directory being C<root>.");
2244 ("cp", (RErr, [Pathname "src"; Pathname "dest"]), 87, [],
2245 [InitBasicFS, Always, TestOutput (
2246 [["write_file"; "/old"; "file content"; "0"];
2247 ["cp"; "/old"; "/new"];
2248 ["cat"; "/new"]], "file content");
2249 InitBasicFS, Always, TestOutputTrue (
2250 [["write_file"; "/old"; "file content"; "0"];
2251 ["cp"; "/old"; "/new"];
2252 ["is_file"; "/old"]]);
2253 InitBasicFS, Always, TestOutput (
2254 [["write_file"; "/old"; "file content"; "0"];
2256 ["cp"; "/old"; "/dir/new"];
2257 ["cat"; "/dir/new"]], "file content")],
2260 This copies a file from C<src> to C<dest> where C<dest> is
2261 either a destination filename or destination directory.");
2263 ("cp_a", (RErr, [Pathname "src"; Pathname "dest"]), 88, [],
2264 [InitBasicFS, Always, TestOutput (
2265 [["mkdir"; "/olddir"];
2266 ["mkdir"; "/newdir"];
2267 ["write_file"; "/olddir/file"; "file content"; "0"];
2268 ["cp_a"; "/olddir"; "/newdir"];
2269 ["cat"; "/newdir/olddir/file"]], "file content")],
2270 "copy a file or directory recursively",
2272 This copies a file or directory from C<src> to C<dest>
2273 recursively using the C<cp -a> command.");
2275 ("mv", (RErr, [Pathname "src"; Pathname "dest"]), 89, [],
2276 [InitBasicFS, Always, TestOutput (
2277 [["write_file"; "/old"; "file content"; "0"];
2278 ["mv"; "/old"; "/new"];
2279 ["cat"; "/new"]], "file content");
2280 InitBasicFS, Always, TestOutputFalse (
2281 [["write_file"; "/old"; "file content"; "0"];
2282 ["mv"; "/old"; "/new"];
2283 ["is_file"; "/old"]])],
2286 This moves a file from C<src> to C<dest> where C<dest> is
2287 either a destination filename or destination directory.");
2289 ("drop_caches", (RErr, [Int "whattodrop"]), 90, [],
2290 [InitEmpty, Always, TestRun (
2291 [["drop_caches"; "3"]])],
2292 "drop kernel page cache, dentries and inodes",
2294 This instructs the guest kernel to drop its page cache,
2295 and/or dentries and inode caches. The parameter C<whattodrop>
2296 tells the kernel what precisely to drop, see
2297 L<http://linux-mm.org/Drop_Caches>
2299 Setting C<whattodrop> to 3 should drop everything.
2301 This automatically calls L<sync(2)> before the operation,
2302 so that the maximum guest memory is freed.");
2304 ("dmesg", (RString "kmsgs", []), 91, [],
2305 [InitEmpty, Always, TestRun (
2307 "return kernel messages",
2309 This returns the kernel messages (C<dmesg> output) from
2310 the guest kernel. This is sometimes useful for extended
2311 debugging of problems.
2313 Another way to get the same information is to enable
2314 verbose messages with C<guestfs_set_verbose> or by setting
2315 the environment variable C<LIBGUESTFS_DEBUG=1> before
2316 running the program.");
2318 ("ping_daemon", (RErr, []), 92, [],
2319 [InitEmpty, Always, TestRun (
2320 [["ping_daemon"]])],
2321 "ping the guest daemon",
2323 This is a test probe into the guestfs daemon running inside
2324 the qemu subprocess. Calling this function checks that the
2325 daemon responds to the ping message, without affecting the daemon
2326 or attached block device(s) in any other way.");
2328 ("equal", (RBool "equality", [Pathname "file1"; Pathname "file2"]), 93, [],
2329 [InitBasicFS, Always, TestOutputTrue (
2330 [["write_file"; "/file1"; "contents of a file"; "0"];
2331 ["cp"; "/file1"; "/file2"];
2332 ["equal"; "/file1"; "/file2"]]);
2333 InitBasicFS, Always, TestOutputFalse (
2334 [["write_file"; "/file1"; "contents of a file"; "0"];
2335 ["write_file"; "/file2"; "contents of another file"; "0"];
2336 ["equal"; "/file1"; "/file2"]]);
2337 InitBasicFS, Always, TestLastFail (
2338 [["equal"; "/file1"; "/file2"]])],
2339 "test if two files have equal contents",
2341 This compares the two files C<file1> and C<file2> and returns
2342 true if their content is exactly equal, or false otherwise.
2344 The external L<cmp(1)> program is used for the comparison.");
2346 ("strings", (RStringList "stringsout", [Pathname "path"]), 94, [ProtocolLimitWarning],
2347 [InitISOFS, Always, TestOutputList (
2348 [["strings"; "/known-5"]], ["abcdefghi"; "jklmnopqr"]);
2349 InitISOFS, Always, TestOutputList (
2350 [["strings"; "/empty"]], [])],
2351 "print the printable strings in a file",
2353 This runs the L<strings(1)> command on a file and returns
2354 the list of printable strings found.");
2356 ("strings_e", (RStringList "stringsout", [String "encoding"; Pathname "path"]), 95, [ProtocolLimitWarning],
2357 [InitISOFS, Always, TestOutputList (
2358 [["strings_e"; "b"; "/known-5"]], []);
2359 InitBasicFS, Disabled, TestOutputList (
2360 [["write_file"; "/new"; "\000h\000e\000l\000l\000o\000\n\000w\000o\000r\000l\000d\000\n"; "24"];
2361 ["strings_e"; "b"; "/new"]], ["hello"; "world"])],
2362 "print the printable strings in a file",
2364 This is like the C<guestfs_strings> command, but allows you to
2365 specify the encoding.
2367 See the L<strings(1)> manpage for the full list of encodings.
2369 Commonly useful encodings are C<l> (lower case L) which will
2370 show strings inside Windows/x86 files.
2372 The returned strings are transcoded to UTF-8.");
2374 ("hexdump", (RString "dump", [Pathname "path"]), 96, [ProtocolLimitWarning],
2375 [InitISOFS, Always, TestOutput (
2376 [["hexdump"; "/known-4"]], "00000000 61 62 63 0a 64 65 66 0a 67 68 69 |abc.def.ghi|\n0000000b\n");
2377 (* Test for RHBZ#501888c2 regression which caused large hexdump
2378 * commands to segfault.
2380 InitISOFS, Always, TestRun (
2381 [["hexdump"; "/100krandom"]])],
2382 "dump a file in hexadecimal",
2384 This runs C<hexdump -C> on the given C<path>. The result is
2385 the human-readable, canonical hex dump of the file.");
2387 ("zerofree", (RErr, [Device "device"]), 97, [],
2388 [InitNone, Always, TestOutput (
2389 [["sfdiskM"; "/dev/sda"; ","];
2390 ["mkfs"; "ext3"; "/dev/sda1"];
2391 ["mount"; "/dev/sda1"; "/"];
2392 ["write_file"; "/new"; "test file"; "0"];
2393 ["umount"; "/dev/sda1"];
2394 ["zerofree"; "/dev/sda1"];
2395 ["mount"; "/dev/sda1"; "/"];
2396 ["cat"; "/new"]], "test file")],
2397 "zero unused inodes and disk blocks on ext2/3 filesystem",
2399 This runs the I<zerofree> program on C<device>. This program
2400 claims to zero unused inodes and disk blocks on an ext2/3
2401 filesystem, thus making it possible to compress the filesystem
2404 You should B<not> run this program if the filesystem is
2407 It is possible that using this program can damage the filesystem
2408 or data on the filesystem.");
2410 ("pvresize", (RErr, [Device "device"]), 98, [],
2412 "resize an LVM physical volume",
2414 This resizes (expands or shrinks) an existing LVM physical
2415 volume to match the new size of the underlying device.");
2417 ("sfdisk_N", (RErr, [Device "device"; Int "partnum";
2418 Int "cyls"; Int "heads"; Int "sectors";
2419 String "line"]), 99, [DangerWillRobinson],
2421 "modify a single partition on a block device",
2423 This runs L<sfdisk(8)> option to modify just the single
2424 partition C<n> (note: C<n> counts from 1).
2426 For other parameters, see C<guestfs_sfdisk>. You should usually
2427 pass C<0> for the cyls/heads/sectors parameters.");
2429 ("sfdisk_l", (RString "partitions", [Device "device"]), 100, [],
2431 "display the partition table",
2433 This displays the partition table on C<device>, in the
2434 human-readable output of the L<sfdisk(8)> command. It is
2435 not intended to be parsed.");
2437 ("sfdisk_kernel_geometry", (RString "partitions", [Device "device"]), 101, [],
2439 "display the kernel geometry",
2441 This displays the kernel's idea of the geometry of C<device>.
2443 The result is in human-readable format, and not designed to
2446 ("sfdisk_disk_geometry", (RString "partitions", [Device "device"]), 102, [],
2448 "display the disk geometry from the partition table",
2450 This displays the disk geometry of C<device> read from the
2451 partition table. Especially in the case where the underlying
2452 block device has been resized, this can be different from the
2453 kernel's idea of the geometry (see C<guestfs_sfdisk_kernel_geometry>).
2455 The result is in human-readable format, and not designed to
2458 ("vg_activate_all", (RErr, [Bool "activate"]), 103, [],
2460 "activate or deactivate all volume groups",
2462 This command activates or (if C<activate> is false) deactivates
2463 all logical volumes in all volume groups.
2464 If activated, then they are made known to the
2465 kernel, ie. they appear as C</dev/mapper> devices. If deactivated,
2466 then those devices disappear.
2468 This command is the same as running C<vgchange -a y|n>");
2470 ("vg_activate", (RErr, [Bool "activate"; StringList "volgroups"]), 104, [],
2472 "activate or deactivate some volume groups",
2474 This command activates or (if C<activate> is false) deactivates
2475 all logical volumes in the listed volume groups C<volgroups>.
2476 If activated, then they are made known to the
2477 kernel, ie. they appear as C</dev/mapper> devices. If deactivated,
2478 then those devices disappear.
2480 This command is the same as running C<vgchange -a y|n volgroups...>
2482 Note that if C<volgroups> is an empty list then B<all> volume groups
2483 are activated or deactivated.");
2485 ("lvresize", (RErr, [Device "device"; Int "mbytes"]), 105, [],
2486 [InitNone, Always, TestOutput (
2487 [["sfdiskM"; "/dev/sda"; ","];
2488 ["pvcreate"; "/dev/sda1"];
2489 ["vgcreate"; "VG"; "/dev/sda1"];
2490 ["lvcreate"; "LV"; "VG"; "10"];
2491 ["mkfs"; "ext2"; "/dev/VG/LV"];
2492 ["mount"; "/dev/VG/LV"; "/"];
2493 ["write_file"; "/new"; "test content"; "0"];
2495 ["lvresize"; "/dev/VG/LV"; "20"];
2496 ["e2fsck_f"; "/dev/VG/LV"];
2497 ["resize2fs"; "/dev/VG/LV"];
2498 ["mount"; "/dev/VG/LV"; "/"];
2499 ["cat"; "/new"]], "test content")],
2500 "resize an LVM logical volume",
2502 This resizes (expands or shrinks) an existing LVM logical
2503 volume to C<mbytes>. When reducing, data in the reduced part
2506 ("resize2fs", (RErr, [Device "device"]), 106, [],
2507 [], (* lvresize tests this *)
2508 "resize an ext2/ext3 filesystem",
2510 This resizes an ext2 or ext3 filesystem to match the size of
2511 the underlying device.
2513 I<Note:> It is sometimes required that you run C<guestfs_e2fsck_f>
2514 on the C<device> before calling this command. For unknown reasons
2515 C<resize2fs> sometimes gives an error about this and sometimes not.
2516 In any case, it is always safe to call C<guestfs_e2fsck_f> before
2517 calling this function.");
2519 ("find", (RStringList "names", [Pathname "directory"]), 107, [ProtocolLimitWarning],
2520 [InitBasicFS, Always, TestOutputList (
2521 [["find"; "/"]], ["lost+found"]);
2522 InitBasicFS, Always, TestOutputList (
2526 ["find"; "/"]], ["a"; "b"; "b/c"; "lost+found"]);
2527 InitBasicFS, Always, TestOutputList (
2528 [["mkdir_p"; "/a/b/c"];
2529 ["touch"; "/a/b/c/d"];
2530 ["find"; "/a/b/"]], ["c"; "c/d"])],
2531 "find all files and directories",
2533 This command lists out all files and directories, recursively,
2534 starting at C<directory>. It is essentially equivalent to
2535 running the shell command C<find directory -print> but some
2536 post-processing happens on the output, described below.
2538 This returns a list of strings I<without any prefix>. Thus
2539 if the directory structure was:
2545 then the returned list from C<guestfs_find> C</tmp> would be
2553 If C<directory> is not a directory, then this command returns
2556 The returned list is sorted.
2558 See also C<guestfs_find0>.");
2560 ("e2fsck_f", (RErr, [Device "device"]), 108, [],
2561 [], (* lvresize tests this *)
2562 "check an ext2/ext3 filesystem",
2564 This runs C<e2fsck -p -f device>, ie. runs the ext2/ext3
2565 filesystem checker on C<device>, noninteractively (C<-p>),
2566 even if the filesystem appears to be clean (C<-f>).
2568 This command is only needed because of C<guestfs_resize2fs>
2569 (q.v.). Normally you should use C<guestfs_fsck>.");
2571 ("sleep", (RErr, [Int "secs"]), 109, [],
2572 [InitNone, Always, TestRun (
2574 "sleep for some seconds",
2576 Sleep for C<secs> seconds.");
2578 ("ntfs_3g_probe", (RInt "status", [Bool "rw"; Device "device"]), 110, [],
2579 [InitNone, Always, TestOutputInt (
2580 [["sfdiskM"; "/dev/sda"; ","];
2581 ["mkfs"; "ntfs"; "/dev/sda1"];
2582 ["ntfs_3g_probe"; "true"; "/dev/sda1"]], 0);
2583 InitNone, Always, TestOutputInt (
2584 [["sfdiskM"; "/dev/sda"; ","];
2585 ["mkfs"; "ext2"; "/dev/sda1"];
2586 ["ntfs_3g_probe"; "true"; "/dev/sda1"]], 12)],
2587 "probe NTFS volume",
2589 This command runs the L<ntfs-3g.probe(8)> command which probes
2590 an NTFS C<device> for mountability. (Not all NTFS volumes can
2591 be mounted read-write, and some cannot be mounted at all).
2593 C<rw> is a boolean flag. Set it to true if you want to test
2594 if the volume can be mounted read-write. Set it to false if
2595 you want to test if the volume can be mounted read-only.
2597 The return value is an integer which C<0> if the operation
2598 would succeed, or some non-zero value documented in the
2599 L<ntfs-3g.probe(8)> manual page.");
2601 ("sh", (RString "output", [String "command"]), 111, [],
2602 [], (* XXX needs tests *)
2603 "run a command via the shell",
2605 This call runs a command from the guest filesystem via the
2608 This is like C<guestfs_command>, but passes the command to:
2610 /bin/sh -c \"command\"
2612 Depending on the guest's shell, this usually results in
2613 wildcards being expanded, shell expressions being interpolated
2616 All the provisos about C<guestfs_command> apply to this call.");
2618 ("sh_lines", (RStringList "lines", [String "command"]), 112, [],
2619 [], (* XXX needs tests *)
2620 "run a command via the shell returning lines",
2622 This is the same as C<guestfs_sh>, but splits the result
2623 into a list of lines.
2625 See also: C<guestfs_command_lines>");
2627 ("glob_expand", (RStringList "paths", [Pathname "pattern"]), 113, [],
2628 (* Use Pathname here, and hence ABS_PATH (pattern,... in generated
2629 * code in stubs.c, since all valid glob patterns must start with "/".
2630 * There is no concept of "cwd" in libguestfs, hence no "."-relative names.
2632 [InitBasicFS, Always, TestOutputList (
2633 [["mkdir_p"; "/a/b/c"];
2634 ["touch"; "/a/b/c/d"];
2635 ["touch"; "/a/b/c/e"];
2636 ["glob_expand"; "/a/b/c/*"]], ["/a/b/c/d"; "/a/b/c/e"]);
2637 InitBasicFS, Always, TestOutputList (
2638 [["mkdir_p"; "/a/b/c"];
2639 ["touch"; "/a/b/c/d"];
2640 ["touch"; "/a/b/c/e"];
2641 ["glob_expand"; "/a/*/c/*"]], ["/a/b/c/d"; "/a/b/c/e"]);
2642 InitBasicFS, Always, TestOutputList (
2643 [["mkdir_p"; "/a/b/c"];
2644 ["touch"; "/a/b/c/d"];
2645 ["touch"; "/a/b/c/e"];
2646 ["glob_expand"; "/a/*/x/*"]], [])],
2647 "expand a wildcard path",
2649 This command searches for all the pathnames matching
2650 C<pattern> according to the wildcard expansion rules
2653 If no paths match, then this returns an empty list
2654 (note: not an error).
2656 It is just a wrapper around the C L<glob(3)> function
2657 with flags C<GLOB_MARK|GLOB_BRACE>.
2658 See that manual page for more details.");
2660 ("scrub_device", (RErr, [Device "device"]), 114, [DangerWillRobinson],
2661 [InitNone, Always, TestRun ( (* use /dev/sdc because it's smaller *)
2662 [["scrub_device"; "/dev/sdc"]])],
2663 "scrub (securely wipe) a device",
2665 This command writes patterns over C<device> to make data retrieval
2668 It is an interface to the L<scrub(1)> program. See that
2669 manual page for more details.");
2671 ("scrub_file", (RErr, [Pathname "file"]), 115, [],
2672 [InitBasicFS, Always, TestRun (
2673 [["write_file"; "/file"; "content"; "0"];
2674 ["scrub_file"; "/file"]])],
2675 "scrub (securely wipe) a file",
2677 This command writes patterns over a file to make data retrieval
2680 The file is I<removed> after scrubbing.
2682 It is an interface to the L<scrub(1)> program. See that
2683 manual page for more details.");
2685 ("scrub_freespace", (RErr, [Pathname "dir"]), 116, [],
2686 [], (* XXX needs testing *)
2687 "scrub (securely wipe) free space",
2689 This command creates the directory C<dir> and then fills it
2690 with files until the filesystem is full, and scrubs the files
2691 as for C<guestfs_scrub_file>, and deletes them.
2692 The intention is to scrub any free space on the partition
2695 It is an interface to the L<scrub(1)> program. See that
2696 manual page for more details.");
2698 ("mkdtemp", (RString "dir", [Pathname "template"]), 117, [],
2699 [InitBasicFS, Always, TestRun (
2701 ["mkdtemp"; "/tmp/tmpXXXXXX"]])],
2702 "create a temporary directory",
2704 This command creates a temporary directory. The
2705 C<template> parameter should be a full pathname for the
2706 temporary directory name with the final six characters being
2709 For example: \"/tmp/myprogXXXXXX\" or \"/Temp/myprogXXXXXX\",
2710 the second one being suitable for Windows filesystems.
2712 The name of the temporary directory that was created
2715 The temporary directory is created with mode 0700
2716 and is owned by root.
2718 The caller is responsible for deleting the temporary
2719 directory and its contents after use.
2721 See also: L<mkdtemp(3)>");
2723 ("wc_l", (RInt "lines", [Pathname "path"]), 118, [],
2724 [InitISOFS, Always, TestOutputInt (
2725 [["wc_l"; "/10klines"]], 10000)],
2726 "count lines in a file",
2728 This command counts the lines in a file, using the
2729 C<wc -l> external command.");
2731 ("wc_w", (RInt "words", [Pathname "path"]), 119, [],
2732 [InitISOFS, Always, TestOutputInt (
2733 [["wc_w"; "/10klines"]], 10000)],
2734 "count words in a file",
2736 This command counts the words in a file, using the
2737 C<wc -w> external command.");
2739 ("wc_c", (RInt "chars", [Pathname "path"]), 120, [],
2740 [InitISOFS, Always, TestOutputInt (
2741 [["wc_c"; "/100kallspaces"]], 102400)],
2742 "count characters in a file",
2744 This command counts the characters in a file, using the
2745 C<wc -c> external command.");
2747 ("head", (RStringList "lines", [Pathname "path"]), 121, [ProtocolLimitWarning],
2748 [InitISOFS, Always, TestOutputList (
2749 [["head"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz";"3abcdefghijklmnopqrstuvwxyz";"4abcdefghijklmnopqrstuvwxyz";"5abcdefghijklmnopqrstuvwxyz";"6abcdefghijklmnopqrstuvwxyz";"7abcdefghijklmnopqrstuvwxyz";"8abcdefghijklmnopqrstuvwxyz";"9abcdefghijklmnopqrstuvwxyz"])],
2750 "return first 10 lines of a file",
2752 This command returns up to the first 10 lines of a file as
2753 a list of strings.");
2755 ("head_n", (RStringList "lines", [Int "nrlines"; Pathname "path"]), 122, [ProtocolLimitWarning],
2756 [InitISOFS, Always, TestOutputList (
2757 [["head_n"; "3"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz"]);
2758 InitISOFS, Always, TestOutputList (
2759 [["head_n"; "-9997"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz"]);
2760 InitISOFS, Always, TestOutputList (
2761 [["head_n"; "0"; "/10klines"]], [])],
2762 "return first N lines of a file",
2764 If the parameter C<nrlines> is a positive number, this returns the first
2765 C<nrlines> lines of the file C<path>.
2767 If the parameter C<nrlines> is a negative number, this returns lines
2768 from the file C<path>, excluding the last C<nrlines> lines.
2770 If the parameter C<nrlines> is zero, this returns an empty list.");
2772 ("tail", (RStringList "lines", [Pathname "path"]), 123, [ProtocolLimitWarning],
2773 [InitISOFS, Always, TestOutputList (
2774 [["tail"; "/10klines"]], ["9990abcdefghijklmnopqrstuvwxyz";"9991abcdefghijklmnopqrstuvwxyz";"9992abcdefghijklmnopqrstuvwxyz";"9993abcdefghijklmnopqrstuvwxyz";"9994abcdefghijklmnopqrstuvwxyz";"9995abcdefghijklmnopqrstuvwxyz";"9996abcdefghijklmnopqrstuvwxyz";"9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"])],
2775 "return last 10 lines of a file",
2777 This command returns up to the last 10 lines of a file as
2778 a list of strings.");
2780 ("tail_n", (RStringList "lines", [Int "nrlines"; Pathname "path"]), 124, [ProtocolLimitWarning],
2781 [InitISOFS, Always, TestOutputList (
2782 [["tail_n"; "3"; "/10klines"]], ["9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"]);
2783 InitISOFS, Always, TestOutputList (
2784 [["tail_n"; "-9998"; "/10klines"]], ["9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"]);
2785 InitISOFS, Always, TestOutputList (
2786 [["tail_n"; "0"; "/10klines"]], [])],
2787 "return last N lines of a file",
2789 If the parameter C<nrlines> is a positive number, this returns the last
2790 C<nrlines> lines of the file C<path>.
2792 If the parameter C<nrlines> is a negative number, this returns lines
2793 from the file C<path>, starting with the C<-nrlines>th line.
2795 If the parameter C<nrlines> is zero, this returns an empty list.");
2797 ("df", (RString "output", []), 125, [],
2798 [], (* XXX Tricky to test because it depends on the exact format
2799 * of the 'df' command and other imponderables.
2801 "report file system disk space usage",
2803 This command runs the C<df> command to report disk space used.
2805 This command is mostly useful for interactive sessions. It
2806 is I<not> intended that you try to parse the output string.
2807 Use C<statvfs> from programs.");
2809 ("df_h", (RString "output", []), 126, [],
2810 [], (* XXX Tricky to test because it depends on the exact format
2811 * of the 'df' command and other imponderables.
2813 "report file system disk space usage (human readable)",
2815 This command runs the C<df -h> command to report disk space used
2816 in human-readable format.
2818 This command is mostly useful for interactive sessions. It
2819 is I<not> intended that you try to parse the output string.
2820 Use C<statvfs> from programs.");
2822 ("du", (RInt64 "sizekb", [Pathname "path"]), 127, [],
2823 [InitISOFS, Always, TestOutputInt (
2824 [["du"; "/directory"]], 2 (* ISO fs blocksize is 2K *))],
2825 "estimate file space usage",
2827 This command runs the C<du -s> command to estimate file space
2830 C<path> can be a file or a directory. If C<path> is a directory
2831 then the estimate includes the contents of the directory and all
2832 subdirectories (recursively).
2834 The result is the estimated size in I<kilobytes>
2835 (ie. units of 1024 bytes).");
2837 ("initrd_list", (RStringList "filenames", [Pathname "path"]), 128, [],
2838 [InitISOFS, Always, TestOutputList (
2839 [["initrd_list"; "/initrd"]], ["empty";"known-1";"known-2";"known-3";"known-4"; "known-5"])],
2840 "list files in an initrd",
2842 This command lists out files contained in an initrd.
2844 The files are listed without any initial C</> character. The
2845 files are listed in the order they appear (not necessarily
2846 alphabetical). Directory names are listed as separate items.
2848 Old Linux kernels (2.4 and earlier) used a compressed ext2
2849 filesystem as initrd. We I<only> support the newer initramfs
2850 format (compressed cpio files).");
2852 ("mount_loop", (RErr, [Pathname "file"; Pathname "mountpoint"]), 129, [],
2854 "mount a file using the loop device",
2856 This command lets you mount C<file> (a filesystem image
2857 in a file) on a mount point. It is entirely equivalent to
2858 the command C<mount -o loop file mountpoint>.");
2860 ("mkswap", (RErr, [Device "device"]), 130, [],
2861 [InitEmpty, Always, TestRun (
2862 [["sfdiskM"; "/dev/sda"; ","];
2863 ["mkswap"; "/dev/sda1"]])],
2864 "create a swap partition",
2866 Create a swap partition on C<device>.");
2868 ("mkswap_L", (RErr, [String "label"; Device "device"]), 131, [],
2869 [InitEmpty, Always, TestRun (
2870 [["sfdiskM"; "/dev/sda"; ","];
2871 ["mkswap_L"; "hello"; "/dev/sda1"]])],
2872 "create a swap partition with a label",
2874 Create a swap partition on C<device> with label C<label>.
2876 Note that you cannot attach a swap label to a block device
2877 (eg. C</dev/sda>), just to a partition. This appears to be
2878 a limitation of the kernel or swap tools.");
2880 ("mkswap_U", (RErr, [String "uuid"; Device "device"]), 132, [],
2881 (let uuid = uuidgen () in
2882 [InitEmpty, Always, TestRun (
2883 [["sfdiskM"; "/dev/sda"; ","];
2884 ["mkswap_U"; uuid; "/dev/sda1"]])]),
2885 "create a swap partition with an explicit UUID",
2887 Create a swap partition on C<device> with UUID C<uuid>.");
2889 ("mknod", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"]), 133, [],
2890 [InitBasicFS, Always, TestOutputStruct (
2891 [["mknod"; "0o10777"; "0"; "0"; "/node"];
2892 (* NB: default umask 022 means 0777 -> 0755 in these tests *)
2893 ["stat"; "/node"]], [CompareWithInt ("mode", 0o10755)]);
2894 InitBasicFS, Always, TestOutputStruct (
2895 [["mknod"; "0o60777"; "66"; "99"; "/node"];
2896 ["stat"; "/node"]], [CompareWithInt ("mode", 0o60755)])],
2897 "make block, character or FIFO devices",
2899 This call creates block or character special devices, or
2900 named pipes (FIFOs).
2902 The C<mode> parameter should be the mode, using the standard
2903 constants. C<devmajor> and C<devminor> are the
2904 device major and minor numbers, only used when creating block
2905 and character special devices.");
2907 ("mkfifo", (RErr, [Int "mode"; Pathname "path"]), 134, [],
2908 [InitBasicFS, Always, TestOutputStruct (
2909 [["mkfifo"; "0o777"; "/node"];
2910 ["stat"; "/node"]], [CompareWithInt ("mode", 0o10755)])],
2911 "make FIFO (named pipe)",
2913 This call creates a FIFO (named pipe) called C<path> with
2914 mode C<mode>. It is just a convenient wrapper around
2915 C<guestfs_mknod>.");
2917 ("mknod_b", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"]), 135, [],
2918 [InitBasicFS, Always, TestOutputStruct (
2919 [["mknod_b"; "0o777"; "99"; "66"; "/node"];
2920 ["stat"; "/node"]], [CompareWithInt ("mode", 0o60755)])],
2921 "make block device node",
2923 This call creates a block device node called C<path> with
2924 mode C<mode> and device major/minor C<devmajor> and C<devminor>.
2925 It is just a convenient wrapper around C<guestfs_mknod>.");
2927 ("mknod_c", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"]), 136, [],
2928 [InitBasicFS, Always, TestOutputStruct (
2929 [["mknod_c"; "0o777"; "99"; "66"; "/node"];
2930 ["stat"; "/node"]], [CompareWithInt ("mode", 0o20755)])],
2931 "make char device node",
2933 This call creates a char device node called C<path> with
2934 mode C<mode> and device major/minor C<devmajor> and C<devminor>.
2935 It is just a convenient wrapper around C<guestfs_mknod>.");
2937 ("umask", (RInt "oldmask", [Int "mask"]), 137, [],
2938 [], (* XXX umask is one of those stateful things that we should
2939 * reset between each test.
2941 "set file mode creation mask (umask)",
2943 This function sets the mask used for creating new files and
2944 device nodes to C<mask & 0777>.
2946 Typical umask values would be C<022> which creates new files
2947 with permissions like \"-rw-r--r--\" or \"-rwxr-xr-x\", and
2948 C<002> which creates new files with permissions like
2949 \"-rw-rw-r--\" or \"-rwxrwxr-x\".
2951 The default umask is C<022>. This is important because it
2952 means that directories and device nodes will be created with
2953 C<0644> or C<0755> mode even if you specify C<0777>.
2955 See also L<umask(2)>, C<guestfs_mknod>, C<guestfs_mkdir>.
2957 This call returns the previous umask.");
2959 ("readdir", (RStructList ("entries", "dirent"), [Pathname "dir"]), 138, [],
2961 "read directories entries",
2963 This returns the list of directory entries in directory C<dir>.
2965 All entries in the directory are returned, including C<.> and
2966 C<..>. The entries are I<not> sorted, but returned in the same
2967 order as the underlying filesystem.
2969 Also this call returns basic file type information about each
2970 file. The C<ftyp> field will contain one of the following characters:
3008 The L<readdir(3)> returned a C<d_type> field with an
3013 This function is primarily intended for use by programs. To
3014 get a simple list of names, use C<guestfs_ls>. To get a printable
3015 directory for human consumption, use C<guestfs_ll>.");
3017 ("sfdiskM", (RErr, [Device "device"; StringList "lines"]), 139, [DangerWillRobinson],
3019 "create partitions on a block device",
3021 This is a simplified interface to the C<guestfs_sfdisk>
3022 command, where partition sizes are specified in megabytes
3023 only (rounded to the nearest cylinder) and you don't need
3024 to specify the cyls, heads and sectors parameters which
3025 were rarely if ever used anyway.
3027 See also C<guestfs_sfdisk> and the L<sfdisk(8)> manpage.");
3029 ("zfile", (RString "description", [String "meth"; Pathname "path"]), 140, [DeprecatedBy "file"],
3031 "determine file type inside a compressed file",
3033 This command runs C<file> after first decompressing C<path>
3036 C<method> must be one of C<gzip>, C<compress> or C<bzip2>.
3038 Since 1.0.63, use C<guestfs_file> instead which can now
3039 process compressed files.");
3041 ("getxattrs", (RStructList ("xattrs", "xattr"), [Pathname "path"]), 141, [],
3043 "list extended attributes of a file or directory",
3045 This call lists the extended attributes of the file or directory
3048 At the system call level, this is a combination of the
3049 L<listxattr(2)> and L<getxattr(2)> calls.
3051 See also: C<guestfs_lgetxattrs>, L<attr(5)>.");
3053 ("lgetxattrs", (RStructList ("xattrs", "xattr"), [Pathname "path"]), 142, [],
3055 "list extended attributes of a file or directory",
3057 This is the same as C<guestfs_getxattrs>, but if C<path>
3058 is a symbolic link, then it returns the extended attributes
3059 of the link itself.");
3061 ("setxattr", (RErr, [String "xattr";
3062 String "val"; Int "vallen"; (* will be BufferIn *)
3063 Pathname "path"]), 143, [],
3065 "set extended attribute of a file or directory",
3067 This call sets the extended attribute named C<xattr>
3068 of the file C<path> to the value C<val> (of length C<vallen>).
3069 The value is arbitrary 8 bit data.
3071 See also: C<guestfs_lsetxattr>, L<attr(5)>.");
3073 ("lsetxattr", (RErr, [String "xattr";
3074 String "val"; Int "vallen"; (* will be BufferIn *)
3075 Pathname "path"]), 144, [],
3077 "set extended attribute of a file or directory",
3079 This is the same as C<guestfs_setxattr>, but if C<path>
3080 is a symbolic link, then it sets an extended attribute
3081 of the link itself.");
3083 ("removexattr", (RErr, [String "xattr"; Pathname "path"]), 145, [],
3085 "remove extended attribute of a file or directory",
3087 This call removes the extended attribute named C<xattr>
3088 of the file C<path>.
3090 See also: C<guestfs_lremovexattr>, L<attr(5)>.");
3092 ("lremovexattr", (RErr, [String "xattr"; Pathname "path"]), 146, [],
3094 "remove extended attribute of a file or directory",
3096 This is the same as C<guestfs_removexattr>, but if C<path>
3097 is a symbolic link, then it removes an extended attribute
3098 of the link itself.");
3100 ("mountpoints", (RHashtable "mps", []), 147, [],
3104 This call is similar to C<guestfs_mounts>. That call returns
3105 a list of devices. This one returns a hash table (map) of
3106 device name to directory where the device is mounted.");
3108 ("mkmountpoint", (RErr, [String "exemptpath"]), 148, [],
3109 (* This is a special case: while you would expect a parameter
3110 * of type "Pathname", that doesn't work, because it implies
3111 * NEED_ROOT in the generated calling code in stubs.c, and
3112 * this function cannot use NEED_ROOT.
3115 "create a mountpoint",
3117 C<guestfs_mkmountpoint> and C<guestfs_rmmountpoint> are
3118 specialized calls that can be used to create extra mountpoints
3119 before mounting the first filesystem.
3121 These calls are I<only> necessary in some very limited circumstances,
3122 mainly the case where you want to mount a mix of unrelated and/or
3123 read-only filesystems together.
3125 For example, live CDs often contain a \"Russian doll\" nest of
3126 filesystems, an ISO outer layer, with a squashfs image inside, with
3127 an ext2/3 image inside that. You can unpack this as follows
3130 add-ro Fedora-11-i686-Live.iso
3133 mkmountpoint /squash
3136 mount-loop /cd/LiveOS/squashfs.img /squash
3137 mount-loop /squash/LiveOS/ext3fs.img /ext3
3139 The inner filesystem is now unpacked under the /ext3 mountpoint.");
3141 ("rmmountpoint", (RErr, [String "exemptpath"]), 149, [],
3143 "remove a mountpoint",
3145 This calls removes a mountpoint that was previously created
3146 with C<guestfs_mkmountpoint>. See C<guestfs_mkmountpoint>
3147 for full details.");
3149 ("read_file", (RBufferOut "content", [Pathname "path"]), 150, [ProtocolLimitWarning],
3150 [InitISOFS, Always, TestOutputBuffer (
3151 [["read_file"; "/known-4"]], "abc\ndef\nghi")],
3154 This calls returns the contents of the file C<path> as a
3157 Unlike C<guestfs_cat>, this function can correctly
3158 handle files that contain embedded ASCII NUL characters.
3159 However unlike C<guestfs_download>, this function is limited
3160 in the total size of file that can be handled.");
3162 ("grep", (RStringList "lines", [String "regex"; Pathname "path"]), 151, [ProtocolLimitWarning],
3163 [InitISOFS, Always, TestOutputList (
3164 [["grep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"]);
3165 InitISOFS, Always, TestOutputList (
3166 [["grep"; "nomatch"; "/test-grep.txt"]], [])],
3167 "return lines matching a pattern",
3169 This calls the external C<grep> program and returns the
3172 ("egrep", (RStringList "lines", [String "regex"; Pathname "path"]), 152, [ProtocolLimitWarning],
3173 [InitISOFS, Always, TestOutputList (
3174 [["egrep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"])],
3175 "return lines matching a pattern",
3177 This calls the external C<egrep> program and returns the
3180 ("fgrep", (RStringList "lines", [String "pattern"; Pathname "path"]), 153, [ProtocolLimitWarning],
3181 [InitISOFS, Always, TestOutputList (
3182 [["fgrep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"])],
3183 "return lines matching a pattern",
3185 This calls the external C<fgrep> program and returns the
3188 ("grepi", (RStringList "lines", [String "regex"; Pathname "path"]), 154, [ProtocolLimitWarning],
3189 [InitISOFS, Always, TestOutputList (
3190 [["grepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])],
3191 "return lines matching a pattern",
3193 This calls the external C<grep -i> program and returns the
3196 ("egrepi", (RStringList "lines", [String "regex"; Pathname "path"]), 155, [ProtocolLimitWarning],
3197 [InitISOFS, Always, TestOutputList (
3198 [["egrepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])],
3199 "return lines matching a pattern",
3201 This calls the external C<egrep -i> program and returns the
3204 ("fgrepi", (RStringList "lines", [String "pattern"; Pathname "path"]), 156, [ProtocolLimitWarning],
3205 [InitISOFS, Always, TestOutputList (
3206 [["fgrepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])],
3207 "return lines matching a pattern",
3209 This calls the external C<fgrep -i> program and returns the
3212 ("zgrep", (RStringList "lines", [String "regex"; Pathname "path"]), 157, [ProtocolLimitWarning],
3213 [InitISOFS, Always, TestOutputList (
3214 [["zgrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])],
3215 "return lines matching a pattern",
3217 This calls the external C<zgrep> program and returns the
3220 ("zegrep", (RStringList "lines", [String "regex"; Pathname "path"]), 158, [ProtocolLimitWarning],
3221 [InitISOFS, Always, TestOutputList (
3222 [["zegrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])],
3223 "return lines matching a pattern",
3225 This calls the external C<zegrep> program and returns the
3228 ("zfgrep", (RStringList "lines", [String "pattern"; Pathname "path"]), 159, [ProtocolLimitWarning],
3229 [InitISOFS, Always, TestOutputList (
3230 [["zfgrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])],
3231 "return lines matching a pattern",
3233 This calls the external C<zfgrep> program and returns the
3236 ("zgrepi", (RStringList "lines", [String "regex"; Pathname "path"]), 160, [ProtocolLimitWarning],
3237 [InitISOFS, Always, TestOutputList (
3238 [["zgrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])],
3239 "return lines matching a pattern",
3241 This calls the external C<zgrep -i> program and returns the
3244 ("zegrepi", (RStringList "lines", [String "regex"; Pathname "path"]), 161, [ProtocolLimitWarning],
3245 [InitISOFS, Always, TestOutputList (
3246 [["zegrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])],
3247 "return lines matching a pattern",
3249 This calls the external C<zegrep -i> program and returns the
3252 ("zfgrepi", (RStringList "lines", [String "pattern"; Pathname "path"]), 162, [ProtocolLimitWarning],
3253 [InitISOFS, Always, TestOutputList (
3254 [["zfgrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])],
3255 "return lines matching a pattern",
3257 This calls the external C<zfgrep -i> program and returns the
3260 ("realpath", (RString "rpath", [Pathname "path"]), 163, [],
3261 [InitISOFS, Always, TestOutput (
3262 [["realpath"; "/../directory"]], "/directory")],
3263 "canonicalized absolute pathname",
3265 Return the canonicalized absolute pathname of C<path>. The
3266 returned path has no C<.>, C<..> or symbolic link path elements.");
3268 ("ln", (RErr, [String "target"; Pathname "linkname"]), 164, [],
3269 [InitBasicFS, Always, TestOutputStruct (
3272 ["stat"; "/b"]], [CompareWithInt ("nlink", 2)])],
3273 "create a hard link",
3275 This command creates a hard link using the C<ln> command.");
3277 ("ln_f", (RErr, [String "target"; Pathname "linkname"]), 165, [],
3278 [InitBasicFS, Always, TestOutputStruct (
3281 ["ln_f"; "/a"; "/b"];
3282 ["stat"; "/b"]], [CompareWithInt ("nlink", 2)])],
3283 "create a hard link",
3285 This command creates a hard link using the C<ln -f> command.
3286 The C<-f> option removes the link (C<linkname>) if it exists already.");
3288 ("ln_s", (RErr, [String "target"; Pathname "linkname"]), 166, [],
3289 [InitBasicFS, Always, TestOutputStruct (
3291 ["ln_s"; "a"; "/b"];
3292 ["lstat"; "/b"]], [CompareWithInt ("mode", 0o120777)])],
3293 "create a symbolic link",
3295 This command creates a symbolic link using the C<ln -s> command.");
3297 ("ln_sf", (RErr, [String "target"; Pathname "linkname"]), 167, [],
3298 [InitBasicFS, Always, TestOutput (
3299 [["mkdir_p"; "/a/b"];
3300 ["touch"; "/a/b/c"];
3301 ["ln_sf"; "../d"; "/a/b/c"];
3302 ["readlink"; "/a/b/c"]], "../d")],
3303 "create a symbolic link",
3305 This command creates a symbolic link using the C<ln -sf> command,
3306 The C<-f> option removes the link (C<linkname>) if it exists already.");
3308 ("readlink", (RString "link", [Pathname "path"]), 168, [],
3309 [] (* XXX tested above *),
3310 "read the target of a symbolic link",
3312 This command reads the target of a symbolic link.");
3314 ("fallocate", (RErr, [Pathname "path"; Int "len"]), 169, [],
3315 [InitBasicFS, Always, TestOutputStruct (
3316 [["fallocate"; "/a"; "1000000"];
3317 ["stat"; "/a"]], [CompareWithInt ("size", 1_000_000)])],
3318 "preallocate a file in the guest filesystem",
3320 This command preallocates a file (containing zero bytes) named
3321 C<path> of size C<len> bytes. If the file exists already, it
3324 Do not confuse this with the guestfish-specific
3325 C<alloc> command which allocates a file in the host and
3326 attaches it as a device.");
3328 ("swapon_device", (RErr, [Device "device"]), 170, [],
3329 [InitPartition, Always, TestRun (
3330 [["mkswap"; "/dev/sda1"];
3331 ["swapon_device"; "/dev/sda1"];
3332 ["swapoff_device"; "/dev/sda1"]])],
3333 "enable swap on device",
3335 This command enables the libguestfs appliance to use the
3336 swap device or partition named C<device>. The increased
3337 memory is made available for all commands, for example
3338 those run using C<guestfs_command> or C<guestfs_sh>.
3340 Note that you should not swap to existing guest swap
3341 partitions unless you know what you are doing. They may
3342 contain hibernation information, or other information that
3343 the guest doesn't want you to trash. You also risk leaking
3344 information about the host to the guest this way. Instead,
3345 attach a new host device to the guest and swap on that.");
3347 ("swapoff_device", (RErr, [Device "device"]), 171, [],
3348 [], (* XXX tested by swapon_device *)
3349 "disable swap on device",
3351 This command disables the libguestfs appliance swap
3352 device or partition named C<device>.
3353 See C<guestfs_swapon_device>.");
3355 ("swapon_file", (RErr, [Pathname "file"]), 172, [],
3356 [InitBasicFS, Always, TestRun (
3357 [["fallocate"; "/swap"; "8388608"];
3358 ["mkswap_file"; "/swap"];
3359 ["swapon_file"; "/swap"];
3360 ["swapoff_file"; "/swap"]])],
3361 "enable swap on file",
3363 This command enables swap to a file.
3364 See C<guestfs_swapon_device> for other notes.");
3366 ("swapoff_file", (RErr, [Pathname "file"]), 173, [],
3367 [], (* XXX tested by swapon_file *)
3368 "disable swap on file",
3370 This command disables the libguestfs appliance swap on file.");
3372 ("swapon_label", (RErr, [String "label"]), 174, [],
3373 [InitEmpty, Always, TestRun (
3374 [["sfdiskM"; "/dev/sdb"; ","];
3375 ["mkswap_L"; "swapit"; "/dev/sdb1"];
3376 ["swapon_label"; "swapit"];
3377 ["swapoff_label"; "swapit"];
3378 ["zero"; "/dev/sdb"];
3379 ["blockdev_rereadpt"; "/dev/sdb"]])],
3380 "enable swap on labeled swap partition",
3382 This command enables swap to a labeled swap partition.
3383 See C<guestfs_swapon_device> for other notes.");
3385 ("swapoff_label", (RErr, [String "label"]), 175, [],
3386 [], (* XXX tested by swapon_label *)
3387 "disable swap on labeled swap partition",
3389 This command disables the libguestfs appliance swap on
3390 labeled swap partition.");
3392 ("swapon_uuid", (RErr, [String "uuid"]), 176, [],
3393 (let uuid = uuidgen () in
3394 [InitEmpty, Always, TestRun (
3395 [["mkswap_U"; uuid; "/dev/sdb"];
3396 ["swapon_uuid"; uuid];
3397 ["swapoff_uuid"; uuid]])]),
3398 "enable swap on swap partition by UUID",
3400 This command enables swap to a swap partition with the given UUID.
3401 See C<guestfs_swapon_device> for other notes.");
3403 ("swapoff_uuid", (RErr, [String "uuid"]), 177, [],
3404 [], (* XXX tested by swapon_uuid *)
3405 "disable swap on swap partition by UUID",
3407 This command disables the libguestfs appliance swap partition
3408 with the given UUID.");
3410 ("mkswap_file", (RErr, [Pathname "path"]), 178, [],
3411 [InitBasicFS, Always, TestRun (
3412 [["fallocate"; "/swap"; "8388608"];
3413 ["mkswap_file"; "/swap"]])],
3414 "create a swap file",
3418 This command just writes a swap file signature to an existing
3419 file. To create the file itself, use something like C<guestfs_fallocate>.");
3421 ("inotify_init", (RErr, [Int "maxevents"]), 179, [],
3422 [InitISOFS, Always, TestRun (
3423 [["inotify_init"; "0"]])],
3424 "create an inotify handle",
3426 This command creates a new inotify handle.
3427 The inotify subsystem can be used to notify events which happen to
3428 objects in the guest filesystem.
3430 C<maxevents> is the maximum number of events which will be
3431 queued up between calls to C<guestfs_inotify_read> or
3432 C<guestfs_inotify_files>.
3433 If this is passed as C<0>, then the kernel (or previously set)
3434 default is used. For Linux 2.6.29 the default was 16384 events.
3435 Beyond this limit, the kernel throws away events, but records
3436 the fact that it threw them away by setting a flag
3437 C<IN_Q_OVERFLOW> in the returned structure list (see
3438 C<guestfs_inotify_read>).
3440 Before any events are generated, you have to add some
3441 watches to the internal watch list. See:
3442 C<guestfs_inotify_add_watch>,
3443 C<guestfs_inotify_rm_watch> and
3444 C<guestfs_inotify_watch_all>.
3446 Queued up events should be read periodically by calling
3447 C<guestfs_inotify_read>
3448 (or C<guestfs_inotify_files> which is just a helpful
3449 wrapper around C<guestfs_inotify_read>). If you don't
3450 read the events out often enough then you risk the internal
3453 The handle should be closed after use by calling
3454 C<guestfs_inotify_close>. This also removes any
3455 watches automatically.
3457 See also L<inotify(7)> for an overview of the inotify interface
3458 as exposed by the Linux kernel, which is roughly what we expose
3459 via libguestfs. Note that there is one global inotify handle
3460 per libguestfs instance.");
3462 ("inotify_add_watch", (RInt64 "wd", [Pathname "path"; Int "mask"]), 180, [],
3463 [InitBasicFS, Always, TestOutputList (
3464 [["inotify_init"; "0"];
3465 ["inotify_add_watch"; "/"; "1073741823"];
3468 ["inotify_files"]], ["a"; "b"])],
3469 "add an inotify watch",
3471 Watch C<path> for the events listed in C<mask>.
3473 Note that if C<path> is a directory then events within that
3474 directory are watched, but this does I<not> happen recursively
3475 (in subdirectories).
3477 Note for non-C or non-Linux callers: the inotify events are
3478 defined by the Linux kernel ABI and are listed in
3479 C</usr/include/sys/inotify.h>.");
3481 ("inotify_rm_watch", (RErr, [Int(*XXX64*) "wd"]), 181, [],
3483 "remove an inotify watch",
3485 Remove a previously defined inotify watch.
3486 See C<guestfs_inotify_add_watch>.");
3488 ("inotify_read", (RStructList ("events", "inotify_event"), []), 182, [],
3490 "return list of inotify events",
3492 Return the complete queue of events that have happened
3493 since the previous read call.
3495 If no events have happened, this returns an empty list.
3497 I<Note>: In order to make sure that all events have been
3498 read, you must call this function repeatedly until it
3499 returns an empty list. The reason is that the call will
3500 read events up to the maximum appliance-to-host message
3501 size and leave remaining events in the queue.");
3503 ("inotify_files", (RStringList "paths", []), 183, [],
3505 "return list of watched files that had events",
3507 This function is a helpful wrapper around C<guestfs_inotify_read>
3508 which just returns a list of pathnames of objects that were
3509 touched. The returned pathnames are sorted and deduplicated.");
3511 ("inotify_close", (RErr, []), 184, [],
3513 "close the inotify handle",
3515 This closes the inotify handle which was previously
3516 opened by inotify_init. It removes all watches, throws
3517 away any pending events, and deallocates all resources.");
3519 ("setcon", (RErr, [String "context"]), 185, [],
3521 "set SELinux security context",
3523 This sets the SELinux security context of the daemon
3524 to the string C<context>.
3526 See the documentation about SELINUX in L<guestfs(3)>.");
3528 ("getcon", (RString "context", []), 186, [],
3530 "get SELinux security context",
3532 This gets the SELinux security context of the daemon.
3534 See the documentation about SELINUX in L<guestfs(3)>,
3535 and C<guestfs_setcon>");
3537 ("mkfs_b", (RErr, [String "fstype"; Int "blocksize"; Device "device"]), 187, [],
3538 [InitEmpty, Always, TestOutput (
3539 [["sfdiskM"; "/dev/sda"; ","];
3540 ["mkfs_b"; "ext2"; "4096"; "/dev/sda1"];
3541 ["mount"; "/dev/sda1"; "/"];
3542 ["write_file"; "/new"; "new file contents"; "0"];
3543 ["cat"; "/new"]], "new file contents")],
3544 "make a filesystem with block size",
3546 This call is similar to C<guestfs_mkfs>, but it allows you to
3547 control the block size of the resulting filesystem. Supported
3548 block sizes depend on the filesystem type, but typically they
3549 are C<1024>, C<2048> or C<4096> only.");
3551 ("mke2journal", (RErr, [Int "blocksize"; Device "device"]), 188, [],
3552 [InitEmpty, Always, TestOutput (
3553 [["sfdiskM"; "/dev/sda"; ",100 ,"];
3554 ["mke2journal"; "4096"; "/dev/sda1"];
3555 ["mke2fs_J"; "ext2"; "4096"; "/dev/sda2"; "/dev/sda1"];
3556 ["mount"; "/dev/sda2"; "/"];
3557 ["write_file"; "/new"; "new file contents"; "0"];
3558 ["cat"; "/new"]], "new file contents")],
3559 "make ext2/3/4 external journal",
3561 This creates an ext2 external journal on C<device>. It is equivalent
3564 mke2fs -O journal_dev -b blocksize device");
3566 ("mke2journal_L", (RErr, [Int "blocksize"; String "label"; Device "device"]), 189, [],
3567 [InitEmpty, Always, TestOutput (
3568 [["sfdiskM"; "/dev/sda"; ",100 ,"];
3569 ["mke2journal_L"; "4096"; "JOURNAL"; "/dev/sda1"];
3570 ["mke2fs_JL"; "ext2"; "4096"; "/dev/sda2"; "JOURNAL"];
3571 ["mount"; "/dev/sda2"; "/"];
3572 ["write_file"; "/new"; "new file contents"; "0"];
3573 ["cat"; "/new"]], "new file contents")],
3574 "make ext2/3/4 external journal with label",
3576 This creates an ext2 external journal on C<device> with label C<label>.");
3578 ("mke2journal_U", (RErr, [Int "blocksize"; String "uuid"; Device "device"]), 190, [],
3579 (let uuid = uuidgen () in
3580 [InitEmpty, Always, TestOutput (
3581 [["sfdiskM"; "/dev/sda"; ",100 ,"];
3582 ["mke2journal_U"; "4096"; uuid; "/dev/sda1"];
3583 ["mke2fs_JU"; "ext2"; "4096"; "/dev/sda2"; uuid];
3584 ["mount"; "/dev/sda2"; "/"];
3585 ["write_file"; "/new"; "new file contents"; "0"];
3586 ["cat"; "/new"]], "new file contents")]),
3587 "make ext2/3/4 external journal with UUID",
3589 This creates an ext2 external journal on C<device> with UUID C<uuid>.");
3591 ("mke2fs_J", (RErr, [String "fstype"; Int "blocksize"; Device "device"; Device "journal"]), 191, [],
3593 "make ext2/3/4 filesystem with external journal",
3595 This creates an ext2/3/4 filesystem on C<device> with
3596 an external journal on C<journal>. It is equivalent
3599 mke2fs -t fstype -b blocksize -J device=<journal> <device>
3601 See also C<guestfs_mke2journal>.");
3603 ("mke2fs_JL", (RErr, [String "fstype"; Int "blocksize"; Device "device"; String "label"]), 192, [],
3605 "make ext2/3/4 filesystem with external journal",
3607 This creates an ext2/3/4 filesystem on C<device> with
3608 an external journal on the journal labeled C<label>.
3610 See also C<guestfs_mke2journal_L>.");
3612 ("mke2fs_JU", (RErr, [String "fstype"; Int "blocksize"; Device "device"; String "uuid"]), 193, [],
3614 "make ext2/3/4 filesystem with external journal",
3616 This creates an ext2/3/4 filesystem on C<device> with
3617 an external journal on the journal with UUID C<uuid>.
3619 See also C<guestfs_mke2journal_U>.");
3621 ("modprobe", (RErr, [String "modulename"]), 194, [],
3622 [InitNone, Always, TestRun [["modprobe"; "fat"]]],
3623 "load a kernel module",
3625 This loads a kernel module in the appliance.
3627 The kernel module must have been whitelisted when libguestfs
3628 was built (see C<appliance/kmod.whitelist.in> in the source).");
3630 ("echo_daemon", (RString "output", [StringList "words"]), 195, [],
3631 [InitNone, Always, TestOutput (
3632 [["echo_daemon"; "This is a test"]], "This is a test"
3634 "echo arguments back to the client",
3636 This command concatenate the list of C<words> passed with single spaces between
3637 them and returns the resulting string.
3639 You can use this command to test the connection through to the daemon.
3641 See also C<guestfs_ping_daemon>.");
3643 ("find0", (RErr, [Pathname "directory"; FileOut "files"]), 196, [],
3644 [], (* There is a regression test for this. *)
3645 "find all files and directories, returning NUL-separated list",
3647 This command lists out all files and directories, recursively,
3648 starting at C<directory>, placing the resulting list in the
3649 external file called C<files>.
3651 This command works the same way as C<guestfs_find> with the
3652 following exceptions:
3658 The resulting list is written to an external file.
3662 Items (filenames) in the result are separated
3663 by C<\\0> characters. See L<find(1)> option I<-print0>.
3667 This command is not limited in the number of names that it
3672 The result list is not sorted.
3676 ("case_sensitive_path", (RString "rpath", [Pathname "path"]), 197, [],
3677 [InitISOFS, Always, TestOutput (
3678 [["case_sensitive_path"; "/DIRECTORY"]], "/directory");
3679 InitISOFS, Always, TestOutput (
3680 [["case_sensitive_path"; "/DIRECTORY/"]], "/directory");
3681 InitISOFS, Always, TestOutput (
3682 [["case_sensitive_path"; "/Known-1"]], "/known-1");
3683 InitISOFS, Always, TestLastFail (
3684 [["case_sensitive_path"; "/Known-1/"]]);
3685 InitBasicFS, Always, TestOutput (
3687 ["mkdir"; "/a/bbb"];
3688 ["touch"; "/a/bbb/c"];
3689 ["case_sensitive_path"; "/A/bbB/C"]], "/a/bbb/c");
3690 InitBasicFS, Always, TestOutput (
3692 ["mkdir"; "/a/bbb"];
3693 ["touch"; "/a/bbb/c"];
3694 ["case_sensitive_path"; "/A////bbB/C"]], "/a/bbb/c");
3695 InitBasicFS, Always, TestLastFail (
3697 ["mkdir"; "/a/bbb"];
3698 ["touch"; "/a/bbb/c"];
3699 ["case_sensitive_path"; "/A/bbb/../bbb/C"]])],
3700 "return true path on case-insensitive filesystem",
3702 This can be used to resolve case insensitive paths on
3703 a filesystem which is case sensitive. The use case is
3704 to resolve paths which you have read from Windows configuration
3705 files or the Windows Registry, to the true path.
3707 The command handles a peculiarity of the Linux ntfs-3g
3708 filesystem driver (and probably others), which is that although
3709 the underlying filesystem is case-insensitive, the driver
3710 exports the filesystem to Linux as case-sensitive.
3712 One consequence of this is that special directories such
3713 as C<c:\\windows> may appear as C</WINDOWS> or C</windows>
3714 (or other things) depending on the precise details of how
3715 they were created. In Windows itself this would not be
3718 Bug or feature? You decide:
3719 L<http://www.tuxera.com/community/ntfs-3g-faq/#posixfilenames1>
3721 This function resolves the true case of each element in the
3722 path and returns the case-sensitive path.
3724 Thus C<guestfs_case_sensitive_path> (\"/Windows/System32\")
3725 might return C<\"/WINDOWS/system32\"> (the exact return value
3726 would depend on details of how the directories were originally
3727 created under Windows).