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;