summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/HALKit/AMD64
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-21 15:13:19 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-21 15:13:19 +0100
commit59bb4017bff80dcbb0a05c6339720b0556c1967e (patch)
tree4a3d281c70453756b454ead778c69034cdb95c41 /dev/Kernel/HALKit/AMD64
parent47702b0d6fe3f18f36eb633056db2914ad019945 (diff)
kernel(storage): Add two functions, sk_io_read_ahci and sk_io_write_ahci. To avoid using
lambdas inside the device initialization expression. This leads to the following: - Better readability. - Much more predictible code. - And a check on *disk* which could've been invalid memory area (NULL address here) Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/HALKit/AMD64')
-rw-r--r--dev/Kernel/HALKit/AMD64/Storage/AHCI+Generic.cc52
1 files changed, 41 insertions, 11 deletions
diff --git a/dev/Kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/Kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
index ae0ae239..23ac2aeb 100644
--- a/dev/Kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
+++ b/dev/Kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
@@ -321,22 +321,52 @@ namespace NeOS
return pi;
}
+ namespace Detail
+ {
+ /// @brief Read AHCI device.
+ /// @param self device
+ /// @param mnt mounted disk.
+ STATIC Void sk_io_read_ahci(IDeviceObject<MountpointInterface*>* self, MountpointInterface* mnt)
+ {
+ AHCIDeviceInterface* dev = (AHCIDeviceInterface*)self;
+
+ if (!dev)
+ return;
+
+ auto disk = mnt->GetAddressOf(dev->GetIndex());
+
+ if (!disk)
+ return;
+
+ drv_std_input_output<NO, YES, NO>(disk->fPacket.fPacketLba, (UInt8*)disk->fPacket.fPacketContent, kAHCISectorSize, disk->fPacket.fPacketSize);
+ }
+
+ /// @brief Write AHCI device.
+ /// @param self device
+ /// @param mnt mounted disk.
+ STATIC Void sk_io_write_ahci(IDeviceObject<MountpointInterface*>* self, MountpointInterface* mnt)
+ {
+ AHCIDeviceInterface* dev = (AHCIDeviceInterface*)self;
+
+ if (!dev)
+ return;
+
+ auto disk = mnt->GetAddressOf(dev->GetIndex());
+
+ if (!disk)
+ return;
+
+ drv_std_input_output<YES, YES, NO>(disk->fPacket.fPacketLba, (UInt8*)disk->fPacket.fPacketContent, kAHCISectorSize, disk->fPacket.fPacketSize);
+ }
+ }
+
ErrorOr<AHCIDeviceInterface> sk_acquire_ahci_device(Int32 drv_index)
{
if (!drv_std_detected_ahci())
return ErrorOr<AHCIDeviceInterface>(kErrorDisk);
- AHCIDeviceInterface device([](IDeviceObject<MountpointInterface*>* self, MountpointInterface* mnt) -> void {
- AHCIDeviceInterface* dev = (AHCIDeviceInterface*)self;
-
- auto disk = mnt->GetAddressOf(dev->GetIndex());
- drv_std_input_output<YES, YES, NO>(disk->fPacket.fPacketLba, (UInt8*)disk->fPacket.fPacketContent, kAHCISectorSize, disk->fPacket.fPacketSize); },
- [](IDeviceObject<MountpointInterface*>* self, MountpointInterface* mnt) -> void {
- AHCIDeviceInterface* dev = (AHCIDeviceInterface*)self;
-
- auto disk = mnt->GetAddressOf(dev->GetIndex());
- drv_std_input_output<NO, YES, NO>(disk->fPacket.fPacketLba, (UInt8*)disk->fPacket.fPacketContent, kAHCISectorSize, disk->fPacket.fPacketSize);
- },
+ AHCIDeviceInterface device(Detail::sk_io_read_ahci,
+ Detail::sk_io_write_ahci,
nullptr);
device.SetPortsImplemented(kSATAPortsImplemented);