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

Commit af5064d4 authored by David Anderson's avatar David Anderson Committed by android-build-merger
Browse files

Merge "fs_mgr: Add a method for creating one-off partition instances."

am: 67c5ca20

Change-Id: I5ce89869e60d29fc67bfb29c6e3bde9a1e9f7dd4
parents c67c7f9a 67c5ca20
Loading
Loading
Loading
Loading
+43 −11
Original line number Diff line number Diff line
@@ -79,6 +79,25 @@ static bool CreateDmTable(const std::string& block_device, const LpMetadata& met
    return true;
}

static bool CreateLogicalPartition(const std::string& block_device, const LpMetadata& metadata,
                                   const LpMetadataPartition& partition, std::string* path) {
    DeviceMapper& dm = DeviceMapper::Instance();

    DmTable table;
    if (!CreateDmTable(block_device, metadata, partition, &table)) {
        return false;
    }
    std::string name = GetPartitionName(partition);
    if (!dm.CreateDevice(name, table)) {
        return false;
    }
    if (!dm.GetDmDevicePathByName(name, path)) {
        return false;
    }
    LINFO << "Created logical partition " << name << " on device " << *path;
    return true;
}

bool CreateLogicalPartitions(const std::string& block_device) {
    uint32_t slot = SlotNumberForSlotSuffix(fs_mgr_get_slot_suffix());
    auto metadata = ReadMetadata(block_device.c_str(), slot);
@@ -86,23 +105,36 @@ bool CreateLogicalPartitions(const std::string& block_device) {
        LOG(ERROR) << "Could not read partition table.";
        return true;
    }

    DeviceMapper& dm = DeviceMapper::Instance();
    for (const auto& partition : metadata->partitions) {
        DmTable table;
        if (!CreateDmTable(block_device, *metadata.get(), partition, &table)) {
        std::string path;
        if (!CreateLogicalPartition(block_device, *metadata.get(), partition, &path)) {
            LERROR << "Could not create logical partition: " << GetPartitionName(partition);
            return false;
        }
        std::string name = GetPartitionName(partition);
        if (!dm.CreateDevice(name, table)) {
            return false;
    }
        std::string path;
        dm.GetDmDevicePathByName(partition.name, &path);
        LINFO << "Created logical partition " << name << " on device " << path;
    return true;
}

bool CreateLogicalPartition(const std::string& block_device, uint32_t metadata_slot,
                            const std::string& partition_name, std::string* path) {
    auto metadata = ReadMetadata(block_device.c_str(), metadata_slot);
    if (!metadata) {
        LOG(ERROR) << "Could not read partition table.";
        return true;
    }
    for (const auto& partition : metadata->partitions) {
        if (GetPartitionName(partition) == partition_name) {
            return CreateLogicalPartition(block_device, *metadata.get(), partition, path);
        }
    }
    LERROR << "Could not find any partition with name: " << partition_name;
    return false;
}

bool DestroyLogicalPartition(const std::string& name) {
    DeviceMapper& dm = DeviceMapper::Instance();
    return dm.DeleteDevice(name);
}

}  // namespace fs_mgr
}  // namespace android
+9 −0
Original line number Diff line number Diff line
@@ -39,6 +39,15 @@ namespace fs_mgr {

bool CreateLogicalPartitions(const std::string& block_device);

// Create a block device for a single logical partition, given metadata and
// the partition name. On success, a path to the partition's block device is
// returned.
bool CreateLogicalPartition(const std::string& block_device, uint32_t metadata_slot,
                            const std::string& partition_name, std::string* path);

// Destroy the block device for a logical partition, by name.
bool DestroyLogicalPartition(const std::string& name);

}  // namespace fs_mgr
}  // namespace android