X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=fish%2Fcmds.c;h=8d50021e77b8cb71f883812944d78823b3f242d3;hp=47c66da357fba08f9f90c32f9b3225d13605c283;hb=85ed8cef99c19b4143844991d14e0b848fecc5da;hpb=e8ecc08f663b44f3d79517affe52f137858dfe00 diff --git a/fish/cmds.c b/fish/cmds.c index 47c66da..8d50021 100644 --- a/fish/cmds.c +++ b/fish/cmds.c @@ -113,6 +113,7 @@ void list_commands (void) printf ("%-20s %s\n", "ping-daemon", "ping the guest daemon"); printf ("%-20s %s\n", "pvcreate", "create an LVM physical volume"); printf ("%-20s %s\n", "pvremove", "remove an LVM physical volume"); + printf ("%-20s %s\n", "pvresize", "resize an LVM physical volume"); printf ("%-20s %s\n", "pvs", "list the LVM physical volumes (PVs)"); printf ("%-20s %s\n", "pvs-full", "list the LVM physical volumes (PVs)"); printf ("%-20s %s\n", "read-lines", "read file as lines"); @@ -127,6 +128,10 @@ void list_commands (void) printf ("%-20s %s\n", "set-qemu", "set the qemu binary"); printf ("%-20s %s\n", "set-verbose", "set verbose mode"); printf ("%-20s %s\n", "sfdisk", "create partitions on a block device"); + printf ("%-20s %s\n", "sfdisk-N", "modify a single partition on a block device"); + printf ("%-20s %s\n", "sfdisk-disk-geometry", "display the disk geometry from the partition table"); + printf ("%-20s %s\n", "sfdisk-kernel-geometry", "display the kernel geometry"); + printf ("%-20s %s\n", "sfdisk-l", "display the partition table"); printf ("%-20s %s\n", "stat", "get file information"); printf ("%-20s %s\n", "statvfs", "get file system statistics"); printf ("%-20s %s\n", "strings", "print the printable strings in a file"); @@ -141,12 +146,15 @@ void list_commands (void) printf ("%-20s %s\n", "umount", "unmount a filesystem"); printf ("%-20s %s\n", "umount-all", "unmount all filesystems"); printf ("%-20s %s\n", "upload", "upload a file from the local machine"); + printf ("%-20s %s\n", "vg-activate", "activate or deactivate some volume groups"); + printf ("%-20s %s\n", "vg-activate-all", "activate or deactivate all volume groups"); printf ("%-20s %s\n", "vgcreate", "create an LVM volume group"); printf ("%-20s %s\n", "vgremove", "remove an LVM volume group"); printf ("%-20s %s\n", "vgs", "list the LVM volume groups (VGs)"); printf ("%-20s %s\n", "vgs-full", "list the LVM volume groups (VGs)"); printf ("%-20s %s\n", "write-file", "create a file"); printf ("%-20s %s\n", "zero", "write zeroes to the device"); + printf ("%-20s %s\n", "zerofree", "zero unused inodes and disk blocks on ext2/3 filesystem"); printf (" Use -h / help to show detailed help for a command.\n"); } @@ -168,19 +176,19 @@ void display_command (const char *cmd) pod2text ("config - add qemu parameters", " config \n\nThis can be used to add arbitrary qemu command line parameters\nof the form C<-param value>. Actually it's not quite arbitrary - we\nprevent you from setting some parameters which would interfere with\nparameters that we use.\n\nThe first character of C string must be a C<-> (dash).\n\nC can be NULL."); else if (strcasecmp (cmd, "set_qemu") == 0 || strcasecmp (cmd, "set-qemu") == 0 || strcasecmp (cmd, "qemu") == 0) - pod2text ("set-qemu - set the qemu binary", " set-qemu \n\nSet the qemu binary that we will use.\n\nThe default is chosen when the library was compiled by the\nconfigure script.\n\nYou can also override this by setting the C\nenvironment variable.\n\nThe string C is stashed in the libguestfs handle, so the caller\nmust make sure it remains valid for the lifetime of the handle.\n\nSetting C to C restores the default qemu binary.\n\nYou can use 'qemu' as an alias for this command."); + pod2text ("set-qemu - set the qemu binary", " set-qemu \n\nSet the qemu binary that we will use.\n\nThe default is chosen when the library was compiled by the\nconfigure script.\n\nYou can also override this by setting the C\nenvironment variable.\n\nSetting C to C restores the default qemu binary.\n\nYou can use 'qemu' as an alias for this command."); else if (strcasecmp (cmd, "get_qemu") == 0 || strcasecmp (cmd, "get-qemu") == 0) pod2text ("get-qemu - get the qemu binary", " get-qemu\n\nReturn the current qemu binary.\n\nThis is always non-NULL. If it wasn't set already, then this will\nreturn the default qemu binary name."); else if (strcasecmp (cmd, "set_path") == 0 || strcasecmp (cmd, "set-path") == 0 || strcasecmp (cmd, "path") == 0) - pod2text ("set-path - set the search path", " set-path \n\nSet the path that libguestfs searches for kernel and initrd.img.\n\nThe default is C<$libdir/guestfs> unless overridden by setting\nC environment variable.\n\nThe string C is stashed in the libguestfs handle, so the caller\nmust make sure it remains valid for the lifetime of the handle.\n\nSetting C to C restores the default path.\n\nYou can use 'path' as an alias for this command."); + pod2text ("set-path - set the search path", " set-path \n\nSet the path that libguestfs searches for kernel and initrd.img.\n\nThe default is C<$libdir/guestfs> unless overridden by setting\nC environment variable.\n\nSetting C to C restores the default path.\n\nYou can use 'path' as an alias for this command."); else if (strcasecmp (cmd, "get_path") == 0 || strcasecmp (cmd, "get-path") == 0) pod2text ("get-path - get the search path", " get-path\n\nReturn the current search path.\n\nThis is always non-NULL. If it wasn't set already, then this will\nreturn the default path."); else if (strcasecmp (cmd, "set_append") == 0 || strcasecmp (cmd, "set-append") == 0 || strcasecmp (cmd, "append") == 0) - pod2text ("set-append - add options to kernel command line", " set-append \n\nThis function is used to add additional options to the\nguest kernel command line.\n\nThe default is C unless overridden by setting\nC environment variable.\n\nThe string C is stashed in the libguestfs handle, so the caller\nmust make sure it remains valid for the lifetime of the handle.\n\nSetting C to C means I additional options\nare passed (libguestfs always adds a few of its own).\n\nYou can use 'append' as an alias for this command."); + pod2text ("set-append - add options to kernel command line", " set-append \n\nThis function is used to add additional options to the\nguest kernel command line.\n\nThe default is C unless overridden by setting\nC environment variable.\n\nSetting C to C means I additional options\nare passed (libguestfs always adds a few of its own).\n\nYou can use 'append' as an alias for this command."); else if (strcasecmp (cmd, "get_append") == 0 || strcasecmp (cmd, "get-append") == 0) pod2text ("get-append - get the additional kernel options", " get-append\n\nReturn the additional kernel options which are added to the\nguest kernel command line.\n\nIf C then no options are added."); @@ -339,7 +347,7 @@ void display_command (const char *cmd) pod2text ("mkfs - make a filesystem", " mkfs \n\nThis creates a filesystem on C (usually a partition\nor LVM logical volume). The filesystem type is C, for\nexample C."); else if (strcasecmp (cmd, "sfdisk") == 0) - pod2text ("sfdisk - create partitions on a block device", " sfdisk \n\nThis is a direct interface to the L program for creating\npartitions on block devices.\n\nC should be a block device, for example C.\n\nC, C and C are the number of cylinders, heads\nand sectors on the device, which are passed directly to sfdisk as\nthe I<-C>, I<-H> and I<-S> parameters. If you pass C<0> for any\nof these, then the corresponding parameter is omitted. Usually for\n'large' disks, you can just pass C<0> for these, but for small\n(floppy-sized) disks, sfdisk (or rather, the kernel) cannot work\nout the right geometry and you will need to tell it.\n\nC is a list of lines that we feed to C. For more\ninformation refer to the L manpage.\n\nTo create a single partition occupying the whole disk, you would\npass C as a single element list, when the single element being\nthe string C<,> (comma).\n\nB."); + pod2text ("sfdisk - create partitions on a block device", " sfdisk \n\nThis is a direct interface to the L program for creating\npartitions on block devices.\n\nC should be a block device, for example C.\n\nC, C and C are the number of cylinders, heads\nand sectors on the device, which are passed directly to sfdisk as\nthe I<-C>, I<-H> and I<-S> parameters. If you pass C<0> for any\nof these, then the corresponding parameter is omitted. Usually for\n'large' disks, you can just pass C<0> for these, but for small\n(floppy-sized) disks, sfdisk (or rather, the kernel) cannot work\nout the right geometry and you will need to tell it.\n\nC is a list of lines that we feed to C. For more\ninformation refer to the L manpage.\n\nTo create a single partition occupying the whole disk, you would\npass C as a single element list, when the single element being\nthe string C<,> (comma).\n\nSee also: C, C\n\nB."); else if (strcasecmp (cmd, "write_file") == 0 || strcasecmp (cmd, "write-file") == 0) pod2text ("write-file - create a file", " write-file \n\nThis call creates a file called C. The contents of the\nfile is the string C (which can contain any 8 bit data),\nwith length C.\n\nAs a special case, if C is C<0>\nthen the length is calculated using C (so in this case\nthe content cannot contain embedded ASCII NULs).\n\nI Owing to a bug, writing content containing ASCII NUL\ncharacters does I work, even if the length is specified.\nWe hope to resolve this bug in a future version. In the meantime\nuse C.\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."); @@ -500,6 +508,30 @@ void display_command (const char *cmd) if (strcasecmp (cmd, "hexdump") == 0) pod2text ("hexdump - dump a file in hexadecimal", " hexdump \n\nThis runs C on the given C. The result is\nthe human-readable, canonical hex dump of the file.\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."); else + if (strcasecmp (cmd, "zerofree") == 0) + pod2text ("zerofree - zero unused inodes and disk blocks on ext2/3 filesystem", " zerofree \n\nThis runs the I program on C. This program\nclaims to zero unused inodes and disk blocks on an ext2/3\nfilesystem, thus making it possible to compress the filesystem\nmore effectively.\n\nYou should B run this program if the filesystem is\nmounted.\n\nIt is possible that using this program can damage the filesystem\nor data on the filesystem."); + else + if (strcasecmp (cmd, "pvresize") == 0) + pod2text ("pvresize - resize an LVM physical volume", " pvresize \n\nThis resizes (expands or shrinks) an existing LVM physical\nvolume to match the new size of the underlying device."); + else + if (strcasecmp (cmd, "sfdisk_N") == 0 || strcasecmp (cmd, "sfdisk-N") == 0) + pod2text ("sfdisk-N - modify a single partition on a block device", " sfdisk-N \n\nThis runs L option to modify just the single\npartition C (note: C counts from 1).\n\nFor other parameters, see C. You should usually\npass C<0> for the cyls/heads/sectors parameters.\n\nB."); + else + if (strcasecmp (cmd, "sfdisk_l") == 0 || strcasecmp (cmd, "sfdisk-l") == 0) + pod2text ("sfdisk-l - display the partition table", " sfdisk-l \n\nThis displays the partition table on C, in the\nhuman-readable output of the L command. It is\nnot intended to be parsed."); + else + if (strcasecmp (cmd, "sfdisk_kernel_geometry") == 0 || strcasecmp (cmd, "sfdisk-kernel-geometry") == 0) + pod2text ("sfdisk-kernel-geometry - display the kernel geometry", " sfdisk-kernel-geometry \n\nThis displays the kernel's idea of the geometry of C.\n\nThe result is in human-readable format, and not designed to\nbe parsed."); + else + if (strcasecmp (cmd, "sfdisk_disk_geometry") == 0 || strcasecmp (cmd, "sfdisk-disk-geometry") == 0) + pod2text ("sfdisk-disk-geometry - display the disk geometry from the partition table", " sfdisk-disk-geometry \n\nThis displays the disk geometry of C read from the\npartition table. Especially in the case where the underlying\nblock device has been resized, this can be different from the\nkernel's idea of the geometry (see C).\n\nThe result is in human-readable format, and not designed to\nbe parsed."); + else + if (strcasecmp (cmd, "vg_activate_all") == 0 || strcasecmp (cmd, "vg-activate-all") == 0) + pod2text ("vg-activate-all - activate or deactivate all volume groups", " vg-activate-all \n\nThis command activates or (if C is false) deactivates\nall logical volumes in all volume groups.\nIf activated, then they are made known to the\nkernel, ie. they appear as C devices. If deactivated,\nthen those devices disappear.\n\nThis command is the same as running C"); + else + if (strcasecmp (cmd, "vg_activate") == 0 || strcasecmp (cmd, "vg-activate") == 0) + pod2text ("vg-activate - activate or deactivate some volume groups", " vg-activate \n\nThis command activates or (if C is false) deactivates\nall logical volumes in the listed volume groups C.\nIf activated, then they are made known to the\nkernel, ie. they appear as C devices. If deactivated,\nthen those devices disappear.\n\nThis command is the same as running C\n\nNote that if C is an empty list then B volume groups\nare activated or deactivated."); + else display_builtin_command (cmd); } @@ -2438,6 +2470,139 @@ static int run_hexdump (const char *cmd, int argc, char *argv[]) return 0; } +static int run_zerofree (const char *cmd, int argc, char *argv[]) +{ + int r; + const char *device; + if (argc != 1) { + fprintf (stderr, "%s should have 1 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + device = argv[0]; + r = guestfs_zerofree (g, device); + return r; +} + +static int run_pvresize (const char *cmd, int argc, char *argv[]) +{ + int r; + const char *device; + if (argc != 1) { + fprintf (stderr, "%s should have 1 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + device = argv[0]; + r = guestfs_pvresize (g, device); + return r; +} + +static int run_sfdisk_N (const char *cmd, int argc, char *argv[]) +{ + int r; + const char *device; + int n; + int cyls; + int heads; + int sectors; + const char *line; + if (argc != 6) { + fprintf (stderr, "%s should have 6 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + device = argv[0]; + n = atoi (argv[1]); + cyls = atoi (argv[2]); + heads = atoi (argv[3]); + sectors = atoi (argv[4]); + line = argv[5]; + r = guestfs_sfdisk_N (g, device, n, cyls, heads, sectors, line); + return r; +} + +static int run_sfdisk_l (const char *cmd, int argc, char *argv[]) +{ + char *r; + const char *device; + if (argc != 1) { + fprintf (stderr, "%s should have 1 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + device = argv[0]; + r = guestfs_sfdisk_l (g, device); + if (r == NULL) return -1; + printf ("%s\n", r); + free (r); + return 0; +} + +static int run_sfdisk_kernel_geometry (const char *cmd, int argc, char *argv[]) +{ + char *r; + const char *device; + if (argc != 1) { + fprintf (stderr, "%s should have 1 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + device = argv[0]; + r = guestfs_sfdisk_kernel_geometry (g, device); + if (r == NULL) return -1; + printf ("%s\n", r); + free (r); + return 0; +} + +static int run_sfdisk_disk_geometry (const char *cmd, int argc, char *argv[]) +{ + char *r; + const char *device; + if (argc != 1) { + fprintf (stderr, "%s should have 1 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + device = argv[0]; + r = guestfs_sfdisk_disk_geometry (g, device); + if (r == NULL) return -1; + printf ("%s\n", r); + free (r); + return 0; +} + +static int run_vg_activate_all (const char *cmd, int argc, char *argv[]) +{ + int r; + int activate; + if (argc != 1) { + fprintf (stderr, "%s should have 1 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + activate = is_true (argv[0]) ? 1 : 0; + r = guestfs_vg_activate_all (g, activate); + return r; +} + +static int run_vg_activate (const char *cmd, int argc, char *argv[]) +{ + int r; + int activate; + char **volgroups; + if (argc != 2) { + fprintf (stderr, "%s should have 2 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + activate = is_true (argv[0]) ? 1 : 0; + volgroups = parse_string_list (argv[1]); + r = guestfs_vg_activate (g, activate, volgroups); + return r; +} + int run_action (const char *cmd, int argc, char *argv[]) { if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0) @@ -2788,6 +2953,30 @@ int run_action (const char *cmd, int argc, char *argv[]) if (strcasecmp (cmd, "hexdump") == 0) return run_hexdump (cmd, argc, argv); else + if (strcasecmp (cmd, "zerofree") == 0) + return run_zerofree (cmd, argc, argv); + else + if (strcasecmp (cmd, "pvresize") == 0) + return run_pvresize (cmd, argc, argv); + else + if (strcasecmp (cmd, "sfdisk_N") == 0 || strcasecmp (cmd, "sfdisk-N") == 0) + return run_sfdisk_N (cmd, argc, argv); + else + if (strcasecmp (cmd, "sfdisk_l") == 0 || strcasecmp (cmd, "sfdisk-l") == 0) + return run_sfdisk_l (cmd, argc, argv); + else + if (strcasecmp (cmd, "sfdisk_kernel_geometry") == 0 || strcasecmp (cmd, "sfdisk-kernel-geometry") == 0) + return run_sfdisk_kernel_geometry (cmd, argc, argv); + else + if (strcasecmp (cmd, "sfdisk_disk_geometry") == 0 || strcasecmp (cmd, "sfdisk-disk-geometry") == 0) + return run_sfdisk_disk_geometry (cmd, argc, argv); + else + if (strcasecmp (cmd, "vg_activate_all") == 0 || strcasecmp (cmd, "vg-activate-all") == 0) + return run_vg_activate_all (cmd, argc, argv); + else + if (strcasecmp (cmd, "vg_activate") == 0 || strcasecmp (cmd, "vg-activate") == 0) + return run_vg_activate (cmd, argc, argv); + else { fprintf (stderr, "%s: unknown command\n", cmd); return -1;