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
This commit is contained in:
Tim Zimmermann 2021-06-08 16:14:55 +02:00 committed by zlewchan
parent 128d724d3b
commit 88a154d769

View file

@ -16,7 +16,10 @@
#include "install/wipe_data.h"
#include <fcntl.h>
#include <linux/fs.h>
#include <string.h>
#include <sys/ioctl.h>
#include <functional>
#include <vector>
@ -25,6 +28,7 @@
#include <android-base/logging.h>
#include <android-base/stringprintf.h>
#include <fs_mgr/roots.h>
#include <libdm/dm.h>
#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;