Loading fs_mgr/fs_mgr_dm_linear.cpp +43 −11 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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 fs_mgr/include/fs_mgr_dm_linear.h +9 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading
fs_mgr/fs_mgr_dm_linear.cpp +43 −11 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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
fs_mgr/include/fs_mgr_dm_linear.h +9 −0 Original line number Diff line number Diff line Loading @@ -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 Loading