X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=fish%2Fcmds.c;h=c9c05158bee9fbb0e4b2297c817fc540da064b2d;hb=1799b5ce4741446704418fe06ea7e13a91028b7e;hp=6067eed975c291bd8a446dd24deb13b2df247e6d;hpb=b2ed0f4c55c2bd3d07341ba2207f0cb238eb4e18;p=libguestfs.git diff --git a/fish/cmds.c b/fish/cmds.c index 6067eed..c9c0515 100644 --- a/fish/cmds.c +++ b/fish/cmds.c @@ -72,6 +72,7 @@ void list_commands (void) 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"); @@ -91,6 +92,7 @@ void list_commands (void) 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"); @@ -115,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"); @@ -624,6 +627,15 @@ void display_command (const char *cmd) 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); } @@ -3062,6 +3074,55 @@ static int run_df_h (const char *cmd, int argc, char *argv[]) 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) @@ -3505,6 +3566,15 @@ int run_action (const char *cmd, int argc, char *argv[]) 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;