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
diff --git a/Volume.cpp b/Volume.cpp
index 45db27e..e70a590 100644
--- a/Volume.cpp
+++ b/Volume.cpp
@@ -591,7 +591,7 @@
return -1;
}
-int Volume::unmountVol(bool force) {
+int Volume::unmountVol(bool force, bool revert) {
int i, rc;
if (getState() != Volume::State_Mounted) {
@@ -645,6 +645,16 @@
SLOGI("%s unmounted sucessfully", getMountpoint());
+ /* If this is an encrypted volume, and we've been asked to undo
+ * the crypto mapping, then revert the dm-crypt mapping, and revert
+ * the device info to the original values.
+ */
+ if (revert && isDecrypted()) {
+ cryptfs_revert_volume(getLabel());
+ revertDeviceInfo();
+ SLOGI("Encrypted volume %s reverted successfully", getMountpoint());
+ }
+
setState(Volume::State_Idle);
mCurrentlyMountedKdev = -1;
return 0;