Use target device mapper given mapper target

Let's translate /dev/block/mapper for dm libs.

Bug: 311084775
Change-Id: I23666c5590a15652192e004e1990edd73b7a8df8
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
This commit is contained in:
Jaegeuk Kim 2023-11-15 08:34:20 -08:00
parent 8fbaaa33a1
commit a720fe785c
2 changed files with 8 additions and 4 deletions

View file

@ -612,8 +612,12 @@ std::string DeviceMapper::GetTargetType(const struct dm_target_spec& spec) {
std::optional<std::string> ExtractBlockDeviceName(const std::string& path) {
static constexpr std::string_view kDevBlockPrefix("/dev/block/");
if (android::base::StartsWith(path, kDevBlockPrefix)) {
return path.substr(kDevBlockPrefix.length());
std::string real_path;
if (!android::base::Realpath(path, &real_path)) {
real_path = path;
}
if (android::base::StartsWith(real_path, kDevBlockPrefix)) {
return real_path.substr(kDevBlockPrefix.length());
}
return {};
}

View file

@ -52,8 +52,8 @@ enum class DmDeviceState { INVALID, SUSPENDED, ACTIVE };
static constexpr uint64_t kSectorSize = 512;
// Returns `path` without /dev/block prefix if and only if `path` starts with
// that prefix.
// Returns `path` without /dev/block prefix if `path` starts with that prefix.
// Or, if `path` is a symlink, do the same with its real path.
std::optional<std::string> ExtractBlockDeviceName(const std::string& path);
// This interface is for testing purposes. See DeviceMapper proper for what these methods do.