1 =head2 guestfs_add_cdrom
3 int guestfs_add_cdrom (guestfs_h *handle,
6 This function adds a virtual CD-ROM disk image to the guest.
8 This is equivalent to the qemu parameter C<-cdrom filename>.
10 This function returns 0 on success or -1 on error.
12 =head2 guestfs_add_drive
14 int guestfs_add_drive (guestfs_h *handle,
15 const char *filename);
17 This function adds a virtual machine disk image C<filename> to the
18 guest. The first time you call this function, the disk appears as IDE
19 disk 0 (C</dev/sda>) in the guest, the second time as C</dev/sdb>, and
22 You don't necessarily need to be root when using libguestfs. However
23 you obviously do need sufficient permissions to access the filename
24 for whatever operations you want to perform (ie. read access if you
25 just want to read the image or write access if you want to modify the
28 This is equivalent to the qemu parameter C<-drive file=filename>.
30 This function returns 0 on success or -1 on error.
32 =head2 guestfs_aug_close
34 int guestfs_aug_close (guestfs_h *handle);
36 Close the current Augeas handle and free up any resources
37 used by it. After calling this, you have to call
38 C<guestfs_aug_init> again before you can use any other
41 This function returns 0 on success or -1 on error.
43 =head2 guestfs_aug_defnode
45 struct guestfs_int_bool *guestfs_aug_defnode (guestfs_h *handle,
50 Defines a variable C<name> whose value is the result of
53 If C<expr> evaluates to an empty nodeset, a node is created,
54 equivalent to calling C<guestfs_aug_set> C<expr>, C<value>.
55 C<name> will be the nodeset containing that single node.
57 On success this returns a pair containing the
58 number of nodes in the nodeset, and a boolean flag
59 if a node was created.
61 This function returns a C<struct guestfs_int_bool *>.
62 I<The caller must call C<guestfs_free_int_bool> after use>.
64 =head2 guestfs_aug_defvar
66 int guestfs_aug_defvar (guestfs_h *handle,
70 Defines an Augeas variable C<name> whose value is the result
71 of evaluating C<expr>. If C<expr> is NULL, then C<name> is
74 On success this returns the number of nodes in C<expr>, or
75 C<0> if C<expr> evaluates to something which is not a nodeset.
77 On error this function returns -1.
79 =head2 guestfs_aug_get
81 char *guestfs_aug_get (guestfs_h *handle,
84 Look up the value associated with C<path>. If C<path>
85 matches exactly one node, the C<value> is returned.
87 This function returns a string or NULL on error.
88 I<The caller must free the returned string after use>.
90 =head2 guestfs_aug_init
92 int guestfs_aug_init (guestfs_h *handle,
96 Create a new Augeas handle for editing configuration files.
97 If there was any previous Augeas handle associated with this
98 guestfs session, then it is closed.
100 You must call this before using any other C<guestfs_aug_*>
103 C<root> is the filesystem root. C<root> must not be NULL,
106 The flags are the same as the flags defined in
107 E<lt>augeas.hE<gt>, the logical I<or> of the following
112 =item C<AUG_SAVE_BACKUP> = 1
114 Keep the original file with a C<.augsave> extension.
116 =item C<AUG_SAVE_NEWFILE> = 2
118 Save changes into a file with extension C<.augnew>, and
119 do not overwrite original. Overrides C<AUG_SAVE_BACKUP>.
121 =item C<AUG_TYPE_CHECK> = 4
123 Typecheck lenses (can be expensive).
125 =item C<AUG_NO_STDINC> = 8
127 Do not use standard load path for modules.
129 =item C<AUG_SAVE_NOOP> = 16
131 Make save a no-op, just record what would have been changed.
133 =item C<AUG_NO_LOAD> = 32
135 Do not load the tree in C<guestfs_aug_init>.
139 To close the handle, you can call C<guestfs_aug_close>.
141 To find out more about Augeas, see L<http://augeas.net/>.
143 This function returns 0 on success or -1 on error.
145 =head2 guestfs_aug_insert
147 int guestfs_aug_insert (guestfs_h *handle,
152 Create a new sibling C<label> for C<path>, inserting it into
153 the tree before or after C<path> (depending on the boolean
156 C<path> must match exactly one existing node in the tree, and
157 C<label> must be a label, ie. not contain C</>, C<*> or end
158 with a bracketed index C<[N]>.
160 This function returns 0 on success or -1 on error.
162 =head2 guestfs_aug_load
164 int guestfs_aug_load (guestfs_h *handle);
166 Load files into the tree.
168 See C<aug_load> in the Augeas documentation for the full gory
171 This function returns 0 on success or -1 on error.
173 =head2 guestfs_aug_ls
175 char **guestfs_aug_ls (guestfs_h *handle,
178 This is just a shortcut for listing C<guestfs_aug_match>
179 C<path/*> and sorting the resulting nodes into alphabetical order.
181 This function returns a NULL-terminated array of strings
182 (like L<environ(3)>), or NULL if there was an error.
183 I<The caller must free the strings and the array after use>.
185 =head2 guestfs_aug_match
187 char **guestfs_aug_match (guestfs_h *handle,
190 Returns a list of paths which match the path expression C<path>.
191 The returned paths are sufficiently qualified so that they match
192 exactly one node in the current tree.
194 This function returns a NULL-terminated array of strings
195 (like L<environ(3)>), or NULL if there was an error.
196 I<The caller must free the strings and the array after use>.
198 =head2 guestfs_aug_mv
200 int guestfs_aug_mv (guestfs_h *handle,
204 Move the node C<src> to C<dest>. C<src> must match exactly
205 one node. C<dest> is overwritten if it exists.
207 This function returns 0 on success or -1 on error.
209 =head2 guestfs_aug_rm
211 int guestfs_aug_rm (guestfs_h *handle,
214 Remove C<path> and all of its children.
216 On success this returns the number of entries which were removed.
218 On error this function returns -1.
220 =head2 guestfs_aug_save
222 int guestfs_aug_save (guestfs_h *handle);
224 This writes all pending changes to disk.
226 The flags which were passed to C<guestfs_aug_init> affect exactly
229 This function returns 0 on success or -1 on error.
231 =head2 guestfs_aug_set
233 int guestfs_aug_set (guestfs_h *handle,
237 Set the value associated with C<path> to C<value>.
239 This function returns 0 on success or -1 on error.
243 char *guestfs_cat (guestfs_h *handle,
246 Return the contents of the file named C<path>.
248 Note that this function cannot correctly handle binary files
249 (specifically, files containing C<\0> character which is treated
250 as end of string). For those you need to use the C<guestfs_read_file>
251 function which has a more complex interface.
253 This function returns a string or NULL on error.
254 I<The caller must free the returned string after use>.
256 Because of the message protocol, there is a transfer limit
257 of somewhere between 2MB and 4MB. To transfer large files you should use
260 =head2 guestfs_config
262 int guestfs_config (guestfs_h *handle,
263 const char *qemuparam,
264 const char *qemuvalue);
266 This can be used to add arbitrary qemu command line parameters
267 of the form C<-param value>. Actually it's not quite arbitrary - we
268 prevent you from setting some parameters which would interfere with
269 parameters that we use.
271 The first character of C<param> string must be a C<-> (dash).
273 C<value> can be NULL.
275 This function returns 0 on success or -1 on error.
277 =head2 guestfs_get_autosync
279 int guestfs_get_autosync (guestfs_h *handle);
281 Get the autosync flag.
283 This function returns a C truth value on success or -1 on error.
285 =head2 guestfs_get_path
287 const char *guestfs_get_path (guestfs_h *handle);
289 Return the current search path.
291 This is always non-NULL. If it wasn't set already, then this will
292 return the default path.
294 This function returns a string or NULL on error.
295 The string is owned by the guest handle and must I<not> be freed.
297 =head2 guestfs_get_verbose
299 int guestfs_get_verbose (guestfs_h *handle);
301 This returns the verbose messages flag.
303 This function returns a C truth value on success or -1 on error.
305 =head2 guestfs_kill_subprocess
307 int guestfs_kill_subprocess (guestfs_h *handle);
309 This kills the qemu subprocess. You should never need to call this.
311 This function returns 0 on success or -1 on error.
313 =head2 guestfs_launch
315 int guestfs_launch (guestfs_h *handle);
317 Internally libguestfs is implemented by running a virtual machine
320 You should call this after configuring the handle
321 (eg. adding drives) but before performing any actions.
323 This function returns 0 on success or -1 on error.
325 =head2 guestfs_list_devices
327 char **guestfs_list_devices (guestfs_h *handle);
329 List all the block devices.
331 The full block device names are returned, eg. C</dev/sda>
333 This function returns a NULL-terminated array of strings
334 (like L<environ(3)>), or NULL if there was an error.
335 I<The caller must free the strings and the array after use>.
337 =head2 guestfs_list_partitions
339 char **guestfs_list_partitions (guestfs_h *handle);
341 List all the partitions detected on all block devices.
343 The full partition device names are returned, eg. C</dev/sda1>
345 This does not return logical volumes. For that you will need to
348 This function returns a NULL-terminated array of strings
349 (like L<environ(3)>), or NULL if there was an error.
350 I<The caller must free the strings and the array after use>.
354 char *guestfs_ll (guestfs_h *handle,
355 const char *directory);
357 List the files in C<directory> (relative to the root directory,
358 there is no cwd) in the format of 'ls -la'.
360 This command is mostly useful for interactive sessions. It
361 is I<not> intended that you try to parse the output string.
363 This function returns a string or NULL on error.
364 I<The caller must free the returned string after use>.
368 char **guestfs_ls (guestfs_h *handle,
369 const char *directory);
371 List the files in C<directory> (relative to the root directory,
372 there is no cwd). The '.' and '..' entries are not returned, but
373 hidden files are shown.
375 This command is mostly useful for interactive sessions. Programs
376 should probably use C<guestfs_readdir> instead.
378 This function returns a NULL-terminated array of strings
379 (like L<environ(3)>), or NULL if there was an error.
380 I<The caller must free the strings and the array after use>.
384 char **guestfs_lvs (guestfs_h *handle);
386 List all the logical volumes detected. This is the equivalent
387 of the L<lvs(8)> command.
389 This returns a list of the logical volume device names
390 (eg. C</dev/VolGroup00/LogVol00>).
392 See also C<guestfs_lvs_full>.
394 This function returns a NULL-terminated array of strings
395 (like L<environ(3)>), or NULL if there was an error.
396 I<The caller must free the strings and the array after use>.
398 =head2 guestfs_lvs_full
400 struct guestfs_lvm_lv_list *guestfs_lvs_full (guestfs_h *handle);
402 List all the logical volumes detected. This is the equivalent
403 of the L<lvs(8)> command. The "full" version includes all fields.
405 This function returns a C<struct guestfs_lvm_lv_list *>.
406 I<The caller must call C<guestfs_free_lvm_lv_list> after use>.
410 int guestfs_mount (guestfs_h *handle,
412 const char *mountpoint);
414 Mount a guest disk at a position in the filesystem. Block devices
415 are named C</dev/sda>, C</dev/sdb> and so on, as they were added to
416 the guest. If those block devices contain partitions, they will have
417 the usual names (eg. C</dev/sda1>). Also LVM C</dev/VG/LV>-style
420 The rules are the same as for L<mount(2)>: A filesystem must
421 first be mounted on C</> before others can be mounted. Other
422 filesystems can only be mounted on directories which already
425 The mounted filesystem is writable, if we have sufficient permissions
426 on the underlying device.
428 The filesystem options C<sync> and C<noatime> are set with this
429 call, in order to improve reliability.
431 This function returns 0 on success or -1 on error.
435 char **guestfs_pvs (guestfs_h *handle);
437 List all the physical volumes detected. This is the equivalent
438 of the L<pvs(8)> command.
440 This returns a list of just the device names that contain
441 PVs (eg. C</dev/sda2>).
443 See also C<guestfs_pvs_full>.
445 This function returns a NULL-terminated array of strings
446 (like L<environ(3)>), or NULL if there was an error.
447 I<The caller must free the strings and the array after use>.
449 =head2 guestfs_pvs_full
451 struct guestfs_lvm_pv_list *guestfs_pvs_full (guestfs_h *handle);
453 List all the physical volumes detected. This is the equivalent
454 of the L<pvs(8)> command. The "full" version includes all fields.
456 This function returns a C<struct guestfs_lvm_pv_list *>.
457 I<The caller must call C<guestfs_free_lvm_pv_list> after use>.
459 =head2 guestfs_read_lines
461 char **guestfs_read_lines (guestfs_h *handle,
464 Return the contents of the file named C<path>.
466 The file contents are returned as a list of lines. Trailing
467 C<LF> and C<CRLF> character sequences are I<not> returned.
469 Note that this function cannot correctly handle binary files
470 (specifically, files containing C<\0> character which is treated
471 as end of line). For those you need to use the C<guestfs_read_file>
472 function which has a more complex interface.
474 This function returns a NULL-terminated array of strings
475 (like L<environ(3)>), or NULL if there was an error.
476 I<The caller must free the strings and the array after use>.
478 =head2 guestfs_set_autosync
480 int guestfs_set_autosync (guestfs_h *handle,
483 If C<autosync> is true, this enables autosync. Libguestfs will make a
484 best effort attempt to run C<guestfs_sync> when the handle is closed
485 (also if the program exits without closing handles).
487 This function returns 0 on success or -1 on error.
489 =head2 guestfs_set_path
491 int guestfs_set_path (guestfs_h *handle,
494 Set the path that libguestfs searches for kernel and initrd.img.
496 The default is C<$libdir/guestfs> unless overridden by setting
497 C<LIBGUESTFS_PATH> environment variable.
499 The string C<path> is stashed in the libguestfs handle, so the caller
500 must make sure it remains valid for the lifetime of the handle.
502 Setting C<path> to C<NULL> restores the default path.
504 This function returns 0 on success or -1 on error.
506 =head2 guestfs_set_verbose
508 int guestfs_set_verbose (guestfs_h *handle,
511 If C<verbose> is true, this turns on verbose messages (to C<stderr>).
513 Verbose messages are disabled unless the environment variable
514 C<LIBGUESTFS_DEBUG> is defined and set to C<1>.
516 This function returns 0 on success or -1 on error.
520 int guestfs_sync (guestfs_h *handle);
522 This syncs the disk, so that any writes are flushed through to the
523 underlying disk image.
525 You should always call this if you have modified a disk image, before
528 This function returns 0 on success or -1 on error.
532 int guestfs_touch (guestfs_h *handle,
535 Touch acts like the L<touch(1)> command. It can be used to
536 update the timestamps on a file, or, if the file does not exist,
537 to create a new zero-length file.
539 This function returns 0 on success or -1 on error.
543 char **guestfs_vgs (guestfs_h *handle);
545 List all the volumes groups detected. This is the equivalent
546 of the L<vgs(8)> command.
548 This returns a list of just the volume group names that were
549 detected (eg. C<VolGroup00>).
551 See also C<guestfs_vgs_full>.
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 =head2 guestfs_vgs_full
559 struct guestfs_lvm_vg_list *guestfs_vgs_full (guestfs_h *handle);
561 List all the volumes groups detected. This is the equivalent
562 of the L<vgs(8)> command. The "full" version includes all fields.
564 This function returns a C<struct guestfs_lvm_vg_list *>.
565 I<The caller must call C<guestfs_free_lvm_vg_list> after use>.
567 =head2 guestfs_wait_ready
569 int guestfs_wait_ready (guestfs_h *handle);
571 Internally libguestfs is implemented by running a virtual machine
574 You should call this after C<guestfs_launch> to wait for the launch
577 This function returns 0 on success or -1 on error.