Kernel: StorageDevices now specify prefix for partition names

This commit is contained in:
Bananymous 2024-01-14 01:16:48 +02:00
parent c6130f33d7
commit 812e9efd41
5 changed files with 11 additions and 10 deletions

View File

@ -9,7 +9,7 @@ namespace Kernel
class Partition final : public BlockDevice class Partition final : public BlockDevice
{ {
public: public:
static BAN::ErrorOr<BAN::RefPtr<Partition>> create(BAN::RefPtr<BlockDevice>, 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<BAN::RefPtr<Partition>> create(BAN::RefPtr<BlockDevice>, 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_type() const { return m_type; }
const BAN::GUID& partition_guid() const { return m_guid; } const BAN::GUID& partition_guid() const { return m_guid; }
@ -26,7 +26,7 @@ namespace Kernel
virtual BAN::StringView name() const override { return m_name; } virtual BAN::StringView name() const override { return m_name; }
private: private:
Partition(BAN::RefPtr<BlockDevice>, const BAN::GUID&, const BAN::GUID&, uint64_t, uint64_t, uint64_t, const char*, uint32_t); Partition(BAN::RefPtr<BlockDevice>, const BAN::GUID&, const BAN::GUID&, uint64_t, uint64_t, uint64_t, const char*, uint32_t, BAN::StringView);
private: private:
BAN::RefPtr<BlockDevice> m_device; BAN::RefPtr<BlockDevice> m_device;

View File

@ -16,7 +16,7 @@ namespace Kernel
{ } { }
virtual ~StorageDevice(); virtual ~StorageDevice();
BAN::ErrorOr<void> initialize_partitions(); BAN::ErrorOr<void> initialize_partitions(BAN::StringView name_prefix);
virtual BAN::ErrorOr<void> read_blocks(uint64_t lba, size_t sector_count, BAN::ByteSpan buffer) override { return read_sectors(lba, sector_count, buffer); } virtual BAN::ErrorOr<void> read_blocks(uint64_t lba, size_t sector_count, BAN::ByteSpan buffer) override { return read_sectors(lba, sector_count, buffer); }
virtual BAN::ErrorOr<void> write_blocks(uint64_t lba, size_t sector_count, BAN::ConstByteSpan buffer) override { return write_sectors(lba, sector_count, buffer); } virtual BAN::ErrorOr<void> write_blocks(uint64_t lba, size_t sector_count, BAN::ConstByteSpan buffer) override { return write_sectors(lba, sector_count, buffer); }

View File

@ -76,7 +76,7 @@ namespace Kernel
add_disk_cache(); add_disk_cache();
DevFileSystem::get().add_device(this); 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()); dprintln("{}", res.error());
return {}; return {};

View File

@ -5,15 +5,15 @@
namespace Kernel namespace Kernel
{ {
BAN::ErrorOr<BAN::RefPtr<Partition>> Partition::create(BAN::RefPtr<BlockDevice> 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<BAN::RefPtr<Partition>> Partition::create(BAN::RefPtr<BlockDevice> 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) if (partition_ptr == nullptr)
return BAN::Error::from_errno(ENOMEM); return BAN::Error::from_errno(ENOMEM);
return BAN::RefPtr<Partition>::adopt(partition_ptr); return BAN::RefPtr<Partition>::adopt(partition_ptr);
} }
Partition::Partition(BAN::RefPtr<BlockDevice> 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<BlockDevice> 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) : BlockDevice(0660, 0, 0)
, m_device(device) , m_device(device)
, m_type(type) , m_type(type)
@ -21,7 +21,7 @@ namespace Kernel
, m_first_block(first_block) , m_first_block(first_block)
, m_last_block(last_block) , m_last_block(last_block)
, m_attributes(attr) , 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)) , m_rdev(makedev(major(device->rdev()), index))
{ {
memcpy(m_label, label, sizeof(m_label)); memcpy(m_label, label, sizeof(m_label));

View File

@ -142,7 +142,7 @@ namespace Kernel
return true; return true;
} }
BAN::ErrorOr<void> StorageDevice::initialize_partitions() BAN::ErrorOr<void> StorageDevice::initialize_partitions(BAN::StringView name_prefix)
{ {
if (total_size() < sizeof(GPTHeader)) if (total_size() < sizeof(GPTHeader))
return BAN::Error::from_error_code(ErrorCode::Storage_GPTHeader); return BAN::Error::from_error_code(ErrorCode::Storage_GPTHeader);
@ -189,7 +189,8 @@ namespace Kernel
entry.ending_lba, entry.ending_lba,
entry.attributes, entry.attributes,
utf8_name, utf8_name,
i + 1 i + 1,
name_prefix
)); ));
TRY(m_partitions.push_back(BAN::move(partition))); TRY(m_partitions.push_back(BAN::move(partition)));
} }