summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2021-12-02 21:59:35 +0100
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-12-02 21:59:35 +0100
commitf473d0cef2930f8404ac262d93eb9067c2b41c3a (patch)
treebc3d102e4396e16e70ec1a02b44fb5462b49b7f7
parentMerge changes from topic "presubmit-am-7a6e71eafa1b4d2399629cd748f22c65" into sc-qpr1-dev am: ecb6b5c225 (diff)
parentMerge "Avoid to format raw disk if metadata encryption is enabled" am: 5bd36e04be (diff)
downloadandroid_bootable_recovery-f473d0cef2930f8404ac262d93eb9067c2b41c3a.tar
android_bootable_recovery-f473d0cef2930f8404ac262d93eb9067c2b41c3a.tar.gz
android_bootable_recovery-f473d0cef2930f8404ac262d93eb9067c2b41c3a.tar.bz2
android_bootable_recovery-f473d0cef2930f8404ac262d93eb9067c2b41c3a.tar.lz
android_bootable_recovery-f473d0cef2930f8404ac262d93eb9067c2b41c3a.tar.xz
android_bootable_recovery-f473d0cef2930f8404ac262d93eb9067c2b41c3a.tar.zst
android_bootable_recovery-f473d0cef2930f8404ac262d93eb9067c2b41c3a.zip
Diffstat (limited to '')
-rw-r--r--recovery_utils/roots.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/recovery_utils/roots.cpp b/recovery_utils/roots.cpp
index 0b82c1ccd..d761e7525 100644
--- a/recovery_utils/roots.cpp
+++ b/recovery_utils/roots.cpp
@@ -34,6 +34,7 @@
#include <android-base/stringprintf.h>
#include <android-base/unique_fd.h>
#include <ext4_utils/ext4_utils.h>
+#include <ext4_utils/wipe.h>
#include <fs_mgr.h>
#include <fs_mgr/roots.h>
@@ -176,6 +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 do encrypt_in_place the raw disk which gives a subtle duration
+ // to get any failure in the process. In order to avoid it, let's simply wipe
+ // the raw disk if we don't reserve any space, which behaves exactly same as booting
+ // after "fastboot -w".
+ if (!v->metadata_encryption.empty() && length == 0) {
+ 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") {
static constexpr int kBlockSize = 4096;
std::vector<std::string> mke2fs_args = {