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 Note that this call checks for the existence of C<filename>. This
11 stops you from specifying other types of drive which are supported
12 by qemu such as C<nbd:> and C<http:> URLs. To specify those, use
13 the general C<guestfs_config> call instead.
15 This function returns 0 on success or -1 on error.
17 =head2 guestfs_add_drive
19 int guestfs_add_drive (guestfs_h *handle,
20 const char *filename);
22 This function adds a virtual machine disk image C<filename> to the
23 guest. The first time you call this function, the disk appears as IDE
24 disk 0 (C</dev/sda>) in the guest, the second time as C</dev/sdb>, and
27 You don't necessarily need to be root when using libguestfs. However
28 you obviously do need sufficient permissions to access the filename
29 for whatever operations you want to perform (ie. read access if you
30 just want to read the image or write access if you want to modify the
33 This is equivalent to the qemu parameter C<-drive file=filename,cache=off>.
35 Note that this call checks for the existence of C<filename>. This
36 stops you from specifying other types of drive which are supported
37 by qemu such as C<nbd:> and C<http:> URLs. To specify those, use
38 the general C<guestfs_config> call instead.
40 This function returns 0 on success or -1 on error.
42 =head2 guestfs_add_drive_ro
44 int guestfs_add_drive_ro (guestfs_h *handle,
45 const char *filename);
47 This adds a drive in snapshot mode, making it effectively
50 Note that writes to the device are allowed, and will be seen for
51 the duration of the guestfs handle, but they are written
52 to a temporary file which is discarded as soon as the guestfs
53 handle is closed. We don't currently have any method to enable
54 changes to be committed, although qemu can support this.
56 This is equivalent to the qemu parameter
57 C<-drive file=filename,snapshot=on>.
59 Note that this call checks for the existence of C<filename>. This
60 stops you from specifying other types of drive which are supported
61 by qemu such as C<nbd:> and C<http:> URLs. To specify those, use
62 the general C<guestfs_config> call instead.
64 This function returns 0 on success or -1 on error.
66 =head2 guestfs_aug_close
68 int guestfs_aug_close (guestfs_h *handle);
70 Close the current Augeas handle and free up any resources
71 used by it. After calling this, you have to call
72 C<guestfs_aug_init> again before you can use any other
75 This function returns 0 on success or -1 on error.
77 =head2 guestfs_aug_defnode
79 struct guestfs_int_bool *guestfs_aug_defnode (guestfs_h *handle,
84 Defines a variable C<name> whose value is the result of
87 If C<expr> evaluates to an empty nodeset, a node is created,
88 equivalent to calling C<guestfs_aug_set> C<expr>, C<value>.
89 C<name> will be the nodeset containing that single node.
91 On success this returns a pair containing the
92 number of nodes in the nodeset, and a boolean flag
93 if a node was created.
95 This function returns a C<struct guestfs_int_bool *>,
96 or NULL if there was an error.
97 I<The caller must call C<guestfs_free_int_bool> after use>.
99 =head2 guestfs_aug_defvar
101 int guestfs_aug_defvar (guestfs_h *handle,
105 Defines an Augeas variable C<name> whose value is the result
106 of evaluating C<expr>. If C<expr> is NULL, then C<name> is
109 On success this returns the number of nodes in C<expr>, or
110 C<0> if C<expr> evaluates to something which is not a nodeset.
112 On error this function returns -1.
114 =head2 guestfs_aug_get
116 char *guestfs_aug_get (guestfs_h *handle,
119 Look up the value associated with C<path>. If C<path>
120 matches exactly one node, the C<value> is returned.
122 This function returns a string, or NULL on error.
123 I<The caller must free the returned string after use>.
125 =head2 guestfs_aug_init
127 int guestfs_aug_init (guestfs_h *handle,
131 Create a new Augeas handle for editing configuration files.
132 If there was any previous Augeas handle associated with this
133 guestfs session, then it is closed.
135 You must call this before using any other C<guestfs_aug_*>
138 C<root> is the filesystem root. C<root> must not be NULL,
141 The flags are the same as the flags defined in
142 E<lt>augeas.hE<gt>, the logical I<or> of the following
147 =item C<AUG_SAVE_BACKUP> = 1
149 Keep the original file with a C<.augsave> extension.
151 =item C<AUG_SAVE_NEWFILE> = 2
153 Save changes into a file with extension C<.augnew>, and
154 do not overwrite original. Overrides C<AUG_SAVE_BACKUP>.
156 =item C<AUG_TYPE_CHECK> = 4
158 Typecheck lenses (can be expensive).
160 =item C<AUG_NO_STDINC> = 8
162 Do not use standard load path for modules.
164 =item C<AUG_SAVE_NOOP> = 16
166 Make save a no-op, just record what would have been changed.
168 =item C<AUG_NO_LOAD> = 32
170 Do not load the tree in C<guestfs_aug_init>.
174 To close the handle, you can call C<guestfs_aug_close>.
176 To find out more about Augeas, see L<http://augeas.net/>.
178 This function returns 0 on success or -1 on error.
180 =head2 guestfs_aug_insert
182 int guestfs_aug_insert (guestfs_h *handle,
187 Create a new sibling C<label> for C<path>, inserting it into
188 the tree before or after C<path> (depending on the boolean
191 C<path> must match exactly one existing node in the tree, and
192 C<label> must be a label, ie. not contain C</>, C<*> or end
193 with a bracketed index C<[N]>.
195 This function returns 0 on success or -1 on error.
197 =head2 guestfs_aug_load
199 int guestfs_aug_load (guestfs_h *handle);
201 Load files into the tree.
203 See C<aug_load> in the Augeas documentation for the full gory
206 This function returns 0 on success or -1 on error.
208 =head2 guestfs_aug_ls
210 char **guestfs_aug_ls (guestfs_h *handle,
213 This is just a shortcut for listing C<guestfs_aug_match>
214 C<path/*> and sorting the resulting nodes into alphabetical order.
216 This function returns a NULL-terminated array of strings
217 (like L<environ(3)>), or NULL if there was an error.
218 I<The caller must free the strings and the array after use>.
220 =head2 guestfs_aug_match
222 char **guestfs_aug_match (guestfs_h *handle,
225 Returns a list of paths which match the path expression C<path>.
226 The returned paths are sufficiently qualified so that they match
227 exactly one node in the current tree.
229 This function returns a NULL-terminated array of strings
230 (like L<environ(3)>), or NULL if there was an error.
231 I<The caller must free the strings and the array after use>.
233 =head2 guestfs_aug_mv
235 int guestfs_aug_mv (guestfs_h *handle,
239 Move the node C<src> to C<dest>. C<src> must match exactly
240 one node. C<dest> is overwritten if it exists.
242 This function returns 0 on success or -1 on error.
244 =head2 guestfs_aug_rm
246 int guestfs_aug_rm (guestfs_h *handle,
249 Remove C<path> and all of its children.
251 On success this returns the number of entries which were removed.
253 On error this function returns -1.
255 =head2 guestfs_aug_save
257 int guestfs_aug_save (guestfs_h *handle);
259 This writes all pending changes to disk.
261 The flags which were passed to C<guestfs_aug_init> affect exactly
264 This function returns 0 on success or -1 on error.
266 =head2 guestfs_aug_set
268 int guestfs_aug_set (guestfs_h *handle,
272 Set the value associated with C<path> to C<value>.
274 This function returns 0 on success or -1 on error.
276 =head2 guestfs_blockdev_flushbufs
278 int guestfs_blockdev_flushbufs (guestfs_h *handle,
281 This tells the kernel to flush internal buffers associated
284 This uses the L<blockdev(8)> command.
286 This function returns 0 on success or -1 on error.
288 =head2 guestfs_blockdev_getbsz
290 int guestfs_blockdev_getbsz (guestfs_h *handle,
293 This returns the block size of a device.
295 (Note this is different from both I<size in blocks> and
296 I<filesystem block size>).
298 This uses the L<blockdev(8)> command.
300 On error this function returns -1.
302 =head2 guestfs_blockdev_getro
304 int guestfs_blockdev_getro (guestfs_h *handle,
307 Returns a boolean indicating if the block device is read-only
308 (true if read-only, false if not).
310 This uses the L<blockdev(8)> command.
312 This function returns a C truth value on success or -1 on error.
314 =head2 guestfs_blockdev_getsize64
316 int64_t guestfs_blockdev_getsize64 (guestfs_h *handle,
319 This returns the size of the device in bytes.
321 See also C<guestfs_blockdev_getsz>.
323 This uses the L<blockdev(8)> command.
325 On error this function returns -1.
327 =head2 guestfs_blockdev_getss
329 int guestfs_blockdev_getss (guestfs_h *handle,
332 This returns the size of sectors on a block device.
333 Usually 512, but can be larger for modern devices.
335 (Note, this is not the size in sectors, use C<guestfs_blockdev_getsz>
338 This uses the L<blockdev(8)> command.
340 On error this function returns -1.
342 =head2 guestfs_blockdev_getsz
344 int64_t guestfs_blockdev_getsz (guestfs_h *handle,
347 This returns the size of the device in units of 512-byte sectors
348 (even if the sectorsize isn't 512 bytes ... weird).
350 See also C<guestfs_blockdev_getss> for the real sector size of
351 the device, and C<guestfs_blockdev_getsize64> for the more
352 useful I<size in bytes>.
354 This uses the L<blockdev(8)> command.
356 On error this function returns -1.
358 =head2 guestfs_blockdev_rereadpt
360 int guestfs_blockdev_rereadpt (guestfs_h *handle,
363 Reread the partition table on C<device>.
365 This uses the L<blockdev(8)> command.
367 This function returns 0 on success or -1 on error.
369 =head2 guestfs_blockdev_setbsz
371 int guestfs_blockdev_setbsz (guestfs_h *handle,
375 This sets the block size of a device.
377 (Note this is different from both I<size in blocks> and
378 I<filesystem block size>).
380 This uses the L<blockdev(8)> command.
382 This function returns 0 on success or -1 on error.
384 =head2 guestfs_blockdev_setro
386 int guestfs_blockdev_setro (guestfs_h *handle,
389 Sets the block device named C<device> to read-only.
391 This uses the L<blockdev(8)> command.
393 This function returns 0 on success or -1 on error.
395 =head2 guestfs_blockdev_setrw
397 int guestfs_blockdev_setrw (guestfs_h *handle,
400 Sets the block device named C<device> to read-write.
402 This uses the L<blockdev(8)> command.
404 This function returns 0 on success or -1 on error.
408 char *guestfs_cat (guestfs_h *handle,
411 Return the contents of the file named C<path>.
413 Note that this function cannot correctly handle binary files
414 (specifically, files containing C<\0> character which is treated
415 as end of string). For those you need to use the C<guestfs_download>
416 function which has a more complex interface.
418 This function returns a string, or NULL on error.
419 I<The caller must free the returned string after use>.
421 Because of the message protocol, there is a transfer limit
422 of somewhere between 2MB and 4MB. To transfer large files you should use
425 =head2 guestfs_checksum
427 char *guestfs_checksum (guestfs_h *handle,
428 const char *csumtype,
431 This call computes the MD5, SHAx or CRC checksum of the
434 The type of checksum to compute is given by the C<csumtype>
435 parameter which must have one of the following values:
441 Compute the cyclic redundancy check (CRC) specified by POSIX
442 for the C<cksum> command.
446 Compute the MD5 hash (using the C<md5sum> program).
450 Compute the SHA1 hash (using the C<sha1sum> program).
454 Compute the SHA224 hash (using the C<sha224sum> program).
458 Compute the SHA256 hash (using the C<sha256sum> program).
462 Compute the SHA384 hash (using the C<sha384sum> program).
466 Compute the SHA512 hash (using the C<sha512sum> program).
470 The checksum is returned as a printable string.
472 This function returns a string, or NULL on error.
473 I<The caller must free the returned string after use>.
477 int guestfs_chmod (guestfs_h *handle,
481 Change the mode (permissions) of C<path> to C<mode>. Only
482 numeric modes are supported.
484 This function returns 0 on success or -1 on error.
488 int guestfs_chown (guestfs_h *handle,
493 Change the file owner to C<owner> and group to C<group>.
495 Only numeric uid and gid are supported. If you want to use
496 names, you will need to locate and parse the password file
497 yourself (Augeas support makes this relatively easy).
499 This function returns 0 on success or -1 on error.
501 =head2 guestfs_command
503 char *guestfs_command (guestfs_h *handle,
504 char * const* const arguments);
506 This call runs a command from the guest filesystem. The
507 filesystem must be mounted, and must contain a compatible
508 operating system (ie. something Linux, with the same
509 or compatible processor architecture).
511 The single parameter is an argv-style list of arguments.
512 The first element is the name of the program to run.
513 Subsequent elements are parameters. The list must be
514 non-empty (ie. must contain a program name). Note that
515 the command runs directly, and is I<not> invoked via
516 the shell (see C<guestfs_sh>).
518 The return value is anything printed to I<stdout> by
521 If the command returns a non-zero exit status, then
522 this function returns an error message. The error message
523 string is the content of I<stderr> from the command.
525 The C<$PATH> environment variable will contain at least
526 C</usr/bin> and C</bin>. If you require a program from
527 another location, you should provide the full path in the
530 Shared libraries and data files required by the program
531 must be available on filesystems which are mounted in the
532 correct places. It is the caller's responsibility to ensure
533 all filesystems that are needed are mounted at the right
536 This function returns a string, or NULL on error.
537 I<The caller must free the returned string after use>.
539 Because of the message protocol, there is a transfer limit
540 of somewhere between 2MB and 4MB. To transfer large files you should use
543 =head2 guestfs_command_lines
545 char **guestfs_command_lines (guestfs_h *handle,
546 char * const* const arguments);
548 This is the same as C<guestfs_command>, but splits the
549 result into a list of lines.
551 See also: C<guestfs_sh_lines>
553 This function returns a NULL-terminated array of strings
554 (like L<environ(3)>), or NULL if there was an error.
555 I<The caller must free the strings and the array after use>.
557 Because of the message protocol, there is a transfer limit
558 of somewhere between 2MB and 4MB. To transfer large files you should use
561 =head2 guestfs_config
563 int guestfs_config (guestfs_h *handle,
564 const char *qemuparam,
565 const char *qemuvalue);
567 This can be used to add arbitrary qemu command line parameters
568 of the form C<-param value>. Actually it's not quite arbitrary - we
569 prevent you from setting some parameters which would interfere with
570 parameters that we use.
572 The first character of C<param> string must be a C<-> (dash).
574 C<value> can be NULL.
576 This function returns 0 on success or -1 on error.
580 int guestfs_cp (guestfs_h *handle,
584 This copies a file from C<src> to C<dest> where C<dest> is
585 either a destination filename or destination directory.
587 This function returns 0 on success or -1 on error.
591 int guestfs_cp_a (guestfs_h *handle,
595 This copies a file or directory from C<src> to C<dest>
596 recursively using the C<cp -a> command.
598 This function returns 0 on success or -1 on error.
602 char *guestfs_debug (guestfs_h *handle,
604 char * const* const extraargs);
606 The C<guestfs_debug> command exposes some internals of
607 C<guestfsd> (the guestfs daemon) that runs inside the
610 There is no comprehensive help for this command. You have
611 to look at the file C<daemon/debug.c> in the libguestfs source
612 to find out what you can do.
614 This function returns a string, or NULL on error.
615 I<The caller must free the returned string after use>.
619 char *guestfs_df (guestfs_h *handle);
621 This command runs the C<df> command to report disk space used.
623 This command is mostly useful for interactive sessions. It
624 is I<not> intended that you try to parse the output string.
625 Use C<statvfs> from programs.
627 This function returns a string, or NULL on error.
628 I<The caller must free the returned string after use>.
632 char *guestfs_df_h (guestfs_h *handle);
634 This command runs the C<df -h> command to report disk space used
635 in human-readable format.
637 This command is mostly useful for interactive sessions. It
638 is I<not> intended that you try to parse the output string.
639 Use C<statvfs> from programs.
641 This function returns a string, or NULL on error.
642 I<The caller must free the returned string after use>.
646 char *guestfs_dmesg (guestfs_h *handle);
648 This returns the kernel messages (C<dmesg> output) from
649 the guest kernel. This is sometimes useful for extended
650 debugging of problems.
652 Another way to get the same information is to enable
653 verbose messages with C<guestfs_set_verbose> or by setting
654 the environment variable C<LIBGUESTFS_DEBUG=1> before
657 This function returns a string, or NULL on error.
658 I<The caller must free the returned string after use>.
660 =head2 guestfs_download
662 int guestfs_download (guestfs_h *handle,
663 const char *remotefilename,
664 const char *filename);
666 Download file C<remotefilename> and save it as C<filename>
667 on the local machine.
669 C<filename> can also be a named pipe.
671 See also C<guestfs_upload>, C<guestfs_cat>.
673 This function returns 0 on success or -1 on error.
675 =head2 guestfs_drop_caches
677 int guestfs_drop_caches (guestfs_h *handle,
680 This instructs the guest kernel to drop its page cache,
681 and/or dentries and inode caches. The parameter C<whattodrop>
682 tells the kernel what precisely to drop, see
683 L<http://linux-mm.org/Drop_Caches>
685 Setting C<whattodrop> to 3 should drop everything.
687 This automatically calls L<sync(2)> before the operation,
688 so that the maximum guest memory is freed.
690 This function returns 0 on success or -1 on error.
692 =head2 guestfs_e2fsck_f
694 int guestfs_e2fsck_f (guestfs_h *handle,
697 This runs C<e2fsck -p -f device>, ie. runs the ext2/ext3
698 filesystem checker on C<device>, noninteractively (C<-p>),
699 even if the filesystem appears to be clean (C<-f>).
701 This command is only needed because of C<guestfs_resize2fs>
702 (q.v.). Normally you should use C<guestfs_fsck>.
704 This function returns 0 on success or -1 on error.
706 =head2 guestfs_end_busy
708 int guestfs_end_busy (guestfs_h *handle);
710 This sets the state to C<READY>, or if in C<CONFIG> then it leaves the
711 state as is. This is only used when implementing
712 actions using the low-level API.
714 For more information on states, see L<guestfs(3)>.
716 This function returns 0 on success or -1 on error.
720 int guestfs_equal (guestfs_h *handle,
724 This compares the two files C<file1> and C<file2> and returns
725 true if their content is exactly equal, or false otherwise.
727 The external L<cmp(1)> program is used for the comparison.
729 This function returns a C truth value on success or -1 on error.
731 =head2 guestfs_exists
733 int guestfs_exists (guestfs_h *handle,
736 This returns C<true> if and only if there is a file, directory
737 (or anything) with the given C<path> name.
739 See also C<guestfs_is_file>, C<guestfs_is_dir>, C<guestfs_stat>.
741 This function returns a C truth value on success or -1 on error.
745 char *guestfs_file (guestfs_h *handle,
748 This call uses the standard L<file(1)> command to determine
749 the type or contents of the file. This also works on devices,
750 for example to find out whether a partition contains a filesystem.
752 The exact command which runs is C<file -bsL path>. Note in
753 particular that the filename is not prepended to the output
756 This function returns a string, or NULL on error.
757 I<The caller must free the returned string after use>.
761 char **guestfs_find (guestfs_h *handle,
762 const char *directory);
764 This command lists out all files and directories, recursively,
765 starting at C<directory>. It is essentially equivalent to
766 running the shell command C<find directory -print> but some
767 post-processing happens on the output, described below.
769 This returns a list of strings I<without any prefix>. Thus
770 if the directory structure was:
776 then the returned list from C<guestfs_find> C</tmp> would be
784 If C<directory> is not a directory, then this command returns
787 The returned list is sorted.
789 This function returns a NULL-terminated array of strings
790 (like L<environ(3)>), or NULL if there was an error.
791 I<The caller must free the strings and the array after use>.
795 int guestfs_fsck (guestfs_h *handle,
799 This runs the filesystem checker (fsck) on C<device> which
800 should have filesystem type C<fstype>.
802 The returned integer is the status. See L<fsck(8)> for the
803 list of status codes from C<fsck>.
811 Multiple status codes can be summed together.
815 A non-zero return code can mean "success", for example if
816 errors have been corrected on the filesystem.
820 Checking or repairing NTFS volumes is not supported
825 This command is entirely equivalent to running C<fsck -a -t fstype device>.
827 On error this function returns -1.
829 =head2 guestfs_get_append
831 const char *guestfs_get_append (guestfs_h *handle);
833 Return the additional kernel options which are added to the
834 guest kernel command line.
836 If C<NULL> then no options are added.
838 This function returns a string, or NULL on error.
839 The string is owned by the guest handle and must I<not> be freed.
841 =head2 guestfs_get_autosync
843 int guestfs_get_autosync (guestfs_h *handle);
845 Get the autosync flag.
847 This function returns a C truth value on success or -1 on error.
849 =head2 guestfs_get_e2label
851 char *guestfs_get_e2label (guestfs_h *handle,
854 This returns the ext2/3/4 filesystem label of the filesystem on
857 This function returns a string, or NULL on error.
858 I<The caller must free the returned string after use>.
860 =head2 guestfs_get_e2uuid
862 char *guestfs_get_e2uuid (guestfs_h *handle,
865 This returns the ext2/3/4 filesystem UUID of the filesystem on
868 This function returns a string, or NULL on error.
869 I<The caller must free the returned string after use>.
871 =head2 guestfs_get_path
873 const char *guestfs_get_path (guestfs_h *handle);
875 Return the current search path.
877 This is always non-NULL. If it wasn't set already, then this will
878 return the default path.
880 This function returns a string, or NULL on error.
881 The string is owned by the guest handle and must I<not> be freed.
883 =head2 guestfs_get_qemu
885 const char *guestfs_get_qemu (guestfs_h *handle);
887 Return the current qemu binary.
889 This is always non-NULL. If it wasn't set already, then this will
890 return the default qemu binary name.
892 This function returns a string, or NULL on error.
893 The string is owned by the guest handle and must I<not> be freed.
895 =head2 guestfs_get_state
897 int guestfs_get_state (guestfs_h *handle);
899 This returns the current state as an opaque integer. This is
900 only useful for printing debug and internal error messages.
902 For more information on states, see L<guestfs(3)>.
904 On error this function returns -1.
906 =head2 guestfs_get_verbose
908 int guestfs_get_verbose (guestfs_h *handle);
910 This returns the verbose messages flag.
912 This function returns a C truth value on success or -1 on error.
914 =head2 guestfs_glob_expand
916 char **guestfs_glob_expand (guestfs_h *handle,
917 const char *pattern);
919 This command searches for all the pathnames matching
920 C<pattern> according to the wildcard expansion rules
923 If no paths match, then this returns an empty list
924 (note: not an error).
926 It is just a wrapper around the C L<glob(3)> function
927 with flags C<GLOB_MARK|GLOB_BRACE>.
928 See that manual page for more details.
930 This function returns a NULL-terminated array of strings
931 (like L<environ(3)>), or NULL if there was an error.
932 I<The caller must free the strings and the array after use>.
934 =head2 guestfs_grub_install
936 int guestfs_grub_install (guestfs_h *handle,
940 This command installs GRUB (the Grand Unified Bootloader) on
941 C<device>, with the root directory being C<root>.
943 This function returns 0 on success or -1 on error.
947 char **guestfs_head (guestfs_h *handle,
950 This command returns up to the first 10 lines of a file as
953 This function returns a NULL-terminated array of strings
954 (like L<environ(3)>), or NULL if there was an error.
955 I<The caller must free the strings and the array after use>.
957 Because of the message protocol, there is a transfer limit
958 of somewhere between 2MB and 4MB. To transfer large files you should use
961 =head2 guestfs_head_n
963 char **guestfs_head_n (guestfs_h *handle,
967 If the parameter C<nrlines> is a positive number, this returns the first
968 C<nrlines> lines of the file C<path>.
970 If the parameter C<nrlines> is a negative number, this returns lines
971 from the file C<path>, excluding the last C<nrlines> lines.
973 If the parameter C<nrlines> is zero, this returns an empty list.
975 This function returns a NULL-terminated array of strings
976 (like L<environ(3)>), or NULL if there was an error.
977 I<The caller must free the strings and the array after use>.
979 Because of the message protocol, there is a transfer limit
980 of somewhere between 2MB and 4MB. To transfer large files you should use
983 =head2 guestfs_hexdump
985 char *guestfs_hexdump (guestfs_h *handle,
988 This runs C<hexdump -C> on the given C<path>. The result is
989 the human-readable, canonical hex dump of the file.
991 This function returns a string, or NULL on error.
992 I<The caller must free the returned string after use>.
994 Because of the message protocol, there is a transfer limit
995 of somewhere between 2MB and 4MB. To transfer large files you should use
998 =head2 guestfs_is_busy
1000 int guestfs_is_busy (guestfs_h *handle);
1002 This returns true iff this handle is busy processing a command
1003 (in the C<BUSY> state).
1005 For more information on states, see L<guestfs(3)>.
1007 This function returns a C truth value on success or -1 on error.
1009 =head2 guestfs_is_config
1011 int guestfs_is_config (guestfs_h *handle);
1013 This returns true iff this handle is being configured
1014 (in the C<CONFIG> state).
1016 For more information on states, see L<guestfs(3)>.
1018 This function returns a C truth value on success or -1 on error.
1020 =head2 guestfs_is_dir
1022 int guestfs_is_dir (guestfs_h *handle,
1025 This returns C<true> if and only if there is a directory
1026 with the given C<path> name. Note that it returns false for
1027 other objects like files.
1029 See also C<guestfs_stat>.
1031 This function returns a C truth value on success or -1 on error.
1033 =head2 guestfs_is_file
1035 int guestfs_is_file (guestfs_h *handle,
1038 This returns C<true> if and only if there is a file
1039 with the given C<path> name. Note that it returns false for
1040 other objects like directories.
1042 See also C<guestfs_stat>.
1044 This function returns a C truth value on success or -1 on error.
1046 =head2 guestfs_is_launching
1048 int guestfs_is_launching (guestfs_h *handle);
1050 This returns true iff this handle is launching the subprocess
1051 (in the C<LAUNCHING> state).
1053 For more information on states, see L<guestfs(3)>.
1055 This function returns a C truth value on success or -1 on error.
1057 =head2 guestfs_is_ready
1059 int guestfs_is_ready (guestfs_h *handle);
1061 This returns true iff this handle is ready to accept commands
1062 (in the C<READY> state).
1064 For more information on states, see L<guestfs(3)>.
1066 This function returns a C truth value on success or -1 on error.
1068 =head2 guestfs_kill_subprocess
1070 int guestfs_kill_subprocess (guestfs_h *handle);
1072 This kills the qemu subprocess. You should never need to call this.
1074 This function returns 0 on success or -1 on error.
1076 =head2 guestfs_launch
1078 int guestfs_launch (guestfs_h *handle);
1080 Internally libguestfs is implemented by running a virtual machine
1083 You should call this after configuring the handle
1084 (eg. adding drives) but before performing any actions.
1086 This function returns 0 on success or -1 on error.
1088 =head2 guestfs_list_devices
1090 char **guestfs_list_devices (guestfs_h *handle);
1092 List all the block devices.
1094 The full block device names are returned, eg. C</dev/sda>
1096 This function returns a NULL-terminated array of strings
1097 (like L<environ(3)>), or NULL if there was an error.
1098 I<The caller must free the strings and the array after use>.
1100 =head2 guestfs_list_partitions
1102 char **guestfs_list_partitions (guestfs_h *handle);
1104 List all the partitions detected on all block devices.
1106 The full partition device names are returned, eg. C</dev/sda1>
1108 This does not return logical volumes. For that you will need to
1109 call C<guestfs_lvs>.
1111 This function returns a NULL-terminated array of strings
1112 (like L<environ(3)>), or NULL if there was an error.
1113 I<The caller must free the strings and the array after use>.
1117 char *guestfs_ll (guestfs_h *handle,
1118 const char *directory);
1120 List the files in C<directory> (relative to the root directory,
1121 there is no cwd) in the format of 'ls -la'.
1123 This command is mostly useful for interactive sessions. It
1124 is I<not> intended that you try to parse the output string.
1126 This function returns a string, or NULL on error.
1127 I<The caller must free the returned string after use>.
1131 char **guestfs_ls (guestfs_h *handle,
1132 const char *directory);
1134 List the files in C<directory> (relative to the root directory,
1135 there is no cwd). The '.' and '..' entries are not returned, but
1136 hidden files are shown.
1138 This command is mostly useful for interactive sessions. Programs
1139 should probably use C<guestfs_readdir> instead.
1141 This function returns a NULL-terminated array of strings
1142 (like L<environ(3)>), or NULL if there was an error.
1143 I<The caller must free the strings and the array after use>.
1145 =head2 guestfs_lstat
1147 struct guestfs_stat *guestfs_lstat (guestfs_h *handle,
1150 Returns file information for the given C<path>.
1152 This is the same as C<guestfs_stat> except that if C<path>
1153 is a symbolic link, then the link is stat-ed, not the file it
1156 This is the same as the C<lstat(2)> system call.
1158 This function returns a C<struct guestfs_stat *>
1159 (see L<stat(2)> and E<lt>guestfs-structs.hE<gt>),
1160 or NULL if there was an error.
1161 I<The caller must call C<free> after use>.
1163 =head2 guestfs_lvcreate
1165 int guestfs_lvcreate (guestfs_h *handle,
1167 const char *volgroup,
1170 This creates an LVM volume group called C<logvol>
1171 on the volume group C<volgroup>, with C<size> megabytes.
1173 This function returns 0 on success or -1 on error.
1175 =head2 guestfs_lvm_remove_all
1177 int guestfs_lvm_remove_all (guestfs_h *handle);
1179 This command removes all LVM logical volumes, volume groups
1180 and physical volumes.
1182 This function returns 0 on success or -1 on error.
1184 B<This command is dangerous. Without careful use you
1185 can easily destroy all your data>.
1187 =head2 guestfs_lvremove
1189 int guestfs_lvremove (guestfs_h *handle,
1190 const char *device);
1192 Remove an LVM logical volume C<device>, where C<device> is
1193 the path to the LV, such as C</dev/VG/LV>.
1195 You can also remove all LVs in a volume group by specifying
1196 the VG name, C</dev/VG>.
1198 This function returns 0 on success or -1 on error.
1200 =head2 guestfs_lvresize
1202 int guestfs_lvresize (guestfs_h *handle,
1206 This resizes (expands or shrinks) an existing LVM logical
1207 volume to C<mbytes>. When reducing, data in the reduced part
1210 This function returns 0 on success or -1 on error.
1214 char **guestfs_lvs (guestfs_h *handle);
1216 List all the logical volumes detected. This is the equivalent
1217 of the L<lvs(8)> command.
1219 This returns a list of the logical volume device names
1220 (eg. C</dev/VolGroup00/LogVol00>).
1222 See also C<guestfs_lvs_full>.
1224 This function returns a NULL-terminated array of strings
1225 (like L<environ(3)>), or NULL if there was an error.
1226 I<The caller must free the strings and the array after use>.
1228 =head2 guestfs_lvs_full
1230 struct guestfs_lvm_lv_list *guestfs_lvs_full (guestfs_h *handle);
1232 List all the logical volumes detected. This is the equivalent
1233 of the L<lvs(8)> command. The "full" version includes all fields.
1235 This function returns a C<struct guestfs_lvm_lv_list *>
1236 (see E<lt>guestfs-structs.hE<gt>),
1237 or NULL if there was an error.
1238 I<The caller must call C<guestfs_free_lvm_lv_list> after use>.
1240 =head2 guestfs_mkdir
1242 int guestfs_mkdir (guestfs_h *handle,
1245 Create a directory named C<path>.
1247 This function returns 0 on success or -1 on error.
1249 =head2 guestfs_mkdir_p
1251 int guestfs_mkdir_p (guestfs_h *handle,
1254 Create a directory named C<path>, creating any parent directories
1255 as necessary. This is like the C<mkdir -p> shell command.
1257 This function returns 0 on success or -1 on error.
1259 =head2 guestfs_mkdtemp
1261 char *guestfs_mkdtemp (guestfs_h *handle,
1262 const char *template);
1264 This command creates a temporary directory. The
1265 C<template> parameter should be a full pathname for the
1266 temporary directory name with the final six characters being
1269 For example: "/tmp/myprogXXXXXX" or "/Temp/myprogXXXXXX",
1270 the second one being suitable for Windows filesystems.
1272 The name of the temporary directory that was created
1275 The temporary directory is created with mode 0700
1276 and is owned by root.
1278 The caller is responsible for deleting the temporary
1279 directory and its contents after use.
1281 See also: L<mkdtemp(3)>
1283 This function returns a string, or NULL on error.
1284 I<The caller must free the returned string after use>.
1288 int guestfs_mkfs (guestfs_h *handle,
1290 const char *device);
1292 This creates a filesystem on C<device> (usually a partition
1293 or LVM logical volume). The filesystem type is C<fstype>, for
1296 This function returns 0 on success or -1 on error.
1298 =head2 guestfs_mount
1300 int guestfs_mount (guestfs_h *handle,
1302 const char *mountpoint);
1304 Mount a guest disk at a position in the filesystem. Block devices
1305 are named C</dev/sda>, C</dev/sdb> and so on, as they were added to
1306 the guest. If those block devices contain partitions, they will have
1307 the usual names (eg. C</dev/sda1>). Also LVM C</dev/VG/LV>-style
1310 The rules are the same as for L<mount(2)>: A filesystem must
1311 first be mounted on C</> before others can be mounted. Other
1312 filesystems can only be mounted on directories which already
1315 The mounted filesystem is writable, if we have sufficient permissions
1316 on the underlying device.
1318 The filesystem options C<sync> and C<noatime> are set with this
1319 call, in order to improve reliability.
1321 This function returns 0 on success or -1 on error.
1323 =head2 guestfs_mount_options
1325 int guestfs_mount_options (guestfs_h *handle,
1326 const char *options,
1328 const char *mountpoint);
1330 This is the same as the C<guestfs_mount> command, but it
1331 allows you to set the mount options as for the
1332 L<mount(8)> I<-o> flag.
1334 This function returns 0 on success or -1 on error.
1336 =head2 guestfs_mount_ro
1338 int guestfs_mount_ro (guestfs_h *handle,
1340 const char *mountpoint);
1342 This is the same as the C<guestfs_mount> command, but it
1343 mounts the filesystem with the read-only (I<-o ro>) flag.
1345 This function returns 0 on success or -1 on error.
1347 =head2 guestfs_mount_vfs
1349 int guestfs_mount_vfs (guestfs_h *handle,
1350 const char *options,
1351 const char *vfstype,
1353 const char *mountpoint);
1355 This is the same as the C<guestfs_mount> command, but it
1356 allows you to set both the mount options and the vfstype
1357 as for the L<mount(8)> I<-o> and I<-t> flags.
1359 This function returns 0 on success or -1 on error.
1361 =head2 guestfs_mounts
1363 char **guestfs_mounts (guestfs_h *handle);
1365 This returns the list of currently mounted filesystems. It returns
1366 the list of devices (eg. C</dev/sda1>, C</dev/VG/LV>).
1368 Some internal mounts are not shown.
1370 This function returns a NULL-terminated array of strings
1371 (like L<environ(3)>), or NULL if there was an error.
1372 I<The caller must free the strings and the array after use>.
1376 int guestfs_mv (guestfs_h *handle,
1380 This moves a file from C<src> to C<dest> where C<dest> is
1381 either a destination filename or destination directory.
1383 This function returns 0 on success or -1 on error.
1385 =head2 guestfs_ntfs_3g_probe
1387 int guestfs_ntfs_3g_probe (guestfs_h *handle,
1389 const char *device);
1391 This command runs the L<ntfs-3g.probe(8)> command which probes
1392 an NTFS C<device> for mountability. (Not all NTFS volumes can
1393 be mounted read-write, and some cannot be mounted at all).
1395 C<rw> is a boolean flag. Set it to true if you want to test
1396 if the volume can be mounted read-write. Set it to false if
1397 you want to test if the volume can be mounted read-only.
1399 The return value is an integer which C<0> if the operation
1400 would succeed, or some non-zero value documented in the
1401 L<ntfs-3g.probe(8)> manual page.
1403 On error this function returns -1.
1405 =head2 guestfs_ping_daemon
1407 int guestfs_ping_daemon (guestfs_h *handle);
1409 This is a test probe into the guestfs daemon running inside
1410 the qemu subprocess. Calling this function checks that the
1411 daemon responds to the ping message, without affecting the daemon
1412 or attached block device(s) in any other way.
1414 This function returns 0 on success or -1 on error.
1416 =head2 guestfs_pvcreate
1418 int guestfs_pvcreate (guestfs_h *handle,
1419 const char *device);
1421 This creates an LVM physical volume on the named C<device>,
1422 where C<device> should usually be a partition name such
1425 This function returns 0 on success or -1 on error.
1427 =head2 guestfs_pvremove
1429 int guestfs_pvremove (guestfs_h *handle,
1430 const char *device);
1432 This wipes a physical volume C<device> so that LVM will no longer
1435 The implementation uses the C<pvremove> command which refuses to
1436 wipe physical volumes that contain any volume groups, so you have
1437 to remove those first.
1439 This function returns 0 on success or -1 on error.
1441 =head2 guestfs_pvresize
1443 int guestfs_pvresize (guestfs_h *handle,
1444 const char *device);
1446 This resizes (expands or shrinks) an existing LVM physical
1447 volume to match the new size of the underlying device.
1449 This function returns 0 on success or -1 on error.
1453 char **guestfs_pvs (guestfs_h *handle);
1455 List all the physical volumes detected. This is the equivalent
1456 of the L<pvs(8)> command.
1458 This returns a list of just the device names that contain
1459 PVs (eg. C</dev/sda2>).
1461 See also C<guestfs_pvs_full>.
1463 This function returns a NULL-terminated array of strings
1464 (like L<environ(3)>), or NULL if there was an error.
1465 I<The caller must free the strings and the array after use>.
1467 =head2 guestfs_pvs_full
1469 struct guestfs_lvm_pv_list *guestfs_pvs_full (guestfs_h *handle);
1471 List all the physical volumes detected. This is the equivalent
1472 of the L<pvs(8)> command. The "full" version includes all fields.
1474 This function returns a C<struct guestfs_lvm_pv_list *>
1475 (see E<lt>guestfs-structs.hE<gt>),
1476 or NULL if there was an error.
1477 I<The caller must call C<guestfs_free_lvm_pv_list> after use>.
1479 =head2 guestfs_read_lines
1481 char **guestfs_read_lines (guestfs_h *handle,
1484 Return the contents of the file named C<path>.
1486 The file contents are returned as a list of lines. Trailing
1487 C<LF> and C<CRLF> character sequences are I<not> returned.
1489 Note that this function cannot correctly handle binary files
1490 (specifically, files containing C<\0> character which is treated
1491 as end of line). For those you need to use the C<guestfs_read_file>
1492 function which has a more complex interface.
1494 This function returns a NULL-terminated array of strings
1495 (like L<environ(3)>), or NULL if there was an error.
1496 I<The caller must free the strings and the array after use>.
1498 =head2 guestfs_resize2fs
1500 int guestfs_resize2fs (guestfs_h *handle,
1501 const char *device);
1503 This resizes an ext2 or ext3 filesystem to match the size of
1504 the underlying device.
1506 I<Note:> It is sometimes required that you run C<guestfs_e2fsck_f>
1507 on the C<device> before calling this command. For unknown reasons
1508 C<resize2fs> sometimes gives an error about this and sometimes not.
1509 In any case, it is always safe to call C<guestfs_e2fsck_f> before
1510 calling this function.
1512 This function returns 0 on success or -1 on error.
1516 int guestfs_rm (guestfs_h *handle,
1519 Remove the single file C<path>.
1521 This function returns 0 on success or -1 on error.
1523 =head2 guestfs_rm_rf
1525 int guestfs_rm_rf (guestfs_h *handle,
1528 Remove the file or directory C<path>, recursively removing the
1529 contents if its a directory. This is like the C<rm -rf> shell
1532 This function returns 0 on success or -1 on error.
1534 =head2 guestfs_rmdir
1536 int guestfs_rmdir (guestfs_h *handle,
1539 Remove the single directory C<path>.
1541 This function returns 0 on success or -1 on error.
1543 =head2 guestfs_scrub_device
1545 int guestfs_scrub_device (guestfs_h *handle,
1546 const char *device);
1548 This command writes patterns over C<device> to make data retrieval
1551 It is an interface to the L<scrub(1)> program. See that
1552 manual page for more details.
1554 This function returns 0 on success or -1 on error.
1556 B<This command is dangerous. Without careful use you
1557 can easily destroy all your data>.
1559 =head2 guestfs_scrub_file
1561 int guestfs_scrub_file (guestfs_h *handle,
1564 This command writes patterns over a file to make data retrieval
1567 The file is I<removed> after scrubbing.
1569 It is an interface to the L<scrub(1)> program. See that
1570 manual page for more details.
1572 This function returns 0 on success or -1 on error.
1574 =head2 guestfs_scrub_freespace
1576 int guestfs_scrub_freespace (guestfs_h *handle,
1579 This command creates the directory C<dir> and then fills it
1580 with files until the filesystem is full, and scrubs the files
1581 as for C<guestfs_scrub_file>, and deletes them.
1582 The intention is to scrub any free space on the partition
1585 It is an interface to the L<scrub(1)> program. See that
1586 manual page for more details.
1588 This function returns 0 on success or -1 on error.
1590 =head2 guestfs_set_append
1592 int guestfs_set_append (guestfs_h *handle,
1593 const char *append);
1595 This function is used to add additional options to the
1596 guest kernel command line.
1598 The default is C<NULL> unless overridden by setting
1599 C<LIBGUESTFS_APPEND> environment variable.
1601 Setting C<append> to C<NULL> means I<no> additional options
1602 are passed (libguestfs always adds a few of its own).
1604 This function returns 0 on success or -1 on error.
1606 =head2 guestfs_set_autosync
1608 int guestfs_set_autosync (guestfs_h *handle,
1611 If C<autosync> is true, this enables autosync. Libguestfs will make a
1612 best effort attempt to run C<guestfs_umount_all> followed by
1613 C<guestfs_sync> when the handle is closed
1614 (also if the program exits without closing handles).
1616 This is disabled by default (except in guestfish where it is
1617 enabled by default).
1619 This function returns 0 on success or -1 on error.
1621 =head2 guestfs_set_busy
1623 int guestfs_set_busy (guestfs_h *handle);
1625 This sets the state to C<BUSY>. This is only used when implementing
1626 actions using the low-level API.
1628 For more information on states, see L<guestfs(3)>.
1630 This function returns 0 on success or -1 on error.
1632 =head2 guestfs_set_e2label
1634 int guestfs_set_e2label (guestfs_h *handle,
1638 This sets the ext2/3/4 filesystem label of the filesystem on
1639 C<device> to C<label>. Filesystem labels are limited to
1642 You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2label>
1643 to return the existing label on a filesystem.
1645 This function returns 0 on success or -1 on error.
1647 =head2 guestfs_set_e2uuid
1649 int guestfs_set_e2uuid (guestfs_h *handle,
1653 This sets the ext2/3/4 filesystem UUID of the filesystem on
1654 C<device> to C<uuid>. The format of the UUID and alternatives
1655 such as C<clear>, C<random> and C<time> are described in the
1656 L<tune2fs(8)> manpage.
1658 You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2uuid>
1659 to return the existing UUID of a filesystem.
1661 This function returns 0 on success or -1 on error.
1663 =head2 guestfs_set_path
1665 int guestfs_set_path (guestfs_h *handle,
1668 Set the path that libguestfs searches for kernel and initrd.img.
1670 The default is C<$libdir/guestfs> unless overridden by setting
1671 C<LIBGUESTFS_PATH> environment variable.
1673 Setting C<path> to C<NULL> restores the default path.
1675 This function returns 0 on success or -1 on error.
1677 =head2 guestfs_set_qemu
1679 int guestfs_set_qemu (guestfs_h *handle,
1682 Set the qemu binary that we will use.
1684 The default is chosen when the library was compiled by the
1687 You can also override this by setting the C<LIBGUESTFS_QEMU>
1688 environment variable.
1690 Setting C<qemu> to C<NULL> restores the default qemu binary.
1692 This function returns 0 on success or -1 on error.
1694 =head2 guestfs_set_ready
1696 int guestfs_set_ready (guestfs_h *handle);
1698 This sets the state to C<READY>. This is only used when implementing
1699 actions using the low-level API.
1701 For more information on states, see L<guestfs(3)>.
1703 This function returns 0 on success or -1 on error.
1705 =head2 guestfs_set_verbose
1707 int guestfs_set_verbose (guestfs_h *handle,
1710 If C<verbose> is true, this turns on verbose messages (to C<stderr>).
1712 Verbose messages are disabled unless the environment variable
1713 C<LIBGUESTFS_DEBUG> is defined and set to C<1>.
1715 This function returns 0 on success or -1 on error.
1717 =head2 guestfs_sfdisk
1719 int guestfs_sfdisk (guestfs_h *handle,
1724 char * const* const lines);
1726 This is a direct interface to the L<sfdisk(8)> program for creating
1727 partitions on block devices.
1729 C<device> should be a block device, for example C</dev/sda>.
1731 C<cyls>, C<heads> and C<sectors> are the number of cylinders, heads
1732 and sectors on the device, which are passed directly to sfdisk as
1733 the I<-C>, I<-H> and I<-S> parameters. If you pass C<0> for any
1734 of these, then the corresponding parameter is omitted. Usually for
1735 'large' disks, you can just pass C<0> for these, but for small
1736 (floppy-sized) disks, sfdisk (or rather, the kernel) cannot work
1737 out the right geometry and you will need to tell it.
1739 C<lines> is a list of lines that we feed to C<sfdisk>. For more
1740 information refer to the L<sfdisk(8)> manpage.
1742 To create a single partition occupying the whole disk, you would
1743 pass C<lines> as a single element list, when the single element being
1744 the string C<,> (comma).
1746 See also: C<guestfs_sfdisk_l>, C<guestfs_sfdisk_N>
1748 This function returns 0 on success or -1 on error.
1750 B<This command is dangerous. Without careful use you
1751 can easily destroy all your data>.
1753 =head2 guestfs_sfdisk_N
1755 int guestfs_sfdisk_N (guestfs_h *handle,
1763 This runs L<sfdisk(8)> option to modify just the single
1764 partition C<n> (note: C<n> counts from 1).
1766 For other parameters, see C<guestfs_sfdisk>. You should usually
1767 pass C<0> for the cyls/heads/sectors parameters.
1769 This function returns 0 on success or -1 on error.
1771 B<This command is dangerous. Without careful use you
1772 can easily destroy all your data>.
1774 =head2 guestfs_sfdisk_disk_geometry
1776 char *guestfs_sfdisk_disk_geometry (guestfs_h *handle,
1777 const char *device);
1779 This displays the disk geometry of C<device> read from the
1780 partition table. Especially in the case where the underlying
1781 block device has been resized, this can be different from the
1782 kernel's idea of the geometry (see C<guestfs_sfdisk_kernel_geometry>).
1784 The result is in human-readable format, and not designed to
1787 This function returns a string, or NULL on error.
1788 I<The caller must free the returned string after use>.
1790 =head2 guestfs_sfdisk_kernel_geometry
1792 char *guestfs_sfdisk_kernel_geometry (guestfs_h *handle,
1793 const char *device);
1795 This displays the kernel's idea of the geometry of C<device>.
1797 The result is in human-readable format, and not designed to
1800 This function returns a string, or NULL on error.
1801 I<The caller must free the returned string after use>.
1803 =head2 guestfs_sfdisk_l
1805 char *guestfs_sfdisk_l (guestfs_h *handle,
1806 const char *device);
1808 This displays the partition table on C<device>, in the
1809 human-readable output of the L<sfdisk(8)> command. It is
1810 not intended to be parsed.
1812 This function returns a string, or NULL on error.
1813 I<The caller must free the returned string after use>.
1817 char *guestfs_sh (guestfs_h *handle,
1818 const char *command);
1820 This call runs a command from the guest filesystem via the
1823 This is like C<guestfs_command>, but passes the command to:
1825 /bin/sh -c "command"
1827 Depending on the guest's shell, this usually results in
1828 wildcards being expanded, shell expressions being interpolated
1831 All the provisos about C<guestfs_command> apply to this call.
1833 This function returns a string, or NULL on error.
1834 I<The caller must free the returned string after use>.
1836 =head2 guestfs_sh_lines
1838 char **guestfs_sh_lines (guestfs_h *handle,
1839 const char *command);
1841 This is the same as C<guestfs_sh>, but splits the result
1842 into a list of lines.
1844 See also: C<guestfs_command_lines>
1846 This function returns a NULL-terminated array of strings
1847 (like L<environ(3)>), or NULL if there was an error.
1848 I<The caller must free the strings and the array after use>.
1850 =head2 guestfs_sleep
1852 int guestfs_sleep (guestfs_h *handle,
1855 Sleep for C<secs> seconds.
1857 This function returns 0 on success or -1 on error.
1861 struct guestfs_stat *guestfs_stat (guestfs_h *handle,
1864 Returns file information for the given C<path>.
1866 This is the same as the C<stat(2)> system call.
1868 This function returns a C<struct guestfs_stat *>
1869 (see L<stat(2)> and E<lt>guestfs-structs.hE<gt>),
1870 or NULL if there was an error.
1871 I<The caller must call C<free> after use>.
1873 =head2 guestfs_statvfs
1875 struct guestfs_statvfs *guestfs_statvfs (guestfs_h *handle,
1878 Returns file system statistics for any mounted file system.
1879 C<path> should be a file or directory in the mounted file system
1880 (typically it is the mount point itself, but it doesn't need to be).
1882 This is the same as the C<statvfs(2)> system call.
1884 This function returns a C<struct guestfs_statvfs *>
1885 (see L<statvfs(2)> and E<lt>guestfs-structs.hE<gt>),
1886 or NULL if there was an error.
1887 I<The caller must call C<free> after use>.
1889 =head2 guestfs_strings
1891 char **guestfs_strings (guestfs_h *handle,
1894 This runs the L<strings(1)> command on a file and returns
1895 the list of printable strings found.
1897 This function returns a NULL-terminated array of strings
1898 (like L<environ(3)>), or NULL if there was an error.
1899 I<The caller must free the strings and the array after use>.
1901 Because of the message protocol, there is a transfer limit
1902 of somewhere between 2MB and 4MB. To transfer large files you should use
1905 =head2 guestfs_strings_e
1907 char **guestfs_strings_e (guestfs_h *handle,
1908 const char *encoding,
1911 This is like the C<guestfs_strings> command, but allows you to
1912 specify the encoding.
1914 See the L<strings(1)> manpage for the full list of encodings.
1916 Commonly useful encodings are C<l> (lower case L) which will
1917 show strings inside Windows/x86 files.
1919 The returned strings are transcoded to UTF-8.
1921 This function returns a NULL-terminated array of strings
1922 (like L<environ(3)>), or NULL if there was an error.
1923 I<The caller must free the strings and the array after use>.
1925 Because of the message protocol, there is a transfer limit
1926 of somewhere between 2MB and 4MB. To transfer large files you should use
1931 int guestfs_sync (guestfs_h *handle);
1933 This syncs the disk, so that any writes are flushed through to the
1934 underlying disk image.
1936 You should always call this if you have modified a disk image, before
1939 This function returns 0 on success or -1 on error.
1943 char **guestfs_tail (guestfs_h *handle,
1946 This command returns up to the last 10 lines of a file as
1949 This function returns a NULL-terminated array of strings
1950 (like L<environ(3)>), or NULL if there was an error.
1951 I<The caller must free the strings and the array after use>.
1953 Because of the message protocol, there is a transfer limit
1954 of somewhere between 2MB and 4MB. To transfer large files you should use
1957 =head2 guestfs_tail_n
1959 char **guestfs_tail_n (guestfs_h *handle,
1963 If the parameter C<nrlines> is a positive number, this returns the last
1964 C<nrlines> lines of the file C<path>.
1966 If the parameter C<nrlines> is a negative number, this returns lines
1967 from the file C<path>, starting with the C<-nrlines>th line.
1969 If the parameter C<nrlines> is zero, this returns an empty list.
1971 This function returns a NULL-terminated array of strings
1972 (like L<environ(3)>), or NULL if there was an error.
1973 I<The caller must free the strings and the array after use>.
1975 Because of the message protocol, there is a transfer limit
1976 of somewhere between 2MB and 4MB. To transfer large files you should use
1979 =head2 guestfs_tar_in
1981 int guestfs_tar_in (guestfs_h *handle,
1982 const char *tarfile,
1983 const char *directory);
1985 This command uploads and unpacks local file C<tarfile> (an
1986 I<uncompressed> tar file) into C<directory>.
1988 To upload a compressed tarball, use C<guestfs_tgz_in>.
1990 This function returns 0 on success or -1 on error.
1992 =head2 guestfs_tar_out
1994 int guestfs_tar_out (guestfs_h *handle,
1995 const char *directory,
1996 const char *tarfile);
1998 This command packs the contents of C<directory> and downloads
1999 it to local file C<tarfile>.
2001 To download a compressed tarball, use C<guestfs_tgz_out>.
2003 This function returns 0 on success or -1 on error.
2005 =head2 guestfs_tgz_in
2007 int guestfs_tgz_in (guestfs_h *handle,
2008 const char *tarball,
2009 const char *directory);
2011 This command uploads and unpacks local file C<tarball> (a
2012 I<gzip compressed> tar file) into C<directory>.
2014 To upload an uncompressed tarball, use C<guestfs_tar_in>.
2016 This function returns 0 on success or -1 on error.
2018 =head2 guestfs_tgz_out
2020 int guestfs_tgz_out (guestfs_h *handle,
2021 const char *directory,
2022 const char *tarball);
2024 This command packs the contents of C<directory> and downloads
2025 it to local file C<tarball>.
2027 To download an uncompressed tarball, use C<guestfs_tar_out>.
2029 This function returns 0 on success or -1 on error.
2031 =head2 guestfs_touch
2033 int guestfs_touch (guestfs_h *handle,
2036 Touch acts like the L<touch(1)> command. It can be used to
2037 update the timestamps on a file, or, if the file does not exist,
2038 to create a new zero-length file.
2040 This function returns 0 on success or -1 on error.
2042 =head2 guestfs_tune2fs_l
2044 char **guestfs_tune2fs_l (guestfs_h *handle,
2045 const char *device);
2047 This returns the contents of the ext2, ext3 or ext4 filesystem
2048 superblock on C<device>.
2050 It is the same as running C<tune2fs -l device>. See L<tune2fs(8)>
2051 manpage for more details. The list of fields returned isn't
2052 clearly defined, and depends on both the version of C<tune2fs>
2053 that libguestfs was built against, and the filesystem itself.
2055 This function returns a NULL-terminated array of
2056 strings, or NULL if there was an error.
2057 The array of strings will always have length C<2n+1>, where
2058 C<n> keys and values alternate, followed by the trailing NULL entry.
2059 I<The caller must free the strings and the array after use>.
2061 =head2 guestfs_umount
2063 int guestfs_umount (guestfs_h *handle,
2064 const char *pathordevice);
2066 This unmounts the given filesystem. The filesystem may be
2067 specified either by its mountpoint (path) or the device which
2068 contains the filesystem.
2070 This function returns 0 on success or -1 on error.
2072 =head2 guestfs_umount_all
2074 int guestfs_umount_all (guestfs_h *handle);
2076 This unmounts all mounted filesystems.
2078 Some internal mounts are not unmounted by this call.
2080 This function returns 0 on success or -1 on error.
2082 =head2 guestfs_upload
2084 int guestfs_upload (guestfs_h *handle,
2085 const char *filename,
2086 const char *remotefilename);
2088 Upload local file C<filename> to C<remotefilename> on the
2091 C<filename> can also be a named pipe.
2093 See also C<guestfs_download>.
2095 This function returns 0 on success or -1 on error.
2097 =head2 guestfs_vg_activate
2099 int guestfs_vg_activate (guestfs_h *handle,
2101 char * const* const volgroups);
2103 This command activates or (if C<activate> is false) deactivates
2104 all logical volumes in the listed volume groups C<volgroups>.
2105 If activated, then they are made known to the
2106 kernel, ie. they appear as C</dev/mapper> devices. If deactivated,
2107 then those devices disappear.
2109 This command is the same as running C<vgchange -a y|n volgroups...>
2111 Note that if C<volgroups> is an empty list then B<all> volume groups
2112 are activated or deactivated.
2114 This function returns 0 on success or -1 on error.
2116 =head2 guestfs_vg_activate_all
2118 int guestfs_vg_activate_all (guestfs_h *handle,
2121 This command activates or (if C<activate> is false) deactivates
2122 all logical volumes in all volume groups.
2123 If activated, then they are made known to the
2124 kernel, ie. they appear as C</dev/mapper> devices. If deactivated,
2125 then those devices disappear.
2127 This command is the same as running C<vgchange -a y|n>
2129 This function returns 0 on success or -1 on error.
2131 =head2 guestfs_vgcreate
2133 int guestfs_vgcreate (guestfs_h *handle,
2134 const char *volgroup,
2135 char * const* const physvols);
2137 This creates an LVM volume group called C<volgroup>
2138 from the non-empty list of physical volumes C<physvols>.
2140 This function returns 0 on success or -1 on error.
2142 =head2 guestfs_vgremove
2144 int guestfs_vgremove (guestfs_h *handle,
2145 const char *vgname);
2147 Remove an LVM volume group C<vgname>, (for example C<VG>).
2149 This also forcibly removes all logical volumes in the volume
2152 This function returns 0 on success or -1 on error.
2156 char **guestfs_vgs (guestfs_h *handle);
2158 List all the volumes groups detected. This is the equivalent
2159 of the L<vgs(8)> command.
2161 This returns a list of just the volume group names that were
2162 detected (eg. C<VolGroup00>).
2164 See also C<guestfs_vgs_full>.
2166 This function returns a NULL-terminated array of strings
2167 (like L<environ(3)>), or NULL if there was an error.
2168 I<The caller must free the strings and the array after use>.
2170 =head2 guestfs_vgs_full
2172 struct guestfs_lvm_vg_list *guestfs_vgs_full (guestfs_h *handle);
2174 List all the volumes groups detected. This is the equivalent
2175 of the L<vgs(8)> command. The "full" version includes all fields.
2177 This function returns a C<struct guestfs_lvm_vg_list *>
2178 (see E<lt>guestfs-structs.hE<gt>),
2179 or NULL if there was an error.
2180 I<The caller must call C<guestfs_free_lvm_vg_list> after use>.
2182 =head2 guestfs_wait_ready
2184 int guestfs_wait_ready (guestfs_h *handle);
2186 Internally libguestfs is implemented by running a virtual machine
2189 You should call this after C<guestfs_launch> to wait for the launch
2192 This function returns 0 on success or -1 on error.
2196 int guestfs_wc_c (guestfs_h *handle,
2199 This command counts the characters in a file, using the
2200 C<wc -c> external command.
2202 On error this function returns -1.
2206 int guestfs_wc_l (guestfs_h *handle,
2209 This command counts the lines in a file, using the
2210 C<wc -l> external command.
2212 On error this function returns -1.
2216 int guestfs_wc_w (guestfs_h *handle,
2219 This command counts the words in a file, using the
2220 C<wc -w> external command.
2222 On error this function returns -1.
2224 =head2 guestfs_write_file
2226 int guestfs_write_file (guestfs_h *handle,
2228 const char *content,
2231 This call creates a file called C<path>. The contents of the
2232 file is the string C<content> (which can contain any 8 bit data),
2233 with length C<size>.
2235 As a special case, if C<size> is C<0>
2236 then the length is calculated using C<strlen> (so in this case
2237 the content cannot contain embedded ASCII NULs).
2239 I<NB.> Owing to a bug, writing content containing ASCII NUL
2240 characters does I<not> work, even if the length is specified.
2241 We hope to resolve this bug in a future version. In the meantime
2242 use C<guestfs_upload>.
2244 This function returns 0 on success or -1 on error.
2246 Because of the message protocol, there is a transfer limit
2247 of somewhere between 2MB and 4MB. To transfer large files you should use
2252 int guestfs_zero (guestfs_h *handle,
2253 const char *device);
2255 This command writes zeroes over the first few blocks of C<device>.
2257 How many blocks are zeroed isn't specified (but it's I<not> enough
2258 to securely wipe the device). It should be sufficient to remove
2259 any partition tables, filesystem superblocks and so on.
2261 See also: C<guestfs_scrub_device>.
2263 This function returns 0 on success or -1 on error.
2265 =head2 guestfs_zerofree
2267 int guestfs_zerofree (guestfs_h *handle,
2268 const char *device);
2270 This runs the I<zerofree> program on C<device>. This program
2271 claims to zero unused inodes and disk blocks on an ext2/3
2272 filesystem, thus making it possible to compress the filesystem
2275 You should B<not> run this program if the filesystem is
2278 It is possible that using this program can damage the filesystem
2279 or data on the filesystem.
2281 This function returns 0 on success or -1 on error.