Rename pvs -> pvs-full (etc), so we can add simple pvs (etc) commands.
[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-full", "list the LVM logical volumes (LVs)");
40   printf ("%-20s %s\n", "mount", "mount a guest disk at a position in the filesystem");
41   printf ("%-20s %s\n", "pvs-full", "list the LVM physical volumes (PVs)");
42   printf ("%-20s %s\n", "sync", "sync disks, writes are flushed through to the disk image");
43   printf ("%-20s %s\n", "touch", "update file timestamps or create a new file");
44   printf ("%-20s %s\n", "vgs-full", "list the LVM volume groups (VGs)");
45   printf ("    Use -h <cmd> / help <cmd> to show detailed help for a command.\n");
46 }
47
48 void display_command (const char *cmd)
49 {
50   if (strcasecmp (cmd, "mount") == 0)
51     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.");
52   else
53   if (strcasecmp (cmd, "sync") == 0)
54     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\ncalling C<guestfs_close>.");
55   else
56   if (strcasecmp (cmd, "touch") == 0)
57     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.");
58   else
59   if (strcasecmp (cmd, "cat") == 0)
60     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<guestfs_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.");
61   else
62   if (strcasecmp (cmd, "ll") == 0)
63     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.");
64   else
65   if (strcasecmp (cmd, "ls") == 0)
66     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<guestfs_readdir> instead.");
67   else
68   if (strcasecmp (cmd, "list_devices") == 0 || strcasecmp (cmd, "list-devices") == 0)
69     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>\n");
70   else
71   if (strcasecmp (cmd, "list_partitions") == 0 || strcasecmp (cmd, "list-partitions") == 0)
72     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<guestfs_lvs>.");
73   else
74   if (strcasecmp (cmd, "pvs_full") == 0 || strcasecmp (cmd, "pvs-full") == 0)
75     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.");
76   else
77   if (strcasecmp (cmd, "vgs_full") == 0 || strcasecmp (cmd, "vgs-full") == 0)
78     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.");
79   else
80   if (strcasecmp (cmd, "lvs_full") == 0 || strcasecmp (cmd, "lvs-full") == 0)
81     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.");
82   else
83     display_builtin_command (cmd);
84 }
85
86 static void print_pv (struct guestfs_lvm_pv *pv)
87 {
88   int i;
89
90   printf ("pv_name: %s\n", pv->pv_name);
91   printf ("pv_uuid: ");
92   for (i = 0; i < 32; ++i)
93     printf ("%c", pv->pv_uuid[i]);
94   printf ("\n");
95   printf ("pv_fmt: %s\n", pv->pv_fmt);
96   printf ("pv_size: %" PRIu64 "\n", pv->pv_size);
97   printf ("dev_size: %" PRIu64 "\n", pv->dev_size);
98   printf ("pv_free: %" PRIu64 "\n", pv->pv_free);
99   printf ("pv_used: %" PRIu64 "\n", pv->pv_used);
100   printf ("pv_attr: %s\n", pv->pv_attr);
101   printf ("pv_pe_count: %" PRIi64 "\n", pv->pv_pe_count);
102   printf ("pv_pe_alloc_count: %" PRIi64 "\n", pv->pv_pe_alloc_count);
103   printf ("pv_tags: %s\n", pv->pv_tags);
104   printf ("pe_start: %" PRIu64 "\n", pv->pe_start);
105   printf ("pv_mda_count: %" PRIi64 "\n", pv->pv_mda_count);
106   printf ("pv_mda_free: %" PRIu64 "\n", pv->pv_mda_free);
107 }
108
109 static void print_pv_list (struct guestfs_lvm_pv_list *pvs)
110 {
111   int i;
112
113   for (i = 0; i < pvs->len; ++i)
114     print_pv (&pvs->val[i]);
115 }
116
117 static void print_vg (struct guestfs_lvm_vg *vg)
118 {
119   int i;
120
121   printf ("vg_name: %s\n", vg->vg_name);
122   printf ("vg_uuid: ");
123   for (i = 0; i < 32; ++i)
124     printf ("%c", vg->vg_uuid[i]);
125   printf ("\n");
126   printf ("vg_fmt: %s\n", vg->vg_fmt);
127   printf ("vg_attr: %s\n", vg->vg_attr);
128   printf ("vg_size: %" PRIu64 "\n", vg->vg_size);
129   printf ("vg_free: %" PRIu64 "\n", vg->vg_free);
130   printf ("vg_sysid: %s\n", vg->vg_sysid);
131   printf ("vg_extent_size: %" PRIu64 "\n", vg->vg_extent_size);
132   printf ("vg_extent_count: %" PRIi64 "\n", vg->vg_extent_count);
133   printf ("vg_free_count: %" PRIi64 "\n", vg->vg_free_count);
134   printf ("max_lv: %" PRIi64 "\n", vg->max_lv);
135   printf ("max_pv: %" PRIi64 "\n", vg->max_pv);
136   printf ("pv_count: %" PRIi64 "\n", vg->pv_count);
137   printf ("lv_count: %" PRIi64 "\n", vg->lv_count);
138   printf ("snap_count: %" PRIi64 "\n", vg->snap_count);
139   printf ("vg_seqno: %" PRIi64 "\n", vg->vg_seqno);
140   printf ("vg_tags: %s\n", vg->vg_tags);
141   printf ("vg_mda_count: %" PRIi64 "\n", vg->vg_mda_count);
142   printf ("vg_mda_free: %" PRIu64 "\n", vg->vg_mda_free);
143 }
144
145 static void print_vg_list (struct guestfs_lvm_vg_list *vgs)
146 {
147   int i;
148
149   for (i = 0; i < vgs->len; ++i)
150     print_vg (&vgs->val[i]);
151 }
152
153 static void print_lv (struct guestfs_lvm_lv *lv)
154 {
155   int i;
156
157   printf ("lv_name: %s\n", lv->lv_name);
158   printf ("lv_uuid: ");
159   for (i = 0; i < 32; ++i)
160     printf ("%c", lv->lv_uuid[i]);
161   printf ("\n");
162   printf ("lv_attr: %s\n", lv->lv_attr);
163   printf ("lv_major: %" PRIi64 "\n", lv->lv_major);
164   printf ("lv_minor: %" PRIi64 "\n", lv->lv_minor);
165   printf ("lv_kernel_major: %" PRIi64 "\n", lv->lv_kernel_major);
166   printf ("lv_kernel_minor: %" PRIi64 "\n", lv->lv_kernel_minor);
167   printf ("lv_size: %" PRIu64 "\n", lv->lv_size);
168   printf ("seg_count: %" PRIi64 "\n", lv->seg_count);
169   printf ("origin: %s\n", lv->origin);
170   if (lv->snap_percent >= 0) printf ("snap_percent: %g %%\n", lv->snap_percent);
171   else printf ("snap_percent: \n");
172   if (lv->copy_percent >= 0) printf ("copy_percent: %g %%\n", lv->copy_percent);
173   else printf ("copy_percent: \n");
174   printf ("move_pv: %s\n", lv->move_pv);
175   printf ("lv_tags: %s\n", lv->lv_tags);
176   printf ("mirror_log: %s\n", lv->mirror_log);
177   printf ("modules: %s\n", lv->modules);
178 }
179
180 static void print_lv_list (struct guestfs_lvm_lv_list *lvs)
181 {
182   int i;
183
184   for (i = 0; i < lvs->len; ++i)
185     print_lv (&lvs->val[i]);
186 }
187
188 static int run_mount (const char *cmd, int argc, char *argv[])
189 {
190   int r;
191   const char *device;
192   const char *mountpoint;
193   if (argc != 2) {
194     fprintf (stderr, "%s should have 2 parameter(s)\n", cmd);
195     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
196     return -1;
197   }
198   device = argv[0];
199   mountpoint = argv[1];
200   r = guestfs_mount (g, device, mountpoint);
201   return r;
202 }
203
204 static int run_sync (const char *cmd, int argc, char *argv[])
205 {
206   int r;
207   if (argc != 0) {
208     fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
209     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
210     return -1;
211   }
212   r = guestfs_sync (g);
213   return r;
214 }
215
216 static int run_touch (const char *cmd, int argc, char *argv[])
217 {
218   int r;
219   const char *path;
220   if (argc != 1) {
221     fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
222     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
223     return -1;
224   }
225   path = argv[0];
226   r = guestfs_touch (g, path);
227   return r;
228 }
229
230 static int run_cat (const char *cmd, int argc, char *argv[])
231 {
232   char *r;
233   const char *path;
234   if (argc != 1) {
235     fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
236     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
237     return -1;
238   }
239   path = argv[0];
240   r = guestfs_cat (g, path);
241   if (r == NULL) return -1;
242   printf ("%s", r);
243   free (r);
244   return 0;
245 }
246
247 static int run_ll (const char *cmd, int argc, char *argv[])
248 {
249   char *r;
250   const char *directory;
251   if (argc != 1) {
252     fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
253     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
254     return -1;
255   }
256   directory = argv[0];
257   r = guestfs_ll (g, directory);
258   if (r == NULL) return -1;
259   printf ("%s", r);
260   free (r);
261   return 0;
262 }
263
264 static int run_ls (const char *cmd, int argc, char *argv[])
265 {
266   char **r;
267   const char *directory;
268   if (argc != 1) {
269     fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
270     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
271     return -1;
272   }
273   directory = argv[0];
274   r = guestfs_ls (g, directory);
275   if (r == NULL) return -1;
276   print_strings (r);
277   free_strings (r);
278   return 0;
279 }
280
281 static int run_list_devices (const char *cmd, int argc, char *argv[])
282 {
283   char **r;
284   if (argc != 0) {
285     fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
286     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
287     return -1;
288   }
289   r = guestfs_list_devices (g);
290   if (r == NULL) return -1;
291   print_strings (r);
292   free_strings (r);
293   return 0;
294 }
295
296 static int run_list_partitions (const char *cmd, int argc, char *argv[])
297 {
298   char **r;
299   if (argc != 0) {
300     fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
301     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
302     return -1;
303   }
304   r = guestfs_list_partitions (g);
305   if (r == NULL) return -1;
306   print_strings (r);
307   free_strings (r);
308   return 0;
309 }
310
311 static int run_pvs_full (const char *cmd, int argc, char *argv[])
312 {
313   struct guestfs_lvm_pv_list *r;
314   if (argc != 0) {
315     fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
316     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
317     return -1;
318   }
319   r = guestfs_pvs_full (g);
320   if (r == NULL) return -1;
321   print_pv_list (r);
322   guestfs_free_lvm_pv_list (r);
323   return 0;
324 }
325
326 static int run_vgs_full (const char *cmd, int argc, char *argv[])
327 {
328   struct guestfs_lvm_vg_list *r;
329   if (argc != 0) {
330     fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
331     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
332     return -1;
333   }
334   r = guestfs_vgs_full (g);
335   if (r == NULL) return -1;
336   print_vg_list (r);
337   guestfs_free_lvm_vg_list (r);
338   return 0;
339 }
340
341 static int run_lvs_full (const char *cmd, int argc, char *argv[])
342 {
343   struct guestfs_lvm_lv_list *r;
344   if (argc != 0) {
345     fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
346     fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
347     return -1;
348   }
349   r = guestfs_lvs_full (g);
350   if (r == NULL) return -1;
351   print_lv_list (r);
352   guestfs_free_lvm_lv_list (r);
353   return 0;
354 }
355
356 int run_action (const char *cmd, int argc, char *argv[])
357 {
358   if (strcasecmp (cmd, "mount") == 0)
359     return run_mount (cmd, argc, argv);
360   else
361   if (strcasecmp (cmd, "sync") == 0)
362     return run_sync (cmd, argc, argv);
363   else
364   if (strcasecmp (cmd, "touch") == 0)
365     return run_touch (cmd, argc, argv);
366   else
367   if (strcasecmp (cmd, "cat") == 0)
368     return run_cat (cmd, argc, argv);
369   else
370   if (strcasecmp (cmd, "ll") == 0)
371     return run_ll (cmd, argc, argv);
372   else
373   if (strcasecmp (cmd, "ls") == 0)
374     return run_ls (cmd, argc, argv);
375   else
376   if (strcasecmp (cmd, "list_devices") == 0 || strcasecmp (cmd, "list-devices") == 0)
377     return run_list_devices (cmd, argc, argv);
378   else
379   if (strcasecmp (cmd, "list_partitions") == 0 || strcasecmp (cmd, "list-partitions") == 0)
380     return run_list_partitions (cmd, argc, argv);
381   else
382   if (strcasecmp (cmd, "pvs_full") == 0 || strcasecmp (cmd, "pvs-full") == 0)
383     return run_pvs_full (cmd, argc, argv);
384   else
385   if (strcasecmp (cmd, "vgs_full") == 0 || strcasecmp (cmd, "vgs-full") == 0)
386     return run_vgs_full (cmd, argc, argv);
387   else
388   if (strcasecmp (cmd, "lvs_full") == 0 || strcasecmp (cmd, "lvs-full") == 0)
389     return run_lvs_full (cmd, argc, argv);
390   else
391     {
392       fprintf (stderr, "%s: unknown command\n", cmd);
393       return -1;
394     }
395   return 0;
396 }
397