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-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");
48 void display_command (const char *cmd)
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.");
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>.");
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.");
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.");
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.");
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.");
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");
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>.");
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.");
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.");
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.");
83 display_builtin_command (cmd);
86 static void print_pv (struct guestfs_lvm_pv *pv)
90 printf ("pv_name: %s\n", pv->pv_name);
92 for (i = 0; i < 32; ++i)
93 printf ("%c", pv->pv_uuid[i]);
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);
109 static void print_pv_list (struct guestfs_lvm_pv_list *pvs)
113 for (i = 0; i < pvs->len; ++i)
114 print_pv (&pvs->val[i]);
117 static void print_vg (struct guestfs_lvm_vg *vg)
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]);
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);
145 static void print_vg_list (struct guestfs_lvm_vg_list *vgs)
149 for (i = 0; i < vgs->len; ++i)
150 print_vg (&vgs->val[i]);
153 static void print_lv (struct guestfs_lvm_lv *lv)
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]);
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);
180 static void print_lv_list (struct guestfs_lvm_lv_list *lvs)
184 for (i = 0; i < lvs->len; ++i)
185 print_lv (&lvs->val[i]);
188 static int run_mount (const char *cmd, int argc, char *argv[])
192 const char *mountpoint;
194 fprintf (stderr, "%s should have 2 parameter(s)\n", cmd);
195 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
199 mountpoint = argv[1];
200 r = guestfs_mount (g, device, mountpoint);
204 static int run_sync (const char *cmd, int argc, char *argv[])
208 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
209 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
212 r = guestfs_sync (g);
216 static int run_touch (const char *cmd, int argc, char *argv[])
221 fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
222 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
226 r = guestfs_touch (g, path);
230 static int run_cat (const char *cmd, int argc, char *argv[])
235 fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
236 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
240 r = guestfs_cat (g, path);
241 if (r == NULL) return -1;
247 static int run_ll (const char *cmd, int argc, char *argv[])
250 const char *directory;
252 fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
253 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
257 r = guestfs_ll (g, directory);
258 if (r == NULL) return -1;
264 static int run_ls (const char *cmd, int argc, char *argv[])
267 const char *directory;
269 fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
270 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
274 r = guestfs_ls (g, directory);
275 if (r == NULL) return -1;
281 static int run_list_devices (const char *cmd, int argc, char *argv[])
285 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
286 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
289 r = guestfs_list_devices (g);
290 if (r == NULL) return -1;
296 static int run_list_partitions (const char *cmd, int argc, char *argv[])
300 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
301 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
304 r = guestfs_list_partitions (g);
305 if (r == NULL) return -1;
311 static int run_pvs_full (const char *cmd, int argc, char *argv[])
313 struct guestfs_lvm_pv_list *r;
315 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
316 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
319 r = guestfs_pvs_full (g);
320 if (r == NULL) return -1;
322 guestfs_free_lvm_pv_list (r);
326 static int run_vgs_full (const char *cmd, int argc, char *argv[])
328 struct guestfs_lvm_vg_list *r;
330 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
331 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
334 r = guestfs_vgs_full (g);
335 if (r == NULL) return -1;
337 guestfs_free_lvm_vg_list (r);
341 static int run_lvs_full (const char *cmd, int argc, char *argv[])
343 struct guestfs_lvm_lv_list *r;
345 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
346 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
349 r = guestfs_lvs_full (g);
350 if (r == NULL) return -1;
352 guestfs_free_lvm_lv_list (r);
356 int run_action (const char *cmd, int argc, char *argv[])
358 if (strcasecmp (cmd, "mount") == 0)
359 return run_mount (cmd, argc, argv);
361 if (strcasecmp (cmd, "sync") == 0)
362 return run_sync (cmd, argc, argv);
364 if (strcasecmp (cmd, "touch") == 0)
365 return run_touch (cmd, argc, argv);
367 if (strcasecmp (cmd, "cat") == 0)
368 return run_cat (cmd, argc, argv);
370 if (strcasecmp (cmd, "ll") == 0)
371 return run_ll (cmd, argc, argv);
373 if (strcasecmp (cmd, "ls") == 0)
374 return run_ls (cmd, argc, argv);
376 if (strcasecmp (cmd, "list_devices") == 0 || strcasecmp (cmd, "list-devices") == 0)
377 return run_list_devices (cmd, argc, argv);
379 if (strcasecmp (cmd, "list_partitions") == 0 || strcasecmp (cmd, "list-partitions") == 0)
380 return run_list_partitions (cmd, argc, argv);
382 if (strcasecmp (cmd, "pvs_full") == 0 || strcasecmp (cmd, "pvs-full") == 0)
383 return run_pvs_full (cmd, argc, argv);
385 if (strcasecmp (cmd, "vgs_full") == 0 || strcasecmp (cmd, "vgs-full") == 0)
386 return run_vgs_full (cmd, argc, argv);
388 if (strcasecmp (cmd, "lvs_full") == 0 || strcasecmp (cmd, "lvs-full") == 0)
389 return run_lvs_full (cmd, argc, argv);
392 fprintf (stderr, "%s: unknown command\n", cmd);