Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50ce7e09 authored by David Anderson's avatar David Anderson
Browse files

libfiemap_writer: Allow callers to query the block device of a file.

Bug: 126249541
Test: manual test
Change-Id: I478bcf60caf0cedc84189c39fee4b6c4f94b6ed6
parent 82b54d2a
Loading
Loading
Loading
Loading
+7 −2
Original line number Original line Diff line number Diff line
@@ -126,7 +126,8 @@ static bool DeviceMapperStackPop(const std::string& bdev, std::string* bdev_raw)
    return DeviceMapperStackPop(bdev_next, 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;
    struct stat sb;
    if (stat(file_path.c_str(), &sb)) {
    if (stat(file_path.c_str(), &sb)) {
        PLOG(ERROR) << "Failed to get stat for: " << file_path;
        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;
        return false;
    }
    }


    if (uses_dm) {
        *uses_dm = (bdev_raw != bdev);
    }

    LOG(DEBUG) << "Popped device (" << bdev_raw << ") from device mapper stack starting with ("
    LOG(DEBUG) << "Popped device (" << bdev_raw << ") from device mapper stack starting with ("
               << bdev << ")";
               << bdev << ")";


@@ -458,7 +463,7 @@ FiemapUniquePtr FiemapWriter::Open(const std::string& file_path, uint64_t file_s
    }
    }


    std::string bdev_path;
    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;
        LOG(ERROR) << "Failed to get block dev path for file: " << file_path;
        cleanup(abs_path, create);
        cleanup(abs_path, create);
        return nullptr;
        return nullptr;
+7 −0
Original line number Original line Diff line number Diff line
@@ -57,6 +57,13 @@ class FiemapWriter final {
    // FiemapWriter::Open).
    // FiemapWriter::Open).
    static bool HasPinnedExtents(const std::string& file_path);
    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 counter part of Write(). It is an error for the offset to be unaligned with
    // the block device's block size.
    // the block device's block size.
    // In case of error, the contents of buffer MUST be discarded.
    // In case of error, the contents of buffer MUST be discarded.