diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-03-31 15:40:16 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-03-31 15:40:16 +0200 |
| commit | aaad58f2d6a56830860cb6ddef099096b089c389 (patch) | |
| tree | 99c6e18b73c6c17463ffa0bd93de62edf71bcddb /dev/kernel | |
| parent | b3dfc99a0ac690cf3de2348a8887bfa4bef243bc (diff) | |
storage: unify naming for drive protocol interface
Renamed `fDriveKind` to `fProtocol` across kernel storage subsystems
to clarify its purpose as a protocol identifier (e.g., "AHCI", "ATA-")
rather than a general "kind" classification.
Updated all affected header and source files:
- DriveMgr, HeFS, AHCI, ATADeviceInterface, and NeFS now consistently
reference `fProtocol()` instead of `fDriveKind()`.
- Added streaming operators (`<<`, `>>`) to AHCI and ATA device
interfaces for improved mountpoint interaction.
- Promoted `GetPortsImplemented()` and `SetPortsImplemented()` to
public for AHCI device configuration.
- Added null checks and protocol verification logic in stream operators.
This refactor improves clarity and consistency when working with
storage devices across the kernel.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel')
| -rw-r--r-- | dev/kernel/FSKit/HeFS.h | 2 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/DriveMgr.h | 2 | ||||
| -rw-r--r-- | dev/kernel/StorageKit/AHCI.h | 32 | ||||
| -rw-r--r-- | dev/kernel/src/DriveMgr.cc | 4 | ||||
| -rw-r--r-- | dev/kernel/src/FS/NeFS.cc | 2 | ||||
| -rw-r--r-- | dev/kernel/src/Storage/AHCIDeviceInterface.cc | 76 | ||||
| -rw-r--r-- | dev/kernel/src/Storage/ATADeviceInterface.cc | 19 |
7 files changed, 103 insertions, 34 deletions
diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index 6c294ec6..6fdaafab 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -41,7 +41,7 @@ struct HeFS_BOOT_NODE final Kernel::UInt64 fSectorCount;
Kernel::UInt64 fSectorSize;
Kernel::UInt32 fChecksum;
- Kernel::UInt8 fDriveKind;
+ Kernel::UInt8 fKind;
Kernel::UInt8 fTextEncoding;
Kernel::UInt64 fRootINode;
Kernel::UInt64 fRecoveryINode;
diff --git a/dev/kernel/KernelKit/DriveMgr.h b/dev/kernel/KernelKit/DriveMgr.h index 24a0f48d..e07e2d30 100644 --- a/dev/kernel/KernelKit/DriveMgr.h +++ b/dev/kernel/KernelKit/DriveMgr.h @@ -72,7 +72,7 @@ namespace Kernel Void (*fOutput)(DrivePacket packet); Void (*fVerify)(DrivePacket packet); Void (*fInit)(DrivePacket packet); - const Char* (*fDriveKind)(Void); + const Char* (*fProtocol)(Void); }; ///! drive as a device. diff --git a/dev/kernel/StorageKit/AHCI.h b/dev/kernel/StorageKit/AHCI.h index caf75991..d6aeaee8 100644 --- a/dev/kernel/StorageKit/AHCI.h +++ b/dev/kernel/StorageKit/AHCI.h @@ -27,27 +27,17 @@ namespace Kernel const Char* Name() const override; - const UInt16& GetPortsImplemented() - { - return this->fPortsImplemented; - } - - Void SetPortsImplemented(const UInt16& pi) - { - MUST_PASS(pi > 0); - this->fPortsImplemented = pi; - } - - const UInt32& GetIndex() - { - return this->fDriveIndex; - } - - Void SetIndex(const UInt32& drv) - { - MUST_PASS(MountpointInterface::kDriveIndexInvalid != drv); - this->fDriveIndex = drv; - } + const UInt16& GetPortsImplemented(); + + Void SetPortsImplemented(const UInt16& pi); + + const UInt32& GetIndex(); + + Void SetIndex(const UInt32& drv); + + public: + AHCIDeviceInterface& operator<<(MountpointInterface* Data) override; + AHCIDeviceInterface& operator>>(MountpointInterface* Data) override; private: Void (*fCleanup)(Void) = {nullptr}; diff --git a/dev/kernel/src/DriveMgr.cc b/dev/kernel/src/DriveMgr.cc index d8683fc5..3b0dd9ee 100644 --- a/dev/kernel/src/DriveMgr.cc +++ b/dev/kernel/src/DriveMgr.cc @@ -148,7 +148,7 @@ namespace Kernel trait.fOutput = io_drv_unimplemented; trait.fVerify = io_drv_unimplemented; trait.fInit = io_drv_unimplemented; - trait.fDriveKind = io_drv_kind; + trait.fProtocol = io_drv_kind; kout << "Construct: " << trait.fName << "\r"; @@ -224,7 +224,7 @@ namespace Kernel trait.fOutput = io_drv_output; trait.fInput = io_drv_input; trait.fInit = io_drv_init; - trait.fDriveKind = io_drv_kind; + trait.fProtocol = io_drv_kind; kout << "Detecting partition scheme of: " << trait.fName << ".\r"; diff --git a/dev/kernel/src/FS/NeFS.cc b/dev/kernel/src/FS/NeFS.cc index 6b73dc09..90c5995a 100644 --- a/dev/kernel/src/FS/NeFS.cc +++ b/dev/kernel/src/FS/NeFS.cc @@ -598,7 +598,7 @@ bool NeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input const L drive->fOutput(drive->fPacket); - kout << "drive kind: " << drive->fDriveKind() << kendl; + kout << "drive kind: " << drive->fProtocol() << kendl; kout << "partition name: " << part_block->PartitionName << kendl; kout << "start: " << hex_number(part_block->StartCatalog) << kendl; diff --git a/dev/kernel/src/Storage/AHCIDeviceInterface.cc b/dev/kernel/src/Storage/AHCIDeviceInterface.cc index 954d9f5b..9419dc4e 100644 --- a/dev/kernel/src/Storage/AHCIDeviceInterface.cc +++ b/dev/kernel/src/Storage/AHCIDeviceInterface.cc @@ -34,3 +34,79 @@ const Char* AHCIDeviceInterface::Name() const { return "/dev/sda{}"; } + +/// @brief Output operator. +/// @param Data the disk mountpoint. +/// @return the class itself after operation. +AHCIDeviceInterface& AHCIDeviceInterface::operator<<(MountpointInterface* Data) +{ + if (!Data) + return *this; + + for (SizeT driveCount = 0; driveCount < kDriveMaxCount; ++driveCount) + { + auto interface = Data->GetAddressOf(driveCount); + + if ((interface) && rt_string_cmp((interface)->fProtocol(), "AHCI", rt_string_len("AHCI")) == 0) + { + continue; + } + else if ((interface) && + rt_string_cmp((interface)->fProtocol(), "AHCI", rt_string_len("AHCI")) != 0) + { + return *this; + } + } + + return (AHCIDeviceInterface&)IDeviceObject<MountpointInterface*>::operator<<( + Data); +} + +/// @brief Input operator. +/// @param Data the disk mountpoint. +/// @return the class itself after operation. +AHCIDeviceInterface& AHCIDeviceInterface::operator>>(MountpointInterface* Data) +{ + if (!Data) + return *this; + + for (SizeT driveCount = 0; driveCount < kDriveMaxCount; ++driveCount) + { + auto interface = Data->GetAddressOf(driveCount); + + // really check if it's ATA. + if ((interface) && rt_string_cmp((interface)->fProtocol(), "AHCI", rt_string_len("AHCI")) == 0) + { + continue; + } + else if ((interface) && + rt_string_cmp((interface)->fProtocol(), "AHCI", rt_string_len("AHCI")) != 0) + { + return *this; + } + } + + return (AHCIDeviceInterface&)IDeviceObject<MountpointInterface*>::operator>>( + Data); +} + +const UInt16& AHCIDeviceInterface::GetPortsImplemented() +{ + return this->fPortsImplemented; +} + +Void AHCIDeviceInterface::SetPortsImplemented(const UInt16& pi) +{ + MUST_PASS(pi > 0); + this->fPortsImplemented = pi; +} + +const UInt32& AHCIDeviceInterface::GetIndex() +{ + return this->fDriveIndex; +} + +Void AHCIDeviceInterface::SetIndex(const UInt32& drv) +{ + MUST_PASS(MountpointInterface::kDriveIndexInvalid != drv); +}
\ No newline at end of file diff --git a/dev/kernel/src/Storage/ATADeviceInterface.cc b/dev/kernel/src/Storage/ATADeviceInterface.cc index 615e82db..118a6d0a 100644 --- a/dev/kernel/src/Storage/ATADeviceInterface.cc +++ b/dev/kernel/src/Storage/ATADeviceInterface.cc @@ -36,8 +36,8 @@ const Char* ATADeviceInterface::Name() const } /// @brief Output operator. -/// @param Data -/// @return +/// @param Data the disk mountpoint. +/// @return the class itself after operation. ATADeviceInterface& ATADeviceInterface::operator<<(MountpointInterface* Data) { if (!Data) @@ -46,12 +46,13 @@ ATADeviceInterface& ATADeviceInterface::operator<<(MountpointInterface* Data) for (SizeT driveCount = 0; driveCount < kDriveMaxCount; ++driveCount) { auto interface = Data->GetAddressOf(driveCount); - if ((interface) && rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) == 0) + + if ((interface) && rt_string_cmp((interface)->fProtocol(), "ATA-", rt_string_len("ATA-")) == 0) { continue; } else if ((interface) && - rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) != 0) + rt_string_cmp((interface)->fProtocol(), "ATA-", rt_string_len("ATA-")) != 0) { return *this; } @@ -62,8 +63,8 @@ ATADeviceInterface& ATADeviceInterface::operator<<(MountpointInterface* Data) } /// @brief Input operator. -/// @param Data -/// @return +/// @param Data the disk mountpoint. +/// @return the class itself after operation. ATADeviceInterface& ATADeviceInterface::operator>>(MountpointInterface* Data) { if (!Data) @@ -72,12 +73,14 @@ ATADeviceInterface& ATADeviceInterface::operator>>(MountpointInterface* Data) for (SizeT driveCount = 0; driveCount < kDriveMaxCount; ++driveCount) { auto interface = Data->GetAddressOf(driveCount); - if ((interface) && rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) == 0) + + // really check if it's ATA. + if ((interface) && rt_string_cmp((interface)->fProtocol(), "ATA-", rt_string_len("ATA-")) == 0) { continue; } else if ((interface) && - rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) != 0) + rt_string_cmp((interface)->fProtocol(), "ATA-", rt_string_len("ATA-")) != 0) { return *this; } |
