Loading fs_mgr/libfiemap/binder.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ class ImageManagerBinder final : public IImageManager { bool RemoveAllImages() override; bool DisableImage(const std::string& name) override; bool RemoveDisabledImages() override; bool GetMappedImageDevice(const std::string& name, std::string* device) override; std::vector<std::string> GetAllBackingImages() override; Loading Loading @@ -180,6 +181,16 @@ bool ImageManagerBinder::RemoveDisabledImages() { return true; } bool ImageManagerBinder::GetMappedImageDevice(const std::string& name, std::string* device) { auto status = manager_->getMappedImageDevice(name, device); if (!status.isOk()) { LOG(ERROR) << __PRETTY_FUNCTION__ << " binder returned: " << status.exceptionMessage().string(); return false; } return !device->empty(); } static android::sp<IGsid> AcquireIGsid(const std::chrono::milliseconds& timeout_ms) { if (android::base::GetProperty("init.svc.gsid", "") != "running") { if (!android::base::SetProperty("ctl.start", "gsid") || Loading fs_mgr/libfiemap/image_manager.cpp +17 −1 Original line number Diff line number Diff line Loading @@ -648,11 +648,27 @@ bool ImageManager::RemoveDisabledImages() { bool ok = true; for (const auto& partition : metadata->partitions) { if (partition.attributes & LP_PARTITION_ATTR_DISABLED) { ok &= DeleteBackingImage(GetPartitionName(partition)); } } return ok; } bool ImageManager::GetMappedImageDevice(const std::string& name, std::string* device) { auto prop_name = GetStatusPropertyName(name); *device = android::base::GetProperty(prop_name, ""); if (!device->empty()) { return true; } auto& dm = DeviceMapper::Instance(); if (dm.GetState(name) == DmDeviceState::INVALID) { return false; } return dm.GetDmDevicePathByName(name, device); } std::unique_ptr<MappedDevice> MappedDevice::Open(IImageManager* manager, const std::chrono::milliseconds& timeout_ms, const std::string& name) { Loading fs_mgr/libfiemap/image_test.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -120,6 +120,17 @@ TEST_F(NativeTest, DisableImage) { ASSERT_TRUE(!manager_->BackingImageExists(base_name_)); } TEST_F(NativeTest, GetMappedImageDevice) { ASSERT_TRUE(manager_->CreateBackingImage(base_name_, kTestImageSize, false, nullptr)); std::string path1, path2; ASSERT_TRUE(manager_->MapImageDevice(base_name_, 5s, &path1)); ASSERT_TRUE(manager_->GetMappedImageDevice(base_name_, &path2)); EXPECT_EQ(path1, path2); ASSERT_TRUE(manager_->UnmapImageDevice(base_name_)); } // This fixture is for tests against a simulated device environment. Rather // than use /data, we create an image and then layer a new filesystem within // it. Each test then decides how to mount and create layered images. This Loading fs_mgr/libfiemap/include/libfiemap/image_manager.h +6 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,11 @@ class IImageManager { virtual bool MapImageWithDeviceMapper(const IPartitionOpener& opener, const std::string& name, std::string* dev) = 0; // If an image was mapped, return the path to its device. Otherwise, return // false. Errors are not reported in this case, calling IsImageMapped is // not necessary. virtual bool GetMappedImageDevice(const std::string& name, std::string* device) = 0; // Mark an image as disabled. This is useful for marking an image as // will-be-deleted in recovery, since recovery cannot mount /data. // Loading Loading @@ -131,6 +136,7 @@ class ImageManager final : public IImageManager { bool RemoveAllImages() override; bool DisableImage(const std::string& name) override; bool RemoveDisabledImages() override; bool GetMappedImageDevice(const std::string& name, std::string* device) override; std::vector<std::string> GetAllBackingImages(); // Same as CreateBackingImage, but provides a progress notification. Loading Loading
fs_mgr/libfiemap/binder.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ class ImageManagerBinder final : public IImageManager { bool RemoveAllImages() override; bool DisableImage(const std::string& name) override; bool RemoveDisabledImages() override; bool GetMappedImageDevice(const std::string& name, std::string* device) override; std::vector<std::string> GetAllBackingImages() override; Loading Loading @@ -180,6 +181,16 @@ bool ImageManagerBinder::RemoveDisabledImages() { return true; } bool ImageManagerBinder::GetMappedImageDevice(const std::string& name, std::string* device) { auto status = manager_->getMappedImageDevice(name, device); if (!status.isOk()) { LOG(ERROR) << __PRETTY_FUNCTION__ << " binder returned: " << status.exceptionMessage().string(); return false; } return !device->empty(); } static android::sp<IGsid> AcquireIGsid(const std::chrono::milliseconds& timeout_ms) { if (android::base::GetProperty("init.svc.gsid", "") != "running") { if (!android::base::SetProperty("ctl.start", "gsid") || Loading
fs_mgr/libfiemap/image_manager.cpp +17 −1 Original line number Diff line number Diff line Loading @@ -648,11 +648,27 @@ bool ImageManager::RemoveDisabledImages() { bool ok = true; for (const auto& partition : metadata->partitions) { if (partition.attributes & LP_PARTITION_ATTR_DISABLED) { ok &= DeleteBackingImage(GetPartitionName(partition)); } } return ok; } bool ImageManager::GetMappedImageDevice(const std::string& name, std::string* device) { auto prop_name = GetStatusPropertyName(name); *device = android::base::GetProperty(prop_name, ""); if (!device->empty()) { return true; } auto& dm = DeviceMapper::Instance(); if (dm.GetState(name) == DmDeviceState::INVALID) { return false; } return dm.GetDmDevicePathByName(name, device); } std::unique_ptr<MappedDevice> MappedDevice::Open(IImageManager* manager, const std::chrono::milliseconds& timeout_ms, const std::string& name) { Loading
fs_mgr/libfiemap/image_test.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -120,6 +120,17 @@ TEST_F(NativeTest, DisableImage) { ASSERT_TRUE(!manager_->BackingImageExists(base_name_)); } TEST_F(NativeTest, GetMappedImageDevice) { ASSERT_TRUE(manager_->CreateBackingImage(base_name_, kTestImageSize, false, nullptr)); std::string path1, path2; ASSERT_TRUE(manager_->MapImageDevice(base_name_, 5s, &path1)); ASSERT_TRUE(manager_->GetMappedImageDevice(base_name_, &path2)); EXPECT_EQ(path1, path2); ASSERT_TRUE(manager_->UnmapImageDevice(base_name_)); } // This fixture is for tests against a simulated device environment. Rather // than use /data, we create an image and then layer a new filesystem within // it. Each test then decides how to mount and create layered images. This Loading
fs_mgr/libfiemap/include/libfiemap/image_manager.h +6 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,11 @@ class IImageManager { virtual bool MapImageWithDeviceMapper(const IPartitionOpener& opener, const std::string& name, std::string* dev) = 0; // If an image was mapped, return the path to its device. Otherwise, return // false. Errors are not reported in this case, calling IsImageMapped is // not necessary. virtual bool GetMappedImageDevice(const std::string& name, std::string* device) = 0; // Mark an image as disabled. This is useful for marking an image as // will-be-deleted in recovery, since recovery cannot mount /data. // Loading Loading @@ -131,6 +136,7 @@ class ImageManager final : public IImageManager { bool RemoveAllImages() override; bool DisableImage(const std::string& name) override; bool RemoveDisabledImages() override; bool GetMappedImageDevice(const std::string& name, std::string* device) override; std::vector<std::string> GetAllBackingImages(); // Same as CreateBackingImage, but provides a progress notification. Loading