From 88a154d76958c367e75a047a5acc0d2b2dbae67e Mon Sep 17 00:00:00 2001 From: Tim Zimmermann Date: Tue, 8 Jun 2021 16:14:55 +0200 Subject: [PATCH] recovery: make wiping dynamic partitions work Dynamic partitions need special handling: * Block device path read from fstab is actually the partition's name * We need to use BLKROSET ioctl for allowing write operations Change-Id: Ib0a018f789716c9fc43db9316d15dbda13991c1e --- install/wipe_data.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/install/wipe_data.cpp b/install/wipe_data.cpp index 2b78832c..2b3b8c8a 100644 --- a/install/wipe_data.cpp +++ b/install/wipe_data.cpp @@ -16,7 +16,10 @@ #include "install/wipe_data.h" +#include +#include #include +#include #include #include @@ -25,6 +28,7 @@ #include #include #include +#include #include "bootloader_message/bootloader_message.h" #include "install/snapshot_utils.h" @@ -50,6 +54,40 @@ static bool EraseVolume(const char* volume, RecoveryUI* ui, std::string_view new ui->Print("Formatting %s...\n", volume); Volume* vol = volume_for_mount_point(volume); + if (vol->fs_mgr_flags.logical) { + android::dm::DeviceMapper& dm = android::dm::DeviceMapper::Instance(); + + map_logical_partitions(); + // map_logical_partitions is non-blocking, so check for some limited time + // if it succeeded + for (int i = 0; i < 500; i++) { + if (vol->blk_device[0] == '/' || + dm.GetState(vol->blk_device) == android::dm::DmDeviceState::ACTIVE) + break; + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } + + if (vol->blk_device[0] != '/' && !dm.GetDmDevicePathByName(vol->blk_device, &vol->blk_device)) { + PLOG(ERROR) << "Failed to find dm device path for " << vol->blk_device; + return false; + } + + int fd = open(vol->blk_device.c_str(), O_RDWR); + if (fd < 0) { + PLOG(ERROR) << "Failed to open " << vol->blk_device; + return false; + } + + int val = 0; + if (ioctl(fd, BLKROSET, &val) != 0) { + PLOG(ERROR) << "Failed to set " << vol->blk_device << " rw"; + close(fd); + return false; + } + + close(fd); + } + if (ensure_volume_unmounted(vol->blk_device) == -1) { PLOG(ERROR) << "Failed to unmount volume!"; return false;