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.11.2\n"
10 "Report-Msgid-Bugs-To: libguestfs@redhat.com\n"
11 "POT-Creation-Date: 2011-04-18 20:45+0200\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-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-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-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:1087 ../src/guestfs.pod:1091 ../src/guestfs.pod:1095 ../src/guestfs.pod:1100 ../src/guestfs.pod:1108 ../src/guestfs.pod:1127 ../src/guestfs.pod:1135 ../src/guestfs.pod:1157 ../src/guestfs.pod:1161 ../src/guestfs.pod:1165 ../src/guestfs.pod:1169 ../src/guestfs.pod:1173 ../src/guestfs.pod:1177 ../src/guestfs.pod:1659 ../src/guestfs.pod:1664 ../src/guestfs.pod:1668 ../src/guestfs.pod:1769 ../src/guestfs.pod:1774 ../src/guestfs.pod:1778 ../src/guestfs.pod:1788 ../src/guestfs.pod:2022 ../src/guestfs.pod:2027 ../src/guestfs.pod:2033 ../src/guestfs.pod:2041 ../src/guestfs.pod:2395 ../src/guestfs.pod:2401 ../src/guestfs.pod:2406 ../src/guestfs.pod:2412 ../src/guestfs.pod:2877 ../src/guestfs.pod:2881 ../src/guestfs.pod:2885 ../src/guestfs.pod:2889 ../src/guestfs-actions.pod:15 ../src/guestfs-actions.pod:22 ../src/guestfs-actions.pod:577 ../src/guestfs-actions.pod:585 ../src/guestfs-actions.pod:592 ../src/guestfs-actions.pod:599 ../src/guestfs-actions.pod:1600 ../src/guestfs-actions.pod:1604 ../src/guestfs-actions.pod:1608 ../src/guestfs-actions.pod:1612 ../src/guestfs-actions.pod:1620 ../src/guestfs-actions.pod:1624 ../src/guestfs-actions.pod:1628 ../src/guestfs-actions.pod:1638 ../src/guestfs-actions.pod:1642 ../src/guestfs-actions.pod:1646 ../src/guestfs-actions.pod:1784 ../src/guestfs-actions.pod:1788 ../src/guestfs-actions.pod:1793 ../src/guestfs-actions.pod:1798 ../src/guestfs-actions.pod:1859 ../src/guestfs-actions.pod:1863 ../src/guestfs-actions.pod:1868 ../fish/guestfish.pod:443 ../fish/guestfish.pod:447 ../fish/guestfish.pod:451 ../fish/guestfish.pod:455 ../fish/guestfish-actions.pod:13 ../fish/guestfish-actions.pod:20 ../fish/guestfish-actions.pod:380 ../fish/guestfish-actions.pod:388 ../fish/guestfish-actions.pod:395 ../fish/guestfish-actions.pod:402 ../fish/guestfish-actions.pod:1072 ../fish/guestfish-actions.pod:1076 ../fish/guestfish-actions.pod:1080 ../fish/guestfish-actions.pod:1084 ../fish/guestfish-actions.pod:1092 ../fish/guestfish-actions.pod:1096 ../fish/guestfish-actions.pod:1100 ../fish/guestfish-actions.pod:1110 ../fish/guestfish-actions.pod:1114 ../fish/guestfish-actions.pod:1118 ../fish/guestfish-actions.pod:1208 ../fish/guestfish-actions.pod:1212 ../fish/guestfish-actions.pod:1217 ../fish/guestfish-actions.pod:1222 ../fish/guestfish-actions.pod:1264 ../fish/guestfish-actions.pod:1268 ../fish/guestfish-actions.pod:1273 ../tools/virt-edit.pl:351 ../tools/virt-edit.pl:356 ../tools/virt-edit.pl:361 ../tools/virt-edit.pl:372 ../tools/virt-edit.pl:376 ../tools/virt-win-reg.pl:536 ../tools/virt-win-reg.pl:542 ../tools/virt-win-reg.pl:548
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:1280 ../src/guestfs.pod:1411 ../src/guestfs.pod:2440
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:1284 ../src/guestfs.pod:1415 ../src/guestfs.pod:2465
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:1421
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:765
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 can be found using inspection (see L</INSPECTION> and "
1279 "L</guestfs_inspect_get_drive_mappings>)"
1283 #: ../src/guestfs.pod:647
1285 "Dealing with separator characters (backslash vs forward slash) is outside "
1286 "the scope of libguestfs, but usually a simple character replacement will "
1291 #: ../src/guestfs.pod:651
1293 "To resolve the case insensitivity of paths, call "
1294 "L</guestfs_case_sensitive_path>."
1298 #: ../src/guestfs.pod:654
1299 msgid "ACCESSING THE WINDOWS REGISTRY"
1303 #: ../src/guestfs.pod:656
1305 "Libguestfs also provides some help for decoding Windows Registry \"hive\" "
1306 "files, through the library C<hivex> which is part of the libguestfs project "
1307 "although ships as a separate tarball. You have to locate and download the "
1308 "hive file(s) yourself, and then pass them to C<hivex> functions. See also "
1309 "the programs L<hivexml(1)>, L<hivexsh(1)>, L<hivexregedit(1)> and "
1310 "L<virt-win-reg(1)> for more help on this issue."
1314 #: ../src/guestfs.pod:664
1315 msgid "SYMLINKS ON NTFS-3G FILESYSTEMS"
1319 #: ../src/guestfs.pod:666
1321 "Ntfs-3g tries to rewrite \"Junction Points\" and NTFS \"symbolic links\" to "
1322 "provide something which looks like a Linux symlink. The way it tries to do "
1323 "the rewriting is described here:"
1327 #: ../src/guestfs.pod:670
1328 msgid "L<http://www.tuxera.com/community/ntfs-3g-advanced/junction-points-and-symbolic-links/>"
1332 #: ../src/guestfs.pod:672
1334 "The essential problem is that ntfs-3g simply does not have enough "
1335 "information to do a correct job. NTFS links can contain drive letters and "
1336 "references to external device GUIDs that ntfs-3g has no way of resolving. "
1337 "It is almost certainly the case that libguestfs callers should ignore what "
1338 "ntfs-3g does (ie. don't use L</guestfs_readlink> on NTFS volumes)."
1342 #: ../src/guestfs.pod:679
1344 "Instead if you encounter a symbolic link on an ntfs-3g filesystem, use "
1345 "L</guestfs_lgetxattr> to read the C<system.ntfs_reparse_data> extended "
1346 "attribute, and read the raw reparse data from that (you can find the format "
1347 "documented in various places around the web)."
1351 #: ../src/guestfs.pod:684
1352 msgid "EXTENDED ATTRIBUTES ON NTFS-3G FILESYSTEMS"
1356 #: ../src/guestfs.pod:686
1358 "There are other useful extended attributes that can be read from ntfs-3g "
1359 "filesystems (using L</guestfs_getxattr>). See:"
1363 #: ../src/guestfs.pod:689
1364 msgid "L<http://www.tuxera.com/community/ntfs-3g-advanced/extended-attributes/>"
1368 #: ../src/guestfs.pod:691
1369 msgid "USING LIBGUESTFS WITH OTHER PROGRAMMING LANGUAGES"
1373 #: ../src/guestfs.pod:693
1375 "Although we don't want to discourage you from using the C API, we will "
1376 "mention here that the same API is also available in other languages."
1380 #: ../src/guestfs.pod:696
1382 "The API is broadly identical in all supported languages. This means that "
1383 "the C call C<guestfs_add_drive_ro(g,file)> is C<$g-E<gt>add_drive_ro($file)> "
1384 "in Perl, C<g.add_drive_ro(file)> in Python, and C<g#add_drive_ro file> in "
1385 "OCaml. In other words, a straightforward, predictable isomorphism between "
1390 #: ../src/guestfs.pod:702
1392 "Error messages are automatically transformed into exceptions if the language "
1397 #: ../src/guestfs.pod:705
1399 "We don't try to \"object orientify\" parts of the API in OO languages, "
1400 "although contributors are welcome to write higher level APIs above what we "
1401 "provide in their favourite languages if they wish."
1405 #: ../src/guestfs.pod:711
1410 #: ../src/guestfs.pod:713
1412 "You can use the I<guestfs.h> header file from C++ programs. The C++ API is "
1413 "identical to the C API. C++ classes and exceptions are not used."
1417 #: ../src/guestfs.pod:717
1422 #: ../src/guestfs.pod:719
1424 "The C# bindings are highly experimental. Please read the warnings at the "
1425 "top of C<csharp/Libguestfs.cs>."
1429 #: ../src/guestfs.pod:722
1434 #: ../src/guestfs.pod:724
1436 "This is the only language binding that is working but incomplete. Only "
1437 "calls which return simple integers have been bound in Haskell, and we are "
1438 "looking for help to complete this binding."
1442 #: ../src/guestfs.pod:728
1447 #: ../src/guestfs.pod:730
1449 "Full documentation is contained in the Javadoc which is distributed with "
1454 #: ../src/guestfs.pod:733
1459 #: ../src/guestfs.pod:735
1460 msgid "See L<guestfs-ocaml(3)>."
1464 #: ../src/guestfs.pod:737
1469 #: ../src/guestfs.pod:739
1470 msgid "See L<guestfs-perl(3)> and L<Sys::Guestfs(3)>."
1474 #: ../src/guestfs.pod:741
1479 #: ../src/guestfs.pod:743
1481 "For documentation see C<README-PHP> supplied with libguestfs sources or in "
1482 "the php-libguestfs package for your distribution."
1486 #: ../src/guestfs.pod:746
1487 msgid "The PHP binding only works correctly on 64 bit machines."
1491 #: ../src/guestfs.pod:748
1496 #: ../src/guestfs.pod:750
1497 msgid "See L<guestfs-python(3)>."
1501 #: ../src/guestfs.pod:752
1506 #: ../src/guestfs.pod:754
1507 msgid "See L<guestfs-ruby(3)>."
1511 #: ../src/guestfs.pod:756
1512 msgid "B<shell scripts>"
1516 #: ../src/guestfs.pod:758
1517 msgid "See L<guestfish(1)>."
1521 #: ../src/guestfs.pod:762
1522 msgid "LIBGUESTFS GOTCHAS"
1526 #: ../src/guestfs.pod:764
1528 "L<http://en.wikipedia.org/wiki/Gotcha_(programming)>: \"A feature of a "
1529 "system [...] that works in the way it is documented but is counterintuitive "
1530 "and almost invites mistakes.\""
1534 #: ../src/guestfs.pod:768
1536 "Since we developed libguestfs and the associated tools, there are several "
1537 "things we would have designed differently, but are now stuck with for "
1538 "backwards compatibility or other reasons. If there is ever a libguestfs 2.0 "
1539 "release, you can expect these to change. Beware of them."
1543 #: ../src/guestfs.pod:776
1544 msgid "Autosync / forgetting to sync."
1548 #: ../src/guestfs.pod:778
1550 "When modifying a filesystem from C or another language, you B<must> unmount "
1551 "all filesystems and call L</guestfs_sync> explicitly before you close the "
1552 "libguestfs handle. You can also call:"
1556 #: ../src/guestfs.pod:782
1559 " guestfs_set_autosync (g, 1);\n"
1564 #: ../src/guestfs.pod:784
1566 "to have the unmount/sync done automatically for you when the handle 'g' is "
1567 "closed. (This feature is called \"autosync\", L</guestfs_set_autosync> "
1572 #: ../src/guestfs.pod:788
1574 "If you forget to do this, then it is entirely possible that your changes "
1575 "won't be written out, or will be partially written, or (very rarely) that "
1576 "you'll get disk corruption."
1580 #: ../src/guestfs.pod:792
1582 "Note that in L<guestfish(3)> autosync is the default. So quick and dirty "
1583 "guestfish scripts that forget to sync will work just fine, which can make "
1584 "this very puzzling if you are trying to debug a problem."
1588 #: ../src/guestfs.pod:796
1590 "Update: Autosync is enabled by default for all API users starting from "
1591 "libguestfs 1.5.24."
1595 #: ../src/guestfs.pod:799
1596 msgid "Mount option C<-o sync> should not be the default."
1600 #: ../src/guestfs.pod:801
1602 "If you use L</guestfs_mount>, then C<-o sync,noatime> are added implicitly. "
1603 "However C<-o sync> does not add any reliability benefit, but does have a "
1604 "very large performance impact."
1608 #: ../src/guestfs.pod:805
1610 "The work around is to use L</guestfs_mount_options> and set the mount "
1611 "options that you actually want to use."
1615 #: ../src/guestfs.pod:808
1616 msgid "Read-only should be the default."
1620 #: ../src/guestfs.pod:810
1622 "In L<guestfish(3)>, I<--ro> should be the default, and you should have to "
1623 "specify I<--rw> if you want to make changes to the image."
1627 #: ../src/guestfs.pod:813
1628 msgid "This would reduce the potential to corrupt live VM images."
1632 #: ../src/guestfs.pod:815
1634 "Note that many filesystems change the disk when you just mount and unmount, "
1635 "even if you didn't perform any writes. You need to use "
1636 "L</guestfs_add_drive_ro> to guarantee that the disk is not changed."
1640 #: ../src/guestfs.pod:819
1641 msgid "guestfish command line is hard to use."
1645 #: ../src/guestfs.pod:821
1647 "C<guestfish disk.img> doesn't do what people expect (open C<disk.img> for "
1648 "examination). It tries to run a guestfish command C<disk.img> which doesn't "
1649 "exist, so it fails. In earlier versions of guestfish the error message was "
1650 "also unintuitive, but we have corrected this since. Like the Bourne shell, "
1651 "we should have used C<guestfish -c command> to run commands."
1655 #: ../src/guestfs.pod:828
1656 msgid "guestfish megabyte modifiers don't work right on all commands"
1660 #: ../src/guestfs.pod:830
1662 "In recent guestfish you can use C<1M> to mean 1 megabyte (and similarly for "
1663 "other modifiers). What guestfish actually does is to multiply the number "
1664 "part by the modifier part and pass the result to the C API. However this "
1665 "doesn't work for a few APIs which aren't expecting bytes, but are already "
1666 "expecting some other unit (eg. megabytes)."
1670 #: ../src/guestfs.pod:837
1671 msgid "The most common is L</guestfs_lvcreate>. The guestfish command:"
1675 #: ../src/guestfs.pod:839
1678 " lvcreate LV VG 100M\n"
1683 #: ../src/guestfs.pod:841
1685 "does not do what you might expect. Instead because L</guestfs_lvcreate> is "
1686 "already expecting megabytes, this tries to create a 100 I<terabyte> (100 "
1687 "megabytes * megabytes) logical volume. The error message you get from this "
1688 "is also a little obscure."
1692 #: ../src/guestfs.pod:846
1694 "This could be fixed in the generator by specially marking parameters and "
1695 "return values which take bytes or other units."
1699 #: ../src/guestfs.pod:849
1700 msgid "Ambiguity between devices and paths"
1704 #: ../src/guestfs.pod:851
1706 "There is a subtle ambiguity in the API between a device name "
1707 "(eg. C</dev/sdb2>) and a similar pathname. A file might just happen to be "
1708 "called C<sdb2> in the directory C</dev> (consider some non-Unix VM image)."
1712 #: ../src/guestfs.pod:856
1714 "In the current API we usually resolve this ambiguity by having two separate "
1715 "calls, for example L</guestfs_checksum> and L</guestfs_checksum_device>. "
1716 "Some API calls are ambiguous and (incorrectly) resolve the problem by "
1717 "detecting if the path supplied begins with C</dev/>."
1721 #: ../src/guestfs.pod:862
1723 "To avoid both the ambiguity and the need to duplicate some calls, we could "
1724 "make paths/devices into structured names. One way to do this would be to "
1725 "use a notation like grub (C<hd(0,0)>), although nobody really likes this "
1726 "aspect of grub. Another way would be to use a structured type, equivalent "
1727 "to this OCaml type:"
1731 #: ../src/guestfs.pod:868
1734 " type path = Path of string | Device of int | Partition of int * int\n"
1739 #: ../src/guestfs.pod:870
1740 msgid "which would allow you to pass arguments like:"
1744 #: ../src/guestfs.pod:872
1747 " Path \"/foo/bar\"\n"
1748 " Device 1 (* /dev/sdb, or perhaps /dev/sda *)\n"
1749 " Partition (1, 2) (* /dev/sdb2 (or is it /dev/sda2 or /dev/sdb3?) *)\n"
1750 " Path \"/dev/sdb2\" (* not a device *)\n"
1755 #: ../src/guestfs.pod:877
1757 "As you can see there are still problems to resolve even with this "
1758 "representation. Also consider how it might work in guestfish."
1762 #: ../src/guestfs.pod:882
1763 msgid "PROTOCOL LIMITS"
1767 #: ../src/guestfs.pod:884
1769 "Internally libguestfs uses a message-based protocol to pass API calls and "
1770 "their responses to and from a small \"appliance\" (see L</INTERNALS> for "
1771 "plenty more detail about this). The maximum message size used by the "
1772 "protocol is slightly less than 4 MB. For some API calls you may need to be "
1773 "aware of this limit. The API calls which may be affected are individually "
1774 "documented, with a link back to this section of the documentation."
1778 #: ../src/guestfs.pod:892
1780 "A simple call such as L</guestfs_cat> returns its result (the file data) in "
1781 "a simple string. Because this string is at some point internally encoded as "
1782 "a message, the maximum size that it can return is slightly under 4 MB. If "
1783 "the requested file is larger than this then you will get an error."
1787 #: ../src/guestfs.pod:898
1789 "In order to transfer large files into and out of the guest filesystem, you "
1790 "need to use particular calls that support this. The sections L</UPLOADING> "
1791 "and L</DOWNLOADING> document how to do this."
1795 #: ../src/guestfs.pod:902
1797 "You might also consider mounting the disk image using our FUSE filesystem "
1798 "support (L<guestmount(1)>)."
1802 #: ../src/guestfs.pod:905
1803 msgid "KEYS AND PASSPHRASES"
1807 #: ../src/guestfs.pod:907
1809 "Certain libguestfs calls take a parameter that contains sensitive key "
1810 "material, passed in as a C string."
1814 #: ../src/guestfs.pod:910
1816 "In the future we would hope to change the libguestfs implementation so that "
1817 "keys are L<mlock(2)>-ed into physical RAM, and thus can never end up in "
1818 "swap. However this is I<not> done at the moment, because of the complexity "
1819 "of such an implementation."
1823 #: ../src/guestfs.pod:915
1825 "Therefore you should be aware that any key parameter you pass to libguestfs "
1826 "might end up being written out to the swap partition. If this is a concern, "
1827 "scrub the swap partition or don't use libguestfs on encrypted devices."
1831 #: ../src/guestfs.pod:920
1832 msgid "MULTIPLE HANDLES AND MULTIPLE THREADS"
1836 #: ../src/guestfs.pod:922
1838 "All high-level libguestfs actions are synchronous. If you want to use "
1839 "libguestfs asynchronously then you must create a thread."
1843 #: ../src/guestfs.pod:925
1845 "Only use the handle from a single thread. Either use the handle exclusively "
1846 "from one thread, or provide your own mutex so that two threads cannot issue "
1847 "calls on the same handle at the same time."
1851 #: ../src/guestfs.pod:929
1853 "See the graphical program guestfs-browser for one possible architecture for "
1854 "multithreaded programs using libvirt and libguestfs."
1858 #: ../src/guestfs.pod:932
1863 #: ../src/guestfs.pod:934
1865 "Libguestfs needs a supermin appliance, which it finds by looking along an "
1870 #: ../src/guestfs.pod:937
1872 "By default it looks for these in the directory C<$libdir/guestfs> "
1873 "(eg. C</usr/local/lib/guestfs> or C</usr/lib64/guestfs>)."
1877 #: ../src/guestfs.pod:940
1879 "Use L</guestfs_set_path> or set the environment variable L</LIBGUESTFS_PATH> "
1880 "to change the directories that libguestfs will search in. The value is a "
1881 "colon-separated list of paths. The current directory is I<not> searched "
1882 "unless the path contains an empty element or C<.>. For example "
1883 "C<LIBGUESTFS_PATH=:/usr/lib/guestfs> would search the current directory and "
1884 "then C</usr/lib/guestfs>."
1888 #: ../src/guestfs.pod:947
1889 msgid "QEMU WRAPPERS"
1893 #: ../src/guestfs.pod:949
1895 "If you want to compile your own qemu, run qemu from a non-standard location, "
1896 "or pass extra arguments to qemu, then you can write a shell-script wrapper "
1901 #: ../src/guestfs.pod:953
1903 "There is one important rule to remember: you I<must C<exec qemu>> as the "
1904 "last command in the shell script (so that qemu replaces the shell and "
1905 "becomes the direct child of the libguestfs-using program). If you don't do "
1906 "this, then the qemu process won't be cleaned up correctly."
1910 #: ../src/guestfs.pod:958
1912 "Here is an example of a wrapper, where I have built my own copy of qemu from "
1917 #: ../src/guestfs.pod:961
1921 " qemudir=/home/rjones/d/qemu\n"
1922 " exec $qemudir/x86_64-softmmu/qemu-system-x86_64 -L $qemudir/pc-bios "
1928 #: ../src/guestfs.pod:965
1930 "Save this script as C</tmp/qemu.wrapper> (or wherever), C<chmod +x>, and "
1931 "then use it by setting the LIBGUESTFS_QEMU environment variable. For "
1936 #: ../src/guestfs.pod:969
1939 " LIBGUESTFS_QEMU=/tmp/qemu.wrapper guestfish\n"
1944 #: ../src/guestfs.pod:971
1946 "Note that libguestfs also calls qemu with the -help and -version options in "
1947 "order to determine features."
1951 #: ../src/guestfs.pod:974
1952 msgid "ATTACHING TO RUNNING DAEMONS"
1956 #: ../src/guestfs.pod:976
1958 "I<Note (1):> This is B<highly experimental> and has a tendency to eat "
1959 "babies. Use with caution."
1963 #: ../src/guestfs.pod:979
1965 "I<Note (2):> This section explains how to attach to a running daemon from a "
1966 "low level perspective. For most users, simply using virt tools such as "
1967 "L<guestfish(1)> with the I<--live> option will \"just work\"."
1971 #: ../src/guestfs.pod:983
1972 msgid "Using guestfs_set_attach_method"
1976 #: ../src/guestfs.pod:985
1978 "By calling L</guestfs_set_attach_method> you can change how the library "
1979 "connects to the C<guestfsd> daemon in L</guestfs_launch> (read "
1980 "L</ARCHITECTURE> for some background)."
1984 #: ../src/guestfs.pod:989
1986 "The normal attach method is C<appliance>, where a small appliance is created "
1987 "containing the daemon, and then the library connects to this."
1991 #: ../src/guestfs.pod:992
1993 "Setting attach method to C<unix:I<path>> (where I<path> is the path of a "
1994 "Unix domain socket) causes L</guestfs_launch> to connect to an existing "
1995 "daemon over the Unix domain socket."
1999 #: ../src/guestfs.pod:996
2001 "The normal use for this is to connect to a running virtual machine that "
2002 "contains a C<guestfsd> daemon, and send commands so you can read and write "
2003 "files inside the live virtual machine."
2007 #: ../src/guestfs.pod:1000
2008 msgid "Using guestfs_add_domain with live flag"
2012 #: ../src/guestfs.pod:1002
2014 "L</guestfs_add_domain> provides some help for getting the correct attach "
2015 "method. If you pass the C<live> option to this function, then (if the "
2016 "virtual machine is running) it will examine the libvirt XML looking for a "
2017 "virtio-serial channel to connect to:"
2021 #: ../src/guestfs.pod:1008
2028 " <channel type='unix'>\n"
2029 " <source mode='bind' path='/path/to/socket'/>\n"
2030 " <target type='virtio' name='org.libguestfs.channel.0'/>\n"
2039 #: ../src/guestfs.pod:1020
2041 "L</guestfs_add_domain> extracts C</path/to/socket> and sets the attach "
2042 "method to C<unix:/path/to/socket>."
2046 #: ../src/guestfs.pod:1023
2048 "Some of the libguestfs tools (including guestfish) support a I<--live> "
2049 "option which is passed through to L</guestfs_add_domain> thus allowing you "
2050 "to attach to and modify live virtual machines."
2054 #: ../src/guestfs.pod:1027
2056 "The virtual machine needs to have been set up beforehand so that it has the "
2057 "virtio-serial channel and so that guestfsd is running inside it."
2061 #: ../src/guestfs.pod:1031
2062 msgid "ABI GUARANTEE"
2066 #: ../src/guestfs.pod:1033
2068 "We guarantee the libguestfs ABI (binary interface), for public, high-level "
2069 "actions as outlined in this section. Although we will deprecate some "
2070 "actions, for example if they get replaced by newer calls, we will keep the "
2071 "old actions forever. This allows you the developer to program in confidence "
2072 "against the libguestfs API."
2076 #: ../src/guestfs.pod:1039
2077 msgid "BLOCK DEVICE NAMING"
2081 #: ../src/guestfs.pod:1041
2083 "In the kernel there is now quite a profusion of schemata for naming block "
2084 "devices (in this context, by I<block device> I mean a physical or virtual "
2085 "hard drive). The original Linux IDE driver used names starting with "
2086 "C</dev/hd*>. SCSI devices have historically used a different naming scheme, "
2087 "C</dev/sd*>. When the Linux kernel I<libata> driver became a popular "
2088 "replacement for the old IDE driver (particularly for SATA devices) those "
2089 "devices also used the C</dev/sd*> scheme. Additionally we now have virtual "
2090 "machines with paravirtualized drivers. This has created several different "
2091 "naming systems, such as C</dev/vd*> for virtio disks and C</dev/xvd*> for "
2096 #: ../src/guestfs.pod:1053
2098 "As discussed above, libguestfs uses a qemu appliance running an embedded "
2099 "Linux kernel to access block devices. We can run a variety of appliances "
2100 "based on a variety of Linux kernels."
2104 #: ../src/guestfs.pod:1057
2106 "This causes a problem for libguestfs because many API calls use device or "
2107 "partition names. Working scripts and the recipe (example) scripts that we "
2108 "make available over the internet could fail if the naming scheme changes."
2112 #: ../src/guestfs.pod:1062
2114 "Therefore libguestfs defines C</dev/sd*> as the I<standard naming scheme>. "
2115 "Internally C</dev/sd*> names are translated, if necessary, to other names as "
2116 "required. For example, under RHEL 5 which uses the C</dev/hd*> scheme, any "
2117 "device parameter C</dev/sda2> is translated to C</dev/hda2> transparently."
2121 #: ../src/guestfs.pod:1068
2123 "Note that this I<only> applies to parameters. The L</guestfs_list_devices>, "
2124 "L</guestfs_list_partitions> and similar calls return the true names of the "
2125 "devices and partitions as known to the appliance."
2129 #: ../src/guestfs.pod:1073
2130 msgid "ALGORITHM FOR BLOCK DEVICE NAME TRANSLATION"
2134 #: ../src/guestfs.pod:1075
2136 "Usually this translation is transparent. However in some (very rare) cases "
2137 "you may need to know the exact algorithm. Such cases include where you use "
2138 "L</guestfs_config> to add a mixture of virtio and IDE devices to the "
2139 "qemu-based appliance, so have a mixture of C</dev/sd*> and C</dev/vd*> "
2144 #: ../src/guestfs.pod:1081
2146 "The algorithm is applied only to I<parameters> which are known to be either "
2147 "device or partition names. Return values from functions such as "
2148 "L</guestfs_list_devices> are never changed."
2152 #: ../src/guestfs.pod:1089
2153 msgid "Is the string a parameter which is a device or partition name?"
2157 #: ../src/guestfs.pod:1093
2158 msgid "Does the string begin with C</dev/sd>?"
2162 #: ../src/guestfs.pod:1097
2164 "Does the named device exist? If so, we use that device. However if I<not> "
2165 "then we continue with this algorithm."
2169 #: ../src/guestfs.pod:1102
2170 msgid "Replace initial C</dev/sd> string with C</dev/hd>."
2174 #: ../src/guestfs.pod:1104
2175 msgid "For example, change C</dev/sda2> to C</dev/hda2>."
2179 #: ../src/guestfs.pod:1106
2180 msgid "If that named device exists, use it. If not, continue."
2184 #: ../src/guestfs.pod:1110
2185 msgid "Replace initial C</dev/sd> string with C</dev/vd>."
2189 #: ../src/guestfs.pod:1112
2190 msgid "If that named device exists, use it. If not, return an error."
2194 #: ../src/guestfs.pod:1116
2195 msgid "PORTABILITY CONCERNS WITH BLOCK DEVICE NAMING"
2199 #: ../src/guestfs.pod:1118
2201 "Although the standard naming scheme and automatic translation is useful for "
2202 "simple programs and guestfish scripts, for larger programs it is best not to "
2203 "rely on this mechanism."
2207 #: ../src/guestfs.pod:1122
2209 "Where possible for maximum future portability programs using libguestfs "
2210 "should use these future-proof techniques:"
2214 #: ../src/guestfs.pod:1129
2216 "Use L</guestfs_list_devices> or L</guestfs_list_partitions> to list actual "
2217 "device names, and then use those names directly."
2221 #: ../src/guestfs.pod:1132
2222 msgid "Since those device names exist by definition, they will never be translated."
2226 #: ../src/guestfs.pod:1137
2228 "Use higher level ways to identify filesystems, such as LVM names, UUIDs and "
2229 "filesystem labels."
2233 #: ../src/guestfs.pod:1142
2238 #: ../src/guestfs.pod:1144
2240 "This section discusses security implications of using libguestfs, "
2241 "particularly with untrusted or malicious guests or disk images."
2245 #: ../src/guestfs.pod:1147
2246 msgid "GENERAL SECURITY CONSIDERATIONS"
2250 #: ../src/guestfs.pod:1149
2252 "Be careful with any files or data that you download from a guest (by "
2253 "\"download\" we mean not just the L</guestfs_download> command but any "
2254 "command that reads files, filenames, directories or anything else from a "
2255 "disk image). An attacker could manipulate the data to fool your program "
2256 "into doing the wrong thing. Consider cases such as:"
2260 #: ../src/guestfs.pod:1159
2261 msgid "the data (file etc) not being present"
2265 #: ../src/guestfs.pod:1163
2266 msgid "being present but empty"
2270 #: ../src/guestfs.pod:1167
2271 msgid "being much larger than normal"
2275 #: ../src/guestfs.pod:1171
2276 msgid "containing arbitrary 8 bit data"
2280 #: ../src/guestfs.pod:1175
2281 msgid "being in an unexpected character encoding"
2285 #: ../src/guestfs.pod:1179
2286 msgid "containing homoglyphs."
2290 #: ../src/guestfs.pod:1183
2291 msgid "SECURITY OF MOUNTING FILESYSTEMS"
2295 #: ../src/guestfs.pod:1185
2297 "When you mount a filesystem under Linux, mistakes in the kernel filesystem "
2298 "(VFS) module can sometimes be escalated into exploits by deliberately "
2299 "creating a malicious, malformed filesystem. These exploits are very severe "
2300 "for two reasons. Firstly there are very many filesystem drivers in the "
2301 "kernel, and many of them are infrequently used and not much developer "
2302 "attention has been paid to the code. Linux userspace helps potential "
2303 "crackers by detecting the filesystem type and automatically choosing the "
2304 "right VFS driver, even if that filesystem type is obscure or unexpected for "
2305 "the administrator. Secondly, a kernel-level exploit is like a local root "
2306 "exploit (worse in some ways), giving immediate and total access to the "
2307 "system right down to the hardware level."
2311 #: ../src/guestfs.pod:1198
2313 "That explains why you should never mount a filesystem from an untrusted "
2314 "guest on your host kernel. How about libguestfs? We run a Linux kernel "
2315 "inside a qemu virtual machine, usually running as a non-root user. The "
2316 "attacker would need to write a filesystem which first exploited the kernel, "
2317 "and then exploited either qemu virtualization (eg. a faulty qemu driver) or "
2318 "the libguestfs protocol, and finally to be as serious as the host kernel "
2319 "exploit it would need to escalate its privileges to root. This multi-step "
2320 "escalation, performed by a static piece of data, is thought to be extremely "
2321 "hard to do, although we never say 'never' about security issues."
2325 #: ../src/guestfs.pod:1209
2327 "In any case callers can reduce the attack surface by forcing the filesystem "
2328 "type when mounting (use L</guestfs_mount_vfs>)."
2332 #: ../src/guestfs.pod:1212
2333 msgid "PROTOCOL SECURITY"
2337 #: ../src/guestfs.pod:1214
2339 "The protocol is designed to be secure, being based on RFC 4506 (XDR) with a "
2340 "defined upper message size. However a program that uses libguestfs must "
2341 "also take care - for example you can write a program that downloads a binary "
2342 "from a disk image and executes it locally, and no amount of protocol "
2343 "security will save you from the consequences."
2347 #: ../src/guestfs.pod:1220
2348 msgid "INSPECTION SECURITY"
2352 #: ../src/guestfs.pod:1222
2354 "Parts of the inspection API (see L</INSPECTION>) return untrusted strings "
2355 "directly from the guest, and these could contain any 8 bit data. Callers "
2356 "should be careful to escape these before printing them to a structured file "
2357 "(for example, use HTML escaping if creating a web page)."
2361 #: ../src/guestfs.pod:1228
2363 "Guest configuration may be altered in unusual ways by the administrator of "
2364 "the virtual machine, and may not reflect reality (particularly for untrusted "
2365 "or actively malicious guests). For example we parse the hostname from "
2366 "configuration files like C</etc/sysconfig/network> that we find in the "
2367 "guest, but the guest administrator can easily manipulate these files to "
2368 "provide the wrong hostname."
2372 #: ../src/guestfs.pod:1236
2374 "The inspection API parses guest configuration using two external libraries: "
2375 "Augeas (Linux configuration) and hivex (Windows Registry). Both are "
2376 "designed to be robust in the face of malicious data, although denial of "
2377 "service attacks are still possible, for example with oversized configuration "
2382 #: ../src/guestfs.pod:1242
2383 msgid "RUNNING UNTRUSTED GUEST COMMANDS"
2387 #: ../src/guestfs.pod:1244
2389 "Be very cautious about running commands from the guest. By running a "
2390 "command in the guest, you are giving CPU time to a binary that you do not "
2391 "control, under the same user account as the library, albeit wrapped in qemu "
2392 "virtualization. More information and alternatives can be found in the "
2393 "section L</RUNNING COMMANDS>."
2397 #: ../src/guestfs.pod:1250
2398 msgid "CVE-2010-3851"
2402 #: ../src/guestfs.pod:1252
2403 msgid "https://bugzilla.redhat.com/642934"
2407 #: ../src/guestfs.pod:1254
2409 "This security bug concerns the automatic disk format detection that qemu "
2410 "does on disk images."
2414 #: ../src/guestfs.pod:1257
2416 "A raw disk image is just the raw bytes, there is no header. Other disk "
2417 "images like qcow2 contain a special header. Qemu deals with this by looking "
2418 "for one of the known headers, and if none is found then assuming the disk "
2419 "image must be raw."
2423 #: ../src/guestfs.pod:1262
2425 "This allows a guest which has been given a raw disk image to write some "
2426 "other header. At next boot (or when the disk image is accessed by "
2427 "libguestfs) qemu would do autodetection and think the disk image format was, "
2428 "say, qcow2 based on the header written by the guest."
2432 #: ../src/guestfs.pod:1267
2434 "This in itself would not be a problem, but qcow2 offers many features, one "
2435 "of which is to allow a disk image to refer to another image (called the "
2436 "\"backing disk\"). It does this by placing the path to the backing disk "
2437 "into the qcow2 header. This path is not validated and could point to any "
2438 "host file (eg. \"/etc/passwd\"). The backing disk is then exposed through "
2439 "\"holes\" in the qcow2 disk image, which of course is completely under the "
2440 "control of the attacker."
2444 #: ../src/guestfs.pod:1275
2445 msgid "In libguestfs this is rather hard to exploit except under two circumstances:"
2449 #: ../src/guestfs.pod:1282
2450 msgid "You have enabled the network or have opened the disk in write mode."
2454 #: ../src/guestfs.pod:1286
2456 "You are also running untrusted code from the guest (see L</RUNNING "
2461 #: ../src/guestfs.pod:1291
2463 "The way to avoid this is to specify the expected disk format when adding "
2464 "disks (the optional C<format> option to L</guestfs_add_drive_opts>). You "
2465 "should always do this if the disk is raw format, and it's a good idea for "
2470 #: ../src/guestfs.pod:1296
2472 "For disks added from libvirt using calls like L</guestfs_add_domain>, the "
2473 "format is fetched from libvirt and passed through."
2477 #: ../src/guestfs.pod:1299
2479 "For libguestfs tools, use the I<--format> command line parameter as "
2484 #: ../src/guestfs.pod:1302
2485 msgid "CONNECTION MANAGEMENT"
2489 #: ../src/guestfs.pod:1304
2494 #: ../src/guestfs.pod:1306
2496 "C<guestfs_h> is the opaque type representing a connection handle. Create a "
2497 "handle by calling L</guestfs_create>. Call L</guestfs_close> to free the "
2498 "handle and release all resources used."
2502 #: ../src/guestfs.pod:1310
2504 "For information on using multiple handles and threads, see the section "
2505 "L</MULTIPLE HANDLES AND MULTIPLE THREADS> below."
2509 #: ../src/guestfs.pod:1313
2510 msgid "guestfs_create"
2514 #: ../src/guestfs.pod:1315
2517 " guestfs_h *guestfs_create (void);\n"
2522 #: ../src/guestfs.pod:1317
2523 msgid "Create a connection handle."
2527 #: ../src/guestfs.pod:1319
2529 "You have to call L</guestfs_add_drive_opts> (or one of the equivalent calls) "
2530 "on the handle at least once."
2534 #: ../src/guestfs.pod:1322
2536 "This function returns a non-NULL pointer to a handle on success or NULL on "
2541 #: ../src/guestfs.pod:1325
2542 msgid "After configuring the handle, you have to call L</guestfs_launch>."
2546 #: ../src/guestfs.pod:1327
2548 "You may also want to configure error handling for the handle. See L</ERROR "
2549 "HANDLING> section below."
2553 #: ../src/guestfs.pod:1330
2554 msgid "guestfs_close"
2558 #: ../src/guestfs.pod:1332
2561 " void guestfs_close (guestfs_h *g);\n"
2566 #: ../src/guestfs.pod:1334
2567 msgid "This closes the connection handle and frees up all resources used."
2571 #: ../src/guestfs.pod:1336
2572 msgid "ERROR HANDLING"
2576 #: ../src/guestfs.pod:1338
2578 "API functions can return errors. For example, almost all functions that "
2579 "return C<int> will return C<-1> to indicate an error."
2583 #: ../src/guestfs.pod:1341
2585 "Additional information is available for errors: an error message string and "
2586 "optionally an error number (errno) if the thing that failed was a system "
2591 #: ../src/guestfs.pod:1345
2593 "You can get at the additional information about the last error on the handle "
2594 "by calling L</guestfs_last_error>, L</guestfs_last_errno>, and/or by setting "
2595 "up an error handler with L</guestfs_set_error_handler>."
2599 #: ../src/guestfs.pod:1350
2601 "When the handle is created, a default error handler is installed which "
2602 "prints the error message string to C<stderr>. For small short-running "
2603 "command line programs it is sufficient to do:"
2607 #: ../src/guestfs.pod:1354
2610 " if (guestfs_launch (g) == -1)\n"
2611 " exit (EXIT_FAILURE);\n"
2616 #: ../src/guestfs.pod:1357
2618 "since the default error handler will ensure that an error message has been "
2619 "printed to C<stderr> before the program exits."
2623 #: ../src/guestfs.pod:1360
2625 "For other programs the caller will almost certainly want to install an "
2626 "alternate error handler or do error handling in-line like this:"
2630 #: ../src/guestfs.pod:1363
2633 " g = guestfs_create ();\n"
2638 #: ../src/guestfs.pod:1365
2641 " /* This disables the default behaviour of printing errors\n"
2643 " guestfs_set_error_handler (g, NULL, NULL);\n"
2648 #: ../src/guestfs.pod:1369
2651 " if (guestfs_launch (g) == -1) {\n"
2652 " /* Examine the error message and print it etc. */\n"
2653 " char *msg = guestfs_last_error (g);\n"
2654 " int errnum = guestfs_last_errno (g);\n"
2655 " fprintf (stderr, \"%s\\n\", msg);\n"
2662 #: ../src/guestfs.pod:1377
2664 "Out of memory errors are handled differently. The default action is to call "
2665 "L<abort(3)>. If this is undesirable, then you can set a handler using "
2666 "L</guestfs_set_out_of_memory_handler>."
2670 #: ../src/guestfs.pod:1381
2672 "L</guestfs_create> returns C<NULL> if the handle cannot be created, and "
2673 "because there is no handle if this happens there is no way to get additional "
2674 "error information. However L</guestfs_create> is supposed to be a "
2675 "lightweight operation which can only fail because of insufficient memory (it "
2676 "returns NULL in this case)."
2680 #: ../src/guestfs.pod:1387
2681 msgid "guestfs_last_error"
2685 #: ../src/guestfs.pod:1389
2688 " const char *guestfs_last_error (guestfs_h *g);\n"
2693 #: ../src/guestfs.pod:1391
2695 "This returns the last error message that happened on C<g>. If there has not "
2696 "been an error since the handle was created, then this returns C<NULL>."
2700 #: ../src/guestfs.pod:1395
2702 "The lifetime of the returned string is until the next error occurs, or "
2703 "L</guestfs_close> is called."
2707 #: ../src/guestfs.pod:1398
2708 msgid "guestfs_last_errno"
2712 #: ../src/guestfs.pod:1400
2715 " int guestfs_last_errno (guestfs_h *g);\n"
2720 #: ../src/guestfs.pod:1402
2721 msgid "This returns the last error number (errno) that happened on C<g>."
2725 #: ../src/guestfs.pod:1404
2726 msgid "If successful, an errno integer not equal to zero is returned."
2730 #: ../src/guestfs.pod:1406
2731 msgid "If no error, this returns 0. This call can return 0 in three situations:"
2735 #: ../src/guestfs.pod:1413
2736 msgid "There has not been any error on the handle."
2740 #: ../src/guestfs.pod:1417
2742 "There has been an error but the errno was meaningless. This corresponds to "
2743 "the case where the error did not come from a failed system call, but for "
2744 "some other reason."
2748 #: ../src/guestfs.pod:1423
2750 "There was an error from a failed system call, but for some reason the errno "
2751 "was not captured and returned. This usually indicates a bug in libguestfs."
2755 #: ../src/guestfs.pod:1429
2757 "Libguestfs tries to convert the errno from inside the applicance into a "
2758 "corresponding errno for the caller (not entirely trivial: the appliance "
2759 "might be running a completely different operating system from the library "
2760 "and error numbers are not standardized across Un*xen). If this could not be "
2761 "done, then the error is translated to C<EINVAL>. In practice this should "
2762 "only happen in very rare circumstances."
2766 #: ../src/guestfs.pod:1437
2767 msgid "guestfs_set_error_handler"
2771 #: ../src/guestfs.pod:1439
2774 " typedef void (*guestfs_error_handler_cb) (guestfs_h *g,\n"
2776 " const char *msg);\n"
2777 " void guestfs_set_error_handler (guestfs_h *g,\n"
2778 " guestfs_error_handler_cb cb,\n"
2784 #: ../src/guestfs.pod:1446
2786 "The callback C<cb> will be called if there is an error. The parameters "
2787 "passed to the callback are an opaque data pointer and the error message "
2792 #: ../src/guestfs.pod:1450
2794 "C<errno> is not passed to the callback. To get that the callback must call "
2795 "L</guestfs_last_errno>."
2799 #: ../src/guestfs.pod:1453
2801 "Note that the message string C<msg> is freed as soon as the callback "
2802 "function returns, so if you want to stash it somewhere you must make your "
2807 #: ../src/guestfs.pod:1457
2808 msgid "The default handler prints messages on C<stderr>."
2812 #: ../src/guestfs.pod:1459
2813 msgid "If you set C<cb> to C<NULL> then I<no> handler is called."
2817 #: ../src/guestfs.pod:1461
2818 msgid "guestfs_get_error_handler"
2822 #: ../src/guestfs.pod:1463
2825 " guestfs_error_handler_cb guestfs_get_error_handler (guestfs_h *g,\n"
2826 " void **opaque_rtn);\n"
2831 #: ../src/guestfs.pod:1466
2832 msgid "Returns the current error handler callback."
2836 #: ../src/guestfs.pod:1468
2837 msgid "guestfs_set_out_of_memory_handler"
2841 #: ../src/guestfs.pod:1470
2844 " typedef void (*guestfs_abort_cb) (void);\n"
2845 " int guestfs_set_out_of_memory_handler (guestfs_h *g,\n"
2846 " guestfs_abort_cb);\n"
2851 #: ../src/guestfs.pod:1474
2853 "The callback C<cb> will be called if there is an out of memory situation. "
2854 "I<Note this callback must not return>."
2858 #: ../src/guestfs.pod:1477
2859 msgid "The default is to call L<abort(3)>."
2863 #: ../src/guestfs.pod:1479
2864 msgid "You cannot set C<cb> to C<NULL>. You can't ignore out of memory situations."
2868 #: ../src/guestfs.pod:1482
2869 msgid "guestfs_get_out_of_memory_handler"
2873 #: ../src/guestfs.pod:1484
2876 " guestfs_abort_fn guestfs_get_out_of_memory_handler (guestfs_h *g);\n"
2881 #: ../src/guestfs.pod:1486
2882 msgid "This returns the current out of memory handler."
2886 #: ../src/guestfs.pod:1488
2891 #: ../src/guestfs.pod:1490 ../fish/guestfish.pod:1008
2896 #: ../src/guestfs.pod:1492
2901 #: ../src/guestfs.pod:1494
2906 #: ../src/guestfs.pod:1496
2907 msgid "AVAILABILITY"
2911 #: ../src/guestfs.pod:1498
2912 msgid "GROUPS OF FUNCTIONALITY IN THE APPLIANCE"
2916 #: ../src/guestfs.pod:1500
2918 "Using L</guestfs_available> you can test availability of the following "
2919 "groups of functions. This test queries the appliance to see if the "
2920 "appliance you are currently using supports the functionality."
2924 #: ../src/guestfs.pod:1505
2925 msgid "@AVAILABILITY@"
2929 #: ../src/guestfs.pod:1507
2930 msgid "GUESTFISH supported COMMAND"
2934 #: ../src/guestfs.pod:1509
2936 "In L<guestfish(3)> there is a handy interactive command C<supported> which "
2937 "prints out the available groups and whether they are supported by this build "
2938 "of libguestfs. Note however that you have to do C<run> first."
2942 #: ../src/guestfs.pod:1514
2943 msgid "SINGLE CALLS AT COMPILE TIME"
2947 #: ../src/guestfs.pod:1516
2949 "Since version 1.5.8, C<E<lt>guestfs.hE<gt>> defines symbols for each C API "
2950 "function, such as:"
2954 #: ../src/guestfs.pod:1519
2957 " #define LIBGUESTFS_HAVE_DD 1\n"
2962 #: ../src/guestfs.pod:1521
2963 msgid "if L</guestfs_dd> is available."
2967 #: ../src/guestfs.pod:1523
2969 "Before version 1.5.8, if you needed to test whether a single libguestfs "
2970 "function is available at compile time, we recommended using build tools such "
2971 "as autoconf or cmake. For example in autotools you could use:"
2975 #: ../src/guestfs.pod:1528
2978 " AC_CHECK_LIB([guestfs],[guestfs_create])\n"
2979 " AC_CHECK_FUNCS([guestfs_dd])\n"
2984 #: ../src/guestfs.pod:1531
2986 "which would result in C<HAVE_GUESTFS_DD> being either defined or not defined "
2991 #: ../src/guestfs.pod:1534
2992 msgid "SINGLE CALLS AT RUN TIME"
2996 #: ../src/guestfs.pod:1536
2998 "Testing at compile time doesn't guarantee that a function really exists in "
2999 "the library. The reason is that you might be dynamically linked against a "
3000 "previous I<libguestfs.so> (dynamic library) which doesn't have the call. "
3001 "This situation unfortunately results in a segmentation fault, which is a "
3002 "shortcoming of the C dynamic linking system itself."
3006 #: ../src/guestfs.pod:1543
3008 "You can use L<dlopen(3)> to test if a function is available at run time, as "
3009 "in this example program (note that you still need the compile time check as "
3014 #: ../src/guestfs.pod:1547
3017 " #include <stdio.h>\n"
3018 " #include <stdlib.h>\n"
3019 " #include <unistd.h>\n"
3020 " #include <dlfcn.h>\n"
3021 " #include <guestfs.h>\n"
3026 #: ../src/guestfs.pod:1553
3031 " #ifdef LIBGUESTFS_HAVE_DD\n"
3033 " int has_function;\n"
3038 #: ../src/guestfs.pod:1559
3041 " /* Test if the function guestfs_dd is really available. */\n"
3042 " dl = dlopen (NULL, RTLD_LAZY);\n"
3044 " fprintf (stderr, \"dlopen: %s\\n\", dlerror ());\n"
3045 " exit (EXIT_FAILURE);\n"
3047 " has_function = dlsym (dl, \"guestfs_dd\") != NULL;\n"
3053 #: ../src/guestfs.pod:1568
3056 " if (!has_function)\n"
3057 " printf (\"this libguestfs.so does NOT have guestfs_dd function\\n\");\n"
3059 " printf (\"this libguestfs.so has guestfs_dd function\\n\");\n"
3060 " /* Now it's safe to call\n"
3061 " guestfs_dd (g, \"foo\", \"bar\");\n"
3065 " printf (\"guestfs_dd function was not found at compile time\\n\");\n"
3072 #: ../src/guestfs.pod:1581
3074 "You may think the above is an awful lot of hassle, and it is. There are "
3075 "other ways outside of the C linking system to ensure that this kind of "
3076 "incompatibility never arises, such as using package versioning:"
3080 #: ../src/guestfs.pod:1586
3083 " Requires: libguestfs >= 1.0.80\n"
3088 #: ../src/guestfs.pod:1588
3089 msgid "CALLS WITH OPTIONAL ARGUMENTS"
3093 #: ../src/guestfs.pod:1590
3095 "A recent feature of the API is the introduction of calls which take optional "
3096 "arguments. In C these are declared 3 ways. The main way is as a call which "
3097 "takes variable arguments (ie. C<...>), as in this example:"
3101 #: ../src/guestfs.pod:1595
3104 " int guestfs_add_drive_opts (guestfs_h *g, const char *filename, ...);\n"
3109 #: ../src/guestfs.pod:1597
3111 "Call this with a list of optional arguments, terminated by C<-1>. So to "
3112 "call with no optional arguments specified:"
3116 #: ../src/guestfs.pod:1600
3119 " guestfs_add_drive_opts (g, filename, -1);\n"
3124 #: ../src/guestfs.pod:1602
3125 msgid "With a single optional argument:"
3129 #: ../src/guestfs.pod:1604
3132 " guestfs_add_drive_opts (g, filename,\n"
3133 " GUESTFS_ADD_DRIVE_OPTS_FORMAT, \"qcow2\",\n"
3139 #: ../src/guestfs.pod:1608
3144 #: ../src/guestfs.pod:1610
3147 " guestfs_add_drive_opts (g, filename,\n"
3148 " GUESTFS_ADD_DRIVE_OPTS_FORMAT, \"qcow2\",\n"
3149 " GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,\n"
3155 #: ../src/guestfs.pod:1615
3157 "and so forth. Don't forget the terminating C<-1> otherwise Bad Things will "
3162 #: ../src/guestfs.pod:1618
3163 msgid "USING va_list FOR OPTIONAL ARGUMENTS"
3167 #: ../src/guestfs.pod:1620
3169 "The second variant has the same name with the suffix C<_va>, which works the "
3170 "same way but takes a C<va_list>. See the C manual for details. For the "
3171 "example function, this is declared:"
3175 #: ../src/guestfs.pod:1624
3178 " int guestfs_add_drive_opts_va (guestfs_h *g, const char *filename,\n"
3184 #: ../src/guestfs.pod:1627
3185 msgid "CONSTRUCTING OPTIONAL ARGUMENTS"
3189 #: ../src/guestfs.pod:1629
3191 "The third variant is useful where you need to construct these calls. You "
3192 "pass in a structure where you fill in the optional fields. The structure "
3193 "has a bitmask as the first element which you must set to indicate which "
3194 "fields you have filled in. For our example function the structure and call "
3199 #: ../src/guestfs.pod:1635
3202 " struct guestfs_add_drive_opts_argv {\n"
3203 " uint64_t bitmask;\n"
3205 " const char *format;\n"
3208 " int guestfs_add_drive_opts_argv (guestfs_h *g, const char *filename,\n"
3209 " const struct guestfs_add_drive_opts_argv *optargs);\n"
3214 #: ../src/guestfs.pod:1644
3215 msgid "You could call it like this:"
3219 #: ../src/guestfs.pod:1646
3222 " struct guestfs_add_drive_opts_argv optargs = {\n"
3223 " .bitmask = GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK |\n"
3224 " GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK,\n"
3226 " .format = \"qcow2\"\n"
3232 #: ../src/guestfs.pod:1653
3235 " guestfs_add_drive_opts_argv (g, filename, &optargs);\n"
3240 #: ../src/guestfs.pod:1655 ../src/guestfs-actions.pod:11 ../src/guestfs-actions.pod:1855 ../fish/guestfish-actions.pod:9 ../fish/guestfish-actions.pod:1260 ../tools/virt-win-reg.pl:532
3245 #: ../src/guestfs.pod:1661
3246 msgid "The C<_BITMASK> suffix on each option name when specifying the bitmask."
3250 #: ../src/guestfs.pod:1666
3251 msgid "You do not need to fill in all fields of the structure."
3255 #: ../src/guestfs.pod:1670
3257 "There must be a one-to-one correspondence between fields of the structure "
3258 "that are filled in, and bits set in the bitmask."
3262 #: ../src/guestfs.pod:1675
3263 msgid "OPTIONAL ARGUMENTS IN OTHER LANGUAGES"
3267 #: ../src/guestfs.pod:1677
3269 "In other languages, optional arguments are expressed in the way that is "
3270 "natural for that language. We refer you to the language-specific "
3271 "documentation for more details on that."
3275 #: ../src/guestfs.pod:1681
3276 msgid "For guestfish, see L<guestfish(1)/OPTIONAL ARGUMENTS>."
3280 #: ../src/guestfs.pod:1683
3281 msgid "SETTING CALLBACKS TO HANDLE EVENTS"
3285 #: ../src/guestfs.pod:1685
3287 "B<Note:> This section documents the generic event mechanism introduced in "
3288 "libguestfs 1.10, which you should use in new code if possible. The old "
3289 "functions C<guestfs_set_log_message_callback>, "
3290 "C<guestfs_set_subprocess_quit_callback>, "
3291 "C<guestfs_set_launch_done_callback>, C<guestfs_set_close_callback> and "
3292 "C<guestfs_set_progress_callback> are no longer documented in this manual "
3297 #: ../src/guestfs.pod:1693
3299 "Handles generate events when certain things happen, such as log messages "
3300 "being generated, progress messages during long-running operations, or the "
3301 "handle being closed. The API calls described below let you register a "
3302 "callback to be called when events happen. You can register multiple "
3303 "callbacks (for the same, different or overlapping sets of events), and "
3304 "individually remove callbacks. If callbacks are not removed, then they "
3305 "remain in force until the handle is closed."
3309 #: ../src/guestfs.pod:1701
3311 "In the current implementation, events are only generated synchronously: that "
3312 "means that events (and hence callbacks) can only happen while you are in the "
3313 "middle of making another libguestfs call. The callback is called in the "
3318 #: ../src/guestfs.pod:1706
3320 "Events may contain a payload, usually nothing (void), an array of 64 bit "
3321 "unsigned integers, or a message buffer. Payloads are discussed later on."
3325 #: ../src/guestfs.pod:1710
3326 msgid "CLASSES OF EVENTS"
3330 #: ../src/guestfs.pod:1714
3331 msgid "GUESTFS_EVENT_CLOSE (payload type: void)"
3335 #: ../src/guestfs.pod:1717
3337 "The callback function will be called while the handle is being closed "
3338 "(synchronously from L</guestfs_close>)."
3342 #: ../src/guestfs.pod:1720
3344 "Note that libguestfs installs an L<atexit(3)> handler to try to clean up "
3345 "handles that are open when the program exits. This means that this callback "
3346 "might be called indirectly from L<exit(3)>, which can cause unexpected "
3347 "problems in higher-level languages (eg. if your HLL interpreter has already "
3348 "been cleaned up by the time this is called, and if your callback then jumps "
3349 "into some HLL function)."
3353 #: ../src/guestfs.pod:1727
3355 "If no callback is registered: the handle is closed without any callback "
3360 #: ../src/guestfs.pod:1730
3361 msgid "GUESTFS_EVENT_SUBPROCESS_QUIT (payload type: void)"
3365 #: ../src/guestfs.pod:1733
3367 "The callback function will be called when the child process quits, either "
3368 "asynchronously or if killed by L</guestfs_kill_subprocess>. (This "
3369 "corresponds to a transition from any state to the CONFIG state)."
3373 #: ../src/guestfs.pod:1737 ../src/guestfs.pod:1746
3374 msgid "If no callback is registered: the event is ignored."
3378 #: ../src/guestfs.pod:1739
3379 msgid "GUESTFS_EVENT_LAUNCH_DONE (payload type: void)"
3383 #: ../src/guestfs.pod:1742
3385 "The callback function will be called when the child process becomes ready "
3386 "first time after it has been launched. (This corresponds to a transition "
3387 "from LAUNCHING to the READY state)."
3391 #: ../src/guestfs.pod:1748
3392 msgid "GUESTFS_EVENT_PROGRESS (payload type: array of 4 x uint64_t)"
3396 #: ../src/guestfs.pod:1751
3398 "Some long-running operations can generate progress messages. If this "
3399 "callback is registered, then it will be called each time a progress message "
3400 "is generated (usually two seconds after the operation started, and three "
3401 "times per second thereafter until it completes, although the frequency may "
3402 "change in future versions)."
3406 #: ../src/guestfs.pod:1757
3408 "The callback receives in the payload four unsigned 64 bit numbers which are "
3409 "(in order): C<proc_nr>, C<serial>, C<position>, C<total>."
3413 #: ../src/guestfs.pod:1760
3415 "The units of C<total> are not defined, although for some operations C<total> "
3416 "may relate in some way to the amount of data to be transferred (eg. in bytes "
3417 "or megabytes), and C<position> may be the portion which has been "
3422 #: ../src/guestfs.pod:1765
3423 msgid "The only defined and stable parts of the API are:"
3427 #: ../src/guestfs.pod:1771
3429 "The callback can display to the user some type of progress bar or indicator "
3430 "which shows the ratio of C<position>:C<total>."
3434 #: ../src/guestfs.pod:1776
3435 msgid "0 E<lt>= C<position> E<lt>= C<total>"
3439 #: ../src/guestfs.pod:1780
3441 "If any progress notification is sent during a call, then a final progress "
3442 "notification is always sent when C<position> = C<total> (I<unless> the call "
3443 "fails with an error)."
3447 #: ../src/guestfs.pod:1784
3449 "This is to simplify caller code, so callers can easily set the progress "
3450 "indicator to \"100%\" at the end of the operation, without requiring special "
3451 "code to detect this case."
3455 #: ../src/guestfs.pod:1790
3457 "For some calls we are unable to estimate the progress of the call, but we "
3458 "can still generate progress messages to indicate activity. This is known as "
3459 "\"pulse mode\", and is directly supported by certain progress bar "
3460 "implementations (eg. GtkProgressBar)."
3464 #: ../src/guestfs.pod:1795
3466 "For these calls, zero or more progress messages are generated with "
3467 "C<position = 0> and C<total = 1>, followed by a final message with "
3468 "C<position = total = 1>."
3472 #: ../src/guestfs.pod:1799
3474 "As noted above, if the call fails with an error then the final message may "
3479 #: ../src/guestfs.pod:1804
3481 "The callback also receives the procedure number (C<proc_nr>) and serial "
3482 "number (C<serial>) of the call. These are only useful for debugging "
3483 "protocol issues, and the callback can normally ignore them. The callback "
3484 "may want to print these numbers in error messages or debugging messages."
3488 #: ../src/guestfs.pod:1810
3489 msgid "If no callback is registered: progress messages are discarded."
3493 #: ../src/guestfs.pod:1812
3494 msgid "GUESTFS_EVENT_APPLIANCE (payload type: message buffer)"
3498 #: ../src/guestfs.pod:1815
3500 "The callback function is called whenever a log message is generated by qemu, "
3501 "the appliance kernel, guestfsd (daemon), or utility programs."
3505 #: ../src/guestfs.pod:1818
3507 "If the verbose flag (L</guestfs_set_verbose>) is set before launch "
3508 "(L</guestfs_launch>) then additional debug messages are generated."
3512 #: ../src/guestfs.pod:1821 ../src/guestfs.pod:1835
3514 "If no callback is registered: the messages are discarded unless the verbose "
3515 "flag is set in which case they are sent to stderr. You can override the "
3516 "printing of verbose messages to stderr by setting up a callback."
3520 #: ../src/guestfs.pod:1826
3521 msgid "GUESTFS_EVENT_LIBRARY (payload type: message buffer)"
3525 #: ../src/guestfs.pod:1829
3527 "The callback function is called whenever a log message is generated by the "
3528 "library part of libguestfs."
3532 #: ../src/guestfs.pod:1832
3534 "If the verbose flag (L</guestfs_set_verbose>) is set then additional debug "
3535 "messages are generated."
3539 #: ../src/guestfs.pod:1840
3540 msgid "GUESTFS_EVENT_TRACE (payload type: message buffer)"
3544 #: ../src/guestfs.pod:1843
3546 "The callback function is called whenever a trace message is generated. This "
3547 "only applies if the trace flag (L</guestfs_set_trace>) is set."
3551 #: ../src/guestfs.pod:1846
3553 "If no callback is registered: the messages are sent to stderr. You can "
3554 "override the printing of trace messages to stderr by setting up a callback."
3558 #: ../src/guestfs.pod:1852
3559 msgid "guestfs_set_event_callback"
3563 #: ../src/guestfs.pod:1854
3566 " int guestfs_set_event_callback (guestfs_h *g,\n"
3567 " guestfs_event_callback cb,\n"
3568 " uint64_t event_bitmask,\n"
3575 #: ../src/guestfs.pod:1860
3577 "This function registers a callback (C<cb>) for all event classes in the "
3582 #: ../src/guestfs.pod:1863
3584 "For example, to register for all log message events, you could call this "
3585 "function with the bitmask C<GUESTFS_EVENT_APPLIANCE|GUESTFS_EVENT_LIBRARY>. "
3586 "To register a single callback for all possible classes of events, use "
3587 "C<GUESTFS_EVENT_ALL>."
3591 #: ../src/guestfs.pod:1869
3592 msgid "C<flags> should always be passed as 0."
3596 #: ../src/guestfs.pod:1871
3598 "C<opaque> is an opaque pointer which is passed to the callback. You can use "
3599 "it for any purpose."
3603 #: ../src/guestfs.pod:1874
3605 "The return value is the event handle (an integer) which you can use to "
3606 "delete the callback (see below)."
3610 #: ../src/guestfs.pod:1877
3612 "If there is an error, this function returns C<-1>, and sets the error in the "
3613 "handle in the usual way (see L</guestfs_last_error> etc.)"
3617 #: ../src/guestfs.pod:1880
3619 "Callbacks remain in effect until they are deleted, or until the handle is "
3624 #: ../src/guestfs.pod:1883
3626 "In the case where multiple callbacks are registered for a particular event "
3627 "class, all of the callbacks are called. The order in which multiple "
3628 "callbacks are called is not defined."
3632 #: ../src/guestfs.pod:1887
3633 msgid "guestfs_delete_event_callback"
3637 #: ../src/guestfs.pod:1889
3640 " void guestfs_delete_event_callback (guestfs_h *g, int event_handle);\n"
3645 #: ../src/guestfs.pod:1891
3647 "Delete a callback that was previously registered. C<event_handle> should be "
3648 "the integer that was returned by a previous call to "
3649 "C<guestfs_set_event_callback> on the same handle."
3653 #: ../src/guestfs.pod:1895
3654 msgid "guestfs_event_callback"
3658 #: ../src/guestfs.pod:1897
3661 " typedef void (*guestfs_event_callback) (\n"
3664 " uint64_t event,\n"
3665 " int event_handle,\n"
3667 " const char *buf, size_t buf_len,\n"
3668 " const uint64_t *array, size_t array_len);\n"
3673 #: ../src/guestfs.pod:1906
3674 msgid "This is the type of the event callback function that you have to provide."
3678 #: ../src/guestfs.pod:1909
3680 "The basic parameters are: the handle (C<g>), the opaque user pointer "
3681 "(C<opaque>), the event class (eg. C<GUESTFS_EVENT_PROGRESS>), the event "
3682 "handle, and C<flags> which in the current API you should ignore."
3686 #: ../src/guestfs.pod:1913
3688 "The remaining parameters contain the event payload (if any). Each event may "
3689 "contain a payload, which usually relates to the event class, but for future "
3690 "proofing your code should be written to handle any payload for any event "
3695 #: ../src/guestfs.pod:1918
3697 "C<buf> and C<buf_len> contain a message buffer (if C<buf_len == 0>, then "
3698 "there is no message buffer). Note that this message buffer can contain "
3699 "arbitrary 8 bit data, including NUL bytes."
3703 #: ../src/guestfs.pod:1922
3705 "C<array> and C<array_len> is an array of 64 bit unsigned integers. At the "
3706 "moment this is only used for progress messages."
3710 #: ../src/guestfs.pod:1925
3711 msgid "EXAMPLE: CAPTURING LOG MESSAGES"
3715 #: ../src/guestfs.pod:1927
3717 "One motivation for the generic event API was to allow GUI programs to "
3718 "capture debug and other messages. In libguestfs E<le> 1.8 these were sent "
3719 "unconditionally to C<stderr>."
3723 #: ../src/guestfs.pod:1931
3725 "Events associated with log messages are: C<GUESTFS_EVENT_LIBRARY>, "
3726 "C<GUESTFS_EVENT_APPLIANCE> and C<GUESTFS_EVENT_TRACE>. (Note that error "
3727 "messages are not events; you must capture error messages separately)."
3731 #: ../src/guestfs.pod:1936
3733 "Programs have to set up a callback to capture the classes of events of "
3738 #: ../src/guestfs.pod:1939
3742 " guestfs_set_event_callback\n"
3743 " (g, message_callback,\n"
3744 " GUESTFS_EVENT_LIBRARY|GUESTFS_EVENT_APPLIANCE|\n"
3745 " GUESTFS_EVENT_TRACE,\n"
3746 " 0, NULL) == -1)\n"
3747 " if (eh == -1) {\n"
3748 " // handle error in the usual way\n"
3754 #: ../src/guestfs.pod:1949
3756 "The callback can then direct messages to the appropriate place. In this "
3757 "example, messages are directed to syslog:"
3761 #: ../src/guestfs.pod:1952
3765 " message_callback (\n"
3768 " uint64_t event,\n"
3769 " int event_handle,\n"
3771 " const char *buf, size_t buf_len,\n"
3772 " const uint64_t *array, size_t array_len)\n"
3774 " const int priority = LOG_USER|LOG_INFO;\n"
3775 " if (buf_len > 0)\n"
3776 " syslog (priority, \"event 0x%lx: %s\", event, buf);\n"
3782 #: ../src/guestfs.pod:1967
3783 msgid "PRIVATE DATA AREA"
3787 #: ../src/guestfs.pod:1969
3789 "You can attach named pieces of private data to the libguestfs handle, fetch "
3790 "them by name, and walk over them, for the lifetime of the handle. This is "
3791 "called the private data area and is only available from the C API."
3795 #: ../src/guestfs.pod:1974
3796 msgid "To attach a named piece of data, use the following call:"
3800 #: ../src/guestfs.pod:1976
3803 " void guestfs_set_private (guestfs_h *g, const char *key, void *data);\n"
3808 #: ../src/guestfs.pod:1978
3810 "C<key> is the name to associate with this data, and C<data> is an arbitrary "
3811 "pointer (which can be C<NULL>). Any previous item with the same name is "
3816 #: ../src/guestfs.pod:1982
3818 "You can use any C<key> you want, but names beginning with an underscore "
3819 "character are reserved for internal libguestfs purposes (for implementing "
3820 "language bindings). It is recommended to prefix the name with some unique "
3821 "string to avoid collisions with other users."
3825 #: ../src/guestfs.pod:1987
3826 msgid "To retrieve the pointer, use:"
3830 #: ../src/guestfs.pod:1989
3833 " void *guestfs_get_private (guestfs_h *g, const char *key);\n"
3838 #: ../src/guestfs.pod:1991
3840 "This function returns C<NULL> if either no data is found associated with "
3841 "C<key>, or if the user previously set the C<key>'s C<data> pointer to "
3846 #: ../src/guestfs.pod:1995
3848 "Libguestfs does not try to look at or interpret the C<data> pointer in any "
3849 "way. As far as libguestfs is concerned, it need not be a valid pointer at "
3850 "all. In particular, libguestfs does I<not> try to free the data when the "
3851 "handle is closed. If the data must be freed, then the caller must either "
3852 "free it before calling L</guestfs_close> or must set up a close callback to "
3853 "do it (see L</GUESTFS_EVENT_CLOSE>)."
3857 #: ../src/guestfs.pod:2002
3858 msgid "To walk over all entries, use these two functions:"
3862 #: ../src/guestfs.pod:2004
3865 " void *guestfs_first_private (guestfs_h *g, const char **key_rtn);\n"
3870 #: ../src/guestfs.pod:2006
3873 " void *guestfs_next_private (guestfs_h *g, const char **key_rtn);\n"
3878 #: ../src/guestfs.pod:2008
3880 "C<guestfs_first_private> returns the first key, pointer pair (\"first\" does "
3881 "not have any particular meaning -- keys are not returned in any defined "
3882 "order). A pointer to the key is returned in C<*key_rtn> and the "
3883 "corresponding data pointer is returned from the function. C<NULL> is "
3884 "returned if there are no keys stored in the handle."
3888 #: ../src/guestfs.pod:2014
3890 "C<guestfs_next_private> returns the next key, pointer pair. The return "
3891 "value of this function is also C<NULL> is there are no further entries to "
3896 #: ../src/guestfs.pod:2018
3897 msgid "Notes about walking over entries:"
3901 #: ../src/guestfs.pod:2024
3902 msgid "You must not call C<guestfs_set_private> while walking over the entries."
3906 #: ../src/guestfs.pod:2029
3908 "The handle maintains an internal iterator which is reset when you call "
3909 "C<guestfs_first_private>. This internal iterator is invalidated when you "
3910 "call C<guestfs_set_private>."
3914 #: ../src/guestfs.pod:2035
3915 msgid "If you have set the data pointer associated with a key to C<NULL>, ie:"
3919 #: ../src/guestfs.pod:2037
3922 " guestfs_set_private (g, key, NULL);\n"
3927 #: ../src/guestfs.pod:2039
3928 msgid "then that C<key> is not returned when walking."
3932 #: ../src/guestfs.pod:2043
3934 "C<*key_rtn> is only valid until the next call to C<guestfs_first_private>, "
3935 "C<guestfs_next_private> or C<guestfs_set_private>."
3939 #: ../src/guestfs.pod:2049
3941 "The following example code shows how to print all keys and data pointers "
3942 "that are associated with the handle C<g>:"
3946 #: ../src/guestfs.pod:2052
3949 " const char *key;\n"
3950 " void *data = guestfs_first_private (g, &key);\n"
3951 " while (data != NULL)\n"
3953 " printf (\"key = %s, data = %p\\n\", key, data);\n"
3954 " data = guestfs_next_private (g, &key);\n"
3960 #: ../src/guestfs.pod:2060
3962 "More commonly you are only interested in keys that begin with an "
3963 "application-specific prefix C<foo_>. Modify the loop like so:"
3967 #: ../src/guestfs.pod:2063
3970 " const char *key;\n"
3971 " void *data = guestfs_first_private (g, &key);\n"
3972 " while (data != NULL)\n"
3974 " if (strncmp (key, \"foo_\", strlen (\"foo_\")) == 0)\n"
3975 " printf (\"key = %s, data = %p\\n\", key, data);\n"
3976 " data = guestfs_next_private (g, &key);\n"
3982 #: ../src/guestfs.pod:2072
3984 "If you need to modify keys while walking, then you have to jump back to the "
3985 "beginning of the loop. For example, to delete all keys prefixed with "
3990 #: ../src/guestfs.pod:2076
3993 " const char *key;\n"
3996 " data = guestfs_first_private (g, &key);\n"
3997 " while (data != NULL)\n"
3999 " if (strncmp (key, \"foo_\", strlen (\"foo_\")) == 0)\n"
4001 " guestfs_set_private (g, key, NULL);\n"
4002 " /* note that 'key' pointer is now invalid, and so is\n"
4003 " the internal iterator */\n"
4006 " data = guestfs_next_private (g, &key);\n"
4012 #: ../src/guestfs.pod:2092
4014 "Note that the above loop is guaranteed to terminate because the keys are "
4015 "being deleted, but other manipulations of keys within the loop might not "
4016 "terminate unless you also maintain an indication of which keys have been "
4021 #: ../src/guestfs.pod:2097 ../src/guestfs.pod:2102
4026 #: ../src/guestfs.pod:2099
4028 "<!-- old anchor for the next section --> <a "
4029 "name=\"state_machine_and_low_level_event_api\"/>"
4033 #: ../src/guestfs.pod:2104
4034 msgid "ARCHITECTURE"
4038 #: ../src/guestfs.pod:2106
4040 "Internally, libguestfs is implemented by running an appliance (a special "
4041 "type of small virtual machine) using L<qemu(1)>. Qemu runs as a child "
4042 "process of the main program."
4046 #: ../src/guestfs.pod:2110
4049 " ___________________\n"
4051 " | main program |\n"
4053 " | | child process / appliance\n"
4054 " | | __________________________\n"
4056 " +-------------------+ RPC | +-----------------+ |\n"
4057 " | libguestfs <--------------------> guestfsd | |\n"
4058 " | | | +-----------------+ |\n"
4059 " \\___________________/ | | Linux kernel | |\n"
4060 " | +--^--------------+ |\n"
4061 " \\_________|________________/\n"
4067 " \\______________/\n"
4072 #: ../src/guestfs.pod:2130
4074 "The library, linked to the main program, creates the child process and hence "
4075 "the appliance in the L</guestfs_launch> function."
4079 #: ../src/guestfs.pod:2133
4081 "Inside the appliance is a Linux kernel and a complete stack of userspace "
4082 "tools (such as LVM and ext2 programs) and a small controlling daemon called "
4083 "L</guestfsd>. The library talks to L</guestfsd> using remote procedure "
4084 "calls (RPC). There is a mostly one-to-one correspondence between libguestfs "
4085 "API calls and RPC calls to the daemon. Lastly the disk image(s) are "
4086 "attached to the qemu process which translates device access by the "
4087 "appliance's Linux kernel into accesses to the image."
4091 #: ../src/guestfs.pod:2142
4093 "A common misunderstanding is that the appliance \"is\" the virtual machine. "
4094 "Although the disk image you are attached to might also be used by some "
4095 "virtual machine, libguestfs doesn't know or care about this. (But you will "
4096 "care if both libguestfs's qemu process and your virtual machine are trying "
4097 "to update the disk image at the same time, since these usually results in "
4098 "massive disk corruption)."
4102 #: ../src/guestfs.pod:2149
4103 msgid "STATE MACHINE"
4107 #: ../src/guestfs.pod:2151
4108 msgid "libguestfs uses a state machine to model the child process:"
4112 #: ../src/guestfs.pod:2153
4124 " / | \\ \\ guestfs_launch\n"
4125 " / | _\\__V______\n"
4127 " / | | LAUNCHING |\n"
4128 " / | \\___________/\n"
4130 " / | guestfs_launch\n"
4132 " ______ / __|____V\n"
4133 " / \\ ------> / \\\n"
4134 " | BUSY | | READY |\n"
4135 " \\______/ <------ \\________/\n"
4140 #: ../src/guestfs.pod:2175
4142 "The normal transitions are (1) CONFIG (when the handle is created, but there "
4143 "is no child process), (2) LAUNCHING (when the child process is booting up), "
4144 "(3) alternating between READY and BUSY as commands are issued to, and "
4145 "carried out by, the child process."
4149 #: ../src/guestfs.pod:2180
4151 "The guest may be killed by L</guestfs_kill_subprocess>, or may die "
4152 "asynchronously at any time (eg. due to some internal error), and that causes "
4153 "the state to transition back to CONFIG."
4157 #: ../src/guestfs.pod:2184
4159 "Configuration commands for qemu such as L</guestfs_add_drive> can only be "
4160 "issued when in the CONFIG state."
4164 #: ../src/guestfs.pod:2187
4166 "The API offers one call that goes from CONFIG through LAUNCHING to READY. "
4167 "L</guestfs_launch> blocks until the child process is READY to accept "
4168 "commands (or until some failure or timeout). L</guestfs_launch> internally "
4169 "moves the state from CONFIG to LAUNCHING while it is running."
4173 #: ../src/guestfs.pod:2193
4175 "API actions such as L</guestfs_mount> can only be issued when in the READY "
4176 "state. These API calls block waiting for the command to be carried out "
4177 "(ie. the state to transition to BUSY and then back to READY). There are no "
4178 "non-blocking versions, and no way to issue more than one command per handle "
4183 #: ../src/guestfs.pod:2199
4185 "Finally, the child process sends asynchronous messages back to the main "
4186 "program, such as kernel log messages. You can register a callback to "
4187 "receive these messages."
4191 #: ../src/guestfs.pod:2203
4196 #: ../src/guestfs.pod:2205
4197 msgid "COMMUNICATION PROTOCOL"
4201 #: ../src/guestfs.pod:2207
4203 "Don't rely on using this protocol directly. This section documents how it "
4204 "currently works, but it may change at any time."
4208 #: ../src/guestfs.pod:2210
4210 "The protocol used to talk between the library and the daemon running inside "
4211 "the qemu virtual machine is a simple RPC mechanism built on top of XDR (RFC "
4212 "1014, RFC 1832, RFC 4506)."
4216 #: ../src/guestfs.pod:2214
4218 "The detailed format of structures is in C<src/guestfs_protocol.x> (note: "
4219 "this file is automatically generated)."
4223 #: ../src/guestfs.pod:2217
4225 "There are two broad cases, ordinary functions that don't have any C<FileIn> "
4226 "and C<FileOut> parameters, which are handled with very simple request/reply "
4227 "messages. Then there are functions that have any C<FileIn> or C<FileOut> "
4228 "parameters, which use the same request and reply messages, but they may also "
4229 "be followed by files sent using a chunked encoding."
4233 #: ../src/guestfs.pod:2224
4234 msgid "ORDINARY FUNCTIONS (NO FILEIN/FILEOUT PARAMS)"
4238 #: ../src/guestfs.pod:2226
4239 msgid "For ordinary functions, the request message is:"
4243 #: ../src/guestfs.pod:2228
4246 " total length (header + arguments,\n"
4247 " but not including the length word itself)\n"
4248 " struct guestfs_message_header (encoded as XDR)\n"
4249 " struct guestfs_<foo>_args (encoded as XDR)\n"
4254 #: ../src/guestfs.pod:2233
4256 "The total length field allows the daemon to allocate a fixed size buffer "
4257 "into which it slurps the rest of the message. As a result, the total length "
4258 "is limited to C<GUESTFS_MESSAGE_MAX> bytes (currently 4MB), which means the "
4259 "effective size of any request is limited to somewhere under this size."
4263 #: ../src/guestfs.pod:2239
4265 "Note also that many functions don't take any arguments, in which case the "
4266 "C<guestfs_I<foo>_args> is completely omitted."
4270 #: ../src/guestfs.pod:2242
4272 "The header contains the procedure number (C<guestfs_proc>) which is how the "
4273 "receiver knows what type of args structure to expect, or none at all."
4277 #: ../src/guestfs.pod:2246
4279 "For functions that take optional arguments, the optional arguments are "
4280 "encoded in the C<guestfs_I<foo>_args> structure in the same way as ordinary "
4281 "arguments. A bitmask in the header indicates which optional arguments are "
4282 "meaningful. The bitmask is also checked to see if it contains bits set "
4283 "which the daemon does not know about (eg. if more optional arguments were "
4284 "added in a later version of the library), and this causes the call to be "
4289 #: ../src/guestfs.pod:2254
4290 msgid "The reply message for ordinary functions is:"
4294 #: ../src/guestfs.pod:2256
4297 " total length (header + ret,\n"
4298 " but not including the length word itself)\n"
4299 " struct guestfs_message_header (encoded as XDR)\n"
4300 " struct guestfs_<foo>_ret (encoded as XDR)\n"
4305 #: ../src/guestfs.pod:2261
4307 "As above the C<guestfs_I<foo>_ret> structure may be completely omitted for "
4308 "functions that return no formal return values."
4312 #: ../src/guestfs.pod:2264
4313 msgid "As above the total length of the reply is limited to C<GUESTFS_MESSAGE_MAX>."
4317 #: ../src/guestfs.pod:2267
4319 "In the case of an error, a flag is set in the header, and the reply message "
4320 "is slightly changed:"
4324 #: ../src/guestfs.pod:2270
4327 " total length (header + error,\n"
4328 " but not including the length word itself)\n"
4329 " struct guestfs_message_header (encoded as XDR)\n"
4330 " struct guestfs_message_error (encoded as XDR)\n"
4335 #: ../src/guestfs.pod:2275
4337 "The C<guestfs_message_error> structure contains the error message as a "
4342 #: ../src/guestfs.pod:2278
4343 msgid "FUNCTIONS THAT HAVE FILEIN PARAMETERS"
4347 #: ../src/guestfs.pod:2280
4349 "A C<FileIn> parameter indicates that we transfer a file I<into> the guest. "
4350 "The normal request message is sent (see above). However this is followed by "
4351 "a sequence of file chunks."
4355 #: ../src/guestfs.pod:2284
4358 " total length (header + arguments,\n"
4359 " but not including the length word itself,\n"
4360 " and not including the chunks)\n"
4361 " struct guestfs_message_header (encoded as XDR)\n"
4362 " struct guestfs_<foo>_args (encoded as XDR)\n"
4363 " sequence of chunks for FileIn param #0\n"
4364 " sequence of chunks for FileIn param #1 etc.\n"
4369 #: ../src/guestfs.pod:2292
4370 msgid "The \"sequence of chunks\" is:"
4374 #: ../src/guestfs.pod:2294
4377 " length of chunk (not including length word itself)\n"
4378 " struct guestfs_chunk (encoded as XDR)\n"
4379 " length of chunk\n"
4380 " struct guestfs_chunk (encoded as XDR)\n"
4382 " length of chunk\n"
4383 " struct guestfs_chunk (with data.data_len == 0)\n"
4388 #: ../src/guestfs.pod:2302
4390 "The final chunk has the C<data_len> field set to zero. Additionally a flag "
4391 "is set in the final chunk to indicate either successful completion or early "
4396 #: ../src/guestfs.pod:2306
4398 "At time of writing there are no functions that have more than one FileIn "
4399 "parameter. However this is (theoretically) supported, by sending the "
4400 "sequence of chunks for each FileIn parameter one after another (from left to "
4405 #: ../src/guestfs.pod:2311
4407 "Both the library (sender) I<and> the daemon (receiver) may cancel the "
4408 "transfer. The library does this by sending a chunk with a special flag set "
4409 "to indicate cancellation. When the daemon sees this, it cancels the whole "
4410 "RPC, does I<not> send any reply, and goes back to reading the next request."
4414 #: ../src/guestfs.pod:2317
4416 "The daemon may also cancel. It does this by writing a special word "
4417 "C<GUESTFS_CANCEL_FLAG> to the socket. The library listens for this during "
4418 "the transfer, and if it gets it, it will cancel the transfer (it sends a "
4419 "cancel chunk). The special word is chosen so that even if cancellation "
4420 "happens right at the end of the transfer (after the library has finished "
4421 "writing and has started listening for the reply), the \"spurious\" cancel "
4422 "flag will not be confused with the reply message."
4426 #: ../src/guestfs.pod:2326
4428 "This protocol allows the transfer of arbitrary sized files (no 32 bit "
4429 "limit), and also files where the size is not known in advance (eg. from "
4430 "pipes or sockets). However the chunks are rather small "
4431 "(C<GUESTFS_MAX_CHUNK_SIZE>), so that neither the library nor the daemon need "
4432 "to keep much in memory."
4436 #: ../src/guestfs.pod:2332
4437 msgid "FUNCTIONS THAT HAVE FILEOUT PARAMETERS"
4441 #: ../src/guestfs.pod:2334
4443 "The protocol for FileOut parameters is exactly the same as for FileIn "
4444 "parameters, but with the roles of daemon and library reversed."
4448 #: ../src/guestfs.pod:2337
4451 " total length (header + ret,\n"
4452 " but not including the length word itself,\n"
4453 " and not including the chunks)\n"
4454 " struct guestfs_message_header (encoded as XDR)\n"
4455 " struct guestfs_<foo>_ret (encoded as XDR)\n"
4456 " sequence of chunks for FileOut param #0\n"
4457 " sequence of chunks for FileOut param #1 etc.\n"
4462 #: ../src/guestfs.pod:2345
4463 msgid "INITIAL MESSAGE"
4467 #: ../src/guestfs.pod:2347
4469 "When the daemon launches it sends an initial word (C<GUESTFS_LAUNCH_FLAG>) "
4470 "which indicates that the guest and daemon is alive. This is what "
4471 "L</guestfs_launch> waits for."
4475 #: ../src/guestfs.pod:2351
4476 msgid "PROGRESS NOTIFICATION MESSAGES"
4480 #: ../src/guestfs.pod:2353
4482 "The daemon may send progress notification messages at any time. These are "
4483 "distinguished by the normal length word being replaced by "
4484 "C<GUESTFS_PROGRESS_FLAG>, followed by a fixed size progress message."
4488 #: ../src/guestfs.pod:2357
4490 "The library turns them into progress callbacks (see "
4491 "L</GUESTFS_EVENT_PROGRESS>) if there is a callback registered, or discards "
4496 #: ../src/guestfs.pod:2361
4498 "The daemon self-limits the frequency of progress messages it sends (see "
4499 "C<daemon/proto.c:notify_progress>). Not all calls generate progress "
4504 #: ../src/guestfs.pod:2365
4505 msgid "LIBGUESTFS VERSION NUMBERS"
4509 #: ../src/guestfs.pod:2367
4511 "Since April 2010, libguestfs has started to make separate development and "
4512 "stable releases, along with corresponding branches in our git repository. "
4513 "These separate releases can be identified by version number:"
4517 #: ../src/guestfs.pod:2372
4520 " even numbers for stable: 1.2.x, 1.4.x, ...\n"
4521 " .-------- odd numbers for development: 1.3.x, 1.5.x, ...\n"
4527 " | `-------- sub-version\n"
4529 " `------ always '1' because we don't change the ABI\n"
4534 #: ../src/guestfs.pod:2383
4535 msgid "Thus \"1.3.5\" is the 5th update to the development branch \"1.3\"."
4539 #: ../src/guestfs.pod:2385
4541 "As time passes we cherry pick fixes from the development branch and backport "
4542 "those into the stable branch, the effect being that the stable branch should "
4543 "get more stable and less buggy over time. So the stable releases are ideal "
4544 "for people who don't need new features but would just like the software to "
4549 #: ../src/guestfs.pod:2391
4550 msgid "Our criteria for backporting changes are:"
4554 #: ../src/guestfs.pod:2397
4556 "Documentation changes which don't affect any code are backported unless the "
4557 "documentation refers to a future feature which is not in stable."
4561 #: ../src/guestfs.pod:2403
4563 "Bug fixes which are not controversial, fix obvious problems, and have been "
4564 "well tested are backported."
4568 #: ../src/guestfs.pod:2408
4570 "Simple rearrangements of code which shouldn't affect how it works get "
4571 "backported. This is so that the code in the two branches doesn't get too "
4572 "far out of step, allowing us to backport future fixes more easily."