Pass wiped and fs_type to vold to format encrypted partition
Bug: 172378121
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
Change-Id: I358380fc47fe9d4d75337323c772ca1af122d2c6
diff --git a/fs_mgr/fs_mgr.cpp b/fs_mgr/fs_mgr.cpp
index 4c9fd9b..2876094 100644
--- a/fs_mgr/fs_mgr.cpp
+++ b/fs_mgr/fs_mgr.cpp
@@ -1324,6 +1324,7 @@
int error_count = 0;
CheckpointManager checkpoint_manager;
AvbUniquePtr avb_handle(nullptr);
+ bool wiped = false;
bool userdata_mounted = false;
if (fstab->empty()) {
@@ -1457,7 +1458,8 @@
encryptable = status;
if (status == FS_MGR_MNTALL_DEV_NEEDS_METADATA_ENCRYPTION) {
if (!call_vdc({"cryptfs", "encryptFstab", attempted_entry.blk_device,
- attempted_entry.mount_point},
+ attempted_entry.mount_point, wiped ? "true" : "false",
+ attempted_entry.fs_type},
nullptr)) {
LERROR << "Encryption failed";
set_type_property(encryptable);
@@ -1474,7 +1476,7 @@
}
// Mounting failed, understand why and retry.
- bool wiped = partition_wiped(current_entry.blk_device.c_str());
+ wiped = partition_wiped(current_entry.blk_device.c_str());
bool crypt_footer = false;
if (mount_errno != EBUSY && mount_errno != EACCES &&
current_entry.fs_mgr_flags.formattable && wiped) {
@@ -1499,6 +1501,27 @@
} else if (current_entry.is_encryptable() && current_entry.key_loc == KEY_IN_FOOTER) {
crypt_footer = true;
}
+
+ // EncryptInplace will be used when vdc gives an error or needs to format partitions
+ // other than /data
+ if (should_use_metadata_encryption(current_entry) &&
+ current_entry.mount_point == "/data") {
+
+ // vdc->Format requires "ro.crypto.type" to set an encryption flag
+ encryptable = FS_MGR_MNTALL_DEV_IS_METADATA_ENCRYPTED;
+ set_type_property(encryptable);
+
+ if (!call_vdc({"cryptfs", "encryptFstab", current_entry.blk_device,
+ current_entry.mount_point, "true" /* shouldFormat */,
+ current_entry.fs_type},
+ nullptr)) {
+ LERROR << "Encryption failed";
+ } else {
+ userdata_mounted = true;
+ continue;
+ }
+ }
+
if (fs_mgr_do_format(current_entry, crypt_footer) == 0) {
// Let's replay the mount actions.
i = top_idx - 1;