Updated HACKING notes about debugging.
[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_cat
33
34  char *guestfs_cat (guestfs_h *handle,
35                 const char *path);
36
37 Return the contents of the file named C<path>.
38
39 Note that this function cannot correctly handle binary files
40 (specifically, files containing C<\0> character which is treated
41 as end of string).  For those you need to use the C<guestfs_read_file>
42 function which has a more complex interface.
43
44 This function returns a string or NULL on error.
45 I<The caller must free the returned string after use>.
46
47 Because of the message protocol, there is a transfer limit 
48 of somewhere between 2MB and 4MB.  To transfer large files you should use
49 FTP.
50
51 =head2 guestfs_config
52
53  int guestfs_config (guestfs_h *handle,
54                 const char *qemuparam,
55                 const char *qemuvalue);
56
57 This can be used to add arbitrary qemu command line parameters
58 of the form C<-param value>.  Actually it's not quite arbitrary - we
59 prevent you from setting some parameters which would interfere with
60 parameters that we use.
61
62 The first character of C<param> string must be a C<-> (dash).
63
64 C<value> can be NULL.
65
66 This function returns 0 on success or -1 on error.
67
68 =head2 guestfs_get_autosync
69
70  int guestfs_get_autosync (guestfs_h *handle);
71
72 Get the autosync flag.
73
74 This function returns a C truth value on success or -1 on error.
75
76 =head2 guestfs_get_path
77
78  const char *guestfs_get_path (guestfs_h *handle);
79
80 Return the current search path.
81
82 This is always non-NULL.  If it wasn't set already, then this will
83 return the default path.
84
85 This function returns a string or NULL on error.
86 The string is owned by the guest handle and must I<not> be freed.
87
88 =head2 guestfs_get_verbose
89
90  int guestfs_get_verbose (guestfs_h *handle);
91
92 This returns the verbose messages flag.
93
94 This function returns a C truth value on success or -1 on error.
95
96 =head2 guestfs_kill_subprocess
97
98  int guestfs_kill_subprocess (guestfs_h *handle);
99
100 This kills the qemu subprocess.  You should never need to call this.
101
102 This function returns 0 on success or -1 on error.
103
104 =head2 guestfs_launch
105
106  int guestfs_launch (guestfs_h *handle);
107
108 Internally libguestfs is implemented by running a virtual machine
109 using L<qemu(1)>.
110
111 You should call this after configuring the handle
112 (eg. adding drives) but before performing any actions.
113
114 This function returns 0 on success or -1 on error.
115
116 =head2 guestfs_list_devices
117
118  char **guestfs_list_devices (guestfs_h *handle);
119
120 List all the block devices.
121
122 The full block device names are returned, eg. C</dev/sda>
123
124 This function returns a NULL-terminated array of strings
125 (like L<environ(3)>), or NULL if there was an error.
126 I<The caller must free the strings and the array after use>.
127
128 =head2 guestfs_list_partitions
129
130  char **guestfs_list_partitions (guestfs_h *handle);
131
132 List all the partitions detected on all block devices.
133
134 The full partition device names are returned, eg. C</dev/sda1>
135
136 This does not return logical volumes.  For that you will need to
137 call C<guestfs_lvs>.
138
139 This function returns a NULL-terminated array of strings
140 (like L<environ(3)>), or NULL if there was an error.
141 I<The caller must free the strings and the array after use>.
142
143 =head2 guestfs_ll
144
145  char *guestfs_ll (guestfs_h *handle,
146                 const char *directory);
147
148 List the files in C<directory> (relative to the root directory,
149 there is no cwd) in the format of 'ls -la'.
150
151 This command is mostly useful for interactive sessions.  It
152 is I<not> intended that you try to parse the output string.
153
154 This function returns a string or NULL on error.
155 I<The caller must free the returned string after use>.
156
157 =head2 guestfs_ls
158
159  char **guestfs_ls (guestfs_h *handle,
160                 const char *directory);
161
162 List the files in C<directory> (relative to the root directory,
163 there is no cwd).  The '.' and '..' entries are not returned, but
164 hidden files are shown.
165
166 This command is mostly useful for interactive sessions.  Programs
167 should probably use C<guestfs_readdir> instead.
168
169 This function returns a NULL-terminated array of strings
170 (like L<environ(3)>), or NULL if there was an error.
171 I<The caller must free the strings and the array after use>.
172
173 =head2 guestfs_lvs
174
175  char **guestfs_lvs (guestfs_h *handle);
176
177 List all the logical volumes detected.  This is the equivalent
178 of the L<lvs(8)> command.
179
180 This returns a list of the logical volume device names
181 (eg. C</dev/VolGroup00/LogVol00>).
182
183 See also C<guestfs_lvs_full>.
184
185 This function returns a NULL-terminated array of strings
186 (like L<environ(3)>), or NULL if there was an error.
187 I<The caller must free the strings and the array after use>.
188
189 =head2 guestfs_lvs_full
190
191  struct guestfs_lvm_lv_list *guestfs_lvs_full (guestfs_h *handle);
192
193 List all the logical volumes detected.  This is the equivalent
194 of the L<lvs(8)> command.  The "full" version includes all fields.
195
196 This function returns a C<struct guestfs_lvm_lv_list>.
197 I<The caller must call C<guestfs_free_lvm_lv_list> after use.>.
198
199 =head2 guestfs_mount
200
201  int guestfs_mount (guestfs_h *handle,
202                 const char *device,
203                 const char *mountpoint);
204
205 Mount a guest disk at a position in the filesystem.  Block devices
206 are named C</dev/sda>, C</dev/sdb> and so on, as they were added to
207 the guest.  If those block devices contain partitions, they will have
208 the usual names (eg. C</dev/sda1>).  Also LVM C</dev/VG/LV>-style
209 names can be used.
210
211 The rules are the same as for L<mount(2)>:  A filesystem must
212 first be mounted on C</> before others can be mounted.  Other
213 filesystems can only be mounted on directories which already
214 exist.
215
216 The mounted filesystem is writable, if we have sufficient permissions
217 on the underlying device.
218
219 The filesystem options C<sync> and C<noatime> are set with this
220 call, in order to improve reliability.
221
222 This function returns 0 on success or -1 on error.
223
224 =head2 guestfs_pvs
225
226  char **guestfs_pvs (guestfs_h *handle);
227
228 List all the physical volumes detected.  This is the equivalent
229 of the L<pvs(8)> command.
230
231 This returns a list of just the device names that contain
232 PVs (eg. C</dev/sda2>).
233
234 See also C<guestfs_pvs_full>.
235
236 This function returns a NULL-terminated array of strings
237 (like L<environ(3)>), or NULL if there was an error.
238 I<The caller must free the strings and the array after use>.
239
240 =head2 guestfs_pvs_full
241
242  struct guestfs_lvm_pv_list *guestfs_pvs_full (guestfs_h *handle);
243
244 List all the physical volumes detected.  This is the equivalent
245 of the L<pvs(8)> command.  The "full" version includes all fields.
246
247 This function returns a C<struct guestfs_lvm_pv_list>.
248 I<The caller must call C<guestfs_free_lvm_pv_list> after use.>.
249
250 =head2 guestfs_read_lines
251
252  char **guestfs_read_lines (guestfs_h *handle,
253                 const char *path);
254
255 Return the contents of the file named C<path>.
256
257 The file contents are returned as a list of lines.  Trailing
258 C<LF> and C<CRLF> character sequences are I<not> returned.
259
260 Note that this function cannot correctly handle binary files
261 (specifically, files containing C<\0> character which is treated
262 as end of line).  For those you need to use the C<guestfs_read_file>
263 function which has a more complex interface.
264
265 This function returns a NULL-terminated array of strings
266 (like L<environ(3)>), or NULL if there was an error.
267 I<The caller must free the strings and the array after use>.
268
269 =head2 guestfs_set_autosync
270
271  int guestfs_set_autosync (guestfs_h *handle,
272                 int autosync);
273
274 If C<autosync> is true, this enables autosync.  Libguestfs will make a
275 best effort attempt to run C<guestfs_sync> when the handle is closed
276 (also if the program exits without closing handles).
277
278 This function returns 0 on success or -1 on error.
279
280 =head2 guestfs_set_path
281
282  int guestfs_set_path (guestfs_h *handle,
283                 const char *path);
284
285 Set the path that libguestfs searches for kernel and initrd.img.
286
287 The default is C<$libdir/guestfs> unless overridden by setting
288 C<LIBGUESTFS_PATH> environment variable.
289
290 The string C<path> is stashed in the libguestfs handle, so the caller
291 must make sure it remains valid for the lifetime of the handle.
292
293 Setting C<path> to C<NULL> restores the default path.
294
295 This function returns 0 on success or -1 on error.
296
297 =head2 guestfs_set_verbose
298
299  int guestfs_set_verbose (guestfs_h *handle,
300                 int verbose);
301
302 If C<verbose> is true, this turns on verbose messages (to C<stderr>).
303
304 Verbose messages are disabled unless the environment variable
305 C<LIBGUESTFS_DEBUG> is defined and set to C<1>.
306
307 This function returns 0 on success or -1 on error.
308
309 =head2 guestfs_sync
310
311  int guestfs_sync (guestfs_h *handle);
312
313 This syncs the disk, so that any writes are flushed through to the
314 underlying disk image.
315
316 You should always call this if you have modified a disk image, before
317 closing the handle.
318
319 This function returns 0 on success or -1 on error.
320
321 =head2 guestfs_touch
322
323  int guestfs_touch (guestfs_h *handle,
324                 const char *path);
325
326 Touch acts like the L<touch(1)> command.  It can be used to
327 update the timestamps on a file, or, if the file does not exist,
328 to create a new zero-length file.
329
330 This function returns 0 on success or -1 on error.
331
332 =head2 guestfs_vgs
333
334  char **guestfs_vgs (guestfs_h *handle);
335
336 List all the volumes groups detected.  This is the equivalent
337 of the L<vgs(8)> command.
338
339 This returns a list of just the volume group names that were
340 detected (eg. C<VolGroup00>).
341
342 See also C<guestfs_vgs_full>.
343
344 This function returns a NULL-terminated array of strings
345 (like L<environ(3)>), or NULL if there was an error.
346 I<The caller must free the strings and the array after use>.
347
348 =head2 guestfs_vgs_full
349
350  struct guestfs_lvm_vg_list *guestfs_vgs_full (guestfs_h *handle);
351
352 List all the volumes groups detected.  This is the equivalent
353 of the L<vgs(8)> command.  The "full" version includes all fields.
354
355 This function returns a C<struct guestfs_lvm_vg_list>.
356 I<The caller must call C<guestfs_free_lvm_vg_list> after use.>.
357
358 =head2 guestfs_wait_ready
359
360  int guestfs_wait_ready (guestfs_h *handle);
361
362 Internally libguestfs is implemented by running a virtual machine
363 using L<qemu(1)>.
364
365 You should call this after C<guestfs_launch> to wait for the launch
366 to complete.
367
368 This function returns 0 on success or -1 on error.
369