8add55fe7082320dbdefe1ebaac261032902dd6c
[libguestfs.git] / generator / generator_actions.ml
1 (* libguestfs
2  * Copyright (C) 2009-2010 Red Hat Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  *)
18
19 (* Please read generator/README first. *)
20
21 (* Note about long descriptions: When referring to another
22  * action, use the format C<guestfs_other> (ie. the full name of
23  * the C function).  This will be replaced as appropriate in other
24  * language bindings.
25  *
26  * Apart from that, long descriptions are just perldoc paragraphs.
27  *)
28
29 open Generator_types
30 open Generator_utils
31
32 (* These test functions are used in the language binding tests. *)
33
34 let test_all_args = [
35   String "str";
36   OptString "optstr";
37   StringList "strlist";
38   Bool "b";
39   Int "integer";
40   Int64 "integer64";
41   FileIn "filein";
42   FileOut "fileout";
43   BufferIn "bufferin";
44 ]
45
46 let test_all_rets = [
47   (* except for RErr, which is tested thoroughly elsewhere *)
48   "test0rint",         RInt "valout";
49   "test0rint64",       RInt64 "valout";
50   "test0rbool",        RBool "valout";
51   "test0rconststring", RConstString "valout";
52   "test0rconstoptstring", RConstOptString "valout";
53   "test0rstring",      RString "valout";
54   "test0rstringlist",  RStringList "valout";
55   "test0rstruct",      RStruct ("valout", "lvm_pv");
56   "test0rstructlist",  RStructList ("valout", "lvm_pv");
57   "test0rhashtable",   RHashtable "valout";
58 ]
59
60 let test_functions = [
61   ("test0", (RErr, test_all_args, []), -1, [NotInFish; NotInDocs],
62    [],
63    "internal test function - do not use",
64    "\
65 This is an internal test function which is used to test whether
66 the automatically generated bindings can handle every possible
67 parameter type correctly.
68
69 It echos the contents of each parameter to stdout.
70
71 You probably don't want to call this function.");
72 ] @ List.flatten (
73   List.map (
74     fun (name, ret) ->
75       [(name, (ret, [String "val"], []), -1, [NotInFish; NotInDocs],
76         [],
77         "internal test function - do not use",
78         "\
79 This is an internal test function which is used to test whether
80 the automatically generated bindings can handle every possible
81 return type correctly.
82
83 It converts string C<val> to the return type.
84
85 You probably don't want to call this function.");
86        (name ^ "err", (ret, [], []), -1, [NotInFish; NotInDocs],
87         [],
88         "internal test function - do not use",
89         "\
90 This is an internal test function which is used to test whether
91 the automatically generated bindings can handle every possible
92 return type correctly.
93
94 This function always returns an error.
95
96 You probably don't want to call this function.")]
97   ) test_all_rets
98 )
99
100 (* non_daemon_functions are any functions which don't get processed
101  * in the daemon, eg. functions for setting and getting local
102  * configuration values.
103  *)
104
105 let non_daemon_functions = test_functions @ [
106   ("launch", (RErr, [], []), -1, [FishAlias "run"],
107    [],
108    "launch the qemu subprocess",
109    "\
110 Internally libguestfs is implemented by running a virtual machine
111 using L<qemu(1)>.
112
113 You should call this after configuring the handle
114 (eg. adding drives) but before performing any actions.");
115
116   ("wait_ready", (RErr, [], []), -1, [NotInFish],
117    [],
118    "wait until the qemu subprocess launches (no op)",
119    "\
120 This function is a no op.
121
122 In versions of the API E<lt> 1.0.71 you had to call this function
123 just after calling C<guestfs_launch> to wait for the launch
124 to complete.  However this is no longer necessary because
125 C<guestfs_launch> now does the waiting.
126
127 If you see any calls to this function in code then you can just
128 remove them, unless you want to retain compatibility with older
129 versions of the API.");
130
131   ("kill_subprocess", (RErr, [], []), -1, [],
132    [],
133    "kill the qemu subprocess",
134    "\
135 This kills the qemu subprocess.  You should never need to call this.");
136
137   ("add_drive", (RErr, [String "filename"], []), -1, [],
138    [],
139    "add an image to examine or modify",
140    "\
141 This function is the equivalent of calling C<guestfs_add_drive_opts>
142 with no optional parameters, so the disk is added writable, with
143 the format being detected automatically.
144
145 Automatic detection of the format opens you up to a potential
146 security hole when dealing with untrusted raw-format images.
147 See CVE-2010-3851 and RHBZ#642934.  Specifying the format closes
148 this security hole.  Therefore you should think about replacing
149 calls to this function with calls to C<guestfs_add_drive_opts>,
150 and specifying the format.");
151
152   ("add_cdrom", (RErr, [String "filename"], []), -1, [DeprecatedBy "add_drive_opts"],
153    [],
154    "add a CD-ROM disk image to examine",
155    "\
156 This function adds a virtual CD-ROM disk image to the guest.
157
158 This is equivalent to the qemu parameter C<-cdrom filename>.
159
160 Notes:
161
162 =over 4
163
164 =item *
165
166 This call checks for the existence of C<filename>.  This
167 stops you from specifying other types of drive which are supported
168 by qemu such as C<nbd:> and C<http:> URLs.  To specify those, use
169 the general C<guestfs_config> call instead.
170
171 =item *
172
173 If you just want to add an ISO file (often you use this as an
174 efficient way to transfer large files into the guest), then you
175 should probably use C<guestfs_add_drive_ro> instead.
176
177 =back");
178
179   ("add_drive_ro", (RErr, [String "filename"], []), -1, [FishAlias "add-ro"],
180    [],
181    "add a drive in snapshot mode (read-only)",
182    "\
183 This function is the equivalent of calling C<guestfs_add_drive_opts>
184 with the optional parameter C<GUESTFS_ADD_DRIVE_OPTS_READONLY> set to 1,
185 so the disk is added read-only, with the format being detected
186 automatically.");
187
188   ("config", (RErr, [String "qemuparam"; OptString "qemuvalue"], []), -1, [],
189    [],
190    "add qemu parameters",
191    "\
192 This can be used to add arbitrary qemu command line parameters
193 of the form C<-param value>.  Actually it's not quite arbitrary - we
194 prevent you from setting some parameters which would interfere with
195 parameters that we use.
196
197 The first character of C<param> string must be a C<-> (dash).
198
199 C<value> can be NULL.");
200
201   ("set_qemu", (RErr, [OptString "qemu"], []), -1, [FishAlias "qemu"],
202    [],
203    "set the qemu binary",
204    "\
205 Set the qemu binary that we will use.
206
207 The default is chosen when the library was compiled by the
208 configure script.
209
210 You can also override this by setting the C<LIBGUESTFS_QEMU>
211 environment variable.
212
213 Setting C<qemu> to C<NULL> restores the default qemu binary.
214
215 Note that you should call this function as early as possible
216 after creating the handle.  This is because some pre-launch
217 operations depend on testing qemu features (by running C<qemu -help>).
218 If the qemu binary changes, we don't retest features, and
219 so you might see inconsistent results.  Using the environment
220 variable C<LIBGUESTFS_QEMU> is safest of all since that picks
221 the qemu binary at the same time as the handle is created.");
222
223   ("get_qemu", (RConstString "qemu", [], []), -1, [],
224    [InitNone, Always, TestRun (
225       [["get_qemu"]])],
226    "get the qemu binary",
227    "\
228 Return the current qemu binary.
229
230 This is always non-NULL.  If it wasn't set already, then this will
231 return the default qemu binary name.");
232
233   ("set_path", (RErr, [OptString "searchpath"], []), -1, [FishAlias "path"],
234    [],
235    "set the search path",
236    "\
237 Set the path that libguestfs searches for kernel and initrd.img.
238
239 The default is C<$libdir/guestfs> unless overridden by setting
240 C<LIBGUESTFS_PATH> environment variable.
241
242 Setting C<path> to C<NULL> restores the default path.");
243
244   ("get_path", (RConstString "path", [], []), -1, [],
245    [InitNone, Always, TestRun (
246       [["get_path"]])],
247    "get the search path",
248    "\
249 Return the current search path.
250
251 This is always non-NULL.  If it wasn't set already, then this will
252 return the default path.");
253
254   ("set_append", (RErr, [OptString "append"], []), -1, [FishAlias "append"],
255    [],
256    "add options to kernel command line",
257    "\
258 This function is used to add additional options to the
259 guest kernel command line.
260
261 The default is C<NULL> unless overridden by setting
262 C<LIBGUESTFS_APPEND> environment variable.
263
264 Setting C<append> to C<NULL> means I<no> additional options
265 are passed (libguestfs always adds a few of its own).");
266
267   ("get_append", (RConstOptString "append", [], []), -1, [],
268    (* This cannot be tested with the current framework.  The
269     * function can return NULL in normal operations, which the
270     * test framework interprets as an error.
271     *)
272    [],
273    "get the additional kernel options",
274    "\
275 Return the additional kernel options which are added to the
276 guest kernel command line.
277
278 If C<NULL> then no options are added.");
279
280   ("set_autosync", (RErr, [Bool "autosync"], []), -1, [FishAlias "autosync"],
281    [],
282    "set autosync mode",
283    "\
284 If C<autosync> is true, this enables autosync.  Libguestfs will make a
285 best effort attempt to run C<guestfs_umount_all> followed by
286 C<guestfs_sync> when the handle is closed
287 (also if the program exits without closing handles).
288
289 This is enabled by default (since libguestfs 1.5.24, previously it was
290 disabled by default).");
291
292   ("get_autosync", (RBool "autosync", [], []), -1, [],
293    [InitNone, Always, TestOutputTrue (
294       [["get_autosync"]])],
295    "get autosync mode",
296    "\
297 Get the autosync flag.");
298
299   ("set_verbose", (RErr, [Bool "verbose"], []), -1, [FishAlias "verbose"],
300    [],
301    "set verbose mode",
302    "\
303 If C<verbose> is true, this turns on verbose messages (to C<stderr>).
304
305 Verbose messages are disabled unless the environment variable
306 C<LIBGUESTFS_DEBUG> is defined and set to C<1>.");
307
308   ("get_verbose", (RBool "verbose", [], []), -1, [],
309    [],
310    "get verbose mode",
311    "\
312 This returns the verbose messages flag.");
313
314   ("is_ready", (RBool "ready", [], []), -1, [],
315    [InitNone, Always, TestOutputTrue (
316       [["is_ready"]])],
317    "is ready to accept commands",
318    "\
319 This returns true iff this handle is ready to accept commands
320 (in the C<READY> state).
321
322 For more information on states, see L<guestfs(3)>.");
323
324   ("is_config", (RBool "config", [], []), -1, [],
325    [InitNone, Always, TestOutputFalse (
326       [["is_config"]])],
327    "is in configuration state",
328    "\
329 This returns true iff this handle is being configured
330 (in the C<CONFIG> state).
331
332 For more information on states, see L<guestfs(3)>.");
333
334   ("is_launching", (RBool "launching", [], []), -1, [],
335    [InitNone, Always, TestOutputFalse (
336       [["is_launching"]])],
337    "is launching subprocess",
338    "\
339 This returns true iff this handle is launching the subprocess
340 (in the C<LAUNCHING> state).
341
342 For more information on states, see L<guestfs(3)>.");
343
344   ("is_busy", (RBool "busy", [], []), -1, [],
345    [InitNone, Always, TestOutputFalse (
346       [["is_busy"]])],
347    "is busy processing a command",
348    "\
349 This returns true iff this handle is busy processing a command
350 (in the C<BUSY> state).
351
352 For more information on states, see L<guestfs(3)>.");
353
354   ("get_state", (RInt "state", [], []), -1, [],
355    [],
356    "get the current state",
357    "\
358 This returns the current state as an opaque integer.  This is
359 only useful for printing debug and internal error messages.
360
361 For more information on states, see L<guestfs(3)>.");
362
363   ("set_memsize", (RErr, [Int "memsize"], []), -1, [FishAlias "memsize"],
364    [InitNone, Always, TestOutputInt (
365       [["set_memsize"; "500"];
366        ["get_memsize"]], 500)],
367    "set memory allocated to the qemu subprocess",
368    "\
369 This sets the memory size in megabytes allocated to the
370 qemu subprocess.  This only has any effect if called before
371 C<guestfs_launch>.
372
373 You can also change this by setting the environment
374 variable C<LIBGUESTFS_MEMSIZE> before the handle is
375 created.
376
377 For more information on the architecture of libguestfs,
378 see L<guestfs(3)>.");
379
380   ("get_memsize", (RInt "memsize", [], []), -1, [],
381    [InitNone, Always, TestOutputIntOp (
382       [["get_memsize"]], ">=", 256)],
383    "get memory allocated to the qemu subprocess",
384    "\
385 This gets the memory size in megabytes allocated to the
386 qemu subprocess.
387
388 If C<guestfs_set_memsize> was not called
389 on this handle, and if C<LIBGUESTFS_MEMSIZE> was not set,
390 then this returns the compiled-in default value for memsize.
391
392 For more information on the architecture of libguestfs,
393 see L<guestfs(3)>.");
394
395   ("get_pid", (RInt "pid", [], []), -1, [FishAlias "pid"],
396    [InitNone, Always, TestOutputIntOp (
397       [["get_pid"]], ">=", 1)],
398    "get PID of qemu subprocess",
399    "\
400 Return the process ID of the qemu subprocess.  If there is no
401 qemu subprocess, then this will return an error.
402
403 This is an internal call used for debugging and testing.");
404
405   ("version", (RStruct ("version", "version"), [], []), -1, [],
406    [InitNone, Always, TestOutputStruct (
407       [["version"]], [CompareWithInt ("major", 1)])],
408    "get the library version number",
409    "\
410 Return the libguestfs version number that the program is linked
411 against.
412
413 Note that because of dynamic linking this is not necessarily
414 the version of libguestfs that you compiled against.  You can
415 compile the program, and then at runtime dynamically link
416 against a completely different C<libguestfs.so> library.
417
418 This call was added in version C<1.0.58>.  In previous
419 versions of libguestfs there was no way to get the version
420 number.  From C code you can use dynamic linker functions
421 to find out if this symbol exists (if it doesn't, then
422 it's an earlier version).
423
424 The call returns a structure with four elements.  The first
425 three (C<major>, C<minor> and C<release>) are numbers and
426 correspond to the usual version triplet.  The fourth element
427 (C<extra>) is a string and is normally empty, but may be
428 used for distro-specific information.
429
430 To construct the original version string:
431 C<$major.$minor.$release$extra>
432
433 See also: L<guestfs(3)/LIBGUESTFS VERSION NUMBERS>.
434
435 I<Note:> Don't use this call to test for availability
436 of features.  In enterprise distributions we backport
437 features from later versions into earlier versions,
438 making this an unreliable way to test for features.
439 Use C<guestfs_available> instead.");
440
441   ("set_selinux", (RErr, [Bool "selinux"], []), -1, [FishAlias "selinux"],
442    [InitNone, Always, TestOutputTrue (
443       [["set_selinux"; "true"];
444        ["get_selinux"]])],
445    "set SELinux enabled or disabled at appliance boot",
446    "\
447 This sets the selinux flag that is passed to the appliance
448 at boot time.  The default is C<selinux=0> (disabled).
449
450 Note that if SELinux is enabled, it is always in
451 Permissive mode (C<enforcing=0>).
452
453 For more information on the architecture of libguestfs,
454 see L<guestfs(3)>.");
455
456   ("get_selinux", (RBool "selinux", [], []), -1, [],
457    [],
458    "get SELinux enabled flag",
459    "\
460 This returns the current setting of the selinux flag which
461 is passed to the appliance at boot time.  See C<guestfs_set_selinux>.
462
463 For more information on the architecture of libguestfs,
464 see L<guestfs(3)>.");
465
466   ("set_trace", (RErr, [Bool "trace"], []), -1, [FishAlias "trace"],
467    [InitNone, Always, TestOutputFalse (
468       [["set_trace"; "false"];
469        ["get_trace"]])],
470    "enable or disable command traces",
471    "\
472 If the command trace flag is set to 1, then commands are
473 printed on stderr before they are executed in a format
474 which is very similar to the one used by guestfish.  In
475 other words, you can run a program with this enabled, and
476 you will get out a script which you can feed to guestfish
477 to perform the same set of actions.
478
479 If you want to trace C API calls into libguestfs (and
480 other libraries) then possibly a better way is to use
481 the external ltrace(1) command.
482
483 Command traces are disabled unless the environment variable
484 C<LIBGUESTFS_TRACE> is defined and set to C<1>.");
485
486   ("get_trace", (RBool "trace", [], []), -1, [],
487    [],
488    "get command trace enabled flag",
489    "\
490 Return the command trace flag.");
491
492   ("set_direct", (RErr, [Bool "direct"], []), -1, [FishAlias "direct"],
493    [InitNone, Always, TestOutputFalse (
494       [["set_direct"; "false"];
495        ["get_direct"]])],
496    "enable or disable direct appliance mode",
497    "\
498 If the direct appliance mode flag is enabled, then stdin and
499 stdout are passed directly through to the appliance once it
500 is launched.
501
502 One consequence of this is that log messages aren't caught
503 by the library and handled by C<guestfs_set_log_message_callback>,
504 but go straight to stdout.
505
506 You probably don't want to use this unless you know what you
507 are doing.
508
509 The default is disabled.");
510
511   ("get_direct", (RBool "direct", [], []), -1, [],
512    [],
513    "get direct appliance mode flag",
514    "\
515 Return the direct appliance mode flag.");
516
517   ("set_recovery_proc", (RErr, [Bool "recoveryproc"], []), -1, [FishAlias "recovery-proc"],
518    [InitNone, Always, TestOutputTrue (
519       [["set_recovery_proc"; "true"];
520        ["get_recovery_proc"]])],
521    "enable or disable the recovery process",
522    "\
523 If this is called with the parameter C<false> then
524 C<guestfs_launch> does not create a recovery process.  The
525 purpose of the recovery process is to stop runaway qemu
526 processes in the case where the main program aborts abruptly.
527
528 This only has any effect if called before C<guestfs_launch>,
529 and the default is true.
530
531 About the only time when you would want to disable this is
532 if the main process will fork itself into the background
533 (\"daemonize\" itself).  In this case the recovery process
534 thinks that the main program has disappeared and so kills
535 qemu, which is not very helpful.");
536
537   ("get_recovery_proc", (RBool "recoveryproc", [], []), -1, [],
538    [],
539    "get recovery process enabled flag",
540    "\
541 Return the recovery process enabled flag.");
542
543   ("add_drive_with_if", (RErr, [String "filename"; String "iface"], []), -1, [DeprecatedBy "add_drive_opts"],
544    [],
545    "add a drive specifying the QEMU block emulation to use",
546    "\
547 This is the same as C<guestfs_add_drive> but it allows you
548 to specify the QEMU interface emulation to use at run time.");
549
550   ("add_drive_ro_with_if", (RErr, [String "filename"; String "iface"], []), -1, [DeprecatedBy "add_drive_opts"],
551    [],
552    "add a drive read-only specifying the QEMU block emulation to use",
553    "\
554 This is the same as C<guestfs_add_drive_ro> but it allows you
555 to specify the QEMU interface emulation to use at run time.");
556
557   ("file_architecture", (RString "arch", [Pathname "filename"], []), -1, [],
558    [InitISOFS, Always, TestOutput (
559       [["file_architecture"; "/bin-i586-dynamic"]], "i386");
560     InitISOFS, Always, TestOutput (
561       [["file_architecture"; "/bin-sparc-dynamic"]], "sparc");
562     InitISOFS, Always, TestOutput (
563       [["file_architecture"; "/bin-win32.exe"]], "i386");
564     InitISOFS, Always, TestOutput (
565       [["file_architecture"; "/bin-win64.exe"]], "x86_64");
566     InitISOFS, Always, TestOutput (
567       [["file_architecture"; "/bin-x86_64-dynamic"]], "x86_64");
568     InitISOFS, Always, TestOutput (
569       [["file_architecture"; "/lib-i586.so"]], "i386");
570     InitISOFS, Always, TestOutput (
571       [["file_architecture"; "/lib-sparc.so"]], "sparc");
572     InitISOFS, Always, TestOutput (
573       [["file_architecture"; "/lib-win32.dll"]], "i386");
574     InitISOFS, Always, TestOutput (
575       [["file_architecture"; "/lib-win64.dll"]], "x86_64");
576     InitISOFS, Always, TestOutput (
577       [["file_architecture"; "/lib-x86_64.so"]], "x86_64");
578     InitISOFS, Always, TestOutput (
579       [["file_architecture"; "/initrd-x86_64.img"]], "x86_64");
580     InitISOFS, Always, TestOutput (
581       [["file_architecture"; "/initrd-x86_64.img.gz"]], "x86_64");],
582    "detect the architecture of a binary file",
583    "\
584 This detects the architecture of the binary C<filename>,
585 and returns it if known.
586
587 Currently defined architectures are:
588
589 =over 4
590
591 =item \"i386\"
592
593 This string is returned for all 32 bit i386, i486, i586, i686 binaries
594 irrespective of the precise processor requirements of the binary.
595
596 =item \"x86_64\"
597
598 64 bit x86-64.
599
600 =item \"sparc\"
601
602 32 bit SPARC.
603
604 =item \"sparc64\"
605
606 64 bit SPARC V9 and above.
607
608 =item \"ia64\"
609
610 Intel Itanium.
611
612 =item \"ppc\"
613
614 32 bit Power PC.
615
616 =item \"ppc64\"
617
618 64 bit Power PC.
619
620 =back
621
622 Libguestfs may return other architecture strings in future.
623
624 The function works on at least the following types of files:
625
626 =over 4
627
628 =item *
629
630 many types of Un*x and Linux binary
631
632 =item *
633
634 many types of Un*x and Linux shared library
635
636 =item *
637
638 Windows Win32 and Win64 binaries
639
640 =item *
641
642 Windows Win32 and Win64 DLLs
643
644 Win32 binaries and DLLs return C<i386>.
645
646 Win64 binaries and DLLs return C<x86_64>.
647
648 =item *
649
650 Linux kernel modules
651
652 =item *
653
654 Linux new-style initrd images
655
656 =item *
657
658 some non-x86 Linux vmlinuz kernels
659
660 =back
661
662 What it can't do currently:
663
664 =over 4
665
666 =item *
667
668 static libraries (libfoo.a)
669
670 =item *
671
672 Linux old-style initrd as compressed ext2 filesystem (RHEL 3)
673
674 =item *
675
676 x86 Linux vmlinuz kernels
677
678 x86 vmlinuz images (bzImage format) consist of a mix of 16-, 32- and
679 compressed code, and are horribly hard to unpack.  If you want to find
680 the architecture of a kernel, use the architecture of the associated
681 initrd or kernel module(s) instead.
682
683 =back");
684
685   ("inspect_os", (RStringList "roots", [], []), -1, [],
686    [],
687    "inspect disk and return list of operating systems found",
688    "\
689 This function uses other libguestfs functions and certain
690 heuristics to inspect the disk(s) (usually disks belonging to
691 a virtual machine), looking for operating systems.
692
693 The list returned is empty if no operating systems were found.
694
695 If one operating system was found, then this returns a list with
696 a single element, which is the name of the root filesystem of
697 this operating system.  It is also possible for this function
698 to return a list containing more than one element, indicating
699 a dual-boot or multi-boot virtual machine, with each element being
700 the root filesystem of one of the operating systems.
701
702 You can pass the root string(s) returned to other
703 C<guestfs_inspect_get_*> functions in order to query further
704 information about each operating system, such as the name
705 and version.
706
707 This function uses other libguestfs features such as
708 C<guestfs_mount_ro> and C<guestfs_umount_all> in order to mount
709 and unmount filesystems and look at the contents.  This should
710 be called with no disks currently mounted.  The function may also
711 use Augeas, so any existing Augeas handle will be closed.
712
713 This function cannot decrypt encrypted disks.  The caller
714 must do that first (supplying the necessary keys) if the
715 disk is encrypted.
716
717 Please read L<guestfs(3)/INSPECTION> for more details.
718
719 See also C<guestfs_list_filesystems>.");
720
721   ("inspect_get_type", (RString "name", [Device "root"], []), -1, [],
722    [],
723    "get type of inspected operating system",
724    "\
725 This function should only be called with a root device string
726 as returned by C<guestfs_inspect_os>.
727
728 This returns the type of the inspected operating system.
729 Currently defined types are:
730
731 =over 4
732
733 =item \"linux\"
734
735 Any Linux-based operating system.
736
737 =item \"windows\"
738
739 Any Microsoft Windows operating system.
740
741 =item \"unknown\"
742
743 The operating system type could not be determined.
744
745 =back
746
747 Future versions of libguestfs may return other strings here.
748 The caller should be prepared to handle any string.
749
750 Please read L<guestfs(3)/INSPECTION> for more details.");
751
752   ("inspect_get_arch", (RString "arch", [Device "root"], []), -1, [],
753    [],
754    "get architecture of inspected operating system",
755    "\
756 This function should only be called with a root device string
757 as returned by C<guestfs_inspect_os>.
758
759 This returns the architecture of the inspected operating system.
760 The possible return values are listed under
761 C<guestfs_file_architecture>.
762
763 If the architecture could not be determined, then the
764 string C<unknown> is returned.
765
766 Please read L<guestfs(3)/INSPECTION> for more details.");
767
768   ("inspect_get_distro", (RString "distro", [Device "root"], []), -1, [],
769    [],
770    "get distro of inspected operating system",
771    "\
772 This function should only be called with a root device string
773 as returned by C<guestfs_inspect_os>.
774
775 This returns the distro (distribution) of the inspected operating
776 system.
777
778 Currently defined distros are:
779
780 =over 4
781
782 =item \"debian\"
783
784 Debian or a Debian-derived distro such as Ubuntu.
785
786 =item \"fedora\"
787
788 Fedora.
789
790 =item \"redhat-based\"
791
792 Some Red Hat-derived distro.
793
794 =item \"rhel\"
795
796 Red Hat Enterprise Linux and some derivatives.
797
798 =item \"windows\"
799
800 Windows does not have distributions.  This string is
801 returned if the OS type is Windows.
802
803 =item \"unknown\"
804
805 The distro could not be determined.
806
807 =back
808
809 Future versions of libguestfs may return other strings here.
810 The caller should be prepared to handle any string.
811
812 Please read L<guestfs(3)/INSPECTION> for more details.");
813
814   ("inspect_get_major_version", (RInt "major", [Device "root"], []), -1, [],
815    [],
816    "get major version of inspected operating system",
817    "\
818 This function should only be called with a root device string
819 as returned by C<guestfs_inspect_os>.
820
821 This returns the major version number of the inspected operating
822 system.
823
824 Windows uses a consistent versioning scheme which is I<not>
825 reflected in the popular public names used by the operating system.
826 Notably the operating system known as \"Windows 7\" is really
827 version 6.1 (ie. major = 6, minor = 1).  You can find out the
828 real versions corresponding to releases of Windows by consulting
829 Wikipedia or MSDN.
830
831 If the version could not be determined, then C<0> is returned.
832
833 Please read L<guestfs(3)/INSPECTION> for more details.");
834
835   ("inspect_get_minor_version", (RInt "minor", [Device "root"], []), -1, [],
836    [],
837    "get minor version of inspected operating system",
838    "\
839 This function should only be called with a root device string
840 as returned by C<guestfs_inspect_os>.
841
842 This returns the minor version number of the inspected operating
843 system.
844
845 If the version could not be determined, then C<0> is returned.
846
847 Please read L<guestfs(3)/INSPECTION> for more details.
848 See also C<guestfs_inspect_get_major_version>.");
849
850   ("inspect_get_product_name", (RString "product", [Device "root"], []), -1, [],
851    [],
852    "get product name of inspected operating system",
853    "\
854 This function should only be called with a root device string
855 as returned by C<guestfs_inspect_os>.
856
857 This returns the product name of the inspected operating
858 system.  The product name is generally some freeform string
859 which can be displayed to the user, but should not be
860 parsed by programs.
861
862 If the product name could not be determined, then the
863 string C<unknown> is returned.
864
865 Please read L<guestfs(3)/INSPECTION> for more details.");
866
867   ("inspect_get_mountpoints", (RHashtable "mountpoints", [Device "root"], []), -1, [],
868    [],
869    "get mountpoints of inspected operating system",
870    "\
871 This function should only be called with a root device string
872 as returned by C<guestfs_inspect_os>.
873
874 This returns a hash of where we think the filesystems
875 associated with this operating system should be mounted.
876 Callers should note that this is at best an educated guess
877 made by reading configuration files such as C</etc/fstab>.
878
879 Each element in the returned hashtable has a key which
880 is the path of the mountpoint (eg. C</boot>) and a value
881 which is the filesystem that would be mounted there
882 (eg. C</dev/sda1>).
883
884 Non-mounted devices such as swap devices are I<not>
885 returned in this list.
886
887 Please read L<guestfs(3)/INSPECTION> for more details.
888 See also C<guestfs_inspect_get_filesystems>.");
889
890   ("inspect_get_filesystems", (RStringList "filesystems", [Device "root"], []), -1, [],
891    [],
892    "get filesystems associated with inspected operating system",
893    "\
894 This function should only be called with a root device string
895 as returned by C<guestfs_inspect_os>.
896
897 This returns a list of all the filesystems that we think
898 are associated with this operating system.  This includes
899 the root filesystem, other ordinary filesystems, and
900 non-mounted devices like swap partitions.
901
902 In the case of a multi-boot virtual machine, it is possible
903 for a filesystem to be shared between operating systems.
904
905 Please read L<guestfs(3)/INSPECTION> for more details.
906 See also C<guestfs_inspect_get_mountpoints>.");
907
908   ("set_network", (RErr, [Bool "network"], []), -1, [FishAlias "network"],
909    [],
910    "set enable network flag",
911    "\
912 If C<network> is true, then the network is enabled in the
913 libguestfs appliance.  The default is false.
914
915 This affects whether commands are able to access the network
916 (see L<guestfs(3)/RUNNING COMMANDS>).
917
918 You must call this before calling C<guestfs_launch>, otherwise
919 it has no effect.");
920
921   ("get_network", (RBool "network", [], []), -1, [],
922    [],
923    "get enable network flag",
924    "\
925 This returns the enable network flag.");
926
927   ("list_filesystems", (RHashtable "fses", [], []), -1, [],
928    [],
929    "list filesystems",
930    "\
931 This inspection command looks for filesystems on partitions,
932 block devices and logical volumes, returning a list of devices
933 containing filesystems and their type.
934
935 The return value is a hash, where the keys are the devices
936 containing filesystems, and the values are the filesystem types.
937 For example:
938
939  \"/dev/sda1\" => \"ntfs\"
940  \"/dev/sda2\" => \"ext2\"
941  \"/dev/vg_guest/lv_root\" => \"ext4\"
942  \"/dev/vg_guest/lv_swap\" => \"swap\"
943
944 The value can have the special value \"unknown\", meaning the
945 content of the device is undetermined or empty.
946 \"swap\" means a Linux swap partition.
947
948 This command runs other libguestfs commands, which might include
949 C<guestfs_mount> and C<guestfs_umount>, and therefore you should
950 use this soon after launch and only when nothing is mounted.
951
952 Not all of the filesystems returned will be mountable.  In
953 particular, swap partitions are returned in the list.  Also
954 this command does not check that each filesystem
955 found is valid and mountable, and some filesystems might
956 be mountable but require special options.  Filesystems may
957 not all belong to a single logical operating system
958 (use C<guestfs_inspect_os> to look for OSes).");
959
960   ("add_drive_opts", (RErr, [String "filename"], [Bool "readonly"; String "format"; String "iface"]), -1, [FishAlias "add"],
961    [],
962    "add an image to examine or modify",
963    "\
964 This function adds a virtual machine disk image C<filename> to
965 libguestfs.  The first time you call this function, the disk
966 appears as C</dev/sda>, the second time as C</dev/sdb>, and
967 so on.
968
969 You don't necessarily need to be root when using libguestfs.  However
970 you obviously do need sufficient permissions to access the filename
971 for whatever operations you want to perform (ie. read access if you
972 just want to read the image or write access if you want to modify the
973 image).
974
975 This call checks that C<filename> exists.
976
977 The optional arguments are:
978
979 =over 4
980
981 =item C<readonly>
982
983 If true then the image is treated as read-only.  Writes are still
984 allowed, but they are stored in a temporary snapshot overlay which
985 is discarded at the end.  The disk that you add is not modified.
986
987 =item C<format>
988
989 This forces the image format.  If you omit this (or use C<guestfs_add_drive>
990 or C<guestfs_add_drive_ro>) then the format is automatically detected.
991 Possible formats include C<raw> and C<qcow2>.
992
993 Automatic detection of the format opens you up to a potential
994 security hole when dealing with untrusted raw-format images.
995 See CVE-2010-3851 and RHBZ#642934.  Specifying the format closes
996 this security hole.
997
998 =item C<iface>
999
1000 This rarely-used option lets you emulate the behaviour of the
1001 deprecated C<guestfs_add_drive_with_if> call (q.v.)
1002
1003 =back");
1004
1005 ]
1006
1007 (* daemon_functions are any functions which cause some action
1008  * to take place in the daemon.
1009  *)
1010
1011 let daemon_functions = [
1012   ("mount", (RErr, [Device "device"; String "mountpoint"], []), 1, [],
1013    [InitEmpty, Always, TestOutput (
1014       [["part_disk"; "/dev/sda"; "mbr"];
1015        ["mkfs"; "ext2"; "/dev/sda1"];
1016        ["mount"; "/dev/sda1"; "/"];
1017        ["write"; "/new"; "new file contents"];
1018        ["cat"; "/new"]], "new file contents")],
1019    "mount a guest disk at a position in the filesystem",
1020    "\
1021 Mount a guest disk at a position in the filesystem.  Block devices
1022 are named C</dev/sda>, C</dev/sdb> and so on, as they were added to
1023 the guest.  If those block devices contain partitions, they will have
1024 the usual names (eg. C</dev/sda1>).  Also LVM C</dev/VG/LV>-style
1025 names can be used.
1026
1027 The rules are the same as for L<mount(2)>:  A filesystem must
1028 first be mounted on C</> before others can be mounted.  Other
1029 filesystems can only be mounted on directories which already
1030 exist.
1031
1032 The mounted filesystem is writable, if we have sufficient permissions
1033 on the underlying device.
1034
1035 B<Important note:>
1036 When you use this call, the filesystem options C<sync> and C<noatime>
1037 are set implicitly.  This was originally done because we thought it
1038 would improve reliability, but it turns out that I<-o sync> has a
1039 very large negative performance impact and negligible effect on
1040 reliability.  Therefore we recommend that you avoid using
1041 C<guestfs_mount> in any code that needs performance, and instead
1042 use C<guestfs_mount_options> (use an empty string for the first
1043 parameter if you don't want any options).");
1044
1045   ("sync", (RErr, [], []), 2, [],
1046    [ InitEmpty, Always, TestRun [["sync"]]],
1047    "sync disks, writes are flushed through to the disk image",
1048    "\
1049 This syncs the disk, so that any writes are flushed through to the
1050 underlying disk image.
1051
1052 You should always call this if you have modified a disk image, before
1053 closing the handle.");
1054
1055   ("touch", (RErr, [Pathname "path"], []), 3, [],
1056    [InitBasicFS, Always, TestOutputTrue (
1057       [["touch"; "/new"];
1058        ["exists"; "/new"]])],
1059    "update file timestamps or create a new file",
1060    "\
1061 Touch acts like the L<touch(1)> command.  It can be used to
1062 update the timestamps on a file, or, if the file does not exist,
1063 to create a new zero-length file.
1064
1065 This command only works on regular files, and will fail on other
1066 file types such as directories, symbolic links, block special etc.");
1067
1068   ("cat", (RString "content", [Pathname "path"], []), 4, [ProtocolLimitWarning],
1069    [InitISOFS, Always, TestOutput (
1070       [["cat"; "/known-2"]], "abcdef\n")],
1071    "list the contents of a file",
1072    "\
1073 Return the contents of the file named C<path>.
1074
1075 Note that this function cannot correctly handle binary files
1076 (specifically, files containing C<\\0> character which is treated
1077 as end of string).  For those you need to use the C<guestfs_read_file>
1078 or C<guestfs_download> functions which have a more complex interface.");
1079
1080   ("ll", (RString "listing", [Pathname "directory"], []), 5, [],
1081    [], (* XXX Tricky to test because it depends on the exact format
1082         * of the 'ls -l' command, which changes between F10 and F11.
1083         *)
1084    "list the files in a directory (long format)",
1085    "\
1086 List the files in C<directory> (relative to the root directory,
1087 there is no cwd) in the format of 'ls -la'.
1088
1089 This command is mostly useful for interactive sessions.  It
1090 is I<not> intended that you try to parse the output string.");
1091
1092   ("ls", (RStringList "listing", [Pathname "directory"], []), 6, [],
1093    [InitBasicFS, Always, TestOutputList (
1094       [["touch"; "/new"];
1095        ["touch"; "/newer"];
1096        ["touch"; "/newest"];
1097        ["ls"; "/"]], ["lost+found"; "new"; "newer"; "newest"])],
1098    "list the files in a directory",
1099    "\
1100 List the files in C<directory> (relative to the root directory,
1101 there is no cwd).  The '.' and '..' entries are not returned, but
1102 hidden files are shown.
1103
1104 This command is mostly useful for interactive sessions.  Programs
1105 should probably use C<guestfs_readdir> instead.");
1106
1107   ("list_devices", (RStringList "devices", [], []), 7, [],
1108    [InitEmpty, Always, TestOutputListOfDevices (
1109       [["list_devices"]], ["/dev/sda"; "/dev/sdb"; "/dev/sdc"; "/dev/sdd"])],
1110    "list the block devices",
1111    "\
1112 List all the block devices.
1113
1114 The full block device names are returned, eg. C</dev/sda>.
1115
1116 See also C<guestfs_list_filesystems>.");
1117
1118   ("list_partitions", (RStringList "partitions", [], []), 8, [],
1119    [InitBasicFS, Always, TestOutputListOfDevices (
1120       [["list_partitions"]], ["/dev/sda1"]);
1121     InitEmpty, Always, TestOutputListOfDevices (
1122       [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1123        ["list_partitions"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])],
1124    "list the partitions",
1125    "\
1126 List all the partitions detected on all block devices.
1127
1128 The full partition device names are returned, eg. C</dev/sda1>
1129
1130 This does not return logical volumes.  For that you will need to
1131 call C<guestfs_lvs>.
1132
1133 See also C<guestfs_list_filesystems>.");
1134
1135   ("pvs", (RStringList "physvols", [], []), 9, [Optional "lvm2"],
1136    [InitBasicFSonLVM, Always, TestOutputListOfDevices (
1137       [["pvs"]], ["/dev/sda1"]);
1138     InitEmpty, Always, TestOutputListOfDevices (
1139       [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1140        ["pvcreate"; "/dev/sda1"];
1141        ["pvcreate"; "/dev/sda2"];
1142        ["pvcreate"; "/dev/sda3"];
1143        ["pvs"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])],
1144    "list the LVM physical volumes (PVs)",
1145    "\
1146 List all the physical volumes detected.  This is the equivalent
1147 of the L<pvs(8)> command.
1148
1149 This returns a list of just the device names that contain
1150 PVs (eg. C</dev/sda2>).
1151
1152 See also C<guestfs_pvs_full>.");
1153
1154   ("vgs", (RStringList "volgroups", [], []), 10, [Optional "lvm2"],
1155    [InitBasicFSonLVM, Always, TestOutputList (
1156       [["vgs"]], ["VG"]);
1157     InitEmpty, Always, TestOutputList (
1158       [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1159        ["pvcreate"; "/dev/sda1"];
1160        ["pvcreate"; "/dev/sda2"];
1161        ["pvcreate"; "/dev/sda3"];
1162        ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
1163        ["vgcreate"; "VG2"; "/dev/sda3"];
1164        ["vgs"]], ["VG1"; "VG2"])],
1165    "list the LVM volume groups (VGs)",
1166    "\
1167 List all the volumes groups detected.  This is the equivalent
1168 of the L<vgs(8)> command.
1169
1170 This returns a list of just the volume group names that were
1171 detected (eg. C<VolGroup00>).
1172
1173 See also C<guestfs_vgs_full>.");
1174
1175   ("lvs", (RStringList "logvols", [], []), 11, [Optional "lvm2"],
1176    [InitBasicFSonLVM, Always, TestOutputList (
1177       [["lvs"]], ["/dev/VG/LV"]);
1178     InitEmpty, Always, TestOutputList (
1179       [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1180        ["pvcreate"; "/dev/sda1"];
1181        ["pvcreate"; "/dev/sda2"];
1182        ["pvcreate"; "/dev/sda3"];
1183        ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
1184        ["vgcreate"; "VG2"; "/dev/sda3"];
1185        ["lvcreate"; "LV1"; "VG1"; "50"];
1186        ["lvcreate"; "LV2"; "VG1"; "50"];
1187        ["lvcreate"; "LV3"; "VG2"; "50"];
1188        ["lvs"]], ["/dev/VG1/LV1"; "/dev/VG1/LV2"; "/dev/VG2/LV3"])],
1189    "list the LVM logical volumes (LVs)",
1190    "\
1191 List all the logical volumes detected.  This is the equivalent
1192 of the L<lvs(8)> command.
1193
1194 This returns a list of the logical volume device names
1195 (eg. C</dev/VolGroup00/LogVol00>).
1196
1197 See also C<guestfs_lvs_full>, C<guestfs_list_filesystems>.");
1198
1199   ("pvs_full", (RStructList ("physvols", "lvm_pv"), [], []), 12, [Optional "lvm2"],
1200    [], (* XXX how to test? *)
1201    "list the LVM physical volumes (PVs)",
1202    "\
1203 List all the physical volumes detected.  This is the equivalent
1204 of the L<pvs(8)> command.  The \"full\" version includes all fields.");
1205
1206   ("vgs_full", (RStructList ("volgroups", "lvm_vg"), [], []), 13, [Optional "lvm2"],
1207    [], (* XXX how to test? *)
1208    "list the LVM volume groups (VGs)",
1209    "\
1210 List all the volumes groups detected.  This is the equivalent
1211 of the L<vgs(8)> command.  The \"full\" version includes all fields.");
1212
1213   ("lvs_full", (RStructList ("logvols", "lvm_lv"), [], []), 14, [Optional "lvm2"],
1214    [], (* XXX how to test? *)
1215    "list the LVM logical volumes (LVs)",
1216    "\
1217 List all the logical volumes detected.  This is the equivalent
1218 of the L<lvs(8)> command.  The \"full\" version includes all fields.");
1219
1220   ("read_lines", (RStringList "lines", [Pathname "path"], []), 15, [],
1221    [InitISOFS, Always, TestOutputList (
1222       [["read_lines"; "/known-4"]], ["abc"; "def"; "ghi"]);
1223     InitISOFS, Always, TestOutputList (
1224       [["read_lines"; "/empty"]], [])],
1225    "read file as lines",
1226    "\
1227 Return the contents of the file named C<path>.
1228
1229 The file contents are returned as a list of lines.  Trailing
1230 C<LF> and C<CRLF> character sequences are I<not> returned.
1231
1232 Note that this function cannot correctly handle binary files
1233 (specifically, files containing C<\\0> character which is treated
1234 as end of line).  For those you need to use the C<guestfs_read_file>
1235 function which has a more complex interface.");
1236
1237   ("aug_init", (RErr, [Pathname "root"; Int "flags"], []), 16, [Optional "augeas"],
1238    [], (* XXX Augeas code needs tests. *)
1239    "create a new Augeas handle",
1240    "\
1241 Create a new Augeas handle for editing configuration files.
1242 If there was any previous Augeas handle associated with this
1243 guestfs session, then it is closed.
1244
1245 You must call this before using any other C<guestfs_aug_*>
1246 commands.
1247
1248 C<root> is the filesystem root.  C<root> must not be NULL,
1249 use C</> instead.
1250
1251 The flags are the same as the flags defined in
1252 E<lt>augeas.hE<gt>, the logical I<or> of the following
1253 integers:
1254
1255 =over 4
1256
1257 =item C<AUG_SAVE_BACKUP> = 1
1258
1259 Keep the original file with a C<.augsave> extension.
1260
1261 =item C<AUG_SAVE_NEWFILE> = 2
1262
1263 Save changes into a file with extension C<.augnew>, and
1264 do not overwrite original.  Overrides C<AUG_SAVE_BACKUP>.
1265
1266 =item C<AUG_TYPE_CHECK> = 4
1267
1268 Typecheck lenses (can be expensive).
1269
1270 =item C<AUG_NO_STDINC> = 8
1271
1272 Do not use standard load path for modules.
1273
1274 =item C<AUG_SAVE_NOOP> = 16
1275
1276 Make save a no-op, just record what would have been changed.
1277
1278 =item C<AUG_NO_LOAD> = 32
1279
1280 Do not load the tree in C<guestfs_aug_init>.
1281
1282 =back
1283
1284 To close the handle, you can call C<guestfs_aug_close>.
1285
1286 To find out more about Augeas, see L<http://augeas.net/>.");
1287
1288   ("aug_close", (RErr, [], []), 26, [Optional "augeas"],
1289    [], (* XXX Augeas code needs tests. *)
1290    "close the current Augeas handle",
1291    "\
1292 Close the current Augeas handle and free up any resources
1293 used by it.  After calling this, you have to call
1294 C<guestfs_aug_init> again before you can use any other
1295 Augeas functions.");
1296
1297   ("aug_defvar", (RInt "nrnodes", [String "name"; OptString "expr"], []), 17, [Optional "augeas"],
1298    [], (* XXX Augeas code needs tests. *)
1299    "define an Augeas variable",
1300    "\
1301 Defines an Augeas variable C<name> whose value is the result
1302 of evaluating C<expr>.  If C<expr> is NULL, then C<name> is
1303 undefined.
1304
1305 On success this returns the number of nodes in C<expr>, or
1306 C<0> if C<expr> evaluates to something which is not a nodeset.");
1307
1308   ("aug_defnode", (RStruct ("nrnodescreated", "int_bool"), [String "name"; String "expr"; String "val"], []), 18, [Optional "augeas"],
1309    [], (* XXX Augeas code needs tests. *)
1310    "define an Augeas node",
1311    "\
1312 Defines a variable C<name> whose value is the result of
1313 evaluating C<expr>.
1314
1315 If C<expr> evaluates to an empty nodeset, a node is created,
1316 equivalent to calling C<guestfs_aug_set> C<expr>, C<value>.
1317 C<name> will be the nodeset containing that single node.
1318
1319 On success this returns a pair containing the
1320 number of nodes in the nodeset, and a boolean flag
1321 if a node was created.");
1322
1323   ("aug_get", (RString "val", [String "augpath"], []), 19, [Optional "augeas"],
1324    [], (* XXX Augeas code needs tests. *)
1325    "look up the value of an Augeas path",
1326    "\
1327 Look up the value associated with C<path>.  If C<path>
1328 matches exactly one node, the C<value> is returned.");
1329
1330   ("aug_set", (RErr, [String "augpath"; String "val"], []), 20, [Optional "augeas"],
1331    [], (* XXX Augeas code needs tests. *)
1332    "set Augeas path to value",
1333    "\
1334 Set the value associated with C<path> to C<val>.
1335
1336 In the Augeas API, it is possible to clear a node by setting
1337 the value to NULL.  Due to an oversight in the libguestfs API
1338 you cannot do that with this call.  Instead you must use the
1339 C<guestfs_aug_clear> call.");
1340
1341   ("aug_insert", (RErr, [String "augpath"; String "label"; Bool "before"], []), 21, [Optional "augeas"],
1342    [], (* XXX Augeas code needs tests. *)
1343    "insert a sibling Augeas node",
1344    "\
1345 Create a new sibling C<label> for C<path>, inserting it into
1346 the tree before or after C<path> (depending on the boolean
1347 flag C<before>).
1348
1349 C<path> must match exactly one existing node in the tree, and
1350 C<label> must be a label, ie. not contain C</>, C<*> or end
1351 with a bracketed index C<[N]>.");
1352
1353   ("aug_rm", (RInt "nrnodes", [String "augpath"], []), 22, [Optional "augeas"],
1354    [], (* XXX Augeas code needs tests. *)
1355    "remove an Augeas path",
1356    "\
1357 Remove C<path> and all of its children.
1358
1359 On success this returns the number of entries which were removed.");
1360
1361   ("aug_mv", (RErr, [String "src"; String "dest"], []), 23, [Optional "augeas"],
1362    [], (* XXX Augeas code needs tests. *)
1363    "move Augeas node",
1364    "\
1365 Move the node C<src> to C<dest>.  C<src> must match exactly
1366 one node.  C<dest> is overwritten if it exists.");
1367
1368   ("aug_match", (RStringList "matches", [String "augpath"], []), 24, [Optional "augeas"],
1369    [], (* XXX Augeas code needs tests. *)
1370    "return Augeas nodes which match augpath",
1371    "\
1372 Returns a list of paths which match the path expression C<path>.
1373 The returned paths are sufficiently qualified so that they match
1374 exactly one node in the current tree.");
1375
1376   ("aug_save", (RErr, [], []), 25, [Optional "augeas"],
1377    [], (* XXX Augeas code needs tests. *)
1378    "write all pending Augeas changes to disk",
1379    "\
1380 This writes all pending changes to disk.
1381
1382 The flags which were passed to C<guestfs_aug_init> affect exactly
1383 how files are saved.");
1384
1385   ("aug_load", (RErr, [], []), 27, [Optional "augeas"],
1386    [], (* XXX Augeas code needs tests. *)
1387    "load files into the tree",
1388    "\
1389 Load files into the tree.
1390
1391 See C<aug_load> in the Augeas documentation for the full gory
1392 details.");
1393
1394   ("aug_ls", (RStringList "matches", [String "augpath"], []), 28, [Optional "augeas"],
1395    [], (* XXX Augeas code needs tests. *)
1396    "list Augeas nodes under augpath",
1397    "\
1398 This is just a shortcut for listing C<guestfs_aug_match>
1399 C<path/*> and sorting the resulting nodes into alphabetical order.");
1400
1401   ("rm", (RErr, [Pathname "path"], []), 29, [],
1402    [InitBasicFS, Always, TestRun
1403       [["touch"; "/new"];
1404        ["rm"; "/new"]];
1405     InitBasicFS, Always, TestLastFail
1406       [["rm"; "/new"]];
1407     InitBasicFS, Always, TestLastFail
1408       [["mkdir"; "/new"];
1409        ["rm"; "/new"]]],
1410    "remove a file",
1411    "\
1412 Remove the single file C<path>.");
1413
1414   ("rmdir", (RErr, [Pathname "path"], []), 30, [],
1415    [InitBasicFS, Always, TestRun
1416       [["mkdir"; "/new"];
1417        ["rmdir"; "/new"]];
1418     InitBasicFS, Always, TestLastFail
1419       [["rmdir"; "/new"]];
1420     InitBasicFS, Always, TestLastFail
1421       [["touch"; "/new"];
1422        ["rmdir"; "/new"]]],
1423    "remove a directory",
1424    "\
1425 Remove the single directory C<path>.");
1426
1427   ("rm_rf", (RErr, [Pathname "path"], []), 31, [],
1428    [InitBasicFS, Always, TestOutputFalse
1429       [["mkdir"; "/new"];
1430        ["mkdir"; "/new/foo"];
1431        ["touch"; "/new/foo/bar"];
1432        ["rm_rf"; "/new"];
1433        ["exists"; "/new"]]],
1434    "remove a file or directory recursively",
1435    "\
1436 Remove the file or directory C<path>, recursively removing the
1437 contents if its a directory.  This is like the C<rm -rf> shell
1438 command.");
1439
1440   ("mkdir", (RErr, [Pathname "path"], []), 32, [],
1441    [InitBasicFS, Always, TestOutputTrue
1442       [["mkdir"; "/new"];
1443        ["is_dir"; "/new"]];
1444     InitBasicFS, Always, TestLastFail
1445       [["mkdir"; "/new/foo/bar"]]],
1446    "create a directory",
1447    "\
1448 Create a directory named C<path>.");
1449
1450   ("mkdir_p", (RErr, [Pathname "path"], []), 33, [],
1451    [InitBasicFS, Always, TestOutputTrue
1452       [["mkdir_p"; "/new/foo/bar"];
1453        ["is_dir"; "/new/foo/bar"]];
1454     InitBasicFS, Always, TestOutputTrue
1455       [["mkdir_p"; "/new/foo/bar"];
1456        ["is_dir"; "/new/foo"]];
1457     InitBasicFS, Always, TestOutputTrue
1458       [["mkdir_p"; "/new/foo/bar"];
1459        ["is_dir"; "/new"]];
1460     (* Regression tests for RHBZ#503133: *)
1461     InitBasicFS, Always, TestRun
1462       [["mkdir"; "/new"];
1463        ["mkdir_p"; "/new"]];
1464     InitBasicFS, Always, TestLastFail
1465       [["touch"; "/new"];
1466        ["mkdir_p"; "/new"]]],
1467    "create a directory and parents",
1468    "\
1469 Create a directory named C<path>, creating any parent directories
1470 as necessary.  This is like the C<mkdir -p> shell command.");
1471
1472   ("chmod", (RErr, [Int "mode"; Pathname "path"], []), 34, [],
1473    [], (* XXX Need stat command to test *)
1474    "change file mode",
1475    "\
1476 Change the mode (permissions) of C<path> to C<mode>.  Only
1477 numeric modes are supported.
1478
1479 I<Note>: When using this command from guestfish, C<mode>
1480 by default would be decimal, unless you prefix it with
1481 C<0> to get octal, ie. use C<0700> not C<700>.
1482
1483 The mode actually set is affected by the umask.");
1484
1485   ("chown", (RErr, [Int "owner"; Int "group"; Pathname "path"], []), 35, [],
1486    [], (* XXX Need stat command to test *)
1487    "change file owner and group",
1488    "\
1489 Change the file owner to C<owner> and group to C<group>.
1490
1491 Only numeric uid and gid are supported.  If you want to use
1492 names, you will need to locate and parse the password file
1493 yourself (Augeas support makes this relatively easy).");
1494
1495   ("exists", (RBool "existsflag", [Pathname "path"], []), 36, [],
1496    [InitISOFS, Always, TestOutputTrue (
1497       [["exists"; "/empty"]]);
1498     InitISOFS, Always, TestOutputTrue (
1499       [["exists"; "/directory"]])],
1500    "test if file or directory exists",
1501    "\
1502 This returns C<true> if and only if there is a file, directory
1503 (or anything) with the given C<path> name.
1504
1505 See also C<guestfs_is_file>, C<guestfs_is_dir>, C<guestfs_stat>.");
1506
1507   ("is_file", (RBool "fileflag", [Pathname "path"], []), 37, [],
1508    [InitISOFS, Always, TestOutputTrue (
1509       [["is_file"; "/known-1"]]);
1510     InitISOFS, Always, TestOutputFalse (
1511       [["is_file"; "/directory"]])],
1512    "test if a regular file",
1513    "\
1514 This returns C<true> if and only if there is a regular file
1515 with the given C<path> name.  Note that it returns false for
1516 other objects like directories.
1517
1518 See also C<guestfs_stat>.");
1519
1520   ("is_dir", (RBool "dirflag", [Pathname "path"], []), 38, [],
1521    [InitISOFS, Always, TestOutputFalse (
1522       [["is_dir"; "/known-3"]]);
1523     InitISOFS, Always, TestOutputTrue (
1524       [["is_dir"; "/directory"]])],
1525    "test if a directory",
1526    "\
1527 This returns C<true> if and only if there is a directory
1528 with the given C<path> name.  Note that it returns false for
1529 other objects like files.
1530
1531 See also C<guestfs_stat>.");
1532
1533   ("pvcreate", (RErr, [Device "device"], []), 39, [Optional "lvm2"],
1534    [InitEmpty, Always, TestOutputListOfDevices (
1535       [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1536        ["pvcreate"; "/dev/sda1"];
1537        ["pvcreate"; "/dev/sda2"];
1538        ["pvcreate"; "/dev/sda3"];
1539        ["pvs"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])],
1540    "create an LVM physical volume",
1541    "\
1542 This creates an LVM physical volume on the named C<device>,
1543 where C<device> should usually be a partition name such
1544 as C</dev/sda1>.");
1545
1546   ("vgcreate", (RErr, [String "volgroup"; DeviceList "physvols"], []), 40, [Optional "lvm2"],
1547    [InitEmpty, Always, TestOutputList (
1548       [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1549        ["pvcreate"; "/dev/sda1"];
1550        ["pvcreate"; "/dev/sda2"];
1551        ["pvcreate"; "/dev/sda3"];
1552        ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
1553        ["vgcreate"; "VG2"; "/dev/sda3"];
1554        ["vgs"]], ["VG1"; "VG2"])],
1555    "create an LVM volume group",
1556    "\
1557 This creates an LVM volume group called C<volgroup>
1558 from the non-empty list of physical volumes C<physvols>.");
1559
1560   ("lvcreate", (RErr, [String "logvol"; String "volgroup"; Int "mbytes"], []), 41, [Optional "lvm2"],
1561    [InitEmpty, Always, TestOutputList (
1562       [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1563        ["pvcreate"; "/dev/sda1"];
1564        ["pvcreate"; "/dev/sda2"];
1565        ["pvcreate"; "/dev/sda3"];
1566        ["vgcreate"; "VG1"; "/dev/sda1 /dev/sda2"];
1567        ["vgcreate"; "VG2"; "/dev/sda3"];
1568        ["lvcreate"; "LV1"; "VG1"; "50"];
1569        ["lvcreate"; "LV2"; "VG1"; "50"];
1570        ["lvcreate"; "LV3"; "VG2"; "50"];
1571        ["lvcreate"; "LV4"; "VG2"; "50"];
1572        ["lvcreate"; "LV5"; "VG2"; "50"];
1573        ["lvs"]],
1574       ["/dev/VG1/LV1"; "/dev/VG1/LV2";
1575        "/dev/VG2/LV3"; "/dev/VG2/LV4"; "/dev/VG2/LV5"])],
1576    "create an LVM logical volume",
1577    "\
1578 This creates an LVM logical volume called C<logvol>
1579 on the volume group C<volgroup>, with C<size> megabytes.");
1580
1581   ("mkfs", (RErr, [String "fstype"; Device "device"], []), 42, [],
1582    [InitEmpty, Always, TestOutput (
1583       [["part_disk"; "/dev/sda"; "mbr"];
1584        ["mkfs"; "ext2"; "/dev/sda1"];
1585        ["mount_options"; ""; "/dev/sda1"; "/"];
1586        ["write"; "/new"; "new file contents"];
1587        ["cat"; "/new"]], "new file contents")],
1588    "make a filesystem",
1589    "\
1590 This creates a filesystem on C<device> (usually a partition
1591 or LVM logical volume).  The filesystem type is C<fstype>, for
1592 example C<ext3>.");
1593
1594   ("sfdisk", (RErr, [Device "device";
1595                      Int "cyls"; Int "heads"; Int "sectors";
1596                      StringList "lines"], []), 43, [DangerWillRobinson],
1597    [],
1598    "create partitions on a block device",
1599    "\
1600 This is a direct interface to the L<sfdisk(8)> program for creating
1601 partitions on block devices.
1602
1603 C<device> should be a block device, for example C</dev/sda>.
1604
1605 C<cyls>, C<heads> and C<sectors> are the number of cylinders, heads
1606 and sectors on the device, which are passed directly to sfdisk as
1607 the I<-C>, I<-H> and I<-S> parameters.  If you pass C<0> for any
1608 of these, then the corresponding parameter is omitted.  Usually for
1609 'large' disks, you can just pass C<0> for these, but for small
1610 (floppy-sized) disks, sfdisk (or rather, the kernel) cannot work
1611 out the right geometry and you will need to tell it.
1612
1613 C<lines> is a list of lines that we feed to C<sfdisk>.  For more
1614 information refer to the L<sfdisk(8)> manpage.
1615
1616 To create a single partition occupying the whole disk, you would
1617 pass C<lines> as a single element list, when the single element being
1618 the string C<,> (comma).
1619
1620 See also: C<guestfs_sfdisk_l>, C<guestfs_sfdisk_N>,
1621 C<guestfs_part_init>");
1622
1623   ("write_file", (RErr, [Pathname "path"; String "content"; Int "size"], []), 44, [ProtocolLimitWarning; DeprecatedBy "write"],
1624    (* Regression test for RHBZ#597135. *)
1625    [InitBasicFS, Always, TestLastFail
1626       [["write_file"; "/new"; "abc"; "10000"]]],
1627    "create a file",
1628    "\
1629 This call creates a file called C<path>.  The contents of the
1630 file is the string C<content> (which can contain any 8 bit data),
1631 with length C<size>.
1632
1633 As a special case, if C<size> is C<0>
1634 then the length is calculated using C<strlen> (so in this case
1635 the content cannot contain embedded ASCII NULs).
1636
1637 I<NB.> Owing to a bug, writing content containing ASCII NUL
1638 characters does I<not> work, even if the length is specified.");
1639
1640   ("umount", (RErr, [String "pathordevice"], []), 45, [FishAlias "unmount"],
1641    [InitEmpty, Always, TestOutputListOfDevices (
1642       [["part_disk"; "/dev/sda"; "mbr"];
1643        ["mkfs"; "ext2"; "/dev/sda1"];
1644        ["mount_options"; ""; "/dev/sda1"; "/"];
1645        ["mounts"]], ["/dev/sda1"]);
1646     InitEmpty, Always, TestOutputList (
1647       [["part_disk"; "/dev/sda"; "mbr"];
1648        ["mkfs"; "ext2"; "/dev/sda1"];
1649        ["mount_options"; ""; "/dev/sda1"; "/"];
1650        ["umount"; "/"];
1651        ["mounts"]], [])],
1652    "unmount a filesystem",
1653    "\
1654 This unmounts the given filesystem.  The filesystem may be
1655 specified either by its mountpoint (path) or the device which
1656 contains the filesystem.");
1657
1658   ("mounts", (RStringList "devices", [], []), 46, [],
1659    [InitBasicFS, Always, TestOutputListOfDevices (
1660       [["mounts"]], ["/dev/sda1"])],
1661    "show mounted filesystems",
1662    "\
1663 This returns the list of currently mounted filesystems.  It returns
1664 the list of devices (eg. C</dev/sda1>, C</dev/VG/LV>).
1665
1666 Some internal mounts are not shown.
1667
1668 See also: C<guestfs_mountpoints>");
1669
1670   ("umount_all", (RErr, [], []), 47, [FishAlias "unmount-all"],
1671    [InitBasicFS, Always, TestOutputList (
1672       [["umount_all"];
1673        ["mounts"]], []);
1674     (* check that umount_all can unmount nested mounts correctly: *)
1675     InitEmpty, Always, TestOutputList (
1676       [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"];
1677        ["mkfs"; "ext2"; "/dev/sda1"];
1678        ["mkfs"; "ext2"; "/dev/sda2"];
1679        ["mkfs"; "ext2"; "/dev/sda3"];
1680        ["mount_options"; ""; "/dev/sda1"; "/"];
1681        ["mkdir"; "/mp1"];
1682        ["mount_options"; ""; "/dev/sda2"; "/mp1"];
1683        ["mkdir"; "/mp1/mp2"];
1684        ["mount_options"; ""; "/dev/sda3"; "/mp1/mp2"];
1685        ["mkdir"; "/mp1/mp2/mp3"];
1686        ["umount_all"];
1687        ["mounts"]], [])],
1688    "unmount all filesystems",
1689    "\
1690 This unmounts all mounted filesystems.
1691
1692 Some internal mounts are not unmounted by this call.");
1693
1694   ("lvm_remove_all", (RErr, [], []), 48, [DangerWillRobinson; Optional "lvm2"],
1695    [],
1696    "remove all LVM LVs, VGs and PVs",
1697    "\
1698 This command removes all LVM logical volumes, volume groups
1699 and physical volumes.");
1700
1701   ("file", (RString "description", [Dev_or_Path "path"], []), 49, [],
1702    [InitISOFS, Always, TestOutput (
1703       [["file"; "/empty"]], "empty");
1704     InitISOFS, Always, TestOutput (
1705       [["file"; "/known-1"]], "ASCII text");
1706     InitISOFS, Always, TestLastFail (
1707       [["file"; "/notexists"]]);
1708     InitISOFS, Always, TestOutput (
1709       [["file"; "/abssymlink"]], "symbolic link");
1710     InitISOFS, Always, TestOutput (
1711       [["file"; "/directory"]], "directory")],
1712    "determine file type",
1713    "\
1714 This call uses the standard L<file(1)> command to determine
1715 the type or contents of the file.
1716
1717 This call will also transparently look inside various types
1718 of compressed file.
1719
1720 The exact command which runs is C<file -zb path>.  Note in
1721 particular that the filename is not prepended to the output
1722 (the C<-b> option).
1723
1724 This command can also be used on C</dev/> devices
1725 (and partitions, LV names).  You can for example use this
1726 to determine if a device contains a filesystem, although
1727 it's usually better to use C<guestfs_vfs_type>.
1728
1729 If the C<path> does not begin with C</dev/> then
1730 this command only works for the content of regular files.
1731 For other file types (directory, symbolic link etc) it
1732 will just return the string C<directory> etc.");
1733
1734   ("command", (RString "output", [StringList "arguments"], []), 50, [ProtocolLimitWarning],
1735    [InitBasicFS, Always, TestOutput (
1736       [["upload"; "test-command"; "/test-command"];
1737        ["chmod"; "0o755"; "/test-command"];
1738        ["command"; "/test-command 1"]], "Result1");
1739     InitBasicFS, Always, TestOutput (
1740       [["upload"; "test-command"; "/test-command"];
1741        ["chmod"; "0o755"; "/test-command"];
1742        ["command"; "/test-command 2"]], "Result2\n");
1743     InitBasicFS, Always, TestOutput (
1744       [["upload"; "test-command"; "/test-command"];
1745        ["chmod"; "0o755"; "/test-command"];
1746        ["command"; "/test-command 3"]], "\nResult3");
1747     InitBasicFS, Always, TestOutput (
1748       [["upload"; "test-command"; "/test-command"];
1749        ["chmod"; "0o755"; "/test-command"];
1750        ["command"; "/test-command 4"]], "\nResult4\n");
1751     InitBasicFS, Always, TestOutput (
1752       [["upload"; "test-command"; "/test-command"];
1753        ["chmod"; "0o755"; "/test-command"];
1754        ["command"; "/test-command 5"]], "\nResult5\n\n");
1755     InitBasicFS, Always, TestOutput (
1756       [["upload"; "test-command"; "/test-command"];
1757        ["chmod"; "0o755"; "/test-command"];
1758        ["command"; "/test-command 6"]], "\n\nResult6\n\n");
1759     InitBasicFS, Always, TestOutput (
1760       [["upload"; "test-command"; "/test-command"];
1761        ["chmod"; "0o755"; "/test-command"];
1762        ["command"; "/test-command 7"]], "");
1763     InitBasicFS, Always, TestOutput (
1764       [["upload"; "test-command"; "/test-command"];
1765        ["chmod"; "0o755"; "/test-command"];
1766        ["command"; "/test-command 8"]], "\n");
1767     InitBasicFS, Always, TestOutput (
1768       [["upload"; "test-command"; "/test-command"];
1769        ["chmod"; "0o755"; "/test-command"];
1770        ["command"; "/test-command 9"]], "\n\n");
1771     InitBasicFS, Always, TestOutput (
1772       [["upload"; "test-command"; "/test-command"];
1773        ["chmod"; "0o755"; "/test-command"];
1774        ["command"; "/test-command 10"]], "Result10-1\nResult10-2\n");
1775     InitBasicFS, Always, TestOutput (
1776       [["upload"; "test-command"; "/test-command"];
1777        ["chmod"; "0o755"; "/test-command"];
1778        ["command"; "/test-command 11"]], "Result11-1\nResult11-2");
1779     InitBasicFS, Always, TestLastFail (
1780       [["upload"; "test-command"; "/test-command"];
1781        ["chmod"; "0o755"; "/test-command"];
1782        ["command"; "/test-command"]])],
1783    "run a command from the guest filesystem",
1784    "\
1785 This call runs a command from the guest filesystem.  The
1786 filesystem must be mounted, and must contain a compatible
1787 operating system (ie. something Linux, with the same
1788 or compatible processor architecture).
1789
1790 The single parameter is an argv-style list of arguments.
1791 The first element is the name of the program to run.
1792 Subsequent elements are parameters.  The list must be
1793 non-empty (ie. must contain a program name).  Note that
1794 the command runs directly, and is I<not> invoked via
1795 the shell (see C<guestfs_sh>).
1796
1797 The return value is anything printed to I<stdout> by
1798 the command.
1799
1800 If the command returns a non-zero exit status, then
1801 this function returns an error message.  The error message
1802 string is the content of I<stderr> from the command.
1803
1804 The C<$PATH> environment variable will contain at least
1805 C</usr/bin> and C</bin>.  If you require a program from
1806 another location, you should provide the full path in the
1807 first parameter.
1808
1809 Shared libraries and data files required by the program
1810 must be available on filesystems which are mounted in the
1811 correct places.  It is the caller's responsibility to ensure
1812 all filesystems that are needed are mounted at the right
1813 locations.");
1814
1815   ("command_lines", (RStringList "lines", [StringList "arguments"], []), 51, [ProtocolLimitWarning],
1816    [InitBasicFS, Always, TestOutputList (
1817       [["upload"; "test-command"; "/test-command"];
1818        ["chmod"; "0o755"; "/test-command"];
1819        ["command_lines"; "/test-command 1"]], ["Result1"]);
1820     InitBasicFS, Always, TestOutputList (
1821       [["upload"; "test-command"; "/test-command"];
1822        ["chmod"; "0o755"; "/test-command"];
1823        ["command_lines"; "/test-command 2"]], ["Result2"]);
1824     InitBasicFS, Always, TestOutputList (
1825       [["upload"; "test-command"; "/test-command"];
1826        ["chmod"; "0o755"; "/test-command"];
1827        ["command_lines"; "/test-command 3"]], ["";"Result3"]);
1828     InitBasicFS, Always, TestOutputList (
1829       [["upload"; "test-command"; "/test-command"];
1830        ["chmod"; "0o755"; "/test-command"];
1831        ["command_lines"; "/test-command 4"]], ["";"Result4"]);
1832     InitBasicFS, Always, TestOutputList (
1833       [["upload"; "test-command"; "/test-command"];
1834        ["chmod"; "0o755"; "/test-command"];
1835        ["command_lines"; "/test-command 5"]], ["";"Result5";""]);
1836     InitBasicFS, Always, TestOutputList (
1837       [["upload"; "test-command"; "/test-command"];
1838        ["chmod"; "0o755"; "/test-command"];
1839        ["command_lines"; "/test-command 6"]], ["";"";"Result6";""]);
1840     InitBasicFS, Always, TestOutputList (
1841       [["upload"; "test-command"; "/test-command"];
1842        ["chmod"; "0o755"; "/test-command"];
1843        ["command_lines"; "/test-command 7"]], []);
1844     InitBasicFS, Always, TestOutputList (
1845       [["upload"; "test-command"; "/test-command"];
1846        ["chmod"; "0o755"; "/test-command"];
1847        ["command_lines"; "/test-command 8"]], [""]);
1848     InitBasicFS, Always, TestOutputList (
1849       [["upload"; "test-command"; "/test-command"];
1850        ["chmod"; "0o755"; "/test-command"];
1851        ["command_lines"; "/test-command 9"]], ["";""]);
1852     InitBasicFS, Always, TestOutputList (
1853       [["upload"; "test-command"; "/test-command"];
1854        ["chmod"; "0o755"; "/test-command"];
1855        ["command_lines"; "/test-command 10"]], ["Result10-1";"Result10-2"]);
1856     InitBasicFS, Always, TestOutputList (
1857       [["upload"; "test-command"; "/test-command"];
1858        ["chmod"; "0o755"; "/test-command"];
1859        ["command_lines"; "/test-command 11"]], ["Result11-1";"Result11-2"])],
1860    "run a command, returning lines",
1861    "\
1862 This is the same as C<guestfs_command>, but splits the
1863 result into a list of lines.
1864
1865 See also: C<guestfs_sh_lines>");
1866
1867   ("stat", (RStruct ("statbuf", "stat"), [Pathname "path"], []), 52, [],
1868    [InitISOFS, Always, TestOutputStruct (
1869       [["stat"; "/empty"]], [CompareWithInt ("size", 0)])],
1870    "get file information",
1871    "\
1872 Returns file information for the given C<path>.
1873
1874 This is the same as the C<stat(2)> system call.");
1875
1876   ("lstat", (RStruct ("statbuf", "stat"), [Pathname "path"], []), 53, [],
1877    [InitISOFS, Always, TestOutputStruct (
1878       [["lstat"; "/empty"]], [CompareWithInt ("size", 0)])],
1879    "get file information for a symbolic link",
1880    "\
1881 Returns file information for the given C<path>.
1882
1883 This is the same as C<guestfs_stat> except that if C<path>
1884 is a symbolic link, then the link is stat-ed, not the file it
1885 refers to.
1886
1887 This is the same as the C<lstat(2)> system call.");
1888
1889   ("statvfs", (RStruct ("statbuf", "statvfs"), [Pathname "path"], []), 54, [],
1890    [InitISOFS, Always, TestOutputStruct (
1891       [["statvfs"; "/"]], [CompareWithInt ("namemax", 255)])],
1892    "get file system statistics",
1893    "\
1894 Returns file system statistics for any mounted file system.
1895 C<path> should be a file or directory in the mounted file system
1896 (typically it is the mount point itself, but it doesn't need to be).
1897
1898 This is the same as the C<statvfs(2)> system call.");
1899
1900   ("tune2fs_l", (RHashtable "superblock", [Device "device"], []), 55, [],
1901    [], (* XXX test *)
1902    "get ext2/ext3/ext4 superblock details",
1903    "\
1904 This returns the contents of the ext2, ext3 or ext4 filesystem
1905 superblock on C<device>.
1906
1907 It is the same as running C<tune2fs -l device>.  See L<tune2fs(8)>
1908 manpage for more details.  The list of fields returned isn't
1909 clearly defined, and depends on both the version of C<tune2fs>
1910 that libguestfs was built against, and the filesystem itself.");
1911
1912   ("blockdev_setro", (RErr, [Device "device"], []), 56, [],
1913    [InitEmpty, Always, TestOutputTrue (
1914       [["blockdev_setro"; "/dev/sda"];
1915        ["blockdev_getro"; "/dev/sda"]])],
1916    "set block device to read-only",
1917    "\
1918 Sets the block device named C<device> to read-only.
1919
1920 This uses the L<blockdev(8)> command.");
1921
1922   ("blockdev_setrw", (RErr, [Device "device"], []), 57, [],
1923    [InitEmpty, Always, TestOutputFalse (
1924       [["blockdev_setrw"; "/dev/sda"];
1925        ["blockdev_getro"; "/dev/sda"]])],
1926    "set block device to read-write",
1927    "\
1928 Sets the block device named C<device> to read-write.
1929
1930 This uses the L<blockdev(8)> command.");
1931
1932   ("blockdev_getro", (RBool "ro", [Device "device"], []), 58, [],
1933    [InitEmpty, Always, TestOutputTrue (
1934       [["blockdev_setro"; "/dev/sda"];
1935        ["blockdev_getro"; "/dev/sda"]])],
1936    "is block device set to read-only",
1937    "\
1938 Returns a boolean indicating if the block device is read-only
1939 (true if read-only, false if not).
1940
1941 This uses the L<blockdev(8)> command.");
1942
1943   ("blockdev_getss", (RInt "sectorsize", [Device "device"], []), 59, [],
1944    [InitEmpty, Always, TestOutputInt (
1945       [["blockdev_getss"; "/dev/sda"]], 512)],
1946    "get sectorsize of block device",
1947    "\
1948 This returns the size of sectors on a block device.
1949 Usually 512, but can be larger for modern devices.
1950
1951 (Note, this is not the size in sectors, use C<guestfs_blockdev_getsz>
1952 for that).
1953
1954 This uses the L<blockdev(8)> command.");
1955
1956   ("blockdev_getbsz", (RInt "blocksize", [Device "device"], []), 60, [],
1957    [InitEmpty, Always, TestOutputInt (
1958       [["blockdev_getbsz"; "/dev/sda"]], 4096)],
1959    "get blocksize of block device",
1960    "\
1961 This returns the block size of a device.
1962
1963 (Note this is different from both I<size in blocks> and
1964 I<filesystem block size>).
1965
1966 This uses the L<blockdev(8)> command.");
1967
1968   ("blockdev_setbsz", (RErr, [Device "device"; Int "blocksize"], []), 61, [],
1969    [], (* XXX test *)
1970    "set blocksize of block device",
1971    "\
1972 This sets the block size of a device.
1973
1974 (Note this is different from both I<size in blocks> and
1975 I<filesystem block size>).
1976
1977 This uses the L<blockdev(8)> command.");
1978
1979   ("blockdev_getsz", (RInt64 "sizeinsectors", [Device "device"], []), 62, [],
1980    [InitEmpty, Always, TestOutputInt (
1981       [["blockdev_getsz"; "/dev/sda"]], 1024000)],
1982    "get total size of device in 512-byte sectors",
1983    "\
1984 This returns the size of the device in units of 512-byte sectors
1985 (even if the sectorsize isn't 512 bytes ... weird).
1986
1987 See also C<guestfs_blockdev_getss> for the real sector size of
1988 the device, and C<guestfs_blockdev_getsize64> for the more
1989 useful I<size in bytes>.
1990
1991 This uses the L<blockdev(8)> command.");
1992
1993   ("blockdev_getsize64", (RInt64 "sizeinbytes", [Device "device"], []), 63, [],
1994    [InitEmpty, Always, TestOutputInt (
1995       [["blockdev_getsize64"; "/dev/sda"]], 524288000)],
1996    "get total size of device in bytes",
1997    "\
1998 This returns the size of the device in bytes.
1999
2000 See also C<guestfs_blockdev_getsz>.
2001
2002 This uses the L<blockdev(8)> command.");
2003
2004   ("blockdev_flushbufs", (RErr, [Device "device"], []), 64, [],
2005    [InitEmpty, Always, TestRun
2006       [["blockdev_flushbufs"; "/dev/sda"]]],
2007    "flush device buffers",
2008    "\
2009 This tells the kernel to flush internal buffers associated
2010 with C<device>.
2011
2012 This uses the L<blockdev(8)> command.");
2013
2014   ("blockdev_rereadpt", (RErr, [Device "device"], []), 65, [],
2015    [InitEmpty, Always, TestRun
2016       [["blockdev_rereadpt"; "/dev/sda"]]],
2017    "reread partition table",
2018    "\
2019 Reread the partition table on C<device>.
2020
2021 This uses the L<blockdev(8)> command.");
2022
2023   ("upload", (RErr, [FileIn "filename"; Dev_or_Path "remotefilename"], []), 66, [],
2024    [InitBasicFS, Always, TestOutput (
2025       (* Pick a file from cwd which isn't likely to change. *)
2026       [["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
2027        ["checksum"; "md5"; "/COPYING.LIB"]],
2028       Digest.to_hex (Digest.file "COPYING.LIB"))],
2029    "upload a file from the local machine",
2030    "\
2031 Upload local file C<filename> to C<remotefilename> on the
2032 filesystem.
2033
2034 C<filename> can also be a named pipe.
2035
2036 See also C<guestfs_download>.");
2037
2038   ("download", (RErr, [Dev_or_Path "remotefilename"; FileOut "filename"], []), 67, [Progress],
2039    [InitBasicFS, Always, TestOutput (
2040       (* Pick a file from cwd which isn't likely to change. *)
2041       [["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
2042        ["download"; "/COPYING.LIB"; "testdownload.tmp"];
2043        ["upload"; "testdownload.tmp"; "/upload"];
2044        ["checksum"; "md5"; "/upload"]],
2045       Digest.to_hex (Digest.file "COPYING.LIB"))],
2046    "download a file to the local machine",
2047    "\
2048 Download file C<remotefilename> and save it as C<filename>
2049 on the local machine.
2050
2051 C<filename> can also be a named pipe.
2052
2053 See also C<guestfs_upload>, C<guestfs_cat>.");
2054
2055   ("checksum", (RString "checksum", [String "csumtype"; Pathname "path"], []), 68, [],
2056    [InitISOFS, Always, TestOutput (
2057       [["checksum"; "crc"; "/known-3"]], "2891671662");
2058     InitISOFS, Always, TestLastFail (
2059       [["checksum"; "crc"; "/notexists"]]);
2060     InitISOFS, Always, TestOutput (
2061       [["checksum"; "md5"; "/known-3"]], "46d6ca27ee07cdc6fa99c2e138cc522c");
2062     InitISOFS, Always, TestOutput (
2063       [["checksum"; "sha1"; "/known-3"]], "b7ebccc3ee418311091c3eda0a45b83c0a770f15");
2064     InitISOFS, Always, TestOutput (
2065       [["checksum"; "sha224"; "/known-3"]], "d2cd1774b28f3659c14116be0a6dc2bb5c4b350ce9cd5defac707741");
2066     InitISOFS, Always, TestOutput (
2067       [["checksum"; "sha256"; "/known-3"]], "75bb71b90cd20cb13f86d2bea8dad63ac7194e7517c3b52b8d06ff52d3487d30");
2068     InitISOFS, Always, TestOutput (
2069       [["checksum"; "sha384"; "/known-3"]], "5fa7883430f357b5d7b7271d3a1d2872b51d73cba72731de6863d3dea55f30646af2799bef44d5ea776a5ec7941ac640");
2070     InitISOFS, Always, TestOutput (
2071       [["checksum"; "sha512"; "/known-3"]], "2794062c328c6b216dca90443b7f7134c5f40e56bd0ed7853123275a09982a6f992e6ca682f9d2fba34a4c5e870d8fe077694ff831e3032a004ee077e00603f6");
2072     (* Test for RHBZ#579608, absolute symbolic links. *)
2073     InitISOFS, Always, TestOutput (
2074       [["checksum"; "sha512"; "/abssymlink"]], "5f57d0639bc95081c53afc63a449403883818edc64da48930ad6b1a4fb49be90404686877743fbcd7c99811f3def7df7bc22635c885c6a8cf79c806b43451c1a")],
2075    "compute MD5, SHAx or CRC checksum of file",
2076    "\
2077 This call computes the MD5, SHAx or CRC checksum of the
2078 file named C<path>.
2079
2080 The type of checksum to compute is given by the C<csumtype>
2081 parameter which must have one of the following values:
2082
2083 =over 4
2084
2085 =item C<crc>
2086
2087 Compute the cyclic redundancy check (CRC) specified by POSIX
2088 for the C<cksum> command.
2089
2090 =item C<md5>
2091
2092 Compute the MD5 hash (using the C<md5sum> program).
2093
2094 =item C<sha1>
2095
2096 Compute the SHA1 hash (using the C<sha1sum> program).
2097
2098 =item C<sha224>
2099
2100 Compute the SHA224 hash (using the C<sha224sum> program).
2101
2102 =item C<sha256>
2103
2104 Compute the SHA256 hash (using the C<sha256sum> program).
2105
2106 =item C<sha384>
2107
2108 Compute the SHA384 hash (using the C<sha384sum> program).
2109
2110 =item C<sha512>
2111
2112 Compute the SHA512 hash (using the C<sha512sum> program).
2113
2114 =back
2115
2116 The checksum is returned as a printable string.
2117
2118 To get the checksum for a device, use C<guestfs_checksum_device>.
2119
2120 To get the checksums for many files, use C<guestfs_checksums_out>.");
2121
2122   ("tar_in", (RErr, [FileIn "tarfile"; Pathname "directory"], []), 69, [],
2123    [InitBasicFS, Always, TestOutput (
2124       [["tar_in"; "../images/helloworld.tar"; "/"];
2125        ["cat"; "/hello"]], "hello\n")],
2126    "unpack tarfile to directory",
2127    "\
2128 This command uploads and unpacks local file C<tarfile> (an
2129 I<uncompressed> tar file) into C<directory>.
2130
2131 To upload a compressed tarball, use C<guestfs_tgz_in>
2132 or C<guestfs_txz_in>.");
2133
2134   ("tar_out", (RErr, [String "directory"; FileOut "tarfile"], []), 70, [],
2135    [],
2136    "pack directory into tarfile",
2137    "\
2138 This command packs the contents of C<directory> and downloads
2139 it to local file C<tarfile>.
2140
2141 To download a compressed tarball, use C<guestfs_tgz_out>
2142 or C<guestfs_txz_out>.");
2143
2144   ("tgz_in", (RErr, [FileIn "tarball"; Pathname "directory"], []), 71, [],
2145    [InitBasicFS, Always, TestOutput (
2146       [["tgz_in"; "../images/helloworld.tar.gz"; "/"];
2147        ["cat"; "/hello"]], "hello\n")],
2148    "unpack compressed tarball to directory",
2149    "\
2150 This command uploads and unpacks local file C<tarball> (a
2151 I<gzip compressed> tar file) into C<directory>.
2152
2153 To upload an uncompressed tarball, use C<guestfs_tar_in>.");
2154
2155   ("tgz_out", (RErr, [Pathname "directory"; FileOut "tarball"], []), 72, [],
2156    [],
2157    "pack directory into compressed tarball",
2158    "\
2159 This command packs the contents of C<directory> and downloads
2160 it to local file C<tarball>.
2161
2162 To download an uncompressed tarball, use C<guestfs_tar_out>.");
2163
2164   ("mount_ro", (RErr, [Device "device"; String "mountpoint"], []), 73, [],
2165    [InitBasicFS, Always, TestLastFail (
2166       [["umount"; "/"];
2167        ["mount_ro"; "/dev/sda1"; "/"];
2168        ["touch"; "/new"]]);
2169     InitBasicFS, Always, TestOutput (
2170       [["write"; "/new"; "data"];
2171        ["umount"; "/"];
2172        ["mount_ro"; "/dev/sda1"; "/"];
2173        ["cat"; "/new"]], "data")],
2174    "mount a guest disk, read-only",
2175    "\
2176 This is the same as the C<guestfs_mount> command, but it
2177 mounts the filesystem with the read-only (I<-o ro>) flag.");
2178
2179   ("mount_options", (RErr, [String "options"; Device "device"; String "mountpoint"], []), 74, [],
2180    [],
2181    "mount a guest disk with mount options",
2182    "\
2183 This is the same as the C<guestfs_mount> command, but it
2184 allows you to set the mount options as for the
2185 L<mount(8)> I<-o> flag.
2186
2187 If the C<options> parameter is an empty string, then
2188 no options are passed (all options default to whatever
2189 the filesystem uses).");
2190
2191   ("mount_vfs", (RErr, [String "options"; String "vfstype"; Device "device"; String "mountpoint"], []), 75, [],
2192    [],
2193    "mount a guest disk with mount options and vfstype",
2194    "\
2195 This is the same as the C<guestfs_mount> command, but it
2196 allows you to set both the mount options and the vfstype
2197 as for the L<mount(8)> I<-o> and I<-t> flags.");
2198
2199   ("debug", (RString "result", [String "subcmd"; StringList "extraargs"], []), 76, [],
2200    [],
2201    "debugging and internals",
2202    "\
2203 The C<guestfs_debug> command exposes some internals of
2204 C<guestfsd> (the guestfs daemon) that runs inside the
2205 qemu subprocess.
2206
2207 There is no comprehensive help for this command.  You have
2208 to look at the file C<daemon/debug.c> in the libguestfs source
2209 to find out what you can do.");
2210
2211   ("lvremove", (RErr, [Device "device"], []), 77, [Optional "lvm2"],
2212    [InitEmpty, Always, TestOutputList (
2213       [["part_disk"; "/dev/sda"; "mbr"];
2214        ["pvcreate"; "/dev/sda1"];
2215        ["vgcreate"; "VG"; "/dev/sda1"];
2216        ["lvcreate"; "LV1"; "VG"; "50"];
2217        ["lvcreate"; "LV2"; "VG"; "50"];
2218        ["lvremove"; "/dev/VG/LV1"];
2219        ["lvs"]], ["/dev/VG/LV2"]);
2220     InitEmpty, Always, TestOutputList (
2221       [["part_disk"; "/dev/sda"; "mbr"];
2222        ["pvcreate"; "/dev/sda1"];
2223        ["vgcreate"; "VG"; "/dev/sda1"];
2224        ["lvcreate"; "LV1"; "VG"; "50"];
2225        ["lvcreate"; "LV2"; "VG"; "50"];
2226        ["lvremove"; "/dev/VG"];
2227        ["lvs"]], []);
2228     InitEmpty, Always, TestOutputList (
2229       [["part_disk"; "/dev/sda"; "mbr"];
2230        ["pvcreate"; "/dev/sda1"];
2231        ["vgcreate"; "VG"; "/dev/sda1"];
2232        ["lvcreate"; "LV1"; "VG"; "50"];
2233        ["lvcreate"; "LV2"; "VG"; "50"];
2234        ["lvremove"; "/dev/VG"];
2235        ["vgs"]], ["VG"])],
2236    "remove an LVM logical volume",
2237    "\
2238 Remove an LVM logical volume C<device>, where C<device> is
2239 the path to the LV, such as C</dev/VG/LV>.
2240
2241 You can also remove all LVs in a volume group by specifying
2242 the VG name, C</dev/VG>.");
2243
2244   ("vgremove", (RErr, [String "vgname"], []), 78, [Optional "lvm2"],
2245    [InitEmpty, Always, TestOutputList (
2246       [["part_disk"; "/dev/sda"; "mbr"];
2247        ["pvcreate"; "/dev/sda1"];
2248        ["vgcreate"; "VG"; "/dev/sda1"];
2249        ["lvcreate"; "LV1"; "VG"; "50"];
2250        ["lvcreate"; "LV2"; "VG"; "50"];
2251        ["vgremove"; "VG"];
2252        ["lvs"]], []);
2253     InitEmpty, Always, TestOutputList (
2254       [["part_disk"; "/dev/sda"; "mbr"];
2255        ["pvcreate"; "/dev/sda1"];
2256        ["vgcreate"; "VG"; "/dev/sda1"];
2257        ["lvcreate"; "LV1"; "VG"; "50"];
2258        ["lvcreate"; "LV2"; "VG"; "50"];
2259        ["vgremove"; "VG"];
2260        ["vgs"]], [])],
2261    "remove an LVM volume group",
2262    "\
2263 Remove an LVM volume group C<vgname>, (for example C<VG>).
2264
2265 This also forcibly removes all logical volumes in the volume
2266 group (if any).");
2267
2268   ("pvremove", (RErr, [Device "device"], []), 79, [Optional "lvm2"],
2269    [InitEmpty, Always, TestOutputListOfDevices (
2270       [["part_disk"; "/dev/sda"; "mbr"];
2271        ["pvcreate"; "/dev/sda1"];
2272        ["vgcreate"; "VG"; "/dev/sda1"];
2273        ["lvcreate"; "LV1"; "VG"; "50"];
2274        ["lvcreate"; "LV2"; "VG"; "50"];
2275        ["vgremove"; "VG"];
2276        ["pvremove"; "/dev/sda1"];
2277        ["lvs"]], []);
2278     InitEmpty, Always, TestOutputListOfDevices (
2279       [["part_disk"; "/dev/sda"; "mbr"];
2280        ["pvcreate"; "/dev/sda1"];
2281        ["vgcreate"; "VG"; "/dev/sda1"];
2282        ["lvcreate"; "LV1"; "VG"; "50"];
2283        ["lvcreate"; "LV2"; "VG"; "50"];
2284        ["vgremove"; "VG"];
2285        ["pvremove"; "/dev/sda1"];
2286        ["vgs"]], []);
2287     InitEmpty, Always, TestOutputListOfDevices (
2288       [["part_disk"; "/dev/sda"; "mbr"];
2289        ["pvcreate"; "/dev/sda1"];
2290        ["vgcreate"; "VG"; "/dev/sda1"];
2291        ["lvcreate"; "LV1"; "VG"; "50"];
2292        ["lvcreate"; "LV2"; "VG"; "50"];
2293        ["vgremove"; "VG"];
2294        ["pvremove"; "/dev/sda1"];
2295        ["pvs"]], [])],
2296    "remove an LVM physical volume",
2297    "\
2298 This wipes a physical volume C<device> so that LVM will no longer
2299 recognise it.
2300
2301 The implementation uses the C<pvremove> command which refuses to
2302 wipe physical volumes that contain any volume groups, so you have
2303 to remove those first.");
2304
2305   ("set_e2label", (RErr, [Device "device"; String "label"], []), 80, [],
2306    [InitBasicFS, Always, TestOutput (
2307       [["set_e2label"; "/dev/sda1"; "testlabel"];
2308        ["get_e2label"; "/dev/sda1"]], "testlabel")],
2309    "set the ext2/3/4 filesystem label",
2310    "\
2311 This sets the ext2/3/4 filesystem label of the filesystem on
2312 C<device> to C<label>.  Filesystem labels are limited to
2313 16 characters.
2314
2315 You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2label>
2316 to return the existing label on a filesystem.");
2317
2318   ("get_e2label", (RString "label", [Device "device"], []), 81, [DeprecatedBy "vfs_label"],
2319    [],
2320    "get the ext2/3/4 filesystem label",
2321    "\
2322 This returns the ext2/3/4 filesystem label of the filesystem on
2323 C<device>.");
2324
2325   ("set_e2uuid", (RErr, [Device "device"; String "uuid"], []), 82, [],
2326    (let uuid = uuidgen () in
2327     [InitBasicFS, Always, TestOutput (
2328        [["set_e2uuid"; "/dev/sda1"; uuid];
2329         ["get_e2uuid"; "/dev/sda1"]], uuid);
2330      InitBasicFS, Always, TestOutput (
2331        [["set_e2uuid"; "/dev/sda1"; "clear"];
2332         ["get_e2uuid"; "/dev/sda1"]], "");
2333      (* We can't predict what UUIDs will be, so just check the commands run. *)
2334      InitBasicFS, Always, TestRun (
2335        [["set_e2uuid"; "/dev/sda1"; "random"]]);
2336      InitBasicFS, Always, TestRun (
2337        [["set_e2uuid"; "/dev/sda1"; "time"]])]),
2338    "set the ext2/3/4 filesystem UUID",
2339    "\
2340 This sets the ext2/3/4 filesystem UUID of the filesystem on
2341 C<device> to C<uuid>.  The format of the UUID and alternatives
2342 such as C<clear>, C<random> and C<time> are described in the
2343 L<tune2fs(8)> manpage.
2344
2345 You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2uuid>
2346 to return the existing UUID of a filesystem.");
2347
2348   ("get_e2uuid", (RString "uuid", [Device "device"], []), 83, [DeprecatedBy "vfs_uuid"],
2349    (* Regression test for RHBZ#597112. *)
2350    (let uuid = uuidgen () in
2351     [InitBasicFS, Always, TestOutput (
2352        [["mke2journal"; "1024"; "/dev/sdb"];
2353         ["set_e2uuid"; "/dev/sdb"; uuid];
2354         ["get_e2uuid"; "/dev/sdb"]], uuid)]),
2355    "get the ext2/3/4 filesystem UUID",
2356    "\
2357 This returns the ext2/3/4 filesystem UUID of the filesystem on
2358 C<device>.");
2359
2360   ("fsck", (RInt "status", [String "fstype"; Device "device"], []), 84, [FishOutput FishOutputHexadecimal],
2361    [InitBasicFS, Always, TestOutputInt (
2362       [["umount"; "/dev/sda1"];
2363        ["fsck"; "ext2"; "/dev/sda1"]], 0);
2364     InitBasicFS, Always, TestOutputInt (
2365       [["umount"; "/dev/sda1"];
2366        ["zero"; "/dev/sda1"];
2367        ["fsck"; "ext2"; "/dev/sda1"]], 8)],
2368    "run the filesystem checker",
2369    "\
2370 This runs the filesystem checker (fsck) on C<device> which
2371 should have filesystem type C<fstype>.
2372
2373 The returned integer is the status.  See L<fsck(8)> for the
2374 list of status codes from C<fsck>.
2375
2376 Notes:
2377
2378 =over 4
2379
2380 =item *
2381
2382 Multiple status codes can be summed together.
2383
2384 =item *
2385
2386 A non-zero return code can mean \"success\", for example if
2387 errors have been corrected on the filesystem.
2388
2389 =item *
2390
2391 Checking or repairing NTFS volumes is not supported
2392 (by linux-ntfs).
2393
2394 =back
2395
2396 This command is entirely equivalent to running C<fsck -a -t fstype device>.");
2397
2398   ("zero", (RErr, [Device "device"], []), 85, [Progress],
2399    [InitBasicFS, Always, TestOutput (
2400       [["umount"; "/dev/sda1"];
2401        ["zero"; "/dev/sda1"];
2402        ["file"; "/dev/sda1"]], "data")],
2403    "write zeroes to the device",
2404    "\
2405 This command writes zeroes over the first few blocks of C<device>.
2406
2407 How many blocks are zeroed isn't specified (but it's I<not> enough
2408 to securely wipe the device).  It should be sufficient to remove
2409 any partition tables, filesystem superblocks and so on.
2410
2411 See also: C<guestfs_zero_device>, C<guestfs_scrub_device>.");
2412
2413   ("grub_install", (RErr, [Pathname "root"; Device "device"], []), 86, [],
2414    (* See:
2415     * https://bugzilla.redhat.com/show_bug.cgi?id=484986
2416     * https://bugzilla.redhat.com/show_bug.cgi?id=479760
2417     *)
2418    [InitBasicFS, Always, TestOutputTrue (
2419       [["mkdir_p"; "/boot/grub"];
2420        ["write"; "/boot/grub/device.map"; "(hd0) /dev/vda"];
2421        ["grub_install"; "/"; "/dev/vda"];
2422        ["is_dir"; "/boot"]])],
2423    "install GRUB",
2424    "\
2425 This command installs GRUB (the Grand Unified Bootloader) on
2426 C<device>, with the root directory being C<root>.
2427
2428 Note: If grub-install reports the error
2429 \"No suitable drive was found in the generated device map.\"
2430 it may be that you need to create a C</boot/grub/device.map>
2431 file first that contains the mapping between grub device names
2432 and Linux device names.  It is usually sufficient to create
2433 a file containing:
2434
2435  (hd0) /dev/vda
2436
2437 replacing C</dev/vda> with the name of the installation device.");
2438
2439   ("cp", (RErr, [Pathname "src"; Pathname "dest"], []), 87, [],
2440    [InitBasicFS, Always, TestOutput (
2441       [["write"; "/old"; "file content"];
2442        ["cp"; "/old"; "/new"];
2443        ["cat"; "/new"]], "file content");
2444     InitBasicFS, Always, TestOutputTrue (
2445       [["write"; "/old"; "file content"];
2446        ["cp"; "/old"; "/new"];
2447        ["is_file"; "/old"]]);
2448     InitBasicFS, Always, TestOutput (
2449       [["write"; "/old"; "file content"];
2450        ["mkdir"; "/dir"];
2451        ["cp"; "/old"; "/dir/new"];
2452        ["cat"; "/dir/new"]], "file content")],
2453    "copy a file",
2454    "\
2455 This copies a file from C<src> to C<dest> where C<dest> is
2456 either a destination filename or destination directory.");
2457
2458   ("cp_a", (RErr, [Pathname "src"; Pathname "dest"], []), 88, [],
2459    [InitBasicFS, Always, TestOutput (
2460       [["mkdir"; "/olddir"];
2461        ["mkdir"; "/newdir"];
2462        ["write"; "/olddir/file"; "file content"];
2463        ["cp_a"; "/olddir"; "/newdir"];
2464        ["cat"; "/newdir/olddir/file"]], "file content")],
2465    "copy a file or directory recursively",
2466    "\
2467 This copies a file or directory from C<src> to C<dest>
2468 recursively using the C<cp -a> command.");
2469
2470   ("mv", (RErr, [Pathname "src"; Pathname "dest"], []), 89, [],
2471    [InitBasicFS, Always, TestOutput (
2472       [["write"; "/old"; "file content"];
2473        ["mv"; "/old"; "/new"];
2474        ["cat"; "/new"]], "file content");
2475     InitBasicFS, Always, TestOutputFalse (
2476       [["write"; "/old"; "file content"];
2477        ["mv"; "/old"; "/new"];
2478        ["is_file"; "/old"]])],
2479    "move a file",
2480    "\
2481 This moves a file from C<src> to C<dest> where C<dest> is
2482 either a destination filename or destination directory.");
2483
2484   ("drop_caches", (RErr, [Int "whattodrop"], []), 90, [],
2485    [InitEmpty, Always, TestRun (
2486       [["drop_caches"; "3"]])],
2487    "drop kernel page cache, dentries and inodes",
2488    "\
2489 This instructs the guest kernel to drop its page cache,
2490 and/or dentries and inode caches.  The parameter C<whattodrop>
2491 tells the kernel what precisely to drop, see
2492 L<http://linux-mm.org/Drop_Caches>
2493
2494 Setting C<whattodrop> to 3 should drop everything.
2495
2496 This automatically calls L<sync(2)> before the operation,
2497 so that the maximum guest memory is freed.");
2498
2499   ("dmesg", (RString "kmsgs", [], []), 91, [],
2500    [InitEmpty, Always, TestRun (
2501       [["dmesg"]])],
2502    "return kernel messages",
2503    "\
2504 This returns the kernel messages (C<dmesg> output) from
2505 the guest kernel.  This is sometimes useful for extended
2506 debugging of problems.
2507
2508 Another way to get the same information is to enable
2509 verbose messages with C<guestfs_set_verbose> or by setting
2510 the environment variable C<LIBGUESTFS_DEBUG=1> before
2511 running the program.");
2512
2513   ("ping_daemon", (RErr, [], []), 92, [],
2514    [InitEmpty, Always, TestRun (
2515       [["ping_daemon"]])],
2516    "ping the guest daemon",
2517    "\
2518 This is a test probe into the guestfs daemon running inside
2519 the qemu subprocess.  Calling this function checks that the
2520 daemon responds to the ping message, without affecting the daemon
2521 or attached block device(s) in any other way.");
2522
2523   ("equal", (RBool "equality", [Pathname "file1"; Pathname "file2"], []), 93, [],
2524    [InitBasicFS, Always, TestOutputTrue (
2525       [["write"; "/file1"; "contents of a file"];
2526        ["cp"; "/file1"; "/file2"];
2527        ["equal"; "/file1"; "/file2"]]);
2528     InitBasicFS, Always, TestOutputFalse (
2529       [["write"; "/file1"; "contents of a file"];
2530        ["write"; "/file2"; "contents of another file"];
2531        ["equal"; "/file1"; "/file2"]]);
2532     InitBasicFS, Always, TestLastFail (
2533       [["equal"; "/file1"; "/file2"]])],
2534    "test if two files have equal contents",
2535    "\
2536 This compares the two files C<file1> and C<file2> and returns
2537 true if their content is exactly equal, or false otherwise.
2538
2539 The external L<cmp(1)> program is used for the comparison.");
2540
2541   ("strings", (RStringList "stringsout", [Pathname "path"], []), 94, [ProtocolLimitWarning],
2542    [InitISOFS, Always, TestOutputList (
2543       [["strings"; "/known-5"]], ["abcdefghi"; "jklmnopqr"]);
2544     InitISOFS, Always, TestOutputList (
2545       [["strings"; "/empty"]], []);
2546     (* Test for RHBZ#579608, absolute symbolic links. *)
2547     InitISOFS, Always, TestRun (
2548       [["strings"; "/abssymlink"]])],
2549    "print the printable strings in a file",
2550    "\
2551 This runs the L<strings(1)> command on a file and returns
2552 the list of printable strings found.");
2553
2554   ("strings_e", (RStringList "stringsout", [String "encoding"; Pathname "path"], []), 95, [ProtocolLimitWarning],
2555    [InitISOFS, Always, TestOutputList (
2556       [["strings_e"; "b"; "/known-5"]], []);
2557     InitBasicFS, Always, TestOutputList (
2558       [["write"; "/new"; "\000h\000e\000l\000l\000o\000\n\000w\000o\000r\000l\000d\000\n"];
2559        ["strings_e"; "b"; "/new"]], ["hello"; "world"])],
2560    "print the printable strings in a file",
2561    "\
2562 This is like the C<guestfs_strings> command, but allows you to
2563 specify the encoding of strings that are looked for in
2564 the source file C<path>.
2565
2566 Allowed encodings are:
2567
2568 =over 4
2569
2570 =item s
2571
2572 Single 7-bit-byte characters like ASCII and the ASCII-compatible
2573 parts of ISO-8859-X (this is what C<guestfs_strings> uses).
2574
2575 =item S
2576
2577 Single 8-bit-byte characters.
2578
2579 =item b
2580
2581 16-bit big endian strings such as those encoded in
2582 UTF-16BE or UCS-2BE.
2583
2584 =item l (lower case letter L)
2585
2586 16-bit little endian such as UTF-16LE and UCS-2LE.
2587 This is useful for examining binaries in Windows guests.
2588
2589 =item B
2590
2591 32-bit big endian such as UCS-4BE.
2592
2593 =item L
2594
2595 32-bit little endian such as UCS-4LE.
2596
2597 =back
2598
2599 The returned strings are transcoded to UTF-8.");
2600
2601   ("hexdump", (RString "dump", [Pathname "path"], []), 96, [ProtocolLimitWarning],
2602    [InitISOFS, Always, TestOutput (
2603       [["hexdump"; "/known-4"]], "00000000  61 62 63 0a 64 65 66 0a  67 68 69                 |abc.def.ghi|\n0000000b\n");
2604     (* Test for RHBZ#501888c2 regression which caused large hexdump
2605      * commands to segfault.
2606      *)
2607     InitISOFS, Always, TestRun (
2608       [["hexdump"; "/100krandom"]]);
2609     (* Test for RHBZ#579608, absolute symbolic links. *)
2610     InitISOFS, Always, TestRun (
2611       [["hexdump"; "/abssymlink"]])],
2612    "dump a file in hexadecimal",
2613    "\
2614 This runs C<hexdump -C> on the given C<path>.  The result is
2615 the human-readable, canonical hex dump of the file.");
2616
2617   ("zerofree", (RErr, [Device "device"], []), 97, [Optional "zerofree"],
2618    [InitNone, Always, TestOutput (
2619       [["part_disk"; "/dev/sda"; "mbr"];
2620        ["mkfs"; "ext3"; "/dev/sda1"];
2621        ["mount_options"; ""; "/dev/sda1"; "/"];
2622        ["write"; "/new"; "test file"];
2623        ["umount"; "/dev/sda1"];
2624        ["zerofree"; "/dev/sda1"];
2625        ["mount_options"; ""; "/dev/sda1"; "/"];
2626        ["cat"; "/new"]], "test file")],
2627    "zero unused inodes and disk blocks on ext2/3 filesystem",
2628    "\
2629 This runs the I<zerofree> program on C<device>.  This program
2630 claims to zero unused inodes and disk blocks on an ext2/3
2631 filesystem, thus making it possible to compress the filesystem
2632 more effectively.
2633
2634 You should B<not> run this program if the filesystem is
2635 mounted.
2636
2637 It is possible that using this program can damage the filesystem
2638 or data on the filesystem.");
2639
2640   ("pvresize", (RErr, [Device "device"], []), 98, [Optional "lvm2"],
2641    [],
2642    "resize an LVM physical volume",
2643    "\
2644 This resizes (expands or shrinks) an existing LVM physical
2645 volume to match the new size of the underlying device.");
2646
2647   ("sfdisk_N", (RErr, [Device "device"; Int "partnum";
2648                        Int "cyls"; Int "heads"; Int "sectors";
2649                        String "line"], []), 99, [DangerWillRobinson],
2650    [],
2651    "modify a single partition on a block device",
2652    "\
2653 This runs L<sfdisk(8)> option to modify just the single
2654 partition C<n> (note: C<n> counts from 1).
2655
2656 For other parameters, see C<guestfs_sfdisk>.  You should usually
2657 pass C<0> for the cyls/heads/sectors parameters.
2658
2659 See also: C<guestfs_part_add>");
2660
2661   ("sfdisk_l", (RString "partitions", [Device "device"], []), 100, [],
2662    [],
2663    "display the partition table",
2664    "\
2665 This displays the partition table on C<device>, in the
2666 human-readable output of the L<sfdisk(8)> command.  It is
2667 not intended to be parsed.
2668
2669 See also: C<guestfs_part_list>");
2670
2671   ("sfdisk_kernel_geometry", (RString "partitions", [Device "device"], []), 101, [],
2672    [],
2673    "display the kernel geometry",
2674    "\
2675 This displays the kernel's idea of the geometry of C<device>.
2676
2677 The result is in human-readable format, and not designed to
2678 be parsed.");
2679
2680   ("sfdisk_disk_geometry", (RString "partitions", [Device "device"], []), 102, [],
2681    [],
2682    "display the disk geometry from the partition table",
2683    "\
2684 This displays the disk geometry of C<device> read from the
2685 partition table.  Especially in the case where the underlying
2686 block device has been resized, this can be different from the
2687 kernel's idea of the geometry (see C<guestfs_sfdisk_kernel_geometry>).
2688
2689 The result is in human-readable format, and not designed to
2690 be parsed.");
2691
2692   ("vg_activate_all", (RErr, [Bool "activate"], []), 103, [Optional "lvm2"],
2693    [],
2694    "activate or deactivate all volume groups",
2695    "\
2696 This command activates or (if C<activate> is false) deactivates
2697 all logical volumes in all volume groups.
2698 If activated, then they are made known to the
2699 kernel, ie. they appear as C</dev/mapper> devices.  If deactivated,
2700 then those devices disappear.
2701
2702 This command is the same as running C<vgchange -a y|n>");
2703
2704   ("vg_activate", (RErr, [Bool "activate"; StringList "volgroups"], []), 104, [Optional "lvm2"],
2705    [],
2706    "activate or deactivate some volume groups",
2707    "\
2708 This command activates or (if C<activate> is false) deactivates
2709 all logical volumes in the listed volume groups C<volgroups>.
2710 If activated, then they are made known to the
2711 kernel, ie. they appear as C</dev/mapper> devices.  If deactivated,
2712 then those devices disappear.
2713
2714 This command is the same as running C<vgchange -a y|n volgroups...>
2715
2716 Note that if C<volgroups> is an empty list then B<all> volume groups
2717 are activated or deactivated.");
2718
2719   ("lvresize", (RErr, [Device "device"; Int "mbytes"], []), 105, [Optional "lvm2"],
2720    [InitNone, Always, TestOutput (
2721       [["part_disk"; "/dev/sda"; "mbr"];
2722        ["pvcreate"; "/dev/sda1"];
2723        ["vgcreate"; "VG"; "/dev/sda1"];
2724        ["lvcreate"; "LV"; "VG"; "10"];
2725        ["mkfs"; "ext2"; "/dev/VG/LV"];
2726        ["mount_options"; ""; "/dev/VG/LV"; "/"];
2727        ["write"; "/new"; "test content"];
2728        ["umount"; "/"];
2729        ["lvresize"; "/dev/VG/LV"; "20"];
2730        ["e2fsck_f"; "/dev/VG/LV"];
2731        ["resize2fs"; "/dev/VG/LV"];
2732        ["mount_options"; ""; "/dev/VG/LV"; "/"];
2733        ["cat"; "/new"]], "test content");
2734     InitNone, Always, TestRun (
2735       (* Make an LV smaller to test RHBZ#587484. *)
2736       [["part_disk"; "/dev/sda"; "mbr"];
2737        ["pvcreate"; "/dev/sda1"];
2738        ["vgcreate"; "VG"; "/dev/sda1"];
2739        ["lvcreate"; "LV"; "VG"; "20"];
2740        ["lvresize"; "/dev/VG/LV"; "10"]])],
2741    "resize an LVM logical volume",
2742    "\
2743 This resizes (expands or shrinks) an existing LVM logical
2744 volume to C<mbytes>.  When reducing, data in the reduced part
2745 is lost.");
2746
2747   ("resize2fs", (RErr, [Device "device"], []), 106, [],
2748    [], (* lvresize tests this *)
2749    "resize an ext2, ext3 or ext4 filesystem",
2750    "\
2751 This resizes an ext2, ext3 or ext4 filesystem to match the size of
2752 the underlying device.
2753
2754 I<Note:> It is sometimes required that you run C<guestfs_e2fsck_f>
2755 on the C<device> before calling this command.  For unknown reasons
2756 C<resize2fs> sometimes gives an error about this and sometimes not.
2757 In any case, it is always safe to call C<guestfs_e2fsck_f> before
2758 calling this function.");
2759
2760   ("find", (RStringList "names", [Pathname "directory"], []), 107, [ProtocolLimitWarning],
2761    [InitBasicFS, Always, TestOutputList (
2762       [["find"; "/"]], ["lost+found"]);
2763     InitBasicFS, Always, TestOutputList (
2764       [["touch"; "/a"];
2765        ["mkdir"; "/b"];
2766        ["touch"; "/b/c"];
2767        ["find"; "/"]], ["a"; "b"; "b/c"; "lost+found"]);
2768     InitBasicFS, Always, TestOutputList (
2769       [["mkdir_p"; "/a/b/c"];
2770        ["touch"; "/a/b/c/d"];
2771        ["find"; "/a/b/"]], ["c"; "c/d"])],
2772    "find all files and directories",
2773    "\
2774 This command lists out all files and directories, recursively,
2775 starting at C<directory>.  It is essentially equivalent to
2776 running the shell command C<find directory -print> but some
2777 post-processing happens on the output, described below.
2778
2779 This returns a list of strings I<without any prefix>.  Thus
2780 if the directory structure was:
2781
2782  /tmp/a
2783  /tmp/b
2784  /tmp/c/d
2785
2786 then the returned list from C<guestfs_find> C</tmp> would be
2787 4 elements:
2788
2789  a
2790  b
2791  c
2792  c/d
2793
2794 If C<directory> is not a directory, then this command returns
2795 an error.
2796
2797 The returned list is sorted.
2798
2799 See also C<guestfs_find0>.");
2800
2801   ("e2fsck_f", (RErr, [Device "device"], []), 108, [],
2802    [], (* lvresize tests this *)
2803    "check an ext2/ext3 filesystem",
2804    "\
2805 This runs C<e2fsck -p -f device>, ie. runs the ext2/ext3
2806 filesystem checker on C<device>, noninteractively (C<-p>),
2807 even if the filesystem appears to be clean (C<-f>).
2808
2809 This command is only needed because of C<guestfs_resize2fs>
2810 (q.v.).  Normally you should use C<guestfs_fsck>.");
2811
2812   ("sleep", (RErr, [Int "secs"], []), 109, [],
2813    [InitNone, Always, TestRun (
2814       [["sleep"; "1"]])],
2815    "sleep for some seconds",
2816    "\
2817 Sleep for C<secs> seconds.");
2818
2819   ("ntfs_3g_probe", (RInt "status", [Bool "rw"; Device "device"], []), 110, [Optional "ntfs3g"],
2820    [InitNone, Always, TestOutputInt (
2821       [["part_disk"; "/dev/sda"; "mbr"];
2822        ["mkfs"; "ntfs"; "/dev/sda1"];
2823        ["ntfs_3g_probe"; "true"; "/dev/sda1"]], 0);
2824     InitNone, Always, TestOutputInt (
2825       [["part_disk"; "/dev/sda"; "mbr"];
2826        ["mkfs"; "ext2"; "/dev/sda1"];
2827        ["ntfs_3g_probe"; "true"; "/dev/sda1"]], 12)],
2828    "probe NTFS volume",
2829    "\
2830 This command runs the L<ntfs-3g.probe(8)> command which probes
2831 an NTFS C<device> for mountability.  (Not all NTFS volumes can
2832 be mounted read-write, and some cannot be mounted at all).
2833
2834 C<rw> is a boolean flag.  Set it to true if you want to test
2835 if the volume can be mounted read-write.  Set it to false if
2836 you want to test if the volume can be mounted read-only.
2837
2838 The return value is an integer which C<0> if the operation
2839 would succeed, or some non-zero value documented in the
2840 L<ntfs-3g.probe(8)> manual page.");
2841
2842   ("sh", (RString "output", [String "command"], []), 111, [],
2843    [], (* XXX needs tests *)
2844    "run a command via the shell",
2845    "\
2846 This call runs a command from the guest filesystem via the
2847 guest's C</bin/sh>.
2848
2849 This is like C<guestfs_command>, but passes the command to:
2850
2851  /bin/sh -c \"command\"
2852
2853 Depending on the guest's shell, this usually results in
2854 wildcards being expanded, shell expressions being interpolated
2855 and so on.
2856
2857 All the provisos about C<guestfs_command> apply to this call.");
2858
2859   ("sh_lines", (RStringList "lines", [String "command"], []), 112, [],
2860    [], (* XXX needs tests *)
2861    "run a command via the shell returning lines",
2862    "\
2863 This is the same as C<guestfs_sh>, but splits the result
2864 into a list of lines.
2865
2866 See also: C<guestfs_command_lines>");
2867
2868   ("glob_expand", (RStringList "paths", [Pathname "pattern"], []), 113, [],
2869    (* Use Pathname here, and hence ABS_PATH (pattern,... in generated
2870     * code in stubs.c, since all valid glob patterns must start with "/".
2871     * There is no concept of "cwd" in libguestfs, hence no "."-relative names.
2872     *)
2873    [InitBasicFS, Always, TestOutputList (
2874       [["mkdir_p"; "/a/b/c"];
2875        ["touch"; "/a/b/c/d"];
2876        ["touch"; "/a/b/c/e"];
2877        ["glob_expand"; "/a/b/c/*"]], ["/a/b/c/d"; "/a/b/c/e"]);
2878     InitBasicFS, Always, TestOutputList (
2879       [["mkdir_p"; "/a/b/c"];
2880        ["touch"; "/a/b/c/d"];
2881        ["touch"; "/a/b/c/e"];
2882        ["glob_expand"; "/a/*/c/*"]], ["/a/b/c/d"; "/a/b/c/e"]);
2883     InitBasicFS, Always, TestOutputList (
2884       [["mkdir_p"; "/a/b/c"];
2885        ["touch"; "/a/b/c/d"];
2886        ["touch"; "/a/b/c/e"];
2887        ["glob_expand"; "/a/*/x/*"]], [])],
2888    "expand a wildcard path",
2889    "\
2890 This command searches for all the pathnames matching
2891 C<pattern> according to the wildcard expansion rules
2892 used by the shell.
2893
2894 If no paths match, then this returns an empty list
2895 (note: not an error).
2896
2897 It is just a wrapper around the C L<glob(3)> function
2898 with flags C<GLOB_MARK|GLOB_BRACE>.
2899 See that manual page for more details.");
2900
2901   ("scrub_device", (RErr, [Device "device"], []), 114, [DangerWillRobinson; Optional "scrub"],
2902    [InitNone, Always, TestRun ( (* use /dev/sdc because it's smaller *)
2903       [["scrub_device"; "/dev/sdc"]])],
2904    "scrub (securely wipe) a device",
2905    "\
2906 This command writes patterns over C<device> to make data retrieval
2907 more difficult.
2908
2909 It is an interface to the L<scrub(1)> program.  See that
2910 manual page for more details.");
2911
2912   ("scrub_file", (RErr, [Pathname "file"], []), 115, [Optional "scrub"],
2913    [InitBasicFS, Always, TestRun (
2914       [["write"; "/file"; "content"];
2915        ["scrub_file"; "/file"]])],
2916    "scrub (securely wipe) a file",
2917    "\
2918 This command writes patterns over a file to make data retrieval
2919 more difficult.
2920
2921 The file is I<removed> after scrubbing.
2922
2923 It is an interface to the L<scrub(1)> program.  See that
2924 manual page for more details.");
2925
2926   ("scrub_freespace", (RErr, [Pathname "dir"], []), 116, [Optional "scrub"],
2927    [], (* XXX needs testing *)
2928    "scrub (securely wipe) free space",
2929    "\
2930 This command creates the directory C<dir> and then fills it
2931 with files until the filesystem is full, and scrubs the files
2932 as for C<guestfs_scrub_file>, and deletes them.
2933 The intention is to scrub any free space on the partition
2934 containing C<dir>.
2935
2936 It is an interface to the L<scrub(1)> program.  See that
2937 manual page for more details.");
2938
2939   ("mkdtemp", (RString "dir", [Pathname "template"], []), 117, [],
2940    [InitBasicFS, Always, TestRun (
2941       [["mkdir"; "/tmp"];
2942        ["mkdtemp"; "/tmp/tmpXXXXXX"]])],
2943    "create a temporary directory",
2944    "\
2945 This command creates a temporary directory.  The
2946 C<template> parameter should be a full pathname for the
2947 temporary directory name with the final six characters being
2948 \"XXXXXX\".
2949
2950 For example: \"/tmp/myprogXXXXXX\" or \"/Temp/myprogXXXXXX\",
2951 the second one being suitable for Windows filesystems.
2952
2953 The name of the temporary directory that was created
2954 is returned.
2955
2956 The temporary directory is created with mode 0700
2957 and is owned by root.
2958
2959 The caller is responsible for deleting the temporary
2960 directory and its contents after use.
2961
2962 See also: L<mkdtemp(3)>");
2963
2964   ("wc_l", (RInt "lines", [Pathname "path"], []), 118, [],
2965    [InitISOFS, Always, TestOutputInt (
2966       [["wc_l"; "/10klines"]], 10000);
2967     (* Test for RHBZ#579608, absolute symbolic links. *)
2968     InitISOFS, Always, TestOutputInt (
2969       [["wc_l"; "/abssymlink"]], 10000)],
2970    "count lines in a file",
2971    "\
2972 This command counts the lines in a file, using the
2973 C<wc -l> external command.");
2974
2975   ("wc_w", (RInt "words", [Pathname "path"], []), 119, [],
2976    [InitISOFS, Always, TestOutputInt (
2977       [["wc_w"; "/10klines"]], 10000)],
2978    "count words in a file",
2979    "\
2980 This command counts the words in a file, using the
2981 C<wc -w> external command.");
2982
2983   ("wc_c", (RInt "chars", [Pathname "path"], []), 120, [],
2984    [InitISOFS, Always, TestOutputInt (
2985       [["wc_c"; "/100kallspaces"]], 102400)],
2986    "count characters in a file",
2987    "\
2988 This command counts the characters in a file, using the
2989 C<wc -c> external command.");
2990
2991   ("head", (RStringList "lines", [Pathname "path"], []), 121, [ProtocolLimitWarning],
2992    [InitISOFS, Always, TestOutputList (
2993       [["head"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz";"3abcdefghijklmnopqrstuvwxyz";"4abcdefghijklmnopqrstuvwxyz";"5abcdefghijklmnopqrstuvwxyz";"6abcdefghijklmnopqrstuvwxyz";"7abcdefghijklmnopqrstuvwxyz";"8abcdefghijklmnopqrstuvwxyz";"9abcdefghijklmnopqrstuvwxyz"]);
2994     (* Test for RHBZ#579608, absolute symbolic links. *)
2995     InitISOFS, Always, TestOutputList (
2996       [["head"; "/abssymlink"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz";"3abcdefghijklmnopqrstuvwxyz";"4abcdefghijklmnopqrstuvwxyz";"5abcdefghijklmnopqrstuvwxyz";"6abcdefghijklmnopqrstuvwxyz";"7abcdefghijklmnopqrstuvwxyz";"8abcdefghijklmnopqrstuvwxyz";"9abcdefghijklmnopqrstuvwxyz"])],
2997    "return first 10 lines of a file",
2998    "\
2999 This command returns up to the first 10 lines of a file as
3000 a list of strings.");
3001
3002   ("head_n", (RStringList "lines", [Int "nrlines"; Pathname "path"], []), 122, [ProtocolLimitWarning],
3003    [InitISOFS, Always, TestOutputList (
3004       [["head_n"; "3"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz"]);
3005     InitISOFS, Always, TestOutputList (
3006       [["head_n"; "-9997"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz"]);
3007     InitISOFS, Always, TestOutputList (
3008       [["head_n"; "0"; "/10klines"]], [])],
3009    "return first N lines of a file",
3010    "\
3011 If the parameter C<nrlines> is a positive number, this returns the first
3012 C<nrlines> lines of the file C<path>.
3013
3014 If the parameter C<nrlines> is a negative number, this returns lines
3015 from the file C<path>, excluding the last C<nrlines> lines.
3016
3017 If the parameter C<nrlines> is zero, this returns an empty list.");
3018
3019   ("tail", (RStringList "lines", [Pathname "path"], []), 123, [ProtocolLimitWarning],
3020    [InitISOFS, Always, TestOutputList (
3021       [["tail"; "/10klines"]], ["9990abcdefghijklmnopqrstuvwxyz";"9991abcdefghijklmnopqrstuvwxyz";"9992abcdefghijklmnopqrstuvwxyz";"9993abcdefghijklmnopqrstuvwxyz";"9994abcdefghijklmnopqrstuvwxyz";"9995abcdefghijklmnopqrstuvwxyz";"9996abcdefghijklmnopqrstuvwxyz";"9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"])],
3022    "return last 10 lines of a file",
3023    "\
3024 This command returns up to the last 10 lines of a file as
3025 a list of strings.");
3026
3027   ("tail_n", (RStringList "lines", [Int "nrlines"; Pathname "path"], []), 124, [ProtocolLimitWarning],
3028    [InitISOFS, Always, TestOutputList (
3029       [["tail_n"; "3"; "/10klines"]], ["9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"]);
3030     InitISOFS, Always, TestOutputList (
3031       [["tail_n"; "-9998"; "/10klines"]], ["9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"]);
3032     InitISOFS, Always, TestOutputList (
3033       [["tail_n"; "0"; "/10klines"]], [])],
3034    "return last N lines of a file",
3035    "\
3036 If the parameter C<nrlines> is a positive number, this returns the last
3037 C<nrlines> lines of the file C<path>.
3038
3039 If the parameter C<nrlines> is a negative number, this returns lines
3040 from the file C<path>, starting with the C<-nrlines>th line.
3041
3042 If the parameter C<nrlines> is zero, this returns an empty list.");
3043
3044   ("df", (RString "output", [], []), 125, [],
3045    [], (* XXX Tricky to test because it depends on the exact format
3046         * of the 'df' command and other imponderables.
3047         *)
3048    "report file system disk space usage",
3049    "\
3050 This command runs the C<df> command to report disk space used.
3051
3052 This command is mostly useful for interactive sessions.  It
3053 is I<not> intended that you try to parse the output string.
3054 Use C<statvfs> from programs.");
3055
3056   ("df_h", (RString "output", [], []), 126, [],
3057    [], (* XXX Tricky to test because it depends on the exact format
3058         * of the 'df' command and other imponderables.
3059         *)
3060    "report file system disk space usage (human readable)",
3061    "\
3062 This command runs the C<df -h> command to report disk space used
3063 in human-readable format.
3064
3065 This command is mostly useful for interactive sessions.  It
3066 is I<not> intended that you try to parse the output string.
3067 Use C<statvfs> from programs.");
3068
3069   ("du", (RInt64 "sizekb", [Pathname "path"], []), 127, [],
3070    [InitISOFS, Always, TestOutputInt (
3071       [["du"; "/directory"]], 2 (* ISO fs blocksize is 2K *))],
3072    "estimate file space usage",
3073    "\
3074 This command runs the C<du -s> command to estimate file space
3075 usage for C<path>.
3076
3077 C<path> can be a file or a directory.  If C<path> is a directory
3078 then the estimate includes the contents of the directory and all
3079 subdirectories (recursively).
3080
3081 The result is the estimated size in I<kilobytes>
3082 (ie. units of 1024 bytes).");
3083
3084   ("initrd_list", (RStringList "filenames", [Pathname "path"], []), 128, [],
3085    [InitISOFS, Always, TestOutputList (
3086       [["initrd_list"; "/initrd"]], ["empty";"known-1";"known-2";"known-3";"known-4"; "known-5"])],
3087    "list files in an initrd",
3088    "\
3089 This command lists out files contained in an initrd.
3090
3091 The files are listed without any initial C</> character.  The
3092 files are listed in the order they appear (not necessarily
3093 alphabetical).  Directory names are listed as separate items.
3094
3095 Old Linux kernels (2.4 and earlier) used a compressed ext2
3096 filesystem as initrd.  We I<only> support the newer initramfs
3097 format (compressed cpio files).");
3098
3099   ("mount_loop", (RErr, [Pathname "file"; Pathname "mountpoint"], []), 129, [],
3100    [],
3101    "mount a file using the loop device",
3102    "\
3103 This command lets you mount C<file> (a filesystem image
3104 in a file) on a mount point.  It is entirely equivalent to
3105 the command C<mount -o loop file mountpoint>.");
3106
3107   ("mkswap", (RErr, [Device "device"], []), 130, [],
3108    [InitEmpty, Always, TestRun (
3109       [["part_disk"; "/dev/sda"; "mbr"];
3110        ["mkswap"; "/dev/sda1"]])],
3111    "create a swap partition",
3112    "\
3113 Create a swap partition on C<device>.");
3114
3115   ("mkswap_L", (RErr, [String "label"; Device "device"], []), 131, [],
3116    [InitEmpty, Always, TestRun (
3117       [["part_disk"; "/dev/sda"; "mbr"];
3118        ["mkswap_L"; "hello"; "/dev/sda1"]])],
3119    "create a swap partition with a label",
3120    "\
3121 Create a swap partition on C<device> with label C<label>.
3122
3123 Note that you cannot attach a swap label to a block device
3124 (eg. C</dev/sda>), just to a partition.  This appears to be
3125 a limitation of the kernel or swap tools.");
3126
3127   ("mkswap_U", (RErr, [String "uuid"; Device "device"], []), 132, [Optional "linuxfsuuid"],
3128    (let uuid = uuidgen () in
3129     [InitEmpty, Always, TestRun (
3130        [["part_disk"; "/dev/sda"; "mbr"];
3131         ["mkswap_U"; uuid; "/dev/sda1"]])]),
3132    "create a swap partition with an explicit UUID",
3133    "\
3134 Create a swap partition on C<device> with UUID C<uuid>.");
3135
3136   ("mknod", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"], []), 133, [Optional "mknod"],
3137    [InitBasicFS, Always, TestOutputStruct (
3138       [["mknod"; "0o10777"; "0"; "0"; "/node"];
3139        (* NB: default umask 022 means 0777 -> 0755 in these tests *)
3140        ["stat"; "/node"]], [CompareWithInt ("mode", 0o10755)]);
3141     InitBasicFS, Always, TestOutputStruct (
3142       [["mknod"; "0o60777"; "66"; "99"; "/node"];
3143        ["stat"; "/node"]], [CompareWithInt ("mode", 0o60755)])],
3144    "make block, character or FIFO devices",
3145    "\
3146 This call creates block or character special devices, or
3147 named pipes (FIFOs).
3148
3149 The C<mode> parameter should be the mode, using the standard
3150 constants.  C<devmajor> and C<devminor> are the
3151 device major and minor numbers, only used when creating block
3152 and character special devices.
3153
3154 Note that, just like L<mknod(2)>, the mode must be bitwise
3155 OR'd with S_IFBLK, S_IFCHR, S_IFIFO or S_IFSOCK (otherwise this call
3156 just creates a regular file).  These constants are
3157 available in the standard Linux header files, or you can use
3158 C<guestfs_mknod_b>, C<guestfs_mknod_c> or C<guestfs_mkfifo>
3159 which are wrappers around this command which bitwise OR
3160 in the appropriate constant for you.
3161
3162 The mode actually set is affected by the umask.");
3163
3164   ("mkfifo", (RErr, [Int "mode"; Pathname "path"], []), 134, [Optional "mknod"],
3165    [InitBasicFS, Always, TestOutputStruct (
3166       [["mkfifo"; "0o777"; "/node"];
3167        ["stat"; "/node"]], [CompareWithInt ("mode", 0o10755)])],
3168    "make FIFO (named pipe)",
3169    "\
3170 This call creates a FIFO (named pipe) called C<path> with
3171 mode C<mode>.  It is just a convenient wrapper around
3172 C<guestfs_mknod>.
3173
3174 The mode actually set is affected by the umask.");
3175
3176   ("mknod_b", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"], []), 135, [Optional "mknod"],
3177    [InitBasicFS, Always, TestOutputStruct (
3178       [["mknod_b"; "0o777"; "99"; "66"; "/node"];
3179        ["stat"; "/node"]], [CompareWithInt ("mode", 0o60755)])],
3180    "make block device node",
3181    "\
3182 This call creates a block device node called C<path> with
3183 mode C<mode> and device major/minor C<devmajor> and C<devminor>.
3184 It is just a convenient wrapper around C<guestfs_mknod>.
3185
3186 The mode actually set is affected by the umask.");
3187
3188   ("mknod_c", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"], []), 136, [Optional "mknod"],
3189    [InitBasicFS, Always, TestOutputStruct (
3190       [["mknod_c"; "0o777"; "99"; "66"; "/node"];
3191        ["stat"; "/node"]], [CompareWithInt ("mode", 0o20755)])],
3192    "make char device node",
3193    "\
3194 This call creates a char device node called C<path> with
3195 mode C<mode> and device major/minor C<devmajor> and C<devminor>.
3196 It is just a convenient wrapper around C<guestfs_mknod>.
3197
3198 The mode actually set is affected by the umask.");
3199
3200   ("umask", (RInt "oldmask", [Int "mask"], []), 137, [FishOutput FishOutputOctal],
3201    [InitEmpty, Always, TestOutputInt (
3202       [["umask"; "0o22"]], 0o22)],
3203    "set file mode creation mask (umask)",
3204    "\
3205 This function sets the mask used for creating new files and
3206 device nodes to C<mask & 0777>.
3207
3208 Typical umask values would be C<022> which creates new files
3209 with permissions like \"-rw-r--r--\" or \"-rwxr-xr-x\", and
3210 C<002> which creates new files with permissions like
3211 \"-rw-rw-r--\" or \"-rwxrwxr-x\".
3212
3213 The default umask is C<022>.  This is important because it
3214 means that directories and device nodes will be created with
3215 C<0644> or C<0755> mode even if you specify C<0777>.
3216
3217 See also C<guestfs_get_umask>,
3218 L<umask(2)>, C<guestfs_mknod>, C<guestfs_mkdir>.
3219
3220 This call returns the previous umask.");
3221
3222   ("readdir", (RStructList ("entries", "dirent"), [Pathname "dir"], []), 138, [],
3223    [],
3224    "read directories entries",
3225    "\
3226 This returns the list of directory entries in directory C<dir>.
3227
3228 All entries in the directory are returned, including C<.> and
3229 C<..>.  The entries are I<not> sorted, but returned in the same
3230 order as the underlying filesystem.
3231
3232 Also this call returns basic file type information about each
3233 file.  The C<ftyp> field will contain one of the following characters:
3234
3235 =over 4
3236
3237 =item 'b'
3238
3239 Block special
3240
3241 =item 'c'
3242
3243 Char special
3244
3245 =item 'd'
3246
3247 Directory
3248
3249 =item 'f'
3250
3251 FIFO (named pipe)
3252
3253 =item 'l'
3254
3255 Symbolic link
3256
3257 =item 'r'
3258
3259 Regular file
3260
3261 =item 's'
3262
3263 Socket
3264
3265 =item 'u'
3266
3267 Unknown file type
3268
3269 =item '?'
3270
3271 The L<readdir(3)> call returned a C<d_type> field with an
3272 unexpected value
3273
3274 =back
3275
3276 This function is primarily intended for use by programs.  To
3277 get a simple list of names, use C<guestfs_ls>.  To get a printable
3278 directory for human consumption, use C<guestfs_ll>.");
3279
3280   ("sfdiskM", (RErr, [Device "device"; StringList "lines"], []), 139, [DangerWillRobinson],
3281    [],
3282    "create partitions on a block device",
3283    "\
3284 This is a simplified interface to the C<guestfs_sfdisk>
3285 command, where partition sizes are specified in megabytes
3286 only (rounded to the nearest cylinder) and you don't need
3287 to specify the cyls, heads and sectors parameters which
3288 were rarely if ever used anyway.
3289
3290 See also: C<guestfs_sfdisk>, the L<sfdisk(8)> manpage
3291 and C<guestfs_part_disk>");
3292
3293   ("zfile", (RString "description", [String "meth"; Pathname "path"], []), 140, [DeprecatedBy "file"],
3294    [],
3295    "determine file type inside a compressed file",
3296    "\
3297 This command runs C<file> after first decompressing C<path>
3298 using C<method>.
3299
3300 C<method> must be one of C<gzip>, C<compress> or C<bzip2>.
3301
3302 Since 1.0.63, use C<guestfs_file> instead which can now
3303 process compressed files.");
3304
3305   ("getxattrs", (RStructList ("xattrs", "xattr"), [Pathname "path"], []), 141, [Optional "linuxxattrs"],
3306    [],
3307    "list extended attributes of a file or directory",
3308    "\
3309 This call lists the extended attributes of the file or directory
3310 C<path>.
3311
3312 At the system call level, this is a combination of the
3313 L<listxattr(2)> and L<getxattr(2)> calls.
3314
3315 See also: C<guestfs_lgetxattrs>, L<attr(5)>.");
3316
3317   ("lgetxattrs", (RStructList ("xattrs", "xattr"), [Pathname "path"], []), 142, [Optional "linuxxattrs"],
3318    [],
3319    "list extended attributes of a file or directory",
3320    "\
3321 This is the same as C<guestfs_getxattrs>, but if C<path>
3322 is a symbolic link, then it returns the extended attributes
3323 of the link itself.");
3324
3325   ("setxattr", (RErr, [String "xattr";
3326                        String "val"; Int "vallen"; (* will be BufferIn *)
3327                        Pathname "path"], []), 143, [Optional "linuxxattrs"],
3328    [],
3329    "set extended attribute of a file or directory",
3330    "\
3331 This call sets the extended attribute named C<xattr>
3332 of the file C<path> to the value C<val> (of length C<vallen>).
3333 The value is arbitrary 8 bit data.
3334
3335 See also: C<guestfs_lsetxattr>, L<attr(5)>.");
3336
3337   ("lsetxattr", (RErr, [String "xattr";
3338                         String "val"; Int "vallen"; (* will be BufferIn *)
3339                         Pathname "path"], []), 144, [Optional "linuxxattrs"],
3340    [],
3341    "set extended attribute of a file or directory",
3342    "\
3343 This is the same as C<guestfs_setxattr>, but if C<path>
3344 is a symbolic link, then it sets an extended attribute
3345 of the link itself.");
3346
3347   ("removexattr", (RErr, [String "xattr"; Pathname "path"], []), 145, [Optional "linuxxattrs"],
3348    [],
3349    "remove extended attribute of a file or directory",
3350    "\
3351 This call removes the extended attribute named C<xattr>
3352 of the file C<path>.
3353
3354 See also: C<guestfs_lremovexattr>, L<attr(5)>.");
3355
3356   ("lremovexattr", (RErr, [String "xattr"; Pathname "path"], []), 146, [Optional "linuxxattrs"],
3357    [],
3358    "remove extended attribute of a file or directory",
3359    "\
3360 This is the same as C<guestfs_removexattr>, but if C<path>
3361 is a symbolic link, then it removes an extended attribute
3362 of the link itself.");
3363
3364   ("mountpoints", (RHashtable "mps", [], []), 147, [],
3365    [],
3366    "show mountpoints",
3367    "\
3368 This call is similar to C<guestfs_mounts>.  That call returns
3369 a list of devices.  This one returns a hash table (map) of
3370 device name to directory where the device is mounted.");
3371
3372   ("mkmountpoint", (RErr, [String "exemptpath"], []), 148, [],
3373    (* This is a special case: while you would expect a parameter
3374     * of type "Pathname", that doesn't work, because it implies
3375     * NEED_ROOT in the generated calling code in stubs.c, and
3376     * this function cannot use NEED_ROOT.
3377     *)
3378    [],
3379    "create a mountpoint",
3380    "\
3381 C<guestfs_mkmountpoint> and C<guestfs_rmmountpoint> are
3382 specialized calls that can be used to create extra mountpoints
3383 before mounting the first filesystem.
3384
3385 These calls are I<only> necessary in some very limited circumstances,
3386 mainly the case where you want to mount a mix of unrelated and/or
3387 read-only filesystems together.
3388
3389 For example, live CDs often contain a \"Russian doll\" nest of
3390 filesystems, an ISO outer layer, with a squashfs image inside, with
3391 an ext2/3 image inside that.  You can unpack this as follows
3392 in guestfish:
3393
3394  add-ro Fedora-11-i686-Live.iso
3395  run
3396  mkmountpoint /cd
3397  mkmountpoint /squash
3398  mkmountpoint /ext3
3399  mount /dev/sda /cd
3400  mount-loop /cd/LiveOS/squashfs.img /squash
3401  mount-loop /squash/LiveOS/ext3fs.img /ext3
3402
3403 The inner filesystem is now unpacked under the /ext3 mountpoint.");
3404
3405   ("rmmountpoint", (RErr, [String "exemptpath"], []), 149, [],
3406    [],
3407    "remove a mountpoint",
3408    "\
3409 This calls removes a mountpoint that was previously created
3410 with C<guestfs_mkmountpoint>.  See C<guestfs_mkmountpoint>
3411 for full details.");
3412
3413   ("read_file", (RBufferOut "content", [Pathname "path"], []), 150, [ProtocolLimitWarning],
3414    [InitISOFS, Always, TestOutputBuffer (
3415       [["read_file"; "/known-4"]], "abc\ndef\nghi");
3416     (* Test various near large, large and too large files (RHBZ#589039). *)
3417     InitBasicFS, Always, TestLastFail (
3418       [["touch"; "/a"];
3419        ["truncate_size"; "/a"; "4194303"]; (* GUESTFS_MESSAGE_MAX - 1 *)
3420        ["read_file"; "/a"]]);
3421     InitBasicFS, Always, TestLastFail (
3422       [["touch"; "/a"];
3423        ["truncate_size"; "/a"; "4194304"]; (* GUESTFS_MESSAGE_MAX *)
3424        ["read_file"; "/a"]]);
3425     InitBasicFS, Always, TestLastFail (
3426       [["touch"; "/a"];
3427        ["truncate_size"; "/a"; "41943040"]; (* GUESTFS_MESSAGE_MAX * 10 *)
3428        ["read_file"; "/a"]])],
3429    "read a file",
3430    "\
3431 This calls returns the contents of the file C<path> as a
3432 buffer.
3433
3434 Unlike C<guestfs_cat>, this function can correctly
3435 handle files that contain embedded ASCII NUL characters.
3436 However unlike C<guestfs_download>, this function is limited
3437 in the total size of file that can be handled.");
3438
3439   ("grep", (RStringList "lines", [String "regex"; Pathname "path"], []), 151, [ProtocolLimitWarning],
3440    [InitISOFS, Always, TestOutputList (
3441       [["grep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"]);
3442     InitISOFS, Always, TestOutputList (
3443       [["grep"; "nomatch"; "/test-grep.txt"]], []);
3444     (* Test for RHBZ#579608, absolute symbolic links. *)
3445     InitISOFS, Always, TestOutputList (
3446       [["grep"; "nomatch"; "/abssymlink"]], [])],
3447    "return lines matching a pattern",
3448    "\
3449 This calls the external C<grep> program and returns the
3450 matching lines.");
3451
3452   ("egrep", (RStringList "lines", [String "regex"; Pathname "path"], []), 152, [ProtocolLimitWarning],
3453    [InitISOFS, Always, TestOutputList (
3454       [["egrep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"])],
3455    "return lines matching a pattern",
3456    "\
3457 This calls the external C<egrep> program and returns the
3458 matching lines.");
3459
3460   ("fgrep", (RStringList "lines", [String "pattern"; Pathname "path"], []), 153, [ProtocolLimitWarning],
3461    [InitISOFS, Always, TestOutputList (
3462       [["fgrep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"])],
3463    "return lines matching a pattern",
3464    "\
3465 This calls the external C<fgrep> program and returns the
3466 matching lines.");
3467
3468   ("grepi", (RStringList "lines", [String "regex"; Pathname "path"], []), 154, [ProtocolLimitWarning],
3469    [InitISOFS, Always, TestOutputList (
3470       [["grepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])],
3471    "return lines matching a pattern",
3472    "\
3473 This calls the external C<grep -i> program and returns the
3474 matching lines.");
3475
3476   ("egrepi", (RStringList "lines", [String "regex"; Pathname "path"], []), 155, [ProtocolLimitWarning],
3477    [InitISOFS, Always, TestOutputList (
3478       [["egrepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])],
3479    "return lines matching a pattern",
3480    "\
3481 This calls the external C<egrep -i> program and returns the
3482 matching lines.");
3483
3484   ("fgrepi", (RStringList "lines", [String "pattern"; Pathname "path"], []), 156, [ProtocolLimitWarning],
3485    [InitISOFS, Always, TestOutputList (
3486       [["fgrepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])],
3487    "return lines matching a pattern",
3488    "\
3489 This calls the external C<fgrep -i> program and returns the
3490 matching lines.");
3491
3492   ("zgrep", (RStringList "lines", [String "regex"; Pathname "path"], []), 157, [ProtocolLimitWarning],
3493    [InitISOFS, Always, TestOutputList (
3494       [["zgrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])],
3495    "return lines matching a pattern",
3496    "\
3497 This calls the external C<zgrep> program and returns the
3498 matching lines.");
3499
3500   ("zegrep", (RStringList "lines", [String "regex"; Pathname "path"], []), 158, [ProtocolLimitWarning],
3501    [InitISOFS, Always, TestOutputList (
3502       [["zegrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])],
3503    "return lines matching a pattern",
3504    "\
3505 This calls the external C<zegrep> program and returns the
3506 matching lines.");
3507
3508   ("zfgrep", (RStringList "lines", [String "pattern"; Pathname "path"], []), 159, [ProtocolLimitWarning],
3509    [InitISOFS, Always, TestOutputList (
3510       [["zfgrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])],
3511    "return lines matching a pattern",
3512    "\
3513 This calls the external C<zfgrep> program and returns the
3514 matching lines.");
3515
3516   ("zgrepi", (RStringList "lines", [String "regex"; Pathname "path"], []), 160, [ProtocolLimitWarning],
3517    [InitISOFS, Always, TestOutputList (
3518       [["zgrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])],
3519    "return lines matching a pattern",
3520    "\
3521 This calls the external C<zgrep -i> program and returns the
3522 matching lines.");
3523
3524   ("zegrepi", (RStringList "lines", [String "regex"; Pathname "path"], []), 161, [ProtocolLimitWarning],
3525    [InitISOFS, Always, TestOutputList (
3526       [["zegrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])],
3527    "return lines matching a pattern",
3528    "\
3529 This calls the external C<zegrep -i> program and returns the
3530 matching lines.");
3531
3532   ("zfgrepi", (RStringList "lines", [String "pattern"; Pathname "path"], []), 162, [ProtocolLimitWarning],
3533    [InitISOFS, Always, TestOutputList (
3534       [["zfgrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])],
3535    "return lines matching a pattern",
3536    "\
3537 This calls the external C<zfgrep -i> program and returns the
3538 matching lines.");
3539
3540   ("realpath", (RString "rpath", [Pathname "path"], []), 163, [Optional "realpath"],
3541    [InitISOFS, Always, TestOutput (
3542       [["realpath"; "/../directory"]], "/directory")],
3543    "canonicalized absolute pathname",
3544    "\
3545 Return the canonicalized absolute pathname of C<path>.  The
3546 returned path has no C<.>, C<..> or symbolic link path elements.");
3547
3548   ("ln", (RErr, [String "target"; Pathname "linkname"], []), 164, [],
3549    [InitBasicFS, Always, TestOutputStruct (
3550       [["touch"; "/a"];
3551        ["ln"; "/a"; "/b"];
3552        ["stat"; "/b"]], [CompareWithInt ("nlink", 2)])],
3553    "create a hard link",
3554    "\
3555 This command creates a hard link using the C<ln> command.");
3556
3557   ("ln_f", (RErr, [String "target"; Pathname "linkname"], []), 165, [],
3558    [InitBasicFS, Always, TestOutputStruct (
3559       [["touch"; "/a"];
3560        ["touch"; "/b"];
3561        ["ln_f"; "/a"; "/b"];
3562        ["stat"; "/b"]], [CompareWithInt ("nlink", 2)])],
3563    "create a hard link",
3564    "\
3565 This command creates a hard link using the C<ln -f> command.
3566 The C<-f> option removes the link (C<linkname>) if it exists already.");
3567
3568   ("ln_s", (RErr, [String "target"; Pathname "linkname"], []), 166, [],
3569    [InitBasicFS, Always, TestOutputStruct (
3570       [["touch"; "/a"];
3571        ["ln_s"; "a"; "/b"];
3572        ["lstat"; "/b"]], [CompareWithInt ("mode", 0o120777)])],
3573    "create a symbolic link",
3574    "\
3575 This command creates a symbolic link using the C<ln -s> command.");
3576
3577   ("ln_sf", (RErr, [String "target"; Pathname "linkname"], []), 167, [],
3578    [InitBasicFS, Always, TestOutput (
3579       [["mkdir_p"; "/a/b"];
3580        ["touch"; "/a/b/c"];
3581        ["ln_sf"; "../d"; "/a/b/c"];
3582        ["readlink"; "/a/b/c"]], "../d")],
3583    "create a symbolic link",
3584    "\
3585 This command creates a symbolic link using the C<ln -sf> command,
3586 The C<-f> option removes the link (C<linkname>) if it exists already.");
3587
3588   ("readlink", (RString "link", [Pathname "path"], []), 168, [],
3589    [] (* XXX tested above *),
3590    "read the target of a symbolic link",
3591    "\
3592 This command reads the target of a symbolic link.");
3593
3594   ("fallocate", (RErr, [Pathname "path"; Int "len"], []), 169, [DeprecatedBy "fallocate64"],
3595    [InitBasicFS, Always, TestOutputStruct (
3596       [["fallocate"; "/a"; "1000000"];
3597        ["stat"; "/a"]], [CompareWithInt ("size", 1_000_000)])],
3598    "preallocate a file in the guest filesystem",
3599    "\
3600 This command preallocates a file (containing zero bytes) named
3601 C<path> of size C<len> bytes.  If the file exists already, it
3602 is overwritten.
3603
3604 Do not confuse this with the guestfish-specific
3605 C<alloc> command which allocates a file in the host and
3606 attaches it as a device.");
3607
3608   ("swapon_device", (RErr, [Device "device"], []), 170, [],
3609    [InitPartition, Always, TestRun (
3610       [["mkswap"; "/dev/sda1"];
3611        ["swapon_device"; "/dev/sda1"];
3612        ["swapoff_device"; "/dev/sda1"]])],
3613    "enable swap on device",
3614    "\
3615 This command enables the libguestfs appliance to use the
3616 swap device or partition named C<device>.  The increased
3617 memory is made available for all commands, for example
3618 those run using C<guestfs_command> or C<guestfs_sh>.
3619
3620 Note that you should not swap to existing guest swap
3621 partitions unless you know what you are doing.  They may
3622 contain hibernation information, or other information that
3623 the guest doesn't want you to trash.  You also risk leaking
3624 information about the host to the guest this way.  Instead,
3625 attach a new host device to the guest and swap on that.");
3626
3627   ("swapoff_device", (RErr, [Device "device"], []), 171, [],
3628    [], (* XXX tested by swapon_device *)
3629    "disable swap on device",
3630    "\
3631 This command disables the libguestfs appliance swap
3632 device or partition named C<device>.
3633 See C<guestfs_swapon_device>.");
3634
3635   ("swapon_file", (RErr, [Pathname "file"], []), 172, [],
3636    [InitBasicFS, Always, TestRun (
3637       [["fallocate"; "/swap"; "8388608"];
3638        ["mkswap_file"; "/swap"];
3639        ["swapon_file"; "/swap"];
3640        ["swapoff_file"; "/swap"]])],
3641    "enable swap on file",
3642    "\
3643 This command enables swap to a file.
3644 See C<guestfs_swapon_device> for other notes.");
3645
3646   ("swapoff_file", (RErr, [Pathname "file"], []), 173, [],
3647    [], (* XXX tested by swapon_file *)
3648    "disable swap on file",
3649    "\
3650 This command disables the libguestfs appliance swap on file.");
3651
3652   ("swapon_label", (RErr, [String "label"], []), 174, [],
3653    [InitEmpty, Always, TestRun (
3654       [["part_disk"; "/dev/sdb"; "mbr"];
3655        ["mkswap_L"; "swapit"; "/dev/sdb1"];
3656        ["swapon_label"; "swapit"];
3657        ["swapoff_label"; "swapit"];
3658        ["zero"; "/dev/sdb"];
3659        ["blockdev_rereadpt"; "/dev/sdb"]])],
3660    "enable swap on labeled swap partition",
3661    "\
3662 This command enables swap to a labeled swap partition.
3663 See C<guestfs_swapon_device> for other notes.");
3664
3665   ("swapoff_label", (RErr, [String "label"], []), 175, [],
3666    [], (* XXX tested by swapon_label *)
3667    "disable swap on labeled swap partition",
3668    "\
3669 This command disables the libguestfs appliance swap on
3670 labeled swap partition.");
3671
3672   ("swapon_uuid", (RErr, [String "uuid"], []), 176, [Optional "linuxfsuuid"],
3673    (let uuid = uuidgen () in
3674     [InitEmpty, Always, TestRun (
3675        [["mkswap_U"; uuid; "/dev/sdb"];
3676         ["swapon_uuid"; uuid];
3677         ["swapoff_uuid"; uuid]])]),
3678    "enable swap on swap partition by UUID",
3679    "\
3680 This command enables swap to a swap partition with the given UUID.
3681 See C<guestfs_swapon_device> for other notes.");
3682
3683   ("swapoff_uuid", (RErr, [String "uuid"], []), 177, [Optional "linuxfsuuid"],
3684    [], (* XXX tested by swapon_uuid *)
3685    "disable swap on swap partition by UUID",
3686    "\
3687 This command disables the libguestfs appliance swap partition
3688 with the given UUID.");
3689
3690   ("mkswap_file", (RErr, [Pathname "path"], []), 178, [],
3691    [InitBasicFS, Always, TestRun (
3692       [["fallocate"; "/swap"; "8388608"];
3693        ["mkswap_file"; "/swap"]])],
3694    "create a swap file",
3695    "\
3696 Create a swap file.
3697
3698 This command just writes a swap file signature to an existing
3699 file.  To create the file itself, use something like C<guestfs_fallocate>.");
3700
3701   ("inotify_init", (RErr, [Int "maxevents"], []), 179, [Optional "inotify"],
3702    [InitISOFS, Always, TestRun (
3703       [["inotify_init"; "0"]])],
3704    "create an inotify handle",
3705    "\
3706 This command creates a new inotify handle.
3707 The inotify subsystem can be used to notify events which happen to
3708 objects in the guest filesystem.
3709
3710 C<maxevents> is the maximum number of events which will be
3711 queued up between calls to C<guestfs_inotify_read> or
3712 C<guestfs_inotify_files>.
3713 If this is passed as C<0>, then the kernel (or previously set)
3714 default is used.  For Linux 2.6.29 the default was 16384 events.
3715 Beyond this limit, the kernel throws away events, but records
3716 the fact that it threw them away by setting a flag
3717 C<IN_Q_OVERFLOW> in the returned structure list (see
3718 C<guestfs_inotify_read>).
3719
3720 Before any events are generated, you have to add some
3721 watches to the internal watch list.  See:
3722 C<guestfs_inotify_add_watch>,
3723 C<guestfs_inotify_rm_watch> and
3724 C<guestfs_inotify_watch_all>.
3725
3726 Queued up events should be read periodically by calling
3727 C<guestfs_inotify_read>
3728 (or C<guestfs_inotify_files> which is just a helpful
3729 wrapper around C<guestfs_inotify_read>).  If you don't
3730 read the events out often enough then you risk the internal
3731 queue overflowing.
3732
3733 The handle should be closed after use by calling
3734 C<guestfs_inotify_close>.  This also removes any
3735 watches automatically.
3736
3737 See also L<inotify(7)> for an overview of the inotify interface
3738 as exposed by the Linux kernel, which is roughly what we expose
3739 via libguestfs.  Note that there is one global inotify handle
3740 per libguestfs instance.");
3741
3742   ("inotify_add_watch", (RInt64 "wd", [Pathname "path"; Int "mask"], []), 180, [Optional "inotify"],
3743    [InitBasicFS, Always, TestOutputList (
3744       [["inotify_init"; "0"];
3745        ["inotify_add_watch"; "/"; "1073741823"];
3746        ["touch"; "/a"];
3747        ["touch"; "/b"];
3748        ["inotify_files"]], ["a"; "b"])],
3749    "add an inotify watch",
3750    "\
3751 Watch C<path> for the events listed in C<mask>.
3752
3753 Note that if C<path> is a directory then events within that
3754 directory are watched, but this does I<not> happen recursively
3755 (in subdirectories).
3756
3757 Note for non-C or non-Linux callers: the inotify events are
3758 defined by the Linux kernel ABI and are listed in
3759 C</usr/include/sys/inotify.h>.");
3760
3761   ("inotify_rm_watch", (RErr, [Int(*XXX64*) "wd"], []), 181, [Optional "inotify"],
3762    [],
3763    "remove an inotify watch",
3764    "\
3765 Remove a previously defined inotify watch.
3766 See C<guestfs_inotify_add_watch>.");
3767
3768   ("inotify_read", (RStructList ("events", "inotify_event"), [], []), 182, [Optional "inotify"],
3769    [],
3770    "return list of inotify events",
3771    "\
3772 Return the complete queue of events that have happened
3773 since the previous read call.
3774
3775 If no events have happened, this returns an empty list.
3776
3777 I<Note>: In order to make sure that all events have been
3778 read, you must call this function repeatedly until it
3779 returns an empty list.  The reason is that the call will
3780 read events up to the maximum appliance-to-host message
3781 size and leave remaining events in the queue.");
3782
3783   ("inotify_files", (RStringList "paths", [], []), 183, [Optional "inotify"],
3784    [],
3785    "return list of watched files that had events",
3786    "\
3787 This function is a helpful wrapper around C<guestfs_inotify_read>
3788 which just returns a list of pathnames of objects that were
3789 touched.  The returned pathnames are sorted and deduplicated.");
3790
3791   ("inotify_close", (RErr, [], []), 184, [Optional "inotify"],
3792    [],
3793    "close the inotify handle",
3794    "\
3795 This closes the inotify handle which was previously
3796 opened by inotify_init.  It removes all watches, throws
3797 away any pending events, and deallocates all resources.");
3798
3799   ("setcon", (RErr, [String "context"], []), 185, [Optional "selinux"],
3800    [],
3801    "set SELinux security context",
3802    "\
3803 This sets the SELinux security context of the daemon
3804 to the string C<context>.
3805
3806 See the documentation about SELINUX in L<guestfs(3)>.");
3807
3808   ("getcon", (RString "context", [], []), 186, [Optional "selinux"],
3809    [],
3810    "get SELinux security context",
3811    "\
3812 This gets the SELinux security context of the daemon.
3813
3814 See the documentation about SELINUX in L<guestfs(3)>,
3815 and C<guestfs_setcon>");
3816
3817   ("mkfs_b", (RErr, [String "fstype"; Int "blocksize"; Device "device"], []), 187, [],
3818    [InitEmpty, Always, TestOutput (
3819       [["part_disk"; "/dev/sda"; "mbr"];
3820        ["mkfs_b"; "ext2"; "4096"; "/dev/sda1"];
3821        ["mount_options"; ""; "/dev/sda1"; "/"];
3822        ["write"; "/new"; "new file contents"];
3823        ["cat"; "/new"]], "new file contents");
3824     InitEmpty, Always, TestRun (
3825       [["part_disk"; "/dev/sda"; "mbr"];
3826        ["mkfs_b"; "vfat"; "32768"; "/dev/sda1"]]);
3827     InitEmpty, Always, TestLastFail (
3828       [["part_disk"; "/dev/sda"; "mbr"];
3829        ["mkfs_b"; "vfat"; "32769"; "/dev/sda1"]]);
3830     InitEmpty, Always, TestLastFail (
3831       [["part_disk"; "/dev/sda"; "mbr"];
3832        ["mkfs_b"; "vfat"; "33280"; "/dev/sda1"]]);
3833     InitEmpty, IfAvailable "ntfsprogs", TestRun (
3834       [["part_disk"; "/dev/sda"; "mbr"];
3835        ["mkfs_b"; "ntfs"; "32768"; "/dev/sda1"]])],
3836    "make a filesystem with block size",
3837    "\
3838 This call is similar to C<guestfs_mkfs>, but it allows you to
3839 control the block size of the resulting filesystem.  Supported
3840 block sizes depend on the filesystem type, but typically they
3841 are C<1024>, C<2048> or C<4096> only.
3842
3843 For VFAT and NTFS the C<blocksize> parameter is treated as
3844 the requested cluster size.");
3845
3846   ("mke2journal", (RErr, [Int "blocksize"; Device "device"], []), 188, [],
3847    [InitEmpty, Always, TestOutput (
3848       [["sfdiskM"; "/dev/sda"; ",100 ,"];
3849        ["mke2journal"; "4096"; "/dev/sda1"];
3850        ["mke2fs_J"; "ext2"; "4096"; "/dev/sda2"; "/dev/sda1"];
3851        ["mount_options"; ""; "/dev/sda2"; "/"];
3852        ["write"; "/new"; "new file contents"];
3853        ["cat"; "/new"]], "new file contents")],
3854    "make ext2/3/4 external journal",
3855    "\
3856 This creates an ext2 external journal on C<device>.  It is equivalent
3857 to the command:
3858
3859  mke2fs -O journal_dev -b blocksize device");
3860
3861   ("mke2journal_L", (RErr, [Int "blocksize"; String "label"; Device "device"], []), 189, [],
3862    [InitEmpty, Always, TestOutput (
3863       [["sfdiskM"; "/dev/sda"; ",100 ,"];
3864        ["mke2journal_L"; "4096"; "JOURNAL"; "/dev/sda1"];
3865        ["mke2fs_JL"; "ext2"; "4096"; "/dev/sda2"; "JOURNAL"];
3866        ["mount_options"; ""; "/dev/sda2"; "/"];
3867        ["write"; "/new"; "new file contents"];
3868        ["cat"; "/new"]], "new file contents")],
3869    "make ext2/3/4 external journal with label",
3870    "\
3871 This creates an ext2 external journal on C<device> with label C<label>.");
3872
3873   ("mke2journal_U", (RErr, [Int "blocksize"; String "uuid"; Device "device"], []), 190, [Optional "linuxfsuuid"],
3874    (let uuid = uuidgen () in
3875     [InitEmpty, Always, TestOutput (
3876        [["sfdiskM"; "/dev/sda"; ",100 ,"];
3877         ["mke2journal_U"; "4096"; uuid; "/dev/sda1"];
3878         ["mke2fs_JU"; "ext2"; "4096"; "/dev/sda2"; uuid];
3879         ["mount_options"; ""; "/dev/sda2"; "/"];
3880         ["write"; "/new"; "new file contents"];
3881         ["cat"; "/new"]], "new file contents")]),
3882    "make ext2/3/4 external journal with UUID",
3883    "\
3884 This creates an ext2 external journal on C<device> with UUID C<uuid>.");
3885
3886   ("mke2fs_J", (RErr, [String "fstype"; Int "blocksize"; Device "device"; Device "journal"], []), 191, [],
3887    [],
3888    "make ext2/3/4 filesystem with external journal",
3889    "\
3890 This creates an ext2/3/4 filesystem on C<device> with
3891 an external journal on C<journal>.  It is equivalent
3892 to the command:
3893
3894  mke2fs -t fstype -b blocksize -J device=<journal> <device>
3895
3896 See also C<guestfs_mke2journal>.");
3897
3898   ("mke2fs_JL", (RErr, [String "fstype"; Int "blocksize"; Device "device"; String "label"], []), 192, [],
3899    [],
3900    "make ext2/3/4 filesystem with external journal",
3901    "\
3902 This creates an ext2/3/4 filesystem on C<device> with
3903 an external journal on the journal labeled C<label>.
3904
3905 See also C<guestfs_mke2journal_L>.");
3906
3907   ("mke2fs_JU", (RErr, [String "fstype"; Int "blocksize"; Device "device"; String "uuid"], []), 193, [Optional "linuxfsuuid"],
3908    [],
3909    "make ext2/3/4 filesystem with external journal",
3910    "\
3911 This creates an ext2/3/4 filesystem on C<device> with
3912 an external journal on the journal with UUID C<uuid>.
3913
3914 See also C<guestfs_mke2journal_U>.");
3915
3916   ("modprobe", (RErr, [String "modulename"], []), 194, [Optional "linuxmodules"],
3917    [InitNone, Always, TestRun [["modprobe"; "fat"]]],
3918    "load a kernel module",
3919    "\
3920 This loads a kernel module in the appliance.
3921
3922 The kernel module must have been whitelisted when libguestfs
3923 was built (see C<appliance/kmod.whitelist.in> in the source).");
3924
3925   ("echo_daemon", (RString "output", [StringList "words"], []), 195, [],
3926    [InitNone, Always, TestOutput (
3927       [["echo_daemon"; "This is a test"]], "This is a test"
3928     )],
3929    "echo arguments back to the client",
3930    "\
3931 This command concatenates the list of C<words> passed with single spaces
3932 between them and returns the resulting string.
3933
3934 You can use this command to test the connection through to the daemon.
3935
3936 See also C<guestfs_ping_daemon>.");
3937
3938   ("find0", (RErr, [Pathname "directory"; FileOut "files"], []), 196, [],
3939    [], (* There is a regression test for this. *)
3940    "find all files and directories, returning NUL-separated list",
3941    "\
3942 This command lists out all files and directories, recursively,
3943 starting at C<directory>, placing the resulting list in the
3944 external file called C<files>.
3945
3946 This command works the same way as C<guestfs_find> with the
3947 following exceptions:
3948
3949 =over 4
3950
3951 =item *
3952
3953 The resulting list is written to an external file.
3954
3955 =item *
3956
3957 Items (filenames) in the result are separated
3958 by C<\\0> characters.  See L<find(1)> option I<-print0>.
3959
3960 =item *
3961
3962 This command is not limited in the number of names that it
3963 can return.
3964
3965 =item *
3966
3967 The result list is not sorted.
3968
3969 =back");
3970
3971   ("case_sensitive_path", (RString "rpath", [Pathname "path"], []), 197, [],
3972    [InitISOFS, Always, TestOutput (
3973       [["case_sensitive_path"; "/DIRECTORY"]], "/directory");
3974     InitISOFS, Always, TestOutput (
3975       [["case_sensitive_path"; "/DIRECTORY/"]], "/directory");
3976     InitISOFS, Always, TestOutput (
3977       [["case_sensitive_path"; "/Known-1"]], "/known-1");
3978     InitISOFS, Always, TestLastFail (
3979       [["case_sensitive_path"; "/Known-1/"]]);
3980     InitBasicFS, Always, TestOutput (
3981       [["mkdir"; "/a"];
3982        ["mkdir"; "/a/bbb"];
3983        ["touch"; "/a/bbb/c"];
3984        ["case_sensitive_path"; "/A/bbB/C"]], "/a/bbb/c");
3985     InitBasicFS, Always, TestOutput (
3986       [["mkdir"; "/a"];
3987        ["mkdir"; "/a/bbb"];
3988        ["touch"; "/a/bbb/c"];
3989        ["case_sensitive_path"; "/A////bbB/C"]], "/a/bbb/c");
3990     InitBasicFS, Always, TestLastFail (
3991       [["mkdir"; "/a"];
3992        ["mkdir"; "/a/bbb"];
3993        ["touch"; "/a/bbb/c"];
3994        ["case_sensitive_path"; "/A/bbb/../bbb/C"]])],
3995    "return true path on case-insensitive filesystem",
3996    "\
3997 This can be used to resolve case insensitive paths on
3998 a filesystem which is case sensitive.  The use case is
3999 to resolve paths which you have read from Windows configuration
4000 files or the Windows Registry, to the true path.
4001
4002 The command handles a peculiarity of the Linux ntfs-3g
4003 filesystem driver (and probably others), which is that although
4004 the underlying filesystem is case-insensitive, the driver
4005 exports the filesystem to Linux as case-sensitive.
4006
4007 One consequence of this is that special directories such
4008 as C<c:\\windows> may appear as C</WINDOWS> or C</windows>
4009 (or other things) depending on the precise details of how
4010 they were created.  In Windows itself this would not be
4011 a problem.
4012
4013 Bug or feature?  You decide:
4014 L<http://www.tuxera.com/community/ntfs-3g-faq/#posixfilenames1>
4015
4016 This function resolves the true case of each element in the
4017 path and returns the case-sensitive path.
4018
4019 Thus C<guestfs_case_sensitive_path> (\"/Windows/System32\")
4020 might return C<\"/WINDOWS/system32\"> (the exact return value
4021 would depend on details of how the directories were originally
4022 created under Windows).
4023
4024 I<Note>:
4025 This function does not handle drive names, backslashes etc.
4026
4027 See also C<guestfs_realpath>.");
4028
4029   ("vfs_type", (RString "fstype", [Device "device"], []), 198, [],
4030    [InitBasicFS, Always, TestOutput (
4031       [["vfs_type"; "/dev/sda1"]], "ext2")],
4032    "get the Linux VFS type corresponding to a mounted device",
4033    "\
4034 This command gets the filesystem type corresponding to
4035 the filesystem on C<device>.
4036
4037 For most filesystems, the result is the name of the Linux
4038 VFS module which would be used to mount this filesystem
4039 if you mounted it without specifying the filesystem type.
4040 For example a string such as C<ext3> or C<ntfs>.");
4041
4042   ("truncate", (RErr, [Pathname "path"], []), 199, [],
4043    [InitBasicFS, Always, TestOutputStruct (
4044       [["write"; "/test"; "some stuff so size is not zero"];
4045        ["truncate"; "/test"];
4046        ["stat"; "/test"]], [CompareWithInt ("size", 0)])],
4047    "truncate a file to zero size",
4048    "\
4049 This command truncates C<path> to a zero-length file.  The
4050 file must exist already.");
4051
4052   ("truncate_size", (RErr, [Pathname "path"; Int64 "size"], []), 200, [],
4053    [InitBasicFS, Always, TestOutputStruct (
4054       [["touch"; "/test"];
4055        ["truncate_size"; "/test"; "1000"];
4056        ["stat"; "/test"]], [CompareWithInt ("size", 1000)])],
4057    "truncate a file to a particular size",
4058    "\
4059 This command truncates C<path> to size C<size> bytes.  The file
4060 must exist already.
4061
4062 If the current file size is less than C<size> then
4063 the file is extended to the required size with zero bytes.
4064 This creates a sparse file (ie. disk blocks are not allocated
4065 for the file until you write to it).  To create a non-sparse
4066 file of zeroes, use C<guestfs_fallocate64> instead.");
4067
4068   ("utimens", (RErr, [Pathname "path"; Int64 "atsecs"; Int64 "atnsecs"; Int64 "mtsecs"; Int64 "mtnsecs"], []), 201, [],
4069    [InitBasicFS, Always, TestOutputStruct (
4070       [["touch"; "/test"];
4071        ["utimens"; "/test"; "12345"; "67890"; "9876"; "5432"];
4072        ["stat"; "/test"]], [CompareWithInt ("mtime", 9876)])],
4073    "set timestamp of a file with nanosecond precision",
4074    "\
4075 This command sets the timestamps of a file with nanosecond
4076 precision.
4077
4078 C<atsecs, atnsecs> are the last access time (atime) in secs and
4079 nanoseconds from the epoch.
4080
4081 C<mtsecs, mtnsecs> are the last modification time (mtime) in
4082 secs and nanoseconds from the epoch.
4083
4084 If the C<*nsecs> field contains the special value C<-1> then
4085 the corresponding timestamp is set to the current time.  (The
4086 C<*secs> field is ignored in this case).
4087
4088 If the C<*nsecs> field contains the special value C<-2> then
4089 the corresponding timestamp is left unchanged.  (The
4090 C<*secs> field is ignored in this case).");
4091
4092   ("mkdir_mode", (RErr, [Pathname "path"; Int "mode"], []), 202, [],
4093    [InitBasicFS, Always, TestOutputStruct (
4094       [["mkdir_mode"; "/test"; "0o111"];
4095        ["stat"; "/test"]], [CompareWithInt ("mode", 0o40111)])],
4096    "create a directory with a particular mode",
4097    "\
4098 This command creates a directory, setting the initial permissions
4099 of the directory to C<mode>.
4100
4101 For common Linux filesystems, the actual mode which is set will
4102 be C<mode & ~umask & 01777>.  Non-native-Linux filesystems may
4103 interpret the mode in other ways.
4104
4105 See also C<guestfs_mkdir>, C<guestfs_umask>");
4106
4107   ("lchown", (RErr, [Int "owner"; Int "group"; Pathname "path"], []), 203, [],
4108    [], (* XXX *)
4109    "change file owner and group",
4110    "\
4111 Change the file owner to C<owner> and group to C<group>.
4112 This is like C<guestfs_chown> but if C<path> is a symlink then
4113 the link itself is changed, not the target.
4114
4115 Only numeric uid and gid are supported.  If you want to use
4116 names, you will need to locate and parse the password file
4117 yourself (Augeas support makes this relatively easy).");
4118
4119   ("lstatlist", (RStructList ("statbufs", "stat"), [Pathname "path"; StringList "names"], []), 204, [],
4120    [], (* XXX *)
4121    "lstat on multiple files",
4122    "\
4123 This call allows you to perform the C<guestfs_lstat> operation
4124 on multiple files, where all files are in the directory C<path>.
4125 C<names> is the list of files from this directory.
4126
4127 On return you get a list of stat structs, with a one-to-one
4128 correspondence to the C<names> list.  If any name did not exist
4129 or could not be lstat'd, then the C<ino> field of that structure
4130 is set to C<-1>.
4131
4132 This call is intended for programs that want to efficiently
4133 list a directory contents without making many round-trips.
4134 See also C<guestfs_lxattrlist> for a similarly efficient call
4135 for getting extended attributes.  Very long directory listings
4136 might cause the protocol message size to be exceeded, causing
4137 this call to fail.  The caller must split up such requests
4138 into smaller groups of names.");
4139
4140   ("lxattrlist", (RStructList ("xattrs", "xattr"), [Pathname "path"; StringList "names"], []), 205, [Optional "linuxxattrs"],
4141    [], (* XXX *)
4142    "lgetxattr on multiple files",
4143    "\
4144 This call allows you to get the extended attributes
4145 of multiple files, where all files are in the directory C<path>.
4146 C<names> is the list of files from this directory.
4147
4148 On return you get a flat list of xattr structs which must be
4149 interpreted sequentially.  The first xattr struct always has a zero-length
4150 C<attrname>.  C<attrval> in this struct is zero-length
4151 to indicate there was an error doing C<lgetxattr> for this
4152 file, I<or> is a C string which is a decimal number
4153 (the number of following attributes for this file, which could
4154 be C<\"0\">).  Then after the first xattr struct are the
4155 zero or more attributes for the first named file.
4156 This repeats for the second and subsequent files.
4157
4158 This call is intended for programs that want to efficiently
4159 list a directory contents without making many round-trips.
4160 See also C<guestfs_lstatlist> for a similarly efficient call
4161 for getting standard stats.  Very long directory listings
4162 might cause the protocol message size to be exceeded, causing
4163 this call to fail.  The caller must split up such requests
4164 into smaller groups of names.");
4165
4166   ("readlinklist", (RStringList "links", [Pathname "path"; StringList "names"], []), 206, [],
4167    [], (* XXX *)
4168    "readlink on multiple files",
4169    "\
4170 This call allows you to do a C<readlink> operation
4171 on multiple files, where all files are in the directory C<path>.
4172 C<names> is the list of files from this directory.
4173
4174 On return you get a list of strings, with a one-to-one
4175 correspondence to the C<names> list.  Each string is the
4176 value of the symbolic link.
4177
4178 If the C<readlink(2)> operation fails on any name, then
4179 the corresponding result string is the empty string C<\"\">.
4180 However the whole operation is completed even if there
4181 were C<readlink(2)> errors, and so you can call this
4182 function with names where you don't know if they are
4183 symbolic links already (albeit slightly less efficient).
4184
4185 This call is intended for programs that want to efficiently
4186 list a directory contents without making many round-trips.
4187 Very long directory listings might cause the protocol
4188 message size to be exceeded, causing
4189 this call to fail.  The caller must split up such requests
4190 into smaller groups of names.");
4191
4192   ("pread", (RBufferOut "content", [Pathname "path"; Int "count"; Int64 "offset"], []), 207, [ProtocolLimitWarning],
4193    [InitISOFS, Always, TestOutputBuffer (
4194       [["pread"; "/known-4"; "1"; "3"]], "\n");
4195     InitISOFS, Always, TestOutputBuffer (
4196       [["pread"; "/empty"; "0"; "100"]], "")],
4197    "read part of a file",
4198    "\
4199 This command lets you read part of a file.  It reads C<count>
4200 bytes of the file, starting at C<offset>, from file C<path>.
4201
4202 This may read fewer bytes than requested.  For further details
4203 see the L<pread(2)> system call.
4204
4205 See also C<guestfs_pwrite>, C<guestfs_pread_device>.");
4206
4207   ("part_init", (RErr, [Device "device"; String "parttype"], []), 208, [],
4208    [InitEmpty, Always, TestRun (
4209       [["part_init"; "/dev/sda"; "gpt"]])],
4210    "create an empty partition table",
4211    "\
4212 This creates an empty partition table on C<device> of one of the
4213 partition types listed below.  Usually C<parttype> should be
4214 either C<msdos> or C<gpt> (for large disks).
4215
4216 Initially there are no partitions.  Following this, you should
4217 call C<guestfs_part_add> for each partition required.
4218
4219 Possible values for C<parttype> are:
4220
4221 =over 4
4222
4223 =item B<efi> | B<gpt>
4224
4225 Intel EFI / GPT partition table.
4226
4227 This is recommended for >= 2 TB partitions that will be accessed
4228 from Linux and Intel-based Mac OS X.  It also has limited backwards
4229 compatibility with the C<mbr> format.
4230
4231 =item B<mbr> | B<msdos>
4232
4233 The standard PC \"Master Boot Record\" (MBR) format used
4234 by MS-DOS and Windows.  This partition type will B<only> work
4235 for device sizes up to 2 TB.  For large disks we recommend
4236 using C<gpt>.
4237
4238 =back
4239
4240 Other partition table types that may work but are not
4241 supported include:
4242
4243 =over 4
4244
4245 =item B<aix>
4246
4247 AIX disk labels.
4248
4249 =item B<amiga> | B<rdb>
4250
4251 Amiga \"Rigid Disk Block\" format.
4252
4253 =item B<bsd>
4254
4255 BSD disk labels.
4256
4257 =item B<dasd>
4258
4259 DASD, used on IBM mainframes.
4260
4261 =item B<dvh>
4262
4263 MIPS/SGI volumes.
4264
4265 =item B<mac>
4266
4267 Old Mac partition format.  Modern Macs use C<gpt>.
4268
4269 =item B<pc98>
4270
4271 NEC PC-98 format, common in Japan apparently.
4272
4273 =item B<sun>
4274
4275 Sun disk labels.
4276
4277 =back");
4278
4279   ("part_add", (RErr, [Device "device"; String "prlogex"; Int64 "startsect"; Int64 "endsect"], []), 209, [],
4280    [InitEmpty, Always, TestRun (
4281       [["part_init"; "/dev/sda"; "mbr"];
4282        ["part_add"; "/dev/sda"; "primary"; "1"; "-1"]]);
4283     InitEmpty, Always, TestRun (
4284       [["part_init"; "/dev/sda"; "gpt"];
4285        ["part_add"; "/dev/sda"; "primary"; "34"; "127"];
4286        ["part_add"; "/dev/sda"; "primary"; "128"; "-34"]]);
4287     InitEmpty, Always, TestRun (
4288       [["part_init"; "/dev/sda"; "mbr"];
4289        ["part_add"; "/dev/sda"; "primary"; "32"; "127"];
4290        ["part_add"; "/dev/sda"; "primary"; "128"; "255"];
4291        ["part_add"; "/dev/sda"; "primary"; "256"; "511"];
4292        ["part_add"; "/dev/sda"; "primary"; "512"; "-1"]])],
4293    "add a partition to the device",
4294    "\
4295 This command adds a partition to C<device>.  If there is no partition
4296 table on the device, call C<guestfs_part_init> first.
4297
4298 The C<prlogex> parameter is the type of partition.  Normally you
4299 should pass C<p> or C<primary> here, but MBR partition tables also
4300 support C<l> (or C<logical>) and C<e> (or C<extended>) partition
4301 types.
4302
4303 C<startsect> and C<endsect> are the start and end of the partition
4304 in I<sectors>.  C<endsect> may be negative, which means it counts
4305 backwards from the end of the disk (C<-1> is the last sector).
4306
4307 Creating a partition which covers the whole disk is not so easy.
4308 Use C<guestfs_part_disk> to do that.");
4309
4310   ("part_disk", (RErr, [Device "device"; String "parttype"], []), 210, [DangerWillRobinson],
4311    [InitEmpty, Always, TestRun (
4312       [["part_disk"; "/dev/sda"; "mbr"]]);
4313     InitEmpty, Always, TestRun (
4314       [["part_disk"; "/dev/sda"; "gpt"]])],
4315    "partition whole disk with a single primary partition",
4316    "\
4317 This command is simply a combination of C<guestfs_part_init>
4318 followed by C<guestfs_part_add> to create a single primary partition
4319 covering the whole disk.
4320
4321 C<parttype> is the partition table type, usually C<mbr> or C<gpt>,
4322 but other possible values are described in C<guestfs_part_init>.");
4323
4324   ("part_set_bootable", (RErr, [Device "device"; Int "partnum"; Bool "bootable"], []), 211, [],
4325    [InitEmpty, Always, TestRun (
4326       [["part_disk"; "/dev/sda"; "mbr"];
4327        ["part_set_bootable"; "/dev/sda"; "1"; "true"]])],
4328    "make a partition bootable",
4329    "\
4330 This sets the bootable flag on partition numbered C<partnum> on
4331 device C<device>.  Note that partitions are numbered from 1.
4332
4333 The bootable flag is used by some operating systems (notably
4334 Windows) to determine which partition to boot from.  It is by
4335 no means universally recognized.");
4336
4337   ("part_set_name", (RErr, [Device "device"; Int "partnum"; String "name"], []), 212, [],
4338    [InitEmpty, Always, TestRun (
4339       [["part_disk"; "/dev/sda"; "gpt"];
4340        ["part_set_name"; "/dev/sda"; "1"; "thepartname"]])],
4341    "set partition name",
4342    "\
4343 This sets the partition name on partition numbered C<partnum> on
4344 device C<device>.  Note that partitions are numbered from 1.
4345
4346 The partition name can only be set on certain types of partition
4347 table.  This works on C<gpt> but not on C<mbr> partitions.");
4348
4349   ("part_list", (RStructList ("partitions", "partition"), [Device "device"], []), 213, [],
4350    [], (* XXX Add a regression test for this. *)
4351    "list partitions on a device",
4352    "\
4353 This command parses the partition table on C<device> and
4354 returns the list of partitions found.
4355
4356 The fields in the returned structure are:
4357
4358 =over 4
4359
4360 =item B<part_num>
4361
4362 Partition number, counting from 1.
4363
4364 =item B<part_start>
4365
4366 Start of the partition I<in bytes>.  To get sectors you have to
4367 divide by the device's sector size, see C<guestfs_blockdev_getss>.
4368
4369 =item B<part_end>
4370
4371 End of the partition in bytes.
4372
4373 =item B<part_size>
4374
4375 Size of the partition in bytes.
4376
4377 =back");
4378
4379   ("part_get_parttype", (RString "parttype", [Device "device"], []), 214, [],
4380    [InitEmpty, Always, TestOutput (
4381       [["part_disk"; "/dev/sda"; "gpt"];
4382        ["part_get_parttype"; "/dev/sda"]], "gpt")],
4383    "get the partition table type",
4384    "\
4385 This command examines the partition table on C<device> and
4386 returns the partition table type (format) being used.
4387
4388 Common return values include: C<msdos> (a DOS/Windows style MBR
4389 partition table), C<gpt> (a GPT/EFI-style partition table).  Other
4390 values are possible, although unusual.  See C<guestfs_part_init>
4391 for a full list.");
4392
4393   ("fill", (RErr, [Int "c"; Int "len"; Pathname "path"], []), 215, [Progress],
4394    [InitBasicFS, Always, TestOutputBuffer (
4395       [["fill"; "0x63"; "10"; "/test"];
4396        ["read_file"; "/test"]], "cccccccccc")],
4397    "fill a file with octets",
4398    "\
4399 This command creates a new file called C<path>.  The initial
4400 content of the file is C<len> octets of C<c>, where C<c>
4401 must be a number in the range C<[0..255]>.
4402
4403 To fill a file with zero bytes (sparsely), it is
4404 much more efficient to use C<guestfs_truncate_size>.
4405 To create a file with a pattern of repeating bytes
4406 use C<guestfs_fill_pattern>.");
4407
4408   ("available", (RErr, [StringList "groups"], []), 216, [],
4409    [InitNone, Always, TestRun [["available"; ""]]],
4410    "test availability of some parts of the API",
4411    "\
4412 This command is used to check the availability of some
4413 groups of functionality in the appliance, which not all builds of
4414 the libguestfs appliance will be able to provide.
4415
4416 The libguestfs groups, and the functions that those
4417 groups correspond to, are listed in L<guestfs(3)/AVAILABILITY>.
4418 You can also fetch this list at runtime by calling
4419 C<guestfs_available_all_groups>.
4420
4421 The argument C<groups> is a list of group names, eg:
4422 C<[\"inotify\", \"augeas\"]> would check for the availability of
4423 the Linux inotify functions and Augeas (configuration file
4424 editing) functions.
4425
4426 The command returns no error if I<all> requested groups are available.
4427
4428 It fails with an error if one or more of the requested
4429 groups is unavailable in the appliance.
4430
4431 If an unknown group name is included in the
4432 list of groups then an error is always returned.
4433
4434 I<Notes:>
4435
4436 =over 4
4437
4438 =item *
4439
4440 You must call C<guestfs_launch> before calling this function.
4441
4442 The reason is because we don't know what groups are
4443 supported by the appliance/daemon until it is running and can
4444 be queried.
4445
4446 =item *
4447
4448 If a group of functions is available, this does not necessarily
4449 mean that they will work.  You still have to check for errors
4450 when calling individual API functions even if they are
4451 available.
4452
4453 =item *
4454
4455 It is usually the job of distro packagers to build
4456 complete functionality into the libguestfs appliance.
4457 Upstream libguestfs, if built from source with all
4458 requirements satisfied, will support everything.
4459
4460 =item *
4461
4462 This call was added in version C<1.0.80>.  In previous
4463 versions of libguestfs all you could do would be to speculatively
4464 execute a command to find out if the daemon implemented it.
4465 See also C<guestfs_version>.
4466
4467 =back");
4468
4469   ("dd", (RErr, [Dev_or_Path "src"; Dev_or_Path "dest"], []), 217, [],
4470    [InitBasicFS, Always, TestOutputBuffer (
4471       [["write"; "/src"; "hello, world"];
4472        ["dd"; "/src"; "/dest"];
4473        ["read_file"; "/dest"]], "hello, world")],
4474    "copy from source to destination using dd",
4475    "\
4476 This command copies from one source device or file C<src>
4477 to another destination device or file C<dest>.  Normally you
4478 would use this to copy to or from a device or partition, for
4479 example to duplicate a filesystem.
4480
4481 If the destination is a device, it must be as large or larger
4482 than the source file or device, otherwise the copy will fail.
4483 This command cannot do partial copies (see C<guestfs_copy_size>).");
4484
4485   ("filesize", (RInt64 "size", [Pathname "file"], []), 218, [],
4486    [InitBasicFS, Always, TestOutputInt (
4487       [["write"; "/file"; "hello, world"];
4488        ["filesize"; "/file"]], 12)],
4489    "return the size of the file in bytes",
4490    "\
4491 This command returns the size of C<file> in bytes.
4492
4493 To get other stats about a file, use C<guestfs_stat>, C<guestfs_lstat>,
4494 C<guestfs_is_dir>, C<guestfs_is_file> etc.
4495 To get the size of block devices, use C<guestfs_blockdev_getsize64>.");
4496
4497   ("lvrename", (RErr, [String "logvol"; String "newlogvol"], []), 219, [],
4498    [InitBasicFSonLVM, Always, TestOutputList (
4499       [["lvrename"; "/dev/VG/LV"; "/dev/VG/LV2"];
4500        ["lvs"]], ["/dev/VG/LV2"])],
4501    "rename an LVM logical volume",
4502    "\
4503 Rename a logical volume C<logvol> with the new name C<newlogvol>.");
4504
4505   ("vgrename", (RErr, [String "volgroup"; String "newvolgroup"], []), 220, [],
4506    [InitBasicFSonLVM, Always, TestOutputList (
4507       [["umount"; "/"];
4508        ["vg_activate"; "false"; "VG"];
4509        ["vgrename"; "VG"; "VG2"];
4510        ["vg_activate"; "true"; "VG2"];
4511        ["mount_options"; ""; "/dev/VG2/LV"; "/"];
4512        ["vgs"]], ["VG2"])],
4513    "rename an LVM volume group",
4514    "\
4515 Rename a volume group C<volgroup> with the new name C<newvolgroup>.");
4516
4517   ("initrd_cat", (RBufferOut "content", [Pathname "initrdpath"; String "filename"], []), 221, [ProtocolLimitWarning],
4518    [InitISOFS, Always, TestOutputBuffer (
4519       [["initrd_cat"; "/initrd"; "known-4"]], "abc\ndef\nghi")],
4520    "list the contents of a single file in an initrd",
4521    "\
4522 This command unpacks the file C<filename> from the initrd file
4523 called C<initrdpath>.  The filename must be given I<without> the
4524 initial C</> character.
4525
4526 For example, in guestfish you could use the following command
4527 to examine the boot script (usually called C</init>)
4528 contained in a Linux initrd or initramfs image:
4529
4530  initrd-cat /boot/initrd-<version>.img init
4531
4532 See also C<guestfs_initrd_list>.");
4533
4534   ("pvuuid", (RString "uuid", [Device "device"], []), 222, [],
4535    [],
4536    "get the UUID of a physical volume",
4537    "\
4538 This command returns the UUID of the LVM PV C<device>.");
4539
4540   ("vguuid", (RString "uuid", [String "vgname"], []), 223, [],
4541    [],
4542    "get the UUID of a volume group",
4543    "\
4544 This command returns the UUID of the LVM VG named C<vgname>.");
4545
4546   ("lvuuid", (RString "uuid", [Device "device"], []), 224, [],
4547    [],
4548    "get the UUID of a logical volume",
4549    "\
4550 This command returns the UUID of the LVM LV C<device>.");
4551
4552   ("vgpvuuids", (RStringList "uuids", [String "vgname"], []), 225, [],
4553    [],
4554    "get the PV UUIDs containing the volume group",
4555    "\
4556 Given a VG called C<vgname>, this returns the UUIDs of all
4557 the physical volumes that this volume group resides on.
4558
4559 You can use this along with C<guestfs_pvs> and C<guestfs_pvuuid>
4560 calls to associate physical volumes and volume groups.
4561
4562 See also C<guestfs_vglvuuids>.");
4563
4564   ("vglvuuids", (RStringList "uuids", [String "vgname"], []), 226, [],
4565    [],
4566    "get the LV UUIDs of all LVs in the volume group",
4567    "\
4568 Given a VG called C<vgname>, this returns the UUIDs of all
4569 the logical volumes created in this volume group.
4570
4571 You can use this along with C<guestfs_lvs> and C<guestfs_lvuuid>
4572 calls to associate logical volumes and volume groups.
4573
4574 See also C<guestfs_vgpvuuids>.");
4575
4576   ("copy_size", (RErr, [Dev_or_Path "src"; Dev_or_Path "dest"; Int64 "size"], []), 227, [Progress],
4577    [InitBasicFS, Always, TestOutputBuffer (
4578       [["write"; "/src"; "hello, world"];
4579        ["copy_size"; "/src"; "/dest"; "5"];
4580        ["read_file"; "/dest"]], "hello")],
4581    "copy size bytes from source to destination using dd",
4582    "\
4583 This command copies exactly C<size> bytes from one source device
4584 or file C<src> to another destination device or file C<dest>.
4585
4586 Note this will fail if the source is too short or if the destination
4587 is not large enough.");
4588
4589   ("zero_device", (RErr, [Device "device"], []), 228, [DangerWillRobinson; Progress],
4590    [InitBasicFSonLVM, Always, TestRun (
4591       [["zero_device"; "/dev/VG/LV"]])],
4592    "write zeroes to an entire device",
4593    "\
4594 This command writes zeroes over the entire C<device>.  Compare
4595 with C<guestfs_zero> which just zeroes the first few blocks of
4596 a device.");
4597
4598   ("txz_in", (RErr, [FileIn "tarball"; Pathname "directory"], []), 229, [Optional "xz"],
4599    [InitBasicFS, Always, TestOutput (
4600       [["txz_in"; "../images/helloworld.tar.xz"; "/"];
4601        ["cat"; "/hello"]], "hello\n")],
4602    "unpack compressed tarball to directory",
4603    "\
4604 This command uploads and unpacks local file C<tarball> (an
4605 I<xz compressed> tar file) into C<directory>.");
4606
4607   ("txz_out", (RErr, [Pathname "directory"; FileOut "tarball"], []), 230, [Optional "xz"],
4608    [],
4609    "pack directory into compressed tarball",
4610    "\
4611 This command packs the contents of C<directory> and downloads
4612 it to local file C<tarball> (as an xz compressed tar archive).");
4613
4614   ("ntfsresize", (RErr, [Device "device"], []), 231, [Optional "ntfsprogs"],
4615    [],
4616    "resize an NTFS filesystem",
4617    "\
4618 This command resizes an NTFS filesystem, expanding or
4619 shrinking it to the size of the underlying device.
4620 See also L<ntfsresize(8)>.");
4621
4622   ("vgscan", (RErr, [], []), 232, [],
4623    [InitEmpty, Always, TestRun (
4624       [["vgscan"]])],
4625    "rescan for LVM physical volumes, volume groups and logical volumes",
4626    "\
4627 This rescans all block devices and rebuilds the list of LVM
4628 physical volumes, volume groups and logical volumes.");
4629
4630   ("part_del", (RErr, [Device "device"; Int "partnum"], []), 233, [],
4631    [InitEmpty, Always, TestRun (
4632       [["part_init"; "/dev/sda"; "mbr"];
4633        ["part_add"; "/dev/sda"; "primary"; "1"; "-1"];
4634        ["part_del"; "/dev/sda"; "1"]])],
4635    "delete a partition",
4636    "\
4637 This command deletes the partition numbered C<partnum> on C<device>.
4638
4639 Note that in the case of MBR partitioning, deleting an
4640 extended partition also deletes any logical partitions
4641 it contains.");
4642
4643   ("part_get_bootable", (RBool "bootable", [Device "device"; Int "partnum"], []), 234, [],
4644    [InitEmpty, Always, TestOutputTrue (
4645       [["part_init"; "/dev/sda"; "mbr"];
4646        ["part_add"; "/dev/sda"; "primary"; "1"; "-1"];
4647        ["part_set_bootable"; "/dev/sda"; "1"; "true"];
4648        ["part_get_bootable"; "/dev/sda"; "1"]])],
4649    "return true if a partition is bootable",
4650    "\
4651 This command returns true if the partition C<partnum> on
4652 C<device> has the bootable flag set.
4653
4654 See also C<guestfs_part_set_bootable>.");
4655
4656   ("part_get_mbr_id", (RInt "idbyte", [Device "device"; Int "partnum"], []), 235, [FishOutput FishOutputHexadecimal],
4657    [InitEmpty, Always, TestOutputInt (
4658       [["part_init"; "/dev/sda"; "mbr"];
4659        ["part_add"; "/dev/sda"; "primary"; "1"; "-1"];
4660        ["part_set_mbr_id"; "/dev/sda"; "1"; "0x7f"];
4661        ["part_get_mbr_id"; "/dev/sda"; "1"]], 0x7f)],
4662    "get the MBR type byte (ID byte) from a partition",
4663    "\
4664 Returns the MBR type byte (also known as the ID byte) from
4665 the numbered partition C<partnum>.
4666
4667 Note that only MBR (old DOS-style) partitions have type bytes.
4668 You will get undefined results for other partition table
4669 types (see C<guestfs_part_get_parttype>).");
4670
4671   ("part_set_mbr_id", (RErr, [Device "device"; Int "partnum"; Int "idbyte"], []), 236, [],
4672    [], (* tested by part_get_mbr_id *)
4673    "set the MBR type byte (ID byte) of a partition",
4674    "\
4675 Sets the MBR type byte (also known as the ID byte) of
4676 the numbered partition C<partnum> to C<idbyte>.  Note
4677 that the type bytes quoted in most documentation are
4678 in fact hexadecimal numbers, but usually documented
4679 without any leading \"0x\" which might be confusing.
4680
4681 Note that only MBR (old DOS-style) partitions have type bytes.
4682 You will get undefined results for other partition table
4683 types (see C<guestfs_part_get_parttype>).");
4684
4685   ("checksum_device", (RString "checksum", [String "csumtype"; Device "device"], []), 237, [],
4686    [InitISOFS, Always, TestOutputFileMD5 (
4687       [["checksum_device"; "md5"; "/dev/sdd"]],
4688       "../images/test.iso")],
4689    "compute MD5, SHAx or CRC checksum of the contents of a device",
4690    "\
4691 This call computes the MD5, SHAx or CRC checksum of the
4692 contents of the device named C<device>.  For the types of
4693 checksums supported see the C<guestfs_checksum> command.");
4694
4695   ("lvresize_free", (RErr, [Device "lv"; Int "percent"], []), 238, [Optional "lvm2"],
4696    [InitNone, Always, TestRun (
4697       [["part_disk"; "/dev/sda"; "mbr"];
4698        ["pvcreate"; "/dev/sda1"];
4699        ["vgcreate"; "VG"; "/dev/sda1"];
4700        ["lvcreate"; "LV"; "VG"; "10"];
4701        ["lvresize_free"; "/dev/VG/LV"; "100"]])],
4702    "expand an LV to fill free space",
4703    "\
4704 This expands an existing logical volume C<lv> so that it fills
4705 C<pc>% of the remaining free space in the volume group.  Commonly
4706 you would call this with pc = 100 which expands the logical volume
4707 as much as possible, using all remaining free space in the volume
4708 group.");
4709
4710   ("aug_clear", (RErr, [String "augpath"], []), 239, [Optional "augeas"],
4711    [], (* XXX Augeas code needs tests. *)
4712    "clear Augeas path",
4713    "\
4714 Set the value associated with C<path> to C<NULL>.  This
4715 is the same as the L<augtool(1)> C<clear> command.");
4716
4717   ("get_umask", (RInt "mask", [], []), 240, [FishOutput FishOutputOctal],
4718    [InitEmpty, Always, TestOutputInt (
4719       [["get_umask"]], 0o22)],
4720    "get the current umask",
4721    "\
4722 Return the current umask.  By default the umask is C<022>
4723 unless it has been set by calling C<guestfs_umask>.");
4724
4725   ("debug_upload", (RErr, [FileIn "filename"; String "tmpname"; Int "mode"], []), 241, [],
4726    [],
4727    "upload a file to the appliance (internal use only)",
4728    "\
4729 The C<guestfs_debug_upload> command uploads a file to
4730 the libguestfs appliance.
4731
4732 There is no comprehensive help for this command.  You have
4733 to look at the file C<daemon/debug.c> in the libguestfs source
4734 to find out what it is for.");
4735
4736   ("base64_in", (RErr, [FileIn "base64file"; Pathname "filename"], []), 242, [],
4737    [InitBasicFS, Always, TestOutput (
4738       [["base64_in"; "../images/hello.b64"; "/hello"];
4739        ["cat"; "/hello"]], "hello\n")],
4740    "upload base64-encoded data to file",
4741    "\
4742 This command uploads base64-encoded data from C<base64file>
4743 to C<filename>.");
4744
4745   ("base64_out", (RErr, [Pathname "filename"; FileOut "base64file"], []), 243, [],
4746    [],
4747    "download file and encode as base64",
4748    "\
4749 This command downloads the contents of C<filename>, writing
4750 it out to local file C<base64file> encoded as base64.");
4751
4752   ("checksums_out", (RErr, [String "csumtype"; Pathname "directory"; FileOut "sumsfile"], []), 244, [],
4753    [],
4754    "compute MD5, SHAx or CRC checksum of files in a directory",
4755    "\
4756 This command computes the checksums of all regular files in
4757 C<directory> and then emits a list of those checksums to
4758 the local output file C<sumsfile>.
4759
4760 This can be used for verifying the integrity of a virtual
4761 machine.  However to be properly secure you should pay
4762 attention to the output of the checksum command (it uses
4763 the ones from GNU coreutils).  In particular when the
4764 filename is not printable, coreutils uses a special
4765 backslash syntax.  For more information, see the GNU
4766 coreutils info file.");
4767
4768   ("fill_pattern", (RErr, [String "pattern"; Int "len"; Pathname "path"], []), 245, [Progress],
4769    [InitBasicFS, Always, TestOutputBuffer (
4770       [["fill_pattern"; "abcdefghijklmnopqrstuvwxyz"; "28"; "/test"];
4771        ["read_file"; "/test"]], "abcdefghijklmnopqrstuvwxyzab")],
4772    "fill a file with a repeating pattern of bytes",
4773    "\
4774 This function is like C<guestfs_fill> except that it creates
4775 a new file of length C<len> containing the repeating pattern
4776 of bytes in C<pattern>.  The pattern is truncated if necessary
4777 to ensure the length of the file is exactly C<len> bytes.");
4778
4779   ("write", (RErr, [Pathname "path"; BufferIn "content"], []), 246, [ProtocolLimitWarning],
4780    [InitBasicFS, Always, TestOutput (
4781       [["write"; "/new"; "new file contents"];
4782        ["cat"; "/new"]], "new file contents");
4783     InitBasicFS, Always, TestOutput (
4784       [["write"; "/new"; "\nnew file contents\n"];
4785        ["cat"; "/new"]], "\nnew file contents\n");
4786     InitBasicFS, Always, TestOutput (
4787       [["write"; "/new"; "\n\n"];
4788        ["cat"; "/new"]], "\n\n");
4789     InitBasicFS, Always, TestOutput (
4790       [["write"; "/new"; ""];
4791        ["cat"; "/new"]], "");
4792     InitBasicFS, Always, TestOutput (
4793       [["write"; "/new"; "\n\n\n"];
4794        ["cat"; "/new"]], "\n\n\n");
4795     InitBasicFS, Always, TestOutput (
4796       [["write"; "/new"; "\n"];
4797        ["cat"; "/new"]], "\n")],
4798    "create a new file",
4799    "\
4800 This call creates a file called C<path>.  The content of the
4801 file is the string C<content> (which can contain any 8 bit data).");
4802
4803   ("pwrite", (RInt "nbytes", [Pathname "path"; BufferIn "content"; Int64 "offset"], []), 247, [ProtocolLimitWarning],
4804    [InitBasicFS, Always, TestOutput (
4805       [["write"; "/new"; "new file contents"];
4806        ["pwrite"; "/new"; "data"; "4"];
4807        ["cat"; "/new"]], "new data contents");
4808     InitBasicFS, Always, TestOutput (
4809       [["write"; "/new"; "new file contents"];
4810        ["pwrite"; "/new"; "is extended"; "9"];
4811        ["cat"; "/new"]], "new file is extended");
4812     InitBasicFS, Always, TestOutput (
4813       [["write"; "/new"; "new file contents"];
4814        ["pwrite"; "/new"; ""; "4"];
4815        ["cat"; "/new"]], "new file contents")],
4816    "write to part of a file",
4817    "\
4818 This command writes to part of a file.  It writes the data
4819 buffer C<content> to the file C<path> starting at offset C<offset>.
4820
4821 This command implements the L<pwrite(2)> system call, and like
4822 that system call it may not write the full data requested.  The
4823 return value is the number of bytes that were actually written
4824 to the file.  This could even be 0, although short writes are
4825 unlikely for regular files in ordinary circumstances.
4826
4827 See also C<guestfs_pread>, C<guestfs_pwrite_device>.");
4828
4829   ("resize2fs_size", (RErr, [Device "device"; Int64 "size"], []), 248, [],
4830    [],
4831    "resize an ext2, ext3 or ext4 filesystem (with size)",
4832    "\
4833 This command is the same as C<guestfs_resize2fs> except that it
4834 allows you to specify the new size (in bytes) explicitly.");
4835
4836   ("pvresize_size", (RErr, [Device "device"; Int64 "size"], []), 249, [Optional "lvm2"],
4837    [],
4838    "resize an LVM physical volume (with size)",
4839    "\
4840 This command is the same as C<guestfs_pvresize> except that it
4841 allows you to specify the new size (in bytes) explicitly.");
4842
4843   ("ntfsresize_size", (RErr, [Device "device"; Int64 "size"], []), 250, [Optional "ntfsprogs"],
4844    [],
4845    "resize an NTFS filesystem (with size)",
4846    "\
4847 This command is the same as C<guestfs_ntfsresize> except that it
4848 allows you to specify the new size (in bytes) explicitly.");
4849
4850   ("available_all_groups", (RStringList "groups", [], []), 251, [],
4851    [InitNone, Always, TestRun [["available_all_groups"]]],
4852    "return a list of all optional groups",
4853    "\
4854 This command returns a list of all optional groups that this
4855 daemon knows about.  Note this returns both supported and unsupported
4856 groups.  To find out which ones the daemon can actually support
4857 you have to call C<guestfs_available> on each member of the
4858 returned list.
4859
4860 See also C<guestfs_available> and L<guestfs(3)/AVAILABILITY>.");
4861
4862   ("fallocate64", (RErr, [Pathname "path"; Int64 "len"], []), 252, [],
4863    [InitBasicFS, Always, TestOutputStruct (
4864       [["fallocate64"; "/a"; "1000000"];
4865        ["stat"; "/a"]], [CompareWithInt ("size", 1_000_000)])],
4866    "preallocate a file in the guest filesystem",
4867    "\
4868 This command preallocates a file (containing zero bytes) named
4869 C<path> of size C<len> bytes.  If the file exists already, it
4870 is overwritten.
4871
4872 Note that this call allocates disk blocks for the file.
4873 To create a sparse file use C<guestfs_truncate_size> instead.
4874
4875 The deprecated call C<guestfs_fallocate> does the same,
4876 but owing to an oversight it only allowed 30 bit lengths
4877 to be specified, effectively limiting the maximum size
4878 of files created through that call to 1GB.
4879
4880 Do not confuse this with the guestfish-specific
4881 C<alloc> and C<sparse> commands which create
4882 a file in the host and attach it as a device.");
4883
4884   ("vfs_label", (RString "label", [Device "device"], []), 253, [],
4885    [InitBasicFS, Always, TestOutput (
4886        [["set_e2label"; "/dev/sda1"; "LTEST"];
4887         ["vfs_label"; "/dev/sda1"]], "LTEST")],
4888    "get the filesystem label",
4889    "\
4890 This returns the filesystem label of the filesystem on
4891 C<device>.
4892
4893 If the filesystem is unlabeled, this returns the empty string.
4894
4895 To find a filesystem from the label, use C<guestfs_findfs_label>.");
4896
4897   ("vfs_uuid", (RString "uuid", [Device "device"], []), 254, [],
4898    (let uuid = uuidgen () in
4899     [InitBasicFS, Always, TestOutput (
4900        [["set_e2uuid"; "/dev/sda1"; uuid];
4901         ["vfs_uuid"; "/dev/sda1"]], uuid)]),
4902    "get the filesystem UUID",
4903    "\
4904 This returns the filesystem UUID of the filesystem on
4905 C<device>.
4906
4907 If the filesystem does not have a UUID, this returns the empty string.
4908
4909 To find a filesystem from the UUID, use C<guestfs_findfs_uuid>.");
4910
4911   ("lvm_set_filter", (RErr, [DeviceList "devices"], []), 255, [Optional "lvm2"],
4912    (* Can't be tested with the current framework because
4913     * the VG is being used by the mounted filesystem, so
4914     * the vgchange -an command we do first will fail.
4915     *)
4916     [],
4917    "set LVM device filter",
4918    "\
4919 This sets the LVM device filter so that LVM will only be
4920 able to \"see\" the block devices in the list C<devices>,
4921 and will ignore all other attached block devices.
4922
4923 Where disk image(s) contain duplicate PVs or VGs, this
4924 command is useful to get LVM to ignore the duplicates, otherwise
4925 LVM can get confused.  Note also there are two types
4926 of duplication possible: either cloned PVs/VGs which have
4927 identical UUIDs; or VGs that are not cloned but just happen
4928 to have the same name.  In normal operation you cannot
4929 create this situation, but you can do it outside LVM, eg.
4930 by cloning disk images or by bit twiddling inside the LVM
4931 metadata.
4932
4933 This command also clears the LVM cache and performs a volume
4934 group scan.
4935
4936 You can filter whole block devices or individual partitions.
4937
4938 You cannot use this if any VG is currently in use (eg.
4939 contains a mounted filesystem), even if you are not
4940 filtering out that VG.");
4941
4942   ("lvm_clear_filter", (RErr, [], []), 256, [],
4943    [], (* see note on lvm_set_filter *)
4944    "clear LVM device filter",
4945    "\
4946 This undoes the effect of C<guestfs_lvm_set_filter>.  LVM
4947 will be able to see every block device.
4948
4949 This command also clears the LVM cache and performs a volume
4950 group scan.");
4951
4952   ("luks_open", (RErr, [Device "device"; Key "key"; String "mapname"], []), 257, [Optional "luks"],
4953    [],
4954    "open a LUKS-encrypted block device",
4955    "\
4956 This command opens a block device which has been encrypted
4957 according to the Linux Unified Key Setup (LUKS) standard.
4958
4959 C<device> is the encrypted block device or partition.
4960
4961 The caller must supply one of the keys associated with the
4962 LUKS block device, in the C<key> parameter.
4963
4964 This creates a new block device called C</dev/mapper/mapname>.
4965 Reads and writes to this block device are decrypted from and
4966 encrypted to the underlying C<device> respectively.
4967
4968 If this block device contains LVM volume groups, then
4969 calling C<guestfs_vgscan> followed by C<guestfs_vg_activate_all>
4970 will make them visible.");
4971
4972   ("luks_open_ro", (RErr, [Device "device"; Key "key"; String "mapname"], []), 258, [Optional "luks"],
4973    [],
4974    "open a LUKS-encrypted block device read-only",
4975    "\
4976 This is the same as C<guestfs_luks_open> except that a read-only
4977 mapping is created.");
4978
4979   ("luks_close", (RErr, [Device "device"], []), 259, [Optional "luks"],
4980    [],
4981    "close a LUKS device",
4982    "\
4983 This closes a LUKS device that was created earlier by
4984 C<guestfs_luks_open> or C<guestfs_luks_open_ro>.  The
4985 C<device> parameter must be the name of the LUKS mapping
4986 device (ie. C</dev/mapper/mapname>) and I<not> the name
4987 of the underlying block device.");
4988
4989   ("luks_format", (RErr, [Device "device"; Key "key"; Int "keyslot"], []), 260, [Optional "luks"; DangerWillRobinson],
4990    [],
4991    "format a block device as a LUKS encrypted device",
4992    "\
4993 This command erases existing data on C<device> and formats
4994 the device as a LUKS encrypted device.  C<key> is the
4995 initial key, which is added to key slot C<slot>.  (LUKS
4996 supports 8 key slots, numbered 0-7).");
4997
4998   ("luks_format_cipher", (RErr, [Device "device"; Key "key"; Int "keyslot"; String "cipher"], []), 261, [Optional "luks"; DangerWillRobinson],
4999    [],
5000    "format a block device as a LUKS encrypted device",
5001    "\
5002 This command is the same as C<guestfs_luks_format> but
5003 it also allows you to set the C<cipher> used.");
5004
5005   ("luks_add_key", (RErr, [Device "device"; Key "key"; Key "newkey"; Int "keyslot"], []), 262, [Optional "luks"],
5006    [],
5007    "add a key on a LUKS encrypted device",
5008    "\
5009 This command adds a new key on LUKS device C<device>.
5010 C<key> is any existing key, and is used to access the device.
5011 C<newkey> is the new key to add.  C<keyslot> is the key slot
5012 that will be replaced.
5013
5014 Note that if C<keyslot> already contains a key, then this
5015 command will fail.  You have to use C<guestfs_luks_kill_slot>
5016 first to remove that key.");
5017
5018   ("luks_kill_slot", (RErr, [Device "device"; Key "key"; Int "keyslot"], []), 263, [Optional "luks"],
5019    [],
5020    "remove a key from a LUKS encrypted device",
5021    "\
5022 This command deletes the key in key slot C<keyslot> from the
5023 encrypted LUKS device C<device>.  C<key> must be one of the
5024 I<other> keys.");
5025
5026   ("is_lv", (RBool "lvflag", [Device "device"], []), 264, [Optional "lvm2"],
5027    [InitBasicFSonLVM, IfAvailable "lvm2", TestOutputTrue (
5028       [["is_lv"; "/dev/VG/LV"]]);
5029     InitBasicFSonLVM, IfAvailable "lvm2", TestOutputFalse (
5030       [["is_lv"; "/dev/sda1"]])],
5031    "test if device is a logical volume",
5032    "\
5033 This command tests whether C<device> is a logical volume, and
5034 returns true iff this is the case.");
5035
5036   ("findfs_uuid", (RString "device", [String "uuid"], []), 265, [],
5037    [],
5038    "find a filesystem by UUID",
5039    "\
5040 This command searches the filesystems and returns the one
5041 which has the given UUID.  An error is returned if no such
5042 filesystem can be found.
5043
5044 To find the UUID of a filesystem, use C<guestfs_vfs_uuid>.");
5045
5046   ("findfs_label", (RString "device", [String "label"], []), 266, [],
5047    [],
5048    "find a filesystem by label",
5049    "\
5050 This command searches the filesystems and returns the one
5051 which has the given label.  An error is returned if no such
5052 filesystem can be found.
5053
5054 To find the label of a filesystem, use C<guestfs_vfs_label>.");
5055
5056   ("is_chardev", (RBool "flag", [Pathname "path"], []), 267, [],
5057    [InitISOFS, Always, TestOutputFalse (
5058       [["is_chardev"; "/directory"]]);
5059     InitBasicFS, Always, TestOutputTrue (
5060       [["mknod_c"; "0o777"; "99"; "66"; "/test"];
5061        ["is_chardev"; "/test"]])],
5062    "test if character device",
5063    "\
5064 This returns C<true> if and only if there is a character device
5065 with the given C<path> name.
5066
5067 See also C<guestfs_stat>.");
5068
5069   ("is_blockdev", (RBool "flag", [Pathname "path"], []), 268, [],
5070    [InitISOFS, Always, TestOutputFalse (
5071       [["is_blockdev"; "/directory"]]);
5072     InitBasicFS, Always, TestOutputTrue (
5073       [["mknod_b"; "0o777"; "99"; "66"; "/test"];
5074        ["is_blockdev"; "/test"]])],
5075    "test if block device",
5076    "\
5077 This returns C<true> if and only if there is a block device
5078 with the given C<path> name.
5079
5080 See also C<guestfs_stat>.");
5081
5082   ("is_fifo", (RBool "flag", [Pathname "path"], []), 269, [],
5083    [InitISOFS, Always, TestOutputFalse (
5084       [["is_fifo"; "/directory"]]);
5085     InitBasicFS, Always, TestOutputTrue (
5086       [["mkfifo"; "0o777"; "/test"];
5087        ["is_fifo"; "/test"]])],
5088    "test if FIFO (named pipe)",
5089    "\
5090 This returns C<true> if and only if there is a FIFO (named pipe)
5091 with the given C<path> name.
5092
5093 See also C<guestfs_stat>.");
5094
5095   ("is_symlink", (RBool "flag", [Pathname "path"], []), 270, [],
5096    [InitISOFS, Always, TestOutputFalse (
5097       [["is_symlink"; "/directory"]]);
5098     InitISOFS, Always, TestOutputTrue (
5099       [["is_symlink"; "/abssymlink"]])],
5100    "test if symbolic link",
5101    "\
5102 This returns C<true> if and only if there is a symbolic link
5103 with the given C<path> name.
5104
5105 See also C<guestfs_stat>.");
5106
5107   ("is_socket", (RBool "flag", [Pathname "path"], []), 271, [],
5108    (* XXX Need a positive test for sockets. *)
5109    [InitISOFS, Always, TestOutputFalse (
5110       [["is_socket"; "/directory"]])],
5111    "test if socket",
5112    "\
5113 This returns C<true> if and only if there is a Unix domain socket
5114 with the given C<path> name.
5115
5116 See also C<guestfs_stat>.");
5117
5118   ("part_to_dev", (RString "device", [Device "partition"], []), 272, [],
5119    [InitPartition, Always, TestOutputDevice (
5120       [["part_to_dev"; "/dev/sda1"]], "/dev/sda");
5121     InitEmpty, Always, TestLastFail (
5122       [["part_to_dev"; "/dev/sda"]])],
5123    "convert partition name to device name",
5124    "\
5125 This function takes a partition name (eg. \"/dev/sdb1\") and
5126 removes the partition number, returning the device name
5127 (eg. \"/dev/sdb\").
5128
5129 The named partition must exist, for example as a string returned
5130 from C<guestfs_list_partitions>.");
5131
5132   ("upload_offset", (RErr, [FileIn "filename"; Dev_or_Path "remotefilename"; Int64 "offset"], []), 273, [],
5133    (let md5 = Digest.to_hex (Digest.file "COPYING.LIB") in
5134     [InitBasicFS, Always, TestOutput (
5135        [["upload_offset"; "../COPYING.LIB"; "/COPYING.LIB"; "0"];
5136         ["checksum"; "md5"; "/COPYING.LIB"]], md5)]),
5137    "upload a file from the local machine with offset",
5138    "\
5139 Upload local file C<filename> to C<remotefilename> on the
5140 filesystem.
5141
5142 C<remotefilename> is overwritten starting at the byte C<offset>
5143 specified.  The intention is to overwrite parts of existing
5144 files or devices, although if a non-existant file is specified
5145 then it is created with a \"hole\" before C<offset>.  The
5146 size of the data written is implicit in the size of the
5147 source C<filename>.
5148
5149 Note that there is no limit on the amount of data that
5150 can be uploaded with this call, unlike with C<guestfs_pwrite>,
5151 and this call always writes the full amount unless an
5152 error occurs.
5153
5154 See also C<guestfs_upload>, C<guestfs_pwrite>.");
5155
5156   ("download_offset", (RErr, [Dev_or_Path "remotefilename"; FileOut "filename"; Int64 "offset"; Int64 "size"], []), 274, [Progress],
5157    (let md5 = Digest.to_hex (Digest.file "COPYING.LIB") in
5158     let offset = string_of_int 100 in
5159     let size = string_of_int ((Unix.stat "COPYING.LIB").Unix.st_size - 100) in
5160     [InitBasicFS, Always, TestOutput (
5161        (* Pick a file from cwd which isn't likely to change. *)
5162        [["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
5163         ["download_offset"; "/COPYING.LIB"; "testdownload.tmp"; offset; size];
5164         ["upload_offset"; "testdownload.tmp"; "/COPYING.LIB"; offset];
5165         ["checksum"; "md5"; "/COPYING.LIB"]], md5)]),
5166    "download a file to the local machine with offset and size",
5167    "\
5168 Download file C<remotefilename> and save it as C<filename>
5169 on the local machine.
5170
5171 C<remotefilename> is read for C<size> bytes starting at C<offset>
5172 (this region must be within the file or device).
5173
5174 Note that there is no limit on the amount of data that
5175 can be downloaded with this call, unlike with C<guestfs_pread>,
5176 and this call always reads the full amount unless an
5177 error occurs.
5178
5179 See also C<guestfs_download>, C<guestfs_pread>.");
5180
5181   ("pwrite_device", (RInt "nbytes", [Device "device"; BufferIn "content"; Int64 "offset"], []), 275, [ProtocolLimitWarning],
5182    [InitPartition, Always, TestOutputList (
5183       [["pwrite_device"; "/dev/sda"; "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"; "446"];
5184        ["blockdev_rereadpt"; "/dev/sda"];
5185        ["list_partitions"]], [])],
5186    "write to part of a device",
5187    "\
5188 This command writes to part of a device.  It writes the data
5189 buffer C<content> to C<device> starting at offset C<offset>.
5190
5191 This command implements the L<pwrite(2)> system call, and like
5192 that system call it may not write the full data requested
5193 (although short writes to disk devices and partitions are
5194 probably impossible with standard Linux kernels).
5195
5196 See also C<guestfs_pwrite>.");
5197
5198   ("pread_device", (RBufferOut "content", [Device "device"; Int "count"; Int64 "offset"], []), 276, [ProtocolLimitWarning],
5199    [InitEmpty, Always, TestOutputBuffer (
5200       [["pread_device"; "/dev/sdd"; "8"; "32768"]], "\001CD001\001\000")],
5201    "read part of a device",
5202    "\
5203 This command lets you read part of a file.  It reads C<count>
5204 bytes of C<device>, starting at C<offset>.
5205
5206 This may read fewer bytes than requested.  For further details
5207 see the L<pread(2)> system call.
5208
5209 See also C<guestfs_pread>.");
5210
5211   ("lvm_canonical_lv_name", (RString "lv", [Device "lvname"], []), 277, [],
5212    [InitBasicFSonLVM, IfAvailable "lvm2", TestOutput (
5213     [["lvm_canonical_lv_name"; "/dev/mapper/VG-LV"]], "/dev/VG/LV");
5214     InitBasicFSonLVM, IfAvailable "lvm2", TestOutput (
5215     [["lvm_canonical_lv_name"; "/dev/VG/LV"]], "/dev/VG/LV")],
5216    "get canonical name of an LV",
5217    "\
5218 This converts alternative naming schemes for LVs that you
5219 might find to the canonical name.  For example, C</dev/mapper/VG-LV>
5220 is converted to C</dev/VG/LV>.
5221
5222 This command returns an error if the C<lvname> parameter does
5223 not refer to a logical volume.
5224
5225 See also C<guestfs_is_lv>.");
5226
5227 ]
5228
5229 let all_functions = non_daemon_functions @ daemon_functions
5230
5231 (* In some places we want the functions to be displayed sorted
5232  * alphabetically, so this is useful:
5233  *)
5234 let all_functions_sorted = List.sort action_compare all_functions
5235
5236 (* This is used to generate the src/MAX_PROC_NR file which
5237  * contains the maximum procedure number, a surrogate for the
5238  * ABI version number.  See src/Makefile.am for the details.
5239  *)
5240 let max_proc_nr =
5241   let proc_nrs = List.map (
5242     fun (_, _, proc_nr, _, _, _, _) -> proc_nr
5243   ) daemon_functions in
5244   List.fold_left max 0 proc_nrs
5245
5246 (* Non-API meta-commands available only in guestfish.
5247  *
5248  * Note (1): style, proc_nr and tests fields are all meaningless.
5249  * The only fields which are actually used are the shortname,
5250  * FishAlias flags, shortdesc and longdesc.
5251  *
5252  * Note (2): to refer to other commands, use L</shortname>.
5253  *
5254  * Note (3): keep this list sorted by shortname.
5255  *)
5256 let fish_commands = [
5257   ("alloc", (RErr,[], []), -1, [FishAlias "allocate"], [],
5258    "allocate and add a disk file",
5259    " alloc filename size
5260
5261 This creates an empty (zeroed) file of the given size, and then adds
5262 so it can be further examined.
5263
5264 For more advanced image creation, see L<qemu-img(1)> utility.
5265
5266 Size can be specified using standard suffixes, eg. C<1M>.
5267
5268 To create a sparse file, use L</sparse> instead.  To create a
5269 prepared disk image, see L</PREPARED DISK IMAGES>.");
5270
5271   ("copy_in", (RErr,[], []), -1, [], [],
5272    "copy local files or directories into an image",
5273    " copy-in local [local ...] /remotedir
5274
5275 C<copy-in> copies local files or directories recursively into the disk
5276 image, placing them in the directory called C</remotedir> (which must
5277 exist).  This guestfish meta-command turns into a sequence of
5278 L</tar-in> and other commands as necessary.
5279
5280 Multiple local files and directories can be specified, but the last
5281 parameter must always be a remote directory.  Wildcards cannot be
5282 used.");
5283
5284   ("copy_out", (RErr,[], []), -1, [], [],
5285    "copy remote files or directories out of an image",
5286    " copy-out remote [remote ...] localdir
5287
5288 C<copy-out> copies remote files or directories recursively out of the
5289 disk image, placing them on the host disk in a local directory called
5290 C<localdir> (which must exist).  This guestfish meta-command turns
5291 into a sequence of L</download>, L</tar-out> and other commands as
5292 necessary.
5293
5294 Multiple remote files and directories can be specified, but the last
5295 parameter must always be a local directory.  To download to the
5296 current directory, use C<.> as in:
5297
5298  copy-out /home .
5299
5300 Wildcards cannot be used in the ordinary command, but you can use
5301 them with the help of L</glob> like this:
5302
5303  glob copy-out /home/* .");
5304
5305   ("echo", (RErr,[], []), -1, [], [],
5306    "display a line of text",
5307    " echo [params ...]
5308
5309 This echos the parameters to the terminal.");
5310
5311   ("edit", (RErr,[], []), -1, [FishAlias "vi"; FishAlias "emacs"], [],
5312    "edit a file",
5313    " edit filename
5314
5315 This is used to edit a file.  It downloads the file, edits it
5316 locally using your editor, then uploads the result.
5317
5318 The editor is C<$EDITOR>.  However if you use the alternate
5319 commands C<vi> or C<emacs> you will get those corresponding
5320 editors.");
5321
5322   ("glob", (RErr,[], []), -1, [], [],
5323    "expand wildcards in command",
5324    " glob command args...
5325
5326 Expand wildcards in any paths in the args list, and run C<command>
5327 repeatedly on each matching path.
5328
5329 See L</WILDCARDS AND GLOBBING>.");
5330
5331   ("hexedit", (RErr,[], []), -1, [], [],
5332    "edit with a hex editor",
5333    " hexedit <filename|device>
5334  hexedit <filename|device> <max>
5335  hexedit <filename|device> <start> <max>
5336
5337 Use hexedit (a hex editor) to edit all or part of a binary file
5338 or block device.
5339
5340 This command works by downloading potentially the whole file or
5341 device, editing it locally, then uploading it.  If the file or
5342 device is large, you have to specify which part you wish to edit
5343 by using C<max> and/or C<start> C<max> parameters.
5344 C<start> and C<max> are specified in bytes, with the usual
5345 modifiers allowed such as C<1M> (1 megabyte).
5346
5347 For example to edit the first few sectors of a disk you
5348 might do:
5349
5350  hexedit /dev/sda 1M
5351
5352 which would allow you to edit anywhere within the first megabyte
5353 of the disk.
5354
5355 To edit the superblock of an ext2 filesystem on C</dev/sda1>, do:
5356
5357  hexedit /dev/sda1 0x400 0x400
5358
5359 (assuming the superblock is in the standard location).
5360
5361 This command requires the external L<hexedit(1)> program.  You
5362 can specify another program to use by setting the C<HEXEDITOR>
5363 environment variable.
5364
5365 See also L</hexdump>.");
5366
5367   ("lcd", (RErr,[], []), -1, [], [],
5368    "change working directory",
5369    " lcd directory
5370
5371 Change the local directory, ie. the current directory of guestfish
5372 itself.
5373
5374 Note that C<!cd> won't do what you might expect.");
5375
5376   ("man", (RErr,[], []), -1, [FishAlias "manual"], [],
5377    "open the manual",
5378    "  man
5379
5380 Opens the manual page for guestfish.");
5381
5382   ("more", (RErr,[], []), -1, [FishAlias "less"], [],
5383    "view a file",
5384    " more filename
5385
5386  less filename
5387
5388 This is used to view a file.
5389
5390 The default viewer is C<$PAGER>.  However if you use the alternate
5391 command C<less> you will get the C<less> command specifically.");
5392
5393   ("reopen", (RErr,[], []), -1, [], [],
5394    "close and reopen libguestfs handle",
5395    "  reopen
5396
5397 Close and reopen the libguestfs handle.  It is not necessary to use
5398 this normally, because the handle is closed properly when guestfish
5399 exits.  However this is occasionally useful for testing.");
5400
5401   ("sparse", (RErr,[], []), -1, [], [],
5402    "create a sparse disk image and add",
5403    " sparse filename size
5404
5405 This creates an empty sparse file of the given size, and then adds
5406 so it can be further examined.
5407
5408 In all respects it works the same as the L</alloc> command, except that
5409 the image file is allocated sparsely, which means that disk blocks are
5410 not assigned to the file until they are needed.  Sparse disk files
5411 only use space when written to, but they are slower and there is a
5412 danger you could run out of real disk space during a write operation.
5413
5414 For more advanced image creation, see L<qemu-img(1)> utility.
5415
5416 Size can be specified using standard suffixes, eg. C<1M>.");
5417
5418   ("supported", (RErr,[], []), -1, [], [],
5419    "list supported groups of commands",
5420    " supported
5421
5422 This command returns a list of the optional groups
5423 known to the daemon, and indicates which ones are
5424 supported by this build of the libguestfs appliance.
5425
5426 See also L<guestfs(3)/AVAILABILITY>.");
5427
5428   ("time", (RErr,[], []), -1, [], [],
5429    "print elapsed time taken to run a command",
5430    " time command args...
5431
5432 Run the command as usual, but print the elapsed time afterwards.  This
5433 can be useful for benchmarking operations.");
5434
5435 ]