Loading fs_mgr/libdm/dm.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -388,5 +388,13 @@ void DeviceMapper::InitIo(struct dm_ioctl* io, const std::string& name) const { } } std::string DeviceMapper::GetTargetType(const struct dm_target_spec& spec) { if (const void* p = memchr(spec.target_type, '\0', sizeof(spec.target_type))) { ptrdiff_t length = reinterpret_cast<const char*>(p) - spec.target_type; return std::string{spec.target_type, static_cast<size_t>(length)}; } return std::string{spec.target_type, sizeof(spec.target_type)}; } } // namespace dm } // namespace android fs_mgr/libdm/dm_test.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -179,6 +179,10 @@ TEST(libdm, DmLinear) { EXPECT_EQ(targets[1].spec.sector_start, 1); EXPECT_EQ(targets[1].spec.length, 1); // Test GetTargetType(). EXPECT_EQ(DeviceMapper::GetTargetType(targets[0].spec), std::string{"linear"}); EXPECT_EQ(DeviceMapper::GetTargetType(targets[1].spec), std::string{"linear"}); // Normally the TestDevice destructor would delete this, but at least one // test should ensure that device deletion works. ASSERT_TRUE(dev.Destroy()); Loading fs_mgr/libdm/include/libdm/dm.h +2 −0 Original line number Diff line number Diff line Loading @@ -144,6 +144,8 @@ class DeviceMapper final { // mapper device from the kernel. bool GetTableInfo(const std::string& name, std::vector<TargetInfo>* table); static std::string GetTargetType(const struct dm_target_spec& spec); private: // Maximum possible device mapper targets registered in the kernel. // This is only used to read the list of targets from kernel so we allocate Loading fs_mgr/libfiemap_writer/fiemap_writer.cpp +26 −9 Original line number Diff line number Diff line Loading @@ -89,6 +89,31 @@ static bool BlockDeviceToName(uint32_t major, uint32_t minor, std::string* bdev_ return true; } static bool ValidateDmTarget(const DeviceMapper::TargetInfo& target) { const auto& entry = target.spec; if (entry.sector_start != 0) { LOG(INFO) << "Stopping at target with non-zero starting sector"; return false; } auto target_type = DeviceMapper::GetTargetType(entry); if (target_type == "bow" || target_type == "default-key" || target_type == "crypt") { return true; } if (target_type == "linear") { auto pieces = android::base::Split(target.data, " "); if (pieces[1] != "0") { LOG(INFO) << "Stopping at complex linear target with non-zero starting sector: " << pieces[1]; return false; } return true; } LOG(INFO) << "Stopping at complex target type " << target_type; return false; } static bool DeviceMapperStackPop(const std::string& bdev, std::string* bdev_raw) { *bdev_raw = bdev; Loading Loading @@ -128,15 +153,7 @@ static bool DeviceMapperStackPop(const std::string& bdev, std::string* bdev_raw) LOG(INFO) << "Stopping at complex table for " << dm_name << " at " << bdev; return true; } const auto& entry = table[0].spec; std::string target_type(std::string(entry.target_type, sizeof(entry.target_type)).c_str()); if (target_type != "bow" && target_type != "default-key" && target_type != "crypt") { LOG(INFO) << "Stopping at complex target-type " << target_type << " for " << dm_name << " at " << bdev; return true; } if (entry.sector_start != 0) { LOG(INFO) << "Stopping at target-type with non-zero starting sector"; if (!ValidateDmTarget(table[0])) { return true; } Loading Loading
fs_mgr/libdm/dm.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -388,5 +388,13 @@ void DeviceMapper::InitIo(struct dm_ioctl* io, const std::string& name) const { } } std::string DeviceMapper::GetTargetType(const struct dm_target_spec& spec) { if (const void* p = memchr(spec.target_type, '\0', sizeof(spec.target_type))) { ptrdiff_t length = reinterpret_cast<const char*>(p) - spec.target_type; return std::string{spec.target_type, static_cast<size_t>(length)}; } return std::string{spec.target_type, sizeof(spec.target_type)}; } } // namespace dm } // namespace android
fs_mgr/libdm/dm_test.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -179,6 +179,10 @@ TEST(libdm, DmLinear) { EXPECT_EQ(targets[1].spec.sector_start, 1); EXPECT_EQ(targets[1].spec.length, 1); // Test GetTargetType(). EXPECT_EQ(DeviceMapper::GetTargetType(targets[0].spec), std::string{"linear"}); EXPECT_EQ(DeviceMapper::GetTargetType(targets[1].spec), std::string{"linear"}); // Normally the TestDevice destructor would delete this, but at least one // test should ensure that device deletion works. ASSERT_TRUE(dev.Destroy()); Loading
fs_mgr/libdm/include/libdm/dm.h +2 −0 Original line number Diff line number Diff line Loading @@ -144,6 +144,8 @@ class DeviceMapper final { // mapper device from the kernel. bool GetTableInfo(const std::string& name, std::vector<TargetInfo>* table); static std::string GetTargetType(const struct dm_target_spec& spec); private: // Maximum possible device mapper targets registered in the kernel. // This is only used to read the list of targets from kernel so we allocate Loading
fs_mgr/libfiemap_writer/fiemap_writer.cpp +26 −9 Original line number Diff line number Diff line Loading @@ -89,6 +89,31 @@ static bool BlockDeviceToName(uint32_t major, uint32_t minor, std::string* bdev_ return true; } static bool ValidateDmTarget(const DeviceMapper::TargetInfo& target) { const auto& entry = target.spec; if (entry.sector_start != 0) { LOG(INFO) << "Stopping at target with non-zero starting sector"; return false; } auto target_type = DeviceMapper::GetTargetType(entry); if (target_type == "bow" || target_type == "default-key" || target_type == "crypt") { return true; } if (target_type == "linear") { auto pieces = android::base::Split(target.data, " "); if (pieces[1] != "0") { LOG(INFO) << "Stopping at complex linear target with non-zero starting sector: " << pieces[1]; return false; } return true; } LOG(INFO) << "Stopping at complex target type " << target_type; return false; } static bool DeviceMapperStackPop(const std::string& bdev, std::string* bdev_raw) { *bdev_raw = bdev; Loading Loading @@ -128,15 +153,7 @@ static bool DeviceMapperStackPop(const std::string& bdev, std::string* bdev_raw) LOG(INFO) << "Stopping at complex table for " << dm_name << " at " << bdev; return true; } const auto& entry = table[0].spec; std::string target_type(std::string(entry.target_type, sizeof(entry.target_type)).c_str()); if (target_type != "bow" && target_type != "default-key" && target_type != "crypt") { LOG(INFO) << "Stopping at complex target-type " << target_type << " for " << dm_name << " at " << bdev; return true; } if (entry.sector_start != 0) { LOG(INFO) << "Stopping at target-type with non-zero starting sector"; if (!ValidateDmTarget(table[0])) { return true; } Loading