On bad removal unmount mountpoint of storage without partitions.

On bad removal of storage device, this change
will make sure to unmount the mount point
of the storage device having only disk and no partitions.

Change-Id: Ieb6ad1297883b93050abdf7d98346388cd5610df
diff --git a/DirectVolume.cpp b/DirectVolume.cpp
index cfa1e0b..3076d5a 100644
--- a/DirectVolume.cpp
+++ b/DirectVolume.cpp
@@ -330,6 +330,23 @@
              getLabel(), getFuseMountpoint(), major, minor);
     mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskRemoved,
                                              msg, false);
+
+    if ((dev_t) MKDEV(major, minor) == mCurrentlyMountedKdev) {
+
+        bool providesAsec = (getFlags() & VOL_PROVIDES_ASEC) != 0;
+        if (providesAsec && mVm->cleanupAsec(this, true)) {
+            SLOGE("Failed to cleanup ASEC - unmount will probably fail!");
+        }
+
+        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");
+        }
+    }
+
     setState(Volume::State_NoMedia);
 }