1 # SOME DESCRIPTIVE TITLE.
2 # Copyright (C) YEAR Free Software Foundation, Inc.
3 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
8 "Project-Id-Version: PACKAGE VERSION\n"
9 "Report-Msgid-Bugs-To: libguestfs@redhat.com\n"
10 "POT-Creation-Date: 2011-04-22 22:23+0200\n"
11 "PO-Revision-Date: 2010-09-02 14:46+0100\n"
12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13 "Language-Team: LANGUAGE <LL@li.org>\n"
16 "Content-Type: text/plain; charset=UTF-8\n"
17 "Content-Transfer-Encoding: 8bit\n"
21 #: ../src/guestfs.pod:3 ../fish/guestfish.pod:3
22 #: ../test-tool/libguestfs-test-tool.pod:3 ../fuse/guestmount.pod:3
23 #: ../tools/virt-edit.pl:32 ../tools/virt-win-reg.pl:35
24 #: ../tools/virt-list-filesystems.pl:30 ../tools/virt-tar.pl:31
25 #: ../tools/virt-make-fs.pl:35 ../tools/virt-list-partitions.pl:30
31 #: ../src/guestfs.pod:5
32 msgid "guestfs - Library for accessing and modifying virtual machine images"
37 #: ../src/guestfs.pod:7 ../fish/guestfish.pod:7
38 #: ../test-tool/libguestfs-test-tool.pod:7 ../fuse/guestmount.pod:7
39 #: ../tools/virt-edit.pl:36 ../tools/virt-win-reg.pl:39
40 #: ../tools/virt-list-filesystems.pl:34 ../tools/virt-tar.pl:35
41 #: ../tools/virt-make-fs.pl:39 ../tools/virt-list-partitions.pl:34
47 #: ../src/guestfs.pod:9
50 " #include <guestfs.h>\n"
56 #: ../src/guestfs.pod:11
59 " guestfs_h *g = guestfs_create ();\n"
60 " guestfs_add_drive (g, \"guest.img\");\n"
61 " guestfs_launch (g);\n"
62 " guestfs_mount (g, \"/dev/sda1\", \"/\");\n"
63 " guestfs_touch (g, \"/hello\");\n"
64 " guestfs_umount (g, \"/\");\n"
65 " guestfs_close (g);\n"
71 #: ../src/guestfs.pod:19
74 " cc prog.c -o prog -lguestfs\n"
76 " cc prog.c -o prog `pkg-config libguestfs --cflags --libs`\n"
82 #: ../src/guestfs.pod:23 ../fish/guestfish.pod:30
83 #: ../test-tool/libguestfs-test-tool.pod:11 ../fuse/guestmount.pod:20
84 #: ../tools/virt-edit.pl:50 ../tools/virt-win-reg.pl:63
85 #: ../tools/virt-list-filesystems.pl:40 ../tools/virt-tar.pl:77
86 #: ../tools/virt-make-fs.pl:47 ../tools/virt-list-partitions.pl:40
92 #: ../src/guestfs.pod:25
94 "Libguestfs is a library for accessing and modifying guest disk images. "
95 "Amongst the things this is good for: making batch configuration changes to "
96 "guests, getting disk used/free statistics (see also: virt-df), migrating "
97 "between virtualization systems (see also: virt-p2v), performing partial "
98 "backups, performing partial guest clones, cloning guests and changing "
99 "registry/UUID/hostname info, and much else besides."
104 #: ../src/guestfs.pod:33
106 "Libguestfs uses Linux kernel and qemu code, and can access any type of guest "
107 "filesystem that Linux and qemu can, including but not limited to: ext2/3/4, "
108 "btrfs, FAT and NTFS, LVM, many different disk partition schemes, qcow, "
114 #: ../src/guestfs.pod:38
116 "Libguestfs provides ways to enumerate guest storage (eg. partitions, LVs, "
117 "what filesystem is in each LV, etc.). It can also run commands in the "
118 "context of the guest. Also you can access filesystems over FUSE."
123 #: ../src/guestfs.pod:43
125 "Libguestfs is a library that can be linked with C and C++ management "
126 "programs (or management programs written in OCaml, Perl, Python, Ruby, Java, "
127 "PHP, Haskell or C#). You can also use it from shell scripts or the command "
133 #: ../src/guestfs.pod:48
135 "You don't need to be root to use libguestfs, although obviously you do need "
136 "enough permissions to access the disk images."
141 #: ../src/guestfs.pod:51
143 "Libguestfs is a large API because it can do many things. For a gentle "
144 "introduction, please read the L</API OVERVIEW> section next."
149 #: ../src/guestfs.pod:54
151 "There are also some example programs in the L<guestfs-examples(3)> manual "
157 #: ../src/guestfs.pod:57
163 #: ../src/guestfs.pod:59
165 "This section provides a gentler overview of the libguestfs API. We also try "
166 "to group API calls together, where that may not be obvious from reading "
167 "about the individual calls in the main section of this manual."
172 #: ../src/guestfs.pod:64
178 #: ../src/guestfs.pod:66
180 "Before you can use libguestfs calls, you have to create a handle. Then you "
181 "must add at least one disk image to the handle, followed by launching the "
182 "handle, then performing whatever operations you want, and finally closing "
183 "the handle. By convention we use the single letter C<g> for the name of the "
184 "handle variable, although of course you can use any name you want."
189 #: ../src/guestfs.pod:73
190 msgid "The general structure of all libguestfs-using programs looks like this:"
195 #: ../src/guestfs.pod:76
198 " guestfs_h *g = guestfs_create ();\n"
204 #: ../src/guestfs.pod:78
207 " /* Call guestfs_add_drive additional times if there are\n"
208 " * multiple disk images.\n"
210 " guestfs_add_drive (g, \"guest.img\");\n"
216 #: ../src/guestfs.pod:83
219 " /* Most manipulation calls won't work until you've launched\n"
220 " * the handle 'g'. You have to do this _after_ adding drives\n"
221 " * and _before_ other commands.\n"
223 " guestfs_launch (g);\n"
229 #: ../src/guestfs.pod:89
232 " /* Now you can examine what partitions, LVs etc are available.\n"
234 " char **partitions = guestfs_list_partitions (g);\n"
235 " char **logvols = guestfs_lvs (g);\n"
241 #: ../src/guestfs.pod:94
244 " /* To access a filesystem in the image, you must mount it.\n"
246 " guestfs_mount (g, \"/dev/sda1\", \"/\");\n"
251 #: ../src/guestfs.pod:98
254 " /* Now you can perform filesystem actions on the guest\n"
257 " guestfs_touch (g, \"/hello\");\n"
263 #: ../src/guestfs.pod:103
266 " /* This is only needed for libguestfs < 1.5.24. Since then\n"
267 " * it is done automatically when you close the handle. See\n"
268 " * discussion of autosync in this page.\n"
270 " guestfs_sync (g);\n"
276 #: ../src/guestfs.pod:109
279 " /* Close the handle 'g'. */\n"
280 " guestfs_close (g);\n"
286 #: ../src/guestfs.pod:112
288 "The code above doesn't include any error checking. In real code you should "
289 "check return values carefully for errors. In general all functions that "
290 "return integers return C<-1> on error, and all functions that return "
291 "pointers return C<NULL> on error. See section L</ERROR HANDLING> below for "
292 "how to handle errors, and consult the documentation for each function call "
293 "below to see precisely how they return error indications. See L<guestfs-"
294 "examples(3)> for fully worked examples."
299 #: ../src/guestfs.pod:121
305 #: ../src/guestfs.pod:123
307 "The image filename (C<\"guest.img\"> in the example above) could be a disk "
308 "image from a virtual machine, a L<dd(1)> copy of a physical hard disk, an "
309 "actual block device, or simply an empty file of zeroes that you have created "
310 "through L<posix_fallocate(3)>. Libguestfs lets you do useful things to all "
316 #: ../src/guestfs.pod:129
318 "The call you should use in modern code for adding drives is L</"
319 "guestfs_add_drive_opts>. To add a disk image, allowing writes, and "
320 "specifying that the format is raw, do:"
325 #: ../src/guestfs.pod:133
328 " guestfs_add_drive_opts (g, filename,\n"
329 " GUESTFS_ADD_DRIVE_OPTS_FORMAT, \"raw\",\n"
336 #: ../src/guestfs.pod:137
337 msgid "You can add a disk read-only using:"
342 #: ../src/guestfs.pod:139
345 " guestfs_add_drive_opts (g, filename,\n"
346 " GUESTFS_ADD_DRIVE_OPTS_FORMAT, \"raw\",\n"
347 " GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,\n"
354 #: ../src/guestfs.pod:144
356 "or by calling the older function L</guestfs_add_drive_ro>. In either case "
357 "libguestfs won't modify the file."
362 #: ../src/guestfs.pod:147
364 "Be extremely cautious if the disk image is in use, eg. if it is being used "
365 "by a virtual machine. Adding it read-write will almost certainly cause disk "
366 "corruption, but adding it read-only is safe."
371 #: ../src/guestfs.pod:151
373 "You must add at least one disk image, and you may add multiple disk images. "
374 "In the API, the disk images are usually referred to as C</dev/sda> (for the "
375 "first one you added), C</dev/sdb> (for the second one you added), etc."
380 #: ../src/guestfs.pod:156
382 "Once L</guestfs_launch> has been called you cannot add any more images. You "
383 "can call L</guestfs_list_devices> to get a list of the device names, in the "
384 "order that you added them. See also L</BLOCK DEVICE NAMING> below."
389 #: ../src/guestfs.pod:161
394 #: ../src/guestfs.pod:163
396 "Before you can read or write files, create directories and so on in a disk "
397 "image that contains filesystems, you have to mount those filesystems using "
398 "L</guestfs_mount_options> or L</guestfs_mount_ro>. If you already know that "
399 "a disk image contains (for example) one partition with a filesystem on that "
400 "partition, then you can mount it directly:"
404 #: ../src/guestfs.pod:170
407 " guestfs_mount_options (g, \"\", \"/dev/sda1\", \"/\");\n"
412 #: ../src/guestfs.pod:172
414 "where C</dev/sda1> means literally the first partition (C<1>) of the first "
415 "disk image that we added (C</dev/sda>). If the disk contains Linux LVM2 "
416 "logical volumes you could refer to those instead (eg. C</dev/VG/LV>). Note "
417 "that these are libguestfs virtual devices, and are nothing to do with host "
422 #: ../src/guestfs.pod:178
424 "If you are given a disk image and you don't know what it contains then you "
425 "have to find out. Libguestfs can do that too: use L</"
426 "guestfs_list_partitions> and L</guestfs_lvs> to list possible partitions and "
427 "LVs, and either try mounting each to see what is mountable, or else examine "
428 "them with L</guestfs_vfs_type> or L</guestfs_file>. To list just "
429 "filesystems, use L</guestfs_list_filesystems>."
433 #: ../src/guestfs.pod:186
435 "Libguestfs also has a set of APIs for inspection of unknown disk images (see "
436 "L</INSPECTION> below). But you might find it easier to look at higher level "
437 "programs built on top of libguestfs, in particular L<virt-inspector(1)>."
441 #: ../src/guestfs.pod:191
443 "To mount a filesystem read-only, use L</guestfs_mount_ro>. There are "
444 "several other variations of the C<guestfs_mount_*> call."
449 #: ../src/guestfs.pod:194
450 msgid "FILESYSTEM ACCESS AND MODIFICATION"
455 #: ../src/guestfs.pod:196
457 "The majority of the libguestfs API consists of fairly low-level calls for "
458 "accessing and modifying the files, directories, symlinks etc on mounted "
459 "filesystems. There are over a hundred such calls which you can find listed "
460 "in detail below in this man page, and we don't even pretend to cover them "
461 "all in this overview."
466 #: ../src/guestfs.pod:202
468 "Specify filenames as full paths, starting with C<\"/\"> and including the "
474 #: ../src/guestfs.pod:205
476 "For example, if you mounted a filesystem at C<\"/\"> and you want to read "
477 "the file called C<\"etc/passwd\"> then you could do:"
482 #: ../src/guestfs.pod:208
485 " char *data = guestfs_cat (g, \"/etc/passwd\");\n"
491 #: ../src/guestfs.pod:210
493 "This would return C<data> as a newly allocated buffer containing the full "
494 "content of that file (with some conditions: see also L</DOWNLOADING> below), "
495 "or C<NULL> if there was an error."
500 #: ../src/guestfs.pod:214
502 "As another example, to create a top-level directory on that filesystem "
503 "called C<\"var\"> you would do:"
508 #: ../src/guestfs.pod:217
511 " guestfs_mkdir (g, \"/var\");\n"
517 #: ../src/guestfs.pod:219
518 msgid "To create a symlink you could do:"
523 #: ../src/guestfs.pod:221
526 " guestfs_ln_s (g, \"/etc/init.d/portmap\",\n"
527 " \"/etc/rc3.d/S30portmap\");\n"
533 #: ../src/guestfs.pod:224
535 "Libguestfs will reject attempts to use relative paths and there is no "
536 "concept of a current working directory."
541 #: ../src/guestfs.pod:227
543 "Libguestfs can return errors in many situations: for example if the "
544 "filesystem isn't writable, or if a file or directory that you requested "
545 "doesn't exist. If you are using the C API (documented here) you have to "
546 "check for those error conditions after each call. (Other language bindings "
547 "turn these errors into exceptions)."
552 #: ../src/guestfs.pod:233
554 "File writes are affected by the per-handle umask, set by calling L</"
555 "guestfs_umask> and defaulting to 022. See L</UMASK>."
560 #: ../src/guestfs.pod:236
566 #: ../src/guestfs.pod:238
568 "Libguestfs contains API calls to read, create and modify partition tables on "
574 #: ../src/guestfs.pod:241
576 "In the common case where you want to create a single partition covering the "
577 "whole disk, you should use the L</guestfs_part_disk> call:"
582 #: ../src/guestfs.pod:245
585 " const char *parttype = \"mbr\";\n"
586 " if (disk_is_larger_than_2TB)\n"
587 " parttype = \"gpt\";\n"
588 " guestfs_part_disk (g, \"/dev/sda\", parttype);\n"
594 #: ../src/guestfs.pod:250
596 "Obviously this effectively wipes anything that was on that disk image before."
601 #: ../src/guestfs.pod:253
607 #: ../src/guestfs.pod:255
609 "Libguestfs provides access to a large part of the LVM2 API, such as L</"
610 "guestfs_lvcreate> and L</guestfs_vgremove>. It won't make much sense unless "
611 "you familiarize yourself with the concepts of physical volumes, volume "
612 "groups and logical volumes."
617 #: ../src/guestfs.pod:260
619 "This author strongly recommends reading the LVM HOWTO, online at L<http://"
620 "tldp.org/HOWTO/LVM-HOWTO/>."
625 #: ../src/guestfs.pod:263
630 #: ../src/guestfs.pod:265
632 "Use L</guestfs_cat> to download small, text only files. This call is "
633 "limited to files which are less than 2 MB and which cannot contain any ASCII "
634 "NUL (C<\\0>) characters. However the API is very simple to use."
639 #: ../src/guestfs.pod:269
641 "L</guestfs_read_file> can be used to read files which contain arbitrary 8 "
642 "bit data, since it returns a (pointer, size) pair. However it is still "
643 "limited to \"small\" files, less than 2 MB."
648 #: ../src/guestfs.pod:273
650 "L</guestfs_download> can be used to download any file, with no limits on "
651 "content or size (even files larger than 4 GB)."
656 #: ../src/guestfs.pod:276
658 "To download multiple files, see L</guestfs_tar_out> and L</guestfs_tgz_out>."
663 #: ../src/guestfs.pod:279
669 #: ../src/guestfs.pod:281
671 "It's often the case that you want to write a file or files to the disk image."
676 #: ../src/guestfs.pod:284
678 "To write a small file with fixed content, use L</guestfs_write>. To create "
679 "a file of all zeroes, use L</guestfs_truncate_size> (sparse) or L</"
680 "guestfs_fallocate64> (with all disk blocks allocated). There are a variety "
681 "of other functions for creating test files, for example L</guestfs_fill> and "
682 "L</guestfs_fill_pattern>."
687 #: ../src/guestfs.pod:290
689 "To upload a single file, use L</guestfs_upload>. This call has no limits on "
690 "file content or size (even files larger than 4 GB)."
695 #: ../src/guestfs.pod:293
697 "To upload multiple files, see L</guestfs_tar_in> and L</guestfs_tgz_in>."
702 #: ../src/guestfs.pod:295
704 "However the fastest way to upload I<large numbers of arbitrary files> is to "
705 "turn them into a squashfs or CD ISO (see L<mksquashfs(8)> and L<mkisofs(8)"
706 ">), then attach this using L</guestfs_add_drive_ro>. If you add the drive "
707 "in a predictable way (eg. adding it last after all other drives) then you "
708 "can get the device name from L</guestfs_list_devices> and mount it directly "
709 "using L</guestfs_mount_ro>. Note that squashfs images are sometimes non-"
710 "portable between kernel versions, and they don't support labels or UUIDs. "
711 "If you want to pre-build an image or you need to mount it using a label or "
712 "UUID, use an ISO image instead."
717 #: ../src/guestfs.pod:306
723 #: ../src/guestfs.pod:308
725 "There are various different commands for copying between files and devices "
726 "and in and out of the guest filesystem. These are summarised in the table "
732 #: ../src/guestfs.pod:314
733 msgid "B<file> to B<file>"
738 #: ../src/guestfs.pod:316
740 "Use L</guestfs_cp> to copy a single file, or L</guestfs_cp_a> to copy "
741 "directories recursively."
746 #: ../src/guestfs.pod:319
747 msgid "B<file or device> to B<file or device>"
752 #: ../src/guestfs.pod:321
754 "Use L</guestfs_dd> which efficiently uses L<dd(1)> to copy between files and "
755 "devices in the guest."
760 #: ../src/guestfs.pod:324
761 msgid "Example: duplicate the contents of an LV:"
766 #: ../src/guestfs.pod:326
769 " guestfs_dd (g, \"/dev/VG/Original\", \"/dev/VG/Copy\");\n"
775 #: ../src/guestfs.pod:328
777 "The destination (C</dev/VG/Copy>) must be at least as large as the source "
778 "(C</dev/VG/Original>). To copy less than the whole source device, use L</"
779 "guestfs_copy_size>."
784 #: ../src/guestfs.pod:332
785 msgid "B<file on the host> to B<file or device>"
790 #: ../src/guestfs.pod:334
791 msgid "Use L</guestfs_upload>. See L</UPLOADING> above."
796 #: ../src/guestfs.pod:336
797 msgid "B<file or device> to B<file on the host>"
802 #: ../src/guestfs.pod:338
803 msgid "Use L</guestfs_download>. See L</DOWNLOADING> above."
808 #: ../src/guestfs.pod:342
809 msgid "UPLOADING AND DOWNLOADING TO PIPES AND FILE DESCRIPTORS"
814 #: ../src/guestfs.pod:344
816 "Calls like L</guestfs_upload>, L</guestfs_download>, L</guestfs_tar_in>, L</"
817 "guestfs_tar_out> etc appear to only take filenames as arguments, so it "
818 "appears you can only upload and download to files. However many Un*x-like "
819 "hosts let you use the special device files C</dev/stdin>, C</dev/stdout>, C</"
820 "dev/stderr> and C</dev/fd/N> to read and write from stdin, stdout, stderr, "
821 "and arbitrary file descriptor N."
826 #: ../src/guestfs.pod:352
827 msgid "For example, L<virt-cat(1)> writes its output to stdout by doing:"
831 #: ../src/guestfs.pod:355
834 " guestfs_download (g, filename, \"/dev/stdout\");\n"
840 #: ../src/guestfs.pod:357
841 msgid "and you can write tar output to a pipe C<fd> by doing:"
845 #: ../src/guestfs.pod:359
849 " snprintf (devfd, sizeof devfd, \"/dev/fd/%d\", fd);\n"
850 " guestfs_tar_out (g, \"/\", devfd);\n"
856 #: ../src/guestfs.pod:363
857 msgid "LISTING FILES"
862 #: ../src/guestfs.pod:365
864 "L</guestfs_ll> is just designed for humans to read (mainly when using the "
865 "L<guestfish(1)>-equivalent command C<ll>)."
870 #: ../src/guestfs.pod:368
872 "L</guestfs_ls> is a quick way to get a list of files in a directory from "
873 "programs, as a flat list of strings."
878 #: ../src/guestfs.pod:371
880 "L</guestfs_readdir> is a programmatic way to get a list of files in a "
881 "directory, plus additional information about each one. It is more "
882 "equivalent to using the L<readdir(3)> call on a local filesystem."
887 #: ../src/guestfs.pod:375
889 "L</guestfs_find> and L</guestfs_find0> can be used to recursively list files."
894 #: ../src/guestfs.pod:378
895 msgid "RUNNING COMMANDS"
900 #: ../src/guestfs.pod:380
902 "Although libguestfs is primarily an API for manipulating files inside guest "
903 "images, we also provide some limited facilities for running commands inside "
909 #: ../src/guestfs.pod:384
910 msgid "There are many limitations to this:"
915 #: ../src/guestfs.pod:388 ../src/guestfs.pod:393 ../src/guestfs.pod:398
916 #: ../src/guestfs.pod:402 ../src/guestfs.pod:407 ../src/guestfs.pod:411
917 #: ../src/guestfs.pod:416 ../src/guestfs.pod:421 ../src/guestfs.pod:1087
918 #: ../src/guestfs.pod:1091 ../src/guestfs.pod:1095 ../src/guestfs.pod:1100
919 #: ../src/guestfs.pod:1108 ../src/guestfs.pod:1127 ../src/guestfs.pod:1135
920 #: ../src/guestfs.pod:1157 ../src/guestfs.pod:1161 ../src/guestfs.pod:1165
921 #: ../src/guestfs.pod:1169 ../src/guestfs.pod:1173 ../src/guestfs.pod:1177
922 #: ../src/guestfs.pod:1659 ../src/guestfs.pod:1664 ../src/guestfs.pod:1668
923 #: ../src/guestfs.pod:1769 ../src/guestfs.pod:1774 ../src/guestfs.pod:1778
924 #: ../src/guestfs.pod:1788 ../src/guestfs.pod:2022 ../src/guestfs.pod:2027
925 #: ../src/guestfs.pod:2033 ../src/guestfs.pod:2041 ../src/guestfs.pod:2395
926 #: ../src/guestfs.pod:2401 ../src/guestfs.pod:2406 ../src/guestfs.pod:2412
927 #: ../src/guestfs.pod:2877 ../src/guestfs.pod:2881 ../src/guestfs.pod:2885
928 #: ../src/guestfs.pod:2889 ../src/guestfs-actions.pod:15
929 #: ../src/guestfs-actions.pod:22 ../src/guestfs-actions.pod:577
930 #: ../src/guestfs-actions.pod:585 ../src/guestfs-actions.pod:592
931 #: ../src/guestfs-actions.pod:599 ../src/guestfs-actions.pod:1600
932 #: ../src/guestfs-actions.pod:1604 ../src/guestfs-actions.pod:1608
933 #: ../src/guestfs-actions.pod:1612 ../src/guestfs-actions.pod:1620
934 #: ../src/guestfs-actions.pod:1624 ../src/guestfs-actions.pod:1628
935 #: ../src/guestfs-actions.pod:1638 ../src/guestfs-actions.pod:1642
936 #: ../src/guestfs-actions.pod:1646 ../src/guestfs-actions.pod:1784
937 #: ../src/guestfs-actions.pod:1788 ../src/guestfs-actions.pod:1793
938 #: ../src/guestfs-actions.pod:1798 ../src/guestfs-actions.pod:1859
939 #: ../src/guestfs-actions.pod:1863 ../src/guestfs-actions.pod:1868
940 #: ../fish/guestfish.pod:443 ../fish/guestfish.pod:447
941 #: ../fish/guestfish.pod:451 ../fish/guestfish.pod:455
942 #: ../fish/guestfish-actions.pod:13 ../fish/guestfish-actions.pod:20
943 #: ../fish/guestfish-actions.pod:380 ../fish/guestfish-actions.pod:388
944 #: ../fish/guestfish-actions.pod:395 ../fish/guestfish-actions.pod:402
945 #: ../fish/guestfish-actions.pod:1072 ../fish/guestfish-actions.pod:1076
946 #: ../fish/guestfish-actions.pod:1080 ../fish/guestfish-actions.pod:1084
947 #: ../fish/guestfish-actions.pod:1092 ../fish/guestfish-actions.pod:1096
948 #: ../fish/guestfish-actions.pod:1100 ../fish/guestfish-actions.pod:1110
949 #: ../fish/guestfish-actions.pod:1114 ../fish/guestfish-actions.pod:1118
950 #: ../fish/guestfish-actions.pod:1208 ../fish/guestfish-actions.pod:1212
951 #: ../fish/guestfish-actions.pod:1217 ../fish/guestfish-actions.pod:1222
952 #: ../fish/guestfish-actions.pod:1264 ../fish/guestfish-actions.pod:1268
953 #: ../fish/guestfish-actions.pod:1273 ../tools/virt-edit.pl:351
954 #: ../tools/virt-edit.pl:356 ../tools/virt-edit.pl:361
955 #: ../tools/virt-edit.pl:372 ../tools/virt-edit.pl:376
956 #: ../tools/virt-win-reg.pl:536 ../tools/virt-win-reg.pl:542
957 #: ../tools/virt-win-reg.pl:548
963 #: ../src/guestfs.pod:390
965 "The kernel version that the command runs under will be different from what "
971 #: ../src/guestfs.pod:395
973 "If the command needs to communicate with daemons, then most likely they "
979 #: ../src/guestfs.pod:400
980 msgid "The command will be running in limited memory."
985 #: ../src/guestfs.pod:404
987 "The network may not be available unless you enable it (see L</"
988 "guestfs_set_network>)."
993 #: ../src/guestfs.pod:409
994 msgid "Only supports Linux guests (not Windows, BSD, etc)."
999 #: ../src/guestfs.pod:413
1001 "Architecture limitations (eg. won't work for a PPC guest on an X86 host)."
1006 #: ../src/guestfs.pod:418
1008 "For SELinux guests, you may need to enable SELinux and load policy first. "
1009 "See L</SELINUX> in this manpage."
1014 #: ../src/guestfs.pod:423
1016 "I<Security:> It is not safe to run commands from untrusted, possibly "
1017 "malicious guests. These commands may attempt to exploit your program by "
1018 "sending unexpected output. They could also try to exploit the Linux kernel "
1019 "or qemu provided by the libguestfs appliance. They could use the network "
1020 "provided by the libguestfs appliance to bypass ordinary network partitions "
1021 "and firewalls. They could use the elevated privileges or different SELinux "
1022 "context of your program to their advantage."
1027 #: ../src/guestfs.pod:432
1029 "A secure alternative is to use libguestfs to install a \"firstboot\" script "
1030 "(a script which runs when the guest next boots normally), and to have this "
1031 "script run the commands you want in the normal context of the running guest, "
1032 "network security and so on. For information about other security issues, "
1038 #: ../src/guestfs.pod:440
1040 "The two main API calls to run commands are L</guestfs_command> and L</"
1041 "guestfs_sh> (there are also variations)."
1046 #: ../src/guestfs.pod:443
1048 "The difference is that L</guestfs_sh> runs commands using the shell, so any "
1049 "shell globs, redirections, etc will work."
1054 #: ../src/guestfs.pod:446
1055 msgid "CONFIGURATION FILES"
1060 #: ../src/guestfs.pod:448
1062 "To read and write configuration files in Linux guest filesystems, we "
1063 "strongly recommend using Augeas. For example, Augeas understands how to "
1064 "read and write, say, a Linux shadow password file or X.org configuration "
1065 "file, and so avoids you having to write that code."
1070 #: ../src/guestfs.pod:453
1072 "The main Augeas calls are bound through the C<guestfs_aug_*> APIs. We don't "
1073 "document Augeas itself here because there is excellent documentation on the "
1074 "L<http://augeas.net/> website."
1079 #: ../src/guestfs.pod:457
1081 "If you don't want to use Augeas (you fool!) then try calling L</"
1082 "guestfs_read_lines> to get the file as a list of lines which you can iterate "
1088 #: ../src/guestfs.pod:461
1094 #: ../src/guestfs.pod:463
1096 "We support SELinux guests. To ensure that labeling happens correctly in "
1097 "SELinux guests, you need to enable SELinux and load the guest's policy:"
1102 #: ../src/guestfs.pod:469 ../src/guestfs.pod:1280 ../src/guestfs.pod:1411
1103 #: ../src/guestfs.pod:2440
1109 #: ../src/guestfs.pod:471
1110 msgid "Before launching, do:"
1115 #: ../src/guestfs.pod:473
1118 " guestfs_set_selinux (g, 1);\n"
1124 #: ../src/guestfs.pod:475 ../src/guestfs.pod:1284 ../src/guestfs.pod:1415
1125 #: ../src/guestfs.pod:2465
1131 #: ../src/guestfs.pod:477
1133 "After mounting the guest's filesystem(s), load the policy. This is best "
1134 "done by running the L<load_policy(8)> command in the guest itself:"
1139 #: ../src/guestfs.pod:481
1142 " guestfs_sh (g, \"/usr/sbin/load_policy\");\n"
1148 #: ../src/guestfs.pod:483
1150 "(Older versions of C<load_policy> require you to specify the name of the "
1156 #: ../src/guestfs.pod:486 ../src/guestfs.pod:1421
1162 #: ../src/guestfs.pod:488
1164 "Optionally, set the security context for the API. The correct security "
1165 "context to use can only be known by inspecting the guest. As an example:"
1170 #: ../src/guestfs.pod:492
1173 " guestfs_setcon (g, \"unconfined_u:unconfined_r:unconfined_t:s0\");\n"
1179 #: ../src/guestfs.pod:496
1180 msgid "This will work for running commands and editing existing files."
1185 #: ../src/guestfs.pod:498
1187 "When new files are created, you may need to label them explicitly, for "
1188 "example by running the external command C<restorecon pathname>."
1193 #: ../src/guestfs.pod:502
1199 #: ../src/guestfs.pod:504
1201 "Certain calls are affected by the current file mode creation mask (the "
1202 "\"umask\"). In particular ones which create files or directories, such as "
1203 "L</guestfs_touch>, L</guestfs_mknod> or L</guestfs_mkdir>. This affects "
1204 "either the default mode that the file is created with or modifies the mode "
1210 #: ../src/guestfs.pod:510
1212 "The default umask is C<022>, so files are created with modes such as C<0644> "
1213 "and directories with C<0755>."
1218 #: ../src/guestfs.pod:513
1220 "There are two ways to avoid being affected by umask. Either set umask to 0 "
1221 "(call C<guestfs_umask (g, 0)> early after launching). Or call L</"
1222 "guestfs_chmod> after creating each file or directory."
1227 #: ../src/guestfs.pod:517
1228 msgid "For more information about umask, see L<umask(2)>."
1233 #: ../src/guestfs.pod:519 ../fish/guestfish.pod:765
1234 msgid "ENCRYPTED DISKS"
1239 #: ../src/guestfs.pod:521
1241 "Libguestfs allows you to access Linux guests which have been encrypted using "
1242 "whole disk encryption that conforms to the Linux Unified Key Setup (LUKS) "
1243 "standard. This includes nearly all whole disk encryption systems used by "
1244 "modern Linux guests."
1249 #: ../src/guestfs.pod:527
1251 "Use L</guestfs_vfs_type> to identify LUKS-encrypted block devices (it "
1252 "returns the string C<crypto_LUKS>)."
1257 #: ../src/guestfs.pod:530
1259 "Then open these devices by calling L</guestfs_luks_open>. Obviously you "
1260 "will require the passphrase!"
1265 #: ../src/guestfs.pod:533
1267 "Opening a LUKS device creates a new device mapper device called C</dev/"
1268 "mapper/mapname> (where C<mapname> is the string you supply to L</"
1269 "guestfs_luks_open>). Reads and writes to this mapper device are decrypted "
1270 "from and encrypted to the underlying block device respectively."
1275 #: ../src/guestfs.pod:539
1277 "LVM volume groups on the device can be made visible by calling L</"
1278 "guestfs_vgscan> followed by L</guestfs_vg_activate_all>. The logical volume"
1279 "(s) can now be mounted in the usual way."
1284 #: ../src/guestfs.pod:543
1286 "Use the reverse process to close a LUKS device. Unmount any logical volumes "
1287 "on it, deactivate the volume groups by caling C<guestfs_vg_activate (g, 0, "
1288 "[\"/dev/VG\"])>. Then close the mapper device by calling L</"
1289 "guestfs_luks_close> on the C</dev/mapper/mapname> device (I<not> the "
1290 "underlying encrypted block device)."
1295 #: ../src/guestfs.pod:550
1300 #: ../src/guestfs.pod:552
1302 "Libguestfs has APIs for inspecting an unknown disk image to find out if it "
1303 "contains operating systems, an install CD or a live CD. (These APIs used to "
1304 "be in a separate Perl-only library called L<Sys::Guestfs::Lib(3)> but since "
1305 "version 1.5.3 the most frequently used part of this library has been "
1306 "rewritten in C and moved into the core code)."
1311 #: ../src/guestfs.pod:559
1313 "Add all disks belonging to the unknown virtual machine and call L</"
1314 "guestfs_launch> in the usual way."
1319 #: ../src/guestfs.pod:562
1321 "Then call L</guestfs_inspect_os>. This function uses other libguestfs calls "
1322 "and certain heuristics, and returns a list of operating systems that were "
1323 "found. An empty list means none were found. A single element is the root "
1324 "filesystem of the operating system. For dual- or multi-boot guests, "
1325 "multiple roots can be returned, each one corresponding to a separate "
1326 "operating system. (Multi-boot virtual machines are extremely rare in the "
1327 "world of virtualization, but since this scenario can happen, we have built "
1328 "libguestfs to deal with it.)"
1333 #: ../src/guestfs.pod:571
1335 "For each root, you can then call various C<guestfs_inspect_get_*> functions "
1336 "to get additional details about that operating system. For example, call L</"
1337 "guestfs_inspect_get_type> to return the string C<windows> or C<linux> for "
1338 "Windows and Linux-based operating systems respectively."
1343 #: ../src/guestfs.pod:577
1345 "Un*x-like and Linux-based operating systems usually consist of several "
1346 "filesystems which are mounted at boot time (for example, a separate boot "
1347 "partition mounted on C</boot>). The inspection rules are able to detect how "
1348 "filesystems correspond to mount points. Call "
1349 "C<guestfs_inspect_get_mountpoints> to get this mapping. It might return a "
1350 "hash table like this example:"
1355 #: ../src/guestfs.pod:584
1358 " /boot => /dev/sda1\n"
1359 " / => /dev/vg_guest/lv_root\n"
1360 " /usr => /dev/vg_guest/lv_usr\n"
1366 #: ../src/guestfs.pod:588
1368 "The caller can then make calls to L</guestfs_mount_options> to mount the "
1369 "filesystems as suggested."
1374 #: ../src/guestfs.pod:591
1376 "Be careful to mount filesystems in the right order (eg. C</> before C</"
1377 "usr>). Sorting the keys of the hash by length, shortest first, should work."
1382 #: ../src/guestfs.pod:595
1384 "Inspection currently only works for some common operating systems. "
1385 "Contributors are welcome to send patches for other operating systems that we "
1386 "currently cannot detect."
1391 #: ../src/guestfs.pod:599
1393 "Encrypted disks must be opened before inspection. See L</ENCRYPTED DISKS> "
1394 "for more details. The L</guestfs_inspect_os> function just ignores any "
1395 "encrypted devices."
1400 #: ../src/guestfs.pod:603
1402 "A note on the implementation: The call L</guestfs_inspect_os> performs "
1403 "inspection and caches the results in the guest handle. Subsequent calls to "
1404 "C<guestfs_inspect_get_*> return this cached information, but I<do not> re-"
1405 "read the disks. If you change the content of the guest disks, you can redo "
1406 "inspection by calling L</guestfs_inspect_os> again. (L</"
1407 "guestfs_inspect_list_applications> works a little differently from the other "
1408 "calls and does read the disks. See documentation for that function for "
1413 #: ../src/guestfs.pod:612
1414 msgid "INSPECTING INSTALL DISKS"
1418 #: ../src/guestfs.pod:614
1420 "Libguestfs (since 1.9.4) can detect some install disks, install CDs, live "
1425 #: ../src/guestfs.pod:617
1427 "Call L</guestfs_inspect_get_format> to return the format of the operating "
1428 "system, which currently can be C<installed> (a regular operating system) or "
1429 "C<installer> (some sort of install disk)."
1433 #: ../src/guestfs.pod:621
1435 "Further information is available about the operating system that can be "
1436 "installed using the regular inspection APIs like L</"
1437 "guestfs_inspect_get_product_name>, L</guestfs_inspect_get_major_version> etc."
1441 #: ../src/guestfs.pod:626
1443 "Some additional information specific to installer disks is also available "
1444 "from the L</guestfs_inspect_is_live>, L</guestfs_inspect_is_netinst> and L</"
1445 "guestfs_inspect_is_multipart> calls."
1450 #: ../src/guestfs.pod:631
1451 msgid "SPECIAL CONSIDERATIONS FOR WINDOWS GUESTS"
1456 #: ../src/guestfs.pod:633
1458 "Libguestfs can mount NTFS partitions. It does this using the L<http://www."
1459 "ntfs-3g.org/> driver."
1464 #: ../src/guestfs.pod:636
1465 msgid "DRIVE LETTERS AND PATHS"
1470 #: ../src/guestfs.pod:638
1472 "DOS and Windows still use drive letters, and the filesystems are always "
1473 "treated as case insensitive by Windows itself, and therefore you might find "
1474 "a Windows configuration file referring to a path like C<c:\\windows"
1475 "\\system32>. When the filesystem is mounted in libguestfs, that directory "
1476 "might be referred to as C</WINDOWS/System32>."
1480 #: ../src/guestfs.pod:644
1482 "Drive letter mappings can be found using inspection (see L</INSPECTION> and "
1483 "L</guestfs_inspect_get_drive_mappings>)"
1487 #: ../src/guestfs.pod:647
1489 "Dealing with separator characters (backslash vs forward slash) is outside "
1490 "the scope of libguestfs, but usually a simple character replacement will "
1495 #: ../src/guestfs.pod:651
1497 "To resolve the case insensitivity of paths, call L</"
1498 "guestfs_case_sensitive_path>."
1503 #: ../src/guestfs.pod:654
1504 msgid "ACCESSING THE WINDOWS REGISTRY"
1509 #: ../src/guestfs.pod:656
1511 "Libguestfs also provides some help for decoding Windows Registry \"hive\" "
1512 "files, through the library C<hivex> which is part of the libguestfs project "
1513 "although ships as a separate tarball. You have to locate and download the "
1514 "hive file(s) yourself, and then pass them to C<hivex> functions. See also "
1515 "the programs L<hivexml(1)>, L<hivexsh(1)>, L<hivexregedit(1)> and L<virt-win-"
1516 "reg(1)> for more help on this issue."
1521 #: ../src/guestfs.pod:664
1522 msgid "SYMLINKS ON NTFS-3G FILESYSTEMS"
1527 #: ../src/guestfs.pod:666
1529 "Ntfs-3g tries to rewrite \"Junction Points\" and NTFS \"symbolic links\" to "
1530 "provide something which looks like a Linux symlink. The way it tries to do "
1531 "the rewriting is described here:"
1536 #: ../src/guestfs.pod:670
1538 "L<http://www.tuxera.com/community/ntfs-3g-advanced/junction-points-and-"
1544 #: ../src/guestfs.pod:672
1546 "The essential problem is that ntfs-3g simply does not have enough "
1547 "information to do a correct job. NTFS links can contain drive letters and "
1548 "references to external device GUIDs that ntfs-3g has no way of resolving. "
1549 "It is almost certainly the case that libguestfs callers should ignore what "
1550 "ntfs-3g does (ie. don't use L</guestfs_readlink> on NTFS volumes)."
1555 #: ../src/guestfs.pod:679
1557 "Instead if you encounter a symbolic link on an ntfs-3g filesystem, use L</"
1558 "guestfs_lgetxattr> to read the C<system.ntfs_reparse_data> extended "
1559 "attribute, and read the raw reparse data from that (you can find the format "
1560 "documented in various places around the web)."
1565 #: ../src/guestfs.pod:684
1566 msgid "EXTENDED ATTRIBUTES ON NTFS-3G FILESYSTEMS"
1571 #: ../src/guestfs.pod:686
1573 "There are other useful extended attributes that can be read from ntfs-3g "
1574 "filesystems (using L</guestfs_getxattr>). See:"
1579 #: ../src/guestfs.pod:689
1581 "L<http://www.tuxera.com/community/ntfs-3g-advanced/extended-attributes/>"
1586 #: ../src/guestfs.pod:691
1587 msgid "USING LIBGUESTFS WITH OTHER PROGRAMMING LANGUAGES"
1592 #: ../src/guestfs.pod:693
1594 "Although we don't want to discourage you from using the C API, we will "
1595 "mention here that the same API is also available in other languages."
1599 #: ../src/guestfs.pod:696
1601 "The API is broadly identical in all supported languages. This means that "
1602 "the C call C<guestfs_add_drive_ro(g,file)> is C<$g-E<gt>add_drive_ro($file)> "
1603 "in Perl, C<g.add_drive_ro(file)> in Python, and C<g#add_drive_ro file> in "
1604 "OCaml. In other words, a straightforward, predictable isomorphism between "
1610 #: ../src/guestfs.pod:702
1612 "Error messages are automatically transformed into exceptions if the language "
1618 #: ../src/guestfs.pod:705
1620 "We don't try to \"object orientify\" parts of the API in OO languages, "
1621 "although contributors are welcome to write higher level APIs above what we "
1622 "provide in their favourite languages if they wish."
1627 #: ../src/guestfs.pod:711
1633 #: ../src/guestfs.pod:713
1635 "You can use the I<guestfs.h> header file from C++ programs. The C++ API is "
1636 "identical to the C API. C++ classes and exceptions are not used."
1641 #: ../src/guestfs.pod:717
1647 #: ../src/guestfs.pod:719
1649 "The C# bindings are highly experimental. Please read the warnings at the "
1650 "top of C<csharp/Libguestfs.cs>."
1655 #: ../src/guestfs.pod:722
1661 #: ../src/guestfs.pod:724
1663 "This is the only language binding that is working but incomplete. Only "
1664 "calls which return simple integers have been bound in Haskell, and we are "
1665 "looking for help to complete this binding."
1670 #: ../src/guestfs.pod:728
1676 #: ../src/guestfs.pod:730
1678 "Full documentation is contained in the Javadoc which is distributed with "
1684 #: ../src/guestfs.pod:733
1689 #: ../src/guestfs.pod:735
1690 msgid "See L<guestfs-ocaml(3)>."
1695 #: ../src/guestfs.pod:737
1700 #: ../src/guestfs.pod:739
1701 msgid "See L<guestfs-perl(3)> and L<Sys::Guestfs(3)>."
1706 #: ../src/guestfs.pod:741
1712 #: ../src/guestfs.pod:743
1714 "For documentation see C<README-PHP> supplied with libguestfs sources or in "
1715 "the php-libguestfs package for your distribution."
1720 #: ../src/guestfs.pod:746
1721 msgid "The PHP binding only works correctly on 64 bit machines."
1726 #: ../src/guestfs.pod:748
1731 #: ../src/guestfs.pod:750
1732 msgid "See L<guestfs-python(3)>."
1737 #: ../src/guestfs.pod:752
1742 #: ../src/guestfs.pod:754
1743 msgid "See L<guestfs-ruby(3)>."
1748 #: ../src/guestfs.pod:756
1749 msgid "B<shell scripts>"
1753 #: ../src/guestfs.pod:758
1754 msgid "See L<guestfish(1)>."
1759 #: ../src/guestfs.pod:762
1760 msgid "LIBGUESTFS GOTCHAS"
1765 #: ../src/guestfs.pod:764
1767 "L<http://en.wikipedia.org/wiki/Gotcha_(programming)>: \"A feature of a "
1768 "system [...] that works in the way it is documented but is counterintuitive "
1769 "and almost invites mistakes.\""
1774 #: ../src/guestfs.pod:768
1776 "Since we developed libguestfs and the associated tools, there are several "
1777 "things we would have designed differently, but are now stuck with for "
1778 "backwards compatibility or other reasons. If there is ever a libguestfs 2.0 "
1779 "release, you can expect these to change. Beware of them."
1784 #: ../src/guestfs.pod:776
1785 msgid "Autosync / forgetting to sync."
1790 #: ../src/guestfs.pod:778
1792 "When modifying a filesystem from C or another language, you B<must> unmount "
1793 "all filesystems and call L</guestfs_sync> explicitly before you close the "
1794 "libguestfs handle. You can also call:"
1799 #: ../src/guestfs.pod:782
1802 " guestfs_set_autosync (g, 1);\n"
1808 #: ../src/guestfs.pod:784
1810 "to have the unmount/sync done automatically for you when the handle 'g' is "
1811 "closed. (This feature is called \"autosync\", L</guestfs_set_autosync> q.v.)"
1816 #: ../src/guestfs.pod:788
1818 "If you forget to do this, then it is entirely possible that your changes "
1819 "won't be written out, or will be partially written, or (very rarely) that "
1820 "you'll get disk corruption."
1825 #: ../src/guestfs.pod:792
1827 "Note that in L<guestfish(3)> autosync is the default. So quick and dirty "
1828 "guestfish scripts that forget to sync will work just fine, which can make "
1829 "this very puzzling if you are trying to debug a problem."
1834 #: ../src/guestfs.pod:796
1836 "Update: Autosync is enabled by default for all API users starting from "
1837 "libguestfs 1.5.24."
1842 #: ../src/guestfs.pod:799
1843 msgid "Mount option C<-o sync> should not be the default."
1848 #: ../src/guestfs.pod:801
1850 "If you use L</guestfs_mount>, then C<-o sync,noatime> are added implicitly. "
1851 "However C<-o sync> does not add any reliability benefit, but does have a "
1852 "very large performance impact."
1857 #: ../src/guestfs.pod:805
1859 "The work around is to use L</guestfs_mount_options> and set the mount "
1860 "options that you actually want to use."
1865 #: ../src/guestfs.pod:808
1866 msgid "Read-only should be the default."
1871 #: ../src/guestfs.pod:810
1873 "In L<guestfish(3)>, I<--ro> should be the default, and you should have to "
1874 "specify I<--rw> if you want to make changes to the image."
1879 #: ../src/guestfs.pod:813
1880 msgid "This would reduce the potential to corrupt live VM images."
1885 #: ../src/guestfs.pod:815
1887 "Note that many filesystems change the disk when you just mount and unmount, "
1888 "even if you didn't perform any writes. You need to use L</"
1889 "guestfs_add_drive_ro> to guarantee that the disk is not changed."
1894 #: ../src/guestfs.pod:819
1895 msgid "guestfish command line is hard to use."
1900 #: ../src/guestfs.pod:821
1902 "C<guestfish disk.img> doesn't do what people expect (open C<disk.img> for "
1903 "examination). It tries to run a guestfish command C<disk.img> which doesn't "
1904 "exist, so it fails. In earlier versions of guestfish the error message was "
1905 "also unintuitive, but we have corrected this since. Like the Bourne shell, "
1906 "we should have used C<guestfish -c command> to run commands."
1911 #: ../src/guestfs.pod:828
1912 msgid "guestfish megabyte modifiers don't work right on all commands"
1917 #: ../src/guestfs.pod:830
1919 "In recent guestfish you can use C<1M> to mean 1 megabyte (and similarly for "
1920 "other modifiers). What guestfish actually does is to multiply the number "
1921 "part by the modifier part and pass the result to the C API. However this "
1922 "doesn't work for a few APIs which aren't expecting bytes, but are already "
1923 "expecting some other unit (eg. megabytes)."
1928 #: ../src/guestfs.pod:837
1929 msgid "The most common is L</guestfs_lvcreate>. The guestfish command:"
1934 #: ../src/guestfs.pod:839
1937 " lvcreate LV VG 100M\n"
1943 #: ../src/guestfs.pod:841
1945 "does not do what you might expect. Instead because L</guestfs_lvcreate> is "
1946 "already expecting megabytes, this tries to create a 100 I<terabyte> (100 "
1947 "megabytes * megabytes) logical volume. The error message you get from this "
1948 "is also a little obscure."
1953 #: ../src/guestfs.pod:846
1955 "This could be fixed in the generator by specially marking parameters and "
1956 "return values which take bytes or other units."
1961 #: ../src/guestfs.pod:849
1962 msgid "Ambiguity between devices and paths"
1967 #: ../src/guestfs.pod:851
1969 "There is a subtle ambiguity in the API between a device name (eg. C</dev/"
1970 "sdb2>) and a similar pathname. A file might just happen to be called "
1971 "C<sdb2> in the directory C</dev> (consider some non-Unix VM image)."
1976 #: ../src/guestfs.pod:856
1978 "In the current API we usually resolve this ambiguity by having two separate "
1979 "calls, for example L</guestfs_checksum> and L</guestfs_checksum_device>. "
1980 "Some API calls are ambiguous and (incorrectly) resolve the problem by "
1981 "detecting if the path supplied begins with C</dev/>."
1986 #: ../src/guestfs.pod:862
1988 "To avoid both the ambiguity and the need to duplicate some calls, we could "
1989 "make paths/devices into structured names. One way to do this would be to "
1990 "use a notation like grub (C<hd(0,0)>), although nobody really likes this "
1991 "aspect of grub. Another way would be to use a structured type, equivalent "
1992 "to this OCaml type:"
1997 #: ../src/guestfs.pod:868
2000 " type path = Path of string | Device of int | Partition of int * int\n"
2006 #: ../src/guestfs.pod:870
2007 msgid "which would allow you to pass arguments like:"
2012 #: ../src/guestfs.pod:872
2015 " Path \"/foo/bar\"\n"
2016 " Device 1 (* /dev/sdb, or perhaps /dev/sda *)\n"
2017 " Partition (1, 2) (* /dev/sdb2 (or is it /dev/sda2 or /dev/sdb3?) *)\n"
2018 " Path \"/dev/sdb2\" (* not a device *)\n"
2024 #: ../src/guestfs.pod:877
2026 "As you can see there are still problems to resolve even with this "
2027 "representation. Also consider how it might work in guestfish."
2032 #: ../src/guestfs.pod:882
2033 msgid "PROTOCOL LIMITS"
2038 #: ../src/guestfs.pod:884
2040 "Internally libguestfs uses a message-based protocol to pass API calls and "
2041 "their responses to and from a small \"appliance\" (see L</INTERNALS> for "
2042 "plenty more detail about this). The maximum message size used by the "
2043 "protocol is slightly less than 4 MB. For some API calls you may need to be "
2044 "aware of this limit. The API calls which may be affected are individually "
2045 "documented, with a link back to this section of the documentation."
2050 #: ../src/guestfs.pod:892
2052 "A simple call such as L</guestfs_cat> returns its result (the file data) in "
2053 "a simple string. Because this string is at some point internally encoded as "
2054 "a message, the maximum size that it can return is slightly under 4 MB. If "
2055 "the requested file is larger than this then you will get an error."
2060 #: ../src/guestfs.pod:898
2062 "In order to transfer large files into and out of the guest filesystem, you "
2063 "need to use particular calls that support this. The sections L</UPLOADING> "
2064 "and L</DOWNLOADING> document how to do this."
2069 #: ../src/guestfs.pod:902
2071 "You might also consider mounting the disk image using our FUSE filesystem "
2072 "support (L<guestmount(1)>)."
2077 #: ../src/guestfs.pod:905
2078 msgid "KEYS AND PASSPHRASES"
2083 #: ../src/guestfs.pod:907
2085 "Certain libguestfs calls take a parameter that contains sensitive key "
2086 "material, passed in as a C string."
2091 #: ../src/guestfs.pod:910
2093 "In the future we would hope to change the libguestfs implementation so that "
2094 "keys are L<mlock(2)>-ed into physical RAM, and thus can never end up in "
2095 "swap. However this is I<not> done at the moment, because of the complexity "
2096 "of such an implementation."
2101 #: ../src/guestfs.pod:915
2103 "Therefore you should be aware that any key parameter you pass to libguestfs "
2104 "might end up being written out to the swap partition. If this is a concern, "
2105 "scrub the swap partition or don't use libguestfs on encrypted devices."
2110 #: ../src/guestfs.pod:920
2111 msgid "MULTIPLE HANDLES AND MULTIPLE THREADS"
2116 #: ../src/guestfs.pod:922
2118 "All high-level libguestfs actions are synchronous. If you want to use "
2119 "libguestfs asynchronously then you must create a thread."
2124 #: ../src/guestfs.pod:925
2126 "Only use the handle from a single thread. Either use the handle exclusively "
2127 "from one thread, or provide your own mutex so that two threads cannot issue "
2128 "calls on the same handle at the same time."
2133 #: ../src/guestfs.pod:929
2135 "See the graphical program guestfs-browser for one possible architecture for "
2136 "multithreaded programs using libvirt and libguestfs."
2141 #: ../src/guestfs.pod:932
2146 #: ../src/guestfs.pod:934
2148 "Libguestfs needs a supermin appliance, which it finds by looking along an "
2154 #: ../src/guestfs.pod:937
2156 "By default it looks for these in the directory C<$libdir/guestfs> (eg. C</"
2157 "usr/local/lib/guestfs> or C</usr/lib64/guestfs>)."
2162 #: ../src/guestfs.pod:940
2164 "Use L</guestfs_set_path> or set the environment variable L</LIBGUESTFS_PATH> "
2165 "to change the directories that libguestfs will search in. The value is a "
2166 "colon-separated list of paths. The current directory is I<not> searched "
2167 "unless the path contains an empty element or C<.>. For example "
2168 "C<LIBGUESTFS_PATH=:/usr/lib/guestfs> would search the current directory and "
2169 "then C</usr/lib/guestfs>."
2174 #: ../src/guestfs.pod:947
2175 msgid "QEMU WRAPPERS"
2180 #: ../src/guestfs.pod:949
2182 "If you want to compile your own qemu, run qemu from a non-standard location, "
2183 "or pass extra arguments to qemu, then you can write a shell-script wrapper "
2189 #: ../src/guestfs.pod:953
2191 "There is one important rule to remember: you I<must C<exec qemu>> as the "
2192 "last command in the shell script (so that qemu replaces the shell and "
2193 "becomes the direct child of the libguestfs-using program). If you don't do "
2194 "this, then the qemu process won't be cleaned up correctly."
2199 #: ../src/guestfs.pod:958
2201 "Here is an example of a wrapper, where I have built my own copy of qemu from "
2207 #: ../src/guestfs.pod:961
2211 " qemudir=/home/rjones/d/qemu\n"
2212 " exec $qemudir/x86_64-softmmu/qemu-system-x86_64 -L $qemudir/pc-bios \"$@\"\n"
2218 #: ../src/guestfs.pod:965
2220 "Save this script as C</tmp/qemu.wrapper> (or wherever), C<chmod +x>, and "
2221 "then use it by setting the LIBGUESTFS_QEMU environment variable. For "
2227 #: ../src/guestfs.pod:969
2230 " LIBGUESTFS_QEMU=/tmp/qemu.wrapper guestfish\n"
2236 #: ../src/guestfs.pod:971
2238 "Note that libguestfs also calls qemu with the -help and -version options in "
2239 "order to determine features."
2243 #: ../src/guestfs.pod:974
2244 msgid "ATTACHING TO RUNNING DAEMONS"
2248 #: ../src/guestfs.pod:976
2250 "I<Note (1):> This is B<highly experimental> and has a tendency to eat "
2251 "babies. Use with caution."
2255 #: ../src/guestfs.pod:979
2257 "I<Note (2):> This section explains how to attach to a running daemon from a "
2258 "low level perspective. For most users, simply using virt tools such as "
2259 "L<guestfish(1)> with the I<--live> option will \"just work\"."
2263 #: ../src/guestfs.pod:983
2264 msgid "Using guestfs_set_attach_method"
2268 #: ../src/guestfs.pod:985
2270 "By calling L</guestfs_set_attach_method> you can change how the library "
2271 "connects to the C<guestfsd> daemon in L</guestfs_launch> (read L</"
2272 "ARCHITECTURE> for some background)."
2276 #: ../src/guestfs.pod:989
2278 "The normal attach method is C<appliance>, where a small appliance is created "
2279 "containing the daemon, and then the library connects to this."
2283 #: ../src/guestfs.pod:992
2285 "Setting attach method to C<unix:I<path>> (where I<path> is the path of a "
2286 "Unix domain socket) causes L</guestfs_launch> to connect to an existing "
2287 "daemon over the Unix domain socket."
2291 #: ../src/guestfs.pod:996
2293 "The normal use for this is to connect to a running virtual machine that "
2294 "contains a C<guestfsd> daemon, and send commands so you can read and write "
2295 "files inside the live virtual machine."
2299 #: ../src/guestfs.pod:1000
2300 msgid "Using guestfs_add_domain with live flag"
2304 #: ../src/guestfs.pod:1002
2306 "L</guestfs_add_domain> provides some help for getting the correct attach "
2307 "method. If you pass the C<live> option to this function, then (if the "
2308 "virtual machine is running) it will examine the libvirt XML looking for a "
2309 "virtio-serial channel to connect to:"
2313 #: ../src/guestfs.pod:1008
2320 " <channel type='unix'>\n"
2321 " <source mode='bind' path='/path/to/socket'/>\n"
2322 " <target type='virtio' name='org.libguestfs.channel.0'/>\n"
2331 #: ../src/guestfs.pod:1020
2333 "L</guestfs_add_domain> extracts C</path/to/socket> and sets the attach "
2334 "method to C<unix:/path/to/socket>."
2338 #: ../src/guestfs.pod:1023
2340 "Some of the libguestfs tools (including guestfish) support a I<--live> "
2341 "option which is passed through to L</guestfs_add_domain> thus allowing you "
2342 "to attach to and modify live virtual machines."
2346 #: ../src/guestfs.pod:1027
2348 "The virtual machine needs to have been set up beforehand so that it has the "
2349 "virtio-serial channel and so that guestfsd is running inside it."
2354 #: ../src/guestfs.pod:1031
2355 msgid "ABI GUARANTEE"
2360 #: ../src/guestfs.pod:1033
2362 "We guarantee the libguestfs ABI (binary interface), for public, high-level "
2363 "actions as outlined in this section. Although we will deprecate some "
2364 "actions, for example if they get replaced by newer calls, we will keep the "
2365 "old actions forever. This allows you the developer to program in confidence "
2366 "against the libguestfs API."
2371 #: ../src/guestfs.pod:1039
2372 msgid "BLOCK DEVICE NAMING"
2377 #: ../src/guestfs.pod:1041
2379 "In the kernel there is now quite a profusion of schemata for naming block "
2380 "devices (in this context, by I<block device> I mean a physical or virtual "
2381 "hard drive). The original Linux IDE driver used names starting with C</dev/"
2382 "hd*>. SCSI devices have historically used a different naming scheme, C</dev/"
2383 "sd*>. When the Linux kernel I<libata> driver became a popular replacement "
2384 "for the old IDE driver (particularly for SATA devices) those devices also "
2385 "used the C</dev/sd*> scheme. Additionally we now have virtual machines with "
2386 "paravirtualized drivers. This has created several different naming systems, "
2387 "such as C</dev/vd*> for virtio disks and C</dev/xvd*> for Xen PV disks."
2392 #: ../src/guestfs.pod:1053
2394 "As discussed above, libguestfs uses a qemu appliance running an embedded "
2395 "Linux kernel to access block devices. We can run a variety of appliances "
2396 "based on a variety of Linux kernels."
2401 #: ../src/guestfs.pod:1057
2403 "This causes a problem for libguestfs because many API calls use device or "
2404 "partition names. Working scripts and the recipe (example) scripts that we "
2405 "make available over the internet could fail if the naming scheme changes."
2410 #: ../src/guestfs.pod:1062
2412 "Therefore libguestfs defines C</dev/sd*> as the I<standard naming scheme>. "
2413 "Internally C</dev/sd*> names are translated, if necessary, to other names as "
2414 "required. For example, under RHEL 5 which uses the C</dev/hd*> scheme, any "
2415 "device parameter C</dev/sda2> is translated to C</dev/hda2> transparently."
2420 #: ../src/guestfs.pod:1068
2422 "Note that this I<only> applies to parameters. The L</guestfs_list_devices>, "
2423 "L</guestfs_list_partitions> and similar calls return the true names of the "
2424 "devices and partitions as known to the appliance."
2429 #: ../src/guestfs.pod:1073
2430 msgid "ALGORITHM FOR BLOCK DEVICE NAME TRANSLATION"
2435 #: ../src/guestfs.pod:1075
2437 "Usually this translation is transparent. However in some (very rare) cases "
2438 "you may need to know the exact algorithm. Such cases include where you use "
2439 "L</guestfs_config> to add a mixture of virtio and IDE devices to the qemu-"
2440 "based appliance, so have a mixture of C</dev/sd*> and C</dev/vd*> devices."
2445 #: ../src/guestfs.pod:1081
2447 "The algorithm is applied only to I<parameters> which are known to be either "
2448 "device or partition names. Return values from functions such as L</"
2449 "guestfs_list_devices> are never changed."
2454 #: ../src/guestfs.pod:1089
2455 msgid "Is the string a parameter which is a device or partition name?"
2460 #: ../src/guestfs.pod:1093
2461 msgid "Does the string begin with C</dev/sd>?"
2466 #: ../src/guestfs.pod:1097
2468 "Does the named device exist? If so, we use that device. However if I<not> "
2469 "then we continue with this algorithm."
2474 #: ../src/guestfs.pod:1102
2475 msgid "Replace initial C</dev/sd> string with C</dev/hd>."
2480 #: ../src/guestfs.pod:1104
2481 msgid "For example, change C</dev/sda2> to C</dev/hda2>."
2486 #: ../src/guestfs.pod:1106
2487 msgid "If that named device exists, use it. If not, continue."
2492 #: ../src/guestfs.pod:1110
2493 msgid "Replace initial C</dev/sd> string with C</dev/vd>."
2498 #: ../src/guestfs.pod:1112
2499 msgid "If that named device exists, use it. If not, return an error."
2504 #: ../src/guestfs.pod:1116
2505 msgid "PORTABILITY CONCERNS WITH BLOCK DEVICE NAMING"
2510 #: ../src/guestfs.pod:1118
2512 "Although the standard naming scheme and automatic translation is useful for "
2513 "simple programs and guestfish scripts, for larger programs it is best not to "
2514 "rely on this mechanism."
2519 #: ../src/guestfs.pod:1122
2521 "Where possible for maximum future portability programs using libguestfs "
2522 "should use these future-proof techniques:"
2527 #: ../src/guestfs.pod:1129
2529 "Use L</guestfs_list_devices> or L</guestfs_list_partitions> to list actual "
2530 "device names, and then use those names directly."
2535 #: ../src/guestfs.pod:1132
2537 "Since those device names exist by definition, they will never be translated."
2542 #: ../src/guestfs.pod:1137
2544 "Use higher level ways to identify filesystems, such as LVM names, UUIDs and "
2545 "filesystem labels."
2550 #: ../src/guestfs.pod:1142
2556 #: ../src/guestfs.pod:1144
2558 "This section discusses security implications of using libguestfs, "
2559 "particularly with untrusted or malicious guests or disk images."
2564 #: ../src/guestfs.pod:1147
2565 msgid "GENERAL SECURITY CONSIDERATIONS"
2570 #: ../src/guestfs.pod:1149
2572 "Be careful with any files or data that you download from a guest (by "
2573 "\"download\" we mean not just the L</guestfs_download> command but any "
2574 "command that reads files, filenames, directories or anything else from a "
2575 "disk image). An attacker could manipulate the data to fool your program "
2576 "into doing the wrong thing. Consider cases such as:"
2581 #: ../src/guestfs.pod:1159
2582 msgid "the data (file etc) not being present"
2587 #: ../src/guestfs.pod:1163
2588 msgid "being present but empty"
2593 #: ../src/guestfs.pod:1167
2594 msgid "being much larger than normal"
2599 #: ../src/guestfs.pod:1171
2600 msgid "containing arbitrary 8 bit data"
2605 #: ../src/guestfs.pod:1175
2606 msgid "being in an unexpected character encoding"
2611 #: ../src/guestfs.pod:1179
2612 msgid "containing homoglyphs."
2617 #: ../src/guestfs.pod:1183
2618 msgid "SECURITY OF MOUNTING FILESYSTEMS"
2623 #: ../src/guestfs.pod:1185
2625 "When you mount a filesystem under Linux, mistakes in the kernel filesystem "
2626 "(VFS) module can sometimes be escalated into exploits by deliberately "
2627 "creating a malicious, malformed filesystem. These exploits are very severe "
2628 "for two reasons. Firstly there are very many filesystem drivers in the "
2629 "kernel, and many of them are infrequently used and not much developer "
2630 "attention has been paid to the code. Linux userspace helps potential "
2631 "crackers by detecting the filesystem type and automatically choosing the "
2632 "right VFS driver, even if that filesystem type is obscure or unexpected for "
2633 "the administrator. Secondly, a kernel-level exploit is like a local root "
2634 "exploit (worse in some ways), giving immediate and total access to the "
2635 "system right down to the hardware level."
2640 #: ../src/guestfs.pod:1198
2642 "That explains why you should never mount a filesystem from an untrusted "
2643 "guest on your host kernel. How about libguestfs? We run a Linux kernel "
2644 "inside a qemu virtual machine, usually running as a non-root user. The "
2645 "attacker would need to write a filesystem which first exploited the kernel, "
2646 "and then exploited either qemu virtualization (eg. a faulty qemu driver) or "
2647 "the libguestfs protocol, and finally to be as serious as the host kernel "
2648 "exploit it would need to escalate its privileges to root. This multi-step "
2649 "escalation, performed by a static piece of data, is thought to be extremely "
2650 "hard to do, although we never say 'never' about security issues."
2655 #: ../src/guestfs.pod:1209
2657 "In any case callers can reduce the attack surface by forcing the filesystem "
2658 "type when mounting (use L</guestfs_mount_vfs>)."
2663 #: ../src/guestfs.pod:1212
2664 msgid "PROTOCOL SECURITY"
2669 #: ../src/guestfs.pod:1214
2671 "The protocol is designed to be secure, being based on RFC 4506 (XDR) with a "
2672 "defined upper message size. However a program that uses libguestfs must "
2673 "also take care - for example you can write a program that downloads a binary "
2674 "from a disk image and executes it locally, and no amount of protocol "
2675 "security will save you from the consequences."
2680 #: ../src/guestfs.pod:1220
2681 msgid "INSPECTION SECURITY"
2686 #: ../src/guestfs.pod:1222
2688 "Parts of the inspection API (see L</INSPECTION>) return untrusted strings "
2689 "directly from the guest, and these could contain any 8 bit data. Callers "
2690 "should be careful to escape these before printing them to a structured file "
2691 "(for example, use HTML escaping if creating a web page)."
2696 #: ../src/guestfs.pod:1228
2698 "Guest configuration may be altered in unusual ways by the administrator of "
2699 "the virtual machine, and may not reflect reality (particularly for untrusted "
2700 "or actively malicious guests). For example we parse the hostname from "
2701 "configuration files like C</etc/sysconfig/network> that we find in the "
2702 "guest, but the guest administrator can easily manipulate these files to "
2703 "provide the wrong hostname."
2708 #: ../src/guestfs.pod:1236
2710 "The inspection API parses guest configuration using two external libraries: "
2711 "Augeas (Linux configuration) and hivex (Windows Registry). Both are "
2712 "designed to be robust in the face of malicious data, although denial of "
2713 "service attacks are still possible, for example with oversized configuration "
2719 #: ../src/guestfs.pod:1242
2720 msgid "RUNNING UNTRUSTED GUEST COMMANDS"
2725 #: ../src/guestfs.pod:1244
2727 "Be very cautious about running commands from the guest. By running a "
2728 "command in the guest, you are giving CPU time to a binary that you do not "
2729 "control, under the same user account as the library, albeit wrapped in qemu "
2730 "virtualization. More information and alternatives can be found in the "
2731 "section L</RUNNING COMMANDS>."
2736 #: ../src/guestfs.pod:1250
2737 msgid "CVE-2010-3851"
2742 #: ../src/guestfs.pod:1252
2743 msgid "https://bugzilla.redhat.com/642934"
2748 #: ../src/guestfs.pod:1254
2750 "This security bug concerns the automatic disk format detection that qemu "
2751 "does on disk images."
2756 #: ../src/guestfs.pod:1257
2758 "A raw disk image is just the raw bytes, there is no header. Other disk "
2759 "images like qcow2 contain a special header. Qemu deals with this by looking "
2760 "for one of the known headers, and if none is found then assuming the disk "
2761 "image must be raw."
2766 #: ../src/guestfs.pod:1262
2768 "This allows a guest which has been given a raw disk image to write some "
2769 "other header. At next boot (or when the disk image is accessed by "
2770 "libguestfs) qemu would do autodetection and think the disk image format was, "
2771 "say, qcow2 based on the header written by the guest."
2776 #: ../src/guestfs.pod:1267
2778 "This in itself would not be a problem, but qcow2 offers many features, one "
2779 "of which is to allow a disk image to refer to another image (called the "
2780 "\"backing disk\"). It does this by placing the path to the backing disk "
2781 "into the qcow2 header. This path is not validated and could point to any "
2782 "host file (eg. \"/etc/passwd\"). The backing disk is then exposed through "
2783 "\"holes\" in the qcow2 disk image, which of course is completely under the "
2784 "control of the attacker."
2789 #: ../src/guestfs.pod:1275
2791 "In libguestfs this is rather hard to exploit except under two circumstances:"
2796 #: ../src/guestfs.pod:1282
2797 msgid "You have enabled the network or have opened the disk in write mode."
2802 #: ../src/guestfs.pod:1286
2804 "You are also running untrusted code from the guest (see L</RUNNING "
2810 #: ../src/guestfs.pod:1291
2812 "The way to avoid this is to specify the expected disk format when adding "
2813 "disks (the optional C<format> option to L</guestfs_add_drive_opts>). You "
2814 "should always do this if the disk is raw format, and it's a good idea for "
2820 #: ../src/guestfs.pod:1296
2822 "For disks added from libvirt using calls like L</guestfs_add_domain>, the "
2823 "format is fetched from libvirt and passed through."
2828 #: ../src/guestfs.pod:1299
2830 "For libguestfs tools, use the I<--format> command line parameter as "
2836 #: ../src/guestfs.pod:1302
2837 msgid "CONNECTION MANAGEMENT"
2842 #: ../src/guestfs.pod:1304
2848 #: ../src/guestfs.pod:1306
2850 "C<guestfs_h> is the opaque type representing a connection handle. Create a "
2851 "handle by calling L</guestfs_create>. Call L</guestfs_close> to free the "
2852 "handle and release all resources used."
2857 #: ../src/guestfs.pod:1310
2859 "For information on using multiple handles and threads, see the section L</"
2860 "MULTIPLE HANDLES AND MULTIPLE THREADS> below."
2865 #: ../src/guestfs.pod:1313
2866 msgid "guestfs_create"
2871 #: ../src/guestfs.pod:1315
2874 " guestfs_h *guestfs_create (void);\n"
2880 #: ../src/guestfs.pod:1317
2881 msgid "Create a connection handle."
2886 #: ../src/guestfs.pod:1319
2888 "You have to call L</guestfs_add_drive_opts> (or one of the equivalent calls) "
2889 "on the handle at least once."
2894 #: ../src/guestfs.pod:1322
2896 "This function returns a non-NULL pointer to a handle on success or NULL on "
2902 #: ../src/guestfs.pod:1325
2903 msgid "After configuring the handle, you have to call L</guestfs_launch>."
2908 #: ../src/guestfs.pod:1327
2910 "You may also want to configure error handling for the handle. See L</ERROR "
2911 "HANDLING> section below."
2916 #: ../src/guestfs.pod:1330
2917 msgid "guestfs_close"
2922 #: ../src/guestfs.pod:1332
2925 " void guestfs_close (guestfs_h *g);\n"
2931 #: ../src/guestfs.pod:1334
2932 msgid "This closes the connection handle and frees up all resources used."
2937 #: ../src/guestfs.pod:1336
2938 msgid "ERROR HANDLING"
2943 #: ../src/guestfs.pod:1338
2945 "API functions can return errors. For example, almost all functions that "
2946 "return C<int> will return C<-1> to indicate an error."
2951 #: ../src/guestfs.pod:1341
2953 "Additional information is available for errors: an error message string and "
2954 "optionally an error number (errno) if the thing that failed was a system "
2960 #: ../src/guestfs.pod:1345
2962 "You can get at the additional information about the last error on the handle "
2963 "by calling L</guestfs_last_error>, L</guestfs_last_errno>, and/or by setting "
2964 "up an error handler with L</guestfs_set_error_handler>."
2969 #: ../src/guestfs.pod:1350
2971 "When the handle is created, a default error handler is installed which "
2972 "prints the error message string to C<stderr>. For small short-running "
2973 "command line programs it is sufficient to do:"
2978 #: ../src/guestfs.pod:1354
2981 " if (guestfs_launch (g) == -1)\n"
2982 " exit (EXIT_FAILURE);\n"
2988 #: ../src/guestfs.pod:1357
2990 "since the default error handler will ensure that an error message has been "
2991 "printed to C<stderr> before the program exits."
2996 #: ../src/guestfs.pod:1360
2998 "For other programs the caller will almost certainly want to install an "
2999 "alternate error handler or do error handling in-line like this:"
3004 #: ../src/guestfs.pod:1363
3007 " g = guestfs_create ();\n"
3013 #: ../src/guestfs.pod:1365
3016 " /* This disables the default behaviour of printing errors\n"
3018 " guestfs_set_error_handler (g, NULL, NULL);\n"
3024 #: ../src/guestfs.pod:1369
3027 " if (guestfs_launch (g) == -1) {\n"
3028 " /* Examine the error message and print it etc. */\n"
3029 " char *msg = guestfs_last_error (g);\n"
3030 " int errnum = guestfs_last_errno (g);\n"
3031 " fprintf (stderr, \"%s\\n\", msg);\n"
3039 #: ../src/guestfs.pod:1377
3041 "Out of memory errors are handled differently. The default action is to call "
3042 "L<abort(3)>. If this is undesirable, then you can set a handler using L</"
3043 "guestfs_set_out_of_memory_handler>."
3048 #: ../src/guestfs.pod:1381
3050 "L</guestfs_create> returns C<NULL> if the handle cannot be created, and "
3051 "because there is no handle if this happens there is no way to get additional "
3052 "error information. However L</guestfs_create> is supposed to be a "
3053 "lightweight operation which can only fail because of insufficient memory (it "
3054 "returns NULL in this case)."
3059 #: ../src/guestfs.pod:1387
3060 msgid "guestfs_last_error"
3065 #: ../src/guestfs.pod:1389
3068 " const char *guestfs_last_error (guestfs_h *g);\n"
3074 #: ../src/guestfs.pod:1391
3076 "This returns the last error message that happened on C<g>. If there has not "
3077 "been an error since the handle was created, then this returns C<NULL>."
3082 #: ../src/guestfs.pod:1395
3084 "The lifetime of the returned string is until the next error occurs, or L</"
3085 "guestfs_close> is called."
3090 #: ../src/guestfs.pod:1398
3091 msgid "guestfs_last_errno"
3096 #: ../src/guestfs.pod:1400
3099 " int guestfs_last_errno (guestfs_h *g);\n"
3105 #: ../src/guestfs.pod:1402
3106 msgid "This returns the last error number (errno) that happened on C<g>."
3111 #: ../src/guestfs.pod:1404
3112 msgid "If successful, an errno integer not equal to zero is returned."
3117 #: ../src/guestfs.pod:1406
3119 "If no error, this returns 0. This call can return 0 in three situations:"
3124 #: ../src/guestfs.pod:1413
3125 msgid "There has not been any error on the handle."
3130 #: ../src/guestfs.pod:1417
3132 "There has been an error but the errno was meaningless. This corresponds to "
3133 "the case where the error did not come from a failed system call, but for "
3134 "some other reason."
3139 #: ../src/guestfs.pod:1423
3141 "There was an error from a failed system call, but for some reason the errno "
3142 "was not captured and returned. This usually indicates a bug in libguestfs."
3147 #: ../src/guestfs.pod:1429
3149 "Libguestfs tries to convert the errno from inside the applicance into a "
3150 "corresponding errno for the caller (not entirely trivial: the appliance "
3151 "might be running a completely different operating system from the library "
3152 "and error numbers are not standardized across Un*xen). If this could not be "
3153 "done, then the error is translated to C<EINVAL>. In practice this should "
3154 "only happen in very rare circumstances."
3159 #: ../src/guestfs.pod:1437
3160 msgid "guestfs_set_error_handler"
3165 #: ../src/guestfs.pod:1439
3168 " typedef void (*guestfs_error_handler_cb) (guestfs_h *g,\n"
3170 " const char *msg);\n"
3171 " void guestfs_set_error_handler (guestfs_h *g,\n"
3172 " guestfs_error_handler_cb cb,\n"
3179 #: ../src/guestfs.pod:1446
3181 "The callback C<cb> will be called if there is an error. The parameters "
3182 "passed to the callback are an opaque data pointer and the error message "
3188 #: ../src/guestfs.pod:1450
3190 "C<errno> is not passed to the callback. To get that the callback must call "
3191 "L</guestfs_last_errno>."
3196 #: ../src/guestfs.pod:1453
3198 "Note that the message string C<msg> is freed as soon as the callback "
3199 "function returns, so if you want to stash it somewhere you must make your "
3205 #: ../src/guestfs.pod:1457
3206 msgid "The default handler prints messages on C<stderr>."
3211 #: ../src/guestfs.pod:1459
3212 msgid "If you set C<cb> to C<NULL> then I<no> handler is called."
3217 #: ../src/guestfs.pod:1461
3218 msgid "guestfs_get_error_handler"
3223 #: ../src/guestfs.pod:1463
3226 " guestfs_error_handler_cb guestfs_get_error_handler (guestfs_h *g,\n"
3227 " void **opaque_rtn);\n"
3233 #: ../src/guestfs.pod:1466
3234 msgid "Returns the current error handler callback."
3239 #: ../src/guestfs.pod:1468
3240 msgid "guestfs_set_out_of_memory_handler"
3245 #: ../src/guestfs.pod:1470
3248 " typedef void (*guestfs_abort_cb) (void);\n"
3249 " int guestfs_set_out_of_memory_handler (guestfs_h *g,\n"
3250 " guestfs_abort_cb);\n"
3256 #: ../src/guestfs.pod:1474
3258 "The callback C<cb> will be called if there is an out of memory situation. "
3259 "I<Note this callback must not return>."
3264 #: ../src/guestfs.pod:1477
3265 msgid "The default is to call L<abort(3)>."
3270 #: ../src/guestfs.pod:1479
3272 "You cannot set C<cb> to C<NULL>. You can't ignore out of memory situations."
3277 #: ../src/guestfs.pod:1482
3278 msgid "guestfs_get_out_of_memory_handler"
3283 #: ../src/guestfs.pod:1484
3286 " guestfs_abort_fn guestfs_get_out_of_memory_handler (guestfs_h *g);\n"
3292 #: ../src/guestfs.pod:1486
3293 msgid "This returns the current out of memory handler."
3298 #: ../src/guestfs.pod:1488
3304 #: ../src/guestfs.pod:1490 ../fish/guestfish.pod:1008
3310 #: ../src/guestfs.pod:1492
3316 #: ../src/guestfs.pod:1494
3322 #: ../src/guestfs.pod:1496
3323 msgid "AVAILABILITY"
3328 #: ../src/guestfs.pod:1498
3329 msgid "GROUPS OF FUNCTIONALITY IN THE APPLIANCE"
3334 #: ../src/guestfs.pod:1500
3336 "Using L</guestfs_available> you can test availability of the following "
3337 "groups of functions. This test queries the appliance to see if the "
3338 "appliance you are currently using supports the functionality."
3343 #: ../src/guestfs.pod:1505
3344 msgid "@AVAILABILITY@"
3349 #: ../src/guestfs.pod:1507
3350 msgid "GUESTFISH supported COMMAND"
3355 #: ../src/guestfs.pod:1509
3357 "In L<guestfish(3)> there is a handy interactive command C<supported> which "
3358 "prints out the available groups and whether they are supported by this build "
3359 "of libguestfs. Note however that you have to do C<run> first."
3364 #: ../src/guestfs.pod:1514
3365 msgid "SINGLE CALLS AT COMPILE TIME"
3370 #: ../src/guestfs.pod:1516
3372 "Since version 1.5.8, C<E<lt>guestfs.hE<gt>> defines symbols for each C API "
3373 "function, such as:"
3378 #: ../src/guestfs.pod:1519
3381 " #define LIBGUESTFS_HAVE_DD 1\n"
3387 #: ../src/guestfs.pod:1521
3388 msgid "if L</guestfs_dd> is available."
3393 #: ../src/guestfs.pod:1523
3395 "Before version 1.5.8, if you needed to test whether a single libguestfs "
3396 "function is available at compile time, we recommended using build tools such "
3397 "as autoconf or cmake. For example in autotools you could use:"
3402 #: ../src/guestfs.pod:1528
3405 " AC_CHECK_LIB([guestfs],[guestfs_create])\n"
3406 " AC_CHECK_FUNCS([guestfs_dd])\n"
3412 #: ../src/guestfs.pod:1531
3414 "which would result in C<HAVE_GUESTFS_DD> being either defined or not defined "
3420 #: ../src/guestfs.pod:1534
3421 msgid "SINGLE CALLS AT RUN TIME"
3426 #: ../src/guestfs.pod:1536
3428 "Testing at compile time doesn't guarantee that a function really exists in "
3429 "the library. The reason is that you might be dynamically linked against a "
3430 "previous I<libguestfs.so> (dynamic library) which doesn't have the call. "
3431 "This situation unfortunately results in a segmentation fault, which is a "
3432 "shortcoming of the C dynamic linking system itself."
3437 #: ../src/guestfs.pod:1543
3439 "You can use L<dlopen(3)> to test if a function is available at run time, as "
3440 "in this example program (note that you still need the compile time check as "
3446 #: ../src/guestfs.pod:1547
3449 " #include <stdio.h>\n"
3450 " #include <stdlib.h>\n"
3451 " #include <unistd.h>\n"
3452 " #include <dlfcn.h>\n"
3453 " #include <guestfs.h>\n"
3459 #: ../src/guestfs.pod:1553
3464 " #ifdef LIBGUESTFS_HAVE_DD\n"
3466 " int has_function;\n"
3472 #: ../src/guestfs.pod:1559
3475 " /* Test if the function guestfs_dd is really available. */\n"
3476 " dl = dlopen (NULL, RTLD_LAZY);\n"
3478 " fprintf (stderr, \"dlopen: %s\\n\", dlerror ());\n"
3479 " exit (EXIT_FAILURE);\n"
3481 " has_function = dlsym (dl, \"guestfs_dd\") != NULL;\n"
3488 #: ../src/guestfs.pod:1568
3491 " if (!has_function)\n"
3492 " printf (\"this libguestfs.so does NOT have guestfs_dd function\\n\");\n"
3494 " printf (\"this libguestfs.so has guestfs_dd function\\n\");\n"
3495 " /* Now it's safe to call\n"
3496 " guestfs_dd (g, \"foo\", \"bar\");\n"
3500 " printf (\"guestfs_dd function was not found at compile time\\n\");\n"
3508 #: ../src/guestfs.pod:1581
3510 "You may think the above is an awful lot of hassle, and it is. There are "
3511 "other ways outside of the C linking system to ensure that this kind of "
3512 "incompatibility never arises, such as using package versioning:"
3517 #: ../src/guestfs.pod:1586
3520 " Requires: libguestfs >= 1.0.80\n"
3526 #: ../src/guestfs.pod:1588
3527 msgid "CALLS WITH OPTIONAL ARGUMENTS"
3532 #: ../src/guestfs.pod:1590
3534 "A recent feature of the API is the introduction of calls which take optional "
3535 "arguments. In C these are declared 3 ways. The main way is as a call which "
3536 "takes variable arguments (ie. C<...>), as in this example:"
3541 #: ../src/guestfs.pod:1595
3544 " int guestfs_add_drive_opts (guestfs_h *g, const char *filename, ...);\n"
3550 #: ../src/guestfs.pod:1597
3552 "Call this with a list of optional arguments, terminated by C<-1>. So to "
3553 "call with no optional arguments specified:"
3558 #: ../src/guestfs.pod:1600
3561 " guestfs_add_drive_opts (g, filename, -1);\n"
3567 #: ../src/guestfs.pod:1602
3568 msgid "With a single optional argument:"
3573 #: ../src/guestfs.pod:1604
3576 " guestfs_add_drive_opts (g, filename,\n"
3577 " GUESTFS_ADD_DRIVE_OPTS_FORMAT, \"qcow2\",\n"
3584 #: ../src/guestfs.pod:1608
3590 #: ../src/guestfs.pod:1610
3593 " guestfs_add_drive_opts (g, filename,\n"
3594 " GUESTFS_ADD_DRIVE_OPTS_FORMAT, \"qcow2\",\n"
3595 " GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,\n"
3602 #: ../src/guestfs.pod:1615
3604 "and so forth. Don't forget the terminating C<-1> otherwise Bad Things will "
3610 #: ../src/guestfs.pod:1618
3611 msgid "USING va_list FOR OPTIONAL ARGUMENTS"
3616 #: ../src/guestfs.pod:1620
3618 "The second variant has the same name with the suffix C<_va>, which works the "
3619 "same way but takes a C<va_list>. See the C manual for details. For the "
3620 "example function, this is declared:"
3625 #: ../src/guestfs.pod:1624
3628 " int guestfs_add_drive_opts_va (guestfs_h *g, const char *filename,\n"
3635 #: ../src/guestfs.pod:1627
3636 msgid "CONSTRUCTING OPTIONAL ARGUMENTS"
3641 #: ../src/guestfs.pod:1629
3643 "The third variant is useful where you need to construct these calls. You "
3644 "pass in a structure where you fill in the optional fields. The structure "
3645 "has a bitmask as the first element which you must set to indicate which "
3646 "fields you have filled in. For our example function the structure and call "
3652 #: ../src/guestfs.pod:1635
3655 " struct guestfs_add_drive_opts_argv {\n"
3656 " uint64_t bitmask;\n"
3658 " const char *format;\n"
3661 " int guestfs_add_drive_opts_argv (guestfs_h *g, const char *filename,\n"
3662 " const struct guestfs_add_drive_opts_argv *optargs);\n"
3668 #: ../src/guestfs.pod:1644
3669 msgid "You could call it like this:"
3674 #: ../src/guestfs.pod:1646
3677 " struct guestfs_add_drive_opts_argv optargs = {\n"
3678 " .bitmask = GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK |\n"
3679 " GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK,\n"
3681 " .format = \"qcow2\"\n"
3688 #: ../src/guestfs.pod:1653
3691 " guestfs_add_drive_opts_argv (g, filename, &optargs);\n"
3697 #: ../src/guestfs.pod:1655 ../src/guestfs-actions.pod:11
3698 #: ../src/guestfs-actions.pod:1855 ../fish/guestfish-actions.pod:9
3699 #: ../fish/guestfish-actions.pod:1260 ../tools/virt-win-reg.pl:532
3705 #: ../src/guestfs.pod:1661
3706 msgid "The C<_BITMASK> suffix on each option name when specifying the bitmask."
3711 #: ../src/guestfs.pod:1666
3712 msgid "You do not need to fill in all fields of the structure."
3717 #: ../src/guestfs.pod:1670
3719 "There must be a one-to-one correspondence between fields of the structure "
3720 "that are filled in, and bits set in the bitmask."
3725 #: ../src/guestfs.pod:1675
3726 msgid "OPTIONAL ARGUMENTS IN OTHER LANGUAGES"
3731 #: ../src/guestfs.pod:1677
3733 "In other languages, optional arguments are expressed in the way that is "
3734 "natural for that language. We refer you to the language-specific "
3735 "documentation for more details on that."
3740 #: ../src/guestfs.pod:1681
3741 msgid "For guestfish, see L<guestfish(1)/OPTIONAL ARGUMENTS>."
3746 #: ../src/guestfs.pod:1683
3747 msgid "SETTING CALLBACKS TO HANDLE EVENTS"
3751 #: ../src/guestfs.pod:1685
3753 "B<Note:> This section documents the generic event mechanism introduced in "
3754 "libguestfs 1.10, which you should use in new code if possible. The old "
3755 "functions C<guestfs_set_log_message_callback>, "
3756 "C<guestfs_set_subprocess_quit_callback>, "
3757 "C<guestfs_set_launch_done_callback>, C<guestfs_set_close_callback> and "
3758 "C<guestfs_set_progress_callback> are no longer documented in this manual "
3763 #: ../src/guestfs.pod:1693
3765 "Handles generate events when certain things happen, such as log messages "
3766 "being generated, progress messages during long-running operations, or the "
3767 "handle being closed. The API calls described below let you register a "
3768 "callback to be called when events happen. You can register multiple "
3769 "callbacks (for the same, different or overlapping sets of events), and "
3770 "individually remove callbacks. If callbacks are not removed, then they "
3771 "remain in force until the handle is closed."
3775 #: ../src/guestfs.pod:1701
3777 "In the current implementation, events are only generated synchronously: that "
3778 "means that events (and hence callbacks) can only happen while you are in the "
3779 "middle of making another libguestfs call. The callback is called in the "
3784 #: ../src/guestfs.pod:1706
3786 "Events may contain a payload, usually nothing (void), an array of 64 bit "
3787 "unsigned integers, or a message buffer. Payloads are discussed later on."
3791 #: ../src/guestfs.pod:1710
3792 msgid "CLASSES OF EVENTS"
3796 #: ../src/guestfs.pod:1714
3797 msgid "GUESTFS_EVENT_CLOSE (payload type: void)"
3801 #: ../src/guestfs.pod:1717
3803 "The callback function will be called while the handle is being closed "
3804 "(synchronously from L</guestfs_close>)."
3809 #: ../src/guestfs.pod:1720
3811 "Note that libguestfs installs an L<atexit(3)> handler to try to clean up "
3812 "handles that are open when the program exits. This means that this callback "
3813 "might be called indirectly from L<exit(3)>, which can cause unexpected "
3814 "problems in higher-level languages (eg. if your HLL interpreter has already "
3815 "been cleaned up by the time this is called, and if your callback then jumps "
3816 "into some HLL function)."
3820 #: ../src/guestfs.pod:1727
3822 "If no callback is registered: the handle is closed without any callback "
3827 #: ../src/guestfs.pod:1730
3828 msgid "GUESTFS_EVENT_SUBPROCESS_QUIT (payload type: void)"
3832 #: ../src/guestfs.pod:1733
3834 "The callback function will be called when the child process quits, either "
3835 "asynchronously or if killed by L</guestfs_kill_subprocess>. (This "
3836 "corresponds to a transition from any state to the CONFIG state)."
3840 #: ../src/guestfs.pod:1737 ../src/guestfs.pod:1746
3841 msgid "If no callback is registered: the event is ignored."
3845 #: ../src/guestfs.pod:1739
3846 msgid "GUESTFS_EVENT_LAUNCH_DONE (payload type: void)"
3850 #: ../src/guestfs.pod:1742
3852 "The callback function will be called when the child process becomes ready "
3853 "first time after it has been launched. (This corresponds to a transition "
3854 "from LAUNCHING to the READY state)."
3858 #: ../src/guestfs.pod:1748
3859 msgid "GUESTFS_EVENT_PROGRESS (payload type: array of 4 x uint64_t)"
3864 #: ../src/guestfs.pod:1751
3866 "Some long-running operations can generate progress messages. If this "
3867 "callback is registered, then it will be called each time a progress message "
3868 "is generated (usually two seconds after the operation started, and three "
3869 "times per second thereafter until it completes, although the frequency may "
3870 "change in future versions)."
3874 #: ../src/guestfs.pod:1757
3876 "The callback receives in the payload four unsigned 64 bit numbers which are "
3877 "(in order): C<proc_nr>, C<serial>, C<position>, C<total>."
3881 #: ../src/guestfs.pod:1760
3883 "The units of C<total> are not defined, although for some operations C<total> "
3884 "may relate in some way to the amount of data to be transferred (eg. in bytes "
3885 "or megabytes), and C<position> may be the portion which has been transferred."
3890 #: ../src/guestfs.pod:1765
3891 msgid "The only defined and stable parts of the API are:"
3896 #: ../src/guestfs.pod:1771
3898 "The callback can display to the user some type of progress bar or indicator "
3899 "which shows the ratio of C<position>:C<total>."
3904 #: ../src/guestfs.pod:1776
3905 msgid "0 E<lt>= C<position> E<lt>= C<total>"
3909 #: ../src/guestfs.pod:1780
3911 "If any progress notification is sent during a call, then a final progress "
3912 "notification is always sent when C<position> = C<total> (I<unless> the call "
3913 "fails with an error)."
3918 #: ../src/guestfs.pod:1784
3920 "This is to simplify caller code, so callers can easily set the progress "
3921 "indicator to \"100%\" at the end of the operation, without requiring special "
3922 "code to detect this case."
3926 #: ../src/guestfs.pod:1790
3928 "For some calls we are unable to estimate the progress of the call, but we "
3929 "can still generate progress messages to indicate activity. This is known as "
3930 "\"pulse mode\", and is directly supported by certain progress bar "
3931 "implementations (eg. GtkProgressBar)."
3935 #: ../src/guestfs.pod:1795
3937 "For these calls, zero or more progress messages are generated with "
3938 "C<position = 0> and C<total = 1>, followed by a final message with "
3939 "C<position = total = 1>."
3943 #: ../src/guestfs.pod:1799
3945 "As noted above, if the call fails with an error then the final message may "
3950 #: ../src/guestfs.pod:1804
3952 "The callback also receives the procedure number (C<proc_nr>) and serial "
3953 "number (C<serial>) of the call. These are only useful for debugging "
3954 "protocol issues, and the callback can normally ignore them. The callback "
3955 "may want to print these numbers in error messages or debugging messages."
3959 #: ../src/guestfs.pod:1810
3960 msgid "If no callback is registered: progress messages are discarded."
3964 #: ../src/guestfs.pod:1812
3965 msgid "GUESTFS_EVENT_APPLIANCE (payload type: message buffer)"
3969 #: ../src/guestfs.pod:1815
3971 "The callback function is called whenever a log message is generated by qemu, "
3972 "the appliance kernel, guestfsd (daemon), or utility programs."
3976 #: ../src/guestfs.pod:1818
3978 "If the verbose flag (L</guestfs_set_verbose>) is set before launch (L</"
3979 "guestfs_launch>) then additional debug messages are generated."
3983 #: ../src/guestfs.pod:1821 ../src/guestfs.pod:1835
3985 "If no callback is registered: the messages are discarded unless the verbose "
3986 "flag is set in which case they are sent to stderr. You can override the "
3987 "printing of verbose messages to stderr by setting up a callback."
3991 #: ../src/guestfs.pod:1826
3992 msgid "GUESTFS_EVENT_LIBRARY (payload type: message buffer)"
3996 #: ../src/guestfs.pod:1829
3998 "The callback function is called whenever a log message is generated by the "
3999 "library part of libguestfs."
4003 #: ../src/guestfs.pod:1832
4005 "If the verbose flag (L</guestfs_set_verbose>) is set then additional debug "
4006 "messages are generated."
4010 #: ../src/guestfs.pod:1840
4011 msgid "GUESTFS_EVENT_TRACE (payload type: message buffer)"
4015 #: ../src/guestfs.pod:1843
4017 "The callback function is called whenever a trace message is generated. This "
4018 "only applies if the trace flag (L</guestfs_set_trace>) is set."
4022 #: ../src/guestfs.pod:1846
4024 "If no callback is registered: the messages are sent to stderr. You can "
4025 "override the printing of trace messages to stderr by setting up a callback."
4029 #: ../src/guestfs.pod:1852
4030 msgid "guestfs_set_event_callback"
4034 #: ../src/guestfs.pod:1854
4037 " int guestfs_set_event_callback (guestfs_h *g,\n"
4038 " guestfs_event_callback cb,\n"
4039 " uint64_t event_bitmask,\n"
4046 #: ../src/guestfs.pod:1860
4048 "This function registers a callback (C<cb>) for all event classes in the "
4053 #: ../src/guestfs.pod:1863
4055 "For example, to register for all log message events, you could call this "
4056 "function with the bitmask C<GUESTFS_EVENT_APPLIANCE|GUESTFS_EVENT_LIBRARY>. "
4057 "To register a single callback for all possible classes of events, use "
4058 "C<GUESTFS_EVENT_ALL>."
4062 #: ../src/guestfs.pod:1869
4063 msgid "C<flags> should always be passed as 0."
4067 #: ../src/guestfs.pod:1871
4069 "C<opaque> is an opaque pointer which is passed to the callback. You can use "
4070 "it for any purpose."
4074 #: ../src/guestfs.pod:1874
4076 "The return value is the event handle (an integer) which you can use to "
4077 "delete the callback (see below)."
4081 #: ../src/guestfs.pod:1877
4083 "If there is an error, this function returns C<-1>, and sets the error in the "
4084 "handle in the usual way (see L</guestfs_last_error> etc.)"
4088 #: ../src/guestfs.pod:1880
4090 "Callbacks remain in effect until they are deleted, or until the handle is "
4095 #: ../src/guestfs.pod:1883
4097 "In the case where multiple callbacks are registered for a particular event "
4098 "class, all of the callbacks are called. The order in which multiple "
4099 "callbacks are called is not defined."
4103 #: ../src/guestfs.pod:1887
4104 msgid "guestfs_delete_event_callback"
4108 #: ../src/guestfs.pod:1889
4111 " void guestfs_delete_event_callback (guestfs_h *g, int event_handle);\n"
4116 #: ../src/guestfs.pod:1891
4118 "Delete a callback that was previously registered. C<event_handle> should be "
4119 "the integer that was returned by a previous call to "
4120 "C<guestfs_set_event_callback> on the same handle."
4124 #: ../src/guestfs.pod:1895
4125 msgid "guestfs_event_callback"
4129 #: ../src/guestfs.pod:1897
4132 " typedef void (*guestfs_event_callback) (\n"
4135 " uint64_t event,\n"
4136 " int event_handle,\n"
4138 " const char *buf, size_t buf_len,\n"
4139 " const uint64_t *array, size_t array_len);\n"
4144 #: ../src/guestfs.pod:1906
4146 "This is the type of the event callback function that you have to provide."
4150 #: ../src/guestfs.pod:1909
4152 "The basic parameters are: the handle (C<g>), the opaque user pointer "
4153 "(C<opaque>), the event class (eg. C<GUESTFS_EVENT_PROGRESS>), the event "
4154 "handle, and C<flags> which in the current API you should ignore."
4158 #: ../src/guestfs.pod:1913
4160 "The remaining parameters contain the event payload (if any). Each event may "
4161 "contain a payload, which usually relates to the event class, but for future "
4162 "proofing your code should be written to handle any payload for any event "
4167 #: ../src/guestfs.pod:1918
4169 "C<buf> and C<buf_len> contain a message buffer (if C<buf_len == 0>, then "
4170 "there is no message buffer). Note that this message buffer can contain "
4171 "arbitrary 8 bit data, including NUL bytes."
4175 #: ../src/guestfs.pod:1922
4177 "C<array> and C<array_len> is an array of 64 bit unsigned integers. At the "
4178 "moment this is only used for progress messages."
4182 #: ../src/guestfs.pod:1925
4183 msgid "EXAMPLE: CAPTURING LOG MESSAGES"
4187 #: ../src/guestfs.pod:1927
4189 "One motivation for the generic event API was to allow GUI programs to "
4190 "capture debug and other messages. In libguestfs E<le> 1.8 these were sent "
4191 "unconditionally to C<stderr>."
4195 #: ../src/guestfs.pod:1931
4197 "Events associated with log messages are: C<GUESTFS_EVENT_LIBRARY>, "
4198 "C<GUESTFS_EVENT_APPLIANCE> and C<GUESTFS_EVENT_TRACE>. (Note that error "
4199 "messages are not events; you must capture error messages separately)."
4203 #: ../src/guestfs.pod:1936
4205 "Programs have to set up a callback to capture the classes of events of "
4210 #: ../src/guestfs.pod:1939
4214 " guestfs_set_event_callback\n"
4215 " (g, message_callback,\n"
4216 " GUESTFS_EVENT_LIBRARY|GUESTFS_EVENT_APPLIANCE|\n"
4217 " GUESTFS_EVENT_TRACE,\n"
4218 " 0, NULL) == -1)\n"
4219 " if (eh == -1) {\n"
4220 " // handle error in the usual way\n"
4226 #: ../src/guestfs.pod:1949
4228 "The callback can then direct messages to the appropriate place. In this "
4229 "example, messages are directed to syslog:"
4233 #: ../src/guestfs.pod:1952
4237 " message_callback (\n"
4240 " uint64_t event,\n"
4241 " int event_handle,\n"
4243 " const char *buf, size_t buf_len,\n"
4244 " const uint64_t *array, size_t array_len)\n"
4246 " const int priority = LOG_USER|LOG_INFO;\n"
4247 " if (buf_len > 0)\n"
4248 " syslog (priority, \"event 0x%lx: %s\", event, buf);\n"
4255 #: ../src/guestfs.pod:1967
4256 msgid "PRIVATE DATA AREA"
4260 #: ../src/guestfs.pod:1969
4262 "You can attach named pieces of private data to the libguestfs handle, fetch "
4263 "them by name, and walk over them, for the lifetime of the handle. This is "
4264 "called the private data area and is only available from the C API."
4269 #: ../src/guestfs.pod:1974
4270 msgid "To attach a named piece of data, use the following call:"
4275 #: ../src/guestfs.pod:1976
4278 " void guestfs_set_private (guestfs_h *g, const char *key, void *data);\n"
4284 #: ../src/guestfs.pod:1978
4286 "C<key> is the name to associate with this data, and C<data> is an arbitrary "
4287 "pointer (which can be C<NULL>). Any previous item with the same name is "
4293 #: ../src/guestfs.pod:1982
4295 "You can use any C<key> you want, but names beginning with an underscore "
4296 "character are reserved for internal libguestfs purposes (for implementing "
4297 "language bindings). It is recommended to prefix the name with some unique "
4298 "string to avoid collisions with other users."
4303 #: ../src/guestfs.pod:1987
4304 msgid "To retrieve the pointer, use:"
4309 #: ../src/guestfs.pod:1989
4312 " void *guestfs_get_private (guestfs_h *g, const char *key);\n"
4318 #: ../src/guestfs.pod:1991
4320 "This function returns C<NULL> if either no data is found associated with "
4321 "C<key>, or if the user previously set the C<key>'s C<data> pointer to "
4326 #: ../src/guestfs.pod:1995
4328 "Libguestfs does not try to look at or interpret the C<data> pointer in any "
4329 "way. As far as libguestfs is concerned, it need not be a valid pointer at "
4330 "all. In particular, libguestfs does I<not> try to free the data when the "
4331 "handle is closed. If the data must be freed, then the caller must either "
4332 "free it before calling L</guestfs_close> or must set up a close callback to "
4333 "do it (see L</GUESTFS_EVENT_CLOSE>)."
4337 #: ../src/guestfs.pod:2002
4338 msgid "To walk over all entries, use these two functions:"
4342 #: ../src/guestfs.pod:2004
4345 " void *guestfs_first_private (guestfs_h *g, const char **key_rtn);\n"
4350 #: ../src/guestfs.pod:2006
4353 " void *guestfs_next_private (guestfs_h *g, const char **key_rtn);\n"
4358 #: ../src/guestfs.pod:2008
4360 "C<guestfs_first_private> returns the first key, pointer pair (\"first\" does "
4361 "not have any particular meaning -- keys are not returned in any defined "
4362 "order). A pointer to the key is returned in C<*key_rtn> and the "
4363 "corresponding data pointer is returned from the function. C<NULL> is "
4364 "returned if there are no keys stored in the handle."
4368 #: ../src/guestfs.pod:2014
4370 "C<guestfs_next_private> returns the next key, pointer pair. The return "
4371 "value of this function is also C<NULL> is there are no further entries to "
4376 #: ../src/guestfs.pod:2018
4377 msgid "Notes about walking over entries:"
4381 #: ../src/guestfs.pod:2024
4383 "You must not call C<guestfs_set_private> while walking over the entries."
4387 #: ../src/guestfs.pod:2029
4389 "The handle maintains an internal iterator which is reset when you call "
4390 "C<guestfs_first_private>. This internal iterator is invalidated when you "
4391 "call C<guestfs_set_private>."
4395 #: ../src/guestfs.pod:2035
4396 msgid "If you have set the data pointer associated with a key to C<NULL>, ie:"
4400 #: ../src/guestfs.pod:2037
4403 " guestfs_set_private (g, key, NULL);\n"
4408 #: ../src/guestfs.pod:2039
4409 msgid "then that C<key> is not returned when walking."
4413 #: ../src/guestfs.pod:2043
4415 "C<*key_rtn> is only valid until the next call to C<guestfs_first_private>, "
4416 "C<guestfs_next_private> or C<guestfs_set_private>."
4420 #: ../src/guestfs.pod:2049
4422 "The following example code shows how to print all keys and data pointers "
4423 "that are associated with the handle C<g>:"
4427 #: ../src/guestfs.pod:2052
4430 " const char *key;\n"
4431 " void *data = guestfs_first_private (g, &key);\n"
4432 " while (data != NULL)\n"
4434 " printf (\"key = %s, data = %p\\n\", key, data);\n"
4435 " data = guestfs_next_private (g, &key);\n"
4441 #: ../src/guestfs.pod:2060
4443 "More commonly you are only interested in keys that begin with an application-"
4444 "specific prefix C<foo_>. Modify the loop like so:"
4448 #: ../src/guestfs.pod:2063
4451 " const char *key;\n"
4452 " void *data = guestfs_first_private (g, &key);\n"
4453 " while (data != NULL)\n"
4455 " if (strncmp (key, \"foo_\", strlen (\"foo_\")) == 0)\n"
4456 " printf (\"key = %s, data = %p\\n\", key, data);\n"
4457 " data = guestfs_next_private (g, &key);\n"
4463 #: ../src/guestfs.pod:2072
4465 "If you need to modify keys while walking, then you have to jump back to the "
4466 "beginning of the loop. For example, to delete all keys prefixed with "
4471 #: ../src/guestfs.pod:2076
4474 " const char *key;\n"
4477 " data = guestfs_first_private (g, &key);\n"
4478 " while (data != NULL)\n"
4480 " if (strncmp (key, \"foo_\", strlen (\"foo_\")) == 0)\n"
4482 " guestfs_set_private (g, key, NULL);\n"
4483 " /* note that 'key' pointer is now invalid, and so is\n"
4484 " the internal iterator */\n"
4487 " data = guestfs_next_private (g, &key);\n"
4493 #: ../src/guestfs.pod:2092
4495 "Note that the above loop is guaranteed to terminate because the keys are "
4496 "being deleted, but other manipulations of keys within the loop might not "
4497 "terminate unless you also maintain an indication of which keys have been "
4503 #: ../src/guestfs.pod:2097 ../src/guestfs.pod:2102
4509 #: ../src/guestfs.pod:2099
4511 "<!-- old anchor for the next section --> <a name="
4512 "\"state_machine_and_low_level_event_api\"/>"
4517 #: ../src/guestfs.pod:2104
4518 msgid "ARCHITECTURE"
4523 #: ../src/guestfs.pod:2106
4525 "Internally, libguestfs is implemented by running an appliance (a special "
4526 "type of small virtual machine) using L<qemu(1)>. Qemu runs as a child "
4527 "process of the main program."
4532 #: ../src/guestfs.pod:2110
4535 " ___________________\n"
4537 " | main program |\n"
4539 " | | child process / appliance\n"
4540 " | | __________________________\n"
4542 " +-------------------+ RPC | +-----------------+ |\n"
4543 " | libguestfs <--------------------> guestfsd | |\n"
4544 " | | | +-----------------+ |\n"
4545 " \\___________________/ | | Linux kernel | |\n"
4546 " | +--^--------------+ |\n"
4547 " \\_________|________________/\n"
4553 " \\______________/\n"
4559 #: ../src/guestfs.pod:2130
4561 "The library, linked to the main program, creates the child process and hence "
4562 "the appliance in the L</guestfs_launch> function."
4567 #: ../src/guestfs.pod:2133
4569 "Inside the appliance is a Linux kernel and a complete stack of userspace "
4570 "tools (such as LVM and ext2 programs) and a small controlling daemon called "
4571 "L</guestfsd>. The library talks to L</guestfsd> using remote procedure "
4572 "calls (RPC). There is a mostly one-to-one correspondence between libguestfs "
4573 "API calls and RPC calls to the daemon. Lastly the disk image(s) are "
4574 "attached to the qemu process which translates device access by the "
4575 "appliance's Linux kernel into accesses to the image."
4580 #: ../src/guestfs.pod:2142
4582 "A common misunderstanding is that the appliance \"is\" the virtual machine. "
4583 "Although the disk image you are attached to might also be used by some "
4584 "virtual machine, libguestfs doesn't know or care about this. (But you will "
4585 "care if both libguestfs's qemu process and your virtual machine are trying "
4586 "to update the disk image at the same time, since these usually results in "
4587 "massive disk corruption)."
4592 #: ../src/guestfs.pod:2149
4593 msgid "STATE MACHINE"
4598 #: ../src/guestfs.pod:2151
4599 msgid "libguestfs uses a state machine to model the child process:"
4604 #: ../src/guestfs.pod:2153
4616 " / | \\ \\ guestfs_launch\n"
4617 " / | _\\__V______\n"
4619 " / | | LAUNCHING |\n"
4620 " / | \\___________/\n"
4622 " / | guestfs_launch\n"
4624 " ______ / __|____V\n"
4625 " / \\ ------> / \\\n"
4626 " | BUSY | | READY |\n"
4627 " \\______/ <------ \\________/\n"
4633 #: ../src/guestfs.pod:2175
4635 "The normal transitions are (1) CONFIG (when the handle is created, but there "
4636 "is no child process), (2) LAUNCHING (when the child process is booting up), "
4637 "(3) alternating between READY and BUSY as commands are issued to, and "
4638 "carried out by, the child process."
4643 #: ../src/guestfs.pod:2180
4645 "The guest may be killed by L</guestfs_kill_subprocess>, or may die "
4646 "asynchronously at any time (eg. due to some internal error), and that causes "
4647 "the state to transition back to CONFIG."
4652 #: ../src/guestfs.pod:2184
4654 "Configuration commands for qemu such as L</guestfs_add_drive> can only be "
4655 "issued when in the CONFIG state."
4660 #: ../src/guestfs.pod:2187
4662 "The API offers one call that goes from CONFIG through LAUNCHING to READY. "
4663 "L</guestfs_launch> blocks until the child process is READY to accept "
4664 "commands (or until some failure or timeout). L</guestfs_launch> internally "
4665 "moves the state from CONFIG to LAUNCHING while it is running."
4670 #: ../src/guestfs.pod:2193
4672 "API actions such as L</guestfs_mount> can only be issued when in the READY "
4673 "state. These API calls block waiting for the command to be carried out (ie. "
4674 "the state to transition to BUSY and then back to READY). There are no non-"
4675 "blocking versions, and no way to issue more than one command per handle at "
4681 #: ../src/guestfs.pod:2199
4683 "Finally, the child process sends asynchronous messages back to the main "
4684 "program, such as kernel log messages. You can register a callback to "
4685 "receive these messages."
4690 #: ../src/guestfs.pod:2203
4696 #: ../src/guestfs.pod:2205
4697 msgid "COMMUNICATION PROTOCOL"
4702 #: ../src/guestfs.pod:2207
4704 "Don't rely on using this protocol directly. This section documents how it "
4705 "currently works, but it may change at any time."
4710 #: ../src/guestfs.pod:2210
4712 "The protocol used to talk between the library and the daemon running inside "
4713 "the qemu virtual machine is a simple RPC mechanism built on top of XDR (RFC "
4714 "1014, RFC 1832, RFC 4506)."
4719 #: ../src/guestfs.pod:2214
4721 "The detailed format of structures is in C<src/guestfs_protocol.x> (note: "
4722 "this file is automatically generated)."
4727 #: ../src/guestfs.pod:2217
4729 "There are two broad cases, ordinary functions that don't have any C<FileIn> "
4730 "and C<FileOut> parameters, which are handled with very simple request/reply "
4731 "messages. Then there are functions that have any C<FileIn> or C<FileOut> "
4732 "parameters, which use the same request and reply messages, but they may also "
4733 "be followed by files sent using a chunked encoding."
4738 #: ../src/guestfs.pod:2224
4739 msgid "ORDINARY FUNCTIONS (NO FILEIN/FILEOUT PARAMS)"
4744 #: ../src/guestfs.pod:2226
4745 msgid "For ordinary functions, the request message is:"
4750 #: ../src/guestfs.pod:2228
4753 " total length (header + arguments,\n"
4754 " but not including the length word itself)\n"
4755 " struct guestfs_message_header (encoded as XDR)\n"
4756 " struct guestfs_<foo>_args (encoded as XDR)\n"
4762 #: ../src/guestfs.pod:2233
4764 "The total length field allows the daemon to allocate a fixed size buffer "
4765 "into which it slurps the rest of the message. As a result, the total length "
4766 "is limited to C<GUESTFS_MESSAGE_MAX> bytes (currently 4MB), which means the "
4767 "effective size of any request is limited to somewhere under this size."
4772 #: ../src/guestfs.pod:2239
4774 "Note also that many functions don't take any arguments, in which case the "
4775 "C<guestfs_I<foo>_args> is completely omitted."
4780 #: ../src/guestfs.pod:2242
4782 "The header contains the procedure number (C<guestfs_proc>) which is how the "
4783 "receiver knows what type of args structure to expect, or none at all."
4788 #: ../src/guestfs.pod:2246
4790 "For functions that take optional arguments, the optional arguments are "
4791 "encoded in the C<guestfs_I<foo>_args> structure in the same way as ordinary "
4792 "arguments. A bitmask in the header indicates which optional arguments are "
4793 "meaningful. The bitmask is also checked to see if it contains bits set "
4794 "which the daemon does not know about (eg. if more optional arguments were "
4795 "added in a later version of the library), and this causes the call to be "
4801 #: ../src/guestfs.pod:2254
4802 msgid "The reply message for ordinary functions is:"
4807 #: ../src/guestfs.pod:2256
4810 " total length (header + ret,\n"
4811 " but not including the length word itself)\n"
4812 " struct guestfs_message_header (encoded as XDR)\n"
4813 " struct guestfs_<foo>_ret (encoded as XDR)\n"
4819 #: ../src/guestfs.pod:2261
4821 "As above the C<guestfs_I<foo>_ret> structure may be completely omitted for "
4822 "functions that return no formal return values."
4827 #: ../src/guestfs.pod:2264
4829 "As above the total length of the reply is limited to C<GUESTFS_MESSAGE_MAX>."
4834 #: ../src/guestfs.pod:2267
4836 "In the case of an error, a flag is set in the header, and the reply message "
4837 "is slightly changed:"
4842 #: ../src/guestfs.pod:2270
4845 " total length (header + error,\n"
4846 " but not including the length word itself)\n"
4847 " struct guestfs_message_header (encoded as XDR)\n"
4848 " struct guestfs_message_error (encoded as XDR)\n"
4854 #: ../src/guestfs.pod:2275
4856 "The C<guestfs_message_error> structure contains the error message as a "
4862 #: ../src/guestfs.pod:2278
4863 msgid "FUNCTIONS THAT HAVE FILEIN PARAMETERS"
4868 #: ../src/guestfs.pod:2280
4870 "A C<FileIn> parameter indicates that we transfer a file I<into> the guest. "
4871 "The normal request message is sent (see above). However this is followed by "
4872 "a sequence of file chunks."
4877 #: ../src/guestfs.pod:2284
4880 " total length (header + arguments,\n"
4881 " but not including the length word itself,\n"
4882 " and not including the chunks)\n"
4883 " struct guestfs_message_header (encoded as XDR)\n"
4884 " struct guestfs_<foo>_args (encoded as XDR)\n"
4885 " sequence of chunks for FileIn param #0\n"
4886 " sequence of chunks for FileIn param #1 etc.\n"
4892 #: ../src/guestfs.pod:2292
4893 msgid "The \"sequence of chunks\" is:"
4898 #: ../src/guestfs.pod:2294
4901 " length of chunk (not including length word itself)\n"
4902 " struct guestfs_chunk (encoded as XDR)\n"
4903 " length of chunk\n"
4904 " struct guestfs_chunk (encoded as XDR)\n"
4906 " length of chunk\n"
4907 " struct guestfs_chunk (with data.data_len == 0)\n"
4913 #: ../src/guestfs.pod:2302
4915 "The final chunk has the C<data_len> field set to zero. Additionally a flag "
4916 "is set in the final chunk to indicate either successful completion or early "
4922 #: ../src/guestfs.pod:2306
4924 "At time of writing there are no functions that have more than one FileIn "
4925 "parameter. However this is (theoretically) supported, by sending the "
4926 "sequence of chunks for each FileIn parameter one after another (from left to "
4932 #: ../src/guestfs.pod:2311
4934 "Both the library (sender) I<and> the daemon (receiver) may cancel the "
4935 "transfer. The library does this by sending a chunk with a special flag set "
4936 "to indicate cancellation. When the daemon sees this, it cancels the whole "
4937 "RPC, does I<not> send any reply, and goes back to reading the next request."
4942 #: ../src/guestfs.pod:2317
4944 "The daemon may also cancel. It does this by writing a special word "
4945 "C<GUESTFS_CANCEL_FLAG> to the socket. The library listens for this during "
4946 "the transfer, and if it gets it, it will cancel the transfer (it sends a "
4947 "cancel chunk). The special word is chosen so that even if cancellation "
4948 "happens right at the end of the transfer (after the library has finished "
4949 "writing and has started listening for the reply), the \"spurious\" cancel "
4950 "flag will not be confused with the reply message."
4955 #: ../src/guestfs.pod:2326
4957 "This protocol allows the transfer of arbitrary sized files (no 32 bit "
4958 "limit), and also files where the size is not known in advance (eg. from "
4959 "pipes or sockets). However the chunks are rather small "
4960 "(C<GUESTFS_MAX_CHUNK_SIZE>), so that neither the library nor the daemon need "
4961 "to keep much in memory."
4966 #: ../src/guestfs.pod:2332
4967 msgid "FUNCTIONS THAT HAVE FILEOUT PARAMETERS"
4972 #: ../src/guestfs.pod:2334
4974 "The protocol for FileOut parameters is exactly the same as for FileIn "
4975 "parameters, but with the roles of daemon and library reversed."