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

Commit c4073d3e authored by Yifan Hong's avatar Yifan Hong
Browse files

fastbootd: add read arg to OpenPartition

Allow it to read partitions.

Bug: 173654501
Test: pass

Change-Id: I115e84734dd258243ca3f4f1b373b06adcaa4080
parent a4eb4753
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -77,7 +77,8 @@ bool OpenLogicalPartition(FastbootDevice* device, const std::string& partition_n

}  // namespace

bool OpenPartition(FastbootDevice* device, const std::string& name, PartitionHandle* handle) {
bool OpenPartition(FastbootDevice* device, const std::string& name, PartitionHandle* handle,
                   bool read) {
    // We prioritize logical partitions over physical ones, and do this
    // consistently for other partition operations (like getvar:partition-size).
    if (LogicalPartitionExists(device, name)) {
@@ -89,7 +90,8 @@ bool OpenPartition(FastbootDevice* device, const std::string& name, PartitionHan
        return false;
    }

    unique_fd fd(TEMP_FAILURE_RETRY(open(handle->path().c_str(), O_WRONLY | O_EXCL)));
    int flags = O_EXCL | (read ? O_RDONLY : O_WRONLY);
    unique_fd fd(TEMP_FAILURE_RETRY(open(handle->path().c_str(), flags)));
    if (fd < 0) {
        PLOG(ERROR) << "Failed to open block device: " << handle->path();
        return false;
+5 −1
Original line number Diff line number Diff line
@@ -75,7 +75,11 @@ std::string GetSuperSlotSuffix(FastbootDevice* device, const std::string& partit
std::optional<std::string> FindPhysicalPartition(const std::string& name);
bool LogicalPartitionExists(FastbootDevice* device, const std::string& name,
                            bool* is_zero_length = nullptr);
bool OpenPartition(FastbootDevice* device, const std::string& name, PartitionHandle* handle);

// If read, partition is readonly. Else it is write only.
bool OpenPartition(FastbootDevice* device, const std::string& name, PartitionHandle* handle,
                   bool read = false);

bool GetSlotNumber(const std::string& slot, android::hardware::boot::V1_0::Slot* number);
std::vector<std::string> ListPartitions(FastbootDevice* device);
bool GetDeviceLockStatus();