Fixed bugs with ASEC filesystem.

Changed ext4 to be 4kb aligned, and fat to be 32kb aligned.
Fixed issue that could potentially cause unencrypted ext4
ASECS to overwrite the ASEC super block when filled.

Change-Id: I890426c82ac9cbc65add85a8e3f5063504193c31
Signed-off-by: Daniel Rosenberg <drosen@google.com>
diff --git a/Ext4.cpp b/Ext4.cpp
index b82b4c5..acf1777 100644
--- a/Ext4.cpp
+++ b/Ext4.cpp
@@ -67,9 +67,9 @@
     return rc;
 }
 
-int Ext4::format(const char *fsPath, const char *mountpoint) {
+int Ext4::format(const char *fsPath, unsigned int numSectors, const char *mountpoint) {
     int fd;
-    const char *args[5];
+    const char *args[7];
     int rc;
     int status;
 
@@ -77,7 +77,18 @@
     args[1] = "-J";
     args[2] = "-a";
     args[3] = mountpoint;
-    args[4] = fsPath;
+    if (numSectors) {
+        char tmp[32];
+        snprintf(tmp, sizeof(tmp), "%u", numSectors * 512);
+        const char *size = tmp;
+        args[4] = "-l";
+        args[5] = size;
+        args[6] = fsPath;
+        rc = android_fork_execvp(ARRAY_SIZE(args), (char **)args, &status, false, true);
+    } else {
+        args[4] = fsPath;
+        rc = android_fork_execvp(5, (char **)args, &status, false, true);
+    }
     rc = android_fork_execvp(ARRAY_SIZE(args), (char **)args, &status, false,
             true);
     if (rc != 0) {