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 or NULL if there was an error.
63 I<The caller must call C<guestfs_free_int_bool> after use>.
65 =head2 guestfs_aug_defvar
67 int guestfs_aug_defvar (guestfs_h *handle,
71 Defines an Augeas variable C<name> whose value is the result
72 of evaluating C<expr>. If C<expr> is NULL, then C<name> is
75 On success this returns the number of nodes in C<expr>, or
76 C<0> if C<expr> evaluates to something which is not a nodeset.
78 On error this function returns -1.
80 =head2 guestfs_aug_get
82 char *guestfs_aug_get (guestfs_h *handle,
85 Look up the value associated with C<path>. If C<path>
86 matches exactly one node, the C<value> is returned.
88 This function returns a string, or NULL on error.
89 I<The caller must free the returned string after use>.
91 =head2 guestfs_aug_init
93 int guestfs_aug_init (guestfs_h *handle,
97 Create a new Augeas handle for editing configuration files.
98 If there was any previous Augeas handle associated with this
99 guestfs session, then it is closed.
101 You must call this before using any other C<guestfs_aug_*>
104 C<root> is the filesystem root. C<root> must not be NULL,
107 The flags are the same as the flags defined in
108 E<lt>augeas.hE<gt>, the logical I<or> of the following
113 =item C<AUG_SAVE_BACKUP> = 1
115 Keep the original file with a C<.augsave> extension.
117 =item C<AUG_SAVE_NEWFILE> = 2
119 Save changes into a file with extension C<.augnew>, and
120 do not overwrite original. Overrides C<AUG_SAVE_BACKUP>.
122 =item C<AUG_TYPE_CHECK> = 4
124 Typecheck lenses (can be expensive).
126 =item C<AUG_NO_STDINC> = 8
128 Do not use standard load path for modules.
130 =item C<AUG_SAVE_NOOP> = 16
132 Make save a no-op, just record what would have been changed.
134 =item C<AUG_NO_LOAD> = 32
136 Do not load the tree in C<guestfs_aug_init>.
140 To close the handle, you can call C<guestfs_aug_close>.
142 To find out more about Augeas, see L<http://augeas.net/>.
144 This function returns 0 on success or -1 on error.
146 =head2 guestfs_aug_insert
148 int guestfs_aug_insert (guestfs_h *handle,
153 Create a new sibling C<label> for C<path>, inserting it into
154 the tree before or after C<path> (depending on the boolean
157 C<path> must match exactly one existing node in the tree, and
158 C<label> must be a label, ie. not contain C</>, C<*> or end
159 with a bracketed index C<[N]>.
161 This function returns 0 on success or -1 on error.
163 =head2 guestfs_aug_load
165 int guestfs_aug_load (guestfs_h *handle);
167 Load files into the tree.
169 See C<aug_load> in the Augeas documentation for the full gory
172 This function returns 0 on success or -1 on error.
174 =head2 guestfs_aug_ls
176 char **guestfs_aug_ls (guestfs_h *handle,
179 This is just a shortcut for listing C<guestfs_aug_match>
180 C<path/*> and sorting the resulting nodes into alphabetical order.
182 This function returns a NULL-terminated array of strings
183 (like L<environ(3)>), or NULL if there was an error.
184 I<The caller must free the strings and the array after use>.
186 =head2 guestfs_aug_match
188 char **guestfs_aug_match (guestfs_h *handle,
191 Returns a list of paths which match the path expression C<path>.
192 The returned paths are sufficiently qualified so that they match
193 exactly one node in the current tree.
195 This function returns a NULL-terminated array of strings
196 (like L<environ(3)>), or NULL if there was an error.
197 I<The caller must free the strings and the array after use>.
199 =head2 guestfs_aug_mv
201 int guestfs_aug_mv (guestfs_h *handle,
205 Move the node C<src> to C<dest>. C<src> must match exactly
206 one node. C<dest> is overwritten if it exists.
208 This function returns 0 on success or -1 on error.
210 =head2 guestfs_aug_rm
212 int guestfs_aug_rm (guestfs_h *handle,
215 Remove C<path> and all of its children.
217 On success this returns the number of entries which were removed.
219 On error this function returns -1.
221 =head2 guestfs_aug_save
223 int guestfs_aug_save (guestfs_h *handle);
225 This writes all pending changes to disk.
227 The flags which were passed to C<guestfs_aug_init> affect exactly
230 This function returns 0 on success or -1 on error.
232 =head2 guestfs_aug_set
234 int guestfs_aug_set (guestfs_h *handle,
238 Set the value associated with C<path> to C<value>.
240 This function returns 0 on success or -1 on error.
242 =head2 guestfs_blockdev_flushbufs
244 int guestfs_blockdev_flushbufs (guestfs_h *handle,
247 This tells the kernel to flush internal buffers associated
250 This uses the L<blockdev(8)> command.
252 This function returns 0 on success or -1 on error.
254 =head2 guestfs_blockdev_getbsz
256 int guestfs_blockdev_getbsz (guestfs_h *handle,
259 This returns the block size of a device.
261 (Note this is different from both I<size in blocks> and
262 I<filesystem block size>).
264 This uses the L<blockdev(8)> command.
266 On error this function returns -1.
268 =head2 guestfs_blockdev_getro
270 int guestfs_blockdev_getro (guestfs_h *handle,
273 Returns a boolean indicating if the block device is read-only
274 (true if read-only, false if not).
276 This uses the L<blockdev(8)> command.
278 This function returns a C truth value on success or -1 on error.
280 =head2 guestfs_blockdev_getsize64
282 int64_t guestfs_blockdev_getsize64 (guestfs_h *handle,
285 This returns the size of the device in bytes.
287 See also C<guestfs_blockdev_getsz>.
289 This uses the L<blockdev(8)> command.
291 On error this function returns -1.
293 =head2 guestfs_blockdev_getss
295 int guestfs_blockdev_getss (guestfs_h *handle,
298 This returns the size of sectors on a block device.
299 Usually 512, but can be larger for modern devices.
301 (Note, this is not the size in sectors, use C<guestfs_blockdev_getsz>
304 This uses the L<blockdev(8)> command.
306 On error this function returns -1.
308 =head2 guestfs_blockdev_getsz
310 int64_t guestfs_blockdev_getsz (guestfs_h *handle,
313 This returns the size of the device in units of 512-byte sectors
314 (even if the sectorsize isn't 512 bytes ... weird).
316 See also C<guestfs_blockdev_getss> for the real sector size of
317 the device, and C<guestfs_blockdev_getsize64> for the more
318 useful I<size in bytes>.
320 This uses the L<blockdev(8)> command.
322 On error this function returns -1.
324 =head2 guestfs_blockdev_rereadpt
326 int guestfs_blockdev_rereadpt (guestfs_h *handle,
329 Reread the partition table on C<device>.
331 This uses the L<blockdev(8)> command.
333 This function returns 0 on success or -1 on error.
335 =head2 guestfs_blockdev_setbsz
337 int guestfs_blockdev_setbsz (guestfs_h *handle,
341 This sets the block size of a device.
343 (Note this is different from both I<size in blocks> and
344 I<filesystem block size>).
346 This uses the L<blockdev(8)> command.
348 This function returns 0 on success or -1 on error.
350 =head2 guestfs_blockdev_setro
352 int guestfs_blockdev_setro (guestfs_h *handle,
355 Sets the block device named C<device> to read-only.
357 This uses the L<blockdev(8)> command.
359 This function returns 0 on success or -1 on error.
361 =head2 guestfs_blockdev_setrw
363 int guestfs_blockdev_setrw (guestfs_h *handle,
366 Sets the block device named C<device> to read-write.
368 This uses the L<blockdev(8)> command.
370 This function returns 0 on success or -1 on error.
374 char *guestfs_cat (guestfs_h *handle,
377 Return the contents of the file named C<path>.
379 Note that this function cannot correctly handle binary files
380 (specifically, files containing C<\0> character which is treated
381 as end of string). For those you need to use the C<guestfs_download>
382 function which has a more complex interface.
384 This function returns a string, or NULL on error.
385 I<The caller must free the returned string after use>.
387 Because of the message protocol, there is a transfer limit
388 of somewhere between 2MB and 4MB. To transfer large files you should use
391 =head2 guestfs_checksum
393 char *guestfs_checksum (guestfs_h *handle,
394 const char *csumtype,
397 This call computes the MD5, SHAx or CRC checksum of the
400 The type of checksum to compute is given by the C<csumtype>
401 parameter which must have one of the following values:
407 Compute the cyclic redundancy check (CRC) specified by POSIX
408 for the C<cksum> command.
412 Compute the MD5 hash (using the C<md5sum> program).
416 Compute the SHA1 hash (using the C<sha1sum> program).
420 Compute the SHA224 hash (using the C<sha224sum> program).
424 Compute the SHA256 hash (using the C<sha256sum> program).
428 Compute the SHA384 hash (using the C<sha384sum> program).
432 Compute the SHA512 hash (using the C<sha512sum> program).
436 The checksum is returned as a printable string.
438 This function returns a string, or NULL on error.
439 I<The caller must free the returned string after use>.
443 int guestfs_chmod (guestfs_h *handle,
447 Change the mode (permissions) of C<path> to C<mode>. Only
448 numeric modes are supported.
450 This function returns 0 on success or -1 on error.
454 int guestfs_chown (guestfs_h *handle,
459 Change the file owner to C<owner> and group to C<group>.
461 Only numeric uid and gid are supported. If you want to use
462 names, you will need to locate and parse the password file
463 yourself (Augeas support makes this relatively easy).
465 This function returns 0 on success or -1 on error.
467 =head2 guestfs_command
469 char *guestfs_command (guestfs_h *handle,
470 char * const* const arguments);
472 This call runs a command from the guest filesystem. The
473 filesystem must be mounted, and must contain a compatible
474 operating system (ie. something Linux, with the same
475 or compatible processor architecture).
477 The single parameter is an argv-style list of arguments.
478 The first element is the name of the program to run.
479 Subsequent elements are parameters. The list must be
480 non-empty (ie. must contain a program name).
482 The C<$PATH> environment variable will contain at least
483 C</usr/bin> and C</bin>. If you require a program from
484 another location, you should provide the full path in the
487 Shared libraries and data files required by the program
488 must be available on filesystems which are mounted in the
489 correct places. It is the caller's responsibility to ensure
490 all filesystems that are needed are mounted at the right
493 This function returns a string, or NULL on error.
494 I<The caller must free the returned string after use>.
496 =head2 guestfs_command_lines
498 char **guestfs_command_lines (guestfs_h *handle,
499 char * const* const arguments);
501 This is the same as C<guestfs_command>, but splits the
502 result into a list of lines.
504 This function returns a NULL-terminated array of strings
505 (like L<environ(3)>), or NULL if there was an error.
506 I<The caller must free the strings and the array after use>.
508 =head2 guestfs_config
510 int guestfs_config (guestfs_h *handle,
511 const char *qemuparam,
512 const char *qemuvalue);
514 This can be used to add arbitrary qemu command line parameters
515 of the form C<-param value>. Actually it's not quite arbitrary - we
516 prevent you from setting some parameters which would interfere with
517 parameters that we use.
519 The first character of C<param> string must be a C<-> (dash).
521 C<value> can be NULL.
523 This function returns 0 on success or -1 on error.
527 char *guestfs_debug (guestfs_h *handle,
529 char * const* const extraargs);
531 The C<guestfs_debug> command exposes some internals of
532 C<guestfsd> (the guestfs daemon) that runs inside the
535 There is no comprehensive help for this command. You have
536 to look at the file C<daemon/debug.c> in the libguestfs source
537 to find out what you can do.
539 This function returns a string, or NULL on error.
540 I<The caller must free the returned string after use>.
542 =head2 guestfs_download
544 int guestfs_download (guestfs_h *handle,
545 const char *remotefilename,
546 const char *filename);
548 Download file C<remotefilename> and save it as C<filename>
549 on the local machine.
551 C<filename> can also be a named pipe.
553 See also C<guestfs_upload>, C<guestfs_cat>.
555 This function returns 0 on success or -1 on error.
557 =head2 guestfs_exists
559 int guestfs_exists (guestfs_h *handle,
562 This returns C<true> if and only if there is a file, directory
563 (or anything) with the given C<path> name.
565 See also C<guestfs_is_file>, C<guestfs_is_dir>, C<guestfs_stat>.
567 This function returns a C truth value on success or -1 on error.
571 char *guestfs_file (guestfs_h *handle,
574 This call uses the standard L<file(1)> command to determine
575 the type or contents of the file. This also works on devices,
576 for example to find out whether a partition contains a filesystem.
578 The exact command which runs is C<file -bsL path>. Note in
579 particular that the filename is not prepended to the output
582 This function returns a string, or NULL on error.
583 I<The caller must free the returned string after use>.
585 =head2 guestfs_get_autosync
587 int guestfs_get_autosync (guestfs_h *handle);
589 Get the autosync flag.
591 This function returns a C truth value on success or -1 on error.
593 =head2 guestfs_get_e2label
595 char *guestfs_get_e2label (guestfs_h *handle,
598 This returns the ext2/3/4 filesystem label of the filesystem on
601 This function returns a string, or NULL on error.
602 I<The caller must free the returned string after use>.
604 =head2 guestfs_get_e2uuid
606 char *guestfs_get_e2uuid (guestfs_h *handle,
609 This returns the ext2/3/4 filesystem UUID of the filesystem on
612 This function returns a string, or NULL on error.
613 I<The caller must free the returned string after use>.
615 =head2 guestfs_get_path
617 const char *guestfs_get_path (guestfs_h *handle);
619 Return the current search path.
621 This is always non-NULL. If it wasn't set already, then this will
622 return the default path.
624 This function returns a string, or NULL on error.
625 The string is owned by the guest handle and must I<not> be freed.
627 =head2 guestfs_get_qemu
629 const char *guestfs_get_qemu (guestfs_h *handle);
631 Return the current qemu binary.
633 This is always non-NULL. If it wasn't set already, then this will
634 return the default qemu binary name.
636 This function returns a string, or NULL on error.
637 The string is owned by the guest handle and must I<not> be freed.
639 =head2 guestfs_get_state
641 int guestfs_get_state (guestfs_h *handle);
643 This returns the current state as an opaque integer. This is
644 only useful for printing debug and internal error messages.
646 For more information on states, see L<guestfs(3)>.
648 On error this function returns -1.
650 =head2 guestfs_get_verbose
652 int guestfs_get_verbose (guestfs_h *handle);
654 This returns the verbose messages flag.
656 This function returns a C truth value on success or -1 on error.
658 =head2 guestfs_is_busy
660 int guestfs_is_busy (guestfs_h *handle);
662 This returns true iff this handle is busy processing a command
663 (in the C<BUSY> state).
665 For more information on states, see L<guestfs(3)>.
667 This function returns a C truth value on success or -1 on error.
669 =head2 guestfs_is_config
671 int guestfs_is_config (guestfs_h *handle);
673 This returns true iff this handle is being configured
674 (in the C<CONFIG> state).
676 For more information on states, see L<guestfs(3)>.
678 This function returns a C truth value on success or -1 on error.
680 =head2 guestfs_is_dir
682 int guestfs_is_dir (guestfs_h *handle,
685 This returns C<true> if and only if there is a directory
686 with the given C<path> name. Note that it returns false for
687 other objects like files.
689 See also C<guestfs_stat>.
691 This function returns a C truth value on success or -1 on error.
693 =head2 guestfs_is_file
695 int guestfs_is_file (guestfs_h *handle,
698 This returns C<true> if and only if there is a file
699 with the given C<path> name. Note that it returns false for
700 other objects like directories.
702 See also C<guestfs_stat>.
704 This function returns a C truth value on success or -1 on error.
706 =head2 guestfs_is_launching
708 int guestfs_is_launching (guestfs_h *handle);
710 This returns true iff this handle is launching the subprocess
711 (in the C<LAUNCHING> state).
713 For more information on states, see L<guestfs(3)>.
715 This function returns a C truth value on success or -1 on error.
717 =head2 guestfs_is_ready
719 int guestfs_is_ready (guestfs_h *handle);
721 This returns true iff this handle is ready to accept commands
722 (in the C<READY> state).
724 For more information on states, see L<guestfs(3)>.
726 This function returns a C truth value on success or -1 on error.
728 =head2 guestfs_kill_subprocess
730 int guestfs_kill_subprocess (guestfs_h *handle);
732 This kills the qemu subprocess. You should never need to call this.
734 This function returns 0 on success or -1 on error.
736 =head2 guestfs_launch
738 int guestfs_launch (guestfs_h *handle);
740 Internally libguestfs is implemented by running a virtual machine
743 You should call this after configuring the handle
744 (eg. adding drives) but before performing any actions.
746 This function returns 0 on success or -1 on error.
748 =head2 guestfs_list_devices
750 char **guestfs_list_devices (guestfs_h *handle);
752 List all the block devices.
754 The full block device names are returned, eg. C</dev/sda>
756 This function returns a NULL-terminated array of strings
757 (like L<environ(3)>), or NULL if there was an error.
758 I<The caller must free the strings and the array after use>.
760 =head2 guestfs_list_partitions
762 char **guestfs_list_partitions (guestfs_h *handle);
764 List all the partitions detected on all block devices.
766 The full partition device names are returned, eg. C</dev/sda1>
768 This does not return logical volumes. For that you will need to
771 This function returns a NULL-terminated array of strings
772 (like L<environ(3)>), or NULL if there was an error.
773 I<The caller must free the strings and the array after use>.
777 char *guestfs_ll (guestfs_h *handle,
778 const char *directory);
780 List the files in C<directory> (relative to the root directory,
781 there is no cwd) in the format of 'ls -la'.
783 This command is mostly useful for interactive sessions. It
784 is I<not> intended that you try to parse the output string.
786 This function returns a string, or NULL on error.
787 I<The caller must free the returned string after use>.
791 char **guestfs_ls (guestfs_h *handle,
792 const char *directory);
794 List the files in C<directory> (relative to the root directory,
795 there is no cwd). The '.' and '..' entries are not returned, but
796 hidden files are shown.
798 This command is mostly useful for interactive sessions. Programs
799 should probably use C<guestfs_readdir> instead.
801 This function returns a NULL-terminated array of strings
802 (like L<environ(3)>), or NULL if there was an error.
803 I<The caller must free the strings and the array after use>.
807 struct guestfs_stat *guestfs_lstat (guestfs_h *handle,
810 Returns file information for the given C<path>.
812 This is the same as C<guestfs_stat> except that if C<path>
813 is a symbolic link, then the link is stat-ed, not the file it
816 This is the same as the C<lstat(2)> system call.
818 This function returns a C<struct guestfs_stat *>
819 (see L<stat(2)> and E<lt>guestfs-structs.hE<gt>),
820 or NULL if there was an error.
821 I<The caller must call C<free> after use>.
823 =head2 guestfs_lvcreate
825 int guestfs_lvcreate (guestfs_h *handle,
827 const char *volgroup,
830 This creates an LVM volume group called C<logvol>
831 on the volume group C<volgroup>, with C<size> megabytes.
833 This function returns 0 on success or -1 on error.
835 =head2 guestfs_lvm_remove_all
837 int guestfs_lvm_remove_all (guestfs_h *handle);
839 This command removes all LVM logical volumes, volume groups
840 and physical volumes.
842 This function returns 0 on success or -1 on error.
844 B<This command is dangerous. Without careful use you
845 can easily destroy all your data>.
847 =head2 guestfs_lvremove
849 int guestfs_lvremove (guestfs_h *handle,
852 Remove an LVM logical volume C<device>, where C<device> is
853 the path to the LV, such as C</dev/VG/LV>.
855 You can also remove all LVs in a volume group by specifying
856 the VG name, C</dev/VG>.
858 This function returns 0 on success or -1 on error.
862 char **guestfs_lvs (guestfs_h *handle);
864 List all the logical volumes detected. This is the equivalent
865 of the L<lvs(8)> command.
867 This returns a list of the logical volume device names
868 (eg. C</dev/VolGroup00/LogVol00>).
870 See also C<guestfs_lvs_full>.
872 This function returns a NULL-terminated array of strings
873 (like L<environ(3)>), or NULL if there was an error.
874 I<The caller must free the strings and the array after use>.
876 =head2 guestfs_lvs_full
878 struct guestfs_lvm_lv_list *guestfs_lvs_full (guestfs_h *handle);
880 List all the logical volumes detected. This is the equivalent
881 of the L<lvs(8)> command. The "full" version includes all fields.
883 This function returns a C<struct guestfs_lvm_lv_list *>
884 (see E<lt>guestfs-structs.hE<gt>),
885 or NULL if there was an error.
886 I<The caller must call C<guestfs_free_lvm_lv_list> after use>.
890 int guestfs_mkdir (guestfs_h *handle,
893 Create a directory named C<path>.
895 This function returns 0 on success or -1 on error.
897 =head2 guestfs_mkdir_p
899 int guestfs_mkdir_p (guestfs_h *handle,
902 Create a directory named C<path>, creating any parent directories
903 as necessary. This is like the C<mkdir -p> shell command.
905 This function returns 0 on success or -1 on error.
909 int guestfs_mkfs (guestfs_h *handle,
913 This creates a filesystem on C<device> (usually a partition
914 of LVM logical volume). The filesystem type is C<fstype>, for
917 This function returns 0 on success or -1 on error.
921 int guestfs_mount (guestfs_h *handle,
923 const char *mountpoint);
925 Mount a guest disk at a position in the filesystem. Block devices
926 are named C</dev/sda>, C</dev/sdb> and so on, as they were added to
927 the guest. If those block devices contain partitions, they will have
928 the usual names (eg. C</dev/sda1>). Also LVM C</dev/VG/LV>-style
931 The rules are the same as for L<mount(2)>: A filesystem must
932 first be mounted on C</> before others can be mounted. Other
933 filesystems can only be mounted on directories which already
936 The mounted filesystem is writable, if we have sufficient permissions
937 on the underlying device.
939 The filesystem options C<sync> and C<noatime> are set with this
940 call, in order to improve reliability.
942 This function returns 0 on success or -1 on error.
944 =head2 guestfs_mount_options
946 int guestfs_mount_options (guestfs_h *handle,
949 const char *mountpoint);
951 This is the same as the C<guestfs_mount> command, but it
952 allows you to set the mount options as for the
953 L<mount(8)> I<-o> flag.
955 This function returns 0 on success or -1 on error.
957 =head2 guestfs_mount_ro
959 int guestfs_mount_ro (guestfs_h *handle,
961 const char *mountpoint);
963 This is the same as the C<guestfs_mount> command, but it
964 mounts the filesystem with the read-only (I<-o ro>) flag.
966 This function returns 0 on success or -1 on error.
968 =head2 guestfs_mount_vfs
970 int guestfs_mount_vfs (guestfs_h *handle,
974 const char *mountpoint);
976 This is the same as the C<guestfs_mount> command, but it
977 allows you to set both the mount options and the vfstype
978 as for the L<mount(8)> I<-o> and I<-t> flags.
980 This function returns 0 on success or -1 on error.
982 =head2 guestfs_mounts
984 char **guestfs_mounts (guestfs_h *handle);
986 This returns the list of currently mounted filesystems. It returns
987 the list of devices (eg. C</dev/sda1>, C</dev/VG/LV>).
989 Some internal mounts are not shown.
991 This function returns a NULL-terminated array of strings
992 (like L<environ(3)>), or NULL if there was an error.
993 I<The caller must free the strings and the array after use>.
995 =head2 guestfs_pvcreate
997 int guestfs_pvcreate (guestfs_h *handle,
1000 This creates an LVM physical volume on the named C<device>,
1001 where C<device> should usually be a partition name such
1004 This function returns 0 on success or -1 on error.
1006 =head2 guestfs_pvremove
1008 int guestfs_pvremove (guestfs_h *handle,
1009 const char *device);
1011 This wipes a physical volume C<device> so that LVM will no longer
1014 The implementation uses the C<pvremove> command which refuses to
1015 wipe physical volumes that contain any volume groups, so you have
1016 to remove those first.
1018 This function returns 0 on success or -1 on error.
1022 char **guestfs_pvs (guestfs_h *handle);
1024 List all the physical volumes detected. This is the equivalent
1025 of the L<pvs(8)> command.
1027 This returns a list of just the device names that contain
1028 PVs (eg. C</dev/sda2>).
1030 See also C<guestfs_pvs_full>.
1032 This function returns a NULL-terminated array of strings
1033 (like L<environ(3)>), or NULL if there was an error.
1034 I<The caller must free the strings and the array after use>.
1036 =head2 guestfs_pvs_full
1038 struct guestfs_lvm_pv_list *guestfs_pvs_full (guestfs_h *handle);
1040 List all the physical volumes detected. This is the equivalent
1041 of the L<pvs(8)> command. The "full" version includes all fields.
1043 This function returns a C<struct guestfs_lvm_pv_list *>
1044 (see E<lt>guestfs-structs.hE<gt>),
1045 or NULL if there was an error.
1046 I<The caller must call C<guestfs_free_lvm_pv_list> after use>.
1048 =head2 guestfs_read_lines
1050 char **guestfs_read_lines (guestfs_h *handle,
1053 Return the contents of the file named C<path>.
1055 The file contents are returned as a list of lines. Trailing
1056 C<LF> and C<CRLF> character sequences are I<not> returned.
1058 Note that this function cannot correctly handle binary files
1059 (specifically, files containing C<\0> character which is treated
1060 as end of line). For those you need to use the C<guestfs_read_file>
1061 function which has a more complex interface.
1063 This function returns a NULL-terminated array of strings
1064 (like L<environ(3)>), or NULL if there was an error.
1065 I<The caller must free the strings and the array after use>.
1069 int guestfs_rm (guestfs_h *handle,
1072 Remove the single file C<path>.
1074 This function returns 0 on success or -1 on error.
1076 =head2 guestfs_rm_rf
1078 int guestfs_rm_rf (guestfs_h *handle,
1081 Remove the file or directory C<path>, recursively removing the
1082 contents if its a directory. This is like the C<rm -rf> shell
1085 This function returns 0 on success or -1 on error.
1087 =head2 guestfs_rmdir
1089 int guestfs_rmdir (guestfs_h *handle,
1092 Remove the single directory C<path>.
1094 This function returns 0 on success or -1 on error.
1096 =head2 guestfs_set_autosync
1098 int guestfs_set_autosync (guestfs_h *handle,
1101 If C<autosync> is true, this enables autosync. Libguestfs will make a
1102 best effort attempt to run C<guestfs_umount_all> followed by
1103 C<guestfs_sync> when the handle is closed
1104 (also if the program exits without closing handles).
1106 This is disabled by default (except in guestfish where it is
1107 enabled by default).
1109 This function returns 0 on success or -1 on error.
1111 =head2 guestfs_set_busy
1113 int guestfs_set_busy (guestfs_h *handle);
1115 This sets the state to C<BUSY>. This is only used when implementing
1116 actions using the low-level API.
1118 For more information on states, see L<guestfs(3)>.
1120 This function returns 0 on success or -1 on error.
1122 =head2 guestfs_set_e2label
1124 int guestfs_set_e2label (guestfs_h *handle,
1128 This sets the ext2/3/4 filesystem label of the filesystem on
1129 C<device> to C<label>. Filesystem labels are limited to
1132 You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2label>
1133 to return the existing label on a filesystem.
1135 This function returns 0 on success or -1 on error.
1137 =head2 guestfs_set_e2uuid
1139 int guestfs_set_e2uuid (guestfs_h *handle,
1143 This sets the ext2/3/4 filesystem UUID of the filesystem on
1144 C<device> to C<uuid>. The format of the UUID and alternatives
1145 such as C<clear>, C<random> and C<time> are described in the
1146 L<tune2fs(8)> manpage.
1148 You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2uuid>
1149 to return the existing UUID of a filesystem.
1151 This function returns 0 on success or -1 on error.
1153 =head2 guestfs_set_path
1155 int guestfs_set_path (guestfs_h *handle,
1158 Set the path that libguestfs searches for kernel and initrd.img.
1160 The default is C<$libdir/guestfs> unless overridden by setting
1161 C<LIBGUESTFS_PATH> environment variable.
1163 The string C<path> is stashed in the libguestfs handle, so the caller
1164 must make sure it remains valid for the lifetime of the handle.
1166 Setting C<path> to C<NULL> restores the default path.
1168 This function returns 0 on success or -1 on error.
1170 =head2 guestfs_set_qemu
1172 int guestfs_set_qemu (guestfs_h *handle,
1175 Set the qemu binary that we will use.
1177 The default is chosen when the library was compiled by the
1180 You can also override this by setting the C<LIBGUESTFS_QEMU>
1181 environment variable.
1183 The string C<qemu> is stashed in the libguestfs handle, so the caller
1184 must make sure it remains valid for the lifetime of the handle.
1186 Setting C<qemu> to C<NULL> restores the default qemu binary.
1188 This function returns 0 on success or -1 on error.
1190 =head2 guestfs_set_ready
1192 int guestfs_set_ready (guestfs_h *handle);
1194 This sets the state to C<READY>. This is only used when implementing
1195 actions using the low-level API.
1197 For more information on states, see L<guestfs(3)>.
1199 This function returns 0 on success or -1 on error.
1201 =head2 guestfs_set_verbose
1203 int guestfs_set_verbose (guestfs_h *handle,
1206 If C<verbose> is true, this turns on verbose messages (to C<stderr>).
1208 Verbose messages are disabled unless the environment variable
1209 C<LIBGUESTFS_DEBUG> is defined and set to C<1>.
1211 This function returns 0 on success or -1 on error.
1213 =head2 guestfs_sfdisk
1215 int guestfs_sfdisk (guestfs_h *handle,
1220 char * const* const lines);
1222 This is a direct interface to the L<sfdisk(8)> program for creating
1223 partitions on block devices.
1225 C<device> should be a block device, for example C</dev/sda>.
1227 C<cyls>, C<heads> and C<sectors> are the number of cylinders, heads
1228 and sectors on the device, which are passed directly to sfdisk as
1229 the I<-C>, I<-H> and I<-S> parameters. If you pass C<0> for any
1230 of these, then the corresponding parameter is omitted. Usually for
1231 'large' disks, you can just pass C<0> for these, but for small
1232 (floppy-sized) disks, sfdisk (or rather, the kernel) cannot work
1233 out the right geometry and you will need to tell it.
1235 C<lines> is a list of lines that we feed to C<sfdisk>. For more
1236 information refer to the L<sfdisk(8)> manpage.
1238 To create a single partition occupying the whole disk, you would
1239 pass C<lines> as a single element list, when the single element being
1240 the string C<,> (comma).
1242 This function returns 0 on success or -1 on error.
1244 B<This command is dangerous. Without careful use you
1245 can easily destroy all your data>.
1249 struct guestfs_stat *guestfs_stat (guestfs_h *handle,
1252 Returns file information for the given C<path>.
1254 This is the same as the C<stat(2)> system call.
1256 This function returns a C<struct guestfs_stat *>
1257 (see L<stat(2)> and E<lt>guestfs-structs.hE<gt>),
1258 or NULL if there was an error.
1259 I<The caller must call C<free> after use>.
1261 =head2 guestfs_statvfs
1263 struct guestfs_statvfs *guestfs_statvfs (guestfs_h *handle,
1266 Returns file system statistics for any mounted file system.
1267 C<path> should be a file or directory in the mounted file system
1268 (typically it is the mount point itself, but it doesn't need to be).
1270 This is the same as the C<statvfs(2)> system call.
1272 This function returns a C<struct guestfs_statvfs *>
1273 (see L<statvfs(2)> and E<lt>guestfs-structs.hE<gt>),
1274 or NULL if there was an error.
1275 I<The caller must call C<free> after use>.
1279 int guestfs_sync (guestfs_h *handle);
1281 This syncs the disk, so that any writes are flushed through to the
1282 underlying disk image.
1284 You should always call this if you have modified a disk image, before
1287 This function returns 0 on success or -1 on error.
1289 =head2 guestfs_tar_in
1291 int guestfs_tar_in (guestfs_h *handle,
1292 const char *tarfile,
1293 const char *directory);
1295 This command uploads and unpacks local file C<tarfile> (an
1296 I<uncompressed> tar file) into C<directory>.
1298 To upload a compressed tarball, use C<guestfs_tgz_in>.
1300 This function returns 0 on success or -1 on error.
1302 =head2 guestfs_tar_out
1304 int guestfs_tar_out (guestfs_h *handle,
1305 const char *directory,
1306 const char *tarfile);
1308 This command packs the contents of C<directory> and downloads
1309 it to local file C<tarfile>.
1311 To download a compressed tarball, use C<guestfs_tgz_out>.
1313 This function returns 0 on success or -1 on error.
1315 =head2 guestfs_tgz_in
1317 int guestfs_tgz_in (guestfs_h *handle,
1318 const char *tarball,
1319 const char *directory);
1321 This command uploads and unpacks local file C<tarball> (a
1322 I<gzip compressed> tar file) into C<directory>.
1324 To upload an uncompressed tarball, use C<guestfs_tar_in>.
1326 This function returns 0 on success or -1 on error.
1328 =head2 guestfs_tgz_out
1330 int guestfs_tgz_out (guestfs_h *handle,
1331 const char *directory,
1332 const char *tarball);
1334 This command packs the contents of C<directory> and downloads
1335 it to local file C<tarball>.
1337 To download an uncompressed tarball, use C<guestfs_tar_out>.
1339 This function returns 0 on success or -1 on error.
1341 =head2 guestfs_touch
1343 int guestfs_touch (guestfs_h *handle,
1346 Touch acts like the L<touch(1)> command. It can be used to
1347 update the timestamps on a file, or, if the file does not exist,
1348 to create a new zero-length file.
1350 This function returns 0 on success or -1 on error.
1352 =head2 guestfs_tune2fs_l
1354 char **guestfs_tune2fs_l (guestfs_h *handle,
1355 const char *device);
1357 This returns the contents of the ext2, ext3 or ext4 filesystem
1358 superblock on C<device>.
1360 It is the same as running C<tune2fs -l device>. See L<tune2fs(8)>
1361 manpage for more details. The list of fields returned isn't
1362 clearly defined, and depends on both the version of C<tune2fs>
1363 that libguestfs was built against, and the filesystem itself.
1365 This function returns a NULL-terminated array of
1366 strings, or NULL if there was an error.
1367 The array of strings will always have length C<2n+1>, where
1368 C<n> keys and values alternate, followed by the trailing NULL entry.
1369 I<The caller must free the strings and the array after use>.
1371 =head2 guestfs_umount
1373 int guestfs_umount (guestfs_h *handle,
1374 const char *pathordevice);
1376 This unmounts the given filesystem. The filesystem may be
1377 specified either by its mountpoint (path) or the device which
1378 contains the filesystem.
1380 This function returns 0 on success or -1 on error.
1382 =head2 guestfs_umount_all
1384 int guestfs_umount_all (guestfs_h *handle);
1386 This unmounts all mounted filesystems.
1388 Some internal mounts are not unmounted by this call.
1390 This function returns 0 on success or -1 on error.
1392 =head2 guestfs_upload
1394 int guestfs_upload (guestfs_h *handle,
1395 const char *filename,
1396 const char *remotefilename);
1398 Upload local file C<filename> to C<remotefilename> on the
1401 C<filename> can also be a named pipe.
1403 See also C<guestfs_download>.
1405 This function returns 0 on success or -1 on error.
1407 =head2 guestfs_vgcreate
1409 int guestfs_vgcreate (guestfs_h *handle,
1410 const char *volgroup,
1411 char * const* const physvols);
1413 This creates an LVM volume group called C<volgroup>
1414 from the non-empty list of physical volumes C<physvols>.
1416 This function returns 0 on success or -1 on error.
1418 =head2 guestfs_vgremove
1420 int guestfs_vgremove (guestfs_h *handle,
1421 const char *vgname);
1423 Remove an LVM volume group C<vgname>, (for example C<VG>).
1425 This also forcibly removes all logical volumes in the volume
1428 This function returns 0 on success or -1 on error.
1432 char **guestfs_vgs (guestfs_h *handle);
1434 List all the volumes groups detected. This is the equivalent
1435 of the L<vgs(8)> command.
1437 This returns a list of just the volume group names that were
1438 detected (eg. C<VolGroup00>).
1440 See also C<guestfs_vgs_full>.
1442 This function returns a NULL-terminated array of strings
1443 (like L<environ(3)>), or NULL if there was an error.
1444 I<The caller must free the strings and the array after use>.
1446 =head2 guestfs_vgs_full
1448 struct guestfs_lvm_vg_list *guestfs_vgs_full (guestfs_h *handle);
1450 List all the volumes groups detected. This is the equivalent
1451 of the L<vgs(8)> command. The "full" version includes all fields.
1453 This function returns a C<struct guestfs_lvm_vg_list *>
1454 (see E<lt>guestfs-structs.hE<gt>),
1455 or NULL if there was an error.
1456 I<The caller must call C<guestfs_free_lvm_vg_list> after use>.
1458 =head2 guestfs_wait_ready
1460 int guestfs_wait_ready (guestfs_h *handle);
1462 Internally libguestfs is implemented by running a virtual machine
1465 You should call this after C<guestfs_launch> to wait for the launch
1468 This function returns 0 on success or -1 on error.
1470 =head2 guestfs_write_file
1472 int guestfs_write_file (guestfs_h *handle,
1474 const char *content,
1477 This call creates a file called C<path>. The contents of the
1478 file is the string C<content> (which can contain any 8 bit data),
1479 with length C<size>.
1481 As a special case, if C<size> is C<0>
1482 then the length is calculated using C<strlen> (so in this case
1483 the content cannot contain embedded ASCII NULs).
1485 This function returns 0 on success or -1 on error.
1487 Because of the message protocol, there is a transfer limit
1488 of somewhere between 2MB and 4MB. To transfer large files you should use