X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=fish%2Fcmds.c;h=c9c05158bee9fbb0e4b2297c817fc540da064b2d;hb=1799b5ce4741446704418fe06ea7e13a91028b7e;hp=89fa1fb3c04ce5ccabd1ba9acfe462d935333f40;hpb=f450ce75b754fb869b34433c0126f7bb592b141b;p=libguestfs.git diff --git a/fish/cmds.c b/fish/cmds.c index 89fa1fb..c9c0515 100644 --- a/fish/cmds.c +++ b/fish/cmds.c @@ -67,9 +67,12 @@ void list_commands (void) printf ("%-20s %s\n", "cp", "copy a file"); printf ("%-20s %s\n", "cp-a", "copy a file or directory recursively"); printf ("%-20s %s\n", "debug", "debugging and internals"); + printf ("%-20s %s\n", "df", "report file system disk space usage"); + printf ("%-20s %s\n", "df-h", "report file system disk space usage (human readable)"); printf ("%-20s %s\n", "dmesg", "return kernel messages"); printf ("%-20s %s\n", "download", "download a file to the local machine"); printf ("%-20s %s\n", "drop-caches", "drop kernel page cache, dentries and inodes"); + printf ("%-20s %s\n", "du", "estimate file space usage"); printf ("%-20s %s\n", "e2fsck-f", "check an ext2/ext3 filesystem"); printf ("%-20s %s\n", "equal", "test if two files have equal contents"); printf ("%-20s %s\n", "exists", "test if file or directory exists"); @@ -86,7 +89,10 @@ void list_commands (void) printf ("%-20s %s\n", "get-verbose", "get verbose mode"); printf ("%-20s %s\n", "glob-expand", "expand a wildcard path"); printf ("%-20s %s\n", "grub-install", "install GRUB"); + printf ("%-20s %s\n", "head", "return first 10 lines of a file"); + printf ("%-20s %s\n", "head-n", "return first N lines of a file"); printf ("%-20s %s\n", "hexdump", "dump a file in hexadecimal"); + printf ("%-20s %s\n", "initrd-list", "list files in an initrd"); printf ("%-20s %s\n", "is-busy", "is busy processing a command"); printf ("%-20s %s\n", "is-config", "is in configuration state"); printf ("%-20s %s\n", "is-dir", "test if file exists"); @@ -111,6 +117,7 @@ void list_commands (void) printf ("%-20s %s\n", "mkdtemp", "create a temporary directory"); printf ("%-20s %s\n", "mkfs", "make a filesystem"); printf ("%-20s %s\n", "mount", "mount a guest disk at a position in the filesystem"); + printf ("%-20s %s\n", "mount-loop", "mount a file using the loop device"); printf ("%-20s %s\n", "mount-options", "mount a guest disk with mount options"); printf ("%-20s %s\n", "mount-ro", "mount a guest disk, read-only"); printf ("%-20s %s\n", "mount-vfs", "mount a guest disk with mount options and vfstype"); @@ -151,6 +158,8 @@ void list_commands (void) printf ("%-20s %s\n", "strings", "print the printable strings in a file"); printf ("%-20s %s\n", "strings-e", "print the printable strings in a file"); printf ("%-20s %s\n", "sync", "sync disks, writes are flushed through to the disk image"); + printf ("%-20s %s\n", "tail", "return last 10 lines of a file"); + printf ("%-20s %s\n", "tail-n", "return last N lines of a file"); printf ("%-20s %s\n", "tar-in", "unpack tarfile to directory"); printf ("%-20s %s\n", "tar-out", "pack directory into tarfile"); printf ("%-20s %s\n", "tgz-in", "unpack compressed tarball to directory"); @@ -535,7 +544,7 @@ void display_command (const char *cmd) 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."); + 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."); @@ -600,6 +609,33 @@ void display_command (const char *cmd) if (strcasecmp (cmd, "wc_c") == 0 || strcasecmp (cmd, "wc-c") == 0) pod2text ("wc-c - count characters in a file", " wc-c \n\nThis command counts the characters in a file, using the\nC external command."); else + if (strcasecmp (cmd, "head") == 0) + pod2text ("head - return first 10 lines of a file", " head \n\nThis command returns up to the first 10 lines of a file as\na list of strings.\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, "head_n") == 0 || strcasecmp (cmd, "head-n") == 0) + pod2text ("head-n - return first N lines of a file", " head-n \n\nIf the parameter C is a positive number, this returns the first\nC lines of the file C.\n\nIf the parameter C is a negative number, this returns lines\nfrom the file C, excluding the last C lines.\n\nIf the parameter C is zero, this returns an empty list.\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, "tail") == 0) + pod2text ("tail - return last 10 lines of a file", " tail \n\nThis command returns up to the last 10 lines of a file as\na list of strings.\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, "tail_n") == 0 || strcasecmp (cmd, "tail-n") == 0) + pod2text ("tail-n - return last N lines of a file", " tail-n \n\nIf the parameter C is a positive number, this returns the last\nC lines of the file C.\n\nIf the parameter C is a negative number, this returns lines\nfrom the file C, starting with the C<-nrlines>th line.\n\nIf the parameter C is zero, this returns an empty list.\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, "df") == 0) + pod2text ("df - report file system disk space usage", " df\n\nThis command runs the C command to report disk space used.\n\nThis command is mostly useful for interactive sessions. It\nis I intended that you try to parse the output string.\nUse C from programs."); + else + if (strcasecmp (cmd, "df_h") == 0 || strcasecmp (cmd, "df-h") == 0) + pod2text ("df-h - report file system disk space usage (human readable)", " df-h\n\nThis command runs the C command to report disk space used\nin human-readable format.\n\nThis command is mostly useful for interactive sessions. It\nis I intended that you try to parse the output string.\nUse C from programs."); + else + if (strcasecmp (cmd, "du") == 0) + pod2text ("du - estimate file space usage", " du \n\nThis command runs the C command to estimate file space\nusage for C.\n\nC can be a file or a directory. If C is a directory\nthen the estimate includes the contents of the directory and all\nsubdirectories (recursively).\n\nThe result is the estimated size in I\n(ie. units of 1024 bytes)."); + else + if (strcasecmp (cmd, "initrd_list") == 0 || strcasecmp (cmd, "initrd-list") == 0) + pod2text ("initrd-list - list files in an initrd", " initrd-list \n\nThis command lists out files contained in an initrd.\n\nThe files are listed without any initial C character. The\nfiles are listed in the order they appear (not necessarily\nalphabetical). Directory names are listed as separate items.\n\nOld Linux kernels (2.4 and earlier) used a compressed ext2\nfilesystem as initrd. We I support the newer initramfs\nformat (compressed cpio files)."); + else + if (strcasecmp (cmd, "mount_loop") == 0 || strcasecmp (cmd, "mount-loop") == 0) + pod2text ("mount-loop - mount a file using the loop device", " mount-loop \n\nThis command lets you mount C (a filesystem image\nin a file) on a mount point. It is entirely equivalent to\nthe command C."); + else display_builtin_command (cmd); } @@ -2584,7 +2620,7 @@ static int run_sfdisk_N (const char *cmd, int argc, char *argv[]) { int r; const char *device; - int n; + int partnum; int cyls; int heads; int sectors; @@ -2595,12 +2631,12 @@ static int run_sfdisk_N (const char *cmd, int argc, char *argv[]) return -1; } device = argv[0]; - n = atoi (argv[1]); + partnum = 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); + r = guestfs_sfdisk_N (g, device, partnum, cyls, heads, sectors, line); return r; } @@ -2936,6 +2972,157 @@ static int run_wc_c (const char *cmd, int argc, char *argv[]) return 0; } +static int run_head (const char *cmd, int argc, char *argv[]) +{ + char **r; + const char *path; + 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; + } + path = argv[0]; + r = guestfs_head (g, path); + if (r == NULL) return -1; + print_strings (r); + free_strings (r); + return 0; +} + +static int run_head_n (const char *cmd, int argc, char *argv[]) +{ + char **r; + int nrlines; + const char *path; + 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; + } + nrlines = atoi (argv[0]); + path = argv[1]; + r = guestfs_head_n (g, nrlines, path); + if (r == NULL) return -1; + print_strings (r); + free_strings (r); + return 0; +} + +static int run_tail (const char *cmd, int argc, char *argv[]) +{ + char **r; + const char *path; + 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; + } + path = argv[0]; + r = guestfs_tail (g, path); + if (r == NULL) return -1; + print_strings (r); + free_strings (r); + return 0; +} + +static int run_tail_n (const char *cmd, int argc, char *argv[]) +{ + char **r; + int nrlines; + const char *path; + 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; + } + nrlines = atoi (argv[0]); + path = argv[1]; + r = guestfs_tail_n (g, nrlines, path); + if (r == NULL) return -1; + print_strings (r); + free_strings (r); + return 0; +} + +static int run_df (const char *cmd, int argc, char *argv[]) +{ + char *r; + if (argc != 0) { + fprintf (stderr, "%s should have 0 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + r = guestfs_df (g); + if (r == NULL) return -1; + printf ("%s\n", r); + free (r); + return 0; +} + +static int run_df_h (const char *cmd, int argc, char *argv[]) +{ + char *r; + if (argc != 0) { + fprintf (stderr, "%s should have 0 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + r = guestfs_df_h (g); + if (r == NULL) return -1; + printf ("%s\n", r); + free (r); + return 0; +} + +static int run_du (const char *cmd, int argc, char *argv[]) +{ + int64_t r; + const char *path; + 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; + } + path = argv[0]; + r = guestfs_du (g, path); + if (r == -1) return -1; + printf ("%" PRIi64 "\n", r); + return 0; +} + +static int run_initrd_list (const char *cmd, int argc, char *argv[]) +{ + char **r; + const char *path; + 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; + } + path = argv[0]; + r = guestfs_initrd_list (g, path); + if (r == NULL) return -1; + print_strings (r); + free_strings (r); + return 0; +} + +static int run_mount_loop (const char *cmd, int argc, char *argv[]) +{ + int r; + const char *file; + const char *mountpoint; + 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; + } + file = argv[0]; + mountpoint = argv[1]; + r = guestfs_mount_loop (g, file, mountpoint); + return r; +} + int run_action (const char *cmd, int argc, char *argv[]) { if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0) @@ -3361,6 +3548,33 @@ int run_action (const char *cmd, int argc, char *argv[]) if (strcasecmp (cmd, "wc_c") == 0 || strcasecmp (cmd, "wc-c") == 0) return run_wc_c (cmd, argc, argv); else + if (strcasecmp (cmd, "head") == 0) + return run_head (cmd, argc, argv); + else + if (strcasecmp (cmd, "head_n") == 0 || strcasecmp (cmd, "head-n") == 0) + return run_head_n (cmd, argc, argv); + else + if (strcasecmp (cmd, "tail") == 0) + return run_tail (cmd, argc, argv); + else + if (strcasecmp (cmd, "tail_n") == 0 || strcasecmp (cmd, "tail-n") == 0) + return run_tail_n (cmd, argc, argv); + else + if (strcasecmp (cmd, "df") == 0) + return run_df (cmd, argc, argv); + else + if (strcasecmp (cmd, "df_h") == 0 || strcasecmp (cmd, "df-h") == 0) + return run_df_h (cmd, argc, argv); + else + if (strcasecmp (cmd, "du") == 0) + return run_du (cmd, argc, argv); + else + if (strcasecmp (cmd, "initrd_list") == 0 || strcasecmp (cmd, "initrd-list") == 0) + return run_initrd_list (cmd, argc, argv); + else + if (strcasecmp (cmd, "mount_loop") == 0 || strcasecmp (cmd, "mount-loop") == 0) + return run_mount_loop (cmd, argc, argv); + else { fprintf (stderr, "%s: unknown command\n", cmd); return -1;