From e492608f2f3809a824cb70ee03ff305964b69dd7 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 29 Jun 2009 12:47:20 +0100 Subject: Generated code for 'du' command. --- fish/cmds.c | 23 +++++++++++++++++++++++ fish/completion.c | 1 + 2 files changed, 24 insertions(+) (limited to 'fish') diff --git a/fish/cmds.c b/fish/cmds.c index 6067eed9..c802f90b 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"); @@ -623,6 +624,9 @@ void display_command (const char *cmd) 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 display_builtin_command (cmd); } @@ -3062,6 +3066,22 @@ 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; +} + int run_action (const char *cmd, int argc, char *argv[]) { if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0) @@ -3504,6 +3524,9 @@ int run_action (const char *cmd, int argc, char *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 { fprintf (stderr, "%s: unknown command\n", cmd); diff --git a/fish/completion.c b/fish/completion.c index 6b58bd2c..5254a373 100644 --- a/fish/completion.c +++ b/fish/completion.c @@ -193,6 +193,7 @@ static const char *const commands[] = { "tail-n", "df", "df-h", + "du", NULL }; -- cgit