X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=guestfs-actions.pod;h=755479fd1804c7415bad70a24fb490c437b6c068;hp=32c6d672978c0920078d3edd059fbee4d1adaac1;hb=215041c7178922341ecbfdb23eb203f2bb8c29c4;hpb=adefe14e308a0f8cf73f9c60693a3dbbded157b9 diff --git a/guestfs-actions.pod b/guestfs-actions.pod index 32c6d67..755479f 100644 --- a/guestfs-actions.pod +++ b/guestfs-actions.pod @@ -7,6 +7,11 @@ This function adds a virtual CD-ROM disk image to the guest. This is equivalent to the qemu parameter C<-cdrom filename>. +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C call instead. + This function returns 0 on success or -1 on error. =head2 guestfs_add_drive @@ -25,7 +30,36 @@ for whatever operations you want to perform (ie. read access if you just want to read the image or write access if you want to modify the image). -This is equivalent to the qemu parameter C<-drive file=filename>. +This is equivalent to the qemu parameter C<-drive file=filename,cache=off>. + +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C call instead. + +This function returns 0 on success or -1 on error. + +=head2 guestfs_add_drive_ro + + int guestfs_add_drive_ro (guestfs_h *handle, + const char *filename); + +This adds a drive in snapshot mode, making it effectively +read-only. + +Note that writes to the device are allowed, and will be seen for +the duration of the guestfs handle, but they are written +to a temporary file which is discarded as soon as the guestfs +handle is closed. We don't currently have any method to enable +changes to be committed, although qemu can support this. + +This is equivalent to the qemu parameter +C<-drive file=filename,snapshot=on>. + +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C call instead. This function returns 0 on success or -1 on error. @@ -58,7 +92,8 @@ On success this returns a pair containing the number of nodes in the nodeset, and a boolean flag if a node was created. -This function returns a C. +This function returns a C, +or NULL if there was an error. I after use>. =head2 guestfs_aug_defvar @@ -84,7 +119,7 @@ On error this function returns -1. Look up the value associated with C. If C matches exactly one node, the C is returned. -This function returns a string or NULL on error. +This function returns a string, or NULL on error. I. =head2 guestfs_aug_init @@ -238,6 +273,136 @@ Set the value associated with C to C. This function returns 0 on success or -1 on error. +=head2 guestfs_blockdev_flushbufs + + int guestfs_blockdev_flushbufs (guestfs_h *handle, + const char *device); + +This tells the kernel to flush internal buffers associated +with C. + +This uses the L command. + +This function returns 0 on success or -1 on error. + +=head2 guestfs_blockdev_getbsz + + int guestfs_blockdev_getbsz (guestfs_h *handle, + const char *device); + +This returns the block size of a device. + +(Note this is different from both I and +I). + +This uses the L command. + +On error this function returns -1. + +=head2 guestfs_blockdev_getro + + int guestfs_blockdev_getro (guestfs_h *handle, + const char *device); + +Returns a boolean indicating if the block device is read-only +(true if read-only, false if not). + +This uses the L command. + +This function returns a C truth value on success or -1 on error. + +=head2 guestfs_blockdev_getsize64 + + int64_t guestfs_blockdev_getsize64 (guestfs_h *handle, + const char *device); + +This returns the size of the device in bytes. + +See also C. + +This uses the L command. + +On error this function returns -1. + +=head2 guestfs_blockdev_getss + + int guestfs_blockdev_getss (guestfs_h *handle, + const char *device); + +This returns the size of sectors on a block device. +Usually 512, but can be larger for modern devices. + +(Note, this is not the size in sectors, use C +for that). + +This uses the L command. + +On error this function returns -1. + +=head2 guestfs_blockdev_getsz + + int64_t guestfs_blockdev_getsz (guestfs_h *handle, + const char *device); + +This returns the size of the device in units of 512-byte sectors +(even if the sectorsize isn't 512 bytes ... weird). + +See also C for the real sector size of +the device, and C for the more +useful I. + +This uses the L command. + +On error this function returns -1. + +=head2 guestfs_blockdev_rereadpt + + int guestfs_blockdev_rereadpt (guestfs_h *handle, + const char *device); + +Reread the partition table on C. + +This uses the L command. + +This function returns 0 on success or -1 on error. + +=head2 guestfs_blockdev_setbsz + + int guestfs_blockdev_setbsz (guestfs_h *handle, + const char *device, + int blocksize); + +This sets the block size of a device. + +(Note this is different from both I and +I). + +This uses the L command. + +This function returns 0 on success or -1 on error. + +=head2 guestfs_blockdev_setro + + int guestfs_blockdev_setro (guestfs_h *handle, + const char *device); + +Sets the block device named C to read-only. + +This uses the L command. + +This function returns 0 on success or -1 on error. + +=head2 guestfs_blockdev_setrw + + int guestfs_blockdev_setrw (guestfs_h *handle, + const char *device); + +Sets the block device named C to read-write. + +This uses the L command. + +This function returns 0 on success or -1 on error. + =head2 guestfs_cat char *guestfs_cat (guestfs_h *handle, @@ -247,16 +412,66 @@ Return the contents of the file named C. Note that this function cannot correctly handle binary files (specifically, files containing C<\0> character which is treated -as end of string). For those you need to use the C +as end of string). For those you need to use the C function which has a more complex interface. -This function returns a string or NULL on error. +This function returns a string, or NULL on error. I. Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. To transfer large files you should use FTP. +=head2 guestfs_checksum + + char *guestfs_checksum (guestfs_h *handle, + const char *csumtype, + const char *path); + +This call computes the MD5, SHAx or CRC checksum of the +file named C. + +The type of checksum to compute is given by the C +parameter which must have one of the following values: + +=over 4 + +=item C + +Compute the cyclic redundancy check (CRC) specified by POSIX +for the C command. + +=item C + +Compute the MD5 hash (using the C program). + +=item C + +Compute the SHA1 hash (using the C program). + +=item C + +Compute the SHA224 hash (using the C program). + +=item C + +Compute the SHA256 hash (using the C program). + +=item C + +Compute the SHA384 hash (using the C program). + +=item C + +Compute the SHA512 hash (using the C program). + +=back + +The checksum is returned as a printable string. + +This function returns a string, or NULL on error. +I. + =head2 guestfs_chmod int guestfs_chmod (guestfs_h *handle, @@ -283,6 +498,66 @@ yourself (Augeas support makes this relatively easy). This function returns 0 on success or -1 on error. +=head2 guestfs_command + + char *guestfs_command (guestfs_h *handle, + char * const* const arguments); + +This call runs a command from the guest filesystem. The +filesystem must be mounted, and must contain a compatible +operating system (ie. something Linux, with the same +or compatible processor architecture). + +The single parameter is an argv-style list of arguments. +The first element is the name of the program to run. +Subsequent elements are parameters. The list must be +non-empty (ie. must contain a program name). Note that +the command runs directly, and is I invoked via +the shell (see C). + +The return value is anything printed to I by +the command. + +If the command returns a non-zero exit status, then +this function returns an error message. The error message +string is the content of I from the command. + +The C<$PATH> environment variable will contain at least +C and C. If you require a program from +another location, you should provide the full path in the +first parameter. + +Shared libraries and data files required by the program +must be available on filesystems which are mounted in the +correct places. It is the caller's responsibility to ensure +all filesystems that are needed are mounted at the right +locations. + +This function returns a string, or NULL on error. +I. + +Because of the message protocol, there is a transfer limit +of somewhere between 2MB and 4MB. To transfer large files you should use +FTP. + +=head2 guestfs_command_lines + + char **guestfs_command_lines (guestfs_h *handle, + char * const* const arguments); + +This is the same as C, but splits the +result into a list of lines. + +See also: C + +This function returns a NULL-terminated array of strings +(like L), or NULL if there was an error. +I. + +Because of the message protocol, there is a transfer limit +of somewhere between 2MB and 4MB. To transfer large files you should use +FTP. + =head2 guestfs_config int guestfs_config (guestfs_h *handle, @@ -300,165 +575,526 @@ C can be NULL. This function returns 0 on success or -1 on error. -=head2 guestfs_exists - - int guestfs_exists (guestfs_h *handle, - const char *path); - -This returns C if and only if there is a file, directory -(or anything) with the given C name. +=head2 guestfs_cp -See also C, C, C. + int guestfs_cp (guestfs_h *handle, + const char *src, + const char *dest); -This function returns a C truth value on success or -1 on error. +This copies a file from C to C where C is +either a destination filename or destination directory. -=head2 guestfs_file +This function returns 0 on success or -1 on error. - char *guestfs_file (guestfs_h *handle, - const char *path); +=head2 guestfs_cp_a -This call uses the standard L command to determine -the type or contents of the file. This also works on devices, -for example to find out whether a partition contains a filesystem. + int guestfs_cp_a (guestfs_h *handle, + const char *src, + const char *dest); -The exact command which runs is C. Note in -particular that the filename is not prepended to the output -(the C<-b> option). +This copies a file or directory from C to C +recursively using the C command. -This function returns a string or NULL on error. -I. +This function returns 0 on success or -1 on error. -=head2 guestfs_get_autosync +=head2 guestfs_debug - int guestfs_get_autosync (guestfs_h *handle); + char *guestfs_debug (guestfs_h *handle, + const char *subcmd, + char * const* const extraargs); -Get the autosync flag. +The C command exposes some internals of +C (the guestfs daemon) that runs inside the +qemu subprocess. -This function returns a C truth value on success or -1 on error. +There is no comprehensive help for this command. You have +to look at the file C in the libguestfs source +to find out what you can do. -=head2 guestfs_get_path +This function returns a string, or NULL on error. +I. - const char *guestfs_get_path (guestfs_h *handle); +=head2 guestfs_dmesg -Return the current search path. + char *guestfs_dmesg (guestfs_h *handle); -This is always non-NULL. If it wasn't set already, then this will -return the default path. +This returns the kernel messages (C output) from +the guest kernel. This is sometimes useful for extended +debugging of problems. -This function returns a string or NULL on error. -The string is owned by the guest handle and must I be freed. +Another way to get the same information is to enable +verbose messages with C or by setting +the environment variable C before +running the program. -=head2 guestfs_get_verbose +This function returns a string, or NULL on error. +I. - int guestfs_get_verbose (guestfs_h *handle); +=head2 guestfs_download -This returns the verbose messages flag. + int guestfs_download (guestfs_h *handle, + const char *remotefilename, + const char *filename); -This function returns a C truth value on success or -1 on error. +Download file C and save it as C +on the local machine. -=head2 guestfs_is_dir +C can also be a named pipe. - int guestfs_is_dir (guestfs_h *handle, - const char *path); +See also C, C. -This returns C if and only if there is a directory -with the given C name. Note that it returns false for -other objects like files. +This function returns 0 on success or -1 on error. -See also C. +=head2 guestfs_drop_caches -This function returns a C truth value on success or -1 on error. + int guestfs_drop_caches (guestfs_h *handle, + int whattodrop); -=head2 guestfs_is_file +This instructs the guest kernel to drop its page cache, +and/or dentries and inode caches. The parameter C +tells the kernel what precisely to drop, see +L - int guestfs_is_file (guestfs_h *handle, - const char *path); +Setting C to 3 should drop everything. -This returns C if and only if there is a file -with the given C name. Note that it returns false for -other objects like directories. +This automatically calls L before the operation, +so that the maximum guest memory is freed. -See also C. +This function returns 0 on success or -1 on error. -This function returns a C truth value on success or -1 on error. +=head2 guestfs_e2fsck_f -=head2 guestfs_kill_subprocess + int guestfs_e2fsck_f (guestfs_h *handle, + const char *device); - int guestfs_kill_subprocess (guestfs_h *handle); +This runs C, ie. runs the ext2/ext3 +filesystem checker on C, noninteractively (C<-p>), +even if the filesystem appears to be clean (C<-f>). -This kills the qemu subprocess. You should never need to call this. +This command is only needed because of C +(q.v.). Normally you should use C. This function returns 0 on success or -1 on error. -=head2 guestfs_launch +=head2 guestfs_end_busy - int guestfs_launch (guestfs_h *handle); + int guestfs_end_busy (guestfs_h *handle); -Internally libguestfs is implemented by running a virtual machine -using L. +This sets the state to C, or if in C then it leaves the +state as is. This is only used when implementing +actions using the low-level API. -You should call this after configuring the handle -(eg. adding drives) but before performing any actions. +For more information on states, see L. This function returns 0 on success or -1 on error. -=head2 guestfs_list_devices - - char **guestfs_list_devices (guestfs_h *handle); +=head2 guestfs_equal -List all the block devices. + int guestfs_equal (guestfs_h *handle, + const char *file1, + const char *file2); -The full block device names are returned, eg. C +This compares the two files C and C and returns +true if their content is exactly equal, or false otherwise. -This function returns a NULL-terminated array of strings -(like L), or NULL if there was an error. -I. +The external L program is used for the comparison. -=head2 guestfs_list_partitions +This function returns a C truth value on success or -1 on error. - char **guestfs_list_partitions (guestfs_h *handle); +=head2 guestfs_exists -List all the partitions detected on all block devices. + int guestfs_exists (guestfs_h *handle, + const char *path); -The full partition device names are returned, eg. C +This returns C if and only if there is a file, directory +(or anything) with the given C name. -This does not return logical volumes. For that you will need to -call C. +See also C, C, C. -This function returns a NULL-terminated array of strings -(like L), or NULL if there was an error. -I. +This function returns a C truth value on success or -1 on error. -=head2 guestfs_ll +=head2 guestfs_file - char *guestfs_ll (guestfs_h *handle, - const char *directory); + char *guestfs_file (guestfs_h *handle, + const char *path); -List the files in C (relative to the root directory, -there is no cwd) in the format of 'ls -la'. +This call uses the standard L command to determine +the type or contents of the file. This also works on devices, +for example to find out whether a partition contains a filesystem. -This command is mostly useful for interactive sessions. It -is I intended that you try to parse the output string. +The exact command which runs is C. Note in +particular that the filename is not prepended to the output +(the C<-b> option). -This function returns a string or NULL on error. +This function returns a string, or NULL on error. I. -=head2 guestfs_ls +=head2 guestfs_find - char **guestfs_ls (guestfs_h *handle, + char **guestfs_find (guestfs_h *handle, const char *directory); -List the files in C (relative to the root directory, -there is no cwd). The '.' and '..' entries are not returned, but -hidden files are shown. +This command lists out all files and directories, recursively, +starting at C. It is essentially equivalent to +running the shell command C but some +post-processing happens on the output, described below. -This command is mostly useful for interactive sessions. Programs -should probably use C instead. +This returns a list of strings I. Thus +if the directory structure was: + + /tmp/a + /tmp/b + /tmp/c/d + +then the returned list from C C would be +4 elements: + + a + b + c + c/d + +If C is not a directory, then this command returns +an error. + +The returned list is sorted. + +This function returns a NULL-terminated array of strings +(like L), or NULL if there was an error. +I. + +=head2 guestfs_fsck + + int guestfs_fsck (guestfs_h *handle, + const char *fstype, + const char *device); + +This runs the filesystem checker (fsck) on C which +should have filesystem type C. + +The returned integer is the status. See L for the +list of status codes from C. + +Notes: + +=over 4 + +=item * + +Multiple status codes can be summed together. + +=item * + +A non-zero return code can mean "success", for example if +errors have been corrected on the filesystem. + +=item * + +Checking or repairing NTFS volumes is not supported +(by linux-ntfs). + +=back + +This command is entirely equivalent to running C. + +On error this function returns -1. + +=head2 guestfs_get_append + + const char *guestfs_get_append (guestfs_h *handle); + +Return the additional kernel options which are added to the +guest kernel command line. + +If C then no options are added. + +This function returns a string, or NULL on error. +The string is owned by the guest handle and must I be freed. + +=head2 guestfs_get_autosync + + int guestfs_get_autosync (guestfs_h *handle); + +Get the autosync flag. + +This function returns a C truth value on success or -1 on error. + +=head2 guestfs_get_e2label + + char *guestfs_get_e2label (guestfs_h *handle, + const char *device); + +This returns the ext2/3/4 filesystem label of the filesystem on +C. + +This function returns a string, or NULL on error. +I. + +=head2 guestfs_get_e2uuid + + char *guestfs_get_e2uuid (guestfs_h *handle, + const char *device); + +This returns the ext2/3/4 filesystem UUID of the filesystem on +C. + +This function returns a string, or NULL on error. +I. + +=head2 guestfs_get_path + + const char *guestfs_get_path (guestfs_h *handle); + +Return the current search path. + +This is always non-NULL. If it wasn't set already, then this will +return the default path. + +This function returns a string, or NULL on error. +The string is owned by the guest handle and must I be freed. + +=head2 guestfs_get_qemu + + const char *guestfs_get_qemu (guestfs_h *handle); + +Return the current qemu binary. + +This is always non-NULL. If it wasn't set already, then this will +return the default qemu binary name. + +This function returns a string, or NULL on error. +The string is owned by the guest handle and must I be freed. + +=head2 guestfs_get_state + + int guestfs_get_state (guestfs_h *handle); + +This returns the current state as an opaque integer. This is +only useful for printing debug and internal error messages. + +For more information on states, see L. + +On error this function returns -1. + +=head2 guestfs_get_verbose + + int guestfs_get_verbose (guestfs_h *handle); + +This returns the verbose messages flag. + +This function returns a C truth value on success or -1 on error. + +=head2 guestfs_glob_expand + + char **guestfs_glob_expand (guestfs_h *handle, + const char *pattern); + +This command searches for all the pathnames matching +C according to the wildcard expansion rules +used by the shell. + +If no paths match, then this returns an empty list +(note: not an error). + +It is just a wrapper around the C L function +with flags C. +See that manual page for more details. + +This function returns a NULL-terminated array of strings +(like L), or NULL if there was an error. +I. + +=head2 guestfs_grub_install + + int guestfs_grub_install (guestfs_h *handle, + const char *root, + const char *device); + +This command installs GRUB (the Grand Unified Bootloader) on +C, with the root directory being C. + +This function returns 0 on success or -1 on error. + +=head2 guestfs_hexdump + + char *guestfs_hexdump (guestfs_h *handle, + const char *path); + +This runs C on the given C. The result is +the human-readable, canonical hex dump of the file. + +This function returns a string, or NULL on error. +I. + +Because of the message protocol, there is a transfer limit +of somewhere between 2MB and 4MB. To transfer large files you should use +FTP. + +=head2 guestfs_is_busy + + int guestfs_is_busy (guestfs_h *handle); + +This returns true iff this handle is busy processing a command +(in the C state). + +For more information on states, see L. + +This function returns a C truth value on success or -1 on error. + +=head2 guestfs_is_config + + int guestfs_is_config (guestfs_h *handle); + +This returns true iff this handle is being configured +(in the C state). + +For more information on states, see L. + +This function returns a C truth value on success or -1 on error. + +=head2 guestfs_is_dir + + int guestfs_is_dir (guestfs_h *handle, + const char *path); + +This returns C if and only if there is a directory +with the given C name. Note that it returns false for +other objects like files. + +See also C. + +This function returns a C truth value on success or -1 on error. + +=head2 guestfs_is_file + + int guestfs_is_file (guestfs_h *handle, + const char *path); + +This returns C if and only if there is a file +with the given C name. Note that it returns false for +other objects like directories. + +See also C. + +This function returns a C truth value on success or -1 on error. + +=head2 guestfs_is_launching + + int guestfs_is_launching (guestfs_h *handle); + +This returns true iff this handle is launching the subprocess +(in the C state). + +For more information on states, see L. + +This function returns a C truth value on success or -1 on error. + +=head2 guestfs_is_ready + + int guestfs_is_ready (guestfs_h *handle); + +This returns true iff this handle is ready to accept commands +(in the C state). + +For more information on states, see L. + +This function returns a C truth value on success or -1 on error. + +=head2 guestfs_kill_subprocess + + int guestfs_kill_subprocess (guestfs_h *handle); + +This kills the qemu subprocess. You should never need to call this. + +This function returns 0 on success or -1 on error. + +=head2 guestfs_launch + + int guestfs_launch (guestfs_h *handle); + +Internally libguestfs is implemented by running a virtual machine +using L. + +You should call this after configuring the handle +(eg. adding drives) but before performing any actions. + +This function returns 0 on success or -1 on error. + +=head2 guestfs_list_devices + + char **guestfs_list_devices (guestfs_h *handle); + +List all the block devices. + +The full block device names are returned, eg. C This function returns a NULL-terminated array of strings (like L), or NULL if there was an error. I. +=head2 guestfs_list_partitions + + char **guestfs_list_partitions (guestfs_h *handle); + +List all the partitions detected on all block devices. + +The full partition device names are returned, eg. C + +This does not return logical volumes. For that you will need to +call C. + +This function returns a NULL-terminated array of strings +(like L), or NULL if there was an error. +I. + +=head2 guestfs_ll + + char *guestfs_ll (guestfs_h *handle, + const char *directory); + +List the files in C (relative to the root directory, +there is no cwd) in the format of 'ls -la'. + +This command is mostly useful for interactive sessions. It +is I intended that you try to parse the output string. + +This function returns a string, or NULL on error. +I. + +=head2 guestfs_ls + + char **guestfs_ls (guestfs_h *handle, + const char *directory); + +List the files in C (relative to the root directory, +there is no cwd). The '.' and '..' entries are not returned, but +hidden files are shown. + +This command is mostly useful for interactive sessions. Programs +should probably use C instead. + +This function returns a NULL-terminated array of strings +(like L), or NULL if there was an error. +I. + +=head2 guestfs_lstat + + struct guestfs_stat *guestfs_lstat (guestfs_h *handle, + const char *path); + +Returns file information for the given C. + +This is the same as C except that if C +is a symbolic link, then the link is stat-ed, not the file it +refers to. + +This is the same as the C system call. + +This function returns a C +(see L and Eguestfs-structs.hE), +or NULL if there was an error. +I after use>. + =head2 guestfs_lvcreate int guestfs_lvcreate (guestfs_h *handle, @@ -483,6 +1119,31 @@ This function returns 0 on success or -1 on error. B. +=head2 guestfs_lvremove + + int guestfs_lvremove (guestfs_h *handle, + const char *device); + +Remove an LVM logical volume C, where C is +the path to the LV, such as C. + +You can also remove all LVs in a volume group by specifying +the VG name, C. + +This function returns 0 on success or -1 on error. + +=head2 guestfs_lvresize + + int guestfs_lvresize (guestfs_h *handle, + const char *device, + int mbytes); + +This resizes (expands or shrinks) an existing LVM logical +volume to C. When reducing, data in the reduced part +is lost. + +This function returns 0 on success or -1 on error. + =head2 guestfs_lvs char **guestfs_lvs (guestfs_h *handle); @@ -506,7 +1167,9 @@ I. List all the logical volumes detected. This is the equivalent of the L command. The "full" version includes all fields. -This function returns a C. +This function returns a C +(see Eguestfs-structs.hE), +or NULL if there was an error. I after use>. =head2 guestfs_mkdir @@ -528,6 +1191,33 @@ as necessary. This is like the C shell command. This function returns 0 on success or -1 on error. +=head2 guestfs_mkdtemp + + char *guestfs_mkdtemp (guestfs_h *handle, + const char *template); + +This command creates a temporary directory. The +C