diff --git a/kernel/include/kernel/Device.h b/kernel/include/kernel/Device.h index 98e7492b..b1d83f6d 100644 --- a/kernel/include/kernel/Device.h +++ b/kernel/include/kernel/Device.h @@ -65,7 +65,7 @@ namespace Kernel virtual BAN::ErrorOr read(size_t, void*, size_t) override { return BAN::Error::from_errno(EISDIR); } virtual BAN::ErrorOr create_file(BAN::StringView, mode_t) override { return BAN::Error::from_errno(EINVAL); }; - virtual Type type() const override { return Type::DeviceManager; } + virtual InodeType type() const override { return InodeType::DeviceManager; } virtual bool operator==(const Inode&) const override { return false; } virtual BAN::RefPtr root_inode() override { return this; } diff --git a/kernel/include/kernel/FS/Ext2.h b/kernel/include/kernel/FS/Ext2.h index 08608ef2..cc436ff6 100644 --- a/kernel/include/kernel/FS/Ext2.h +++ b/kernel/include/kernel/FS/Ext2.h @@ -142,7 +142,7 @@ namespace Kernel virtual BAN::ErrorOr create_file(BAN::StringView, mode_t) override; - virtual Type type() const override { return Type::Ext2; } + virtual InodeType type() const override { return InodeType::Ext2; } virtual bool operator==(const Inode& other) const override; protected: @@ -175,12 +175,12 @@ namespace Kernel class Ext2FS : public FileSystem { public: - static BAN::ErrorOr create(StorageDevice::Partition&); + static BAN::ErrorOr create(Partition&); virtual BAN::RefPtr root_inode() override { return m_root_inode; } private: - Ext2FS(StorageDevice::Partition& partition) + Ext2FS(Partition& partition) : m_partition(partition) {} @@ -207,7 +207,7 @@ namespace Kernel uint32_t block_size() const { return 1024 << superblock().log_block_size; } private: - StorageDevice::Partition& m_partition; + Partition& m_partition; BAN::RefPtr m_root_inode; diff --git a/kernel/include/kernel/FS/Inode.h b/kernel/include/kernel/FS/Inode.h index 0b08ffbe..1944e23f 100644 --- a/kernel/include/kernel/FS/Inode.h +++ b/kernel/include/kernel/FS/Inode.h @@ -33,7 +33,7 @@ namespace Kernel IFREG = 0x8000, }; - enum class Type + enum class InodeType { DeviceManager, Device, @@ -66,7 +66,7 @@ namespace Kernel virtual BAN::ErrorOr read(size_t, void*, size_t) = 0; virtual BAN::ErrorOr create_file(BAN::StringView, mode_t) = 0; - virtual Type type() const = 0; + virtual InodeType type() const = 0; virtual bool operator==(const Inode&) const = 0; protected: diff --git a/kernel/include/kernel/Input/PS2Keyboard.h b/kernel/include/kernel/Input/PS2Keyboard.h index 53f04f1e..6c472c51 100644 --- a/kernel/include/kernel/Input/PS2Keyboard.h +++ b/kernel/include/kernel/Input/PS2Keyboard.h @@ -76,7 +76,7 @@ namespace Kernel::Input virtual BAN::ErrorOr read(size_t, void*, size_t) override; virtual BAN::ErrorOr create_file(BAN::StringView, mode_t) override { return BAN::Error::from_errno(ENOTDIR); } - virtual Type type() const override { return Type::Device; } + virtual InodeType type() const override { return InodeType::Device; } virtual bool operator==(const Inode&) const override { return false; } protected: diff --git a/kernel/include/kernel/Storage/ATAController.h b/kernel/include/kernel/Storage/ATAController.h index 6fc05499..b593db71 100644 --- a/kernel/include/kernel/Storage/ATAController.h +++ b/kernel/include/kernel/Storage/ATAController.h @@ -9,7 +9,7 @@ namespace Kernel struct ATABus; class ATAController; - class ATADevice : public StorageDevice + class ATADevice final : public StorageDevice { public: virtual BAN::ErrorOr read_sectors(uint64_t, uint8_t, uint8_t*) override; @@ -18,14 +18,14 @@ namespace Kernel virtual uint64_t total_size() const override { return lba_count * sector_size(); } private: - enum class Type + enum class DeviceType { Unknown, ATA, ATAPI, }; - Type type; + DeviceType type; uint8_t slave_bit; // 0x00 for master, 0x10 for slave uint16_t signature; uint16_t capabilities; diff --git a/kernel/include/kernel/Storage/StorageDevice.h b/kernel/include/kernel/Storage/StorageDevice.h index e1b2f962..2cd0bd03 100644 --- a/kernel/include/kernel/Storage/StorageDevice.h +++ b/kernel/include/kernel/Storage/StorageDevice.h @@ -1,6 +1,7 @@ #pragma once #include +#include namespace Kernel { @@ -13,35 +14,37 @@ namespace Kernel uint8_t data4[8]; }; - class StorageDevice + class StorageDevice; + + class Partition { public: - struct Partition - { - Partition(StorageDevice&, const GUID&, const GUID&, uint64_t, uint64_t, uint64_t, const char*); + Partition(StorageDevice&, const GUID&, const GUID&, uint64_t, uint64_t, uint64_t, const char*); - const GUID& type() const { return m_type; } - const GUID& guid() const { return m_guid; } - uint64_t lba_start() const { return m_lba_start; } - uint64_t lba_end() const { return m_lba_end; } - uint64_t attributes() const { return m_attributes; } - const char* name() const { return m_name; } - const StorageDevice& device() const { return m_device; } + const GUID& partition_type() const { return m_type; } + const GUID& partition_guid() const { return m_guid; } + uint64_t lba_start() const { return m_lba_start; } + uint64_t lba_end() const { return m_lba_end; } + uint64_t attributes() const { return m_attributes; } + const char* label() const { return m_label; } + const StorageDevice& device() const { return m_device; } - BAN::ErrorOr read_sectors(uint64_t lba, uint8_t sector_count, uint8_t* buffer); - BAN::ErrorOr write_sectors(uint64_t lba, uint8_t sector_count, const uint8_t* buffer); - bool is_used() const { uint8_t zero[16] {}; return memcmp(&m_type, zero, 16); } + BAN::ErrorOr read_sectors(uint64_t lba, uint8_t sector_count, uint8_t* buffer); + BAN::ErrorOr write_sectors(uint64_t lba, uint8_t sector_count, const uint8_t* buffer); + bool is_used() const { uint8_t zero[16] {}; return memcmp(&m_type, zero, 16); } - private: - StorageDevice& m_device; - const GUID m_type; - const GUID m_guid; - const uint64_t m_lba_start; - const uint64_t m_lba_end; - const uint64_t m_attributes; - char m_name[36 * 4 + 1]; - }; + private: + StorageDevice& m_device; + const GUID m_type; + const GUID m_guid; + const uint64_t m_lba_start; + const uint64_t m_lba_end; + const uint64_t m_attributes; + char m_label[36 * 4 + 1]; + }; + class StorageDevice + { public: virtual ~StorageDevice() {} diff --git a/kernel/kernel/FS/Ext2.cpp b/kernel/kernel/FS/Ext2.cpp index 8dc5b6a4..f30d5666 100644 --- a/kernel/kernel/FS/Ext2.cpp +++ b/kernel/kernel/FS/Ext2.cpp @@ -444,7 +444,7 @@ namespace Kernel return index() == ext2_other.index(); } - BAN::ErrorOr Ext2FS::create(StorageDevice::Partition& partition) + BAN::ErrorOr Ext2FS::create(Partition& partition) { Ext2FS* ext2fs = new Ext2FS(partition); if (ext2fs == nullptr) diff --git a/kernel/kernel/FS/VirtualFileSystem.cpp b/kernel/kernel/FS/VirtualFileSystem.cpp index 089b0c88..d3a65eb6 100644 --- a/kernel/kernel/FS/VirtualFileSystem.cpp +++ b/kernel/kernel/FS/VirtualFileSystem.cpp @@ -92,7 +92,7 @@ namespace Kernel for (auto& partition : device->partitions()) { - if (partition.name() == "banan-root"sv) + if (partition.label() == "banan-root"sv) { if (root_inode()) dwarnln("multiple root partitions found"); @@ -127,7 +127,7 @@ namespace Kernel { for (auto& partition : device->partitions()) { - if (partition.name() == "mount-test"sv) + if (partition.label() == "mount-test"sv) { auto ext2fs = TRY(Ext2FS::create(partition)); TRY(mount(ext2fs, "/mnt"sv)); diff --git a/kernel/kernel/Storage/ATAController.cpp b/kernel/kernel/Storage/ATAController.cpp index 492fafef..0f750e07 100644 --- a/kernel/kernel/Storage/ATAController.cpp +++ b/kernel/kernel/Storage/ATAController.cpp @@ -89,7 +89,7 @@ namespace Kernel ATABus& bus = m_buses[bus_index]; ATADevice& device = bus.devices[device_index]; - device.type = ATADevice::Type::Unknown; + device.type = ATADevice::DeviceType::Unknown; device.slave_bit = device_index << 4; device.bus = &bus; device.controller = this; @@ -113,7 +113,7 @@ namespace Kernel break; } - auto type = ATADevice::Type::ATA; + auto type = ATADevice::DeviceType::ATA; // Not a ATA device, maybe ATAPI if (status & ATA_STATUS_ERR) @@ -122,9 +122,9 @@ namespace Kernel uint8_t lba2 = bus.read(ATA_PORT_LBA2); if (lba1 == 0x14 && lba2 == 0xEB) - type = ATADevice::Type::ATAPI; + type = ATADevice::DeviceType::ATAPI; else if (lba1 == 0x69 && lba2 == 0x96) - type = ATADevice::Type::ATAPI; + type = ATADevice::DeviceType::ATAPI; else continue; @@ -171,12 +171,12 @@ namespace Kernel for (uint32_t j = 0; j < 2; j++) { ATADevice& device = m_buses[i].devices[j]; - if (device.type == ATADevice::Type::Unknown) + if (device.type == ATADevice::DeviceType::Unknown) continue; constexpr uint32_t words_per_mib = 1024 * 1024 / 2; const char* device_type = - device.type == ATADevice::Type::ATA ? "ATA" : - device.type == ATADevice::Type::ATAPI ? "ATAPI" : + device.type == ATADevice::DeviceType::ATA ? "ATA" : + device.type == ATADevice::DeviceType::ATAPI ? "ATAPI" : "Unknown"; dprintln("Found {} Drive ({} MiB) model {}", device_type, device.lba_count * device.sector_words / words_per_mib, device.model); } diff --git a/kernel/kernel/Storage/StorageDevice.cpp b/kernel/kernel/Storage/StorageDevice.cpp index f8b178fc..222f30d4 100644 --- a/kernel/kernel/Storage/StorageDevice.cpp +++ b/kernel/kernel/Storage/StorageDevice.cpp @@ -185,7 +185,7 @@ namespace Kernel return {}; } - StorageDevice::Partition::Partition(StorageDevice& device, const GUID& type, const GUID& guid, uint64_t start, uint64_t end, uint64_t attr, const char* name) + Partition::Partition(StorageDevice& device, const GUID& type, const GUID& guid, uint64_t start, uint64_t end, uint64_t attr, const char* label) : m_device(device) , m_type(type) , m_guid(guid) @@ -193,10 +193,10 @@ namespace Kernel , m_lba_end(end) , m_attributes(attr) { - memcpy(m_name, name, sizeof(m_name)); + memcpy(m_label, label, sizeof(m_label)); } - BAN::ErrorOr StorageDevice::Partition::read_sectors(uint64_t lba, uint8_t sector_count, uint8_t* buffer) + BAN::ErrorOr Partition::read_sectors(uint64_t lba, uint8_t sector_count, uint8_t* buffer) { const uint32_t sectors_in_partition = m_lba_end - m_lba_start; if (lba + sector_count > sectors_in_partition) @@ -205,7 +205,7 @@ namespace Kernel return {}; } - BAN::ErrorOr StorageDevice::Partition::write_sectors(uint64_t lba, uint8_t sector_count, const uint8_t* buffer) + BAN::ErrorOr Partition::write_sectors(uint64_t lba, uint8_t sector_count, const uint8_t* buffer) { const uint32_t sectors_in_partition = m_lba_end - m_lba_start; if (lba + sector_count > sectors_in_partition)