diff options
author | David Anderson <dvander@google.com> | 2019-02-25 17:31:56 -0800 |
---|---|---|
committer | David Anderson <dvander@google.com> | 2019-02-25 19:10:09 -0800 |
commit | 50ce7e090ae71d7c950e889cef342faab444c851 (patch) | |
tree | 690da372c2ebb9f86fae57b445bc89c7f61bbe4b /fs_mgr | |
parent | 82b54d2a5ebf16d0a9c07666d51ade4def2f3ddd (diff) | |
download | system_core-50ce7e090ae71d7c950e889cef342faab444c851.tar.gz system_core-50ce7e090ae71d7c950e889cef342faab444c851.tar.bz2 system_core-50ce7e090ae71d7c950e889cef342faab444c851.zip |
libfiemap_writer: Allow callers to query the block device of a file.
Bug: 126249541
Test: manual test
Change-Id: I478bcf60caf0cedc84189c39fee4b6c4f94b6ed6
Diffstat (limited to 'fs_mgr')
-rw-r--r-- | fs_mgr/libfiemap_writer/fiemap_writer.cpp | 9 | ||||
-rw-r--r-- | fs_mgr/libfiemap_writer/include/libfiemap_writer/fiemap_writer.h | 7 |
2 files changed, 14 insertions, 2 deletions
diff --git a/fs_mgr/libfiemap_writer/fiemap_writer.cpp b/fs_mgr/libfiemap_writer/fiemap_writer.cpp index b9b75f87e..fc24a173f 100644 --- a/fs_mgr/libfiemap_writer/fiemap_writer.cpp +++ b/fs_mgr/libfiemap_writer/fiemap_writer.cpp @@ -126,7 +126,8 @@ static bool DeviceMapperStackPop(const std::string& bdev, std::string* bdev_raw) return DeviceMapperStackPop(bdev_next, bdev_raw); } -static bool FileToBlockDevicePath(const std::string& file_path, std::string* bdev_path) { +bool FiemapWriter::GetBlockDeviceForFile(const std::string& file_path, std::string* bdev_path, + bool* uses_dm) { struct stat sb; if (stat(file_path.c_str(), &sb)) { PLOG(ERROR) << "Failed to get stat for: " << file_path; @@ -146,6 +147,10 @@ static bool FileToBlockDevicePath(const std::string& file_path, std::string* bde return false; } + if (uses_dm) { + *uses_dm = (bdev_raw != bdev); + } + LOG(DEBUG) << "Popped device (" << bdev_raw << ") from device mapper stack starting with (" << bdev << ")"; @@ -458,7 +463,7 @@ FiemapUniquePtr FiemapWriter::Open(const std::string& file_path, uint64_t file_s } std::string bdev_path; - if (!FileToBlockDevicePath(abs_path, &bdev_path)) { + if (!GetBlockDeviceForFile(abs_path, &bdev_path)) { LOG(ERROR) << "Failed to get block dev path for file: " << file_path; cleanup(abs_path, create); return nullptr; diff --git a/fs_mgr/libfiemap_writer/include/libfiemap_writer/fiemap_writer.h b/fs_mgr/libfiemap_writer/include/libfiemap_writer/fiemap_writer.h index edbae7721..b5472c9f7 100644 --- a/fs_mgr/libfiemap_writer/include/libfiemap_writer/fiemap_writer.h +++ b/fs_mgr/libfiemap_writer/include/libfiemap_writer/fiemap_writer.h @@ -57,6 +57,13 @@ class FiemapWriter final { // FiemapWriter::Open). static bool HasPinnedExtents(const std::string& file_path); + // Returns the underlying block device of a file. This will look past device-mapper layers. + // If an intermediate device-mapper layer would not maintain a 1:1 mapping (i.e. is a non- + // trivial dm-linear), then this will fail. If device-mapper nodes are encountered, then + // |uses_dm| will be set to true. + static bool GetBlockDeviceForFile(const std::string& file_path, std::string* bdev_path, + bool* uses_dm = nullptr); + // The counter part of Write(). It is an error for the offset to be unaligned with // the block device's block size. // In case of error, the contents of buffer MUST be discarded. |