68357d62f80de0f518c63d460be45ef5c49d6d18
[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 Note that this call checks for the existence of C<filename>.  This
11 stops you from specifying other types of drive which are supported
12 by qemu such as C<nbd:> and C<http:> URLs.  To specify those, use
13 the general C<guestfs_config> call instead.
14
15 This function returns 0 on success or -1 on error.
16
17 =head2 guestfs_add_drive
18
19  int guestfs_add_drive (guestfs_h *handle,
20                 const char *filename);
21
22 This function adds a virtual machine disk image C<filename> to the
23 guest.  The first time you call this function, the disk appears as IDE
24 disk 0 (C</dev/sda>) in the guest, the second time as C</dev/sdb>, and
25 so on.
26
27 You don't necessarily need to be root when using libguestfs.  However
28 you obviously do need sufficient permissions to access the filename
29 for whatever operations you want to perform (ie. read access if you
30 just want to read the image or write access if you want to modify the
31 image).
32
33 This is equivalent to the qemu parameter C<-drive file=filename,cache=off>.
34
35 Note that this call checks for the existence of C<filename>.  This
36 stops you from specifying other types of drive which are supported
37 by qemu such as C<nbd:> and C<http:> URLs.  To specify those, use
38 the general C<guestfs_config> call instead.
39
40 This function returns 0 on success or -1 on error.
41
42 =head2 guestfs_add_drive_ro
43
44  int guestfs_add_drive_ro (guestfs_h *handle,
45                 const char *filename);
46
47 This adds a drive in snapshot mode, making it effectively
48 read-only.
49
50 Note that writes to the device are allowed, and will be seen for
51 the duration of the guestfs handle, but they are written
52 to a temporary file which is discarded as soon as the guestfs
53 handle is closed.  We don't currently have any method to enable
54 changes to be committed, although qemu can support this.
55
56 This is equivalent to the qemu parameter
57 C<-drive file=filename,snapshot=on>.
58
59 Note that this call checks for the existence of C<filename>.  This
60 stops you from specifying other types of drive which are supported
61 by qemu such as C<nbd:> and C<http:> URLs.  To specify those, use
62 the general C<guestfs_config> call instead.
63
64 This function returns 0 on success or -1 on error.
65
66 =head2 guestfs_aug_close
67
68  int guestfs_aug_close (guestfs_h *handle);
69
70 Close the current Augeas handle and free up any resources
71 used by it.  After calling this, you have to call
72 C<guestfs_aug_init> again before you can use any other
73 Augeas functions.
74
75 This function returns 0 on success or -1 on error.
76
77 =head2 guestfs_aug_defnode
78
79  struct guestfs_int_bool *guestfs_aug_defnode (guestfs_h *handle,
80                 const char *name,
81                 const char *expr,
82                 const char *val);
83
84 Defines a variable C<name> whose value is the result of
85 evaluating C<expr>.
86
87 If C<expr> evaluates to an empty nodeset, a node is created,
88 equivalent to calling C<guestfs_aug_set> C<expr>, C<value>.
89 C<name> will be the nodeset containing that single node.
90
91 On success this returns a pair containing the
92 number of nodes in the nodeset, and a boolean flag
93 if a node was created.
94
95 This function returns a C<struct guestfs_int_bool *>,
96 or NULL if there was an error.
97 I<The caller must call C<guestfs_free_int_bool> after use>.
98
99 =head2 guestfs_aug_defvar
100
101  int guestfs_aug_defvar (guestfs_h *handle,
102                 const char *name,
103                 const char *expr);
104
105 Defines an Augeas variable C<name> whose value is the result
106 of evaluating C<expr>.  If C<expr> is NULL, then C<name> is
107 undefined.
108
109 On success this returns the number of nodes in C<expr>, or
110 C<0> if C<expr> evaluates to something which is not a nodeset.
111
112 On error this function returns -1.
113
114 =head2 guestfs_aug_get
115
116  char *guestfs_aug_get (guestfs_h *handle,
117                 const char *path);
118
119 Look up the value associated with C<path>.  If C<path>
120 matches exactly one node, the C<value> is returned.
121
122 This function returns a string, or NULL on error.
123 I<The caller must free the returned string after use>.
124
125 =head2 guestfs_aug_init
126
127  int guestfs_aug_init (guestfs_h *handle,
128                 const char *root,
129                 int flags);
130
131 Create a new Augeas handle for editing configuration files.
132 If there was any previous Augeas handle associated with this
133 guestfs session, then it is closed.
134
135 You must call this before using any other C<guestfs_aug_*>
136 commands.
137
138 C<root> is the filesystem root.  C<root> must not be NULL,
139 use C</> instead.
140
141 The flags are the same as the flags defined in
142 E<lt>augeas.hE<gt>, the logical I<or> of the following
143 integers:
144
145 =over 4
146
147 =item C<AUG_SAVE_BACKUP> = 1
148
149 Keep the original file with a C<.augsave> extension.
150
151 =item C<AUG_SAVE_NEWFILE> = 2
152
153 Save changes into a file with extension C<.augnew>, and
154 do not overwrite original.  Overrides C<AUG_SAVE_BACKUP>.
155
156 =item C<AUG_TYPE_CHECK> = 4
157
158 Typecheck lenses (can be expensive).
159
160 =item C<AUG_NO_STDINC> = 8
161
162 Do not use standard load path for modules.
163
164 =item C<AUG_SAVE_NOOP> = 16
165
166 Make save a no-op, just record what would have been changed.
167
168 =item C<AUG_NO_LOAD> = 32
169
170 Do not load the tree in C<guestfs_aug_init>.
171
172 =back
173
174 To close the handle, you can call C<guestfs_aug_close>.
175
176 To find out more about Augeas, see L<http://augeas.net/>.
177
178 This function returns 0 on success or -1 on error.
179
180 =head2 guestfs_aug_insert
181
182  int guestfs_aug_insert (guestfs_h *handle,
183                 const char *path,
184                 const char *label,
185                 int before);
186
187 Create a new sibling C<label> for C<path>, inserting it into
188 the tree before or after C<path> (depending on the boolean
189 flag C<before>).
190
191 C<path> must match exactly one existing node in the tree, and
192 C<label> must be a label, ie. not contain C</>, C<*> or end
193 with a bracketed index C<[N]>.
194
195 This function returns 0 on success or -1 on error.
196
197 =head2 guestfs_aug_load
198
199  int guestfs_aug_load (guestfs_h *handle);
200
201 Load files into the tree.
202
203 See C<aug_load> in the Augeas documentation for the full gory
204 details.
205
206 This function returns 0 on success or -1 on error.
207
208 =head2 guestfs_aug_ls
209
210  char **guestfs_aug_ls (guestfs_h *handle,
211                 const char *path);
212
213 This is just a shortcut for listing C<guestfs_aug_match>
214 C<path/*> and sorting the resulting nodes into alphabetical order.
215
216 This function returns a NULL-terminated array of strings
217 (like L<environ(3)>), or NULL if there was an error.
218 I<The caller must free the strings and the array after use>.
219
220 =head2 guestfs_aug_match
221
222  char **guestfs_aug_match (guestfs_h *handle,
223                 const char *path);
224
225 Returns a list of paths which match the path expression C<path>.
226 The returned paths are sufficiently qualified so that they match
227 exactly one node in the current tree.
228
229 This function returns a NULL-terminated array of strings
230 (like L<environ(3)>), or NULL if there was an error.
231 I<The caller must free the strings and the array after use>.
232
233 =head2 guestfs_aug_mv
234
235  int guestfs_aug_mv (guestfs_h *handle,
236                 const char *src,
237                 const char *dest);
238
239 Move the node C<src> to C<dest>.  C<src> must match exactly
240 one node.  C<dest> is overwritten if it exists.
241
242 This function returns 0 on success or -1 on error.
243
244 =head2 guestfs_aug_rm
245
246  int guestfs_aug_rm (guestfs_h *handle,
247                 const char *path);
248
249 Remove C<path> and all of its children.
250
251 On success this returns the number of entries which were removed.
252
253 On error this function returns -1.
254
255 =head2 guestfs_aug_save
256
257  int guestfs_aug_save (guestfs_h *handle);
258
259 This writes all pending changes to disk.
260
261 The flags which were passed to C<guestfs_aug_init> affect exactly
262 how files are saved.
263
264 This function returns 0 on success or -1 on error.
265
266 =head2 guestfs_aug_set
267
268  int guestfs_aug_set (guestfs_h *handle,
269                 const char *path,
270                 const char *val);
271
272 Set the value associated with C<path> to C<value>.
273
274 This function returns 0 on success or -1 on error.
275
276 =head2 guestfs_blockdev_flushbufs
277
278  int guestfs_blockdev_flushbufs (guestfs_h *handle,
279                 const char *device);
280
281 This tells the kernel to flush internal buffers associated
282 with C<device>.
283
284 This uses the L<blockdev(8)> command.
285
286 This function returns 0 on success or -1 on error.
287
288 =head2 guestfs_blockdev_getbsz
289
290  int guestfs_blockdev_getbsz (guestfs_h *handle,
291                 const char *device);
292
293 This returns the block size of a device.
294
295 (Note this is different from both I<size in blocks> and
296 I<filesystem block size>).
297
298 This uses the L<blockdev(8)> command.
299
300 On error this function returns -1.
301
302 =head2 guestfs_blockdev_getro
303
304  int guestfs_blockdev_getro (guestfs_h *handle,
305                 const char *device);
306
307 Returns a boolean indicating if the block device is read-only
308 (true if read-only, false if not).
309
310 This uses the L<blockdev(8)> command.
311
312 This function returns a C truth value on success or -1 on error.
313
314 =head2 guestfs_blockdev_getsize64
315
316  int64_t guestfs_blockdev_getsize64 (guestfs_h *handle,
317                 const char *device);
318
319 This returns the size of the device in bytes.
320
321 See also C<guestfs_blockdev_getsz>.
322
323 This uses the L<blockdev(8)> command.
324
325 On error this function returns -1.
326
327 =head2 guestfs_blockdev_getss
328
329  int guestfs_blockdev_getss (guestfs_h *handle,
330                 const char *device);
331
332 This returns the size of sectors on a block device.
333 Usually 512, but can be larger for modern devices.
334
335 (Note, this is not the size in sectors, use C<guestfs_blockdev_getsz>
336 for that).
337
338 This uses the L<blockdev(8)> command.
339
340 On error this function returns -1.
341
342 =head2 guestfs_blockdev_getsz
343
344  int64_t guestfs_blockdev_getsz (guestfs_h *handle,
345                 const char *device);
346
347 This returns the size of the device in units of 512-byte sectors
348 (even if the sectorsize isn't 512 bytes ... weird).
349
350 See also C<guestfs_blockdev_getss> for the real sector size of
351 the device, and C<guestfs_blockdev_getsize64> for the more
352 useful I<size in bytes>.
353
354 This uses the L<blockdev(8)> command.
355
356 On error this function returns -1.
357
358 =head2 guestfs_blockdev_rereadpt
359
360  int guestfs_blockdev_rereadpt (guestfs_h *handle,
361                 const char *device);
362
363 Reread the partition table on C<device>.
364
365 This uses the L<blockdev(8)> command.
366
367 This function returns 0 on success or -1 on error.
368
369 =head2 guestfs_blockdev_setbsz
370
371  int guestfs_blockdev_setbsz (guestfs_h *handle,
372                 const char *device,
373                 int blocksize);
374
375 This sets the block size of a device.
376
377 (Note this is different from both I<size in blocks> and
378 I<filesystem block size>).
379
380 This uses the L<blockdev(8)> command.
381
382 This function returns 0 on success or -1 on error.
383
384 =head2 guestfs_blockdev_setro
385
386  int guestfs_blockdev_setro (guestfs_h *handle,
387                 const char *device);
388
389 Sets the block device named C<device> to read-only.
390
391 This uses the L<blockdev(8)> command.
392
393 This function returns 0 on success or -1 on error.
394
395 =head2 guestfs_blockdev_setrw
396
397  int guestfs_blockdev_setrw (guestfs_h *handle,
398                 const char *device);
399
400 Sets the block device named C<device> to read-write.
401
402 This uses the L<blockdev(8)> command.
403
404 This function returns 0 on success or -1 on error.
405
406 =head2 guestfs_cat
407
408  char *guestfs_cat (guestfs_h *handle,
409                 const char *path);
410
411 Return the contents of the file named C<path>.
412
413 Note that this function cannot correctly handle binary files
414 (specifically, files containing C<\0> character which is treated
415 as end of string).  For those you need to use the C<guestfs_download>
416 function which has a more complex interface.
417
418 This function returns a string, or NULL on error.
419 I<The caller must free the returned string after use>.
420
421 Because of the message protocol, there is a transfer limit 
422 of somewhere between 2MB and 4MB.  To transfer large files you should use
423 FTP.
424
425 =head2 guestfs_checksum
426
427  char *guestfs_checksum (guestfs_h *handle,
428                 const char *csumtype,
429                 const char *path);
430
431 This call computes the MD5, SHAx or CRC checksum of the
432 file named C<path>.
433
434 The type of checksum to compute is given by the C<csumtype>
435 parameter which must have one of the following values:
436
437 =over 4
438
439 =item C<crc>
440
441 Compute the cyclic redundancy check (CRC) specified by POSIX
442 for the C<cksum> command.
443
444 =item C<md5>
445
446 Compute the MD5 hash (using the C<md5sum> program).
447
448 =item C<sha1>
449
450 Compute the SHA1 hash (using the C<sha1sum> program).
451
452 =item C<sha224>
453
454 Compute the SHA224 hash (using the C<sha224sum> program).
455
456 =item C<sha256>
457
458 Compute the SHA256 hash (using the C<sha256sum> program).
459
460 =item C<sha384>
461
462 Compute the SHA384 hash (using the C<sha384sum> program).
463
464 =item C<sha512>
465
466 Compute the SHA512 hash (using the C<sha512sum> program).
467
468 =back
469
470 The checksum is returned as a printable string.
471
472 This function returns a string, or NULL on error.
473 I<The caller must free the returned string after use>.
474
475 =head2 guestfs_chmod
476
477  int guestfs_chmod (guestfs_h *handle,
478                 int mode,
479                 const char *path);
480
481 Change the mode (permissions) of C<path> to C<mode>.  Only
482 numeric modes are supported.
483
484 This function returns 0 on success or -1 on error.
485
486 =head2 guestfs_chown
487
488  int guestfs_chown (guestfs_h *handle,
489                 int owner,
490                 int group,
491                 const char *path);
492
493 Change the file owner to C<owner> and group to C<group>.
494
495 Only numeric uid and gid are supported.  If you want to use
496 names, you will need to locate and parse the password file
497 yourself (Augeas support makes this relatively easy).
498
499 This function returns 0 on success or -1 on error.
500
501 =head2 guestfs_command
502
503  char *guestfs_command (guestfs_h *handle,
504                 char * const* const arguments);
505
506 This call runs a command from the guest filesystem.  The
507 filesystem must be mounted, and must contain a compatible
508 operating system (ie. something Linux, with the same
509 or compatible processor architecture).
510
511 The single parameter is an argv-style list of arguments.
512 The first element is the name of the program to run.
513 Subsequent elements are parameters.  The list must be
514 non-empty (ie. must contain a program name).  Note that
515 the command runs directly, and is I<not> invoked via
516 the shell (see C<guestfs_sh>).
517
518 The return value is anything printed to I<stdout> by
519 the command.
520
521 If the command returns a non-zero exit status, then
522 this function returns an error message.  The error message
523 string is the content of I<stderr> from the command.
524
525 The C<$PATH> environment variable will contain at least
526 C</usr/bin> and C</bin>.  If you require a program from
527 another location, you should provide the full path in the
528 first parameter.
529
530 Shared libraries and data files required by the program
531 must be available on filesystems which are mounted in the
532 correct places.  It is the caller's responsibility to ensure
533 all filesystems that are needed are mounted at the right
534 locations.
535
536 This function returns a string, or NULL on error.
537 I<The caller must free the returned string after use>.
538
539 Because of the message protocol, there is a transfer limit 
540 of somewhere between 2MB and 4MB.  To transfer large files you should use
541 FTP.
542
543 =head2 guestfs_command_lines
544
545  char **guestfs_command_lines (guestfs_h *handle,
546                 char * const* const arguments);
547
548 This is the same as C<guestfs_command>, but splits the
549 result into a list of lines.
550
551 See also: C<guestfs_sh_lines>
552
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>.
556
557 Because of the message protocol, there is a transfer limit 
558 of somewhere between 2MB and 4MB.  To transfer large files you should use
559 FTP.
560
561 =head2 guestfs_config
562
563  int guestfs_config (guestfs_h *handle,
564                 const char *qemuparam,
565                 const char *qemuvalue);
566
567 This can be used to add arbitrary qemu command line parameters
568 of the form C<-param value>.  Actually it's not quite arbitrary - we
569 prevent you from setting some parameters which would interfere with
570 parameters that we use.
571
572 The first character of C<param> string must be a C<-> (dash).
573
574 C<value> can be NULL.
575
576 This function returns 0 on success or -1 on error.
577
578 =head2 guestfs_cp
579
580  int guestfs_cp (guestfs_h *handle,
581                 const char *src,
582                 const char *dest);
583
584 This copies a file from C<src> to C<dest> where C<dest> is
585 either a destination filename or destination directory.
586
587 This function returns 0 on success or -1 on error.
588
589 =head2 guestfs_cp_a
590
591  int guestfs_cp_a (guestfs_h *handle,
592                 const char *src,
593                 const char *dest);
594
595 This copies a file or directory from C<src> to C<dest>
596 recursively using the C<cp -a> command.
597
598 This function returns 0 on success or -1 on error.
599
600 =head2 guestfs_debug
601
602  char *guestfs_debug (guestfs_h *handle,
603                 const char *subcmd,
604                 char * const* const extraargs);
605
606 The C<guestfs_debug> command exposes some internals of
607 C<guestfsd> (the guestfs daemon) that runs inside the
608 qemu subprocess.
609
610 There is no comprehensive help for this command.  You have
611 to look at the file C<daemon/debug.c> in the libguestfs source
612 to find out what you can do.
613
614 This function returns a string, or NULL on error.
615 I<The caller must free the returned string after use>.
616
617 =head2 guestfs_dmesg
618
619  char *guestfs_dmesg (guestfs_h *handle);
620
621 This returns the kernel messages (C<dmesg> output) from
622 the guest kernel.  This is sometimes useful for extended
623 debugging of problems.
624
625 Another way to get the same information is to enable
626 verbose messages with C<guestfs_set_verbose> or by setting
627 the environment variable C<LIBGUESTFS_DEBUG=1> before
628 running the program.
629
630 This function returns a string, or NULL on error.
631 I<The caller must free the returned string after use>.
632
633 =head2 guestfs_download
634
635  int guestfs_download (guestfs_h *handle,
636                 const char *remotefilename,
637                 const char *filename);
638
639 Download file C<remotefilename> and save it as C<filename>
640 on the local machine.
641
642 C<filename> can also be a named pipe.
643
644 See also C<guestfs_upload>, C<guestfs_cat>.
645
646 This function returns 0 on success or -1 on error.
647
648 =head2 guestfs_drop_caches
649
650  int guestfs_drop_caches (guestfs_h *handle,
651                 int whattodrop);
652
653 This instructs the guest kernel to drop its page cache,
654 and/or dentries and inode caches.  The parameter C<whattodrop>
655 tells the kernel what precisely to drop, see
656 L<http://linux-mm.org/Drop_Caches>
657
658 Setting C<whattodrop> to 3 should drop everything.
659
660 This automatically calls L<sync(2)> before the operation,
661 so that the maximum guest memory is freed.
662
663 This function returns 0 on success or -1 on error.
664
665 =head2 guestfs_e2fsck_f
666
667  int guestfs_e2fsck_f (guestfs_h *handle,
668                 const char *device);
669
670 This runs C<e2fsck -p -f device>, ie. runs the ext2/ext3
671 filesystem checker on C<device>, noninteractively (C<-p>),
672 even if the filesystem appears to be clean (C<-f>).
673
674 This command is only needed because of C<guestfs_resize2fs>
675 (q.v.).  Normally you should use C<guestfs_fsck>.
676
677 This function returns 0 on success or -1 on error.
678
679 =head2 guestfs_end_busy
680
681  int guestfs_end_busy (guestfs_h *handle);
682
683 This sets the state to C<READY>, or if in C<CONFIG> then it leaves the
684 state as is.  This is only used when implementing
685 actions using the low-level API.
686
687 For more information on states, see L<guestfs(3)>.
688
689 This function returns 0 on success or -1 on error.
690
691 =head2 guestfs_equal
692
693  int guestfs_equal (guestfs_h *handle,
694                 const char *file1,
695                 const char *file2);
696
697 This compares the two files C<file1> and C<file2> and returns
698 true if their content is exactly equal, or false otherwise.
699
700 The external L<cmp(1)> program is used for the comparison.
701
702 This function returns a C truth value on success or -1 on error.
703
704 =head2 guestfs_exists
705
706  int guestfs_exists (guestfs_h *handle,
707                 const char *path);
708
709 This returns C<true> if and only if there is a file, directory
710 (or anything) with the given C<path> name.
711
712 See also C<guestfs_is_file>, C<guestfs_is_dir>, C<guestfs_stat>.
713
714 This function returns a C truth value on success or -1 on error.
715
716 =head2 guestfs_file
717
718  char *guestfs_file (guestfs_h *handle,
719                 const char *path);
720
721 This call uses the standard L<file(1)> command to determine
722 the type or contents of the file.  This also works on devices,
723 for example to find out whether a partition contains a filesystem.
724
725 The exact command which runs is C<file -bsL path>.  Note in
726 particular that the filename is not prepended to the output
727 (the C<-b> option).
728
729 This function returns a string, or NULL on error.
730 I<The caller must free the returned string after use>.
731
732 =head2 guestfs_find
733
734  char **guestfs_find (guestfs_h *handle,
735                 const char *directory);
736
737 This command lists out all files and directories, recursively,
738 starting at C<directory>.  It is essentially equivalent to
739 running the shell command C<find directory -print> but some
740 post-processing happens on the output, described below.
741
742 This returns a list of strings I<without any prefix>.  Thus
743 if the directory structure was:
744
745  /tmp/a
746  /tmp/b
747  /tmp/c/d
748
749 then the returned list from C<guestfs_find> C</tmp> would be
750 4 elements:
751
752  a
753  b
754  c
755  c/d
756
757 If C<directory> is not a directory, then this command returns
758 an error.
759
760 The returned list is sorted.
761
762 This function returns a NULL-terminated array of strings
763 (like L<environ(3)>), or NULL if there was an error.
764 I<The caller must free the strings and the array after use>.
765
766 =head2 guestfs_fsck
767
768  int guestfs_fsck (guestfs_h *handle,
769                 const char *fstype,
770                 const char *device);
771
772 This runs the filesystem checker (fsck) on C<device> which
773 should have filesystem type C<fstype>.
774
775 The returned integer is the status.  See L<fsck(8)> for the
776 list of status codes from C<fsck>.
777
778 Notes:
779
780 =over 4
781
782 =item *
783
784 Multiple status codes can be summed together.
785
786 =item *
787
788 A non-zero return code can mean "success", for example if
789 errors have been corrected on the filesystem.
790
791 =item *
792
793 Checking or repairing NTFS volumes is not supported
794 (by linux-ntfs).
795
796 =back
797
798 This command is entirely equivalent to running C<fsck -a -t fstype device>.
799
800 On error this function returns -1.
801
802 =head2 guestfs_get_append
803
804  const char *guestfs_get_append (guestfs_h *handle);
805
806 Return the additional kernel options which are added to the
807 guest kernel command line.
808
809 If C<NULL> then no options are added.
810
811 This function returns a string, or NULL on error.
812 The string is owned by the guest handle and must I<not> be freed.
813
814 =head2 guestfs_get_autosync
815
816  int guestfs_get_autosync (guestfs_h *handle);
817
818 Get the autosync flag.
819
820 This function returns a C truth value on success or -1 on error.
821
822 =head2 guestfs_get_e2label
823
824  char *guestfs_get_e2label (guestfs_h *handle,
825                 const char *device);
826
827 This returns the ext2/3/4 filesystem label of the filesystem on
828 C<device>.
829
830 This function returns a string, or NULL on error.
831 I<The caller must free the returned string after use>.
832
833 =head2 guestfs_get_e2uuid
834
835  char *guestfs_get_e2uuid (guestfs_h *handle,
836                 const char *device);
837
838 This returns the ext2/3/4 filesystem UUID of the filesystem on
839 C<device>.
840
841 This function returns a string, or NULL on error.
842 I<The caller must free the returned string after use>.
843
844 =head2 guestfs_get_path
845
846  const char *guestfs_get_path (guestfs_h *handle);
847
848 Return the current search path.
849
850 This is always non-NULL.  If it wasn't set already, then this will
851 return the default path.
852
853 This function returns a string, or NULL on error.
854 The string is owned by the guest handle and must I<not> be freed.
855
856 =head2 guestfs_get_qemu
857
858  const char *guestfs_get_qemu (guestfs_h *handle);
859
860 Return the current qemu binary.
861
862 This is always non-NULL.  If it wasn't set already, then this will
863 return the default qemu binary name.
864
865 This function returns a string, or NULL on error.
866 The string is owned by the guest handle and must I<not> be freed.
867
868 =head2 guestfs_get_state
869
870  int guestfs_get_state (guestfs_h *handle);
871
872 This returns the current state as an opaque integer.  This is
873 only useful for printing debug and internal error messages.
874
875 For more information on states, see L<guestfs(3)>.
876
877 On error this function returns -1.
878
879 =head2 guestfs_get_verbose
880
881  int guestfs_get_verbose (guestfs_h *handle);
882
883 This returns the verbose messages flag.
884
885 This function returns a C truth value on success or -1 on error.
886
887 =head2 guestfs_glob_expand
888
889  char **guestfs_glob_expand (guestfs_h *handle,
890                 const char *pattern);
891
892 This command searches for all the pathnames matching
893 C<pattern> according to the wildcard expansion rules
894 used by the shell.
895
896 If no paths match, then this returns an empty list
897 (note: not an error).
898
899 It is just a wrapper around the C L<glob(3)> function
900 with flags C<GLOB_MARK|GLOB_BRACE>.
901 See that manual page for more details.
902
903 This function returns a NULL-terminated array of strings
904 (like L<environ(3)>), or NULL if there was an error.
905 I<The caller must free the strings and the array after use>.
906
907 =head2 guestfs_grub_install
908
909  int guestfs_grub_install (guestfs_h *handle,
910                 const char *root,
911                 const char *device);
912
913 This command installs GRUB (the Grand Unified Bootloader) on
914 C<device>, with the root directory being C<root>.
915
916 This function returns 0 on success or -1 on error.
917
918 =head2 guestfs_head
919
920  char **guestfs_head (guestfs_h *handle,
921                 const char *path);
922
923 This command returns up to the first 10 lines of a file as
924 a list of strings.
925
926 This function returns a NULL-terminated array of strings
927 (like L<environ(3)>), or NULL if there was an error.
928 I<The caller must free the strings and the array after use>.
929
930 Because of the message protocol, there is a transfer limit 
931 of somewhere between 2MB and 4MB.  To transfer large files you should use
932 FTP.
933
934 =head2 guestfs_head_n
935
936  char **guestfs_head_n (guestfs_h *handle,
937                 int nrlines,
938                 const char *path);
939
940 If the parameter C<nrlines> is a positive number, this returns the first
941 C<nrlines> lines of the file C<path>.
942
943 If the parameter C<nrlines> is a negative number, this returns lines
944 from the file C<path>, excluding the last C<nrlines> lines.
945
946 If the parameter C<nrlines> is zero, this returns an empty list.
947
948 This function returns a NULL-terminated array of strings
949 (like L<environ(3)>), or NULL if there was an error.
950 I<The caller must free the strings and the array after use>.
951
952 Because of the message protocol, there is a transfer limit 
953 of somewhere between 2MB and 4MB.  To transfer large files you should use
954 FTP.
955
956 =head2 guestfs_hexdump
957
958  char *guestfs_hexdump (guestfs_h *handle,
959                 const char *path);
960
961 This runs C<hexdump -C> on the given C<path>.  The result is
962 the human-readable, canonical hex dump of the file.
963
964 This function returns a string, or NULL on error.
965 I<The caller must free the returned string after use>.
966
967 Because of the message protocol, there is a transfer limit 
968 of somewhere between 2MB and 4MB.  To transfer large files you should use
969 FTP.
970
971 =head2 guestfs_is_busy
972
973  int guestfs_is_busy (guestfs_h *handle);
974
975 This returns true iff this handle is busy processing a command
976 (in the C<BUSY> state).
977
978 For more information on states, see L<guestfs(3)>.
979
980 This function returns a C truth value on success or -1 on error.
981
982 =head2 guestfs_is_config
983
984  int guestfs_is_config (guestfs_h *handle);
985
986 This returns true iff this handle is being configured
987 (in the C<CONFIG> state).
988
989 For more information on states, see L<guestfs(3)>.
990
991 This function returns a C truth value on success or -1 on error.
992
993 =head2 guestfs_is_dir
994
995  int guestfs_is_dir (guestfs_h *handle,
996                 const char *path);
997
998 This returns C<true> if and only if there is a directory
999 with the given C<path> name.  Note that it returns false for
1000 other objects like files.
1001
1002 See also C<guestfs_stat>.
1003
1004 This function returns a C truth value on success or -1 on error.
1005
1006 =head2 guestfs_is_file
1007
1008  int guestfs_is_file (guestfs_h *handle,
1009                 const char *path);
1010
1011 This returns C<true> if and only if there is a file
1012 with the given C<path> name.  Note that it returns false for
1013 other objects like directories.
1014
1015 See also C<guestfs_stat>.
1016
1017 This function returns a C truth value on success or -1 on error.
1018
1019 =head2 guestfs_is_launching
1020
1021  int guestfs_is_launching (guestfs_h *handle);
1022
1023 This returns true iff this handle is launching the subprocess
1024 (in the C<LAUNCHING> state).
1025
1026 For more information on states, see L<guestfs(3)>.
1027
1028 This function returns a C truth value on success or -1 on error.
1029
1030 =head2 guestfs_is_ready
1031
1032  int guestfs_is_ready (guestfs_h *handle);
1033
1034 This returns true iff this handle is ready to accept commands
1035 (in the C<READY> state).
1036
1037 For more information on states, see L<guestfs(3)>.
1038
1039 This function returns a C truth value on success or -1 on error.
1040
1041 =head2 guestfs_kill_subprocess
1042
1043  int guestfs_kill_subprocess (guestfs_h *handle);
1044
1045 This kills the qemu subprocess.  You should never need to call this.
1046
1047 This function returns 0 on success or -1 on error.
1048
1049 =head2 guestfs_launch
1050
1051  int guestfs_launch (guestfs_h *handle);
1052
1053 Internally libguestfs is implemented by running a virtual machine
1054 using L<qemu(1)>.
1055
1056 You should call this after configuring the handle
1057 (eg. adding drives) but before performing any actions.
1058
1059 This function returns 0 on success or -1 on error.
1060
1061 =head2 guestfs_list_devices
1062
1063  char **guestfs_list_devices (guestfs_h *handle);
1064
1065 List all the block devices.
1066
1067 The full block device names are returned, eg. C</dev/sda>
1068
1069 This function returns a NULL-terminated array of strings
1070 (like L<environ(3)>), or NULL if there was an error.
1071 I<The caller must free the strings and the array after use>.
1072
1073 =head2 guestfs_list_partitions
1074
1075  char **guestfs_list_partitions (guestfs_h *handle);
1076
1077 List all the partitions detected on all block devices.
1078
1079 The full partition device names are returned, eg. C</dev/sda1>
1080
1081 This does not return logical volumes.  For that you will need to
1082 call C<guestfs_lvs>.
1083
1084 This function returns a NULL-terminated array of strings
1085 (like L<environ(3)>), or NULL if there was an error.
1086 I<The caller must free the strings and the array after use>.
1087
1088 =head2 guestfs_ll
1089
1090  char *guestfs_ll (guestfs_h *handle,
1091                 const char *directory);
1092
1093 List the files in C<directory> (relative to the root directory,
1094 there is no cwd) in the format of 'ls -la'.
1095
1096 This command is mostly useful for interactive sessions.  It
1097 is I<not> intended that you try to parse the output string.
1098
1099 This function returns a string, or NULL on error.
1100 I<The caller must free the returned string after use>.
1101
1102 =head2 guestfs_ls
1103
1104  char **guestfs_ls (guestfs_h *handle,
1105                 const char *directory);
1106
1107 List the files in C<directory> (relative to the root directory,
1108 there is no cwd).  The '.' and '..' entries are not returned, but
1109 hidden files are shown.
1110
1111 This command is mostly useful for interactive sessions.  Programs
1112 should probably use C<guestfs_readdir> instead.
1113
1114 This function returns a NULL-terminated array of strings
1115 (like L<environ(3)>), or NULL if there was an error.
1116 I<The caller must free the strings and the array after use>.
1117
1118 =head2 guestfs_lstat
1119
1120  struct guestfs_stat *guestfs_lstat (guestfs_h *handle,
1121                 const char *path);
1122
1123 Returns file information for the given C<path>.
1124
1125 This is the same as C<guestfs_stat> except that if C<path>
1126 is a symbolic link, then the link is stat-ed, not the file it
1127 refers to.
1128
1129 This is the same as the C<lstat(2)> system call.
1130
1131 This function returns a C<struct guestfs_stat *>
1132 (see L<stat(2)> and E<lt>guestfs-structs.hE<gt>),
1133 or NULL if there was an error.
1134 I<The caller must call C<free> after use>.
1135
1136 =head2 guestfs_lvcreate
1137
1138  int guestfs_lvcreate (guestfs_h *handle,
1139                 const char *logvol,
1140                 const char *volgroup,
1141                 int mbytes);
1142
1143 This creates an LVM volume group called C<logvol>
1144 on the volume group C<volgroup>, with C<size> megabytes.
1145
1146 This function returns 0 on success or -1 on error.
1147
1148 =head2 guestfs_lvm_remove_all
1149
1150  int guestfs_lvm_remove_all (guestfs_h *handle);
1151
1152 This command removes all LVM logical volumes, volume groups
1153 and physical volumes.
1154
1155 This function returns 0 on success or -1 on error.
1156
1157 B<This command is dangerous.  Without careful use you
1158 can easily destroy all your data>.
1159
1160 =head2 guestfs_lvremove
1161
1162  int guestfs_lvremove (guestfs_h *handle,
1163                 const char *device);
1164
1165 Remove an LVM logical volume C<device>, where C<device> is
1166 the path to the LV, such as C</dev/VG/LV>.
1167
1168 You can also remove all LVs in a volume group by specifying
1169 the VG name, C</dev/VG>.
1170
1171 This function returns 0 on success or -1 on error.
1172
1173 =head2 guestfs_lvresize
1174
1175  int guestfs_lvresize (guestfs_h *handle,
1176                 const char *device,
1177                 int mbytes);
1178
1179 This resizes (expands or shrinks) an existing LVM logical
1180 volume to C<mbytes>.  When reducing, data in the reduced part
1181 is lost.
1182
1183 This function returns 0 on success or -1 on error.
1184
1185 =head2 guestfs_lvs
1186
1187  char **guestfs_lvs (guestfs_h *handle);
1188
1189 List all the logical volumes detected.  This is the equivalent
1190 of the L<lvs(8)> command.
1191
1192 This returns a list of the logical volume device names
1193 (eg. C</dev/VolGroup00/LogVol00>).
1194
1195 See also C<guestfs_lvs_full>.
1196
1197 This function returns a NULL-terminated array of strings
1198 (like L<environ(3)>), or NULL if there was an error.
1199 I<The caller must free the strings and the array after use>.
1200
1201 =head2 guestfs_lvs_full
1202
1203  struct guestfs_lvm_lv_list *guestfs_lvs_full (guestfs_h *handle);
1204
1205 List all the logical volumes detected.  This is the equivalent
1206 of the L<lvs(8)> command.  The "full" version includes all fields.
1207
1208 This function returns a C<struct guestfs_lvm_lv_list *>
1209 (see E<lt>guestfs-structs.hE<gt>),
1210 or NULL if there was an error.
1211 I<The caller must call C<guestfs_free_lvm_lv_list> after use>.
1212
1213 =head2 guestfs_mkdir
1214
1215  int guestfs_mkdir (guestfs_h *handle,
1216                 const char *path);
1217
1218 Create a directory named C<path>.
1219
1220 This function returns 0 on success or -1 on error.
1221
1222 =head2 guestfs_mkdir_p
1223
1224  int guestfs_mkdir_p (guestfs_h *handle,
1225                 const char *path);
1226
1227 Create a directory named C<path>, creating any parent directories
1228 as necessary.  This is like the C<mkdir -p> shell command.
1229
1230 This function returns 0 on success or -1 on error.
1231
1232 =head2 guestfs_mkdtemp
1233
1234  char *guestfs_mkdtemp (guestfs_h *handle,
1235                 const char *template);
1236
1237 This command creates a temporary directory.  The
1238 C<template> parameter should be a full pathname for the
1239 temporary directory name with the final six characters being
1240 "XXXXXX".
1241
1242 For example: "/tmp/myprogXXXXXX" or "/Temp/myprogXXXXXX",
1243 the second one being suitable for Windows filesystems.
1244
1245 The name of the temporary directory that was created
1246 is returned.
1247
1248 The temporary directory is created with mode 0700
1249 and is owned by root.
1250
1251 The caller is responsible for deleting the temporary
1252 directory and its contents after use.
1253
1254 See also: L<mkdtemp(3)>
1255
1256 This function returns a string, or NULL on error.
1257 I<The caller must free the returned string after use>.
1258
1259 =head2 guestfs_mkfs
1260
1261  int guestfs_mkfs (guestfs_h *handle,
1262                 const char *fstype,
1263                 const char *device);
1264
1265 This creates a filesystem on C<device> (usually a partition
1266 or LVM logical volume).  The filesystem type is C<fstype>, for
1267 example C<ext3>.
1268
1269 This function returns 0 on success or -1 on error.
1270
1271 =head2 guestfs_mount
1272
1273  int guestfs_mount (guestfs_h *handle,
1274                 const char *device,
1275                 const char *mountpoint);
1276
1277 Mount a guest disk at a position in the filesystem.  Block devices
1278 are named C</dev/sda>, C</dev/sdb> and so on, as they were added to
1279 the guest.  If those block devices contain partitions, they will have
1280 the usual names (eg. C</dev/sda1>).  Also LVM C</dev/VG/LV>-style
1281 names can be used.
1282
1283 The rules are the same as for L<mount(2)>:  A filesystem must
1284 first be mounted on C</> before others can be mounted.  Other
1285 filesystems can only be mounted on directories which already
1286 exist.
1287
1288 The mounted filesystem is writable, if we have sufficient permissions
1289 on the underlying device.
1290
1291 The filesystem options C<sync> and C<noatime> are set with this
1292 call, in order to improve reliability.
1293
1294 This function returns 0 on success or -1 on error.
1295
1296 =head2 guestfs_mount_options
1297
1298  int guestfs_mount_options (guestfs_h *handle,
1299                 const char *options,
1300                 const char *device,
1301                 const char *mountpoint);
1302
1303 This is the same as the C<guestfs_mount> command, but it
1304 allows you to set the mount options as for the
1305 L<mount(8)> I<-o> flag.
1306
1307 This function returns 0 on success or -1 on error.
1308
1309 =head2 guestfs_mount_ro
1310
1311  int guestfs_mount_ro (guestfs_h *handle,
1312                 const char *device,
1313                 const char *mountpoint);
1314
1315 This is the same as the C<guestfs_mount> command, but it
1316 mounts the filesystem with the read-only (I<-o ro>) flag.
1317
1318 This function returns 0 on success or -1 on error.
1319
1320 =head2 guestfs_mount_vfs
1321
1322  int guestfs_mount_vfs (guestfs_h *handle,
1323                 const char *options,
1324                 const char *vfstype,
1325                 const char *device,
1326                 const char *mountpoint);
1327
1328 This is the same as the C<guestfs_mount> command, but it
1329 allows you to set both the mount options and the vfstype
1330 as for the L<mount(8)> I<-o> and I<-t> flags.
1331
1332 This function returns 0 on success or -1 on error.
1333
1334 =head2 guestfs_mounts
1335
1336  char **guestfs_mounts (guestfs_h *handle);
1337
1338 This returns the list of currently mounted filesystems.  It returns
1339 the list of devices (eg. C</dev/sda1>, C</dev/VG/LV>).
1340
1341 Some internal mounts are not shown.
1342
1343 This function returns a NULL-terminated array of strings
1344 (like L<environ(3)>), or NULL if there was an error.
1345 I<The caller must free the strings and the array after use>.
1346
1347 =head2 guestfs_mv
1348
1349  int guestfs_mv (guestfs_h *handle,
1350                 const char *src,
1351                 const char *dest);
1352
1353 This moves a file from C<src> to C<dest> where C<dest> is
1354 either a destination filename or destination directory.
1355
1356 This function returns 0 on success or -1 on error.
1357
1358 =head2 guestfs_ntfs_3g_probe
1359
1360  int guestfs_ntfs_3g_probe (guestfs_h *handle,
1361                 int rw,
1362                 const char *device);
1363
1364 This command runs the L<ntfs-3g.probe(8)> command which probes
1365 an NTFS C<device> for mountability.  (Not all NTFS volumes can
1366 be mounted read-write, and some cannot be mounted at all).
1367
1368 C<rw> is a boolean flag.  Set it to true if you want to test
1369 if the volume can be mounted read-write.  Set it to false if
1370 you want to test if the volume can be mounted read-only.
1371
1372 The return value is an integer which C<0> if the operation
1373 would succeed, or some non-zero value documented in the
1374 L<ntfs-3g.probe(8)> manual page.
1375
1376 On error this function returns -1.
1377
1378 =head2 guestfs_ping_daemon
1379
1380  int guestfs_ping_daemon (guestfs_h *handle);
1381
1382 This is a test probe into the guestfs daemon running inside
1383 the qemu subprocess.  Calling this function checks that the
1384 daemon responds to the ping message, without affecting the daemon
1385 or attached block device(s) in any other way.
1386
1387 This function returns 0 on success or -1 on error.
1388
1389 =head2 guestfs_pvcreate
1390
1391  int guestfs_pvcreate (guestfs_h *handle,
1392                 const char *device);
1393
1394 This creates an LVM physical volume on the named C<device>,
1395 where C<device> should usually be a partition name such
1396 as C</dev/sda1>.
1397
1398 This function returns 0 on success or -1 on error.
1399
1400 =head2 guestfs_pvremove
1401
1402  int guestfs_pvremove (guestfs_h *handle,
1403                 const char *device);
1404
1405 This wipes a physical volume C<device> so that LVM will no longer
1406 recognise it.
1407
1408 The implementation uses the C<pvremove> command which refuses to
1409 wipe physical volumes that contain any volume groups, so you have
1410 to remove those first.
1411
1412 This function returns 0 on success or -1 on error.
1413
1414 =head2 guestfs_pvresize
1415
1416  int guestfs_pvresize (guestfs_h *handle,
1417                 const char *device);
1418
1419 This resizes (expands or shrinks) an existing LVM physical
1420 volume to match the new size of the underlying device.
1421
1422 This function returns 0 on success or -1 on error.
1423
1424 =head2 guestfs_pvs
1425
1426  char **guestfs_pvs (guestfs_h *handle);
1427
1428 List all the physical volumes detected.  This is the equivalent
1429 of the L<pvs(8)> command.
1430
1431 This returns a list of just the device names that contain
1432 PVs (eg. C</dev/sda2>).
1433
1434 See also C<guestfs_pvs_full>.
1435
1436 This function returns a NULL-terminated array of strings
1437 (like L<environ(3)>), or NULL if there was an error.
1438 I<The caller must free the strings and the array after use>.
1439
1440 =head2 guestfs_pvs_full
1441
1442  struct guestfs_lvm_pv_list *guestfs_pvs_full (guestfs_h *handle);
1443
1444 List all the physical volumes detected.  This is the equivalent
1445 of the L<pvs(8)> command.  The "full" version includes all fields.
1446
1447 This function returns a C<struct guestfs_lvm_pv_list *>
1448 (see E<lt>guestfs-structs.hE<gt>),
1449 or NULL if there was an error.
1450 I<The caller must call C<guestfs_free_lvm_pv_list> after use>.
1451
1452 =head2 guestfs_read_lines
1453
1454  char **guestfs_read_lines (guestfs_h *handle,
1455                 const char *path);
1456
1457 Return the contents of the file named C<path>.
1458
1459 The file contents are returned as a list of lines.  Trailing
1460 C<LF> and C<CRLF> character sequences are I<not> returned.
1461
1462 Note that this function cannot correctly handle binary files
1463 (specifically, files containing C<\0> character which is treated
1464 as end of line).  For those you need to use the C<guestfs_read_file>
1465 function which has a more complex interface.
1466
1467 This function returns a NULL-terminated array of strings
1468 (like L<environ(3)>), or NULL if there was an error.
1469 I<The caller must free the strings and the array after use>.
1470
1471 =head2 guestfs_resize2fs
1472
1473  int guestfs_resize2fs (guestfs_h *handle,
1474                 const char *device);
1475
1476 This resizes an ext2 or ext3 filesystem to match the size of
1477 the underlying device.
1478
1479 I<Note:> It is sometimes required that you run C<guestfs_e2fsck_f>
1480 on the C<device> before calling this command.  For unknown reasons
1481 C<resize2fs> sometimes gives an error about this and sometimes not.
1482 In any case, it is always safe to call C<guestfs_e2fsck_f> before
1483 calling this function.
1484
1485 This function returns 0 on success or -1 on error.
1486
1487 =head2 guestfs_rm
1488
1489  int guestfs_rm (guestfs_h *handle,
1490                 const char *path);
1491
1492 Remove the single file C<path>.
1493
1494 This function returns 0 on success or -1 on error.
1495
1496 =head2 guestfs_rm_rf
1497
1498  int guestfs_rm_rf (guestfs_h *handle,
1499                 const char *path);
1500
1501 Remove the file or directory C<path>, recursively removing the
1502 contents if its a directory.  This is like the C<rm -rf> shell
1503 command.
1504
1505 This function returns 0 on success or -1 on error.
1506
1507 =head2 guestfs_rmdir
1508
1509  int guestfs_rmdir (guestfs_h *handle,
1510                 const char *path);
1511
1512 Remove the single directory C<path>.
1513
1514 This function returns 0 on success or -1 on error.
1515
1516 =head2 guestfs_scrub_device
1517
1518  int guestfs_scrub_device (guestfs_h *handle,
1519                 const char *device);
1520
1521 This command writes patterns over C<device> to make data retrieval
1522 more difficult.
1523
1524 It is an interface to the L<scrub(1)> program.  See that
1525 manual page for more details.
1526
1527 This function returns 0 on success or -1 on error.
1528
1529 B<This command is dangerous.  Without careful use you
1530 can easily destroy all your data>.
1531
1532 =head2 guestfs_scrub_file
1533
1534  int guestfs_scrub_file (guestfs_h *handle,
1535                 const char *file);
1536
1537 This command writes patterns over a file to make data retrieval
1538 more difficult.
1539
1540 The file is I<removed> after scrubbing.
1541
1542 It is an interface to the L<scrub(1)> program.  See that
1543 manual page for more details.
1544
1545 This function returns 0 on success or -1 on error.
1546
1547 =head2 guestfs_scrub_freespace
1548
1549  int guestfs_scrub_freespace (guestfs_h *handle,
1550                 const char *dir);
1551
1552 This command creates the directory C<dir> and then fills it
1553 with files until the filesystem is full, and scrubs the files
1554 as for C<guestfs_scrub_file>, and deletes them.
1555 The intention is to scrub any free space on the partition
1556 containing C<dir>.
1557
1558 It is an interface to the L<scrub(1)> program.  See that
1559 manual page for more details.
1560
1561 This function returns 0 on success or -1 on error.
1562
1563 =head2 guestfs_set_append
1564
1565  int guestfs_set_append (guestfs_h *handle,
1566                 const char *append);
1567
1568 This function is used to add additional options to the
1569 guest kernel command line.
1570
1571 The default is C<NULL> unless overridden by setting
1572 C<LIBGUESTFS_APPEND> environment variable.
1573
1574 Setting C<append> to C<NULL> means I<no> additional options
1575 are passed (libguestfs always adds a few of its own).
1576
1577 This function returns 0 on success or -1 on error.
1578
1579 =head2 guestfs_set_autosync
1580
1581  int guestfs_set_autosync (guestfs_h *handle,
1582                 int autosync);
1583
1584 If C<autosync> is true, this enables autosync.  Libguestfs will make a
1585 best effort attempt to run C<guestfs_umount_all> followed by
1586 C<guestfs_sync> when the handle is closed
1587 (also if the program exits without closing handles).
1588
1589 This is disabled by default (except in guestfish where it is
1590 enabled by default).
1591
1592 This function returns 0 on success or -1 on error.
1593
1594 =head2 guestfs_set_busy
1595
1596  int guestfs_set_busy (guestfs_h *handle);
1597
1598 This sets the state to C<BUSY>.  This is only used when implementing
1599 actions using the low-level API.
1600
1601 For more information on states, see L<guestfs(3)>.
1602
1603 This function returns 0 on success or -1 on error.
1604
1605 =head2 guestfs_set_e2label
1606
1607  int guestfs_set_e2label (guestfs_h *handle,
1608                 const char *device,
1609                 const char *label);
1610
1611 This sets the ext2/3/4 filesystem label of the filesystem on
1612 C<device> to C<label>.  Filesystem labels are limited to
1613 16 characters.
1614
1615 You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2label>
1616 to return the existing label on a filesystem.
1617
1618 This function returns 0 on success or -1 on error.
1619
1620 =head2 guestfs_set_e2uuid
1621
1622  int guestfs_set_e2uuid (guestfs_h *handle,
1623                 const char *device,
1624                 const char *uuid);
1625
1626 This sets the ext2/3/4 filesystem UUID of the filesystem on
1627 C<device> to C<uuid>.  The format of the UUID and alternatives
1628 such as C<clear>, C<random> and C<time> are described in the
1629 L<tune2fs(8)> manpage.
1630
1631 You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2uuid>
1632 to return the existing UUID of a filesystem.
1633
1634 This function returns 0 on success or -1 on error.
1635
1636 =head2 guestfs_set_path
1637
1638  int guestfs_set_path (guestfs_h *handle,
1639                 const char *path);
1640
1641 Set the path that libguestfs searches for kernel and initrd.img.
1642
1643 The default is C<$libdir/guestfs> unless overridden by setting
1644 C<LIBGUESTFS_PATH> environment variable.
1645
1646 Setting C<path> to C<NULL> restores the default path.
1647
1648 This function returns 0 on success or -1 on error.
1649
1650 =head2 guestfs_set_qemu
1651
1652  int guestfs_set_qemu (guestfs_h *handle,
1653                 const char *qemu);
1654
1655 Set the qemu binary that we will use.
1656
1657 The default is chosen when the library was compiled by the
1658 configure script.
1659
1660 You can also override this by setting the C<LIBGUESTFS_QEMU>
1661 environment variable.
1662
1663 Setting C<qemu> to C<NULL> restores the default qemu binary.
1664
1665 This function returns 0 on success or -1 on error.
1666
1667 =head2 guestfs_set_ready
1668
1669  int guestfs_set_ready (guestfs_h *handle);
1670
1671 This sets the state to C<READY>.  This is only used when implementing
1672 actions using the low-level API.
1673
1674 For more information on states, see L<guestfs(3)>.
1675
1676 This function returns 0 on success or -1 on error.
1677
1678 =head2 guestfs_set_verbose
1679
1680  int guestfs_set_verbose (guestfs_h *handle,
1681                 int verbose);
1682
1683 If C<verbose> is true, this turns on verbose messages (to C<stderr>).
1684
1685 Verbose messages are disabled unless the environment variable
1686 C<LIBGUESTFS_DEBUG> is defined and set to C<1>.
1687
1688 This function returns 0 on success or -1 on error.
1689
1690 =head2 guestfs_sfdisk
1691
1692  int guestfs_sfdisk (guestfs_h *handle,
1693                 const char *device,
1694                 int cyls,
1695                 int heads,
1696                 int sectors,
1697                 char * const* const lines);
1698
1699 This is a direct interface to the L<sfdisk(8)> program for creating
1700 partitions on block devices.
1701
1702 C<device> should be a block device, for example C</dev/sda>.
1703
1704 C<cyls>, C<heads> and C<sectors> are the number of cylinders, heads
1705 and sectors on the device, which are passed directly to sfdisk as
1706 the I<-C>, I<-H> and I<-S> parameters.  If you pass C<0> for any
1707 of these, then the corresponding parameter is omitted.  Usually for
1708 'large' disks, you can just pass C<0> for these, but for small
1709 (floppy-sized) disks, sfdisk (or rather, the kernel) cannot work
1710 out the right geometry and you will need to tell it.
1711
1712 C<lines> is a list of lines that we feed to C<sfdisk>.  For more
1713 information refer to the L<sfdisk(8)> manpage.
1714
1715 To create a single partition occupying the whole disk, you would
1716 pass C<lines> as a single element list, when the single element being
1717 the string C<,> (comma).
1718
1719 See also: C<guestfs_sfdisk_l>, C<guestfs_sfdisk_N>
1720
1721 This function returns 0 on success or -1 on error.
1722
1723 B<This command is dangerous.  Without careful use you
1724 can easily destroy all your data>.
1725
1726 =head2 guestfs_sfdisk_N
1727
1728  int guestfs_sfdisk_N (guestfs_h *handle,
1729                 const char *device,
1730                 int partnum,
1731                 int cyls,
1732                 int heads,
1733                 int sectors,
1734                 const char *line);
1735
1736 This runs L<sfdisk(8)> option to modify just the single
1737 partition C<n> (note: C<n> counts from 1).
1738
1739 For other parameters, see C<guestfs_sfdisk>.  You should usually
1740 pass C<0> for the cyls/heads/sectors parameters.
1741
1742 This function returns 0 on success or -1 on error.
1743
1744 B<This command is dangerous.  Without careful use you
1745 can easily destroy all your data>.
1746
1747 =head2 guestfs_sfdisk_disk_geometry
1748
1749  char *guestfs_sfdisk_disk_geometry (guestfs_h *handle,
1750                 const char *device);
1751
1752 This displays the disk geometry of C<device> read from the
1753 partition table.  Especially in the case where the underlying
1754 block device has been resized, this can be different from the
1755 kernel's idea of the geometry (see C<guestfs_sfdisk_kernel_geometry>).
1756
1757 The result is in human-readable format, and not designed to
1758 be parsed.
1759
1760 This function returns a string, or NULL on error.
1761 I<The caller must free the returned string after use>.
1762
1763 =head2 guestfs_sfdisk_kernel_geometry
1764
1765  char *guestfs_sfdisk_kernel_geometry (guestfs_h *handle,
1766                 const char *device);
1767
1768 This displays the kernel's idea of the geometry of C<device>.
1769
1770 The result is in human-readable format, and not designed to
1771 be parsed.
1772
1773 This function returns a string, or NULL on error.
1774 I<The caller must free the returned string after use>.
1775
1776 =head2 guestfs_sfdisk_l
1777
1778  char *guestfs_sfdisk_l (guestfs_h *handle,
1779                 const char *device);
1780
1781 This displays the partition table on C<device>, in the
1782 human-readable output of the L<sfdisk(8)> command.  It is
1783 not intended to be parsed.
1784
1785 This function returns a string, or NULL on error.
1786 I<The caller must free the returned string after use>.
1787
1788 =head2 guestfs_sh
1789
1790  char *guestfs_sh (guestfs_h *handle,
1791                 const char *command);
1792
1793 This call runs a command from the guest filesystem via the
1794 guest's C</bin/sh>.
1795
1796 This is like C<guestfs_command>, but passes the command to:
1797
1798  /bin/sh -c "command"
1799
1800 Depending on the guest's shell, this usually results in
1801 wildcards being expanded, shell expressions being interpolated
1802 and so on.
1803
1804 All the provisos about C<guestfs_command> apply to this call.
1805
1806 This function returns a string, or NULL on error.
1807 I<The caller must free the returned string after use>.
1808
1809 =head2 guestfs_sh_lines
1810
1811  char **guestfs_sh_lines (guestfs_h *handle,
1812                 const char *command);
1813
1814 This is the same as C<guestfs_sh>, but splits the result
1815 into a list of lines.
1816
1817 See also: C<guestfs_command_lines>
1818
1819 This function returns a NULL-terminated array of strings
1820 (like L<environ(3)>), or NULL if there was an error.
1821 I<The caller must free the strings and the array after use>.
1822
1823 =head2 guestfs_sleep
1824
1825  int guestfs_sleep (guestfs_h *handle,
1826                 int secs);
1827
1828 Sleep for C<secs> seconds.
1829
1830 This function returns 0 on success or -1 on error.
1831
1832 =head2 guestfs_stat
1833
1834  struct guestfs_stat *guestfs_stat (guestfs_h *handle,
1835                 const char *path);
1836
1837 Returns file information for the given C<path>.
1838
1839 This is the same as the C<stat(2)> system call.
1840
1841 This function returns a C<struct guestfs_stat *>
1842 (see L<stat(2)> and E<lt>guestfs-structs.hE<gt>),
1843 or NULL if there was an error.
1844 I<The caller must call C<free> after use>.
1845
1846 =head2 guestfs_statvfs
1847
1848  struct guestfs_statvfs *guestfs_statvfs (guestfs_h *handle,
1849                 const char *path);
1850
1851 Returns file system statistics for any mounted file system.
1852 C<path> should be a file or directory in the mounted file system
1853 (typically it is the mount point itself, but it doesn't need to be).
1854
1855 This is the same as the C<statvfs(2)> system call.
1856
1857 This function returns a C<struct guestfs_statvfs *>
1858 (see L<statvfs(2)> and E<lt>guestfs-structs.hE<gt>),
1859 or NULL if there was an error.
1860 I<The caller must call C<free> after use>.
1861
1862 =head2 guestfs_strings
1863
1864  char **guestfs_strings (guestfs_h *handle,
1865                 const char *path);
1866
1867 This runs the L<strings(1)> command on a file and returns
1868 the list of printable strings found.
1869
1870 This function returns a NULL-terminated array of strings
1871 (like L<environ(3)>), or NULL if there was an error.
1872 I<The caller must free the strings and the array after use>.
1873
1874 Because of the message protocol, there is a transfer limit 
1875 of somewhere between 2MB and 4MB.  To transfer large files you should use
1876 FTP.
1877
1878 =head2 guestfs_strings_e
1879
1880  char **guestfs_strings_e (guestfs_h *handle,
1881                 const char *encoding,
1882                 const char *path);
1883
1884 This is like the C<guestfs_strings> command, but allows you to
1885 specify the encoding.
1886
1887 See the L<strings(1)> manpage for the full list of encodings.
1888
1889 Commonly useful encodings are C<l> (lower case L) which will
1890 show strings inside Windows/x86 files.
1891
1892 The returned strings are transcoded to UTF-8.
1893
1894 This function returns a NULL-terminated array of strings
1895 (like L<environ(3)>), or NULL if there was an error.
1896 I<The caller must free the strings and the array after use>.
1897
1898 Because of the message protocol, there is a transfer limit 
1899 of somewhere between 2MB and 4MB.  To transfer large files you should use
1900 FTP.
1901
1902 =head2 guestfs_sync
1903
1904  int guestfs_sync (guestfs_h *handle);
1905
1906 This syncs the disk, so that any writes are flushed through to the
1907 underlying disk image.
1908
1909 You should always call this if you have modified a disk image, before
1910 closing the handle.
1911
1912 This function returns 0 on success or -1 on error.
1913
1914 =head2 guestfs_tail
1915
1916  char **guestfs_tail (guestfs_h *handle,
1917                 const char *path);
1918
1919 This command returns up to the last 10 lines of a file as
1920 a list of strings.
1921
1922 This function returns a NULL-terminated array of strings
1923 (like L<environ(3)>), or NULL if there was an error.
1924 I<The caller must free the strings and the array after use>.
1925
1926 Because of the message protocol, there is a transfer limit 
1927 of somewhere between 2MB and 4MB.  To transfer large files you should use
1928 FTP.
1929
1930 =head2 guestfs_tail_n
1931
1932  char **guestfs_tail_n (guestfs_h *handle,
1933                 int nrlines,
1934                 const char *path);
1935
1936 If the parameter C<nrlines> is a positive number, this returns the last
1937 C<nrlines> lines of the file C<path>.
1938
1939 If the parameter C<nrlines> is a negative number, this returns lines
1940 from the file C<path>, starting with the C<-nrlines>th line.
1941
1942 If the parameter C<nrlines> is zero, this returns an empty list.
1943
1944 This function returns a NULL-terminated array of strings
1945 (like L<environ(3)>), or NULL if there was an error.
1946 I<The caller must free the strings and the array after use>.
1947
1948 Because of the message protocol, there is a transfer limit 
1949 of somewhere between 2MB and 4MB.  To transfer large files you should use
1950 FTP.
1951
1952 =head2 guestfs_tar_in
1953
1954  int guestfs_tar_in (guestfs_h *handle,
1955                 const char *tarfile,
1956                 const char *directory);
1957
1958 This command uploads and unpacks local file C<tarfile> (an
1959 I<uncompressed> tar file) into C<directory>.
1960
1961 To upload a compressed tarball, use C<guestfs_tgz_in>.
1962
1963 This function returns 0 on success or -1 on error.
1964
1965 =head2 guestfs_tar_out
1966
1967  int guestfs_tar_out (guestfs_h *handle,
1968                 const char *directory,
1969                 const char *tarfile);
1970
1971 This command packs the contents of C<directory> and downloads
1972 it to local file C<tarfile>.
1973
1974 To download a compressed tarball, use C<guestfs_tgz_out>.
1975
1976 This function returns 0 on success or -1 on error.
1977
1978 =head2 guestfs_tgz_in
1979
1980  int guestfs_tgz_in (guestfs_h *handle,
1981                 const char *tarball,
1982                 const char *directory);
1983
1984 This command uploads and unpacks local file C<tarball> (a
1985 I<gzip compressed> tar file) into C<directory>.
1986
1987 To upload an uncompressed tarball, use C<guestfs_tar_in>.
1988
1989 This function returns 0 on success or -1 on error.
1990
1991 =head2 guestfs_tgz_out
1992
1993  int guestfs_tgz_out (guestfs_h *handle,
1994                 const char *directory,
1995                 const char *tarball);
1996
1997 This command packs the contents of C<directory> and downloads
1998 it to local file C<tarball>.
1999
2000 To download an uncompressed tarball, use C<guestfs_tar_out>.
2001
2002 This function returns 0 on success or -1 on error.
2003
2004 =head2 guestfs_touch
2005
2006  int guestfs_touch (guestfs_h *handle,
2007                 const char *path);
2008
2009 Touch acts like the L<touch(1)> command.  It can be used to
2010 update the timestamps on a file, or, if the file does not exist,
2011 to create a new zero-length file.
2012
2013 This function returns 0 on success or -1 on error.
2014
2015 =head2 guestfs_tune2fs_l
2016
2017  char **guestfs_tune2fs_l (guestfs_h *handle,
2018                 const char *device);
2019
2020 This returns the contents of the ext2, ext3 or ext4 filesystem
2021 superblock on C<device>.
2022
2023 It is the same as running C<tune2fs -l device>.  See L<tune2fs(8)>
2024 manpage for more details.  The list of fields returned isn't
2025 clearly defined, and depends on both the version of C<tune2fs>
2026 that libguestfs was built against, and the filesystem itself.
2027
2028 This function returns a NULL-terminated array of
2029 strings, or NULL if there was an error.
2030 The array of strings will always have length C<2n+1>, where
2031 C<n> keys and values alternate, followed by the trailing NULL entry.
2032 I<The caller must free the strings and the array after use>.
2033
2034 =head2 guestfs_umount
2035
2036  int guestfs_umount (guestfs_h *handle,
2037                 const char *pathordevice);
2038
2039 This unmounts the given filesystem.  The filesystem may be
2040 specified either by its mountpoint (path) or the device which
2041 contains the filesystem.
2042
2043 This function returns 0 on success or -1 on error.
2044
2045 =head2 guestfs_umount_all
2046
2047  int guestfs_umount_all (guestfs_h *handle);
2048
2049 This unmounts all mounted filesystems.
2050
2051 Some internal mounts are not unmounted by this call.
2052
2053 This function returns 0 on success or -1 on error.
2054
2055 =head2 guestfs_upload
2056
2057  int guestfs_upload (guestfs_h *handle,
2058                 const char *filename,
2059                 const char *remotefilename);
2060
2061 Upload local file C<filename> to C<remotefilename> on the
2062 filesystem.
2063
2064 C<filename> can also be a named pipe.
2065
2066 See also C<guestfs_download>.
2067
2068 This function returns 0 on success or -1 on error.
2069
2070 =head2 guestfs_vg_activate
2071
2072  int guestfs_vg_activate (guestfs_h *handle,
2073                 int activate,
2074                 char * const* const volgroups);
2075
2076 This command activates or (if C<activate> is false) deactivates
2077 all logical volumes in the listed volume groups C<volgroups>.
2078 If activated, then they are made known to the
2079 kernel, ie. they appear as C</dev/mapper> devices.  If deactivated,
2080 then those devices disappear.
2081
2082 This command is the same as running C<vgchange -a y|n volgroups...>
2083
2084 Note that if C<volgroups> is an empty list then B<all> volume groups
2085 are activated or deactivated.
2086
2087 This function returns 0 on success or -1 on error.
2088
2089 =head2 guestfs_vg_activate_all
2090
2091  int guestfs_vg_activate_all (guestfs_h *handle,
2092                 int activate);
2093
2094 This command activates or (if C<activate> is false) deactivates
2095 all logical volumes in all volume groups.
2096 If activated, then they are made known to the
2097 kernel, ie. they appear as C</dev/mapper> devices.  If deactivated,
2098 then those devices disappear.
2099
2100 This command is the same as running C<vgchange -a y|n>
2101
2102 This function returns 0 on success or -1 on error.
2103
2104 =head2 guestfs_vgcreate
2105
2106  int guestfs_vgcreate (guestfs_h *handle,
2107                 const char *volgroup,
2108                 char * const* const physvols);
2109
2110 This creates an LVM volume group called C<volgroup>
2111 from the non-empty list of physical volumes C<physvols>.
2112
2113 This function returns 0 on success or -1 on error.
2114
2115 =head2 guestfs_vgremove
2116
2117  int guestfs_vgremove (guestfs_h *handle,
2118                 const char *vgname);
2119
2120 Remove an LVM volume group C<vgname>, (for example C<VG>).
2121
2122 This also forcibly removes all logical volumes in the volume
2123 group (if any).
2124
2125 This function returns 0 on success or -1 on error.
2126
2127 =head2 guestfs_vgs
2128
2129  char **guestfs_vgs (guestfs_h *handle);
2130
2131 List all the volumes groups detected.  This is the equivalent
2132 of the L<vgs(8)> command.
2133
2134 This returns a list of just the volume group names that were
2135 detected (eg. C<VolGroup00>).
2136
2137 See also C<guestfs_vgs_full>.
2138
2139 This function returns a NULL-terminated array of strings
2140 (like L<environ(3)>), or NULL if there was an error.
2141 I<The caller must free the strings and the array after use>.
2142
2143 =head2 guestfs_vgs_full
2144
2145  struct guestfs_lvm_vg_list *guestfs_vgs_full (guestfs_h *handle);
2146
2147 List all the volumes groups detected.  This is the equivalent
2148 of the L<vgs(8)> command.  The "full" version includes all fields.
2149
2150 This function returns a C<struct guestfs_lvm_vg_list *>
2151 (see E<lt>guestfs-structs.hE<gt>),
2152 or NULL if there was an error.
2153 I<The caller must call C<guestfs_free_lvm_vg_list> after use>.
2154
2155 =head2 guestfs_wait_ready
2156
2157  int guestfs_wait_ready (guestfs_h *handle);
2158
2159 Internally libguestfs is implemented by running a virtual machine
2160 using L<qemu(1)>.
2161
2162 You should call this after C<guestfs_launch> to wait for the launch
2163 to complete.
2164
2165 This function returns 0 on success or -1 on error.
2166
2167 =head2 guestfs_wc_c
2168
2169  int guestfs_wc_c (guestfs_h *handle,
2170                 const char *path);
2171
2172 This command counts the characters in a file, using the
2173 C<wc -c> external command.
2174
2175 On error this function returns -1.
2176
2177 =head2 guestfs_wc_l
2178
2179  int guestfs_wc_l (guestfs_h *handle,
2180                 const char *path);
2181
2182 This command counts the lines in a file, using the
2183 C<wc -l> external command.
2184
2185 On error this function returns -1.
2186
2187 =head2 guestfs_wc_w
2188
2189  int guestfs_wc_w (guestfs_h *handle,
2190                 const char *path);
2191
2192 This command counts the words in a file, using the
2193 C<wc -w> external command.
2194
2195 On error this function returns -1.
2196
2197 =head2 guestfs_write_file
2198
2199  int guestfs_write_file (guestfs_h *handle,
2200                 const char *path,
2201                 const char *content,
2202                 int size);
2203
2204 This call creates a file called C<path>.  The contents of the
2205 file is the string C<content> (which can contain any 8 bit data),
2206 with length C<size>.
2207
2208 As a special case, if C<size> is C<0>
2209 then the length is calculated using C<strlen> (so in this case
2210 the content cannot contain embedded ASCII NULs).
2211
2212 I<NB.> Owing to a bug, writing content containing ASCII NUL
2213 characters does I<not> work, even if the length is specified.
2214 We hope to resolve this bug in a future version.  In the meantime
2215 use C<guestfs_upload>.
2216
2217 This function returns 0 on success or -1 on error.
2218
2219 Because of the message protocol, there is a transfer limit 
2220 of somewhere between 2MB and 4MB.  To transfer large files you should use
2221 FTP.
2222
2223 =head2 guestfs_zero
2224
2225  int guestfs_zero (guestfs_h *handle,
2226                 const char *device);
2227
2228 This command writes zeroes over the first few blocks of C<device>.
2229
2230 How many blocks are zeroed isn't specified (but it's I<not> enough
2231 to securely wipe the device).  It should be sufficient to remove
2232 any partition tables, filesystem superblocks and so on.
2233
2234 See also: C<guestfs_scrub_device>.
2235
2236 This function returns 0 on success or -1 on error.
2237
2238 =head2 guestfs_zerofree
2239
2240  int guestfs_zerofree (guestfs_h *handle,
2241                 const char *device);
2242
2243 This runs the I<zerofree> program on C<device>.  This program
2244 claims to zero unused inodes and disk blocks on an ext2/3
2245 filesystem, thus making it possible to compress the filesystem
2246 more effectively.
2247
2248 You should B<not> run this program if the filesystem is
2249 mounted.
2250
2251 It is possible that using this program can damage the filesystem
2252 or data on the filesystem.
2253
2254 This function returns 0 on success or -1 on error.
2255