merge in master-release history after reset to b31f33b5e41bf295705b8f0c1582c6277e8fec64
diff --git a/CheckBattery.cpp b/CheckBattery.cpp
index ab5e626..8a674d0 100644
--- a/CheckBattery.cpp
+++ b/CheckBattery.cpp
@@ -64,8 +64,8 @@
     status_t status = interface->getProperty(android::BATTERY_PROP_CAPACITY,
                                              &val);
     if (status == NO_ERROR) {
-        SLOGD("Capacity is %d", val.valueInt);
-        battery_ok = val.valueInt > 5 ? 1 : 0;
+        SLOGD("Capacity is %d", (int)val.valueInt64);
+        battery_ok = val.valueInt64 > 5 ? 1 : 0;
     } else {
         SLOGE("Failed to get battery charge");
         battery_ok = 1;
diff --git a/DirectVolume.cpp b/DirectVolume.cpp
index 67f89ea..62c0560 100644
--- a/DirectVolume.cpp
+++ b/DirectVolume.cpp
@@ -38,7 +38,7 @@
     mPaths = new PathCollection();
     for (int i = 0; i < MAX_PARTITIONS; i++)
         mPartMinors[i] = -1;
-    mPendingPartMap = 0;
+    mPendingPartCount = 0;
     mDiskMajor = -1;
     mDiskMinor = -1;
     mDiskNumParts = 0;
@@ -164,12 +164,9 @@
         mDiskNumParts = 1;
     }
 
-    int partmask = 0;
-    int i;
-    for (i = 1; i <= mDiskNumParts; i++) {
-        partmask |= (1 << i);
-    }
-    mPendingPartMap = partmask;
+    mPendingPartCount = mDiskNumParts;
+    for (int i = 0; i < MAX_PARTITIONS; i++)
+        mPartMinors[i] = -1;
 
     if (mDiskNumParts == 0) {
 #ifdef PARTITION_DEBUG
@@ -178,8 +175,7 @@
         setState(Volume::State_Idle);
     } else {
 #ifdef PARTITION_DEBUG
-        SLOGD("Dv::diskIns - waiting for %d partitions (mask 0x%x)",
-             mDiskNumParts, mPendingPartMap);
+        SLOGD("Dv::diskIns - waiting for %d pending partitions", mPendingPartCount);
 #endif
         setState(Volume::State_Pending);
     }
@@ -219,11 +215,12 @@
     if (part_num >= MAX_PARTITIONS) {
         SLOGE("Dv:partAdd: ignoring part_num = %d (max: %d)\n", part_num, MAX_PARTITIONS-1);
     } else {
+        if ((mPartMinors[part_num - 1] == -1) && mPendingPartCount)
+            mPendingPartCount--;
         mPartMinors[part_num -1] = minor;
     }
-    mPendingPartMap &= ~(1 << part_num);
 
-    if (!mPendingPartMap) {
+    if (!mPendingPartCount) {
 #ifdef PARTITION_DEBUG
         SLOGD("Dv:partAdd: Got all partitions - ready to rock!");
 #endif
@@ -236,7 +233,7 @@
         }
     } else {
 #ifdef PARTITION_DEBUG
-        SLOGD("Dv:partAdd: pending mask now = 0x%x", mPendingPartMap);
+        SLOGD("Dv:partAdd: pending %d disk", mPendingPartCount);
 #endif
     }
 }
@@ -259,12 +256,9 @@
         mDiskNumParts = 1;
     }
 
-    int partmask = 0;
-    int i;
-    for (i = 1; i <= mDiskNumParts; i++) {
-        partmask |= (1 << i);
-    }
-    mPendingPartMap = partmask;
+    mPendingPartCount = mDiskNumParts;
+    for (int i = 0; i < MAX_PARTITIONS; i++)
+        mPartMinors[i] = -1;
 
     if (getState() != Volume::State_Formatting) {
         if (mDiskNumParts == 0) {
diff --git a/DirectVolume.h b/DirectVolume.h
index beda7c3..4495256 100644
--- a/DirectVolume.h
+++ b/DirectVolume.h
@@ -38,7 +38,7 @@
     int            mOrigDiskMinor;
     int            mOrigPartMinors[MAX_PARTITIONS];
     int            mDiskNumParts;
-    unsigned int   mPendingPartMap;
+    int            mPendingPartCount;
     int            mIsDecrypted;
 
 public:
diff --git a/VolumeManager.cpp b/VolumeManager.cpp
index 1ffa939..2049706 100644
--- a/VolumeManager.cpp
+++ b/VolumeManager.cpp
@@ -1708,20 +1708,20 @@
 }
 
 int VolumeManager::mkdirs(char* path) {
-    // Require that path lives under a volume we manage
+    // Require that path lives under a volume we manage and is mounted
     const char* emulated_source = getenv("EMULATED_STORAGE_SOURCE");
     const char* root = NULL;
     if (emulated_source && !strncmp(path, emulated_source, strlen(emulated_source))) {
         root = emulated_source;
     } else {
         Volume* vol = getVolumeForFile(path);
-        if (vol) {
+        if (vol && vol->getState() == Volume::State_Mounted) {
             root = vol->getMountpoint();
         }
     }
 
     if (!root) {
-        SLOGE("Failed to find volume for %s", path);
+        SLOGE("Failed to find mounted volume for %s", path);
         return -EINVAL;
     }