From aaad58f2d6a56830860cb6ddef099096b089c389 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 31 Mar 2025 15:40:16 +0200 Subject: 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 --- dev/kernel/src/Storage/AHCIDeviceInterface.cc | 76 +++++++++++++++++++++++++++ dev/kernel/src/Storage/ATADeviceInterface.cc | 19 ++++--- 2 files changed, 87 insertions(+), 8 deletions(-) (limited to 'dev/kernel/src/Storage') 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::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::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; } -- cgit v1.2.3