vold: Unmount secure containers when the underlying media is removed.
Signed-off-by: San Mehat <san@google.com>
This commit is contained in:
parent
0586d54053
commit
88705166ab
2 changed files with 32 additions and 1 deletions
|
@ -51,12 +51,15 @@ VolumeManager *VolumeManager::Instance() {
|
||||||
VolumeManager::VolumeManager() {
|
VolumeManager::VolumeManager() {
|
||||||
mBlockDevices = new BlockDeviceCollection();
|
mBlockDevices = new BlockDeviceCollection();
|
||||||
mVolumes = new VolumeCollection();
|
mVolumes = new VolumeCollection();
|
||||||
|
mActiveContainers = new AsecIdCollection();
|
||||||
mBroadcaster = NULL;
|
mBroadcaster = NULL;
|
||||||
mUsbMassStorageConnected = false;
|
mUsbMassStorageConnected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
VolumeManager::~VolumeManager() {
|
VolumeManager::~VolumeManager() {
|
||||||
delete mBlockDevices;
|
delete mBlockDevices;
|
||||||
|
delete mVolumes;
|
||||||
|
delete mActiveContainers;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VolumeManager::start() {
|
int VolumeManager::start() {
|
||||||
|
@ -257,7 +260,8 @@ int VolumeManager::createAsec(const char *id, unsigned int numSectors,
|
||||||
unlink(asecFileName);
|
unlink(asecFileName);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mActiveContainers->push_back(strdup(id));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,6 +328,8 @@ int VolumeManager::unmountAsec(const char *id) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unlink(mountPoint);
|
||||||
|
|
||||||
if (Devmapper::destroy(id) && errno != ENXIO) {
|
if (Devmapper::destroy(id) && errno != ENXIO) {
|
||||||
LOGE("Failed to destroy devmapper instance (%s)", strerror(errno));
|
LOGE("Failed to destroy devmapper instance (%s)", strerror(errno));
|
||||||
}
|
}
|
||||||
|
@ -332,6 +338,18 @@ int VolumeManager::unmountAsec(const char *id) {
|
||||||
if (!Loop::lookupActive(asecFileName, loopDevice, sizeof(loopDevice))) {
|
if (!Loop::lookupActive(asecFileName, loopDevice, sizeof(loopDevice))) {
|
||||||
Loop::destroyByDevice(loopDevice);
|
Loop::destroyByDevice(loopDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AsecIdCollection::iterator it;
|
||||||
|
for (it = mActiveContainers->begin(); it != mActiveContainers->end(); ++it) {
|
||||||
|
if (!strcmp(*it, id)) {
|
||||||
|
free(*it);
|
||||||
|
mActiveContainers->erase(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (it == mActiveContainers->end()) {
|
||||||
|
LOGW("mActiveContainers is inconsistent!");
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,6 +459,7 @@ int VolumeManager::mountAsec(const char *id, const char *key, int ownerUid) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mActiveContainers->push_back(strdup(id));
|
||||||
LOGD("ASEC %s mounted", id);
|
LOGD("ASEC %s mounted", id);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -610,6 +629,15 @@ int VolumeManager::unmountVolume(const char *label) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while(mActiveContainers->size()) {
|
||||||
|
AsecIdCollection::iterator it = mActiveContainers->begin();
|
||||||
|
LOGI("Unmounting ASEC %s (dependant on %s)", *it, v->getMountpoint());
|
||||||
|
if (unmountAsec(*it)) {
|
||||||
|
LOGE("Failed to unmount ASEC %s (%s) - unmount of %s may fail!", *it,
|
||||||
|
strerror(errno), v->getMountpoint());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return v->unmountVol();
|
return v->unmountVol();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#include "BlockDevice.h"
|
#include "BlockDevice.h"
|
||||||
#include "Volume.h"
|
#include "Volume.h"
|
||||||
|
|
||||||
|
typedef android::List<char *> AsecIdCollection;
|
||||||
|
|
||||||
class VolumeManager {
|
class VolumeManager {
|
||||||
private:
|
private:
|
||||||
static VolumeManager *sInstance;
|
static VolumeManager *sInstance;
|
||||||
|
@ -34,6 +36,7 @@ private:
|
||||||
BlockDeviceCollection *mBlockDevices;
|
BlockDeviceCollection *mBlockDevices;
|
||||||
|
|
||||||
VolumeCollection *mVolumes;
|
VolumeCollection *mVolumes;
|
||||||
|
AsecIdCollection *mActiveContainers;
|
||||||
bool mUsbMassStorageConnected;
|
bool mUsbMassStorageConnected;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue