Loading fs_mgr/fs_mgr.cpp +40 −0 Original line number Diff line number Diff line Loading @@ -1268,6 +1268,46 @@ int fs_mgr_mount_all(Fstab* fstab, int mount_mode) { } } int fs_mgr_umount_all(android::fs_mgr::Fstab* fstab) { AvbUniquePtr avb_handle(nullptr); int ret = FsMgrUmountStatus::SUCCESS; for (auto& current_entry : *fstab) { if (!IsMountPointMounted(current_entry.mount_point)) { continue; } if (umount(current_entry.mount_point.c_str()) == -1) { PERROR << "Failed to umount " << current_entry.mount_point; ret |= FsMgrUmountStatus::ERROR_UMOUNT; continue; } if (current_entry.fs_mgr_flags.logical) { if (!fs_mgr_update_logical_partition(¤t_entry)) { LERROR << "Could not get logical partition blk_device, skipping!"; ret |= FsMgrUmountStatus::ERROR_DEVICE_MAPPER; continue; } } if (current_entry.fs_mgr_flags.avb || !current_entry.avb_keys.empty()) { if (!AvbHandle::TearDownAvbHashtree(¤t_entry, true /* wait */)) { LERROR << "Failed to tear down AVB on mount point: " << current_entry.mount_point; ret |= FsMgrUmountStatus::ERROR_VERITY; continue; } } else if ((current_entry.fs_mgr_flags.verify)) { if (!fs_mgr_teardown_verity(¤t_entry, true /* wait */)) { LERROR << "Failed to tear down verified partition on mount point: " << current_entry.mount_point; ret |= FsMgrUmountStatus::ERROR_VERITY; continue; } } } return ret; } // wrapper to __mount() and expects a fully prepared fstab_rec, // unlike fs_mgr_do_mount which does more things with avb / verity etc. int fs_mgr_do_mount_one(const FstabEntry& entry, const std::string& mount_point) { Loading fs_mgr/fs_mgr_dm_linear.cpp +8 −1 Original line number Diff line number Diff line Loading @@ -193,7 +193,7 @@ bool CreateLogicalPartition(const std::string& block_device, uint32_t metadata_s timeout_ms, path); } bool DestroyLogicalPartition(const std::string& name, const std::chrono::milliseconds& timeout_ms) { bool UnmapDevice(const std::string& name, const std::chrono::milliseconds& timeout_ms) { DeviceMapper& dm = DeviceMapper::Instance(); std::string path; if (timeout_ms > std::chrono::milliseconds::zero()) { Loading @@ -206,6 +206,13 @@ bool DestroyLogicalPartition(const std::string& name, const std::chrono::millise LERROR << "Timed out waiting for device path to unlink: " << path; return false; } return true; } bool DestroyLogicalPartition(const std::string& name, const std::chrono::milliseconds& timeout_ms) { if (!UnmapDevice(name, timeout_ms)) { return false; } LINFO << "Unmapped logical partition " << name; return true; } Loading fs_mgr/fs_mgr_priv.h +8 −0 Original line number Diff line number Diff line Loading @@ -103,3 +103,11 @@ int load_verity_state(const android::fs_mgr::FstabEntry& entry, int* mode); bool fs_mgr_is_ext4(const std::string& blk_device); bool fs_mgr_is_f2fs(const std::string& blk_device); bool fs_mgr_teardown_verity(android::fs_mgr::FstabEntry* fstab, bool wait); namespace android { namespace fs_mgr { bool UnmapDevice(const std::string& name, const std::chrono::milliseconds& timeout_ms); } // namespace fs_mgr } // namespace android fs_mgr/fs_mgr_verity.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ #include "fec/io.h" #include "fs_mgr.h" #include "fs_mgr_dm_linear.h" #include "fs_mgr_priv.h" // Realistically, this file should be part of the android::fs_mgr namespace; Loading Loading @@ -882,3 +883,12 @@ out: return retval; } bool fs_mgr_teardown_verity(FstabEntry* entry, bool wait) { const std::string mount_point(basename(entry->mount_point.c_str())); if (!android::fs_mgr::UnmapDevice(mount_point, wait ? 1000ms : 0ms)) { return false; } LINFO << "Unmapped verity device " << mount_point; return true; } fs_mgr/include/fs_mgr.h +11 −0 Original line number Diff line number Diff line Loading @@ -93,3 +93,14 @@ int fs_mgr_setup_verity(android::fs_mgr::FstabEntry* fstab, bool wait_for_verity // specified, the super partition for the corresponding metadata slot will be // returned. Otherwise, it will use the current slot. std::string fs_mgr_get_super_partition_name(int slot = -1); enum FsMgrUmountStatus : int { SUCCESS = 0, ERROR_UNKNOWN = 1 << 0, ERROR_UMOUNT = 1 << 1, ERROR_VERITY = 1 << 2, ERROR_DEVICE_MAPPER = 1 << 3, }; // fs_mgr_umount_all() is the reverse of fs_mgr_mount_all. In particular, // it destroys verity devices from device mapper after the device is unmounted. int fs_mgr_umount_all(android::fs_mgr::Fstab* fstab); Loading
fs_mgr/fs_mgr.cpp +40 −0 Original line number Diff line number Diff line Loading @@ -1268,6 +1268,46 @@ int fs_mgr_mount_all(Fstab* fstab, int mount_mode) { } } int fs_mgr_umount_all(android::fs_mgr::Fstab* fstab) { AvbUniquePtr avb_handle(nullptr); int ret = FsMgrUmountStatus::SUCCESS; for (auto& current_entry : *fstab) { if (!IsMountPointMounted(current_entry.mount_point)) { continue; } if (umount(current_entry.mount_point.c_str()) == -1) { PERROR << "Failed to umount " << current_entry.mount_point; ret |= FsMgrUmountStatus::ERROR_UMOUNT; continue; } if (current_entry.fs_mgr_flags.logical) { if (!fs_mgr_update_logical_partition(¤t_entry)) { LERROR << "Could not get logical partition blk_device, skipping!"; ret |= FsMgrUmountStatus::ERROR_DEVICE_MAPPER; continue; } } if (current_entry.fs_mgr_flags.avb || !current_entry.avb_keys.empty()) { if (!AvbHandle::TearDownAvbHashtree(¤t_entry, true /* wait */)) { LERROR << "Failed to tear down AVB on mount point: " << current_entry.mount_point; ret |= FsMgrUmountStatus::ERROR_VERITY; continue; } } else if ((current_entry.fs_mgr_flags.verify)) { if (!fs_mgr_teardown_verity(¤t_entry, true /* wait */)) { LERROR << "Failed to tear down verified partition on mount point: " << current_entry.mount_point; ret |= FsMgrUmountStatus::ERROR_VERITY; continue; } } } return ret; } // wrapper to __mount() and expects a fully prepared fstab_rec, // unlike fs_mgr_do_mount which does more things with avb / verity etc. int fs_mgr_do_mount_one(const FstabEntry& entry, const std::string& mount_point) { Loading
fs_mgr/fs_mgr_dm_linear.cpp +8 −1 Original line number Diff line number Diff line Loading @@ -193,7 +193,7 @@ bool CreateLogicalPartition(const std::string& block_device, uint32_t metadata_s timeout_ms, path); } bool DestroyLogicalPartition(const std::string& name, const std::chrono::milliseconds& timeout_ms) { bool UnmapDevice(const std::string& name, const std::chrono::milliseconds& timeout_ms) { DeviceMapper& dm = DeviceMapper::Instance(); std::string path; if (timeout_ms > std::chrono::milliseconds::zero()) { Loading @@ -206,6 +206,13 @@ bool DestroyLogicalPartition(const std::string& name, const std::chrono::millise LERROR << "Timed out waiting for device path to unlink: " << path; return false; } return true; } bool DestroyLogicalPartition(const std::string& name, const std::chrono::milliseconds& timeout_ms) { if (!UnmapDevice(name, timeout_ms)) { return false; } LINFO << "Unmapped logical partition " << name; return true; } Loading
fs_mgr/fs_mgr_priv.h +8 −0 Original line number Diff line number Diff line Loading @@ -103,3 +103,11 @@ int load_verity_state(const android::fs_mgr::FstabEntry& entry, int* mode); bool fs_mgr_is_ext4(const std::string& blk_device); bool fs_mgr_is_f2fs(const std::string& blk_device); bool fs_mgr_teardown_verity(android::fs_mgr::FstabEntry* fstab, bool wait); namespace android { namespace fs_mgr { bool UnmapDevice(const std::string& name, const std::chrono::milliseconds& timeout_ms); } // namespace fs_mgr } // namespace android
fs_mgr/fs_mgr_verity.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ #include "fec/io.h" #include "fs_mgr.h" #include "fs_mgr_dm_linear.h" #include "fs_mgr_priv.h" // Realistically, this file should be part of the android::fs_mgr namespace; Loading Loading @@ -882,3 +883,12 @@ out: return retval; } bool fs_mgr_teardown_verity(FstabEntry* entry, bool wait) { const std::string mount_point(basename(entry->mount_point.c_str())); if (!android::fs_mgr::UnmapDevice(mount_point, wait ? 1000ms : 0ms)) { return false; } LINFO << "Unmapped verity device " << mount_point; return true; }
fs_mgr/include/fs_mgr.h +11 −0 Original line number Diff line number Diff line Loading @@ -93,3 +93,14 @@ int fs_mgr_setup_verity(android::fs_mgr::FstabEntry* fstab, bool wait_for_verity // specified, the super partition for the corresponding metadata slot will be // returned. Otherwise, it will use the current slot. std::string fs_mgr_get_super_partition_name(int slot = -1); enum FsMgrUmountStatus : int { SUCCESS = 0, ERROR_UNKNOWN = 1 << 0, ERROR_UMOUNT = 1 << 1, ERROR_VERITY = 1 << 2, ERROR_DEVICE_MAPPER = 1 << 3, }; // fs_mgr_umount_all() is the reverse of fs_mgr_mount_all. In particular, // it destroys verity devices from device mapper after the device is unmounted. int fs_mgr_umount_all(android::fs_mgr::Fstab* fstab);