Updated generated files.
[libguestfs.git] / fish / cmds.c
1 /* libguestfs generated file
2  * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'.
3  * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
4  *
5  * Copyright (C) 2009 Red Hat Inc.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <inttypes.h>
26
27 #include <guestfs.h>
28 #include "fish.h"
29
30 void list_commands (void)
31 {
32   printf ("    %-16s     %s\n", "Command", "Description");
33   list_builtin_commands ();
34   printf ("%-20s %s\n", "cat", "list the contents of a file");
35   printf ("%-20s %s\n", "list-devices", "list the block devices");
36   printf ("%-20s %s\n", "list-partitions", "list the partitions");
37   printf ("%-20s %s\n", "ll", "list the files in a directory (long format)");
38   printf ("%-20s %s\n", "ls", "list the files in a directory");
39   printf ("%-20s %s\n", "lvs", "list the LVM logical volumes (LVs)");
40   printf ("%-20s %s\n", "lvs-full", "list the LVM logical volumes (LVs)");
41   printf ("%-20s %s\n", "mount", "mount a guest disk at a position in the filesystem");
42   printf ("%-20s %s\n", "pvs", "list the LVM physical volumes (PVs)");
43   printf ("%-20s %s\n", "pvs-full", "list the LVM physical volumes (PVs)");
44   printf ("%-20s %s\n", "sync", "sync disks, writes are flushed through to the disk image");
45   printf ("%-20s %s\n", "touch", "update file timestamps or create a new file");
46   printf ("%-20s %s\n", "vgs", "list the LVM volume groups (VGs)");
47   printf ("%-20s %s\n", "vgs-full", "list the LVM volume groups (VGs)");
48   printf ("    Use -h <cmd> / help <cmd> to show detailed help for a command.\n");
49 }
50
51 void display_command (const char *cmd)
52 {
53   if (strcasecmp (cmd, "mount") == 0)
54     pod2text ("mount - mount a guest disk at a position in the filesystem", " mount <device> <mountpoint>\n\nMount a guest disk at a position in the filesystem.  Block devices\nare named C</dev/sda>, C</dev/sdb> and so on, as they were added to\nthe guest.  If those block devices contain partitions, they will have\nthe usual names (eg. C</dev/sda1>).  Also LVM C</dev/VG/LV>-style\nnames can be used.\n\nThe rules are the same as for L<mount(2)>:  A filesystem must\nfirst be mounted on C</> before others can be mounted.  Other\nfilesystems can only be mounted on directories which already\nexist.\n\nThe mounted filesystem is writable, if we have sufficient permissions\non the underlying device.\n\nThe filesystem options C<sync> and C<noatime> are set with this\ncall, in order to improve reliability.");
55   else
56   if (strcasecmp (cmd, "sync") == 0)
57     pod2text ("sync - sync disks, writes are flushed through to the disk image", " sync\n\nThis syncs the disk, so that any writes are flushed through to the\nunderlying disk image.\n\nYou should always call this if you have modified a disk image, before\nclosing the handle.");
58   else
59   if (strcasecmp (cmd, "touch") == 0)
60     pod2text ("touch - update file timestamps or create a new file", " touch <path>\n\nTouch acts like the L<touch(1)> command.  It can be used to\nupdate the timestamps on a file, or, if the file does not exist,\nto create a new zero-length file.");
61   else
62   if (strcasecmp (cmd, "cat") == 0)
63     pod2text ("cat - list the contents of a file", " cat <path>\n\nReturn the contents of the file named C<path>.\n\nNote that this function cannot correctly handle binary files\n(specifically, files containing C<\\0> character which is treated\nas end of string).  For those you need to use the C<read_file>\nfunction which has a more complex interface.\n\nBecause of the message protocol, there is a transfer limit \nof somewhere between 2MB and 4MB.  To transfer large files you should use\nFTP.");
64   else
65   if (strcasecmp (cmd, "ll") == 0)
66     pod2text ("ll - list the files in a directory (long format)", " ll <directory>\n\nList the files in C<directory> (relative to the root directory,\nthere is no cwd) in the format of 'ls -la'.\n\nThis command is mostly useful for interactive sessions.  It\nis I<not> intended that you try to parse the output string.");
67   else
68   if (strcasecmp (cmd, "ls") == 0)
69     pod2text ("ls - list the files in a directory", " ls <directory>\n\nList the files in C<directory> (relative to the root directory,\nthere is no cwd).  The '.' and '..' entries are not returned, but\nhidden files are shown.\n\nThis command is mostly useful for interactive sessions.  Programs\nshould probably use C<readdir> instead.");
70   else
71   if (strcasecmp (cmd, "list_devices") == 0 || strcasecmp (cmd, "list-devices") == 0)
72     pod2text ("list-devices - list the block devices", " list-devices\n\nList all the block devices.\n\nThe full block device names are returned, eg. C</dev/sda>");
73   else
74   if (strcasecmp (cmd, "list_partitions") == 0 || strcasecmp (cmd, "list-partitions") == 0)
75     pod2text ("list-partitions - list the partitions", " list-partitions\n\nList all the partitions detected on all block devices.\n\nThe full partition device names are returned, eg. C</dev/sda1>\n\nThis does not return logical volumes.  For that you will need to\ncall C<lvs>.");
76   else
77   if (strcasecmp (cmd, "pvs") == 0)
78     pod2text ("pvs - list the LVM physical volumes (PVs)", " pvs\n\nList all the physical volumes detected.  This is the equivalent\nof the L<pvs(8)> command.\n\nThis returns a list of just the device names that contain\nPVs (eg. C</dev/sda2>).\n\nSee also C<pvs_full>.");
79   else
80   if (strcasecmp (cmd, "vgs") == 0)
81     pod2text ("vgs - list the LVM volume groups (VGs)", " vgs\n\nList all the volumes groups detected.  This is the equivalent\nof the L<vgs(8)> command.\n\nThis returns a list of just the volume group names that were\ndetected (eg. C<VolGroup00>).\n\nSee also C<vgs_full>.");
82   else
83   if (strcasecmp (cmd, "lvs") == 0)
84     pod2text ("lvs - list the LVM logical volumes (LVs)", " lvs\n\nList all the logical volumes detected.  This is the equivalent\nof the L<lvs(8)> command.\n\nThis returns a list of the logical volume device names\n(eg. C</dev/VolGroup00/LogVol00>).\n\nSee also C<lvs_full>.");
85   else
86   if (strcasecmp (cmd, "pvs_full") == 0 || strcasecmp (cmd, "pvs-full") == 0)
87     pod2text ("pvs-full - list the LVM physical volumes (PVs)", " pvs-full\n\nList all the physical volumes detected.  This is the equivalent\nof the L<pvs(8)> command.  The \"full\" version includes all fields.");
88   else
89   if (strcasecmp (cmd, "vgs_full") == 0 || strcasecmp (cmd, "vgs-full") == 0)
90     pod2text ("vgs-full - list the LVM volume groups (VGs)", " vgs-full\n\nList all the volumes groups detected.  This is the equivalent\nof the L<vgs(8)> command.  The \"full\" version includes all fields.");
91   else
92   if (strcasecmp (cmd, "lvs_full") == 0 || strcasecmp (cmd, "lvs-full") == 0)
93     pod2text ("lvs-full - list the LVM logical volumes (LVs)", " lvs-full\n\nList all the logical volumes detected.  This is the equivalent\nof the L<lvs(8)> command.  The \"full\" version includes all fields.");
94   else
95     display_builtin_command (cmd);
96 }
97
98 static void print_pv (struct guestfs_lvm_pv *pv)
99 {
100   int i;
101
102   printf ("pv_name: %s\n", pv->pv_name);
103   printf ("pv_uuid: ");
104   for (i = 0; i < 32; ++i)
105     printf ("%c", pv->pv_uuid[i]);
106   printf ("\n");
107   printf ("pv_fmt: %s\n", pv->pv_fmt);
108   printf ("pv_size: %" PRIu64 "\n", pv->pv_size);
109   printf ("dev_size: %" PRIu64 "\n", pv->dev_size);
110   printf ("pv_free: %" PRIu64 "\n", pv->pv_free);
111   printf ("pv_used: %" PRIu64 "\n", pv->pv_used);
112   printf ("pv_attr: %s\n", pv->pv_attr);
113   printf ("pv_pe_count: %" PRIi64 "\n", pv->pv_pe_count);
114   printf ("pv_pe_alloc_count: %" PRIi64 "\n", pv->pv_pe_alloc_count);
115   printf ("pv_tags: %s\n", pv->pv_tags);
116   printf ("pe_start: %" PRIu64 "\n", pv->pe_start);
117   printf ("pv_mda_count: %" PRIi64 "\n", pv->pv_mda_count);
118   printf ("pv_mda_free: %" PRIu64 "\n", pv->pv_mda_free);
119 }
120
121 static void print_pv_list (struct guestfs_lvm_pv_list *pvs)
122 {
123   int i;
124
125   for (i = 0; i < pvs->len; ++i)
126     print_pv (&pvs->val[i]);
127 }
128
129 static void print_vg (struct guestfs_lvm_vg *vg)
130 {
131   int i;
132
133   printf ("vg_name: %s\n", vg->vg_name);
134   printf ("vg_uuid: ");
135   for (i = 0; i < 32; ++i)
136     printf ("%c", vg->vg_uuid[i]);
137   printf ("\n");
138   printf ("vg_fmt: %s\n", vg->vg_fmt);
139   printf ("vg_attr: %s\n", vg->vg_attr);
140   printf ("vg_size: %" PRIu64 "\n", vg->vg_size);
141   printf ("vg_free: %" PRIu64 "\n", vg->vg_free);
142   printf ("vg_sysid: %s\n", vg->vg_sysid);
143   printf ("vg_extent_size: %" PRIu64 "\n", vg->vg_extent_size);
144   printf ("vg_extent_count: %" PRIi64 "\n", vg->vg_extent_count);
145   printf ("vg_free_count: %" PRIi64 "\n", vg->vg_free_count);
146   printf ("max_lv: %" PRIi64 "\n", vg->max_lv);
147   printf ("max_pv: %" PRIi64 "\n", vg->max_pv);
148   printf ("pv_count: %" PRIi64 "\n", vg->pv_count);
149   printf ("lv_count: %" PRIi64 "\n", vg->lv_count);
150   printf ("snap_count: %" PRIi64 "\n", vg->snap_count);
151   printf ("vg_seqno: %" PRIi64 "\n", vg->vg_seqno);
152   printf ("vg_tags: %s\n", vg->vg_tags);
153   printf ("vg_mda_count: %" PRIi64 "\n", vg->vg_mda_count);
154   printf ("vg_mda_free: %" PRIu64 "\n", vg->vg_mda_free);
155 }
156
157 static void print_vg_list (struct guestfs_lvm_vg_list *vgs)
158 {
159   int i;
160
161   for (i = 0; i < vgs->len; ++i)
162     print_vg (&vgs->val[i]);
163 }
164
165 static void print_lv (struct guestfs_lvm_lv *lv)
166 {
167   int i;
168
169   printf ("lv_name: %s\n", lv->lv_name);
170   printf ("lv_uuid: ");
171   for (i = 0; i < 32; ++i)
172     printf ("%c", lv->lv_uuid[i]);
173   printf ("\n");
174   printf ("lv_attr: %s\n", lv->lv_attr);
175   printf ("lv_major: %" PRIi64 "\n", lv->lv_major);
176   printf ("lv_minor: %" PRIi64 "\n", lv->lv_minor);
177   printf ("lv_kernel_major: %" PRIi64 "\n", lv->lv_kernel_major);
178   printf ("lv_kernel_minor: %" PRIi64 "\n", lv->lv_kernel_minor);
179   printf ("lv_size: %" PRIu64 "\n", lv->lv_size);
180   printf ("seg_count: %" PRIi64 "\n", lv->seg_count);
181   printf ("origin: %s\n", lv->origin);
182   if (lv->snap_percent >= 0) printf ("snap_percent: %g %%\n", lv->snap_percent);
183   else printf ("snap_percent: \n");
184   if (lv->copy_percent >= 0) printf ("copy_percent: %g %%\n", lv->copy_percent);
185   else printf ("copy_percent: \n");
186   printf ("move_pv: %s\n", lv->move_pv);
187   printf ("lv_tags: %s\n", lv->lv_tags);
188   printf ("mirror_log: %s\n", lv->mirror_log);
189   printf ("modules: %s\n", lv->modules);
190 }
191
192 static void print_lv_list (struct guestfs_lvm_lv_list *lvs)
193 {
194   int i;
195
196   for (i = 0; i < lvs->len; ++i)
197     print_lv (&lvs->val[i]);
198 }
199
200 static int run_mount (const char *cmd, int argc, char *argv[])
201 {
202   int r;
203   const char *device;
204   const char *mountpoint;
205   if (argc != 2) {
206     fprintf (stderr, "%s should have 2 parameter(s)\n", cmd);
207     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
208     return -1;
209   }
210   device = argv[0];
211   mountpoint = argv[1];
212   r = guestfs_mount (g, device, mountpoint);
213   return r;
214 }
215
216 static int run_sync (const char *cmd, int argc, char *argv[])
217 {
218   int r;
219   if (argc != 0) {
220     fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
221     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
222     return -1;
223   }
224   r = guestfs_sync (g);
225   return r;
226 }
227
228 static int run_touch (const char *cmd, int argc, char *argv[])
229 {
230   int r;
231   const char *path;
232   if (argc != 1) {
233     fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
234     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
235     return -1;
236   }
237   path = argv[0];
238   r = guestfs_touch (g, path);
239   return r;
240 }
241
242 static int run_cat (const char *cmd, int argc, char *argv[])
243 {
244   char *r;
245   const char *path;
246   if (argc != 1) {
247     fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
248     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
249     return -1;
250   }
251   path = argv[0];
252   r = guestfs_cat (g, path);
253   if (r == NULL) return -1;
254   printf ("%s", r);
255   free (r);
256   return 0;
257 }
258
259 static int run_ll (const char *cmd, int argc, char *argv[])
260 {
261   char *r;
262   const char *directory;
263   if (argc != 1) {
264     fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
265     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
266     return -1;
267   }
268   directory = argv[0];
269   r = guestfs_ll (g, directory);
270   if (r == NULL) return -1;
271   printf ("%s", r);
272   free (r);
273   return 0;
274 }
275
276 static int run_ls (const char *cmd, int argc, char *argv[])
277 {
278   char **r;
279   const char *directory;
280   if (argc != 1) {
281     fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
282     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
283     return -1;
284   }
285   directory = argv[0];
286   r = guestfs_ls (g, directory);
287   if (r == NULL) return -1;
288   print_strings (r);
289   free_strings (r);
290   return 0;
291 }
292
293 static int run_list_devices (const char *cmd, int argc, char *argv[])
294 {
295   char **r;
296   if (argc != 0) {
297     fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
298     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
299     return -1;
300   }
301   r = guestfs_list_devices (g);
302   if (r == NULL) return -1;
303   print_strings (r);
304   free_strings (r);
305   return 0;
306 }
307
308 static int run_list_partitions (const char *cmd, int argc, char *argv[])
309 {
310   char **r;
311   if (argc != 0) {
312     fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
313     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
314     return -1;
315   }
316   r = guestfs_list_partitions (g);
317   if (r == NULL) return -1;
318   print_strings (r);
319   free_strings (r);
320   return 0;
321 }
322
323 static int run_pvs (const char *cmd, int argc, char *argv[])
324 {
325   char **r;
326   if (argc != 0) {
327     fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
328     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
329     return -1;
330   }
331   r = guestfs_pvs (g);
332   if (r == NULL) return -1;
333   print_strings (r);
334   free_strings (r);
335   return 0;
336 }
337
338 static int run_vgs (const char *cmd, int argc, char *argv[])
339 {
340   char **r;
341   if (argc != 0) {
342     fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
343     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
344     return -1;
345   }
346   r = guestfs_vgs (g);
347   if (r == NULL) return -1;
348   print_strings (r);
349   free_strings (r);
350   return 0;
351 }
352
353 static int run_lvs (const char *cmd, int argc, char *argv[])
354 {
355   char **r;
356   if (argc != 0) {
357     fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
358     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
359     return -1;
360   }
361   r = guestfs_lvs (g);
362   if (r == NULL) return -1;
363   print_strings (r);
364   free_strings (r);
365   return 0;
366 }
367
368 static int run_pvs_full (const char *cmd, int argc, char *argv[])
369 {
370   struct guestfs_lvm_pv_list *r;
371   if (argc != 0) {
372     fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
373     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
374     return -1;
375   }
376   r = guestfs_pvs_full (g);
377   if (r == NULL) return -1;
378   print_pv_list (r);
379   guestfs_free_lvm_pv_list (r);
380   return 0;
381 }
382
383 static int run_vgs_full (const char *cmd, int argc, char *argv[])
384 {
385   struct guestfs_lvm_vg_list *r;
386   if (argc != 0) {
387     fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
388     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
389     return -1;
390   }
391   r = guestfs_vgs_full (g);
392   if (r == NULL) return -1;
393   print_vg_list (r);
394   guestfs_free_lvm_vg_list (r);
395   return 0;
396 }
397
398 static int run_lvs_full (const char *cmd, int argc, char *argv[])
399 {
400   struct guestfs_lvm_lv_list *r;
401   if (argc != 0) {
402     fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
403     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
404     return -1;
405   }
406   r = guestfs_lvs_full (g);
407   if (r == NULL) return -1;
408   print_lv_list (r);
409   guestfs_free_lvm_lv_list (r);
410   return 0;
411 }
412
413 int run_action (const char *cmd, int argc, char *argv[])
414 {
415   if (strcasecmp (cmd, "mount") == 0)
416     return run_mount (cmd, argc, argv);
417   else
418   if (strcasecmp (cmd, "sync") == 0)
419     return run_sync (cmd, argc, argv);
420   else
421   if (strcasecmp (cmd, "touch") == 0)
422     return run_touch (cmd, argc, argv);
423   else
424   if (strcasecmp (cmd, "cat") == 0)
425     return run_cat (cmd, argc, argv);
426   else
427   if (strcasecmp (cmd, "ll") == 0)
428     return run_ll (cmd, argc, argv);
429   else
430   if (strcasecmp (cmd, "ls") == 0)
431     return run_ls (cmd, argc, argv);
432   else
433   if (strcasecmp (cmd, "list_devices") == 0 || strcasecmp (cmd, "list-devices") == 0)
434     return run_list_devices (cmd, argc, argv);
435   else
436   if (strcasecmp (cmd, "list_partitions") == 0 || strcasecmp (cmd, "list-partitions") == 0)
437     return run_list_partitions (cmd, argc, argv);
438   else
439   if (strcasecmp (cmd, "pvs") == 0)
440     return run_pvs (cmd, argc, argv);
441   else
442   if (strcasecmp (cmd, "vgs") == 0)
443     return run_vgs (cmd, argc, argv);
444   else
445   if (strcasecmp (cmd, "lvs") == 0)
446     return run_lvs (cmd, argc, argv);
447   else
448   if (strcasecmp (cmd, "pvs_full") == 0 || strcasecmp (cmd, "pvs-full") == 0)
449     return run_pvs_full (cmd, argc, argv);
450   else
451   if (strcasecmp (cmd, "vgs_full") == 0 || strcasecmp (cmd, "vgs-full") == 0)
452     return run_vgs_full (cmd, argc, argv);
453   else
454   if (strcasecmp (cmd, "lvs_full") == 0 || strcasecmp (cmd, "lvs-full") == 0)
455     return run_lvs_full (cmd, argc, argv);
456   else
457     {
458       fprintf (stderr, "%s: unknown command\n", cmd);
459       return -1;
460     }
461   return 0;
462 }
463