From c24f7b8224aeb51ff490ea7514af7e13249ae7dc Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Thu, 12 Aug 2021 12:04:07 -0700 Subject: [PATCH] libdm: Export ExtractBlockDeviceName() Make this function available to libdm users. A caller outside libdm will be added by a later patch. Bug: 194450129 Test: mm libfs_mgr libdm_test Change-Id: I3e3560f3cdef8978eac644d5b53cf3851209c0c2 Signed-off-by: Bart Van Assche --- fs_mgr/libdm/dm.cpp | 2 +- fs_mgr/libdm/include/libdm/dm.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/fs_mgr/libdm/dm.cpp b/fs_mgr/libdm/dm.cpp index 6245795e5..4034e30ab 100644 --- a/fs_mgr/libdm/dm.cpp +++ b/fs_mgr/libdm/dm.cpp @@ -578,7 +578,7 @@ std::string DeviceMapper::GetTargetType(const struct dm_target_spec& spec) { return std::string{spec.target_type, sizeof(spec.target_type)}; } -static std::optional ExtractBlockDeviceName(const std::string& path) { +std::optional ExtractBlockDeviceName(const std::string& path) { static constexpr std::string_view kDevBlockPrefix("/dev/block/"); if (android::base::StartsWith(path, kDevBlockPrefix)) { return path.substr(kDevBlockPrefix.length()); diff --git a/fs_mgr/libdm/include/libdm/dm.h b/fs_mgr/libdm/include/libdm/dm.h index 31c300326..7e01b859e 100644 --- a/fs_mgr/libdm/include/libdm/dm.h +++ b/fs_mgr/libdm/include/libdm/dm.h @@ -51,6 +51,10 @@ 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. +std::optional ExtractBlockDeviceName(const std::string& path); + class DeviceMapper final { public: class DmBlockDevice final {