1cd4701e255d89af3070bdea2b2b75e300c2f6ca
[libguestfs.git] / guestfs-actions.pod
1 =head2 guestfs_add_cdrom
2
3  int guestfs_add_cdrom (guestfs_h *handle,
4                 const char *filename);
5
6 This function adds a virtual CD-ROM disk image to the guest.
7
8 This is equivalent to the qemu parameter C<-cdrom filename>.
9
10 This function returns 0 on success or -1 on error.
11
12 =head2 guestfs_add_drive
13
14  int guestfs_add_drive (guestfs_h *handle,
15                 const char *filename);
16
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
20 so on.
21
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
26 image).
27
28 This is equivalent to the qemu parameter C<-drive file=filename>.
29
30 This function returns 0 on success or -1 on error.
31
32 =head2 guestfs_aug_close
33
34  int guestfs_aug_close (guestfs_h *handle);
35
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
39 Augeas functions.
40
41 This function returns 0 on success or -1 on error.
42
43 =head2 guestfs_aug_defnode
44
45  struct guestfs_int_bool *guestfs_aug_defnode (guestfs_h *handle,
46                 const char *name,
47                 const char *expr,
48                 const char *val);
49
50 Defines a variable C<name> whose value is the result of
51 evaluating C<expr>.
52
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.
56
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.
60
61 This function returns a C<struct guestfs_int_bool *>,
62 or NULL if there was an error.
63 I<The caller must call C<guestfs_free_int_bool> after use>.
64
65 =head2 guestfs_aug_defvar
66
67  int guestfs_aug_defvar (guestfs_h *handle,
68                 const char *name,
69                 const char *expr);
70
71 Defines an Augeas variable C<name> whose value is the result
72 of evaluating C<expr>.  If C<expr> is NULL, then C<name> is
73 undefined.
74
75 On success this returns the number of nodes in C<expr>, or
76 C<0> if C<expr> evaluates to something which is not a nodeset.
77
78 On error this function returns -1.
79
80 =head2 guestfs_aug_get
81
82  char *guestfs_aug_get (guestfs_h *handle,
83                 const char *path);
84
85 Look up the value associated with C<path>.  If C<path>
86 matches exactly one node, the C<value> is returned.
87
88 This function returns a string, or NULL on error.
89 I<The caller must free the returned string after use>.
90
91 =head2 guestfs_aug_init
92
93  int guestfs_aug_init (guestfs_h *handle,
94                 const char *root,
95                 int flags);
96
97 Create a new Augeas handle for editing configuration files.
98 If there was any previous Augeas handle associated with this
99 guestfs session, then it is closed.
100
101 You must call this before using any other C<guestfs_aug_*>
102 commands.
103
104 C<root> is the filesystem root.  C<root> must not be NULL,
105 use C</> instead.
106
107 The flags are the same as the flags defined in
108 E<lt>augeas.hE<gt>, the logical I<or> of the following
109 integers:
110
111 =over 4
112
113 =item C<AUG_SAVE_BACKUP> = 1
114
115 Keep the original file with a C<.augsave> extension.
116
117 =item C<AUG_SAVE_NEWFILE> = 2
118
119 Save changes into a file with extension C<.augnew>, and
120 do not overwrite original.  Overrides C<AUG_SAVE_BACKUP>.
121
122 =item C<AUG_TYPE_CHECK> = 4
123
124 Typecheck lenses (can be expensive).
125
126 =item C<AUG_NO_STDINC> = 8
127
128 Do not use standard load path for modules.
129
130 =item C<AUG_SAVE_NOOP> = 16
131
132 Make save a no-op, just record what would have been changed.
133
134 =item C<AUG_NO_LOAD> = 32
135
136 Do not load the tree in C<guestfs_aug_init>.
137
138 =back
139
140 To close the handle, you can call C<guestfs_aug_close>.
141
142 To find out more about Augeas, see L<http://augeas.net/>.
143
144 This function returns 0 on success or -1 on error.
145
146 =head2 guestfs_aug_insert
147
148  int guestfs_aug_insert (guestfs_h *handle,
149                 const char *path,
150                 const char *label,
151                 int before);
152
153 Create a new sibling C<label> for C<path>, inserting it into
154 the tree before or after C<path> (depending on the boolean
155 flag C<before>).
156
157 C<path> must match exactly one existing node in the tree, and
158 C<label> must be a label, ie. not contain C</>, C<*> or end
159 with a bracketed index C<[N]>.
160
161 This function returns 0 on success or -1 on error.
162
163 =head2 guestfs_aug_load
164
165  int guestfs_aug_load (guestfs_h *handle);
166
167 Load files into the tree.
168
169 See C<aug_load> in the Augeas documentation for the full gory
170 details.
171
172 This function returns 0 on success or -1 on error.
173
174 =head2 guestfs_aug_ls
175
176  char **guestfs_aug_ls (guestfs_h *handle,
177                 const char *path);
178
179 This is just a shortcut for listing C<guestfs_aug_match>
180 C<path/*> and sorting the resulting nodes into alphabetical order.
181
182 This function returns a NULL-terminated array of strings
183 (like L<environ(3)>), or NULL if there was an error.
184 I<The caller must free the strings and the array after use>.
185
186 =head2 guestfs_aug_match
187
188  char **guestfs_aug_match (guestfs_h *handle,
189                 const char *path);
190
191 Returns a list of paths which match the path expression C<path>.
192 The returned paths are sufficiently qualified so that they match
193 exactly one node in the current tree.
194
195 This function returns a NULL-terminated array of strings
196 (like L<environ(3)>), or NULL if there was an error.
197 I<The caller must free the strings and the array after use>.
198
199 =head2 guestfs_aug_mv
200
201  int guestfs_aug_mv (guestfs_h *handle,
202                 const char *src,
203                 const char *dest);
204
205 Move the node C<src> to C<dest>.  C<src> must match exactly
206 one node.  C<dest> is overwritten if it exists.
207
208 This function returns 0 on success or -1 on error.
209
210 =head2 guestfs_aug_rm
211
212  int guestfs_aug_rm (guestfs_h *handle,
213                 const char *path);
214
215 Remove C<path> and all of its children.
216
217 On success this returns the number of entries which were removed.
218
219 On error this function returns -1.
220
221 =head2 guestfs_aug_save
222
223  int guestfs_aug_save (guestfs_h *handle);
224
225 This writes all pending changes to disk.
226
227 The flags which were passed to C<guestfs_aug_init> affect exactly
228 how files are saved.
229
230 This function returns 0 on success or -1 on error.
231
232 =head2 guestfs_aug_set
233
234  int guestfs_aug_set (guestfs_h *handle,
235                 const char *path,
236                 const char *val);
237
238 Set the value associated with C<path> to C<value>.
239
240 This function returns 0 on success or -1 on error.
241
242 =head2 guestfs_blockdev_flushbufs
243
244  int guestfs_blockdev_flushbufs (guestfs_h *handle,
245                 const char *device);
246
247 This tells the kernel to flush internal buffers associated
248 with C<device>.
249
250 This uses the L<blockdev(8)> command.
251
252 This function returns 0 on success or -1 on error.
253
254 =head2 guestfs_blockdev_getbsz
255
256  int guestfs_blockdev_getbsz (guestfs_h *handle,
257                 const char *device);
258
259 This returns the block size of a device.
260
261 (Note this is different from both I<size in blocks> and
262 I<filesystem block size>).
263
264 This uses the L<blockdev(8)> command.
265
266 On error this function returns -1.
267
268 =head2 guestfs_blockdev_getro
269
270  int guestfs_blockdev_getro (guestfs_h *handle,
271                 const char *device);
272
273 Returns a boolean indicating if the block device is read-only
274 (true if read-only, false if not).
275
276 This uses the L<blockdev(8)> command.
277
278 This function returns a C truth value on success or -1 on error.
279
280 =head2 guestfs_blockdev_getsize64
281
282  int64_t guestfs_blockdev_getsize64 (guestfs_h *handle,
283                 const char *device);
284
285 This returns the size of the device in bytes.
286
287 See also C<guestfs_blockdev_getsz>.
288
289 This uses the L<blockdev(8)> command.
290
291 On error this function returns -1.
292
293 =head2 guestfs_blockdev_getss
294
295  int guestfs_blockdev_getss (guestfs_h *handle,
296                 const char *device);
297
298 This returns the size of sectors on a block device.
299 Usually 512, but can be larger for modern devices.
300
301 (Note, this is not the size in sectors, use C<guestfs_blockdev_getsz>
302 for that).
303
304 This uses the L<blockdev(8)> command.
305
306 On error this function returns -1.
307
308 =head2 guestfs_blockdev_getsz
309
310  int64_t guestfs_blockdev_getsz (guestfs_h *handle,
311                 const char *device);
312
313 This returns the size of the device in units of 512-byte sectors
314 (even if the sectorsize isn't 512 bytes ... weird).
315
316 See also C<guestfs_blockdev_getss> for the real sector size of
317 the device, and C<guestfs_blockdev_getsize64> for the more
318 useful I<size in bytes>.
319
320 This uses the L<blockdev(8)> command.
321
322 On error this function returns -1.
323
324 =head2 guestfs_blockdev_rereadpt
325
326  int guestfs_blockdev_rereadpt (guestfs_h *handle,
327                 const char *device);
328
329 Reread the partition table on C<device>.
330
331 This uses the L<blockdev(8)> command.
332
333 This function returns 0 on success or -1 on error.
334
335 =head2 guestfs_blockdev_setbsz
336
337  int guestfs_blockdev_setbsz (guestfs_h *handle,
338                 const char *device,
339                 int blocksize);
340
341 This sets the block size of a device.
342
343 (Note this is different from both I<size in blocks> and
344 I<filesystem block size>).
345
346 This uses the L<blockdev(8)> command.
347
348 This function returns 0 on success or -1 on error.
349
350 =head2 guestfs_blockdev_setro
351
352  int guestfs_blockdev_setro (guestfs_h *handle,
353                 const char *device);
354
355 Sets the block device named C<device> to read-only.
356
357 This uses the L<blockdev(8)> command.
358
359 This function returns 0 on success or -1 on error.
360
361 =head2 guestfs_blockdev_setrw
362
363  int guestfs_blockdev_setrw (guestfs_h *handle,
364                 const char *device);
365
366 Sets the block device named C<device> to read-write.
367
368 This uses the L<blockdev(8)> command.
369
370 This function returns 0 on success or -1 on error.
371
372 =head2 guestfs_cat
373
374  char *guestfs_cat (guestfs_h *handle,
375                 const char *path);
376
377 Return the contents of the file named C<path>.
378
379 Note that this function cannot correctly handle binary files
380 (specifically, files containing C<\0> character which is treated
381 as end of string).  For those you need to use the C<guestfs_download>
382 function which has a more complex interface.
383
384 This function returns a string, or NULL on error.
385 I<The caller must free the returned string after use>.
386
387 Because of the message protocol, there is a transfer limit 
388 of somewhere between 2MB and 4MB.  To transfer large files you should use
389 FTP.
390
391 =head2 guestfs_checksum
392
393  char *guestfs_checksum (guestfs_h *handle,
394                 const char *csumtype,
395                 const char *path);
396
397 This call computes the MD5, SHAx or CRC checksum of the
398 file named C<path>.
399
400 The type of checksum to compute is given by the C<csumtype>
401 parameter which must have one of the following values:
402
403 =over 4
404
405 =item C<crc>
406
407 Compute the cyclic redundancy check (CRC) specified by POSIX
408 for the C<cksum> command.
409
410 =item C<md5>
411
412 Compute the MD5 hash (using the C<md5sum> program).
413
414 =item C<sha1>
415
416 Compute the SHA1 hash (using the C<sha1sum> program).
417
418 =item C<sha224>
419
420 Compute the SHA224 hash (using the C<sha224sum> program).
421
422 =item C<sha256>
423
424 Compute the SHA256 hash (using the C<sha256sum> program).
425
426 =item C<sha384>
427
428 Compute the SHA384 hash (using the C<sha384sum> program).
429
430 =item C<sha512>
431
432 Compute the SHA512 hash (using the C<sha512sum> program).
433
434 =back
435
436 The checksum is returned as a printable string.
437
438 This function returns a string, or NULL on error.
439 I<The caller must free the returned string after use>.
440
441 =head2 guestfs_chmod
442
443  int guestfs_chmod (guestfs_h *handle,
444                 int mode,
445                 const char *path);
446
447 Change the mode (permissions) of C<path> to C<mode>.  Only
448 numeric modes are supported.
449
450 This function returns 0 on success or -1 on error.
451
452 =head2 guestfs_chown
453
454  int guestfs_chown (guestfs_h *handle,
455                 int owner,
456                 int group,
457                 const char *path);
458
459 Change the file owner to C<owner> and group to C<group>.
460
461 Only numeric uid and gid are supported.  If you want to use
462 names, you will need to locate and parse the password file
463 yourself (Augeas support makes this relatively easy).
464
465 This function returns 0 on success or -1 on error.
466
467 =head2 guestfs_command
468
469  char *guestfs_command (guestfs_h *handle,
470                 char * const* const arguments);
471
472 This call runs a command from the guest filesystem.  The
473 filesystem must be mounted, and must contain a compatible
474 operating system (ie. something Linux, with the same
475 or compatible processor architecture).
476
477 The single parameter is an argv-style list of arguments.
478 The first element is the name of the program to run.
479 Subsequent elements are parameters.  The list must be
480 non-empty (ie. must contain a program name).
481
482 The C<$PATH> environment variable will contain at least
483 C</usr/bin> and C</bin>.  If you require a program from
484 another location, you should provide the full path in the
485 first parameter.
486
487 Shared libraries and data files required by the program
488 must be available on filesystems which are mounted in the
489 correct places.  It is the caller's responsibility to ensure
490 all filesystems that are needed are mounted at the right
491 locations.
492
493 This function returns a string, or NULL on error.
494 I<The caller must free the returned string after use>.
495
496 =head2 guestfs_command_lines
497
498  char **guestfs_command_lines (guestfs_h *handle,
499                 char * const* const arguments);
500
501 This is the same as C<guestfs_command>, but splits the
502 result into a list of lines.
503
504 This function returns a NULL-terminated array of strings
505 (like L<environ(3)>), or NULL if there was an error.
506 I<The caller must free the strings and the array after use>.
507
508 =head2 guestfs_config
509
510  int guestfs_config (guestfs_h *handle,
511                 const char *qemuparam,
512                 const char *qemuvalue);
513
514 This can be used to add arbitrary qemu command line parameters
515 of the form C<-param value>.  Actually it's not quite arbitrary - we
516 prevent you from setting some parameters which would interfere with
517 parameters that we use.
518
519 The first character of C<param> string must be a C<-> (dash).
520
521 C<value> can be NULL.
522
523 This function returns 0 on success or -1 on error.
524
525 =head2 guestfs_cp
526
527  int guestfs_cp (guestfs_h *handle,
528                 const char *src,
529                 const char *dest);
530
531 This copies a file from C<src> to C<dest> where C<dest> is
532 either a destination filename or destination directory.
533
534 This function returns 0 on success or -1 on error.
535
536 =head2 guestfs_cp_a
537
538  int guestfs_cp_a (guestfs_h *handle,
539                 const char *src,
540                 const char *dest);
541
542 This copies a file or directory from C<src> to C<dest>
543 recursively using the C<cp -a> command.
544
545 This function returns 0 on success or -1 on error.
546
547 =head2 guestfs_debug
548
549  char *guestfs_debug (guestfs_h *handle,
550                 const char *subcmd,
551                 char * const* const extraargs);
552
553 The C<guestfs_debug> command exposes some internals of
554 C<guestfsd> (the guestfs daemon) that runs inside the
555 qemu subprocess.
556
557 There is no comprehensive help for this command.  You have
558 to look at the file C<daemon/debug.c> in the libguestfs source
559 to find out what you can do.
560
561 This function returns a string, or NULL on error.
562 I<The caller must free the returned string after use>.
563
564 =head2 guestfs_download
565
566  int guestfs_download (guestfs_h *handle,
567                 const char *remotefilename,
568                 const char *filename);
569
570 Download file C<remotefilename> and save it as C<filename>
571 on the local machine.
572
573 C<filename> can also be a named pipe.
574
575 See also C<guestfs_upload>, C<guestfs_cat>.
576
577 This function returns 0 on success or -1 on error.
578
579 =head2 guestfs_exists
580
581  int guestfs_exists (guestfs_h *handle,
582                 const char *path);
583
584 This returns C<true> if and only if there is a file, directory
585 (or anything) with the given C<path> name.
586
587 See also C<guestfs_is_file>, C<guestfs_is_dir>, C<guestfs_stat>.
588
589 This function returns a C truth value on success or -1 on error.
590
591 =head2 guestfs_file
592
593  char *guestfs_file (guestfs_h *handle,
594                 const char *path);
595
596 This call uses the standard L<file(1)> command to determine
597 the type or contents of the file.  This also works on devices,
598 for example to find out whether a partition contains a filesystem.
599
600 The exact command which runs is C<file -bsL path>.  Note in
601 particular that the filename is not prepended to the output
602 (the C<-b> option).
603
604 This function returns a string, or NULL on error.
605 I<The caller must free the returned string after use>.
606
607 =head2 guestfs_fsck
608
609  int guestfs_fsck (guestfs_h *handle,
610                 const char *fstype,
611                 const char *device);
612
613 This runs the filesystem checker (fsck) on C<device> which
614 should have filesystem type C<fstype>.
615
616 The returned integer is the status.  See L<fsck(8)> for the
617 list of status codes from C<fsck>.
618
619 Notes:
620
621 =over 4
622
623 =item *
624
625 Multiple status codes can be summed together.
626
627 =item *
628
629 A non-zero return code can mean "success", for example if
630 errors have been corrected on the filesystem.
631
632 =item *
633
634 Checking or repairing NTFS volumes is not supported
635 (by linux-ntfs).
636
637 =back
638
639 This command is entirely equivalent to running C<fsck -a -t fstype device>.
640
641 On error this function returns -1.
642
643 =head2 guestfs_get_autosync
644
645  int guestfs_get_autosync (guestfs_h *handle);
646
647 Get the autosync flag.
648
649 This function returns a C truth value on success or -1 on error.
650
651 =head2 guestfs_get_e2label
652
653  char *guestfs_get_e2label (guestfs_h *handle,
654                 const char *device);
655
656 This returns the ext2/3/4 filesystem label of the filesystem on
657 C<device>.
658
659 This function returns a string, or NULL on error.
660 I<The caller must free the returned string after use>.
661
662 =head2 guestfs_get_e2uuid
663
664  char *guestfs_get_e2uuid (guestfs_h *handle,
665                 const char *device);
666
667 This returns the ext2/3/4 filesystem UUID of the filesystem on
668 C<device>.
669
670 This function returns a string, or NULL on error.
671 I<The caller must free the returned string after use>.
672
673 =head2 guestfs_get_path
674
675  const char *guestfs_get_path (guestfs_h *handle);
676
677 Return the current search path.
678
679 This is always non-NULL.  If it wasn't set already, then this will
680 return the default path.
681
682 This function returns a string, or NULL on error.
683 The string is owned by the guest handle and must I<not> be freed.
684
685 =head2 guestfs_get_qemu
686
687  const char *guestfs_get_qemu (guestfs_h *handle);
688
689 Return the current qemu binary.
690
691 This is always non-NULL.  If it wasn't set already, then this will
692 return the default qemu binary name.
693
694 This function returns a string, or NULL on error.
695 The string is owned by the guest handle and must I<not> be freed.
696
697 =head2 guestfs_get_state
698
699  int guestfs_get_state (guestfs_h *handle);
700
701 This returns the current state as an opaque integer.  This is
702 only useful for printing debug and internal error messages.
703
704 For more information on states, see L<guestfs(3)>.
705
706 On error this function returns -1.
707
708 =head2 guestfs_get_verbose
709
710  int guestfs_get_verbose (guestfs_h *handle);
711
712 This returns the verbose messages flag.
713
714 This function returns a C truth value on success or -1 on error.
715
716 =head2 guestfs_grub_install
717
718  int guestfs_grub_install (guestfs_h *handle,
719                 const char *root,
720                 const char *device);
721
722 This command installs GRUB (the Grand Unified Bootloader) on
723 C<device>, with the root directory being C<root>.
724
725 This function returns 0 on success or -1 on error.
726
727 =head2 guestfs_is_busy
728
729  int guestfs_is_busy (guestfs_h *handle);
730
731 This returns true iff this handle is busy processing a command
732 (in the C<BUSY> state).
733
734 For more information on states, see L<guestfs(3)>.
735
736 This function returns a C truth value on success or -1 on error.
737
738 =head2 guestfs_is_config
739
740  int guestfs_is_config (guestfs_h *handle);
741
742 This returns true iff this handle is being configured
743 (in the C<CONFIG> state).
744
745 For more information on states, see L<guestfs(3)>.
746
747 This function returns a C truth value on success or -1 on error.
748
749 =head2 guestfs_is_dir
750
751  int guestfs_is_dir (guestfs_h *handle,
752                 const char *path);
753
754 This returns C<true> if and only if there is a directory
755 with the given C<path> name.  Note that it returns false for
756 other objects like files.
757
758 See also C<guestfs_stat>.
759
760 This function returns a C truth value on success or -1 on error.
761
762 =head2 guestfs_is_file
763
764  int guestfs_is_file (guestfs_h *handle,
765                 const char *path);
766
767 This returns C<true> if and only if there is a file
768 with the given C<path> name.  Note that it returns false for
769 other objects like directories.
770
771 See also C<guestfs_stat>.
772
773 This function returns a C truth value on success or -1 on error.
774
775 =head2 guestfs_is_launching
776
777  int guestfs_is_launching (guestfs_h *handle);
778
779 This returns true iff this handle is launching the subprocess
780 (in the C<LAUNCHING> state).
781
782 For more information on states, see L<guestfs(3)>.
783
784 This function returns a C truth value on success or -1 on error.
785
786 =head2 guestfs_is_ready
787
788  int guestfs_is_ready (guestfs_h *handle);
789
790 This returns true iff this handle is ready to accept commands
791 (in the C<READY> state).
792
793 For more information on states, see L<guestfs(3)>.
794
795 This function returns a C truth value on success or -1 on error.
796
797 =head2 guestfs_kill_subprocess
798
799  int guestfs_kill_subprocess (guestfs_h *handle);
800
801 This kills the qemu subprocess.  You should never need to call this.
802
803 This function returns 0 on success or -1 on error.
804
805 =head2 guestfs_launch
806
807  int guestfs_launch (guestfs_h *handle);
808
809 Internally libguestfs is implemented by running a virtual machine
810 using L<qemu(1)>.
811
812 You should call this after configuring the handle
813 (eg. adding drives) but before performing any actions.
814
815 This function returns 0 on success or -1 on error.
816
817 =head2 guestfs_list_devices
818
819  char **guestfs_list_devices (guestfs_h *handle);
820
821 List all the block devices.
822
823 The full block device names are returned, eg. C</dev/sda>
824
825 This function returns a NULL-terminated array of strings
826 (like L<environ(3)>), or NULL if there was an error.
827 I<The caller must free the strings and the array after use>.
828
829 =head2 guestfs_list_partitions
830
831  char **guestfs_list_partitions (guestfs_h *handle);
832
833 List all the partitions detected on all block devices.
834
835 The full partition device names are returned, eg. C</dev/sda1>
836
837 This does not return logical volumes.  For that you will need to
838 call C<guestfs_lvs>.
839
840 This function returns a NULL-terminated array of strings
841 (like L<environ(3)>), or NULL if there was an error.
842 I<The caller must free the strings and the array after use>.
843
844 =head2 guestfs_ll
845
846  char *guestfs_ll (guestfs_h *handle,
847                 const char *directory);
848
849 List the files in C<directory> (relative to the root directory,
850 there is no cwd) in the format of 'ls -la'.
851
852 This command is mostly useful for interactive sessions.  It
853 is I<not> intended that you try to parse the output string.
854
855 This function returns a string, or NULL on error.
856 I<The caller must free the returned string after use>.
857
858 =head2 guestfs_ls
859
860  char **guestfs_ls (guestfs_h *handle,
861                 const char *directory);
862
863 List the files in C<directory> (relative to the root directory,
864 there is no cwd).  The '.' and '..' entries are not returned, but
865 hidden files are shown.
866
867 This command is mostly useful for interactive sessions.  Programs
868 should probably use C<guestfs_readdir> instead.
869
870 This function returns a NULL-terminated array of strings
871 (like L<environ(3)>), or NULL if there was an error.
872 I<The caller must free the strings and the array after use>.
873
874 =head2 guestfs_lstat
875
876  struct guestfs_stat *guestfs_lstat (guestfs_h *handle,
877                 const char *path);
878
879 Returns file information for the given C<path>.
880
881 This is the same as C<guestfs_stat> except that if C<path>
882 is a symbolic link, then the link is stat-ed, not the file it
883 refers to.
884
885 This is the same as the C<lstat(2)> system call.
886
887 This function returns a C<struct guestfs_stat *>
888 (see L<stat(2)> and E<lt>guestfs-structs.hE<gt>),
889 or NULL if there was an error.
890 I<The caller must call C<free> after use>.
891
892 =head2 guestfs_lvcreate
893
894  int guestfs_lvcreate (guestfs_h *handle,
895                 const char *logvol,
896                 const char *volgroup,
897                 int mbytes);
898
899 This creates an LVM volume group called C<logvol>
900 on the volume group C<volgroup>, with C<size> megabytes.
901
902 This function returns 0 on success or -1 on error.
903
904 =head2 guestfs_lvm_remove_all
905
906  int guestfs_lvm_remove_all (guestfs_h *handle);
907
908 This command removes all LVM logical volumes, volume groups
909 and physical volumes.
910
911 This function returns 0 on success or -1 on error.
912
913 B<This command is dangerous.  Without careful use you
914 can easily destroy all your data>.
915
916 =head2 guestfs_lvremove
917
918  int guestfs_lvremove (guestfs_h *handle,
919                 const char *device);
920
921 Remove an LVM logical volume C<device>, where C<device> is
922 the path to the LV, such as C</dev/VG/LV>.
923
924 You can also remove all LVs in a volume group by specifying
925 the VG name, C</dev/VG>.
926
927 This function returns 0 on success or -1 on error.
928
929 =head2 guestfs_lvs
930
931  char **guestfs_lvs (guestfs_h *handle);
932
933 List all the logical volumes detected.  This is the equivalent
934 of the L<lvs(8)> command.
935
936 This returns a list of the logical volume device names
937 (eg. C</dev/VolGroup00/LogVol00>).
938
939 See also C<guestfs_lvs_full>.
940
941 This function returns a NULL-terminated array of strings
942 (like L<environ(3)>), or NULL if there was an error.
943 I<The caller must free the strings and the array after use>.
944
945 =head2 guestfs_lvs_full
946
947  struct guestfs_lvm_lv_list *guestfs_lvs_full (guestfs_h *handle);
948
949 List all the logical volumes detected.  This is the equivalent
950 of the L<lvs(8)> command.  The "full" version includes all fields.
951
952 This function returns a C<struct guestfs_lvm_lv_list *>
953 (see E<lt>guestfs-structs.hE<gt>),
954 or NULL if there was an error.
955 I<The caller must call C<guestfs_free_lvm_lv_list> after use>.
956
957 =head2 guestfs_mkdir
958
959  int guestfs_mkdir (guestfs_h *handle,
960                 const char *path);
961
962 Create a directory named C<path>.
963
964 This function returns 0 on success or -1 on error.
965
966 =head2 guestfs_mkdir_p
967
968  int guestfs_mkdir_p (guestfs_h *handle,
969                 const char *path);
970
971 Create a directory named C<path>, creating any parent directories
972 as necessary.  This is like the C<mkdir -p> shell command.
973
974 This function returns 0 on success or -1 on error.
975
976 =head2 guestfs_mkfs
977
978  int guestfs_mkfs (guestfs_h *handle,
979                 const char *fstype,
980                 const char *device);
981
982 This creates a filesystem on C<device> (usually a partition
983 of LVM logical volume).  The filesystem type is C<fstype>, for
984 example C<ext3>.
985
986 This function returns 0 on success or -1 on error.
987
988 =head2 guestfs_mount
989
990  int guestfs_mount (guestfs_h *handle,
991                 const char *device,
992                 const char *mountpoint);
993
994 Mount a guest disk at a position in the filesystem.  Block devices
995 are named C</dev/sda>, C</dev/sdb> and so on, as they were added to
996 the guest.  If those block devices contain partitions, they will have
997 the usual names (eg. C</dev/sda1>).  Also LVM C</dev/VG/LV>-style
998 names can be used.
999
1000 The rules are the same as for L<mount(2)>:  A filesystem must
1001 first be mounted on C</> before others can be mounted.  Other
1002 filesystems can only be mounted on directories which already
1003 exist.
1004
1005 The mounted filesystem is writable, if we have sufficient permissions
1006 on the underlying device.
1007
1008 The filesystem options C<sync> and C<noatime> are set with this
1009 call, in order to improve reliability.
1010
1011 This function returns 0 on success or -1 on error.
1012
1013 =head2 guestfs_mount_options
1014
1015  int guestfs_mount_options (guestfs_h *handle,
1016                 const char *options,
1017                 const char *device,
1018                 const char *mountpoint);
1019
1020 This is the same as the C<guestfs_mount> command, but it
1021 allows you to set the mount options as for the
1022 L<mount(8)> I<-o> flag.
1023
1024 This function returns 0 on success or -1 on error.
1025
1026 =head2 guestfs_mount_ro
1027
1028  int guestfs_mount_ro (guestfs_h *handle,
1029                 const char *device,
1030                 const char *mountpoint);
1031
1032 This is the same as the C<guestfs_mount> command, but it
1033 mounts the filesystem with the read-only (I<-o ro>) flag.
1034
1035 This function returns 0 on success or -1 on error.
1036
1037 =head2 guestfs_mount_vfs
1038
1039  int guestfs_mount_vfs (guestfs_h *handle,
1040                 const char *options,
1041                 const char *vfstype,
1042                 const char *device,
1043                 const char *mountpoint);
1044
1045 This is the same as the C<guestfs_mount> command, but it
1046 allows you to set both the mount options and the vfstype
1047 as for the L<mount(8)> I<-o> and I<-t> flags.
1048
1049 This function returns 0 on success or -1 on error.
1050
1051 =head2 guestfs_mounts
1052
1053  char **guestfs_mounts (guestfs_h *handle);
1054
1055 This returns the list of currently mounted filesystems.  It returns
1056 the list of devices (eg. C</dev/sda1>, C</dev/VG/LV>).
1057
1058 Some internal mounts are not shown.
1059
1060 This function returns a NULL-terminated array of strings
1061 (like L<environ(3)>), or NULL if there was an error.
1062 I<The caller must free the strings and the array after use>.
1063
1064 =head2 guestfs_mv
1065
1066  int guestfs_mv (guestfs_h *handle,
1067                 const char *src,
1068                 const char *dest);
1069
1070 This moves a file from C<src> to C<dest> where C<dest> is
1071 either a destination filename or destination directory.
1072
1073 This function returns 0 on success or -1 on error.
1074
1075 =head2 guestfs_pvcreate
1076
1077  int guestfs_pvcreate (guestfs_h *handle,
1078                 const char *device);
1079
1080 This creates an LVM physical volume on the named C<device>,
1081 where C<device> should usually be a partition name such
1082 as C</dev/sda1>.
1083
1084 This function returns 0 on success or -1 on error.
1085
1086 =head2 guestfs_pvremove
1087
1088  int guestfs_pvremove (guestfs_h *handle,
1089                 const char *device);
1090
1091 This wipes a physical volume C<device> so that LVM will no longer
1092 recognise it.
1093
1094 The implementation uses the C<pvremove> command which refuses to
1095 wipe physical volumes that contain any volume groups, so you have
1096 to remove those first.
1097
1098 This function returns 0 on success or -1 on error.
1099
1100 =head2 guestfs_pvs
1101
1102  char **guestfs_pvs (guestfs_h *handle);
1103
1104 List all the physical volumes detected.  This is the equivalent
1105 of the L<pvs(8)> command.
1106
1107 This returns a list of just the device names that contain
1108 PVs (eg. C</dev/sda2>).
1109
1110 See also C<guestfs_pvs_full>.
1111
1112 This function returns a NULL-terminated array of strings
1113 (like L<environ(3)>), or NULL if there was an error.
1114 I<The caller must free the strings and the array after use>.
1115
1116 =head2 guestfs_pvs_full
1117
1118  struct guestfs_lvm_pv_list *guestfs_pvs_full (guestfs_h *handle);
1119
1120 List all the physical volumes detected.  This is the equivalent
1121 of the L<pvs(8)> command.  The "full" version includes all fields.
1122
1123 This function returns a C<struct guestfs_lvm_pv_list *>
1124 (see E<lt>guestfs-structs.hE<gt>),
1125 or NULL if there was an error.
1126 I<The caller must call C<guestfs_free_lvm_pv_list> after use>.
1127
1128 =head2 guestfs_read_lines
1129
1130  char **guestfs_read_lines (guestfs_h *handle,
1131                 const char *path);
1132
1133 Return the contents of the file named C<path>.
1134
1135 The file contents are returned as a list of lines.  Trailing
1136 C<LF> and C<CRLF> character sequences are I<not> returned.
1137
1138 Note that this function cannot correctly handle binary files
1139 (specifically, files containing C<\0> character which is treated
1140 as end of line).  For those you need to use the C<guestfs_read_file>
1141 function which has a more complex interface.
1142
1143 This function returns a NULL-terminated array of strings
1144 (like L<environ(3)>), or NULL if there was an error.
1145 I<The caller must free the strings and the array after use>.
1146
1147 =head2 guestfs_rm
1148
1149  int guestfs_rm (guestfs_h *handle,
1150                 const char *path);
1151
1152 Remove the single file C<path>.
1153
1154 This function returns 0 on success or -1 on error.
1155
1156 =head2 guestfs_rm_rf
1157
1158  int guestfs_rm_rf (guestfs_h *handle,
1159                 const char *path);
1160
1161 Remove the file or directory C<path>, recursively removing the
1162 contents if its a directory.  This is like the C<rm -rf> shell
1163 command.
1164
1165 This function returns 0 on success or -1 on error.
1166
1167 =head2 guestfs_rmdir
1168
1169  int guestfs_rmdir (guestfs_h *handle,
1170                 const char *path);
1171
1172 Remove the single directory C<path>.
1173
1174 This function returns 0 on success or -1 on error.
1175
1176 =head2 guestfs_set_autosync
1177
1178  int guestfs_set_autosync (guestfs_h *handle,
1179                 int autosync);
1180
1181 If C<autosync> is true, this enables autosync.  Libguestfs will make a
1182 best effort attempt to run C<guestfs_umount_all> followed by
1183 C<guestfs_sync> when the handle is closed
1184 (also if the program exits without closing handles).
1185
1186 This is disabled by default (except in guestfish where it is
1187 enabled by default).
1188
1189 This function returns 0 on success or -1 on error.
1190
1191 =head2 guestfs_set_busy
1192
1193  int guestfs_set_busy (guestfs_h *handle);
1194
1195 This sets the state to C<BUSY>.  This is only used when implementing
1196 actions using the low-level API.
1197
1198 For more information on states, see L<guestfs(3)>.
1199
1200 This function returns 0 on success or -1 on error.
1201
1202 =head2 guestfs_set_e2label
1203
1204  int guestfs_set_e2label (guestfs_h *handle,
1205                 const char *device,
1206                 const char *label);
1207
1208 This sets the ext2/3/4 filesystem label of the filesystem on
1209 C<device> to C<label>.  Filesystem labels are limited to
1210 16 characters.
1211
1212 You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2label>
1213 to return the existing label on a filesystem.
1214
1215 This function returns 0 on success or -1 on error.
1216
1217 =head2 guestfs_set_e2uuid
1218
1219  int guestfs_set_e2uuid (guestfs_h *handle,
1220                 const char *device,
1221                 const char *uuid);
1222
1223 This sets the ext2/3/4 filesystem UUID of the filesystem on
1224 C<device> to C<uuid>.  The format of the UUID and alternatives
1225 such as C<clear>, C<random> and C<time> are described in the
1226 L<tune2fs(8)> manpage.
1227
1228 You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2uuid>
1229 to return the existing UUID of a filesystem.
1230
1231 This function returns 0 on success or -1 on error.
1232
1233 =head2 guestfs_set_path
1234
1235  int guestfs_set_path (guestfs_h *handle,
1236                 const char *path);
1237
1238 Set the path that libguestfs searches for kernel and initrd.img.
1239
1240 The default is C<$libdir/guestfs> unless overridden by setting
1241 C<LIBGUESTFS_PATH> environment variable.
1242
1243 The string C<path> is stashed in the libguestfs handle, so the caller
1244 must make sure it remains valid for the lifetime of the handle.
1245
1246 Setting C<path> to C<NULL> restores the default path.
1247
1248 This function returns 0 on success or -1 on error.
1249
1250 =head2 guestfs_set_qemu
1251
1252  int guestfs_set_qemu (guestfs_h *handle,
1253                 const char *qemu);
1254
1255 Set the qemu binary that we will use.
1256
1257 The default is chosen when the library was compiled by the
1258 configure script.
1259
1260 You can also override this by setting the C<LIBGUESTFS_QEMU>
1261 environment variable.
1262
1263 The string C<qemu> is stashed in the libguestfs handle, so the caller
1264 must make sure it remains valid for the lifetime of the handle.
1265
1266 Setting C<qemu> to C<NULL> restores the default qemu binary.
1267
1268 This function returns 0 on success or -1 on error.
1269
1270 =head2 guestfs_set_ready
1271
1272  int guestfs_set_ready (guestfs_h *handle);
1273
1274 This sets the state to C<READY>.  This is only used when implementing
1275 actions using the low-level API.
1276
1277 For more information on states, see L<guestfs(3)>.
1278
1279 This function returns 0 on success or -1 on error.
1280
1281 =head2 guestfs_set_verbose
1282
1283  int guestfs_set_verbose (guestfs_h *handle,
1284                 int verbose);
1285
1286 If C<verbose> is true, this turns on verbose messages (to C<stderr>).
1287
1288 Verbose messages are disabled unless the environment variable
1289 C<LIBGUESTFS_DEBUG> is defined and set to C<1>.
1290
1291 This function returns 0 on success or -1 on error.
1292
1293 =head2 guestfs_sfdisk
1294
1295  int guestfs_sfdisk (guestfs_h *handle,
1296                 const char *device,
1297                 int cyls,
1298                 int heads,
1299                 int sectors,
1300                 char * const* const lines);
1301
1302 This is a direct interface to the L<sfdisk(8)> program for creating
1303 partitions on block devices.
1304
1305 C<device> should be a block device, for example C</dev/sda>.
1306
1307 C<cyls>, C<heads> and C<sectors> are the number of cylinders, heads
1308 and sectors on the device, which are passed directly to sfdisk as
1309 the I<-C>, I<-H> and I<-S> parameters.  If you pass C<0> for any
1310 of these, then the corresponding parameter is omitted.  Usually for
1311 'large' disks, you can just pass C<0> for these, but for small
1312 (floppy-sized) disks, sfdisk (or rather, the kernel) cannot work
1313 out the right geometry and you will need to tell it.
1314
1315 C<lines> is a list of lines that we feed to C<sfdisk>.  For more
1316 information refer to the L<sfdisk(8)> manpage.
1317
1318 To create a single partition occupying the whole disk, you would
1319 pass C<lines> as a single element list, when the single element being
1320 the string C<,> (comma).
1321
1322 This function returns 0 on success or -1 on error.
1323
1324 B<This command is dangerous.  Without careful use you
1325 can easily destroy all your data>.
1326
1327 =head2 guestfs_stat
1328
1329  struct guestfs_stat *guestfs_stat (guestfs_h *handle,
1330                 const char *path);
1331
1332 Returns file information for the given C<path>.
1333
1334 This is the same as the C<stat(2)> system call.
1335
1336 This function returns a C<struct guestfs_stat *>
1337 (see L<stat(2)> and E<lt>guestfs-structs.hE<gt>),
1338 or NULL if there was an error.
1339 I<The caller must call C<free> after use>.
1340
1341 =head2 guestfs_statvfs
1342
1343  struct guestfs_statvfs *guestfs_statvfs (guestfs_h *handle,
1344                 const char *path);
1345
1346 Returns file system statistics for any mounted file system.
1347 C<path> should be a file or directory in the mounted file system
1348 (typically it is the mount point itself, but it doesn't need to be).
1349
1350 This is the same as the C<statvfs(2)> system call.
1351
1352 This function returns a C<struct guestfs_statvfs *>
1353 (see L<statvfs(2)> and E<lt>guestfs-structs.hE<gt>),
1354 or NULL if there was an error.
1355 I<The caller must call C<free> after use>.
1356
1357 =head2 guestfs_sync
1358
1359  int guestfs_sync (guestfs_h *handle);
1360
1361 This syncs the disk, so that any writes are flushed through to the
1362 underlying disk image.
1363
1364 You should always call this if you have modified a disk image, before
1365 closing the handle.
1366
1367 This function returns 0 on success or -1 on error.
1368
1369 =head2 guestfs_tar_in
1370
1371  int guestfs_tar_in (guestfs_h *handle,
1372                 const char *tarfile,
1373                 const char *directory);
1374
1375 This command uploads and unpacks local file C<tarfile> (an
1376 I<uncompressed> tar file) into C<directory>.
1377
1378 To upload a compressed tarball, use C<guestfs_tgz_in>.
1379
1380 This function returns 0 on success or -1 on error.
1381
1382 =head2 guestfs_tar_out
1383
1384  int guestfs_tar_out (guestfs_h *handle,
1385                 const char *directory,
1386                 const char *tarfile);
1387
1388 This command packs the contents of C<directory> and downloads
1389 it to local file C<tarfile>.
1390
1391 To download a compressed tarball, use C<guestfs_tgz_out>.
1392
1393 This function returns 0 on success or -1 on error.
1394
1395 =head2 guestfs_tgz_in
1396
1397  int guestfs_tgz_in (guestfs_h *handle,
1398                 const char *tarball,
1399                 const char *directory);
1400
1401 This command uploads and unpacks local file C<tarball> (a
1402 I<gzip compressed> tar file) into C<directory>.
1403
1404 To upload an uncompressed tarball, use C<guestfs_tar_in>.
1405
1406 This function returns 0 on success or -1 on error.
1407
1408 =head2 guestfs_tgz_out
1409
1410  int guestfs_tgz_out (guestfs_h *handle,
1411                 const char *directory,
1412                 const char *tarball);
1413
1414 This command packs the contents of C<directory> and downloads
1415 it to local file C<tarball>.
1416
1417 To download an uncompressed tarball, use C<guestfs_tar_out>.
1418
1419 This function returns 0 on success or -1 on error.
1420
1421 =head2 guestfs_touch
1422
1423  int guestfs_touch (guestfs_h *handle,
1424                 const char *path);
1425
1426 Touch acts like the L<touch(1)> command.  It can be used to
1427 update the timestamps on a file, or, if the file does not exist,
1428 to create a new zero-length file.
1429
1430 This function returns 0 on success or -1 on error.
1431
1432 =head2 guestfs_tune2fs_l
1433
1434  char **guestfs_tune2fs_l (guestfs_h *handle,
1435                 const char *device);
1436
1437 This returns the contents of the ext2, ext3 or ext4 filesystem
1438 superblock on C<device>.
1439
1440 It is the same as running C<tune2fs -l device>.  See L<tune2fs(8)>
1441 manpage for more details.  The list of fields returned isn't
1442 clearly defined, and depends on both the version of C<tune2fs>
1443 that libguestfs was built against, and the filesystem itself.
1444
1445 This function returns a NULL-terminated array of
1446 strings, or NULL if there was an error.
1447 The array of strings will always have length C<2n+1>, where
1448 C<n> keys and values alternate, followed by the trailing NULL entry.
1449 I<The caller must free the strings and the array after use>.
1450
1451 =head2 guestfs_umount
1452
1453  int guestfs_umount (guestfs_h *handle,
1454                 const char *pathordevice);
1455
1456 This unmounts the given filesystem.  The filesystem may be
1457 specified either by its mountpoint (path) or the device which
1458 contains the filesystem.
1459
1460 This function returns 0 on success or -1 on error.
1461
1462 =head2 guestfs_umount_all
1463
1464  int guestfs_umount_all (guestfs_h *handle);
1465
1466 This unmounts all mounted filesystems.
1467
1468 Some internal mounts are not unmounted by this call.
1469
1470 This function returns 0 on success or -1 on error.
1471
1472 =head2 guestfs_upload
1473
1474  int guestfs_upload (guestfs_h *handle,
1475                 const char *filename,
1476                 const char *remotefilename);
1477
1478 Upload local file C<filename> to C<remotefilename> on the
1479 filesystem.
1480
1481 C<filename> can also be a named pipe.
1482
1483 See also C<guestfs_download>.
1484
1485 This function returns 0 on success or -1 on error.
1486
1487 =head2 guestfs_vgcreate
1488
1489  int guestfs_vgcreate (guestfs_h *handle,
1490                 const char *volgroup,
1491                 char * const* const physvols);
1492
1493 This creates an LVM volume group called C<volgroup>
1494 from the non-empty list of physical volumes C<physvols>.
1495
1496 This function returns 0 on success or -1 on error.
1497
1498 =head2 guestfs_vgremove
1499
1500  int guestfs_vgremove (guestfs_h *handle,
1501                 const char *vgname);
1502
1503 Remove an LVM volume group C<vgname>, (for example C<VG>).
1504
1505 This also forcibly removes all logical volumes in the volume
1506 group (if any).
1507
1508 This function returns 0 on success or -1 on error.
1509
1510 =head2 guestfs_vgs
1511
1512  char **guestfs_vgs (guestfs_h *handle);
1513
1514 List all the volumes groups detected.  This is the equivalent
1515 of the L<vgs(8)> command.
1516
1517 This returns a list of just the volume group names that were
1518 detected (eg. C<VolGroup00>).
1519
1520 See also C<guestfs_vgs_full>.
1521
1522 This function returns a NULL-terminated array of strings
1523 (like L<environ(3)>), or NULL if there was an error.
1524 I<The caller must free the strings and the array after use>.
1525
1526 =head2 guestfs_vgs_full
1527
1528  struct guestfs_lvm_vg_list *guestfs_vgs_full (guestfs_h *handle);
1529
1530 List all the volumes groups detected.  This is the equivalent
1531 of the L<vgs(8)> command.  The "full" version includes all fields.
1532
1533 This function returns a C<struct guestfs_lvm_vg_list *>
1534 (see E<lt>guestfs-structs.hE<gt>),
1535 or NULL if there was an error.
1536 I<The caller must call C<guestfs_free_lvm_vg_list> after use>.
1537
1538 =head2 guestfs_wait_ready
1539
1540  int guestfs_wait_ready (guestfs_h *handle);
1541
1542 Internally libguestfs is implemented by running a virtual machine
1543 using L<qemu(1)>.
1544
1545 You should call this after C<guestfs_launch> to wait for the launch
1546 to complete.
1547
1548 This function returns 0 on success or -1 on error.
1549
1550 =head2 guestfs_write_file
1551
1552  int guestfs_write_file (guestfs_h *handle,
1553                 const char *path,
1554                 const char *content,
1555                 int size);
1556
1557 This call creates a file called C<path>.  The contents of the
1558 file is the string C<content> (which can contain any 8 bit data),
1559 with length C<size>.
1560
1561 As a special case, if C<size> is C<0>
1562 then the length is calculated using C<strlen> (so in this case
1563 the content cannot contain embedded ASCII NULs).
1564
1565 This function returns 0 on success or -1 on error.
1566
1567 Because of the message protocol, there is a transfer limit 
1568 of somewhere between 2MB and 4MB.  To transfer large files you should use
1569 FTP.
1570
1571 =head2 guestfs_zero
1572
1573  int guestfs_zero (guestfs_h *handle,
1574                 const char *device);
1575
1576 This command writes zeroes over the first few blocks of C<device>.
1577
1578 How many blocks are zeroed isn't specified (but it's I<not> enough
1579 to securely wipe the device).  It should be sufficient to remove
1580 any partition tables, filesystem superblocks and so on.
1581
1582 This function returns 0 on success or -1 on error.
1583