aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2024-01-13 23:12:38 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2024-01-13 23:12:38 +0000
commitfdcc28ebf507b35fb70993e22d9a094a2c146e81 (patch)
treed6936ef699d8dc39ad2d618f533653b3987ff157
parentb1d235a119a6487986072d4447d2de56401e694d (diff)
parent5db49a357d56b548e6ed254f683da8a52010294e (diff)
downloadrecovery-fdcc28ebf507b35fb70993e22d9a094a2c146e81.tar.gz
Merge "Reland "Only format /data in recovery if user specified a new fstype"" into main am: 5db49a357d
Original change: https://android-review.googlesource.com/c/platform/bootable/recovery/+/2909199 Change-Id: I1399bb7b5d57507a9fce323fc07f734f14c97bc5 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--recovery_utils/roots.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/recovery_utils/roots.cpp b/recovery_utils/roots.cpp
index 6396d446..e7a7d652 100644
--- a/recovery_utils/roots.cpp
+++ b/recovery_utils/roots.cpp
@@ -177,8 +177,25 @@ int format_volume(const std::string& volume, const std::string& directory,
}
// If the raw disk will be used as a metadata encrypted device mapper target,
- // next boot will first mount this partition as read only, and then unmount,
- // call encrypt_inplace.
+ // next boot will do encrypt_in_place the raw disk. While fs_mgr mounts /data
+ // as RO to avoid write file operations before encrypt_inplace, this code path
+ // is not well tested so we would like to avoid it if possible. For safety,
+ // let vold do the formatting on boot for metadata encrypted devices, except
+ // when user specified a new fstype. Because init formats /data according
+ // to fstab, it's difficult to override the fstab in init.
+ if (!v->metadata_key_dir.empty() && length == 0 && new_fstype.empty()) {
+ android::base::unique_fd fd(open(v->blk_device.c_str(), O_RDWR));
+ if (fd == -1) {
+ PLOG(ERROR) << "format_volume: failed to open " << v->blk_device;
+ return -1;
+ }
+ int64_t device_size = get_file_size(fd.get(), 0);
+ if (device_size > 0 && !wipe_block_device(fd.get(), device_size)) {
+ LOG(INFO) << "format_volume: wipe metadata encrypted " << v->blk_device << " with size "
+ << device_size;
+ return 0;
+ }
+ }
if ((v->fs_type == "ext4" && new_fstype.empty()) || new_fstype == "ext4") {
LOG(INFO) << "Formatting " << v->blk_device << " as ext4";