Loading fs_mgr/liblp/Android.bp +5 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,11 @@ cc_library { windows: { enabled: true, }, android: { shared_libs: [ "libcutils", ], }, }, export_include_dirs: ["include"], } Loading fs_mgr/liblp/images.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ std::unique_ptr<LpMetadata> ReadFromImageBlob(const void* data, size_t bytes) { } std::unique_ptr<LpMetadata> ReadFromImageFile(const std::string& image_file) { unique_fd fd(open(image_file.c_str(), O_RDONLY | O_CLOEXEC)); unique_fd fd = GetControlFileOrOpen(image_file.c_str(), O_RDONLY | O_CLOEXEC); if (fd < 0) { PERROR << __PRETTY_FUNCTION__ << " open failed: " << image_file; return nullptr; Loading Loading @@ -408,7 +408,7 @@ bool SparseBuilder::CheckExtentOrdering() { } int SparseBuilder::OpenImageFile(const std::string& file) { android::base::unique_fd source_fd(open(file.c_str(), O_RDONLY | O_CLOEXEC)); android::base::unique_fd source_fd = GetControlFileOrOpen(file.c_str(), O_RDONLY | O_CLOEXEC); if (source_fd < 0) { PERROR << "open image file failed: " << file; return -1; Loading fs_mgr/liblp/partition_opener.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -45,7 +45,7 @@ std::string GetPartitionAbsolutePath(const std::string& path) { bool GetBlockDeviceInfo(const std::string& block_device, BlockDeviceInfo* device_info) { #if defined(__linux__) unique_fd fd(open(block_device.c_str(), O_RDONLY)); unique_fd fd = GetControlFileOrOpen(block_device.c_str(), O_RDONLY); if (fd < 0) { PERROR << __PRETTY_FUNCTION__ << "open '" << block_device << "' failed"; return false; Loading Loading @@ -85,7 +85,7 @@ bool GetBlockDeviceInfo(const std::string& block_device, BlockDeviceInfo* device unique_fd PartitionOpener::Open(const std::string& partition_name, int flags) const { std::string path = GetPartitionAbsolutePath(partition_name); return unique_fd{open(path.c_str(), flags | O_CLOEXEC)}; return GetControlFileOrOpen(path.c_str(), flags | O_CLOEXEC); } bool PartitionOpener::GetInfo(const std::string& partition_name, BlockDeviceInfo* info) const { Loading fs_mgr/liblp/utility.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,10 @@ #include <ext4_utils/ext4_utils.h> #include <openssl/sha.h> #ifdef __ANDROID__ #include <cutils/android_get_control_file.h> #endif #include "utility.h" namespace android { Loading Loading @@ -171,5 +175,19 @@ bool SetBlockReadonly(int fd, bool readonly) { #endif } base::unique_fd GetControlFileOrOpen(const char* path, int flags) { #if defined(__ANDROID__) int fd = android_get_control_file(path); if (fd >= 0) { int newfd = TEMP_FAILURE_RETRY(dup(fd)); if (newfd >= 0) { return base::unique_fd(newfd); } PERROR << "Cannot dup fd for already controlled file: " << path << ", reopening..."; } #endif return base::unique_fd(open(path, flags)); } } // namespace fs_mgr } // namespace android fs_mgr/liblp/utility.h +3 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <sys/types.h> #include <android-base/logging.h> #include <android-base/unique_fd.h> #include "liblp/liblp.h" Loading Loading @@ -92,6 +93,8 @@ bool UpdatePartitionGroupName(LpMetadataPartitionGroup* group, const std::string // Call BLKROSET ioctl on fd so that fd is readonly / read-writable. bool SetBlockReadonly(int fd, bool readonly); ::android::base::unique_fd GetControlFileOrOpen(const char* path, int flags); } // namespace fs_mgr } // namespace android Loading Loading
fs_mgr/liblp/Android.bp +5 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,11 @@ cc_library { windows: { enabled: true, }, android: { shared_libs: [ "libcutils", ], }, }, export_include_dirs: ["include"], } Loading
fs_mgr/liblp/images.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ std::unique_ptr<LpMetadata> ReadFromImageBlob(const void* data, size_t bytes) { } std::unique_ptr<LpMetadata> ReadFromImageFile(const std::string& image_file) { unique_fd fd(open(image_file.c_str(), O_RDONLY | O_CLOEXEC)); unique_fd fd = GetControlFileOrOpen(image_file.c_str(), O_RDONLY | O_CLOEXEC); if (fd < 0) { PERROR << __PRETTY_FUNCTION__ << " open failed: " << image_file; return nullptr; Loading Loading @@ -408,7 +408,7 @@ bool SparseBuilder::CheckExtentOrdering() { } int SparseBuilder::OpenImageFile(const std::string& file) { android::base::unique_fd source_fd(open(file.c_str(), O_RDONLY | O_CLOEXEC)); android::base::unique_fd source_fd = GetControlFileOrOpen(file.c_str(), O_RDONLY | O_CLOEXEC); if (source_fd < 0) { PERROR << "open image file failed: " << file; return -1; Loading
fs_mgr/liblp/partition_opener.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -45,7 +45,7 @@ std::string GetPartitionAbsolutePath(const std::string& path) { bool GetBlockDeviceInfo(const std::string& block_device, BlockDeviceInfo* device_info) { #if defined(__linux__) unique_fd fd(open(block_device.c_str(), O_RDONLY)); unique_fd fd = GetControlFileOrOpen(block_device.c_str(), O_RDONLY); if (fd < 0) { PERROR << __PRETTY_FUNCTION__ << "open '" << block_device << "' failed"; return false; Loading Loading @@ -85,7 +85,7 @@ bool GetBlockDeviceInfo(const std::string& block_device, BlockDeviceInfo* device unique_fd PartitionOpener::Open(const std::string& partition_name, int flags) const { std::string path = GetPartitionAbsolutePath(partition_name); return unique_fd{open(path.c_str(), flags | O_CLOEXEC)}; return GetControlFileOrOpen(path.c_str(), flags | O_CLOEXEC); } bool PartitionOpener::GetInfo(const std::string& partition_name, BlockDeviceInfo* info) const { Loading
fs_mgr/liblp/utility.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,10 @@ #include <ext4_utils/ext4_utils.h> #include <openssl/sha.h> #ifdef __ANDROID__ #include <cutils/android_get_control_file.h> #endif #include "utility.h" namespace android { Loading Loading @@ -171,5 +175,19 @@ bool SetBlockReadonly(int fd, bool readonly) { #endif } base::unique_fd GetControlFileOrOpen(const char* path, int flags) { #if defined(__ANDROID__) int fd = android_get_control_file(path); if (fd >= 0) { int newfd = TEMP_FAILURE_RETRY(dup(fd)); if (newfd >= 0) { return base::unique_fd(newfd); } PERROR << "Cannot dup fd for already controlled file: " << path << ", reopening..."; } #endif return base::unique_fd(open(path, flags)); } } // namespace fs_mgr } // namespace android
fs_mgr/liblp/utility.h +3 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <sys/types.h> #include <android-base/logging.h> #include <android-base/unique_fd.h> #include "liblp/liblp.h" Loading Loading @@ -92,6 +93,8 @@ bool UpdatePartitionGroupName(LpMetadataPartitionGroup* group, const std::string // Call BLKROSET ioctl on fd so that fd is readonly / read-writable. bool SetBlockReadonly(int fd, bool readonly); ::android::base::unique_fd GetControlFileOrOpen(const char* path, int flags); } // namespace fs_mgr } // namespace android Loading