From c89b4e4314e8729871bb1e69d197da7446966ffb Mon Sep 17 00:00:00 2001 From: Dan Shi Date: Thu, 11 Jan 2024 02:46:37 +0000 Subject: [PATCH] Revert "Only format /data in recovery if user specified a new fstype" This reverts commit 765172c709e8296e395de7a6ca368883485faa08. Reason for revert: b/319516268 Change-Id: I974722fb433f20c57b9535fef2e28a78acbc1931 --- recovery_utils/roots.cpp | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/recovery_utils/roots.cpp b/recovery_utils/roots.cpp index bc8bc405..6396d446 100644 --- a/recovery_utils/roots.cpp +++ b/recovery_utils/roots.cpp @@ -177,27 +177,10 @@ 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 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; - } - } + // next boot will first mount this partition as read only, and then unmount, + // call encrypt_inplace. - if (new_fstype == "ext4") { + if ((v->fs_type == "ext4" && new_fstype.empty()) || new_fstype == "ext4") { LOG(INFO) << "Formatting " << v->blk_device << " as ext4"; static constexpr int kBlockSize = 4096; std::vector mke2fs_args = {