diff options
author | Bill Richardson <wfrichar@chromium.org> | 2015-01-30 12:22:28 -0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-01-31 05:42:48 +0000 |
commit | 2559338dbdacbcbd3ae426337403196135bbc7e8 (patch) | |
tree | fb87c9b5b7058e14349f16cac2dc81966942ea87 /futility/cmd_show.c | |
parent | 65ce99b3e2c75bbb416b6edf78b5ea0d7f8c3a94 (diff) | |
download | vboot-2559338dbdacbcbd3ae426337403196135bbc7e8.tar.gz |
futility: refactor file type detection into new files
This moves the what-kind-of-file-is-this logic into a separate
file, and makes it work by calling distinct recognizers until one
hits. A new "-t" option to the show command prints what it's
doing.
BUG=chromium:228932
BRANCH=ToT
TEST=make runtests
Change-Id: Id8f60bdf3fe6a9adf41b4555b3448a261fa52fea
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/245122
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'futility/cmd_show.c')
-rw-r--r-- | futility/cmd_show.c | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/futility/cmd_show.c b/futility/cmd_show.c index 7f0e488f..c6584259 100644 --- a/futility/cmd_show.c +++ b/futility/cmd_show.c @@ -17,6 +17,7 @@ #include <unistd.h> #include "bmpblk_header.h" +#include "file_type.h" #include "fmap.h" #include "futility.h" #include "gbb_header.h" @@ -38,6 +39,7 @@ static struct local_data_s { uint64_t fv_size; uint32_t padding; int strict; + int t_flag; } option = { .padding = 65536, }; @@ -505,7 +507,7 @@ enum no_short_opts { }; static const char usage[] = "\n" - "Usage: " MYNAME " %s [OPTIONS] FILE\n" + "Usage: " MYNAME " %s [OPTIONS] FILE [...]\n" "\n" "Where FILE could be a\n" "\n" @@ -516,6 +518,7 @@ static const char usage[] = "\n" " kernel partition (/dev/sda2, /dev/mmcblk0p2)\n" "\n" "Options:\n" + " -t Just show the type of each file\n" " -k|--publickey FILE" " Use this public key for validation\n" " -f|--fv FILE Verify this payload (FW_MAIN_A/B)\n" @@ -544,7 +547,34 @@ static const struct option long_opts[] = { {"debug", 0, &debugging_enabled, 1}, {NULL, 0, NULL, 0}, }; -static char *short_opts = ":f:k:"; +static char *short_opts = ":f:k:t"; + + +static void show_type(char *filename) +{ + enum futil_file_err err; + enum futil_file_type type; + err = futil_file_type(filename, &type); + switch (err) { + case FILE_ERR_NONE: + printf("%s:\t%s\n", filename, futil_file_type_str(type)); + break; + case FILE_ERR_DIR: + printf("%s:\t%s\n", filename, "directory"); + break; + case FILE_ERR_CHR: + printf("%s:\t%s\n", filename, "character special"); + break; + case FILE_ERR_FIFO: + printf("%s:\t%s\n", filename, "FIFO"); + break; + case FILE_ERR_SOCK: + printf("%s:\t%s\n", filename, "socket"); + break; + default: + break; + } +} static int do_show(int argc, char *argv[]) { @@ -574,6 +604,9 @@ static int do_show(int argc, char *argv[]) errorcnt++; } break; + case 't': + option.t_flag = 1; + break; case OPT_PADDING: option.padding = strtoul(optarg, &e, 0); if (!*optarg || (e && *e)) { @@ -613,6 +646,12 @@ static int do_show(int argc, char *argv[]) return 1; } + if (option.t_flag) { + for (i = optind; i < argc; i++) + show_type(argv[i]); + goto done; + } + for (i = optind; i < argc; i++) { infile = argv[i]; ifd = open(infile, O_RDONLY); @@ -646,6 +685,7 @@ boo: } } +done: if (option.k) free(option.k); if (option.fv) |