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.
28 void list_commands (void)
30 printf (" %-16s %s\n", "Command", "Description");
31 list_builtin_commands ();
32 printf ("%-20s %s\n", "cat", "list the contents of a file");
33 printf ("%-20s %s\n", "list-devices", "list the block devices");
34 printf ("%-20s %s\n", "list-partitions", "list the partitions");
35 printf ("%-20s %s\n", "ll", "list the files in a directory (long format)");
36 printf ("%-20s %s\n", "ls", "list the files in a directory");
37 printf ("%-20s %s\n", "mount", "mount a guest disk at a position in the filesystem");
38 printf ("%-20s %s\n", "sync", "sync disks, writes are flushed through to the disk image");
39 printf ("%-20s %s\n", "touch", "update file timestamps or create a new file");
40 printf (" Use -h <cmd> / help <cmd> to show detailed help for a command.\n");
43 void display_command (const char *cmd)
45 if (strcasecmp (cmd, "mount") == 0)
46 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.");
48 if (strcasecmp (cmd, "sync") == 0)
49 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>.");
51 if (strcasecmp (cmd, "touch") == 0)
52 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.");
54 if (strcasecmp (cmd, "cat") == 0)
55 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.");
57 if (strcasecmp (cmd, "ll") == 0)
58 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.");
60 if (strcasecmp (cmd, "ls") == 0)
61 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.");
63 if (strcasecmp (cmd, "list_devices") == 0 || strcasecmp (cmd, "list-devices") == 0)
64 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");
66 if (strcasecmp (cmd, "list_partitions") == 0 || strcasecmp (cmd, "list-partitions") == 0)
67 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>.");
69 display_builtin_command (cmd);
72 static int run_mount (const char *cmd, int argc, char *argv[])
76 const char *mountpoint;
78 fprintf (stderr, "%s should have 2 parameter(s)\n", cmd);
79 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
84 r = guestfs_mount (g, device, mountpoint);
88 static int run_sync (const char *cmd, int argc, char *argv[])
92 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
93 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
100 static int run_touch (const char *cmd, int argc, char *argv[])
105 fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
106 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
110 r = guestfs_touch (g, path);
114 static int run_cat (const char *cmd, int argc, char *argv[])
119 fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
120 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
124 r = guestfs_cat (g, path);
125 if (r == NULL) return -1;
131 static int run_ll (const char *cmd, int argc, char *argv[])
134 const char *directory;
136 fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
137 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
141 r = guestfs_ll (g, directory);
142 if (r == NULL) return -1;
148 static int run_ls (const char *cmd, int argc, char *argv[])
151 const char *directory;
153 fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
154 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
158 r = guestfs_ls (g, directory);
159 if (r == NULL) return -1;
165 static int run_list_devices (const char *cmd, int argc, char *argv[])
169 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
170 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
173 r = guestfs_list_devices (g);
174 if (r == NULL) return -1;
180 static int run_list_partitions (const char *cmd, int argc, char *argv[])
184 fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
185 fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
188 r = guestfs_list_partitions (g);
189 if (r == NULL) return -1;
195 int run_action (const char *cmd, int argc, char *argv[])
197 if (strcasecmp (cmd, "mount") == 0)
198 return run_mount (cmd, argc, argv);
200 if (strcasecmp (cmd, "sync") == 0)
201 return run_sync (cmd, argc, argv);
203 if (strcasecmp (cmd, "touch") == 0)
204 return run_touch (cmd, argc, argv);
206 if (strcasecmp (cmd, "cat") == 0)
207 return run_cat (cmd, argc, argv);
209 if (strcasecmp (cmd, "ll") == 0)
210 return run_ll (cmd, argc, argv);
212 if (strcasecmp (cmd, "ls") == 0)
213 return run_ls (cmd, argc, argv);
215 if (strcasecmp (cmd, "list_devices") == 0 || strcasecmp (cmd, "list-devices") == 0)
216 return run_list_devices (cmd, argc, argv);
218 if (strcasecmp (cmd, "list_partitions") == 0 || strcasecmp (cmd, "list-partitions") == 0)
219 return run_list_partitions (cmd, argc, argv);
222 fprintf (stderr, "%s: unknown command\n", cmd);