Merge "libfiemap_writer: Allow callers to query the block device of a file."
This commit is contained in:
commit
2c32a6cf24
2 changed files with 14 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue