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>
diff --git a/futility/cmd_sign.c b/futility/cmd_sign.c
index f256b00..a960abd 100644
--- a/futility/cmd_sign.c
+++ b/futility/cmd_sign.c
@@ -18,6 +18,7 @@
 #include <unistd.h>
 
 #include "bmpblk_header.h"
+#include "file_type.h"
 #include "fmap.h"
 #include "futility.h"
 #include "gbb_header.h"
@@ -889,7 +890,10 @@
 	}
 
 	/* What are we looking at? */
-	type = futil_what_file_type(infile);
+	if (futil_file_type(infile, &type)) {
+		errorcnt++;
+		goto done;
+	}
 
 	/* We may be able to infer the type based on the other args */
 	if (type == FILE_TYPE_UNKNOWN) {
@@ -900,7 +904,7 @@
 			type = FILE_TYPE_RAW_FIRMWARE;
 	}
 
-	Debug("type=%s\n", futil_file_type_str[type]);
+	Debug("type=%s\n", futil_file_type_str(type));
 
 	/* Check the arguments for the type of thing we want to sign */
 	switch (type) {
@@ -972,6 +976,11 @@
 		errorcnt += no_opt_if(!option.config_data, "config");
 		errorcnt += no_opt_if(option.arch == ARCH_UNSPECIFIED, "arch");
 		break;
+	case FILE_TYPE_CHROMIUMOS_DISK:
+		fprintf(stderr, "Signing a %s is not yet supported\n",
+			futil_file_type_str(type));
+		errorcnt++;
+		break;
 	default:
 		DIE;
 	}