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.
5 * Copyright (C) 2009 Red Hat Inc.
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.
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.
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.
30 void list_commands (void)
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");
51 void display_command (const char *cmd)
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.");
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.");
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.");
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.");
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.");
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.");
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>");
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>.");
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>.");
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>.");
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>.");
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.");
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.");
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.");
95 display_builtin_command (cmd);
98 static void print_pv (struct guestfs_lvm_pv *pv)
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]);
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);
121 static void print_pv_list (struct guestfs_lvm_pv_list *pvs)
125 for (i = 0; i < pvs->len; ++i)
126 print_pv (&pvs->val[i]);
129 static void print_vg (struct guestfs_lvm_vg *vg)
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]);
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);
157 static void print_vg_list (struct guestfs_lvm_vg_list *vgs)
161 for (i = 0; i < vgs->len; ++i)
162 print_vg (&vgs->val[i]);
165 static void print_lv (struct guestfs_lvm_lv *lv)
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]);
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);
192 static void print_lv_list (struct guestfs_lvm_lv_list *lvs)
196 for (i = 0; i < lvs->len; ++i)
197 print_lv (&lvs->val[i]);
200 static int run_mount (const char *cmd, int argc, char *argv[])
204 const char *mountpoint;
206 fprintf (stderr, "%s should have 2 parameter(s)\n", cmd);
207 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
211 mountpoint = argv[1];
212 r = guestfs_mount (g, device, mountpoint);
216 static int run_sync (const char *cmd, int argc, char *argv[])
220 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
221 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
224 r = guestfs_sync (g);
228 static int run_touch (const char *cmd, int argc, char *argv[])
233 fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
234 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
238 r = guestfs_touch (g, path);
242 static int run_cat (const char *cmd, int argc, char *argv[])
247 fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
248 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
252 r = guestfs_cat (g, path);
253 if (r == NULL) return -1;
259 static int run_ll (const char *cmd, int argc, char *argv[])
262 const char *directory;
264 fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
265 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
269 r = guestfs_ll (g, directory);
270 if (r == NULL) return -1;
276 static int run_ls (const char *cmd, int argc, char *argv[])
279 const char *directory;
281 fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
282 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
286 r = guestfs_ls (g, directory);
287 if (r == NULL) return -1;
293 static int run_list_devices (const char *cmd, int argc, char *argv[])
297 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
298 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
301 r = guestfs_list_devices (g);
302 if (r == NULL) return -1;
308 static int run_list_partitions (const char *cmd, int argc, char *argv[])
312 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
313 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
316 r = guestfs_list_partitions (g);
317 if (r == NULL) return -1;
323 static int run_pvs (const char *cmd, int argc, char *argv[])
327 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
328 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
332 if (r == NULL) return -1;
338 static int run_vgs (const char *cmd, int argc, char *argv[])
342 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
343 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
347 if (r == NULL) return -1;
353 static int run_lvs (const char *cmd, int argc, char *argv[])
357 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
358 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
362 if (r == NULL) return -1;
368 static int run_pvs_full (const char *cmd, int argc, char *argv[])
370 struct guestfs_lvm_pv_list *r;
372 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
373 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
376 r = guestfs_pvs_full (g);
377 if (r == NULL) return -1;
379 guestfs_free_lvm_pv_list (r);
383 static int run_vgs_full (const char *cmd, int argc, char *argv[])
385 struct guestfs_lvm_vg_list *r;
387 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
388 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
391 r = guestfs_vgs_full (g);
392 if (r == NULL) return -1;
394 guestfs_free_lvm_vg_list (r);
398 static int run_lvs_full (const char *cmd, int argc, char *argv[])
400 struct guestfs_lvm_lv_list *r;
402 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
403 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
406 r = guestfs_lvs_full (g);
407 if (r == NULL) return -1;
409 guestfs_free_lvm_lv_list (r);
413 int run_action (const char *cmd, int argc, char *argv[])
415 if (strcasecmp (cmd, "mount") == 0)
416 return run_mount (cmd, argc, argv);
418 if (strcasecmp (cmd, "sync") == 0)
419 return run_sync (cmd, argc, argv);
421 if (strcasecmp (cmd, "touch") == 0)
422 return run_touch (cmd, argc, argv);
424 if (strcasecmp (cmd, "cat") == 0)
425 return run_cat (cmd, argc, argv);
427 if (strcasecmp (cmd, "ll") == 0)
428 return run_ll (cmd, argc, argv);
430 if (strcasecmp (cmd, "ls") == 0)
431 return run_ls (cmd, argc, argv);
433 if (strcasecmp (cmd, "list_devices") == 0 || strcasecmp (cmd, "list-devices") == 0)
434 return run_list_devices (cmd, argc, argv);
436 if (strcasecmp (cmd, "list_partitions") == 0 || strcasecmp (cmd, "list-partitions") == 0)
437 return run_list_partitions (cmd, argc, argv);
439 if (strcasecmp (cmd, "pvs") == 0)
440 return run_pvs (cmd, argc, argv);
442 if (strcasecmp (cmd, "vgs") == 0)
443 return run_vgs (cmd, argc, argv);
445 if (strcasecmp (cmd, "lvs") == 0)
446 return run_lvs (cmd, argc, argv);
448 if (strcasecmp (cmd, "pvs_full") == 0 || strcasecmp (cmd, "pvs-full") == 0)
449 return run_pvs_full (cmd, argc, argv);
451 if (strcasecmp (cmd, "vgs_full") == 0 || strcasecmp (cmd, "vgs-full") == 0)
452 return run_vgs_full (cmd, argc, argv);
454 if (strcasecmp (cmd, "lvs_full") == 0 || strcasecmp (cmd, "lvs-full") == 0)
455 return run_lvs_full (cmd, argc, argv);
458 fprintf (stderr, "%s: unknown command\n", cmd);