Add support for creating ext4 images with mke2fs

We are investigating replacing make_ext4fs with the upstream tool mke2fs.
See b/23686092 for more informations.

To mitigate the trouble that may arise if the new tool behave differently
compared to the old one, there will be a transition period where both mke2fs
and make_ext4fs will be supported.

This patch does 3 things:
  - add the necessary code to use mke2fs to format an ext4 partition;
  - add a dependency to the binary used by vold.

Test: m -j32 with TARGET_USES_MKE2FS={,false,true}
                  TARGET_USERIMAGES_USE_EXT4={,true}

Change-Id: I89222642fe1d11a035155c8224b84b2e3719938b
diff --git a/fs/Ext4.cpp b/fs/Ext4.cpp
index 0bd5b0c..0670bb5 100644
--- a/fs/Ext4.cpp
+++ b/fs/Ext4.cpp
@@ -55,7 +55,11 @@
 namespace ext4 {
 
 static const char* kResizefsPath = "/system/bin/resize2fs";
+#ifdef TARGET_USES_MKE2FS
+static const char* kMkfsPath = "/system/bin/mke2fs";
+#else
 static const char* kMkfsPath = "/system/bin/make_ext4fs";
+#endif
 static const char* kFsckPath = "/system/bin/e2fsck";
 
 bool IsSupported() {
@@ -165,6 +169,25 @@
         const std::string& target) {
     std::vector<std::string> cmd;
     cmd.push_back(kMkfsPath);
+
+#ifdef TARGET_USES_MKE2FS
+    cmd.push_back("-b");
+    cmd.push_back("4096");
+
+    cmd.push_back("-t");
+    cmd.push_back("ext4");
+
+    cmd.push_back("-M");
+    cmd.push_back(target);
+
+    cmd.push_back("-O");
+    cmd.push_back("^has_journal");
+
+    cmd.push_back(source);
+
+    if (numSectors)
+        cmd.push_back(StringPrintf("%lu", numSectors * (4096 / 512)));
+#else
     cmd.push_back("-J");
 
     cmd.push_back("-a");
@@ -178,6 +201,7 @@
     // Always generate a real UUID
     cmd.push_back("-u");
     cmd.push_back(source);
+#endif
 
     return ForkExecvp(cmd);
 }