am 43ed123d: ASEC resize tweaking, allow read-write mounting.

* commit '43ed123d3fc1a3edf3660cd0e2528e971abc399e':
  ASEC resize tweaking, allow read-write mounting.
diff --git a/DirectVolume.cpp b/DirectVolume.cpp
index cfa1e0b..64d7744 100644
--- a/DirectVolume.cpp
+++ b/DirectVolume.cpp
@@ -321,11 +321,17 @@
     char msg[255];
     bool enabled;
 
-    if (mVm->shareEnabled(getLabel(), "ums", &enabled) == 0 && enabled) {
+    SLOGD("Volume %s %s disk %d:%d removed\n", getLabel(), getMountpoint(), major, minor);
+    if ((dev_t) MKDEV(major, minor) == mCurrentlyMountedKdev) {
+        /*
+         * Yikes, our mounted disk is going away!
+         */
+
+        doUnmount(major, minor);
+    } else if (mVm->shareEnabled(getLabel(), "ums", &enabled) == 0 && enabled) {
         mVm->unshareVolume(getLabel(), "ums");
     }
 
-    SLOGD("Volume %s %s disk %d:%d removed\n", getLabel(), getMountpoint(), major, minor);
     snprintf(msg, sizeof(msg), "Volume %s %s disk removed (%d:%d)",
              getLabel(), getFuseMountpoint(), major, minor);
     mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskRemoved,
@@ -352,29 +358,12 @@
     if (state != Volume::State_Mounted && state != Volume::State_Shared) {
         return;
     }
-        
+
     if ((dev_t) MKDEV(major, minor) == mCurrentlyMountedKdev) {
         /*
          * Yikes, our mounted partition is going away!
          */
-
-        bool providesAsec = (getFlags() & VOL_PROVIDES_ASEC) != 0;
-        if (providesAsec && mVm->cleanupAsec(this, true)) {
-            SLOGE("Failed to cleanup ASEC - unmount will probably fail!");
-        }
-
-        snprintf(msg, sizeof(msg), "Volume %s %s bad removal (%d:%d)",
-                 getLabel(), getFuseMountpoint(), major, minor);
-        mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval,
-                                             msg, false);
-
-        if (Volume::unmountVol(true, false)) {
-            SLOGE("Failed to unmount volume on bad removal (%s)", 
-                 strerror(errno));
-            // XXX: At this point we're screwed for now
-        } else {
-            SLOGD("Crisis averted");
-        }
+        doUnmount(major, minor);
     } else if (state == Volume::State_Shared) {
         /* removed during mass storage */
         snprintf(msg, sizeof(msg), "Volume %s bad removal (%d:%d)",
@@ -391,6 +380,27 @@
     }
 }
 
+void DirectVolume::doUnmount(int major, int minor) {
+    char msg[255];
+    bool providesAsec = (getFlags() & VOL_PROVIDES_ASEC) != 0;
+    if (providesAsec && mVm->cleanupAsec(this, true)) {
+        SLOGE("Failed to cleanup ASEC - unmount will probably fail!");
+    }
+
+    snprintf(msg, sizeof(msg), "Volume %s %s bad removal (%d:%d)",
+                getLabel(), getFuseMountpoint(), major, minor);
+    mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval,
+                                            msg, false);
+
+    if (Volume::unmountVol(true, false)) {
+        SLOGE("Failed to unmount volume on bad removal (%s)",
+                strerror(errno));
+        // XXX: At this point we're screwed for now
+    } else {
+        SLOGD("Crisis averted");
+    }
+}
+
 /*
  * Called from base to get a list of devicenodes for mounting
  */
diff --git a/DirectVolume.h b/DirectVolume.h
index 5e0df74..96f46af 100644
--- a/DirectVolume.h
+++ b/DirectVolume.h
@@ -84,6 +84,7 @@
     void handlePartitionChanged(const char *devpath, NetlinkEvent *evt);
 
     int doMountVfat(const char *deviceNode, const char *mountPoint);
+    void doUnmount(int major, int minor);
 
 };
 
diff --git a/Volume.cpp b/Volume.cpp
index ca56d1c..0baf008 100644
--- a/Volume.cpp
+++ b/Volume.cpp
@@ -252,7 +252,7 @@
     dev_t diskNode = getDiskDevice();
     dev_t partNode =
         MKDEV(MAJOR(diskNode),
-              MINOR(diskNode) + (formatEntireDevice ? 1 : mPartIdx));
+              MINOR(diskNode) + (formatEntireDevice ? 0 : mPartIdx));
 
     setState(Volume::State_Formatting);