X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=fish%2Fcmds.c;h=8d50021e77b8cb71f883812944d78823b3f242d3;hp=1f3d9cee4a250b4ec5371f0cbd6a084c13799dec;hb=85ed8cef99c19b4143844991d14e0b848fecc5da;hpb=d901cc916102f1aaccfb73396b48aa303e5b8cd7 diff --git a/fish/cmds.c b/fish/cmds.c index 1f3d9ce..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,6 +146,8 @@ 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)"); @@ -340,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."); @@ -504,6 +511,27 @@ void display_command (const char *cmd) 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); } @@ -2456,6 +2484,125 @@ static int run_zerofree (const char *cmd, int argc, char *argv[]) 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) @@ -2809,6 +2956,27 @@ int run_action (const char *cmd, int argc, char *argv[]) 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;