1 =head2 guestfs_add_cdrom
3 int guestfs_add_cdrom (guestfs_h *handle,
6 This function adds a virtual CD-ROM disk image to the guest.
8 This is equivalent to the qemu parameter C<-cdrom filename>.
10 This function returns 0 on success or -1 on error.
12 =head2 guestfs_add_drive
14 int guestfs_add_drive (guestfs_h *handle,
15 const char *filename);
17 This function adds a virtual machine disk image C<filename> to the
18 guest. The first time you call this function, the disk appears as IDE
19 disk 0 (C</dev/sda>) in the guest, the second time as C</dev/sdb>, and
22 You don't necessarily need to be root when using libguestfs. However
23 you obviously do need sufficient permissions to access the filename
24 for whatever operations you want to perform (ie. read access if you
25 just want to read the image or write access if you want to modify the
28 This is equivalent to the qemu parameter C<-drive file=filename>.
30 This function returns 0 on success or -1 on error.
32 =head2 guestfs_aug_close
34 int guestfs_aug_close (guestfs_h *handle);
36 Close the current Augeas handle and free up any resources
37 used by it. After calling this, you have to call
38 C<guestfs_aug_init> again before you can use any other
41 This function returns 0 on success or -1 on error.
43 =head2 guestfs_aug_defnode
45 struct guestfs_int_bool *guestfs_aug_defnode (guestfs_h *handle,
50 Defines a variable C<name> whose value is the result of
53 If C<expr> evaluates to an empty nodeset, a node is created,
54 equivalent to calling C<guestfs_aug_set> C<expr>, C<value>.
55 C<name> will be the nodeset containing that single node.
57 On success this returns a pair containing the
58 number of nodes in the nodeset, and a boolean flag
59 if a node was created.
61 This function returns a C<struct guestfs_int_bool *>.
62 I<The caller must call C<guestfs_free_int_bool> after use>.
64 =head2 guestfs_aug_defvar
66 int guestfs_aug_defvar (guestfs_h *handle,
70 Defines an Augeas variable C<name> whose value is the result
71 of evaluating C<expr>. If C<expr> is NULL, then C<name> is
74 On success this returns the number of nodes in C<expr>, or
75 C<0> if C<expr> evaluates to something which is not a nodeset.
77 On error this function returns -1.
79 =head2 guestfs_aug_get
81 char *guestfs_aug_get (guestfs_h *handle,
84 Look up the value associated with C<path>. If C<path>
85 matches exactly one node, the C<value> is returned.
87 This function returns a string or NULL on error.
88 I<The caller must free the returned string after use>.
90 =head2 guestfs_aug_init
92 int guestfs_aug_init (guestfs_h *handle,
96 Create a new Augeas handle for editing configuration files.
97 If there was any previous Augeas handle associated with this
98 guestfs session, then it is closed.
100 You must call this before using any other C<guestfs_aug_*>
103 C<root> is the filesystem root. C<root> must not be NULL,
106 The flags are the same as the flags defined in
107 E<lt>augeas.hE<gt>, the logical I<or> of the following
112 =item C<AUG_SAVE_BACKUP> = 1
114 Keep the original file with a C<.augsave> extension.
116 =item C<AUG_SAVE_NEWFILE> = 2
118 Save changes into a file with extension C<.augnew>, and
119 do not overwrite original. Overrides C<AUG_SAVE_BACKUP>.
121 =item C<AUG_TYPE_CHECK> = 4
123 Typecheck lenses (can be expensive).
125 =item C<AUG_NO_STDINC> = 8
127 Do not use standard load path for modules.
129 =item C<AUG_SAVE_NOOP> = 16
131 Make save a no-op, just record what would have been changed.
133 =item C<AUG_NO_LOAD> = 32
135 Do not load the tree in C<guestfs_aug_init>.
139 To close the handle, you can call C<guestfs_aug_close>.
141 To find out more about Augeas, see L<http://augeas.net/>.
143 This function returns 0 on success or -1 on error.
145 =head2 guestfs_aug_insert
147 int guestfs_aug_insert (guestfs_h *handle,
152 Create a new sibling C<label> for C<path>, inserting it into
153 the tree before or after C<path> (depending on the boolean
156 C<path> must match exactly one existing node in the tree, and
157 C<label> must be a label, ie. not contain C</>, C<*> or end
158 with a bracketed index C<[N]>.
160 This function returns 0 on success or -1 on error.
162 =head2 guestfs_aug_load
164 int guestfs_aug_load (guestfs_h *handle);
166 Load files into the tree.
168 See C<aug_load> in the Augeas documentation for the full gory
171 This function returns 0 on success or -1 on error.
173 =head2 guestfs_aug_ls
175 char **guestfs_aug_ls (guestfs_h *handle,
178 This is just a shortcut for listing C<guestfs_aug_match>
179 C<path/*> and sorting the resulting nodes into alphabetical order.
181 This function returns a NULL-terminated array of strings
182 (like L<environ(3)>), or NULL if there was an error.
183 I<The caller must free the strings and the array after use>.
185 =head2 guestfs_aug_match
187 char **guestfs_aug_match (guestfs_h *handle,
190 Returns a list of paths which match the path expression C<path>.
191 The returned paths are sufficiently qualified so that they match
192 exactly one node in the current tree.
194 This function returns a NULL-terminated array of strings
195 (like L<environ(3)>), or NULL if there was an error.
196 I<The caller must free the strings and the array after use>.
198 =head2 guestfs_aug_mv
200 int guestfs_aug_mv (guestfs_h *handle,
204 Move the node C<src> to C<dest>. C<src> must match exactly
205 one node. C<dest> is overwritten if it exists.
207 This function returns 0 on success or -1 on error.
209 =head2 guestfs_aug_rm
211 int guestfs_aug_rm (guestfs_h *handle,
214 Remove C<path> and all of its children.
216 On success this returns the number of entries which were removed.
218 On error this function returns -1.
220 =head2 guestfs_aug_save
222 int guestfs_aug_save (guestfs_h *handle);
224 This writes all pending changes to disk.
226 The flags which were passed to C<guestfs_aug_init> affect exactly
229 This function returns 0 on success or -1 on error.
231 =head2 guestfs_aug_set
233 int guestfs_aug_set (guestfs_h *handle,
237 Set the value associated with C<path> to C<value>.
239 This function returns 0 on success or -1 on error.
243 char *guestfs_cat (guestfs_h *handle,
246 Return the contents of the file named C<path>.
248 Note that this function cannot correctly handle binary files
249 (specifically, files containing C<\0> character which is treated
250 as end of string). For those you need to use the C<guestfs_read_file>
251 function which has a more complex interface.
253 This function returns a string or NULL on error.
254 I<The caller must free the returned string after use>.
256 Because of the message protocol, there is a transfer limit
257 of somewhere between 2MB and 4MB. To transfer large files you should use
262 int guestfs_chmod (guestfs_h *handle,
266 Change the mode (permissions) of C<path> to C<mode>. Only
267 numeric modes are supported.
269 This function returns 0 on success or -1 on error.
273 int guestfs_chown (guestfs_h *handle,
278 Change the file owner to C<owner> and group to C<group>.
280 Only numeric uid and gid are supported. If you want to use
281 names, you will need to locate and parse the password file
282 yourself (Augeas support makes this relatively easy).
284 This function returns 0 on success or -1 on error.
286 =head2 guestfs_config
288 int guestfs_config (guestfs_h *handle,
289 const char *qemuparam,
290 const char *qemuvalue);
292 This can be used to add arbitrary qemu command line parameters
293 of the form C<-param value>. Actually it's not quite arbitrary - we
294 prevent you from setting some parameters which would interfere with
295 parameters that we use.
297 The first character of C<param> string must be a C<-> (dash).
299 C<value> can be NULL.
301 This function returns 0 on success or -1 on error.
303 =head2 guestfs_exists
305 int guestfs_exists (guestfs_h *handle,
308 This returns C<true> if and only if there is a file, directory
309 (or anything) with the given C<path> name.
311 See also C<guestfs_is_file>, C<guestfs_is_dir>, C<guestfs_stat>.
313 This function returns a C truth value on success or -1 on error.
315 =head2 guestfs_get_autosync
317 int guestfs_get_autosync (guestfs_h *handle);
319 Get the autosync flag.
321 This function returns a C truth value on success or -1 on error.
323 =head2 guestfs_get_path
325 const char *guestfs_get_path (guestfs_h *handle);
327 Return the current search path.
329 This is always non-NULL. If it wasn't set already, then this will
330 return the default path.
332 This function returns a string or NULL on error.
333 The string is owned by the guest handle and must I<not> be freed.
335 =head2 guestfs_get_verbose
337 int guestfs_get_verbose (guestfs_h *handle);
339 This returns the verbose messages flag.
341 This function returns a C truth value on success or -1 on error.
343 =head2 guestfs_is_dir
345 int guestfs_is_dir (guestfs_h *handle,
348 This returns C<true> if and only if there is a directory
349 with the given C<path> name. Note that it returns false for
350 other objects like files.
352 See also C<guestfs_stat>.
354 This function returns a C truth value on success or -1 on error.
356 =head2 guestfs_is_file
358 int guestfs_is_file (guestfs_h *handle,
361 This returns C<true> if and only if there is a file
362 with the given C<path> name. Note that it returns false for
363 other objects like directories.
365 See also C<guestfs_stat>.
367 This function returns a C truth value on success or -1 on error.
369 =head2 guestfs_kill_subprocess
371 int guestfs_kill_subprocess (guestfs_h *handle);
373 This kills the qemu subprocess. You should never need to call this.
375 This function returns 0 on success or -1 on error.
377 =head2 guestfs_launch
379 int guestfs_launch (guestfs_h *handle);
381 Internally libguestfs is implemented by running a virtual machine
384 You should call this after configuring the handle
385 (eg. adding drives) but before performing any actions.
387 This function returns 0 on success or -1 on error.
389 =head2 guestfs_list_devices
391 char **guestfs_list_devices (guestfs_h *handle);
393 List all the block devices.
395 The full block device names are returned, eg. C</dev/sda>
397 This function returns a NULL-terminated array of strings
398 (like L<environ(3)>), or NULL if there was an error.
399 I<The caller must free the strings and the array after use>.
401 =head2 guestfs_list_partitions
403 char **guestfs_list_partitions (guestfs_h *handle);
405 List all the partitions detected on all block devices.
407 The full partition device names are returned, eg. C</dev/sda1>
409 This does not return logical volumes. For that you will need to
412 This function returns a NULL-terminated array of strings
413 (like L<environ(3)>), or NULL if there was an error.
414 I<The caller must free the strings and the array after use>.
418 char *guestfs_ll (guestfs_h *handle,
419 const char *directory);
421 List the files in C<directory> (relative to the root directory,
422 there is no cwd) in the format of 'ls -la'.
424 This command is mostly useful for interactive sessions. It
425 is I<not> intended that you try to parse the output string.
427 This function returns a string or NULL on error.
428 I<The caller must free the returned string after use>.
432 char **guestfs_ls (guestfs_h *handle,
433 const char *directory);
435 List the files in C<directory> (relative to the root directory,
436 there is no cwd). The '.' and '..' entries are not returned, but
437 hidden files are shown.
439 This command is mostly useful for interactive sessions. Programs
440 should probably use C<guestfs_readdir> instead.
442 This function returns a NULL-terminated array of strings
443 (like L<environ(3)>), or NULL if there was an error.
444 I<The caller must free the strings and the array after use>.
446 =head2 guestfs_lvcreate
448 int guestfs_lvcreate (guestfs_h *handle,
450 const char *volgroup,
453 This creates an LVM volume group called C<logvol>
454 on the volume group C<volgroup>, with C<size> megabytes.
456 This function returns 0 on success or -1 on error.
458 =head2 guestfs_lvm_remove_all
460 int guestfs_lvm_remove_all (guestfs_h *handle);
462 This command removes all LVM logical volumes, volume groups
463 and physical volumes.
465 This function returns 0 on success or -1 on error.
467 B<This command is dangerous. Without careful use you
468 can easily destroy all your data>.
472 char **guestfs_lvs (guestfs_h *handle);
474 List all the logical volumes detected. This is the equivalent
475 of the L<lvs(8)> command.
477 This returns a list of the logical volume device names
478 (eg. C</dev/VolGroup00/LogVol00>).
480 See also C<guestfs_lvs_full>.
482 This function returns a NULL-terminated array of strings
483 (like L<environ(3)>), or NULL if there was an error.
484 I<The caller must free the strings and the array after use>.
486 =head2 guestfs_lvs_full
488 struct guestfs_lvm_lv_list *guestfs_lvs_full (guestfs_h *handle);
490 List all the logical volumes detected. This is the equivalent
491 of the L<lvs(8)> command. The "full" version includes all fields.
493 This function returns a C<struct guestfs_lvm_lv_list *>.
494 I<The caller must call C<guestfs_free_lvm_lv_list> after use>.
498 int guestfs_mkdir (guestfs_h *handle,
501 Create a directory named C<path>.
503 This function returns 0 on success or -1 on error.
505 =head2 guestfs_mkdir_p
507 int guestfs_mkdir_p (guestfs_h *handle,
510 Create a directory named C<path>, creating any parent directories
511 as necessary. This is like the C<mkdir -p> shell command.
513 This function returns 0 on success or -1 on error.
517 int guestfs_mkfs (guestfs_h *handle,
521 This creates a filesystem on C<device> (usually a partition
522 of LVM logical volume). The filesystem type is C<fstype>, for
525 This function returns 0 on success or -1 on error.
529 int guestfs_mount (guestfs_h *handle,
531 const char *mountpoint);
533 Mount a guest disk at a position in the filesystem. Block devices
534 are named C</dev/sda>, C</dev/sdb> and so on, as they were added to
535 the guest. If those block devices contain partitions, they will have
536 the usual names (eg. C</dev/sda1>). Also LVM C</dev/VG/LV>-style
539 The rules are the same as for L<mount(2)>: A filesystem must
540 first be mounted on C</> before others can be mounted. Other
541 filesystems can only be mounted on directories which already
544 The mounted filesystem is writable, if we have sufficient permissions
545 on the underlying device.
547 The filesystem options C<sync> and C<noatime> are set with this
548 call, in order to improve reliability.
550 This function returns 0 on success or -1 on error.
552 =head2 guestfs_mounts
554 char **guestfs_mounts (guestfs_h *handle);
556 This returns the list of currently mounted filesystems. It returns
557 the list of devices (eg. C</dev/sda1>, C</dev/VG/LV>).
559 Some internal mounts are not shown.
561 This function returns a NULL-terminated array of strings
562 (like L<environ(3)>), or NULL if there was an error.
563 I<The caller must free the strings and the array after use>.
565 =head2 guestfs_pvcreate
567 int guestfs_pvcreate (guestfs_h *handle,
570 This creates an LVM physical volume on the named C<device>,
571 where C<device> should usually be a partition name such
574 This function returns 0 on success or -1 on error.
578 char **guestfs_pvs (guestfs_h *handle);
580 List all the physical volumes detected. This is the equivalent
581 of the L<pvs(8)> command.
583 This returns a list of just the device names that contain
584 PVs (eg. C</dev/sda2>).
586 See also C<guestfs_pvs_full>.
588 This function returns a NULL-terminated array of strings
589 (like L<environ(3)>), or NULL if there was an error.
590 I<The caller must free the strings and the array after use>.
592 =head2 guestfs_pvs_full
594 struct guestfs_lvm_pv_list *guestfs_pvs_full (guestfs_h *handle);
596 List all the physical volumes detected. This is the equivalent
597 of the L<pvs(8)> command. The "full" version includes all fields.
599 This function returns a C<struct guestfs_lvm_pv_list *>.
600 I<The caller must call C<guestfs_free_lvm_pv_list> after use>.
602 =head2 guestfs_read_lines
604 char **guestfs_read_lines (guestfs_h *handle,
607 Return the contents of the file named C<path>.
609 The file contents are returned as a list of lines. Trailing
610 C<LF> and C<CRLF> character sequences are I<not> returned.
612 Note that this function cannot correctly handle binary files
613 (specifically, files containing C<\0> character which is treated
614 as end of line). For those you need to use the C<guestfs_read_file>
615 function which has a more complex interface.
617 This function returns a NULL-terminated array of strings
618 (like L<environ(3)>), or NULL if there was an error.
619 I<The caller must free the strings and the array after use>.
623 int guestfs_rm (guestfs_h *handle,
626 Remove the single file C<path>.
628 This function returns 0 on success or -1 on error.
632 int guestfs_rm_rf (guestfs_h *handle,
635 Remove the file or directory C<path>, recursively removing the
636 contents if its a directory. This is like the C<rm -rf> shell
639 This function returns 0 on success or -1 on error.
643 int guestfs_rmdir (guestfs_h *handle,
646 Remove the single directory C<path>.
648 This function returns 0 on success or -1 on error.
650 =head2 guestfs_set_autosync
652 int guestfs_set_autosync (guestfs_h *handle,
655 If C<autosync> is true, this enables autosync. Libguestfs will make a
656 best effort attempt to run C<guestfs_sync> when the handle is closed
657 (also if the program exits without closing handles).
659 This function returns 0 on success or -1 on error.
661 =head2 guestfs_set_path
663 int guestfs_set_path (guestfs_h *handle,
666 Set the path that libguestfs searches for kernel and initrd.img.
668 The default is C<$libdir/guestfs> unless overridden by setting
669 C<LIBGUESTFS_PATH> environment variable.
671 The string C<path> is stashed in the libguestfs handle, so the caller
672 must make sure it remains valid for the lifetime of the handle.
674 Setting C<path> to C<NULL> restores the default path.
676 This function returns 0 on success or -1 on error.
678 =head2 guestfs_set_verbose
680 int guestfs_set_verbose (guestfs_h *handle,
683 If C<verbose> is true, this turns on verbose messages (to C<stderr>).
685 Verbose messages are disabled unless the environment variable
686 C<LIBGUESTFS_DEBUG> is defined and set to C<1>.
688 This function returns 0 on success or -1 on error.
690 =head2 guestfs_sfdisk
692 int guestfs_sfdisk (guestfs_h *handle,
697 char * const* const lines);
699 This is a direct interface to the L<sfdisk(8)> program for creating
700 partitions on block devices.
702 C<device> should be a block device, for example C</dev/sda>.
704 C<cyls>, C<heads> and C<sectors> are the number of cylinders, heads
705 and sectors on the device, which are passed directly to sfdisk as
706 the I<-C>, I<-H> and I<-S> parameters. If you pass C<0> for any
707 of these, then the corresponding parameter is omitted. Usually for
708 'large' disks, you can just pass C<0> for these, but for small
709 (floppy-sized) disks, sfdisk (or rather, the kernel) cannot work
710 out the right geometry and you will need to tell it.
712 C<lines> is a list of lines that we feed to C<sfdisk>. For more
713 information refer to the L<sfdisk(8)> manpage.
715 To create a single partition occupying the whole disk, you would
716 pass C<lines> as a single element list, when the single element being
717 the string C<,> (comma).
719 This function returns 0 on success or -1 on error.
721 B<This command is dangerous. Without careful use you
722 can easily destroy all your data>.
726 int guestfs_sync (guestfs_h *handle);
728 This syncs the disk, so that any writes are flushed through to the
729 underlying disk image.
731 You should always call this if you have modified a disk image, before
734 This function returns 0 on success or -1 on error.
738 int guestfs_touch (guestfs_h *handle,
741 Touch acts like the L<touch(1)> command. It can be used to
742 update the timestamps on a file, or, if the file does not exist,
743 to create a new zero-length file.
745 This function returns 0 on success or -1 on error.
747 =head2 guestfs_umount
749 int guestfs_umount (guestfs_h *handle,
750 const char *pathordevice);
752 This unmounts the given filesystem. The filesystem may be
753 specified either by its mountpoint (path) or the device which
754 contains the filesystem.
756 This function returns 0 on success or -1 on error.
758 =head2 guestfs_umount_all
760 int guestfs_umount_all (guestfs_h *handle);
762 This unmounts all mounted filesystems.
764 Some internal mounts are not unmounted by this call.
766 This function returns 0 on success or -1 on error.
768 =head2 guestfs_vgcreate
770 int guestfs_vgcreate (guestfs_h *handle,
771 const char *volgroup,
772 char * const* const physvols);
774 This creates an LVM volume group called C<volgroup>
775 from the non-empty list of physical volumes C<physvols>.
777 This function returns 0 on success or -1 on error.
781 char **guestfs_vgs (guestfs_h *handle);
783 List all the volumes groups detected. This is the equivalent
784 of the L<vgs(8)> command.
786 This returns a list of just the volume group names that were
787 detected (eg. C<VolGroup00>).
789 See also C<guestfs_vgs_full>.
791 This function returns a NULL-terminated array of strings
792 (like L<environ(3)>), or NULL if there was an error.
793 I<The caller must free the strings and the array after use>.
795 =head2 guestfs_vgs_full
797 struct guestfs_lvm_vg_list *guestfs_vgs_full (guestfs_h *handle);
799 List all the volumes groups detected. This is the equivalent
800 of the L<vgs(8)> command. The "full" version includes all fields.
802 This function returns a C<struct guestfs_lvm_vg_list *>.
803 I<The caller must call C<guestfs_free_lvm_vg_list> after use>.
805 =head2 guestfs_wait_ready
807 int guestfs_wait_ready (guestfs_h *handle);
809 Internally libguestfs is implemented by running a virtual machine
812 You should call this after C<guestfs_launch> to wait for the launch
815 This function returns 0 on success or -1 on error.
817 =head2 guestfs_write_file
819 int guestfs_write_file (guestfs_h *handle,
824 This call creates a file called C<path>. The contents of the
825 file is the string C<content> (which can contain any 8 bit data),
828 As a special case, if C<size> is C<0>
829 then the length is calculated using C<strlen> (so in this case
830 the content cannot contain embedded ASCII NULs).
832 This function returns 0 on success or -1 on error.
834 Because of the message protocol, there is a transfer limit
835 of somewhere between 2MB and 4MB. To transfer large files you should use