Add f2fs support for private volumes.

When formatting volumes, pass along fsType string which can be "auto"
to let the volume select the best choice.  For now, private volumes
assume that MMC devices (like SD cards) are best off using f2fs when
both kernel support and tools are present, otherwise fall back to
ext4.  Use blkid when mounting to pick the right set of tools.

Move filesystem utility methods into namespaces and place in separate
directory to be more organized.

Bug: 20275581
Change-Id: Id5f82d8672dda2e9f68c35b075f28232b0b55ed4
diff --git a/PublicVolume.cpp b/PublicVolume.cpp
index 2b2c32b..9d6887d 100644
--- a/PublicVolume.cpp
+++ b/PublicVolume.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "Fat.h"
+#include "fs/Vfat.h"
 #include "PublicVolume.h"
 #include "Utils.h"
 #include "VolumeManager.h"
@@ -94,7 +94,7 @@
     // TODO: expand to support mounting other filesystems
     readMetadata();
 
-    if (Fat::check(mDevPath.c_str())) {
+    if (vfat::Check(mDevPath)) {
         LOG(ERROR) << getId() << " failed filesystem check";
         return -EIO;
     }
@@ -119,7 +119,7 @@
         return -errno;
     }
 
-    if (Fat::doMount(mDevPath.c_str(), mRawPath.c_str(), false, false, false,
+    if (vfat::Mount(mDevPath, mRawPath, false, false, false,
             AID_MEDIA_RW, AID_MEDIA_RW, 0007, true)) {
         PLOG(ERROR) << getId() << " failed to mount " << mDevPath;
         return -EIO;
@@ -200,11 +200,20 @@
     return OK;
 }
 
-status_t PublicVolume::doFormat() {
-    if (Fat::format(mDevPath.c_str(), 0, true)) {
-        LOG(ERROR) << getId() << " failed to format";
-        return -errno;
+status_t PublicVolume::doFormat(const std::string& fsType) {
+    if (fsType == "vfat" || fsType == "auto") {
+        if (WipeBlockDevice(mDevPath) != OK) {
+            LOG(WARNING) << getId() << " failed to wipe";
+        }
+        if (vfat::Format(mDevPath, 0)) {
+            LOG(ERROR) << getId() << " failed to format";
+            return -errno;
+        }
+    } else {
+        LOG(ERROR) << "Unsupported filesystem " << fsType;
+        return -EINVAL;
     }
+
     return OK;
 }