From 1b80a23c57cff27dc4c9e8a281fcfc4d5d35d778 Mon Sep 17 00:00:00 2001 From: Alessio Balsini Date: Mon, 29 Jul 2019 20:14:46 +0100 Subject: [PATCH] libdm: fetch and present device status flags Fetch detailed information for devices through its flags and store in helper Info class, i.e.: - active - access - activeTable - inactiveTable - bufferFull Change-Id: I3241c5bca00e038d19f99390f40710ca7cff8456 Bug: 137759376 Test: manual test Signed-off-by: Alessio Balsini --- fs_mgr/libdm/dm.cpp | 9 +++++++++ fs_mgr/libdm/include/libdm/dm.h | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/fs_mgr/libdm/dm.cpp b/fs_mgr/libdm/dm.cpp index 1d2683a54..a4e0d76ee 100644 --- a/fs_mgr/libdm/dm.cpp +++ b/fs_mgr/libdm/dm.cpp @@ -150,6 +150,15 @@ bool DeviceMapper::GetDeviceUniquePath(const std::string& name, std::string* pat return true; } +std::optional DeviceMapper::GetDetailedInfo(const std::string& name) const { + struct dm_ioctl io; + InitIo(&io, name); + if (ioctl(fd_, DM_DEV_STATUS, &io) < 0) { + return std::nullopt; + } + return Info(io.flags); +} + DmDeviceState DeviceMapper::GetState(const std::string& name) const { struct dm_ioctl io; InitIo(&io, name); diff --git a/fs_mgr/libdm/include/libdm/dm.h b/fs_mgr/libdm/include/libdm/dm.h index 753b8c97d..c6b37cfd6 100644 --- a/fs_mgr/libdm/include/libdm/dm.h +++ b/fs_mgr/libdm/include/libdm/dm.h @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -70,10 +71,27 @@ class DeviceMapper final { uint64_t dev_; }; + class Info { + uint32_t flags_; + + public: + explicit Info(uint32_t flags) : flags_(flags) {} + + bool IsActiveTablePresent() const { return flags_ & DM_ACTIVE_PRESENT_FLAG; } + bool IsBufferFull() const { return flags_ & DM_BUFFER_FULL_FLAG; } + bool IsInactiveTablePresent() const { return flags_ & DM_INACTIVE_PRESENT_FLAG; } + bool IsReadOnly() const { return flags_ & DM_READONLY_FLAG; } + bool IsSuspended() const { return flags_ & DM_SUSPEND_FLAG; } + }; + // Removes a device mapper device with the given name. // Returns 'true' on success, false otherwise. bool DeleteDevice(const std::string& name); + // Fetches and returns the complete state of the underlying device mapper + // device with given name. + std::optional GetDetailedInfo(const std::string& name) const; + // Returns the current state of the underlying device mapper device // with given name. // One of INVALID, SUSPENDED or ACTIVE.