diff options
| author | Tim Zimmermann <tim@linux4.de> | 2021-06-08 16:14:55 +0200 |
|---|---|---|
| committer | Michael Bestas <mkbestas@lineageos.org> | 2022-08-29 23:07:50 +0300 |
| commit | 241ef2cf6685f317efef8a4926a4e198fdcc5588 (patch) | |
| tree | e0f802de0c2e6586a8bc333d46448846ddd439e6 /install | |
| parent | 281b1188d1924e746cfb74071701ddec03ef4caf (diff) | |
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
Diffstat (limited to 'install')
| -rw-r--r-- | install/wipe_data.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/install/wipe_data.cpp b/install/wipe_data.cpp index 821a1e32..6b488a0e 100644 --- a/install/wipe_data.cpp +++ b/install/wipe_data.cpp @@ -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 "install/snapshot_utils.h" #include "otautil/dirutil.h" @@ -49,6 +53,40 @@ static bool EraseVolume(const char* volume, RecoveryUI* ui) { 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; |
