diff options
author | alk3pInjection <webmaster@raspii.tech> | 2023-04-20 00:08:54 +0800 |
---|---|---|
committer | alk3pInjection <webmaster@raspii.tech> | 2023-04-20 00:08:54 +0800 |
commit | a7dd355e8fe8ad0c579a4f0acd06b2e3b52dfc3a (patch) | |
tree | 2b552b59793a33466247fc6fb8cf89ecbfdc4a05 /fs_mgr/libdm/dm.cpp | |
parent | f0103ea35d56ccebbae16a43cac19ac38b11a9a2 (diff) | |
parent | 43816573a268998f892081eebf3ffe91d65b7e18 (diff) |
Merge tag 'LA.QSSI.13.0.r1-09800-qssi.0' into tachibanatachibana
"LA.QSSI.13.0.r1-09800-qssi.0"
Change-Id: I06ecf682f4d5595bce3383b6031506cc56bc0db2
Diffstat (limited to 'fs_mgr/libdm/dm.cpp')
-rw-r--r-- | fs_mgr/libdm/dm.cpp | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/fs_mgr/libdm/dm.cpp b/fs_mgr/libdm/dm.cpp index 4034e30ab..deffae1ad 100644 --- a/fs_mgr/libdm/dm.cpp +++ b/fs_mgr/libdm/dm.cpp @@ -20,6 +20,7 @@ #include <sys/ioctl.h> #include <sys/sysmacros.h> #include <sys/types.h> +#include <sys/utsname.h> #include <chrono> #include <functional> @@ -289,7 +290,7 @@ bool DeviceMapper::CreateDevice(const std::string& name, const DmTable& table) { return true; } -bool DeviceMapper::LoadTableAndActivate(const std::string& name, const DmTable& table) { +bool DeviceMapper::LoadTable(const std::string& name, const DmTable& table) { std::string ioctl_buffer(sizeof(struct dm_ioctl), 0); ioctl_buffer += table.Serialize(); @@ -305,9 +306,17 @@ bool DeviceMapper::LoadTableAndActivate(const std::string& name, const DmTable& PLOG(ERROR) << "DM_TABLE_LOAD failed"; return false; } + return true; +} - InitIo(io, name); - if (ioctl(fd_, DM_DEV_SUSPEND, io)) { +bool DeviceMapper::LoadTableAndActivate(const std::string& name, const DmTable& table) { + if (!LoadTable(name, table)) { + return false; + } + + struct dm_ioctl io; + InitIo(&io, name); + if (ioctl(fd_, DM_DEV_SUSPEND, &io)) { PLOG(ERROR) << "DM_TABLE_SUSPEND resume failed"; return false; } @@ -703,5 +712,28 @@ std::map<std::string, std::string> DeviceMapper::FindDmPartitions() { return dm_block_devices; } +bool DeviceMapper::CreatePlaceholderDevice(const std::string& name) { + if (!CreateEmptyDevice(name)) { + return false; + } + + struct utsname uts; + unsigned int major, minor; + if (uname(&uts) != 0 || sscanf(uts.release, "%u.%u", &major, &minor) != 2) { + LOG(ERROR) << "Could not parse the kernel version from uname"; + return true; + } + + // On Linux 5.15+, there is no uevent until DM_TABLE_LOAD. + if (major > 5 || (major == 5 && minor >= 15)) { + DmTable table; + table.Emplace<DmTargetError>(0, 1); + if (!LoadTable(name, table)) { + return false; + } + } + return true; +} + } // namespace dm } // namespace android |