From 812e9efd41a3c52afaaea39e2cfa53e8379e9d62 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sun, 14 Jan 2024 01:16:48 +0200 Subject: [PATCH] Kernel: StorageDevices now specify prefix for partition names --- kernel/include/kernel/Storage/Partition.h | 4 ++-- kernel/include/kernel/Storage/StorageDevice.h | 2 +- kernel/kernel/Storage/ATA/ATADevice.cpp | 2 +- kernel/kernel/Storage/Partition.cpp | 8 ++++---- kernel/kernel/Storage/StorageDevice.cpp | 5 +++-- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/kernel/include/kernel/Storage/Partition.h b/kernel/include/kernel/Storage/Partition.h index d8a18c651e..450d8a8c97 100644 --- a/kernel/include/kernel/Storage/Partition.h +++ b/kernel/include/kernel/Storage/Partition.h @@ -9,7 +9,7 @@ namespace Kernel class Partition final : public BlockDevice { public: - static BAN::ErrorOr> create(BAN::RefPtr, const BAN::GUID& type, const BAN::GUID& guid, uint64_t first_block, uint64_t last_block, uint64_t attr, const char* label, uint32_t index); + static BAN::ErrorOr> create(BAN::RefPtr, const BAN::GUID& type, const BAN::GUID& guid, uint64_t first_block, uint64_t last_block, uint64_t attr, const char* label, uint32_t index, BAN::StringView name_prefix); const BAN::GUID& partition_type() const { return m_type; } const BAN::GUID& partition_guid() const { return m_guid; } @@ -26,7 +26,7 @@ namespace Kernel virtual BAN::StringView name() const override { return m_name; } private: - Partition(BAN::RefPtr, const BAN::GUID&, const BAN::GUID&, uint64_t, uint64_t, uint64_t, const char*, uint32_t); + Partition(BAN::RefPtr, const BAN::GUID&, const BAN::GUID&, uint64_t, uint64_t, uint64_t, const char*, uint32_t, BAN::StringView); private: BAN::RefPtr m_device; diff --git a/kernel/include/kernel/Storage/StorageDevice.h b/kernel/include/kernel/Storage/StorageDevice.h index 0cac372ac3..a2ec6ae120 100644 --- a/kernel/include/kernel/Storage/StorageDevice.h +++ b/kernel/include/kernel/Storage/StorageDevice.h @@ -16,7 +16,7 @@ namespace Kernel { } virtual ~StorageDevice(); - BAN::ErrorOr initialize_partitions(); + BAN::ErrorOr initialize_partitions(BAN::StringView name_prefix); virtual BAN::ErrorOr read_blocks(uint64_t lba, size_t sector_count, BAN::ByteSpan buffer) override { return read_sectors(lba, sector_count, buffer); } virtual BAN::ErrorOr write_blocks(uint64_t lba, size_t sector_count, BAN::ConstByteSpan buffer) override { return write_sectors(lba, sector_count, buffer); } diff --git a/kernel/kernel/Storage/ATA/ATADevice.cpp b/kernel/kernel/Storage/ATA/ATADevice.cpp index bb9590540f..84ca7134d4 100644 --- a/kernel/kernel/Storage/ATA/ATADevice.cpp +++ b/kernel/kernel/Storage/ATA/ATADevice.cpp @@ -76,7 +76,7 @@ namespace Kernel add_disk_cache(); DevFileSystem::get().add_device(this); - if (auto res = initialize_partitions(); res.is_error()) + if (auto res = initialize_partitions(name()); res.is_error()) dprintln("{}", res.error()); return {}; diff --git a/kernel/kernel/Storage/Partition.cpp b/kernel/kernel/Storage/Partition.cpp index 7f997435e7..4f2a0b0fa9 100644 --- a/kernel/kernel/Storage/Partition.cpp +++ b/kernel/kernel/Storage/Partition.cpp @@ -5,15 +5,15 @@ namespace Kernel { - BAN::ErrorOr> Partition::create(BAN::RefPtr device, const BAN::GUID& type, const BAN::GUID& guid, uint64_t first_block, uint64_t last_block, uint64_t attr, const char* label, uint32_t index) + BAN::ErrorOr> Partition::create(BAN::RefPtr device, const BAN::GUID& type, const BAN::GUID& guid, uint64_t first_block, uint64_t last_block, uint64_t attr, const char* label, uint32_t index, BAN::StringView name_prefix) { - auto partition_ptr = new Partition(device, type, guid, first_block, last_block, attr, label, index); + auto partition_ptr = new Partition(device, type, guid, first_block, last_block, attr, label, index, name_prefix); if (partition_ptr == nullptr) return BAN::Error::from_errno(ENOMEM); return BAN::RefPtr::adopt(partition_ptr); } - Partition::Partition(BAN::RefPtr device, const BAN::GUID& type, const BAN::GUID& guid, uint64_t first_block, uint64_t last_block, uint64_t attr, const char* label, uint32_t index) + Partition::Partition(BAN::RefPtr device, const BAN::GUID& type, const BAN::GUID& guid, uint64_t first_block, uint64_t last_block, uint64_t attr, const char* label, uint32_t index, BAN::StringView name_prefix) : BlockDevice(0660, 0, 0) , m_device(device) , m_type(type) @@ -21,7 +21,7 @@ namespace Kernel , m_first_block(first_block) , m_last_block(last_block) , m_attributes(attr) - , m_name(BAN::String::formatted("{}{}", device->name(), index)) + , m_name(BAN::String::formatted("{}{}", name_prefix, index)) , m_rdev(makedev(major(device->rdev()), index)) { memcpy(m_label, label, sizeof(m_label)); diff --git a/kernel/kernel/Storage/StorageDevice.cpp b/kernel/kernel/Storage/StorageDevice.cpp index 161af64415..16c3a6f02f 100644 --- a/kernel/kernel/Storage/StorageDevice.cpp +++ b/kernel/kernel/Storage/StorageDevice.cpp @@ -142,7 +142,7 @@ namespace Kernel return true; } - BAN::ErrorOr StorageDevice::initialize_partitions() + BAN::ErrorOr StorageDevice::initialize_partitions(BAN::StringView name_prefix) { if (total_size() < sizeof(GPTHeader)) return BAN::Error::from_error_code(ErrorCode::Storage_GPTHeader); @@ -189,7 +189,8 @@ namespace Kernel entry.ending_lba, entry.attributes, utf8_name, - i + 1 + i + 1, + name_prefix )); TRY(m_partitions.push_back(BAN::move(partition))); }