recovery: updater: autodetect filesystem type

* Attempt to autodetect the filesystem type for mounting from
  update.zips.

Change-Id: Ib6f4535dd88ef714ae1ca6fb0ffae1c7dac0f7ce
diff --git a/updater/install.cpp b/updater/install.cpp
index 93c8904..d86fc49 100644
--- a/updater/install.cpp
+++ b/updater/install.cpp
@@ -48,6 +48,7 @@
 #include <android-base/strings.h>
 #include <android-base/unique_fd.h>
 #include <applypatch/applypatch.h>
+#include <blkid/blkid.h>
 #include <bootloader_message/bootloader_message.h>
 #include <ext4_utils/wipe.h>
 #include <openssl/sha.h>
@@ -348,7 +349,7 @@
   if (!ReadArgs(state, argv, &args)) {
     return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name);
   }
-  const std::string& fs_type = args[0];
+  std::string fs_type = args[0];
   const std::string& partition_type = args[1];
   const std::string& location = args[2];
   const std::string& mount_point = args[3];
@@ -389,6 +390,16 @@
     }
   }
 
+  char* detected_fs_type = blkid_get_tag_value(NULL, "TYPE", location.c_str());
+  if (detected_fs_type) {
+    uiPrintf(state, "detected filesystem %s for %s\n", detected_fs_type, location.c_str());
+    fs_type = detected_fs_type;
+    free(detected_fs_type);
+  } else {
+    uiPrintf(state, "could not detect filesystem for %s, assuming %s\n", location.c_str(),
+             fs_type.c_str());
+  }
+
   if (mount(location.c_str(), mount_point.c_str(), fs_type.c_str(),
             MS_NOATIME | MS_NODEV | MS_NODIRATIME, mount_options.c_str()) < 0) {
     uiPrintf(state, "%s: Failed to mount %s at %s: %s", name, location.c_str(), mount_point.c_str(),