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
Merged-In: I3e3560f3cdef8978eac644d5b53cf3851209c0c2
Change-Id: Ic05cc84565952662178bb649ec97cad6f76dcf92
Ignore-AOSP-First: Already in AOSP.
Signed-off-by: Bart Van Assche <bvanassche@google.com>
This commit is contained in:
Bart Van Assche 2021-08-12 12:04:07 -07:00
parent 96b21cc589
commit 9e54a90e54
2 changed files with 5 additions and 1 deletions

View File

@ -560,7 +560,7 @@ std::string DeviceMapper::GetTargetType(const struct dm_target_spec& spec) {
return std::string{spec.target_type, sizeof(spec.target_type)};
}
static std::optional<std::string> ExtractBlockDeviceName(const std::string& path) {
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());

View File

@ -49,6 +49,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<std::string> ExtractBlockDeviceName(const std::string& path);
class DeviceMapper final {
public:
class DmBlockDevice final {