summaryrefslogtreecommitdiffstats
path: root/DirectVolume.cpp
diff options
context:
space:
mode:
authorKen Sumrall <ksumrall@android.com>2011-08-31 16:14:23 -0700
committerKen Sumrall <ksumrall@android.com>2011-08-31 18:09:35 -0700
commit0b8b59719357fb80c330442787f7d5b1e332263b (patch)
tree4d8b42125be6c78ed47f96bb2a35535649a02d0c /DirectVolume.cpp
parente14fcf99b59954f3b2eb07a3724c078b80d58ffd (diff)
downloadsystem_vold-0b8b59719357fb80c330442787f7d5b1e332263b.tar.gz
system_vold-0b8b59719357fb80c330442787f7d5b1e332263b.tar.bz2
system_vold-0b8b59719357fb80c330442787f7d5b1e332263b.zip
Add the ability to revert a crypto mapping when unmounting a volume
Add the force_and_revert option to the unmount command which will force the unmount, and revert a crypto mapping. This is used during factory reset so that when the internal sdcard volume is formatted, it formats the raw device, not the encrypted mapping. Change-Id: I36b6ff9bb54863b121de635472a303bf4a2334a9
Diffstat (limited to 'DirectVolume.cpp')
-rw-r--r--DirectVolume.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/DirectVolume.cpp b/DirectVolume.cpp
index 2ddd5ab..4acee76 100644
--- a/DirectVolume.cpp
+++ b/DirectVolume.cpp
@@ -317,7 +317,7 @@ void DirectVolume::handlePartitionRemoved(const char *devpath, NetlinkEvent *evt
SLOGE("Failed to cleanup ASEC - unmount will probably fail!");
}
- if (Volume::unmountVol(true)) {
+ 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
@@ -392,6 +392,16 @@ int DirectVolume::updateDeviceInfo(char *new_path, int new_major, int new_minor)
mPaths->erase(it); /* Remove it from the list */
addPath(new_path); /* Put the new path on the list */
+ /* Save away original info so we can restore it when doing factory reset.
+ * Then, when doing the format, it will format the original device in the
+ * clear, otherwise it just formats the encrypted device which is not
+ * readable when the device boots unencrypted after the reset.
+ */
+ mOrigDiskMajor = mDiskMajor;
+ mOrigDiskMinor = mDiskMinor;
+ mOrigPartIdx = mPartIdx;
+ memcpy(mOrigPartMinors, mPartMinors, sizeof(mPartMinors));
+
mDiskMajor = new_major;
mDiskMinor = new_minor;
/* Ugh, virual block devices don't use minor 0 for whole disk and minor > 0 for
@@ -410,6 +420,24 @@ int DirectVolume::updateDeviceInfo(char *new_path, int new_major, int new_minor)
}
/*
+ * Called from base to revert device info to the way it was before a
+ * crypto mapping was created for it.
+ */
+void DirectVolume::revertDeviceInfo(void)
+{
+ if (mIsDecrypted) {
+ mDiskMajor = mOrigDiskMajor;
+ mDiskMinor = mOrigDiskMinor;
+ mPartIdx = mOrigPartIdx;
+ memcpy(mPartMinors, mOrigPartMinors, sizeof(mPartMinors));
+
+ mIsDecrypted = 0;
+ }
+
+ return;
+}
+
+/*
* Called from base to give cryptfs all the info it needs to encrypt eligible volumes
*/
int DirectVolume::getVolInfo(struct volume_info *v)