ASEC resize tweaking, allow read-write mounting.

Resize is no-op when sector count is unchanged; the caller can't
anticipate how vold does its sector calculations.

After resizing, we need to mount the container read-write, so allow
the caller to request "ro" or "rw" mode.

Handle ENOTSUP when trying to fallocate() on some filesystems

Bug: 16514385
Change-Id: I0d3a378280d4c36d14f8108ff428102283d583fa
diff --git a/VolumeManager.cpp b/VolumeManager.cpp
index 06daf40..b2b0cf6 100644
--- a/VolumeManager.cpp
+++ b/VolumeManager.cpp
@@ -641,7 +641,10 @@
      *  add one block for the superblock
      */
     SLOGD("Resizing from %d sectors to %d sectors", oldNumSec, numImgSectors + 1);
-    if (oldNumSec >= numImgSectors + 1) {
+    if (oldNumSec == numImgSectors + 1) {
+        SLOGW("Size unchanged; ignoring resize request");
+        return 0;
+    } else if (oldNumSec > numImgSectors + 1) {
         SLOGE("Only growing is currently supported.");
         close(fd);
         return -1;
@@ -1249,7 +1252,7 @@
     return 0;
 }
 
-int VolumeManager::mountAsec(const char *id, const char *key, int ownerUid) {
+int VolumeManager::mountAsec(const char *id, const char *key, int ownerUid, bool readOnly) {
     char asecFileName[255];
     char mountPoint[255];
 
@@ -1330,9 +1333,9 @@
 
     int result;
     if (sb.c_opts & ASEC_SB_C_OPTS_EXT4) {
-        result = Ext4::doMount(dmDevice, mountPoint, true, false, true);
+        result = Ext4::doMount(dmDevice, mountPoint, readOnly, false, readOnly);
     } else {
-        result = Fat::doMount(dmDevice, mountPoint, true, false, true, ownerUid, 0, 0222, false);
+        result = Fat::doMount(dmDevice, mountPoint, readOnly, false, readOnly, ownerUid, 0, 0222, false);
     }
 
     if (result) {