1 # SOME DESCRIPTIVE TITLE
2 # Copyright (C) YEAR Red Hat Inc.
3 # This file is distributed under the same license as the libguestfs package.
4 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
9 "Project-Id-Version: libguestfs 1.9.5\n"
10 "Report-Msgid-Bugs-To: libguestfs@redhat.com\n"
11 "POT-Creation-Date: 2011-01-18 13:31+0000\n"
12 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14 "Language-Team: LANGUAGE <LL@li.org>\n"
17 "Content-Type: text/plain; charset=UTF-8\n"
18 "Content-Transfer-Encoding: 8bit\n"
21 #: ../src/guestfs.pod:3 ../fish/guestfish.pod:3 ../test-tool/libguestfs-test-tool.pod:3 ../fuse/guestmount.pod:3 ../tools/virt-edit.pl:32 ../tools/virt-win-reg.pl:35 ../tools/virt-resize.pl:40 ../tools/virt-list-filesystems.pl:30 ../tools/virt-tar.pl:31 ../tools/virt-make-fs.pl:35 ../tools/virt-list-partitions.pl:30
26 #: ../src/guestfs.pod:5
27 msgid "guestfs - Library for accessing and modifying virtual machine images"
31 #: ../src/guestfs.pod:7 ../fish/guestfish.pod:7 ../test-tool/libguestfs-test-tool.pod:7 ../fuse/guestmount.pod:7 ../tools/virt-edit.pl:36 ../tools/virt-win-reg.pl:39 ../tools/virt-resize.pl:44 ../tools/virt-list-filesystems.pl:34 ../tools/virt-tar.pl:35 ../tools/virt-make-fs.pl:39 ../tools/virt-list-partitions.pl:34
36 #: ../src/guestfs.pod:9
39 " #include <guestfs.h>\n"
44 #: ../src/guestfs.pod:11
47 " guestfs_h *g = guestfs_create ();\n"
48 " guestfs_add_drive (g, \"guest.img\");\n"
49 " guestfs_launch (g);\n"
50 " guestfs_mount (g, \"/dev/sda1\", \"/\");\n"
51 " guestfs_touch (g, \"/hello\");\n"
52 " guestfs_umount (g, \"/\");\n"
53 " guestfs_close (g);\n"
58 #: ../src/guestfs.pod:19
61 " cc prog.c -o prog -lguestfs\n"
63 " cc prog.c -o prog `pkg-config libguestfs --cflags --libs`\n"
68 #: ../src/guestfs.pod:23 ../fish/guestfish.pod:30 ../test-tool/libguestfs-test-tool.pod:11 ../fuse/guestmount.pod:20 ../tools/virt-edit.pl:50 ../tools/virt-win-reg.pl:63 ../tools/virt-resize.pl:50 ../tools/virt-list-filesystems.pl:40 ../tools/virt-tar.pl:77 ../tools/virt-make-fs.pl:47 ../tools/virt-list-partitions.pl:40
73 #: ../src/guestfs.pod:25
75 "Libguestfs is a library for accessing and modifying guest disk images. "
76 "Amongst the things this is good for: making batch configuration changes to "
77 "guests, getting disk used/free statistics (see also: virt-df), migrating "
78 "between virtualization systems (see also: virt-p2v), performing partial "
79 "backups, performing partial guest clones, cloning guests and changing "
80 "registry/UUID/hostname info, and much else besides."
84 #: ../src/guestfs.pod:33
86 "Libguestfs uses Linux kernel and qemu code, and can access any type of guest "
87 "filesystem that Linux and qemu can, including but not limited to: ext2/3/4, "
88 "btrfs, FAT and NTFS, LVM, many different disk partition schemes, qcow, "
93 #: ../src/guestfs.pod:38
95 "Libguestfs provides ways to enumerate guest storage (eg. partitions, LVs, "
96 "what filesystem is in each LV, etc.). It can also run commands in the "
97 "context of the guest. Also you can access filesystems over FUSE."
101 #: ../src/guestfs.pod:43
103 "Libguestfs is a library that can be linked with C and C++ management "
104 "programs (or management programs written in OCaml, Perl, Python, Ruby, Java, "
105 "PHP, Haskell or C#). You can also use it from shell scripts or the command "
110 #: ../src/guestfs.pod:48
112 "You don't need to be root to use libguestfs, although obviously you do need "
113 "enough permissions to access the disk images."
117 #: ../src/guestfs.pod:51
119 "Libguestfs is a large API because it can do many things. For a gentle "
120 "introduction, please read the L</API OVERVIEW> section next."
124 #: ../src/guestfs.pod:54
126 "There are also some example programs in the L<guestfs-examples(3)> manual "
131 #: ../src/guestfs.pod:57
136 #: ../src/guestfs.pod:59
138 "This section provides a gentler overview of the libguestfs API. We also try "
139 "to group API calls together, where that may not be obvious from reading "
140 "about the individual calls in the main section of this manual."
144 #: ../src/guestfs.pod:64
149 #: ../src/guestfs.pod:66
151 "Before you can use libguestfs calls, you have to create a handle. Then you "
152 "must add at least one disk image to the handle, followed by launching the "
153 "handle, then performing whatever operations you want, and finally closing "
154 "the handle. By convention we use the single letter C<g> for the name of the "
155 "handle variable, although of course you can use any name you want."
159 #: ../src/guestfs.pod:73
160 msgid "The general structure of all libguestfs-using programs looks like this:"
164 #: ../src/guestfs.pod:76
167 " guestfs_h *g = guestfs_create ();\n"
172 #: ../src/guestfs.pod:78
175 " /* Call guestfs_add_drive additional times if there are\n"
176 " * multiple disk images.\n"
178 " guestfs_add_drive (g, \"guest.img\");\n"
183 #: ../src/guestfs.pod:83
186 " /* Most manipulation calls won't work until you've launched\n"
187 " * the handle 'g'. You have to do this _after_ adding drives\n"
188 " * and _before_ other commands.\n"
190 " guestfs_launch (g);\n"
195 #: ../src/guestfs.pod:89
198 " /* Now you can examine what partitions, LVs etc are available.\n"
200 " char **partitions = guestfs_list_partitions (g);\n"
201 " char **logvols = guestfs_lvs (g);\n"
206 #: ../src/guestfs.pod:94
209 " /* To access a filesystem in the image, you must mount it.\n"
211 " guestfs_mount (g, \"/dev/sda1\", \"/\");\n"
216 #: ../src/guestfs.pod:98
219 " /* Now you can perform filesystem actions on the guest\n"
222 " guestfs_touch (g, \"/hello\");\n"
227 #: ../src/guestfs.pod:103
230 " /* This is only needed for libguestfs < 1.5.24. Since then\n"
231 " * it is done automatically when you close the handle. See\n"
232 " * discussion of autosync in this page.\n"
234 " guestfs_sync (g);\n"
239 #: ../src/guestfs.pod:109
242 " /* Close the handle 'g'. */\n"
243 " guestfs_close (g);\n"
248 #: ../src/guestfs.pod:112
250 "The code above doesn't include any error checking. In real code you should "
251 "check return values carefully for errors. In general all functions that "
252 "return integers return C<-1> on error, and all functions that return "
253 "pointers return C<NULL> on error. See section L</ERROR HANDLING> below for "
254 "how to handle errors, and consult the documentation for each function call "
255 "below to see precisely how they return error indications. See "
256 "L<guestfs-examples(3)> for fully worked examples."
260 #: ../src/guestfs.pod:121
265 #: ../src/guestfs.pod:123
267 "The image filename (C<\"guest.img\"> in the example above) could be a disk "
268 "image from a virtual machine, a L<dd(1)> copy of a physical hard disk, an "
269 "actual block device, or simply an empty file of zeroes that you have created "
270 "through L<posix_fallocate(3)>. Libguestfs lets you do useful things to all "
275 #: ../src/guestfs.pod:129
277 "The call you should use in modern code for adding drives is "
278 "L</guestfs_add_drive_opts>. To add a disk image, allowing writes, and "
279 "specifying that the format is raw, do:"
283 #: ../src/guestfs.pod:133
286 " guestfs_add_drive_opts (g, filename,\n"
287 " GUESTFS_ADD_DRIVE_OPTS_FORMAT, \"raw\",\n"
293 #: ../src/guestfs.pod:137
294 msgid "You can add a disk read-only using:"
298 #: ../src/guestfs.pod:139
301 " guestfs_add_drive_opts (g, filename,\n"
302 " GUESTFS_ADD_DRIVE_OPTS_FORMAT, \"raw\",\n"
303 " GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,\n"
309 #: ../src/guestfs.pod:144
311 "or by calling the older function L</guestfs_add_drive_ro>. In either case "
312 "libguestfs won't modify the file."
316 #: ../src/guestfs.pod:147
318 "Be extremely cautious if the disk image is in use, eg. if it is being used "
319 "by a virtual machine. Adding it read-write will almost certainly cause disk "
320 "corruption, but adding it read-only is safe."
324 #: ../src/guestfs.pod:151
326 "You must add at least one disk image, and you may add multiple disk images. "
327 "In the API, the disk images are usually referred to as C</dev/sda> (for the "
328 "first one you added), C</dev/sdb> (for the second one you added), etc."
332 #: ../src/guestfs.pod:156
334 "Once L</guestfs_launch> has been called you cannot add any more images. You "
335 "can call L</guestfs_list_devices> to get a list of the device names, in the "
336 "order that you added them. See also L</BLOCK DEVICE NAMING> below."
340 #: ../src/guestfs.pod:161
345 #: ../src/guestfs.pod:163
347 "Before you can read or write files, create directories and so on in a disk "
348 "image that contains filesystems, you have to mount those filesystems using "
349 "L</guestfs_mount_options> or L</guestfs_mount_ro>. If you already know that "
350 "a disk image contains (for example) one partition with a filesystem on that "
351 "partition, then you can mount it directly:"
355 #: ../src/guestfs.pod:170
358 " guestfs_mount_options (g, \"\", \"/dev/sda1\", \"/\");\n"
363 #: ../src/guestfs.pod:172
365 "where C</dev/sda1> means literally the first partition (C<1>) of the first "
366 "disk image that we added (C</dev/sda>). If the disk contains Linux LVM2 "
367 "logical volumes you could refer to those instead (eg. C</dev/VG/LV>). Note "
368 "that these are libguestfs virtual devices, and are nothing to do with host "
373 #: ../src/guestfs.pod:178
375 "If you are given a disk image and you don't know what it contains then you "
376 "have to find out. Libguestfs can do that too: use "
377 "L</guestfs_list_partitions> and L</guestfs_lvs> to list possible partitions "
378 "and LVs, and either try mounting each to see what is mountable, or else "
379 "examine them with L</guestfs_vfs_type> or L</guestfs_file>. To list just "
380 "filesystems, use L</guestfs_list_filesystems>."
384 #: ../src/guestfs.pod:186
386 "Libguestfs also has a set of APIs for inspection of unknown disk images (see "
387 "L</INSPECTION> below). But you might find it easier to look at higher level "
388 "programs built on top of libguestfs, in particular L<virt-inspector(1)>."
392 #: ../src/guestfs.pod:191
394 "To mount a filesystem read-only, use L</guestfs_mount_ro>. There are "
395 "several other variations of the C<guestfs_mount_*> call."
399 #: ../src/guestfs.pod:194
400 msgid "FILESYSTEM ACCESS AND MODIFICATION"
404 #: ../src/guestfs.pod:196
406 "The majority of the libguestfs API consists of fairly low-level calls for "
407 "accessing and modifying the files, directories, symlinks etc on mounted "
408 "filesystems. There are over a hundred such calls which you can find listed "
409 "in detail below in this man page, and we don't even pretend to cover them "
410 "all in this overview."
414 #: ../src/guestfs.pod:202
416 "Specify filenames as full paths, starting with C<\"/\"> and including the "
421 #: ../src/guestfs.pod:205
423 "For example, if you mounted a filesystem at C<\"/\"> and you want to read "
424 "the file called C<\"etc/passwd\"> then you could do:"
428 #: ../src/guestfs.pod:208
431 " char *data = guestfs_cat (g, \"/etc/passwd\");\n"
436 #: ../src/guestfs.pod:210
438 "This would return C<data> as a newly allocated buffer containing the full "
439 "content of that file (with some conditions: see also L</DOWNLOADING> below), "
440 "or C<NULL> if there was an error."
444 #: ../src/guestfs.pod:214
446 "As another example, to create a top-level directory on that filesystem "
447 "called C<\"var\"> you would do:"
451 #: ../src/guestfs.pod:217
454 " guestfs_mkdir (g, \"/var\");\n"
459 #: ../src/guestfs.pod:219
460 msgid "To create a symlink you could do:"
464 #: ../src/guestfs.pod:221
467 " guestfs_ln_s (g, \"/etc/init.d/portmap\",\n"
468 " \"/etc/rc3.d/S30portmap\");\n"
473 #: ../src/guestfs.pod:224
475 "Libguestfs will reject attempts to use relative paths and there is no "
476 "concept of a current working directory."
480 #: ../src/guestfs.pod:227
482 "Libguestfs can return errors in many situations: for example if the "
483 "filesystem isn't writable, or if a file or directory that you requested "
484 "doesn't exist. If you are using the C API (documented here) you have to "
485 "check for those error conditions after each call. (Other language bindings "
486 "turn these errors into exceptions)."
490 #: ../src/guestfs.pod:233
492 "File writes are affected by the per-handle umask, set by calling "
493 "L</guestfs_umask> and defaulting to 022. See L</UMASK>."
497 #: ../src/guestfs.pod:236
502 #: ../src/guestfs.pod:238
504 "Libguestfs contains API calls to read, create and modify partition tables on "
509 #: ../src/guestfs.pod:241
511 "In the common case where you want to create a single partition covering the "
512 "whole disk, you should use the L</guestfs_part_disk> call:"
516 #: ../src/guestfs.pod:245
519 " const char *parttype = \"mbr\";\n"
520 " if (disk_is_larger_than_2TB)\n"
521 " parttype = \"gpt\";\n"
522 " guestfs_part_disk (g, \"/dev/sda\", parttype);\n"
527 #: ../src/guestfs.pod:250
529 "Obviously this effectively wipes anything that was on that disk image "
534 #: ../src/guestfs.pod:253
539 #: ../src/guestfs.pod:255
541 "Libguestfs provides access to a large part of the LVM2 API, such as "
542 "L</guestfs_lvcreate> and L</guestfs_vgremove>. It won't make much sense "
543 "unless you familiarize yourself with the concepts of physical volumes, "
544 "volume groups and logical volumes."
548 #: ../src/guestfs.pod:260
550 "This author strongly recommends reading the LVM HOWTO, online at "
551 "L<http://tldp.org/HOWTO/LVM-HOWTO/>."
555 #: ../src/guestfs.pod:263
560 #: ../src/guestfs.pod:265
562 "Use L</guestfs_cat> to download small, text only files. This call is "
563 "limited to files which are less than 2 MB and which cannot contain any ASCII "
564 "NUL (C<\\0>) characters. However the API is very simple to use."
568 #: ../src/guestfs.pod:269
570 "L</guestfs_read_file> can be used to read files which contain arbitrary 8 "
571 "bit data, since it returns a (pointer, size) pair. However it is still "
572 "limited to \"small\" files, less than 2 MB."
576 #: ../src/guestfs.pod:273
578 "L</guestfs_download> can be used to download any file, with no limits on "
579 "content or size (even files larger than 4 GB)."
583 #: ../src/guestfs.pod:276
584 msgid "To download multiple files, see L</guestfs_tar_out> and L</guestfs_tgz_out>."
588 #: ../src/guestfs.pod:279
593 #: ../src/guestfs.pod:281
595 "It's often the case that you want to write a file or files to the disk "
600 #: ../src/guestfs.pod:284
602 "To write a small file with fixed content, use L</guestfs_write>. To create "
603 "a file of all zeroes, use L</guestfs_truncate_size> (sparse) or "
604 "L</guestfs_fallocate64> (with all disk blocks allocated). There are a "
605 "variety of other functions for creating test files, for example "
606 "L</guestfs_fill> and L</guestfs_fill_pattern>."
610 #: ../src/guestfs.pod:290
612 "To upload a single file, use L</guestfs_upload>. This call has no limits on "
613 "file content or size (even files larger than 4 GB)."
617 #: ../src/guestfs.pod:293
618 msgid "To upload multiple files, see L</guestfs_tar_in> and L</guestfs_tgz_in>."
622 #: ../src/guestfs.pod:295
624 "However the fastest way to upload I<large numbers of arbitrary files> is to "
625 "turn them into a squashfs or CD ISO (see L<mksquashfs(8)> and "
626 "L<mkisofs(8)>), then attach this using L</guestfs_add_drive_ro>. If you add "
627 "the drive in a predictable way (eg. adding it last after all other drives) "
628 "then you can get the device name from L</guestfs_list_devices> and mount it "
629 "directly using L</guestfs_mount_ro>. Note that squashfs images are "
630 "sometimes non-portable between kernel versions, and they don't support "
631 "labels or UUIDs. If you want to pre-build an image or you need to mount it "
632 "using a label or UUID, use an ISO image instead."
636 #: ../src/guestfs.pod:306
641 #: ../src/guestfs.pod:308
643 "There are various different commands for copying between files and devices "
644 "and in and out of the guest filesystem. These are summarised in the table "
649 #: ../src/guestfs.pod:314
650 msgid "B<file> to B<file>"
654 #: ../src/guestfs.pod:316
656 "Use L</guestfs_cp> to copy a single file, or L</guestfs_cp_a> to copy "
657 "directories recursively."
661 #: ../src/guestfs.pod:319
662 msgid "B<file or device> to B<file or device>"
666 #: ../src/guestfs.pod:321
668 "Use L</guestfs_dd> which efficiently uses L<dd(1)> to copy between files and "
669 "devices in the guest."
673 #: ../src/guestfs.pod:324
674 msgid "Example: duplicate the contents of an LV:"
678 #: ../src/guestfs.pod:326
681 " guestfs_dd (g, \"/dev/VG/Original\", \"/dev/VG/Copy\");\n"
686 #: ../src/guestfs.pod:328
688 "The destination (C</dev/VG/Copy>) must be at least as large as the source "
689 "(C</dev/VG/Original>). To copy less than the whole source device, use "
690 "L</guestfs_copy_size>."
694 #: ../src/guestfs.pod:332
695 msgid "B<file on the host> to B<file or device>"
699 #: ../src/guestfs.pod:334
700 msgid "Use L</guestfs_upload>. See L</UPLOADING> above."
704 #: ../src/guestfs.pod:336
705 msgid "B<file or device> to B<file on the host>"
709 #: ../src/guestfs.pod:338
710 msgid "Use L</guestfs_download>. See L</DOWNLOADING> above."
714 #: ../src/guestfs.pod:342
715 msgid "UPLOADING AND DOWNLOADING TO PIPES AND FILE DESCRIPTORS"
719 #: ../src/guestfs.pod:344
721 "Calls like L</guestfs_upload>, L</guestfs_download>, L</guestfs_tar_in>, "
722 "L</guestfs_tar_out> etc appear to only take filenames as arguments, so it "
723 "appears you can only upload and download to files. However many Un*x-like "
724 "hosts let you use the special device files C</dev/stdin>, C</dev/stdout>, "
725 "C</dev/stderr> and C</dev/fd/N> to read and write from stdin, stdout, "
726 "stderr, and arbitrary file descriptor N."
730 #: ../src/guestfs.pod:352
731 msgid "For example, L<virt-cat(1)> writes its output to stdout by doing:"
735 #: ../src/guestfs.pod:355
738 " guestfs_download (g, filename, \"/dev/stdout\");\n"
743 #: ../src/guestfs.pod:357
744 msgid "and you can write tar output to a pipe C<fd> by doing:"
748 #: ../src/guestfs.pod:359
752 " snprintf (devfd, sizeof devfd, \"/dev/fd/%d\", fd);\n"
753 " guestfs_tar_out (g, \"/\", devfd);\n"
758 #: ../src/guestfs.pod:363
759 msgid "LISTING FILES"
763 #: ../src/guestfs.pod:365
765 "L</guestfs_ll> is just designed for humans to read (mainly when using the "
766 "L<guestfish(1)>-equivalent command C<ll>)."
770 #: ../src/guestfs.pod:368
772 "L</guestfs_ls> is a quick way to get a list of files in a directory from "
773 "programs, as a flat list of strings."
777 #: ../src/guestfs.pod:371
779 "L</guestfs_readdir> is a programmatic way to get a list of files in a "
780 "directory, plus additional information about each one. It is more "
781 "equivalent to using the L<readdir(3)> call on a local filesystem."
785 #: ../src/guestfs.pod:375
787 "L</guestfs_find> and L</guestfs_find0> can be used to recursively list "
792 #: ../src/guestfs.pod:378
793 msgid "RUNNING COMMANDS"
797 #: ../src/guestfs.pod:380
799 "Although libguestfs is primarily an API for manipulating files inside guest "
800 "images, we also provide some limited facilities for running commands inside "
805 #: ../src/guestfs.pod:384
806 msgid "There are many limitations to this:"
810 #: ../src/guestfs.pod:388 ../src/guestfs.pod:393 ../src/guestfs.pod:398 ../src/guestfs.pod:402 ../src/guestfs.pod:407 ../src/guestfs.pod:411 ../src/guestfs.pod:416 ../src/guestfs.pod:421 ../src/guestfs.pod:1031 ../src/guestfs.pod:1035 ../src/guestfs.pod:1039 ../src/guestfs.pod:1044 ../src/guestfs.pod:1052 ../src/guestfs.pod:1071 ../src/guestfs.pod:1079 ../src/guestfs.pod:1101 ../src/guestfs.pod:1105 ../src/guestfs.pod:1109 ../src/guestfs.pod:1113 ../src/guestfs.pod:1117 ../src/guestfs.pod:1121 ../src/guestfs.pod:1603 ../src/guestfs.pod:1608 ../src/guestfs.pod:1612 ../src/guestfs.pod:1722 ../src/guestfs.pod:1727 ../src/guestfs.pod:1731 ../src/guestfs.pod:2083 ../src/guestfs.pod:2089 ../src/guestfs.pod:2094 ../src/guestfs.pod:2100 ../src/guestfs.pod:2564 ../src/guestfs.pod:2568 ../src/guestfs.pod:2572 ../src/guestfs.pod:2576 ../src/guestfs-actions.pod:15 ../src/guestfs-actions.pod:22 ../src/guestfs-actions.pod:569 ../src/guestfs-actions.pod:577 ../src/guestfs-actions.pod:584 ../src/guestfs-actions.pod:591 ../src/guestfs-actions.pod:1587 ../src/guestfs-actions.pod:1591 ../src/guestfs-actions.pod:1595 ../src/guestfs-actions.pod:1599 ../src/guestfs-actions.pod:1607 ../src/guestfs-actions.pod:1611 ../src/guestfs-actions.pod:1615 ../src/guestfs-actions.pod:1625 ../src/guestfs-actions.pod:1629 ../src/guestfs-actions.pod:1633 ../src/guestfs-actions.pod:1771 ../src/guestfs-actions.pod:1775 ../src/guestfs-actions.pod:1780 ../src/guestfs-actions.pod:1785 ../src/guestfs-actions.pod:1846 ../src/guestfs-actions.pod:1850 ../src/guestfs-actions.pod:1855 ../fish/guestfish.pod:427 ../fish/guestfish.pod:431 ../fish/guestfish.pod:435 ../fish/guestfish.pod:439 ../fish/guestfish-actions.pod:13 ../fish/guestfish-actions.pod:20 ../fish/guestfish-actions.pod:373 ../fish/guestfish-actions.pod:381 ../fish/guestfish-actions.pod:388 ../fish/guestfish-actions.pod:395 ../fish/guestfish-actions.pod:1065 ../fish/guestfish-actions.pod:1069 ../fish/guestfish-actions.pod:1073 ../fish/guestfish-actions.pod:1077 ../fish/guestfish-actions.pod:1085 ../fish/guestfish-actions.pod:1089 ../fish/guestfish-actions.pod:1093 ../fish/guestfish-actions.pod:1103 ../fish/guestfish-actions.pod:1107 ../fish/guestfish-actions.pod:1111 ../fish/guestfish-actions.pod:1201 ../fish/guestfish-actions.pod:1205 ../fish/guestfish-actions.pod:1210 ../fish/guestfish-actions.pod:1215 ../fish/guestfish-actions.pod:1257 ../fish/guestfish-actions.pod:1261 ../fish/guestfish-actions.pod:1266 ../tools/virt-win-reg.pl:536 ../tools/virt-win-reg.pl:542 ../tools/virt-win-reg.pl:548 ../tools/virt-resize.pl:345 ../tools/virt-resize.pl:350 ../tools/virt-resize.pl:360
815 #: ../src/guestfs.pod:390
817 "The kernel version that the command runs under will be different from what "
822 #: ../src/guestfs.pod:395
824 "If the command needs to communicate with daemons, then most likely they "
829 #: ../src/guestfs.pod:400
830 msgid "The command will be running in limited memory."
834 #: ../src/guestfs.pod:404
836 "The network may not be available unless you enable it (see "
837 "L</guestfs_set_network>)."
841 #: ../src/guestfs.pod:409
842 msgid "Only supports Linux guests (not Windows, BSD, etc)."
846 #: ../src/guestfs.pod:413
847 msgid "Architecture limitations (eg. won't work for a PPC guest on an X86 host)."
851 #: ../src/guestfs.pod:418
853 "For SELinux guests, you may need to enable SELinux and load policy first. "
854 "See L</SELINUX> in this manpage."
858 #: ../src/guestfs.pod:423
860 "I<Security:> It is not safe to run commands from untrusted, possibly "
861 "malicious guests. These commands may attempt to exploit your program by "
862 "sending unexpected output. They could also try to exploit the Linux kernel "
863 "or qemu provided by the libguestfs appliance. They could use the network "
864 "provided by the libguestfs appliance to bypass ordinary network partitions "
865 "and firewalls. They could use the elevated privileges or different SELinux "
866 "context of your program to their advantage."
870 #: ../src/guestfs.pod:432
872 "A secure alternative is to use libguestfs to install a \"firstboot\" script "
873 "(a script which runs when the guest next boots normally), and to have this "
874 "script run the commands you want in the normal context of the running guest, "
875 "network security and so on. For information about other security issues, "
880 #: ../src/guestfs.pod:440
882 "The two main API calls to run commands are L</guestfs_command> and "
883 "L</guestfs_sh> (there are also variations)."
887 #: ../src/guestfs.pod:443
889 "The difference is that L</guestfs_sh> runs commands using the shell, so any "
890 "shell globs, redirections, etc will work."
894 #: ../src/guestfs.pod:446
895 msgid "CONFIGURATION FILES"
899 #: ../src/guestfs.pod:448
901 "To read and write configuration files in Linux guest filesystems, we "
902 "strongly recommend using Augeas. For example, Augeas understands how to "
903 "read and write, say, a Linux shadow password file or X.org configuration "
904 "file, and so avoids you having to write that code."
908 #: ../src/guestfs.pod:453
910 "The main Augeas calls are bound through the C<guestfs_aug_*> APIs. We don't "
911 "document Augeas itself here because there is excellent documentation on the "
912 "L<http://augeas.net/> website."
916 #: ../src/guestfs.pod:457
918 "If you don't want to use Augeas (you fool!) then try calling "
919 "L</guestfs_read_lines> to get the file as a list of lines which you can "
924 #: ../src/guestfs.pod:461
929 #: ../src/guestfs.pod:463
931 "We support SELinux guests. To ensure that labeling happens correctly in "
932 "SELinux guests, you need to enable SELinux and load the guest's policy:"
936 #: ../src/guestfs.pod:469 ../src/guestfs.pod:1224 ../src/guestfs.pod:1355 ../src/guestfs.pod:2128
941 #: ../src/guestfs.pod:471
942 msgid "Before launching, do:"
946 #: ../src/guestfs.pod:473
949 " guestfs_set_selinux (g, 1);\n"
954 #: ../src/guestfs.pod:475 ../src/guestfs.pod:1228 ../src/guestfs.pod:1359 ../src/guestfs.pod:2153
959 #: ../src/guestfs.pod:477
961 "After mounting the guest's filesystem(s), load the policy. This is best "
962 "done by running the L<load_policy(8)> command in the guest itself:"
966 #: ../src/guestfs.pod:481
969 " guestfs_sh (g, \"/usr/sbin/load_policy\");\n"
974 #: ../src/guestfs.pod:483
976 "(Older versions of C<load_policy> require you to specify the name of the "
981 #: ../src/guestfs.pod:486 ../src/guestfs.pod:1365
986 #: ../src/guestfs.pod:488
988 "Optionally, set the security context for the API. The correct security "
989 "context to use can only be known by inspecting the guest. As an example:"
993 #: ../src/guestfs.pod:492
996 " guestfs_setcon (g, \"unconfined_u:unconfined_r:unconfined_t:s0\");\n"
1001 #: ../src/guestfs.pod:496
1002 msgid "This will work for running commands and editing existing files."
1006 #: ../src/guestfs.pod:498
1008 "When new files are created, you may need to label them explicitly, for "
1009 "example by running the external command C<restorecon pathname>."
1013 #: ../src/guestfs.pod:502
1018 #: ../src/guestfs.pod:504
1020 "Certain calls are affected by the current file mode creation mask (the "
1021 "\"umask\"). In particular ones which create files or directories, such as "
1022 "L</guestfs_touch>, L</guestfs_mknod> or L</guestfs_mkdir>. This affects "
1023 "either the default mode that the file is created with or modifies the mode "
1028 #: ../src/guestfs.pod:510
1030 "The default umask is C<022>, so files are created with modes such as C<0644> "
1031 "and directories with C<0755>."
1035 #: ../src/guestfs.pod:513
1037 "There are two ways to avoid being affected by umask. Either set umask to 0 "
1038 "(call C<guestfs_umask (g, 0)> early after launching). Or call "
1039 "L</guestfs_chmod> after creating each file or directory."
1043 #: ../src/guestfs.pod:517
1044 msgid "For more information about umask, see L<umask(2)>."
1048 #: ../src/guestfs.pod:519 ../fish/guestfish.pod:746
1049 msgid "ENCRYPTED DISKS"
1053 #: ../src/guestfs.pod:521
1055 "Libguestfs allows you to access Linux guests which have been encrypted using "
1056 "whole disk encryption that conforms to the Linux Unified Key Setup (LUKS) "
1057 "standard. This includes nearly all whole disk encryption systems used by "
1058 "modern Linux guests."
1062 #: ../src/guestfs.pod:527
1064 "Use L</guestfs_vfs_type> to identify LUKS-encrypted block devices (it "
1065 "returns the string C<crypto_LUKS>)."
1069 #: ../src/guestfs.pod:530
1071 "Then open these devices by calling L</guestfs_luks_open>. Obviously you "
1072 "will require the passphrase!"
1076 #: ../src/guestfs.pod:533
1078 "Opening a LUKS device creates a new device mapper device called "
1079 "C</dev/mapper/mapname> (where C<mapname> is the string you supply to "
1080 "L</guestfs_luks_open>). Reads and writes to this mapper device are "
1081 "decrypted from and encrypted to the underlying block device respectively."
1085 #: ../src/guestfs.pod:539
1087 "LVM volume groups on the device can be made visible by calling "
1088 "L</guestfs_vgscan> followed by L</guestfs_vg_activate_all>. The logical "
1089 "volume(s) can now be mounted in the usual way."
1093 #: ../src/guestfs.pod:543
1095 "Use the reverse process to close a LUKS device. Unmount any logical volumes "
1096 "on it, deactivate the volume groups by caling C<guestfs_vg_activate (g, 0, "
1097 "[\"/dev/VG\"])>. Then close the mapper device by calling "
1098 "L</guestfs_luks_close> on the C</dev/mapper/mapname> device (I<not> the "
1099 "underlying encrypted block device)."
1103 #: ../src/guestfs.pod:550
1108 #: ../src/guestfs.pod:552
1110 "Libguestfs has APIs for inspecting an unknown disk image to find out if it "
1111 "contains operating systems, an install CD or a live CD. (These APIs used to "
1112 "be in a separate Perl-only library called L<Sys::Guestfs::Lib(3)> but since "
1113 "version 1.5.3 the most frequently used part of this library has been "
1114 "rewritten in C and moved into the core code)."
1118 #: ../src/guestfs.pod:559
1120 "Add all disks belonging to the unknown virtual machine and call "
1121 "L</guestfs_launch> in the usual way."
1125 #: ../src/guestfs.pod:562
1127 "Then call L</guestfs_inspect_os>. This function uses other libguestfs calls "
1128 "and certain heuristics, and returns a list of operating systems that were "
1129 "found. An empty list means none were found. A single element is the root "
1130 "filesystem of the operating system. For dual- or multi-boot guests, "
1131 "multiple roots can be returned, each one corresponding to a separate "
1132 "operating system. (Multi-boot virtual machines are extremely rare in the "
1133 "world of virtualization, but since this scenario can happen, we have built "
1134 "libguestfs to deal with it.)"
1138 #: ../src/guestfs.pod:571
1140 "For each root, you can then call various C<guestfs_inspect_get_*> functions "
1141 "to get additional details about that operating system. For example, call "
1142 "L</guestfs_inspect_get_type> to return the string C<windows> or C<linux> for "
1143 "Windows and Linux-based operating systems respectively."
1147 #: ../src/guestfs.pod:577
1149 "Un*x-like and Linux-based operating systems usually consist of several "
1150 "filesystems which are mounted at boot time (for example, a separate boot "
1151 "partition mounted on C</boot>). The inspection rules are able to detect how "
1152 "filesystems correspond to mount points. Call "
1153 "C<guestfs_inspect_get_mountpoints> to get this mapping. It might return a "
1154 "hash table like this example:"
1158 #: ../src/guestfs.pod:584
1161 " /boot => /dev/sda1\n"
1162 " / => /dev/vg_guest/lv_root\n"
1163 " /usr => /dev/vg_guest/lv_usr\n"
1168 #: ../src/guestfs.pod:588
1170 "The caller can then make calls to L</guestfs_mount_options> to mount the "
1171 "filesystems as suggested."
1175 #: ../src/guestfs.pod:591
1177 "Be careful to mount filesystems in the right order (eg. C</> before "
1178 "C</usr>). Sorting the keys of the hash by length, shortest first, should "
1183 #: ../src/guestfs.pod:595
1185 "Inspection currently only works for some common operating systems. "
1186 "Contributors are welcome to send patches for other operating systems that we "
1187 "currently cannot detect."
1191 #: ../src/guestfs.pod:599
1193 "Encrypted disks must be opened before inspection. See L</ENCRYPTED DISKS> "
1194 "for more details. The L</guestfs_inspect_os> function just ignores any "
1195 "encrypted devices."
1199 #: ../src/guestfs.pod:603
1201 "A note on the implementation: The call L</guestfs_inspect_os> performs "
1202 "inspection and caches the results in the guest handle. Subsequent calls to "
1203 "C<guestfs_inspect_get_*> return this cached information, but I<do not> "
1204 "re-read the disks. If you change the content of the guest disks, you can "
1205 "redo inspection by calling L</guestfs_inspect_os> again. "
1206 "(L</guestfs_inspect_list_applications> works a little differently from the "
1207 "other calls and does read the disks. See documentation for that function "
1212 #: ../src/guestfs.pod:612
1213 msgid "INSPECTING INSTALL DISKS"
1217 #: ../src/guestfs.pod:614
1219 "Libguestfs (since 1.9.4) can detect some install disks, install CDs, live "
1224 #: ../src/guestfs.pod:617
1226 "Call L</guestfs_inspect_get_format> to return the format of the operating "
1227 "system, which currently can be C<installed> (a regular operating system) or "
1228 "C<installer> (some sort of install disk)."
1232 #: ../src/guestfs.pod:621
1234 "Further information is available about the operating system that can be "
1235 "installed using the regular inspection APIs like "
1236 "L</guestfs_inspect_get_product_name>, L</guestfs_inspect_get_major_version> "
1241 #: ../src/guestfs.pod:626
1243 "Some additional information specific to installer disks is also available "
1244 "from the L</guestfs_inspect_is_live>, L</guestfs_inspect_is_netinst> and "
1245 "L</guestfs_inspect_is_multipart> calls."
1249 #: ../src/guestfs.pod:631
1250 msgid "SPECIAL CONSIDERATIONS FOR WINDOWS GUESTS"
1254 #: ../src/guestfs.pod:633
1256 "Libguestfs can mount NTFS partitions. It does this using the "
1257 "L<http://www.ntfs-3g.org/> driver."
1261 #: ../src/guestfs.pod:636
1262 msgid "DRIVE LETTERS AND PATHS"
1266 #: ../src/guestfs.pod:638
1268 "DOS and Windows still use drive letters, and the filesystems are always "
1269 "treated as case insensitive by Windows itself, and therefore you might find "
1270 "a Windows configuration file referring to a path like "
1271 "C<c:\\windows\\system32>. When the filesystem is mounted in libguestfs, "
1272 "that directory might be referred to as C</WINDOWS/System32>."
1276 #: ../src/guestfs.pod:644
1278 "Drive letter mappings are outside the scope of libguestfs. You have to use "
1279 "libguestfs to read the appropriate Windows Registry and configuration files, "
1280 "to determine yourself how drives are mapped (see also L<hivex(3)> and "
1281 "L<virt-inspector(1)>)."
1285 #: ../src/guestfs.pod:649
1287 "Replacing backslash characters with forward slash characters is also outside "
1288 "the scope of libguestfs, but something that you can easily do."
1292 #: ../src/guestfs.pod:652
1294 "Where we can help is in resolving the case insensitivity of paths. For "
1295 "this, call L</guestfs_case_sensitive_path>."
1299 #: ../src/guestfs.pod:655
1300 msgid "ACCESSING THE WINDOWS REGISTRY"
1304 #: ../src/guestfs.pod:657
1306 "Libguestfs also provides some help for decoding Windows Registry \"hive\" "
1307 "files, through the library C<hivex> which is part of the libguestfs project "
1308 "although ships as a separate tarball. You have to locate and download the "
1309 "hive file(s) yourself, and then pass them to C<hivex> functions. See also "
1310 "the programs L<hivexml(1)>, L<hivexsh(1)>, L<hivexregedit(1)> and "
1311 "L<virt-win-reg(1)> for more help on this issue."
1315 #: ../src/guestfs.pod:665
1316 msgid "SYMLINKS ON NTFS-3G FILESYSTEMS"
1320 #: ../src/guestfs.pod:667
1322 "Ntfs-3g tries to rewrite \"Junction Points\" and NTFS \"symbolic links\" to "
1323 "provide something which looks like a Linux symlink. The way it tries to do "
1324 "the rewriting is described here:"
1328 #: ../src/guestfs.pod:671
1329 msgid "L<http://www.tuxera.com/community/ntfs-3g-advanced/junction-points-and-symbolic-links/>"
1333 #: ../src/guestfs.pod:673
1335 "The essential problem is that ntfs-3g simply does not have enough "
1336 "information to do a correct job. NTFS links can contain drive letters and "
1337 "references to external device GUIDs that ntfs-3g has no way of resolving. "
1338 "It is almost certainly the case that libguestfs callers should ignore what "
1339 "ntfs-3g does (ie. don't use L</guestfs_readlink> on NTFS volumes)."
1343 #: ../src/guestfs.pod:680
1345 "Instead if you encounter a symbolic link on an ntfs-3g filesystem, use "
1346 "L</guestfs_lgetxattr> to read the C<system.ntfs_reparse_data> extended "
1347 "attribute, and read the raw reparse data from that (you can find the format "
1348 "documented in various places around the web)."
1352 #: ../src/guestfs.pod:685
1353 msgid "EXTENDED ATTRIBUTES ON NTFS-3G FILESYSTEMS"
1357 #: ../src/guestfs.pod:687
1359 "There are other useful extended attributes that can be read from ntfs-3g "
1360 "filesystems (using L</guestfs_getxattr>). See:"
1364 #: ../src/guestfs.pod:690
1365 msgid "L<http://www.tuxera.com/community/ntfs-3g-advanced/extended-attributes/>"
1369 #: ../src/guestfs.pod:692
1370 msgid "USING LIBGUESTFS WITH OTHER PROGRAMMING LANGUAGES"
1374 #: ../src/guestfs.pod:694
1376 "Although we don't want to discourage you from using the C API, we will "
1377 "mention here that the same API is also available in other languages."
1381 #: ../src/guestfs.pod:697
1383 "The API is broadly identical in all supported languages. This means that "
1384 "the C call C<guestfs_add_drive_ro(g,file)> is C<$g-E<gt>add_drive_ro($file)> "
1385 "in Perl, C<g.add_drive_ro(file)> in Python, and C<g#add_drive_ro file> in "
1386 "OCaml. In other words, a straightforward, predictable isomorphism between "
1391 #: ../src/guestfs.pod:703
1393 "Error messages are automatically transformed into exceptions if the language "
1398 #: ../src/guestfs.pod:706
1400 "We don't try to \"object orientify\" parts of the API in OO languages, "
1401 "although contributors are welcome to write higher level APIs above what we "
1402 "provide in their favourite languages if they wish."
1406 #: ../src/guestfs.pod:712
1411 #: ../src/guestfs.pod:714
1413 "You can use the I<guestfs.h> header file from C++ programs. The C++ API is "
1414 "identical to the C API. C++ classes and exceptions are not used."
1418 #: ../src/guestfs.pod:718
1423 #: ../src/guestfs.pod:720
1425 "The C# bindings are highly experimental. Please read the warnings at the "
1426 "top of C<csharp/Libguestfs.cs>."
1430 #: ../src/guestfs.pod:723
1435 #: ../src/guestfs.pod:725
1437 "This is the only language binding that is working but incomplete. Only "
1438 "calls which return simple integers have been bound in Haskell, and we are "
1439 "looking for help to complete this binding."
1443 #: ../src/guestfs.pod:729
1448 #: ../src/guestfs.pod:731
1450 "Full documentation is contained in the Javadoc which is distributed with "
1455 #: ../src/guestfs.pod:734
1460 #: ../src/guestfs.pod:736
1461 msgid "See L<guestfs-ocaml(3)>."
1465 #: ../src/guestfs.pod:738
1470 #: ../src/guestfs.pod:740
1471 msgid "See L<Sys::Guestfs(3)>."
1475 #: ../src/guestfs.pod:742
1480 #: ../src/guestfs.pod:744
1482 "For documentation see C<README-PHP> supplied with libguestfs sources or in "
1483 "the php-libguestfs package for your distribution."
1487 #: ../src/guestfs.pod:747
1488 msgid "The PHP binding only works correctly on 64 bit machines."
1492 #: ../src/guestfs.pod:749
1497 #: ../src/guestfs.pod:751
1498 msgid "See L<guestfs-python(3)>."
1502 #: ../src/guestfs.pod:753
1507 #: ../src/guestfs.pod:755
1508 msgid "See L<guestfs-ruby(3)>."
1512 #: ../src/guestfs.pod:757
1513 msgid "B<shell scripts>"
1517 #: ../src/guestfs.pod:759
1518 msgid "See L<guestfish(1)>."
1522 #: ../src/guestfs.pod:763
1523 msgid "LIBGUESTFS GOTCHAS"
1527 #: ../src/guestfs.pod:765
1529 "L<http://en.wikipedia.org/wiki/Gotcha_(programming)>: \"A feature of a "
1530 "system [...] that works in the way it is documented but is counterintuitive "
1531 "and almost invites mistakes.\""
1535 #: ../src/guestfs.pod:769
1537 "Since we developed libguestfs and the associated tools, there are several "
1538 "things we would have designed differently, but are now stuck with for "
1539 "backwards compatibility or other reasons. If there is ever a libguestfs 2.0 "
1540 "release, you can expect these to change. Beware of them."
1544 #: ../src/guestfs.pod:777
1545 msgid "Autosync / forgetting to sync."
1549 #: ../src/guestfs.pod:779
1551 "When modifying a filesystem from C or another language, you B<must> unmount "
1552 "all filesystems and call L</guestfs_sync> explicitly before you close the "
1553 "libguestfs handle. You can also call:"
1557 #: ../src/guestfs.pod:783
1560 " guestfs_set_autosync (g, 1);\n"
1565 #: ../src/guestfs.pod:785
1567 "to have the unmount/sync done automatically for you when the handle 'g' is "
1568 "closed. (This feature is called \"autosync\", L</guestfs_set_autosync> "
1573 #: ../src/guestfs.pod:789
1575 "If you forget to do this, then it is entirely possible that your changes "
1576 "won't be written out, or will be partially written, or (very rarely) that "
1577 "you'll get disk corruption."
1581 #: ../src/guestfs.pod:793
1583 "Note that in L<guestfish(3)> autosync is the default. So quick and dirty "
1584 "guestfish scripts that forget to sync will work just fine, which can make "
1585 "this very puzzling if you are trying to debug a problem."
1589 #: ../src/guestfs.pod:797
1591 "Update: Autosync is enabled by default for all API users starting from "
1592 "libguestfs 1.5.24."
1596 #: ../src/guestfs.pod:800
1597 msgid "Mount option C<-o sync> should not be the default."
1601 #: ../src/guestfs.pod:802
1603 "If you use L</guestfs_mount>, then C<-o sync,noatime> are added implicitly. "
1604 "However C<-o sync> does not add any reliability benefit, but does have a "
1605 "very large performance impact."
1609 #: ../src/guestfs.pod:806
1611 "The work around is to use L</guestfs_mount_options> and set the mount "
1612 "options that you actually want to use."
1616 #: ../src/guestfs.pod:809
1617 msgid "Read-only should be the default."
1621 #: ../src/guestfs.pod:811
1623 "In L<guestfish(3)>, I<--ro> should be the default, and you should have to "
1624 "specify I<--rw> if you want to make changes to the image."
1628 #: ../src/guestfs.pod:814
1629 msgid "This would reduce the potential to corrupt live VM images."
1633 #: ../src/guestfs.pod:816
1635 "Note that many filesystems change the disk when you just mount and unmount, "
1636 "even if you didn't perform any writes. You need to use "
1637 "L</guestfs_add_drive_ro> to guarantee that the disk is not changed."
1641 #: ../src/guestfs.pod:820
1642 msgid "guestfish command line is hard to use."
1646 #: ../src/guestfs.pod:822
1648 "C<guestfish disk.img> doesn't do what people expect (open C<disk.img> for "
1649 "examination). It tries to run a guestfish command C<disk.img> which doesn't "
1650 "exist, so it fails. In earlier versions of guestfish the error message was "
1651 "also unintuitive, but we have corrected this since. Like the Bourne shell, "
1652 "we should have used C<guestfish -c command> to run commands."
1656 #: ../src/guestfs.pod:829
1657 msgid "guestfish megabyte modifiers don't work right on all commands"
1661 #: ../src/guestfs.pod:831
1663 "In recent guestfish you can use C<1M> to mean 1 megabyte (and similarly for "
1664 "other modifiers). What guestfish actually does is to multiply the number "
1665 "part by the modifier part and pass the result to the C API. However this "
1666 "doesn't work for a few APIs which aren't expecting bytes, but are already "
1667 "expecting some other unit (eg. megabytes)."
1671 #: ../src/guestfs.pod:838
1672 msgid "The most common is L</guestfs_lvcreate>. The guestfish command:"
1676 #: ../src/guestfs.pod:840
1679 " lvcreate LV VG 100M\n"
1684 #: ../src/guestfs.pod:842
1686 "does not do what you might expect. Instead because L</guestfs_lvcreate> is "
1687 "already expecting megabytes, this tries to create a 100 I<terabyte> (100 "
1688 "megabytes * megabytes) logical volume. The error message you get from this "
1689 "is also a little obscure."
1693 #: ../src/guestfs.pod:847
1695 "This could be fixed in the generator by specially marking parameters and "
1696 "return values which take bytes or other units."
1700 #: ../src/guestfs.pod:850
1701 msgid "Ambiguity between devices and paths"
1705 #: ../src/guestfs.pod:852
1707 "There is a subtle ambiguity in the API between a device name "
1708 "(eg. C</dev/sdb2>) and a similar pathname. A file might just happen to be "
1709 "called C<sdb2> in the directory C</dev> (consider some non-Unix VM image)."
1713 #: ../src/guestfs.pod:857
1715 "In the current API we usually resolve this ambiguity by having two separate "
1716 "calls, for example L</guestfs_checksum> and L</guestfs_checksum_device>. "
1717 "Some API calls are ambiguous and (incorrectly) resolve the problem by "
1718 "detecting if the path supplied begins with C</dev/>."
1722 #: ../src/guestfs.pod:863
1724 "To avoid both the ambiguity and the need to duplicate some calls, we could "
1725 "make paths/devices into structured names. One way to do this would be to "
1726 "use a notation like grub (C<hd(0,0)>), although nobody really likes this "
1727 "aspect of grub. Another way would be to use a structured type, equivalent "
1728 "to this OCaml type:"
1732 #: ../src/guestfs.pod:869
1735 " type path = Path of string | Device of int | Partition of int * int\n"
1740 #: ../src/guestfs.pod:871
1741 msgid "which would allow you to pass arguments like:"
1745 #: ../src/guestfs.pod:873
1748 " Path \"/foo/bar\"\n"
1749 " Device 1 (* /dev/sdb, or perhaps /dev/sda *)\n"
1750 " Partition (1, 2) (* /dev/sdb2 (or is it /dev/sda2 or /dev/sdb3?) *)\n"
1751 " Path \"/dev/sdb2\" (* not a device *)\n"
1756 #: ../src/guestfs.pod:878
1758 "As you can see there are still problems to resolve even with this "
1759 "representation. Also consider how it might work in guestfish."
1763 #: ../src/guestfs.pod:883
1764 msgid "PROTOCOL LIMITS"
1768 #: ../src/guestfs.pod:885
1770 "Internally libguestfs uses a message-based protocol to pass API calls and "
1771 "their responses to and from a small \"appliance\" (see L</INTERNALS> for "
1772 "plenty more detail about this). The maximum message size used by the "
1773 "protocol is slightly less than 4 MB. For some API calls you may need to be "
1774 "aware of this limit. The API calls which may be affected are individually "
1775 "documented, with a link back to this section of the documentation."
1779 #: ../src/guestfs.pod:893
1781 "A simple call such as L</guestfs_cat> returns its result (the file data) in "
1782 "a simple string. Because this string is at some point internally encoded as "
1783 "a message, the maximum size that it can return is slightly under 4 MB. If "
1784 "the requested file is larger than this then you will get an error."
1788 #: ../src/guestfs.pod:899
1790 "In order to transfer large files into and out of the guest filesystem, you "
1791 "need to use particular calls that support this. The sections L</UPLOADING> "
1792 "and L</DOWNLOADING> document how to do this."
1796 #: ../src/guestfs.pod:903
1798 "You might also consider mounting the disk image using our FUSE filesystem "
1799 "support (L<guestmount(1)>)."
1803 #: ../src/guestfs.pod:906
1804 msgid "KEYS AND PASSPHRASES"
1808 #: ../src/guestfs.pod:908
1810 "Certain libguestfs calls take a parameter that contains sensitive key "
1811 "material, passed in as a C string."
1815 #: ../src/guestfs.pod:911
1817 "In the future we would hope to change the libguestfs implementation so that "
1818 "keys are L<mlock(2)>-ed into physical RAM, and thus can never end up in "
1819 "swap. However this is I<not> done at the moment, because of the complexity "
1820 "of such an implementation."
1824 #: ../src/guestfs.pod:916
1826 "Therefore you should be aware that any key parameter you pass to libguestfs "
1827 "might end up being written out to the swap partition. If this is a concern, "
1828 "scrub the swap partition or don't use libguestfs on encrypted devices."
1832 #: ../src/guestfs.pod:921
1833 msgid "MULTIPLE HANDLES AND MULTIPLE THREADS"
1837 #: ../src/guestfs.pod:923
1839 "All high-level libguestfs actions are synchronous. If you want to use "
1840 "libguestfs asynchronously then you must create a thread."
1844 #: ../src/guestfs.pod:926
1846 "Only use the handle from a single thread. Either use the handle exclusively "
1847 "from one thread, or provide your own mutex so that two threads cannot issue "
1848 "calls on the same handle at the same time."
1852 #: ../src/guestfs.pod:930
1854 "See the graphical program guestfs-browser for one possible architecture for "
1855 "multithreaded programs using libvirt and libguestfs."
1859 #: ../src/guestfs.pod:933
1864 #: ../src/guestfs.pod:935
1866 "Libguestfs needs a kernel and initrd.img, which it finds by looking along an "
1871 #: ../src/guestfs.pod:938
1873 "By default it looks for these in the directory C<$libdir/guestfs> "
1874 "(eg. C</usr/local/lib/guestfs> or C</usr/lib64/guestfs>)."
1878 #: ../src/guestfs.pod:941
1880 "Use L</guestfs_set_path> or set the environment variable L</LIBGUESTFS_PATH> "
1881 "to change the directories that libguestfs will search in. The value is a "
1882 "colon-separated list of paths. The current directory is I<not> searched "
1883 "unless the path contains an empty element or C<.>. For example "
1884 "C<LIBGUESTFS_PATH=:/usr/lib/guestfs> would search the current directory and "
1885 "then C</usr/lib/guestfs>."
1889 #: ../src/guestfs.pod:948
1890 msgid "QEMU WRAPPERS"
1894 #: ../src/guestfs.pod:950
1896 "If you want to compile your own qemu, run qemu from a non-standard location, "
1897 "or pass extra arguments to qemu, then you can write a shell-script wrapper "
1902 #: ../src/guestfs.pod:954
1904 "There is one important rule to remember: you I<must C<exec qemu>> as the "
1905 "last command in the shell script (so that qemu replaces the shell and "
1906 "becomes the direct child of the libguestfs-using program). If you don't do "
1907 "this, then the qemu process won't be cleaned up correctly."
1911 #: ../src/guestfs.pod:959
1913 "Here is an example of a wrapper, where I have built my own copy of qemu from "
1918 #: ../src/guestfs.pod:962
1922 " qemudir=/home/rjones/d/qemu\n"
1923 " exec $qemudir/x86_64-softmmu/qemu-system-x86_64 -L $qemudir/pc-bios "
1929 #: ../src/guestfs.pod:966
1931 "Save this script as C</tmp/qemu.wrapper> (or wherever), C<chmod +x>, and "
1932 "then use it by setting the LIBGUESTFS_QEMU environment variable. For "
1937 #: ../src/guestfs.pod:970
1940 " LIBGUESTFS_QEMU=/tmp/qemu.wrapper guestfish\n"
1945 #: ../src/guestfs.pod:972
1947 "Note that libguestfs also calls qemu with the -help and -version options in "
1948 "order to determine features."
1952 #: ../src/guestfs.pod:975
1953 msgid "ABI GUARANTEE"
1957 #: ../src/guestfs.pod:977
1959 "We guarantee the libguestfs ABI (binary interface), for public, high-level "
1960 "actions as outlined in this section. Although we will deprecate some "
1961 "actions, for example if they get replaced by newer calls, we will keep the "
1962 "old actions forever. This allows you the developer to program in confidence "
1963 "against the libguestfs API."
1967 #: ../src/guestfs.pod:983
1968 msgid "BLOCK DEVICE NAMING"
1972 #: ../src/guestfs.pod:985
1974 "In the kernel there is now quite a profusion of schemata for naming block "
1975 "devices (in this context, by I<block device> I mean a physical or virtual "
1976 "hard drive). The original Linux IDE driver used names starting with "
1977 "C</dev/hd*>. SCSI devices have historically used a different naming scheme, "
1978 "C</dev/sd*>. When the Linux kernel I<libata> driver became a popular "
1979 "replacement for the old IDE driver (particularly for SATA devices) those "
1980 "devices also used the C</dev/sd*> scheme. Additionally we now have virtual "
1981 "machines with paravirtualized drivers. This has created several different "
1982 "naming systems, such as C</dev/vd*> for virtio disks and C</dev/xvd*> for "
1987 #: ../src/guestfs.pod:997
1989 "As discussed above, libguestfs uses a qemu appliance running an embedded "
1990 "Linux kernel to access block devices. We can run a variety of appliances "
1991 "based on a variety of Linux kernels."
1995 #: ../src/guestfs.pod:1001
1997 "This causes a problem for libguestfs because many API calls use device or "
1998 "partition names. Working scripts and the recipe (example) scripts that we "
1999 "make available over the internet could fail if the naming scheme changes."
2003 #: ../src/guestfs.pod:1006
2005 "Therefore libguestfs defines C</dev/sd*> as the I<standard naming scheme>. "
2006 "Internally C</dev/sd*> names are translated, if necessary, to other names as "
2007 "required. For example, under RHEL 5 which uses the C</dev/hd*> scheme, any "
2008 "device parameter C</dev/sda2> is translated to C</dev/hda2> transparently."
2012 #: ../src/guestfs.pod:1012
2014 "Note that this I<only> applies to parameters. The L</guestfs_list_devices>, "
2015 "L</guestfs_list_partitions> and similar calls return the true names of the "
2016 "devices and partitions as known to the appliance."
2020 #: ../src/guestfs.pod:1017
2021 msgid "ALGORITHM FOR BLOCK DEVICE NAME TRANSLATION"
2025 #: ../src/guestfs.pod:1019
2027 "Usually this translation is transparent. However in some (very rare) cases "
2028 "you may need to know the exact algorithm. Such cases include where you use "
2029 "L</guestfs_config> to add a mixture of virtio and IDE devices to the "
2030 "qemu-based appliance, so have a mixture of C</dev/sd*> and C</dev/vd*> "
2035 #: ../src/guestfs.pod:1025
2037 "The algorithm is applied only to I<parameters> which are known to be either "
2038 "device or partition names. Return values from functions such as "
2039 "L</guestfs_list_devices> are never changed."
2043 #: ../src/guestfs.pod:1033
2044 msgid "Is the string a parameter which is a device or partition name?"
2048 #: ../src/guestfs.pod:1037
2049 msgid "Does the string begin with C</dev/sd>?"
2053 #: ../src/guestfs.pod:1041
2055 "Does the named device exist? If so, we use that device. However if I<not> "
2056 "then we continue with this algorithm."
2060 #: ../src/guestfs.pod:1046
2061 msgid "Replace initial C</dev/sd> string with C</dev/hd>."
2065 #: ../src/guestfs.pod:1048
2066 msgid "For example, change C</dev/sda2> to C</dev/hda2>."
2070 #: ../src/guestfs.pod:1050
2071 msgid "If that named device exists, use it. If not, continue."
2075 #: ../src/guestfs.pod:1054
2076 msgid "Replace initial C</dev/sd> string with C</dev/vd>."
2080 #: ../src/guestfs.pod:1056
2081 msgid "If that named device exists, use it. If not, return an error."
2085 #: ../src/guestfs.pod:1060
2086 msgid "PORTABILITY CONCERNS WITH BLOCK DEVICE NAMING"
2090 #: ../src/guestfs.pod:1062
2092 "Although the standard naming scheme and automatic translation is useful for "
2093 "simple programs and guestfish scripts, for larger programs it is best not to "
2094 "rely on this mechanism."
2098 #: ../src/guestfs.pod:1066
2100 "Where possible for maximum future portability programs using libguestfs "
2101 "should use these future-proof techniques:"
2105 #: ../src/guestfs.pod:1073
2107 "Use L</guestfs_list_devices> or L</guestfs_list_partitions> to list actual "
2108 "device names, and then use those names directly."
2112 #: ../src/guestfs.pod:1076
2113 msgid "Since those device names exist by definition, they will never be translated."
2117 #: ../src/guestfs.pod:1081
2119 "Use higher level ways to identify filesystems, such as LVM names, UUIDs and "
2120 "filesystem labels."
2124 #: ../src/guestfs.pod:1086
2129 #: ../src/guestfs.pod:1088
2131 "This section discusses security implications of using libguestfs, "
2132 "particularly with untrusted or malicious guests or disk images."
2136 #: ../src/guestfs.pod:1091
2137 msgid "GENERAL SECURITY CONSIDERATIONS"
2141 #: ../src/guestfs.pod:1093
2143 "Be careful with any files or data that you download from a guest (by "
2144 "\"download\" we mean not just the L</guestfs_download> command but any "
2145 "command that reads files, filenames, directories or anything else from a "
2146 "disk image). An attacker could manipulate the data to fool your program "
2147 "into doing the wrong thing. Consider cases such as:"
2151 #: ../src/guestfs.pod:1103
2152 msgid "the data (file etc) not being present"
2156 #: ../src/guestfs.pod:1107
2157 msgid "being present but empty"
2161 #: ../src/guestfs.pod:1111
2162 msgid "being much larger than normal"
2166 #: ../src/guestfs.pod:1115
2167 msgid "containing arbitrary 8 bit data"
2171 #: ../src/guestfs.pod:1119
2172 msgid "being in an unexpected character encoding"
2176 #: ../src/guestfs.pod:1123
2177 msgid "containing homoglyphs."
2181 #: ../src/guestfs.pod:1127
2182 msgid "SECURITY OF MOUNTING FILESYSTEMS"
2186 #: ../src/guestfs.pod:1129
2188 "When you mount a filesystem under Linux, mistakes in the kernel filesystem "
2189 "(VFS) module can sometimes be escalated into exploits by deliberately "
2190 "creating a malicious, malformed filesystem. These exploits are very severe "
2191 "for two reasons. Firstly there are very many filesystem drivers in the "
2192 "kernel, and many of them are infrequently used and not much developer "
2193 "attention has been paid to the code. Linux userspace helps potential "
2194 "crackers by detecting the filesystem type and automatically choosing the "
2195 "right VFS driver, even if that filesystem type is obscure or unexpected for "
2196 "the administrator. Secondly, a kernel-level exploit is like a local root "
2197 "exploit (worse in some ways), giving immediate and total access to the "
2198 "system right down to the hardware level."
2202 #: ../src/guestfs.pod:1142
2204 "That explains why you should never mount a filesystem from an untrusted "
2205 "guest on your host kernel. How about libguestfs? We run a Linux kernel "
2206 "inside a qemu virtual machine, usually running as a non-root user. The "
2207 "attacker would need to write a filesystem which first exploited the kernel, "
2208 "and then exploited either qemu virtualization (eg. a faulty qemu driver) or "
2209 "the libguestfs protocol, and finally to be as serious as the host kernel "
2210 "exploit it would need to escalate its privileges to root. This multi-step "
2211 "escalation, performed by a static piece of data, is thought to be extremely "
2212 "hard to do, although we never say 'never' about security issues."
2216 #: ../src/guestfs.pod:1153
2218 "In any case callers can reduce the attack surface by forcing the filesystem "
2219 "type when mounting (use L</guestfs_mount_vfs>)."
2223 #: ../src/guestfs.pod:1156
2224 msgid "PROTOCOL SECURITY"
2228 #: ../src/guestfs.pod:1158
2230 "The protocol is designed to be secure, being based on RFC 4506 (XDR) with a "
2231 "defined upper message size. However a program that uses libguestfs must "
2232 "also take care - for example you can write a program that downloads a binary "
2233 "from a disk image and executes it locally, and no amount of protocol "
2234 "security will save you from the consequences."
2238 #: ../src/guestfs.pod:1164
2239 msgid "INSPECTION SECURITY"
2243 #: ../src/guestfs.pod:1166
2245 "Parts of the inspection API (see L</INSPECTION>) return untrusted strings "
2246 "directly from the guest, and these could contain any 8 bit data. Callers "
2247 "should be careful to escape these before printing them to a structured file "
2248 "(for example, use HTML escaping if creating a web page)."
2252 #: ../src/guestfs.pod:1172
2254 "Guest configuration may be altered in unusual ways by the administrator of "
2255 "the virtual machine, and may not reflect reality (particularly for untrusted "
2256 "or actively malicious guests). For example we parse the hostname from "
2257 "configuration files like C</etc/sysconfig/network> that we find in the "
2258 "guest, but the guest administrator can easily manipulate these files to "
2259 "provide the wrong hostname."
2263 #: ../src/guestfs.pod:1180
2265 "The inspection API parses guest configuration using two external libraries: "
2266 "Augeas (Linux configuration) and hivex (Windows Registry). Both are "
2267 "designed to be robust in the face of malicious data, although denial of "
2268 "service attacks are still possible, for example with oversized configuration "
2273 #: ../src/guestfs.pod:1186
2274 msgid "RUNNING UNTRUSTED GUEST COMMANDS"
2278 #: ../src/guestfs.pod:1188
2280 "Be very cautious about running commands from the guest. By running a "
2281 "command in the guest, you are giving CPU time to a binary that you do not "
2282 "control, under the same user account as the library, albeit wrapped in qemu "
2283 "virtualization. More information and alternatives can be found in the "
2284 "section L</RUNNING COMMANDS>."
2288 #: ../src/guestfs.pod:1194
2289 msgid "CVE-2010-3851"
2293 #: ../src/guestfs.pod:1196
2294 msgid "https://bugzilla.redhat.com/642934"
2298 #: ../src/guestfs.pod:1198
2300 "This security bug concerns the automatic disk format detection that qemu "
2301 "does on disk images."
2305 #: ../src/guestfs.pod:1201
2307 "A raw disk image is just the raw bytes, there is no header. Other disk "
2308 "images like qcow2 contain a special header. Qemu deals with this by looking "
2309 "for one of the known headers, and if none is found then assuming the disk "
2310 "image must be raw."
2314 #: ../src/guestfs.pod:1206
2316 "This allows a guest which has been given a raw disk image to write some "
2317 "other header. At next boot (or when the disk image is accessed by "
2318 "libguestfs) qemu would do autodetection and think the disk image format was, "
2319 "say, qcow2 based on the header written by the guest."
2323 #: ../src/guestfs.pod:1211
2325 "This in itself would not be a problem, but qcow2 offers many features, one "
2326 "of which is to allow a disk image to refer to another image (called the "
2327 "\"backing disk\"). It does this by placing the path to the backing disk "
2328 "into the qcow2 header. This path is not validated and could point to any "
2329 "host file (eg. \"/etc/passwd\"). The backing disk is then exposed through "
2330 "\"holes\" in the qcow2 disk image, which of course is completely under the "
2331 "control of the attacker."
2335 #: ../src/guestfs.pod:1219
2336 msgid "In libguestfs this is rather hard to exploit except under two circumstances:"
2340 #: ../src/guestfs.pod:1226
2341 msgid "You have enabled the network or have opened the disk in write mode."
2345 #: ../src/guestfs.pod:1230
2347 "You are also running untrusted code from the guest (see L</RUNNING "
2352 #: ../src/guestfs.pod:1235
2354 "The way to avoid this is to specify the expected disk format when adding "
2355 "disks (the optional C<format> option to L</guestfs_add_drive_opts>). You "
2356 "should always do this if the disk is raw format, and it's a good idea for "
2361 #: ../src/guestfs.pod:1240
2363 "For disks added from libvirt using calls like L</guestfs_add_domain>, the "
2364 "format is fetched from libvirt and passed through."
2368 #: ../src/guestfs.pod:1243
2370 "For libguestfs tools, use the I<--format> command line parameter as "
2375 #: ../src/guestfs.pod:1246
2376 msgid "CONNECTION MANAGEMENT"
2380 #: ../src/guestfs.pod:1248
2385 #: ../src/guestfs.pod:1250
2387 "C<guestfs_h> is the opaque type representing a connection handle. Create a "
2388 "handle by calling L</guestfs_create>. Call L</guestfs_close> to free the "
2389 "handle and release all resources used."
2393 #: ../src/guestfs.pod:1254
2395 "For information on using multiple handles and threads, see the section "
2396 "L</MULTIPLE HANDLES AND MULTIPLE THREADS> below."
2400 #: ../src/guestfs.pod:1257
2401 msgid "guestfs_create"
2405 #: ../src/guestfs.pod:1259
2408 " guestfs_h *guestfs_create (void);\n"
2413 #: ../src/guestfs.pod:1261
2414 msgid "Create a connection handle."
2418 #: ../src/guestfs.pod:1263
2420 "You have to call L</guestfs_add_drive_opts> (or one of the equivalent calls) "
2421 "on the handle at least once."
2425 #: ../src/guestfs.pod:1266
2427 "This function returns a non-NULL pointer to a handle on success or NULL on "
2432 #: ../src/guestfs.pod:1269
2433 msgid "After configuring the handle, you have to call L</guestfs_launch>."
2437 #: ../src/guestfs.pod:1271
2439 "You may also want to configure error handling for the handle. See L</ERROR "
2440 "HANDLING> section below."
2444 #: ../src/guestfs.pod:1274
2445 msgid "guestfs_close"
2449 #: ../src/guestfs.pod:1276
2452 " void guestfs_close (guestfs_h *g);\n"
2457 #: ../src/guestfs.pod:1278
2458 msgid "This closes the connection handle and frees up all resources used."
2462 #: ../src/guestfs.pod:1280
2463 msgid "ERROR HANDLING"
2467 #: ../src/guestfs.pod:1282
2469 "API functions can return errors. For example, almost all functions that "
2470 "return C<int> will return C<-1> to indicate an error."
2474 #: ../src/guestfs.pod:1285
2476 "Additional information is available for errors: an error message string and "
2477 "optionally an error number (errno) if the thing that failed was a system "
2482 #: ../src/guestfs.pod:1289
2484 "You can get at the additional information about the last error on the handle "
2485 "by calling L</guestfs_last_error>, L</guestfs_last_errno>, and/or by setting "
2486 "up an error handler with L</guestfs_set_error_handler>."
2490 #: ../src/guestfs.pod:1294
2492 "When the handle is created, a default error handler is installed which "
2493 "prints the error message string to C<stderr>. For small short-running "
2494 "command line programs it is sufficient to do:"
2498 #: ../src/guestfs.pod:1298
2501 " if (guestfs_launch (g) == -1)\n"
2502 " exit (EXIT_FAILURE);\n"
2507 #: ../src/guestfs.pod:1301
2509 "since the default error handler will ensure that an error message has been "
2510 "printed to C<stderr> before the program exits."
2514 #: ../src/guestfs.pod:1304
2516 "For other programs the caller will almost certainly want to install an "
2517 "alternate error handler or do error handling in-line like this:"
2521 #: ../src/guestfs.pod:1307
2524 " g = guestfs_create ();\n"
2529 #: ../src/guestfs.pod:1309
2532 " /* This disables the default behaviour of printing errors\n"
2534 " guestfs_set_error_handler (g, NULL, NULL);\n"
2539 #: ../src/guestfs.pod:1313
2542 " if (guestfs_launch (g) == -1) {\n"
2543 " /* Examine the error message and print it etc. */\n"
2544 " char *msg = guestfs_last_error (g);\n"
2545 " int errnum = guestfs_last_errno (g);\n"
2546 " fprintf (stderr, \"%s\\n\", msg);\n"
2553 #: ../src/guestfs.pod:1321
2555 "Out of memory errors are handled differently. The default action is to call "
2556 "L<abort(3)>. If this is undesirable, then you can set a handler using "
2557 "L</guestfs_set_out_of_memory_handler>."
2561 #: ../src/guestfs.pod:1325
2563 "L</guestfs_create> returns C<NULL> if the handle cannot be created, and "
2564 "because there is no handle if this happens there is no way to get additional "
2565 "error information. However L</guestfs_create> is supposed to be a "
2566 "lightweight operation which can only fail because of insufficient memory (it "
2567 "returns NULL in this case)."
2571 #: ../src/guestfs.pod:1331
2572 msgid "guestfs_last_error"
2576 #: ../src/guestfs.pod:1333
2579 " const char *guestfs_last_error (guestfs_h *g);\n"
2584 #: ../src/guestfs.pod:1335
2586 "This returns the last error message that happened on C<g>. If there has not "
2587 "been an error since the handle was created, then this returns C<NULL>."
2591 #: ../src/guestfs.pod:1339
2593 "The lifetime of the returned string is until the next error occurs, or "
2594 "L</guestfs_close> is called."
2598 #: ../src/guestfs.pod:1342
2599 msgid "guestfs_last_errno"
2603 #: ../src/guestfs.pod:1344
2606 " int guestfs_last_errno (guestfs_h *g);\n"
2611 #: ../src/guestfs.pod:1346
2612 msgid "This returns the last error number (errno) that happened on C<g>."
2616 #: ../src/guestfs.pod:1348
2617 msgid "If successful, an errno integer not equal to zero is returned."
2621 #: ../src/guestfs.pod:1350
2622 msgid "If no error, this returns 0. This call can return 0 in three situations:"
2626 #: ../src/guestfs.pod:1357
2627 msgid "There has not been any error on the handle."
2631 #: ../src/guestfs.pod:1361
2633 "There has been an error but the errno was meaningless. This corresponds to "
2634 "the case where the error did not come from a failed system call, but for "
2635 "some other reason."
2639 #: ../src/guestfs.pod:1367
2641 "There was an error from a failed system call, but for some reason the errno "
2642 "was not captured and returned. This usually indicates a bug in libguestfs."
2646 #: ../src/guestfs.pod:1373
2648 "Libguestfs tries to convert the errno from inside the applicance into a "
2649 "corresponding errno for the caller (not entirely trivial: the appliance "
2650 "might be running a completely different operating system from the library "
2651 "and error numbers are not standardized across Un*xen). If this could not be "
2652 "done, then the error is translated to C<EINVAL>. In practice this should "
2653 "only happen in very rare circumstances."
2657 #: ../src/guestfs.pod:1381
2658 msgid "guestfs_set_error_handler"
2662 #: ../src/guestfs.pod:1383
2665 " typedef void (*guestfs_error_handler_cb) (guestfs_h *g,\n"
2667 " const char *msg);\n"
2668 " void guestfs_set_error_handler (guestfs_h *g,\n"
2669 " guestfs_error_handler_cb cb,\n"
2675 #: ../src/guestfs.pod:1390
2677 "The callback C<cb> will be called if there is an error. The parameters "
2678 "passed to the callback are an opaque data pointer and the error message "
2683 #: ../src/guestfs.pod:1394
2685 "C<errno> is not passed to the callback. To get that the callback must call "
2686 "L</guestfs_last_errno>."
2690 #: ../src/guestfs.pod:1397
2692 "Note that the message string C<msg> is freed as soon as the callback "
2693 "function returns, so if you want to stash it somewhere you must make your "
2698 #: ../src/guestfs.pod:1401
2699 msgid "The default handler prints messages on C<stderr>."
2703 #: ../src/guestfs.pod:1403
2704 msgid "If you set C<cb> to C<NULL> then I<no> handler is called."
2708 #: ../src/guestfs.pod:1405
2709 msgid "guestfs_get_error_handler"
2713 #: ../src/guestfs.pod:1407
2716 " guestfs_error_handler_cb guestfs_get_error_handler (guestfs_h *g,\n"
2717 " void **opaque_rtn);\n"
2722 #: ../src/guestfs.pod:1410
2723 msgid "Returns the current error handler callback."
2727 #: ../src/guestfs.pod:1412
2728 msgid "guestfs_set_out_of_memory_handler"
2732 #: ../src/guestfs.pod:1414
2735 " typedef void (*guestfs_abort_cb) (void);\n"
2736 " int guestfs_set_out_of_memory_handler (guestfs_h *g,\n"
2737 " guestfs_abort_cb);\n"
2742 #: ../src/guestfs.pod:1418
2744 "The callback C<cb> will be called if there is an out of memory situation. "
2745 "I<Note this callback must not return>."
2749 #: ../src/guestfs.pod:1421
2750 msgid "The default is to call L<abort(3)>."
2754 #: ../src/guestfs.pod:1423
2755 msgid "You cannot set C<cb> to C<NULL>. You can't ignore out of memory situations."
2759 #: ../src/guestfs.pod:1426
2760 msgid "guestfs_get_out_of_memory_handler"
2764 #: ../src/guestfs.pod:1428
2767 " guestfs_abort_fn guestfs_get_out_of_memory_handler (guestfs_h *g);\n"
2772 #: ../src/guestfs.pod:1430
2773 msgid "This returns the current out of memory handler."
2777 #: ../src/guestfs.pod:1432
2782 #: ../src/guestfs.pod:1434 ../fish/guestfish.pod:984
2787 #: ../src/guestfs.pod:1436
2792 #: ../src/guestfs.pod:1438
2797 #: ../src/guestfs.pod:1440
2798 msgid "AVAILABILITY"
2802 #: ../src/guestfs.pod:1442
2803 msgid "GROUPS OF FUNCTIONALITY IN THE APPLIANCE"
2807 #: ../src/guestfs.pod:1444
2809 "Using L</guestfs_available> you can test availability of the following "
2810 "groups of functions. This test queries the appliance to see if the "
2811 "appliance you are currently using supports the functionality."
2815 #: ../src/guestfs.pod:1449
2816 msgid "@AVAILABILITY@"
2820 #: ../src/guestfs.pod:1451
2821 msgid "GUESTFISH supported COMMAND"
2825 #: ../src/guestfs.pod:1453
2827 "In L<guestfish(3)> there is a handy interactive command C<supported> which "
2828 "prints out the available groups and whether they are supported by this build "
2829 "of libguestfs. Note however that you have to do C<run> first."
2833 #: ../src/guestfs.pod:1458
2834 msgid "SINGLE CALLS AT COMPILE TIME"
2838 #: ../src/guestfs.pod:1460
2840 "Since version 1.5.8, C<E<lt>guestfs.hE<gt>> defines symbols for each C API "
2841 "function, such as:"
2845 #: ../src/guestfs.pod:1463
2848 " #define LIBGUESTFS_HAVE_DD 1\n"
2853 #: ../src/guestfs.pod:1465
2854 msgid "if L</guestfs_dd> is available."
2858 #: ../src/guestfs.pod:1467
2860 "Before version 1.5.8, if you needed to test whether a single libguestfs "
2861 "function is available at compile time, we recommended using build tools such "
2862 "as autoconf or cmake. For example in autotools you could use:"
2866 #: ../src/guestfs.pod:1472
2869 " AC_CHECK_LIB([guestfs],[guestfs_create])\n"
2870 " AC_CHECK_FUNCS([guestfs_dd])\n"
2875 #: ../src/guestfs.pod:1475
2877 "which would result in C<HAVE_GUESTFS_DD> being either defined or not defined "
2882 #: ../src/guestfs.pod:1478
2883 msgid "SINGLE CALLS AT RUN TIME"
2887 #: ../src/guestfs.pod:1480
2889 "Testing at compile time doesn't guarantee that a function really exists in "
2890 "the library. The reason is that you might be dynamically linked against a "
2891 "previous I<libguestfs.so> (dynamic library) which doesn't have the call. "
2892 "This situation unfortunately results in a segmentation fault, which is a "
2893 "shortcoming of the C dynamic linking system itself."
2897 #: ../src/guestfs.pod:1487
2899 "You can use L<dlopen(3)> to test if a function is available at run time, as "
2900 "in this example program (note that you still need the compile time check as "
2905 #: ../src/guestfs.pod:1491
2908 " #include <stdio.h>\n"
2909 " #include <stdlib.h>\n"
2910 " #include <unistd.h>\n"
2911 " #include <dlfcn.h>\n"
2912 " #include <guestfs.h>\n"
2917 #: ../src/guestfs.pod:1497
2922 " #ifdef LIBGUESTFS_HAVE_DD\n"
2924 " int has_function;\n"
2929 #: ../src/guestfs.pod:1503
2932 " /* Test if the function guestfs_dd is really available. */\n"
2933 " dl = dlopen (NULL, RTLD_LAZY);\n"
2935 " fprintf (stderr, \"dlopen: %s\\n\", dlerror ());\n"
2936 " exit (EXIT_FAILURE);\n"
2938 " has_function = dlsym (dl, \"guestfs_dd\") != NULL;\n"
2944 #: ../src/guestfs.pod:1512
2947 " if (!has_function)\n"
2948 " printf (\"this libguestfs.so does NOT have guestfs_dd function\\n\");\n"
2950 " printf (\"this libguestfs.so has guestfs_dd function\\n\");\n"
2951 " /* Now it's safe to call\n"
2952 " guestfs_dd (g, \"foo\", \"bar\");\n"
2956 " printf (\"guestfs_dd function was not found at compile time\\n\");\n"
2963 #: ../src/guestfs.pod:1525
2965 "You may think the above is an awful lot of hassle, and it is. There are "
2966 "other ways outside of the C linking system to ensure that this kind of "
2967 "incompatibility never arises, such as using package versioning:"
2971 #: ../src/guestfs.pod:1530
2974 " Requires: libguestfs >= 1.0.80\n"
2979 #: ../src/guestfs.pod:1532
2980 msgid "CALLS WITH OPTIONAL ARGUMENTS"
2984 #: ../src/guestfs.pod:1534
2986 "A recent feature of the API is the introduction of calls which take optional "
2987 "arguments. In C these are declared 3 ways. The main way is as a call which "
2988 "takes variable arguments (ie. C<...>), as in this example:"
2992 #: ../src/guestfs.pod:1539
2995 " int guestfs_add_drive_opts (guestfs_h *g, const char *filename, ...);\n"
3000 #: ../src/guestfs.pod:1541
3002 "Call this with a list of optional arguments, terminated by C<-1>. So to "
3003 "call with no optional arguments specified:"
3007 #: ../src/guestfs.pod:1544
3010 " guestfs_add_drive_opts (g, filename, -1);\n"
3015 #: ../src/guestfs.pod:1546
3016 msgid "With a single optional argument:"
3020 #: ../src/guestfs.pod:1548
3023 " guestfs_add_drive_opts (g, filename,\n"
3024 " GUESTFS_ADD_DRIVE_OPTS_FORMAT, \"qcow2\",\n"
3030 #: ../src/guestfs.pod:1552
3035 #: ../src/guestfs.pod:1554
3038 " guestfs_add_drive_opts (g, filename,\n"
3039 " GUESTFS_ADD_DRIVE_OPTS_FORMAT, \"qcow2\",\n"
3040 " GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,\n"
3046 #: ../src/guestfs.pod:1559
3048 "and so forth. Don't forget the terminating C<-1> otherwise Bad Things will "
3053 #: ../src/guestfs.pod:1562
3054 msgid "USING va_list FOR OPTIONAL ARGUMENTS"
3058 #: ../src/guestfs.pod:1564
3060 "The second variant has the same name with the suffix C<_va>, which works the "
3061 "same way but takes a C<va_list>. See the C manual for details. For the "
3062 "example function, this is declared:"
3066 #: ../src/guestfs.pod:1568
3069 " int guestfs_add_drive_opts_va (guestfs_h *g, const char *filename,\n"
3075 #: ../src/guestfs.pod:1571
3076 msgid "CONSTRUCTING OPTIONAL ARGUMENTS"
3080 #: ../src/guestfs.pod:1573
3082 "The third variant is useful where you need to construct these calls. You "
3083 "pass in a structure where you fill in the optional fields. The structure "
3084 "has a bitmask as the first element which you must set to indicate which "
3085 "fields you have filled in. For our example function the structure and call "
3090 #: ../src/guestfs.pod:1579
3093 " struct guestfs_add_drive_opts_argv {\n"
3094 " uint64_t bitmask;\n"
3096 " const char *format;\n"
3099 " int guestfs_add_drive_opts_argv (guestfs_h *g, const char *filename,\n"
3100 " const struct guestfs_add_drive_opts_argv *optargs);\n"
3105 #: ../src/guestfs.pod:1588
3106 msgid "You could call it like this:"
3110 #: ../src/guestfs.pod:1590
3113 " struct guestfs_add_drive_opts_argv optargs = {\n"
3114 " .bitmask = GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK |\n"
3115 " GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK,\n"
3117 " .format = \"qcow2\"\n"
3123 #: ../src/guestfs.pod:1597
3126 " guestfs_add_drive_opts_argv (g, filename, &optargs);\n"
3131 #: ../src/guestfs.pod:1599 ../src/guestfs-actions.pod:11 ../src/guestfs-actions.pod:1842 ../fish/guestfish-actions.pod:9 ../fish/guestfish-actions.pod:1253 ../tools/virt-win-reg.pl:532
3136 #: ../src/guestfs.pod:1605
3137 msgid "The C<_BITMASK> suffix on each option name when specifying the bitmask."
3141 #: ../src/guestfs.pod:1610
3142 msgid "You do not need to fill in all fields of the structure."
3146 #: ../src/guestfs.pod:1614
3148 "There must be a one-to-one correspondence between fields of the structure "
3149 "that are filled in, and bits set in the bitmask."
3153 #: ../src/guestfs.pod:1619
3154 msgid "OPTIONAL ARGUMENTS IN OTHER LANGUAGES"
3158 #: ../src/guestfs.pod:1621
3160 "In other languages, optional arguments are expressed in the way that is "
3161 "natural for that language. We refer you to the language-specific "
3162 "documentation for more details on that."
3166 #: ../src/guestfs.pod:1625
3167 msgid "For guestfish, see L<guestfish(1)/OPTIONAL ARGUMENTS>."
3171 #: ../src/guestfs.pod:1627
3172 msgid "SETTING CALLBACKS TO HANDLE EVENTS"
3176 #: ../src/guestfs.pod:1629
3178 "The child process generates events in some situations. Current events "
3179 "include: receiving a log message, the child process exits."
3183 #: ../src/guestfs.pod:1632
3185 "Use the C<guestfs_set_*_callback> functions to set a callback for different "
3190 #: ../src/guestfs.pod:1635
3192 "Only I<one callback of each type> can be registered for each handle. "
3193 "Calling C<guestfs_set_*_callback> again overwrites the previous callback of "
3194 "that type. Cancel all callbacks of this type by calling this function with "
3195 "C<cb> set to C<NULL>."
3199 #: ../src/guestfs.pod:1640
3200 msgid "guestfs_set_log_message_callback"
3204 #: ../src/guestfs.pod:1642
3207 " typedef void (*guestfs_log_message_cb) (guestfs_h *g, void *opaque,\n"
3208 " char *buf, int len);\n"
3209 " void guestfs_set_log_message_callback (guestfs_h *g,\n"
3210 " guestfs_log_message_cb cb,\n"
3216 #: ../src/guestfs.pod:1648
3218 "The callback function C<cb> will be called whenever qemu or the guest writes "
3219 "anything to the console."
3223 #: ../src/guestfs.pod:1651
3224 msgid "Use this function to capture kernel messages and similar."
3228 #: ../src/guestfs.pod:1653
3230 "Normally there is no log message handler, and log messages are just "
3235 #: ../src/guestfs.pod:1656
3236 msgid "guestfs_set_subprocess_quit_callback"
3240 #: ../src/guestfs.pod:1658
3243 " typedef void (*guestfs_subprocess_quit_cb) (guestfs_h *g, void *opaque);\n"
3244 " void guestfs_set_subprocess_quit_callback (guestfs_h *g,\n"
3245 " guestfs_subprocess_quit_cb cb,\n"
3251 #: ../src/guestfs.pod:1663
3253 "The callback function C<cb> will be called when the child process quits, "
3254 "either asynchronously or if killed by L</guestfs_kill_subprocess>. (This "
3255 "corresponds to a transition from any state to the CONFIG state)."
3259 #: ../src/guestfs.pod:1668
3260 msgid "guestfs_set_launch_done_callback"
3264 #: ../src/guestfs.pod:1670
3267 " typedef void (*guestfs_launch_done_cb) (guestfs_h *g, void *opaque);\n"
3268 " void guestfs_set_launch_done_callback (guestfs_h *g,\n"
3269 " guestfs_launch_done_cb cb,\n"
3275 #: ../src/guestfs.pod:1675
3277 "The callback function C<cb> will be called when the child process becomes "
3278 "ready first time after it has been launched. (This corresponds to a "
3279 "transition from LAUNCHING to the READY state)."
3283 #: ../src/guestfs.pod:1679
3284 msgid "guestfs_set_close_callback"
3288 #: ../src/guestfs.pod:1681
3291 " typedef void (*guestfs_close_cb) (guestfs_h *g, void *opaque);\n"
3292 " void guestfs_set_close_callback (guestfs_h *g,\n"
3293 " guestfs_close_cb cb,\n"
3299 #: ../src/guestfs.pod:1686
3301 "The callback function C<cb> will be called while the handle is being closed "
3302 "(synchronously from L</guestfs_close>)."
3306 #: ../src/guestfs.pod:1689
3308 "Note that libguestfs installs an L<atexit(3)> handler to try to clean up "
3309 "handles that are open when the program exits. This means that this callback "
3310 "might be called indirectly from L<exit(3)>, which can cause unexpected "
3311 "problems in higher-level languages (eg. if your HLL interpreter has already "
3312 "been cleaned up by the time this is called, and if your callback then jumps "
3313 "into some HLL function)."
3317 #: ../src/guestfs.pod:1697
3318 msgid "guestfs_set_progress_callback"
3322 #: ../src/guestfs.pod:1699
3325 " typedef void (*guestfs_progress_cb) (guestfs_h *g, void *opaque,\n"
3326 " int proc_nr, int serial,\n"
3327 " uint64_t position, uint64_t total);\n"
3328 " void guestfs_set_progress_callback (guestfs_h *g,\n"
3329 " guestfs_progress_cb cb,\n"
3335 #: ../src/guestfs.pod:1706
3337 "Some long-running operations can generate progress messages. If this "
3338 "callback is registered, then it will be called each time a progress message "
3339 "is generated (usually two seconds after the operation started, and three "
3340 "times per second thereafter until it completes, although the frequency may "
3341 "change in future versions)."
3345 #: ../src/guestfs.pod:1712
3347 "The callback receives two numbers: C<position> and C<total>. The units of "
3348 "C<total> are not defined, although for some operations C<total> may relate "
3349 "in some way to the amount of data to be transferred (eg. in bytes or "
3350 "megabytes), and C<position> may be the portion which has been transferred."
3354 #: ../src/guestfs.pod:1718
3355 msgid "The only defined and stable parts of the API are:"
3359 #: ../src/guestfs.pod:1724
3361 "The callback can display to the user some type of progress bar or indicator "
3362 "which shows the ratio of C<position>:C<total>."
3366 #: ../src/guestfs.pod:1729
3367 msgid "0 E<lt>= C<position> E<lt>= C<total>"
3371 #: ../src/guestfs.pod:1733
3373 "If any progress notification is sent during a call, then a final progress "
3374 "notification is always sent when C<position> = C<total>."
3378 #: ../src/guestfs.pod:1736
3380 "This is to simplify caller code, so callers can easily set the progress "
3381 "indicator to \"100%\" at the end of the operation, without requiring special "
3382 "code to detect this case."
3386 #: ../src/guestfs.pod:1742
3388 "The callback also receives the procedure number and serial number of the "
3389 "call. These are only useful for debugging protocol issues, and the callback "
3390 "can normally ignore them. The callback may want to print these numbers in "
3391 "error messages or debugging messages."
3395 #: ../src/guestfs.pod:1747
3396 msgid "PRIVATE DATA AREA"
3400 #: ../src/guestfs.pod:1749
3402 "You can attach named pieces of private data to the libguestfs handle, and "
3403 "fetch them by name for the lifetime of the handle. This is called the "
3404 "private data area and is only available from the C API."
3408 #: ../src/guestfs.pod:1753
3409 msgid "To attach a named piece of data, use the following call:"
3413 #: ../src/guestfs.pod:1755
3416 " void guestfs_set_private (guestfs_h *g, const char *key, void *data);\n"
3421 #: ../src/guestfs.pod:1757
3423 "C<key> is the name to associate with this data, and C<data> is an arbitrary "
3424 "pointer (which can be C<NULL>). Any previous item with the same name is "
3429 #: ../src/guestfs.pod:1761
3431 "You can use any C<key> you want, but names beginning with an underscore "
3432 "character are reserved for internal libguestfs purposes (for implementing "
3433 "language bindings). It is recommended to prefix the name with some unique "
3434 "string to avoid collisions with other users."
3438 #: ../src/guestfs.pod:1766
3439 msgid "To retrieve the pointer, use:"
3443 #: ../src/guestfs.pod:1768
3446 " void *guestfs_get_private (guestfs_h *g, const char *key);\n"
3451 #: ../src/guestfs.pod:1770
3453 "This function returns C<NULL> if either no data is found associated with "
3454 "C<key>, or if the user previously set the C<key>'s C<data> pointer to "
3459 #: ../src/guestfs.pod:1774
3461 "Libguestfs does not try to look at or interpret the C<data> pointer in any "
3462 "way. As far as libguestfs is concerned, it need not be a valid pointer at "
3463 "all. In particular, libguestfs does I<not> try to free the data when the "
3464 "handle is closed. If the data must be freed, then the caller must either "
3465 "free it before calling L</guestfs_close> or must set up a close callback to "
3466 "do it (see L</guestfs_set_close_callback>, and note that only one callback "
3467 "can be registered for a handle)."
3471 #: ../src/guestfs.pod:1782
3473 "The private data area is implemented using a hash table, and should be "
3474 "reasonably efficient for moderate numbers of keys."
3478 #: ../src/guestfs.pod:1785 ../src/guestfs.pod:1790
3483 #: ../src/guestfs.pod:1787
3485 "<!-- old anchor for the next section --> <a "
3486 "name=\"state_machine_and_low_level_event_api\"/>"
3490 #: ../src/guestfs.pod:1792
3491 msgid "ARCHITECTURE"
3495 #: ../src/guestfs.pod:1794
3497 "Internally, libguestfs is implemented by running an appliance (a special "
3498 "type of small virtual machine) using L<qemu(1)>. Qemu runs as a child "
3499 "process of the main program."
3503 #: ../src/guestfs.pod:1798
3506 " ___________________\n"
3508 " | main program |\n"
3510 " | | child process / appliance\n"
3511 " | | __________________________\n"
3513 " +-------------------+ RPC | +-----------------+ |\n"
3514 " | libguestfs <--------------------> guestfsd | |\n"
3515 " | | | +-----------------+ |\n"
3516 " \\___________________/ | | Linux kernel | |\n"
3517 " | +--^--------------+ |\n"
3518 " \\_________|________________/\n"
3524 " \\______________/\n"
3529 #: ../src/guestfs.pod:1818
3531 "The library, linked to the main program, creates the child process and hence "
3532 "the appliance in the L</guestfs_launch> function."
3536 #: ../src/guestfs.pod:1821
3538 "Inside the appliance is a Linux kernel and a complete stack of userspace "
3539 "tools (such as LVM and ext2 programs) and a small controlling daemon called "
3540 "L</guestfsd>. The library talks to L</guestfsd> using remote procedure "
3541 "calls (RPC). There is a mostly one-to-one correspondence between libguestfs "
3542 "API calls and RPC calls to the daemon. Lastly the disk image(s) are "
3543 "attached to the qemu process which translates device access by the "
3544 "appliance's Linux kernel into accesses to the image."
3548 #: ../src/guestfs.pod:1830
3550 "A common misunderstanding is that the appliance \"is\" the virtual machine. "
3551 "Although the disk image you are attached to might also be used by some "
3552 "virtual machine, libguestfs doesn't know or care about this. (But you will "
3553 "care if both libguestfs's qemu process and your virtual machine are trying "
3554 "to update the disk image at the same time, since these usually results in "
3555 "massive disk corruption)."
3559 #: ../src/guestfs.pod:1837
3560 msgid "STATE MACHINE"
3564 #: ../src/guestfs.pod:1839
3565 msgid "libguestfs uses a state machine to model the child process:"
3569 #: ../src/guestfs.pod:1841
3581 " / | \\ \\ guestfs_launch\n"
3582 " / | _\\__V______\n"
3584 " / | | LAUNCHING |\n"
3585 " / | \\___________/\n"
3587 " / | guestfs_launch\n"
3589 " ______ / __|____V\n"
3590 " / \\ ------> / \\\n"
3591 " | BUSY | | READY |\n"
3592 " \\______/ <------ \\________/\n"
3597 #: ../src/guestfs.pod:1863
3599 "The normal transitions are (1) CONFIG (when the handle is created, but there "
3600 "is no child process), (2) LAUNCHING (when the child process is booting up), "
3601 "(3) alternating between READY and BUSY as commands are issued to, and "
3602 "carried out by, the child process."
3606 #: ../src/guestfs.pod:1868
3608 "The guest may be killed by L</guestfs_kill_subprocess>, or may die "
3609 "asynchronously at any time (eg. due to some internal error), and that causes "
3610 "the state to transition back to CONFIG."
3614 #: ../src/guestfs.pod:1872
3616 "Configuration commands for qemu such as L</guestfs_add_drive> can only be "
3617 "issued when in the CONFIG state."
3621 #: ../src/guestfs.pod:1875
3623 "The API offers one call that goes from CONFIG through LAUNCHING to READY. "
3624 "L</guestfs_launch> blocks until the child process is READY to accept "
3625 "commands (or until some failure or timeout). L</guestfs_launch> internally "
3626 "moves the state from CONFIG to LAUNCHING while it is running."
3630 #: ../src/guestfs.pod:1881
3632 "API actions such as L</guestfs_mount> can only be issued when in the READY "
3633 "state. These API calls block waiting for the command to be carried out "
3634 "(ie. the state to transition to BUSY and then back to READY). There are no "
3635 "non-blocking versions, and no way to issue more than one command per handle "
3640 #: ../src/guestfs.pod:1887
3642 "Finally, the child process sends asynchronous messages back to the main "
3643 "program, such as kernel log messages. You can register a callback to "
3644 "receive these messages."
3648 #: ../src/guestfs.pod:1891
3653 #: ../src/guestfs.pod:1893
3654 msgid "COMMUNICATION PROTOCOL"
3658 #: ../src/guestfs.pod:1895
3660 "Don't rely on using this protocol directly. This section documents how it "
3661 "currently works, but it may change at any time."
3665 #: ../src/guestfs.pod:1898
3667 "The protocol used to talk between the library and the daemon running inside "
3668 "the qemu virtual machine is a simple RPC mechanism built on top of XDR (RFC "
3669 "1014, RFC 1832, RFC 4506)."
3673 #: ../src/guestfs.pod:1902
3675 "The detailed format of structures is in C<src/guestfs_protocol.x> (note: "
3676 "this file is automatically generated)."
3680 #: ../src/guestfs.pod:1905
3682 "There are two broad cases, ordinary functions that don't have any C<FileIn> "
3683 "and C<FileOut> parameters, which are handled with very simple request/reply "
3684 "messages. Then there are functions that have any C<FileIn> or C<FileOut> "
3685 "parameters, which use the same request and reply messages, but they may also "
3686 "be followed by files sent using a chunked encoding."
3690 #: ../src/guestfs.pod:1912
3691 msgid "ORDINARY FUNCTIONS (NO FILEIN/FILEOUT PARAMS)"
3695 #: ../src/guestfs.pod:1914
3696 msgid "For ordinary functions, the request message is:"
3700 #: ../src/guestfs.pod:1916
3703 " total length (header + arguments,\n"
3704 " but not including the length word itself)\n"
3705 " struct guestfs_message_header (encoded as XDR)\n"
3706 " struct guestfs_<foo>_args (encoded as XDR)\n"
3711 #: ../src/guestfs.pod:1921
3713 "The total length field allows the daemon to allocate a fixed size buffer "
3714 "into which it slurps the rest of the message. As a result, the total length "
3715 "is limited to C<GUESTFS_MESSAGE_MAX> bytes (currently 4MB), which means the "
3716 "effective size of any request is limited to somewhere under this size."
3720 #: ../src/guestfs.pod:1927
3722 "Note also that many functions don't take any arguments, in which case the "
3723 "C<guestfs_I<foo>_args> is completely omitted."
3727 #: ../src/guestfs.pod:1930
3729 "The header contains the procedure number (C<guestfs_proc>) which is how the "
3730 "receiver knows what type of args structure to expect, or none at all."
3734 #: ../src/guestfs.pod:1934
3736 "For functions that take optional arguments, the optional arguments are "
3737 "encoded in the C<guestfs_I<foo>_args> structure in the same way as ordinary "
3738 "arguments. A bitmask in the header indicates which optional arguments are "
3739 "meaningful. The bitmask is also checked to see if it contains bits set "
3740 "which the daemon does not know about (eg. if more optional arguments were "
3741 "added in a later version of the library), and this causes the call to be "
3746 #: ../src/guestfs.pod:1942
3747 msgid "The reply message for ordinary functions is:"
3751 #: ../src/guestfs.pod:1944
3754 " total length (header + ret,\n"
3755 " but not including the length word itself)\n"
3756 " struct guestfs_message_header (encoded as XDR)\n"
3757 " struct guestfs_<foo>_ret (encoded as XDR)\n"
3762 #: ../src/guestfs.pod:1949
3764 "As above the C<guestfs_I<foo>_ret> structure may be completely omitted for "
3765 "functions that return no formal return values."
3769 #: ../src/guestfs.pod:1952
3770 msgid "As above the total length of the reply is limited to C<GUESTFS_MESSAGE_MAX>."
3774 #: ../src/guestfs.pod:1955
3776 "In the case of an error, a flag is set in the header, and the reply message "
3777 "is slightly changed:"
3781 #: ../src/guestfs.pod:1958
3784 " total length (header + error,\n"
3785 " but not including the length word itself)\n"
3786 " struct guestfs_message_header (encoded as XDR)\n"
3787 " struct guestfs_message_error (encoded as XDR)\n"
3792 #: ../src/guestfs.pod:1963
3794 "The C<guestfs_message_error> structure contains the error message as a "
3799 #: ../src/guestfs.pod:1966
3800 msgid "FUNCTIONS THAT HAVE FILEIN PARAMETERS"
3804 #: ../src/guestfs.pod:1968
3806 "A C<FileIn> parameter indicates that we transfer a file I<into> the guest. "
3807 "The normal request message is sent (see above). However this is followed by "
3808 "a sequence of file chunks."
3812 #: ../src/guestfs.pod:1972
3815 " total length (header + arguments,\n"
3816 " but not including the length word itself,\n"
3817 " and not including the chunks)\n"
3818 " struct guestfs_message_header (encoded as XDR)\n"
3819 " struct guestfs_<foo>_args (encoded as XDR)\n"
3820 " sequence of chunks for FileIn param #0\n"
3821 " sequence of chunks for FileIn param #1 etc.\n"
3826 #: ../src/guestfs.pod:1980
3827 msgid "The \"sequence of chunks\" is:"
3831 #: ../src/guestfs.pod:1982
3834 " length of chunk (not including length word itself)\n"
3835 " struct guestfs_chunk (encoded as XDR)\n"
3836 " length of chunk\n"
3837 " struct guestfs_chunk (encoded as XDR)\n"
3839 " length of chunk\n"
3840 " struct guestfs_chunk (with data.data_len == 0)\n"
3845 #: ../src/guestfs.pod:1990
3847 "The final chunk has the C<data_len> field set to zero. Additionally a flag "
3848 "is set in the final chunk to indicate either successful completion or early "
3853 #: ../src/guestfs.pod:1994
3855 "At time of writing there are no functions that have more than one FileIn "
3856 "parameter. However this is (theoretically) supported, by sending the "
3857 "sequence of chunks for each FileIn parameter one after another (from left to "
3862 #: ../src/guestfs.pod:1999
3864 "Both the library (sender) I<and> the daemon (receiver) may cancel the "
3865 "transfer. The library does this by sending a chunk with a special flag set "
3866 "to indicate cancellation. When the daemon sees this, it cancels the whole "
3867 "RPC, does I<not> send any reply, and goes back to reading the next request."
3871 #: ../src/guestfs.pod:2005
3873 "The daemon may also cancel. It does this by writing a special word "
3874 "C<GUESTFS_CANCEL_FLAG> to the socket. The library listens for this during "
3875 "the transfer, and if it gets it, it will cancel the transfer (it sends a "
3876 "cancel chunk). The special word is chosen so that even if cancellation "
3877 "happens right at the end of the transfer (after the library has finished "
3878 "writing and has started listening for the reply), the \"spurious\" cancel "
3879 "flag will not be confused with the reply message."
3883 #: ../src/guestfs.pod:2014
3885 "This protocol allows the transfer of arbitrary sized files (no 32 bit "
3886 "limit), and also files where the size is not known in advance (eg. from "
3887 "pipes or sockets). However the chunks are rather small "
3888 "(C<GUESTFS_MAX_CHUNK_SIZE>), so that neither the library nor the daemon need "
3889 "to keep much in memory."
3893 #: ../src/guestfs.pod:2020
3894 msgid "FUNCTIONS THAT HAVE FILEOUT PARAMETERS"
3898 #: ../src/guestfs.pod:2022
3900 "The protocol for FileOut parameters is exactly the same as for FileIn "
3901 "parameters, but with the roles of daemon and library reversed."
3905 #: ../src/guestfs.pod:2025
3908 " total length (header + ret,\n"
3909 " but not including the length word itself,\n"
3910 " and not including the chunks)\n"
3911 " struct guestfs_message_header (encoded as XDR)\n"
3912 " struct guestfs_<foo>_ret (encoded as XDR)\n"
3913 " sequence of chunks for FileOut param #0\n"
3914 " sequence of chunks for FileOut param #1 etc.\n"
3919 #: ../src/guestfs.pod:2033
3920 msgid "INITIAL MESSAGE"
3924 #: ../src/guestfs.pod:2035
3926 "When the daemon launches it sends an initial word (C<GUESTFS_LAUNCH_FLAG>) "
3927 "which indicates that the guest and daemon is alive. This is what "
3928 "L</guestfs_launch> waits for."
3932 #: ../src/guestfs.pod:2039
3933 msgid "PROGRESS NOTIFICATION MESSAGES"
3937 #: ../src/guestfs.pod:2041
3939 "The daemon may send progress notification messages at any time. These are "
3940 "distinguished by the normal length word being replaced by "
3941 "C<GUESTFS_PROGRESS_FLAG>, followed by a fixed size progress message."
3945 #: ../src/guestfs.pod:2045
3947 "The library turns them into progress callbacks (see "
3948 "C<guestfs_set_progress_callback>) if there is a callback registered, or "
3949 "discards them if not."
3953 #: ../src/guestfs.pod:2049
3955 "The daemon self-limits the frequency of progress messages it sends (see "
3956 "C<daemon/proto.c:notify_progress>). Not all calls generate progress "
3961 #: ../src/guestfs.pod:2053
3962 msgid "LIBGUESTFS VERSION NUMBERS"
3966 #: ../src/guestfs.pod:2055
3968 "Since April 2010, libguestfs has started to make separate development and "
3969 "stable releases, along with corresponding branches in our git repository. "
3970 "These separate releases can be identified by version number:"
3974 #: ../src/guestfs.pod:2060
3977 " even numbers for stable: 1.2.x, 1.4.x, ...\n"
3978 " .-------- odd numbers for development: 1.3.x, 1.5.x, ...\n"
3984 " | `-------- sub-version\n"
3986 " `------ always '1' because we don't change the ABI\n"
3991 #: ../src/guestfs.pod:2071
3992 msgid "Thus \"1.3.5\" is the 5th update to the development branch \"1.3\"."
3996 #: ../src/guestfs.pod:2073
3998 "As time passes we cherry pick fixes from the development branch and backport "
3999 "those into the stable branch, the effect being that the stable branch should "
4000 "get more stable and less buggy over time. So the stable releases are ideal "
4001 "for people who don't need new features but would just like the software to "
4006 #: ../src/guestfs.pod:2079
4007 msgid "Our criteria for backporting changes are:"
4011 #: ../src/guestfs.pod:2085
4013 "Documentation changes which don't affect any code are backported unless the "
4014 "documentation refers to a future feature which is not in stable."
4018 #: ../src/guestfs.pod:2091
4020 "Bug fixes which are not controversial, fix obvious problems, and have been "
4021 "well tested are backported."
4025 #: ../src/guestfs.pod:2096
4027 "Simple rearrangements of code which shouldn't affect how it works get "
4028 "backported. This is so that the code in the two branches doesn't get too "
4029 "far out of step, allowing us to backport future fixes more easily."
4033 #: ../src/guestfs.pod:2102
4035 "We I<don't> backport new features, new APIs, new tools etc, except in one "
4036 "exceptional case: the new feature is required in order to implement an "
4037 "important bug fix."
4041 #: ../src/guestfs.pod:2108
4043 "A new stable branch starts when we think the new features in development are "
4044 "substantial and compelling enough over the current stable branch to warrant "
4045 "it. When that happens we create new stable and development versions 1.N.0 "
4046 "and 1.(N+1).0 [N is even]. The new dot-oh release won't necessarily be so "
4047 "stable at this point, but by backporting fixes from development, that branch "
4048 "will stabilize over time."
4052 #: ../src/guestfs.pod:2116
4053 msgid "EXTENDING LIBGUESTFS"
4057 #: ../src/guestfs.pod:2118
4058 msgid "ADDING A NEW API ACTION"
4062 #: ../src/guestfs.pod:2120
4064 "Large amounts of boilerplate code in libguestfs (RPC, bindings, "
4065 "documentation) are generated, and this makes it easy to extend the "
4070 #: ../src/guestfs.pod:2124
4071 msgid "To add a new API action there are two changes:"
4075 #: ../src/guestfs.pod:2130
4077 "You need to add a description of the call (name, parameters, return type, "
4078 "tests, documentation) to C<generator/generator_actions.ml>."
4082 #: ../src/guestfs.pod:2133
4084 "There are two sorts of API action, depending on whether the call goes "
4085 "through to the daemon in the appliance, or is serviced entirely by the "
4086 "library (see L</ARCHITECTURE> above). L</guestfs_sync> is an example of the "
4087 "former, since the sync is done in the appliance. L</guestfs_set_trace> is "
4088 "an example of the latter, since a trace flag is maintained in the handle and "
4089 "all tracing is done on the library side."
4093 #: ../src/guestfs.pod:2141
4095 "Most new actions are of the first type, and get added to the "
4096 "C<daemon_functions> list. Each function has a unique procedure number used "
4097 "in the RPC protocol which is assigned to that action when we publish "
4098 "libguestfs and cannot be reused. Take the latest procedure number and "
4103 #: ../src/guestfs.pod:2147
4105 "For library-only actions of the second type, add to the "
4106 "C<non_daemon_functions> list. Since these functions are serviced by the "
4107 "library and do not travel over the RPC mechanism to the daemon, these "
4108 "functions do not need a procedure number, and so the procedure number is set "
4113 #: ../src/guestfs.pod:2155
4114 msgid "Implement the action (in C):"
4118 #: ../src/guestfs.pod:2157
4120 "For daemon actions, implement the function C<do_E<lt>nameE<gt>> in the "
4121 "C<daemon/> directory."
4125 #: ../src/guestfs.pod:2160
4127 "For library actions, implement the function C<guestfs__E<lt>nameE<gt>> "
4128 "(note: double underscore) in the C<src/> directory."
4132 #: ../src/guestfs.pod:2163
4133 msgid "In either case, use another function as an example of what to do."
4137 #: ../src/guestfs.pod:2167
4138 msgid "After making these changes, use C<make> to compile."
4142 #: ../src/guestfs.pod:2169
4144 "Note that you don't need to implement the RPC, language bindings, manual "
4145 "pages or anything else. It's all automatically generated from the OCaml "
4150 #: ../src/guestfs.pod:2173
4151 msgid "ADDING TESTS FOR AN API ACTION"
4155 #: ../src/guestfs.pod:2175
4157 "You can supply zero or as many tests as you want per API call. The tests "
4158 "can either be added as part of the API description "
4159 "(C<generator/generator_actions.ml>), or in some rarer cases you may want to "
4160 "drop a script into C<regressions/>. Note that adding a script to "
4161 "C<regressions/> is slower, so if possible use the first method."
4165 #: ../src/guestfs.pod:2181
4167 "The following describes the test environment used when you add an API test "
4168 "in C<generator_actions.ml>."
4172 #: ../src/guestfs.pod:2184
4173 msgid "The test environment has 4 block devices:"
4177 #: ../src/guestfs.pod:2188
4178 msgid "C</dev/sda> 500MB"
4182 #: ../src/guestfs.pod:2190
4183 msgid "General block device for testing."
4187 #: ../src/guestfs.pod:2192
4188 msgid "C</dev/sdb> 50MB"
4192 #: ../src/guestfs.pod:2194
4194 "C</dev/sdb1> is an ext2 filesystem used for testing filesystem write "
4199 #: ../src/guestfs.pod:2197
4200 msgid "C</dev/sdc> 10MB"
4204 #: ../src/guestfs.pod:2199
4205 msgid "Used in a few tests where two block devices are needed."
4209 #: ../src/guestfs.pod:2201
4214 #: ../src/guestfs.pod:2203
4215 msgid "ISO with fixed content (see C<images/test.iso>)."
4219 #: ../src/guestfs.pod:2207
4221 "To be able to run the tests in a reasonable amount of time, the libguestfs "
4222 "appliance and block devices are reused between tests. So don't try testing "
4223 "L</guestfs_kill_subprocess> :-x"
4227 #: ../src/guestfs.pod:2211
4229 "Each test starts with an initial scenario, selected using one of the "
4230 "C<Init*> expressions, described in C<generator/generator_types.ml>. These "
4231 "initialize the disks mentioned above in a particular way as documented in "
4232 "C<generator_types.ml>. You should not assume anything about the previous "
4233 "contents of other disks that are not initialized."
4237 #: ../src/guestfs.pod:2217
4239 "You can add a prerequisite clause to any individual test. This is a "
4240 "run-time check, which, if it fails, causes the test to be skipped. Useful "
4241 "if testing a command which might not work on all variations of libguestfs "
4242 "builds. A test that has prerequisite of C<Always> means to run "
4247 #: ../src/guestfs.pod:2223
4249 "In addition, packagers can skip individual tests by setting environment "
4250 "variables before running C<make check>."
4254 #: ../src/guestfs.pod:2226
4257 " SKIP_TEST_<CMD>_<NUM>=1\n"
4262 #: ../src/guestfs.pod:2228
4263 msgid "eg: C<SKIP_TEST_COMMAND_3=1> skips test #3 of L</guestfs_command>."
4267 #: ../src/guestfs.pod:2230
4272 #: ../src/guestfs.pod:2232
4275 " SKIP_TEST_<CMD>=1\n"
4280 #: ../src/guestfs.pod:2234
4281 msgid "eg: C<SKIP_TEST_ZEROFREE=1> skips all L</guestfs_zerofree> tests."
4285 #: ../src/guestfs.pod:2236
4286 msgid "Packagers can run only certain tests by setting for example:"
4290 #: ../src/guestfs.pod:2238
4293 " TEST_ONLY=\"vfs_type zerofree\"\n"
4298 #: ../src/guestfs.pod:2240
4300 "See C<capitests/tests.c> for more details of how these environment variables "
4305 #: ../src/guestfs.pod:2243
4306 msgid "DEBUGGING NEW API ACTIONS"
4310 #: ../src/guestfs.pod:2245
4311 msgid "Test new actions work before submitting them."
4315 #: ../src/guestfs.pod:2247
4316 msgid "You can use guestfish to try out new commands."
4320 #: ../src/guestfs.pod:2249
4322 "Debugging the daemon is a problem because it runs inside a minimal "
4323 "environment. However you can fprintf messages in the daemon to stderr, and "
4324 "they will show up if you use C<guestfish -v>."
4328 #: ../src/guestfs.pod:2253
4329 msgid "FORMATTING CODE AND OTHER CONVENTIONS"
4333 #: ../src/guestfs.pod:2255
4335 "Our C source code generally adheres to some basic code-formatting "
4336 "conventions. The existing code base is not totally consistent on this "
4337 "front, but we do prefer that contributed code be formatted similarly. In "
4338 "short, use spaces-not-TABs for indentation, use 2 spaces for each "
4339 "indentation level, and other than that, follow the K&R style."
4343 #: ../src/guestfs.pod:2261
4345 "If you use Emacs, add the following to one of one of your start-up files "
4346 "(e.g., ~/.emacs), to help ensure that you get indentation right:"
4350 #: ../src/guestfs.pod:2264
4353 " ;;; In libguestfs, indent with spaces everywhere (not TABs).\n"
4354 " ;;; Exceptions: Makefile and ChangeLog modes.\n"
4355 " (add-hook 'find-file-hook\n"
4356 " '(lambda () (if (and buffer-file-name\n"
4357 " (string-match \"/libguestfs\\\\>\"\n"
4358 " (buffer-file-name))\n"
4359 " (not (string-equal mode-name \"Change Log\"))\n"
4360 " (not (string-equal mode-name \"Makefile\")))\n"
4361 " (setq indent-tabs-mode nil))))\n"
4366 #: ../src/guestfs.pod:2274
4369 " ;;; When editing C sources in libguestfs, use this style.\n"
4370 " (defun libguestfs-c-mode ()\n"
4371 " \"C mode with adjusted defaults for use with libguestfs.\"\n"
4373 " (c-set-style \"K&R\")\n"
4374 " (setq c-indent-level 2)\n"
4375 " (setq c-basic-offset 2))\n"
4376 " (add-hook 'c-mode-hook\n"
4377 " '(lambda () (if (string-match \"/libguestfs\\\\>\"\n"
4378 " (buffer-file-name))\n"
4379 " (libguestfs-c-mode))))\n"
4384 #: ../src/guestfs.pod:2286
4385 msgid "Enable warnings when compiling (and fix any problems this finds):"
4389 #: ../src/guestfs.pod:2289
4392 " ./configure --enable-gcc-warnings\n"
4397 #: ../src/guestfs.pod:2291
4398 msgid "Useful targets are:"
4402 #: ../src/guestfs.pod:2293
4405 " make syntax-check # checks the syntax of the C code\n"
4406 " make check # runs the test suite\n"
4411 #: ../src/guestfs.pod:2296
4412 msgid "DAEMON CUSTOM PRINTF FORMATTERS"
4416 #: ../src/guestfs.pod:2298
4418 "In the daemon code we have created custom printf formatters C<%Q> and C<%R>, "
4419 "which are used to do shell quoting."
4423 #: ../src/guestfs.pod:2303
4428 #: ../src/guestfs.pod:2305
4430 "Simple shell quoted string. Any spaces or other shell characters are "
4435 #: ../src/guestfs.pod:2308
4440 #: ../src/guestfs.pod:2310
4442 "Same as C<%Q> except the string is treated as a path which is prefixed by "
4447 #: ../src/guestfs.pod:2315 ../fish/guestfish.pod:240 ../fish/guestfish.pod:594
4448 msgid "For example:"
4452 #: ../src/guestfs.pod:2317
4455 " asprintf (&cmd, \"cat %R\", path);\n"
4460 #: ../src/guestfs.pod:2319
4461 msgid "would produce C<cat /sysroot/some\\ path\\ with\\ spaces>"
4465 #: ../src/guestfs.pod:2321
4467 "I<Note:> Do I<not> use these when you are passing parameters to the "
4468 "C<command{,r,v,rv}()> functions. These parameters do NOT need to be quoted "
4469 "because they are not passed via the shell (instead, straight to exec). You "
4470 "probably want to use the C<sysroot_path()> function however."
4474 #: ../src/guestfs.pod:2327
4475 msgid "SUBMITTING YOUR NEW API ACTIONS"
4479 #: ../src/guestfs.pod:2329
4481 "Submit patches to the mailing list: "
4482 "L<http://www.redhat.com/mailman/listinfo/libguestfs> and CC to "
4483 "L<rjones@redhat.com>."
4487 #: ../src/guestfs.pod:2333
4488 msgid "INTERNATIONALIZATION (I18N) SUPPORT"
4492 #: ../src/guestfs.pod:2335
4493 msgid "We support i18n (gettext anyhow) in the library."
4497 #: ../src/guestfs.pod:2337
4499 "However many messages come from the daemon, and we don't translate those at "
4500 "the moment. One reason is that the appliance generally has all locale files "
4501 "removed from it, because they take up a lot of space. So we'd have to readd "
4502 "some of those, as well as copying our PO files into the appliance."
4506 #: ../src/guestfs.pod:2343
4508 "Debugging messages are never translated, since they are intended for the "
4513 #: ../src/guestfs.pod:2346
4514 msgid "SOURCE CODE SUBDIRECTORIES"
4518 #: ../src/guestfs.pod:2350
4519 msgid "C<appliance>"
4523 #: ../src/guestfs.pod:2352
4524 msgid "The libguestfs appliance, build scripts and so on."
4528 #: ../src/guestfs.pod:2354
4529 msgid "C<capitests>"
4533 #: ../src/guestfs.pod:2356
4534 msgid "Automated tests of the C API."
4538 #: ../src/guestfs.pod:2358
4543 #: ../src/guestfs.pod:2360
4545 "The L<virt-cat(1)>, L<virt-filesystems(1)> and L<virt-ls(1)> commands and "
4550 #: ../src/guestfs.pod:2363
4555 #: ../src/guestfs.pod:2365
4556 msgid "Outside contributions, experimental parts."
4560 #: ../src/guestfs.pod:2367
4565 #: ../src/guestfs.pod:2369
4567 "The daemon that runs inside the libguestfs appliance and carries out "
4572 #: ../src/guestfs.pod:2372
4577 #: ../src/guestfs.pod:2374
4578 msgid "L<virt-df(1)> command and documentation."