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

Commit 908f07b0 authored by David Anderson's avatar David Anderson
Browse files

fs_mgr: Add a helper for creating one-off dynamic partitions.

This will be used by gsid to invoke mkfs.ext4 on the userdata_gsi
partition. Since the extents are not located on the super partition, we
need a helper method that takes in an LpMetadata.

Bug: 121210348
Test: manual test
Change-Id: I00467ace8a745fb0c0d130babfda1a2d5d97c208
parent 126e4819
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -168,17 +168,12 @@ bool CreateLogicalPartitions(const LpMetadata& metadata, const std::string& supe
    return true;
}

bool CreateLogicalPartition(const std::string& block_device, uint32_t metadata_slot,
bool CreateLogicalPartition(const std::string& block_device, const LpMetadata& metadata,
                            const std::string& partition_name, bool force_writable,
                            const std::chrono::milliseconds& timeout_ms, 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) {
    for (const auto& partition : metadata.partitions) {
        if (GetPartitionName(partition) == partition_name) {
            return CreateLogicalPartition(*metadata.get(), partition, force_writable, timeout_ms,
            return CreateLogicalPartition(metadata, partition, force_writable, timeout_ms,
                                          block_device, path);
        }
    }
@@ -186,6 +181,18 @@ bool CreateLogicalPartition(const std::string& block_device, uint32_t metadata_s
    return false;
}

bool CreateLogicalPartition(const std::string& block_device, uint32_t metadata_slot,
                            const std::string& partition_name, bool force_writable,
                            const std::chrono::milliseconds& timeout_ms, std::string* path) {
    auto metadata = ReadMetadata(block_device.c_str(), metadata_slot);
    if (!metadata) {
        LOG(ERROR) << "Could not read partition table.";
        return true;
    }
    return CreateLogicalPartition(block_device, *metadata.get(), partition_name, force_writable,
                                  timeout_ms, path);
}

bool DestroyLogicalPartition(const std::string& name, const std::chrono::milliseconds& timeout_ms) {
    DeviceMapper& dm = DeviceMapper::Instance();
    std::string path;
+6 −0
Original line number Diff line number Diff line
@@ -60,6 +60,12 @@ bool CreateLogicalPartition(const std::string& block_device, uint32_t metadata_s
                            const std::string& partition_name, bool force_writable,
                            const std::chrono::milliseconds& timeout_ms, std::string* path);

// Same as above, but with a given metadata object. Care should be taken that
// the metadata represents a valid partition layout.
bool CreateLogicalPartition(const std::string& block_device, const LpMetadata& metadata,
                            const std::string& partition_name, bool force_writable,
                            const std::chrono::milliseconds& timeout_ms, std::string* path);

// Destroy the block device for a logical partition, by name. If |timeout_ms|
// is non-zero, then this will block until the device path has been unlinked.
bool DestroyLogicalPartition(const std::string& name, const std::chrono::milliseconds& timeout_ms);