diff options
| author | Amlal <amlalelmahrouss@icloud.com> | 2024-12-21 21:59:13 +0100 |
|---|---|---|
| committer | Amlal <amlalelmahrouss@icloud.com> | 2024-12-21 21:59:45 +0100 |
| commit | 610f91d87152cbe48d3054fcf437d8239da6ef35 (patch) | |
| tree | a386f7047ab73d088169ab2371ddc6ffe8020f1c /dev/Kernel/KernelKit/DriveMgr.h | |
| parent | 509fcca5986651c8ba712fb395f8498f2dea4109 (diff) | |
IMP: :boom: Breaking changes some checks are needed to be done.
Signed-off-by: Amlal <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/KernelKit/DriveMgr.h')
| -rw-r--r-- | dev/Kernel/KernelKit/DriveMgr.h | 169 |
1 files changed, 169 insertions, 0 deletions
diff --git a/dev/Kernel/KernelKit/DriveMgr.h b/dev/Kernel/KernelKit/DriveMgr.h new file mode 100644 index 00000000..b719e48c --- /dev/null +++ b/dev/Kernel/KernelKit/DriveMgr.h @@ -0,0 +1,169 @@ +/* ------------------------------------------- + + Copyright (C) 2024, TQ B.V, all rights reserved. + +------------------------------------------- */ + +#ifndef INC_DRIVE_MANAGER_H +#define INC_DRIVE_MANAGER_H + +#include <KernelKit/UserProcessScheduler.h> +#include <CompilerKit/CompilerKit.h> +#include <KernelKit/DebugOutput.h> +#include <KernelKit/DeviceMgr.h> +#include <KernelKit/LPC.h> +#include <NewKit/Defines.h> +#include <NewKit/KString.h> +#include <NewKit/Ref.h> + +#define kDriveMaxCount (4U) +#define kDriveSectorSz (512U) +#define kDriveInvalidID (-1) +#define kDriveNameLen (32) + +#define drv_sector_cnt(SIZE, SECTOR_SZ) (((SIZE) + (SECTOR_SZ)) / (SECTOR_SZ)) + +namespace Kernel +{ + enum + { + kInvalidDisc = -1, + + /// Storage types, combine with flags. + kBlockDevice = 0xAD, + kMassStorageDisc = 0xDA, + kFloppyDisc = 0xCD, + kOpticalDisc = 0xDC, // CD-ROM/DVD-ROM/Blu-Ray + kTapeDisc = 0xD7, + + /// Storage flags, combine with types. + kReadOnlyDrive = 0x10, // Read only drive + kEPMDrive = 0x11, // Explicit Partition Map. + kEPTDrive = 0x12, // ESP w/ EPM partition. + kMBRDrive = 0x13, // PC classic partition scheme + kGPTDrive = 0x14, // PC new partition scheme + kUnformattedDrive = 0x15, + kStorageCount = 9, + }; + + /// @brief Media drive trait type. + struct DriveTrait final + { + Char fName[kDriveNameLen]; // /System, /Boot, //./Devices/USB... + Int32 fKind; // fMassStorage, fFloppy, fOpticalDisc. + Int32 fFlags; // fReadOnly, fXPMDrive, fXPTDrive + + /// @brief Packet drive (StorageKit compilant.) + struct DrivePacket final + { + VoidPtr fPacketContent{nullptr}; //! packet body. + Char fPacketMime[kDriveNameLen] = "*/*"; //! identify what we're sending. + SizeT fPacketSize{0UL}; //! packet size + UInt32 fPacketCRC32{0UL}; //! sanity crc, in case if good is set to false + Boolean fPacketGood{YES}; + Lba fPacketLba{0UL}; + Boolean fPacketReadOnly{NO}; + } fPacket; + + Void (*fInput)(DrivePacket* packet_ptr); + Void (*fOutput)(DrivePacket* packet_ptr); + Void (*fVerify)(DrivePacket* packet_ptr); + Void (*fInit)(DrivePacket* packet_ptr); + const Char* (*fDriveKind)(Void); + }; + + ///! drive as a device. + typedef DriveTrait* DriveTraitPtr; + + /** + * @brief Mounted drives interface. + * @note This class has all of it's drive set to nullptr, allocate them using + * GetAddressOf(index). + */ + class MountpointInterface final + { + public: + explicit MountpointInterface() = default; + ~MountpointInterface() = default; + + ZKA_COPY_DEFAULT(MountpointInterface); + + public: + DriveTrait& A() + { + return mA; + } + + DriveTrait& B() + { + return mB; + } + + DriveTrait& C() + { + return mC; + } + + DriveTrait& D() + { + return mD; + } + + enum + { + kDriveIndexA = 0, + kDriveIndexB, + kDriveIndexC, + kDriveIndexD, + kDriveIndexInvalid, + }; + + DriveTraitPtr GetAddressOf(const Int32& index) + { + err_local_get() = kErrorSuccess; + + switch (index) + { + case kDriveIndexA: + return &mA; + case kDriveIndexB: + return &mB; + case kDriveIndexC: + return &mC; + case kDriveIndexD: + return &mD; + default: { + err_local_get() = kErrorNoSuchDisk; + kcout << "No such disk index.\n"; + + break; + } + } + + return nullptr; + } + + private: + DriveTrait mA, mB, mC, mD; + }; + + /// @brief Unimplemented drive. + /// @param pckt the packet to read. + /// @return + Void io_drv_unimplemented(DriveTrait::DrivePacket* pckt); + + /// @brief Gets the drive kind (ATA, SCSI, AHCI...) + /// @param void none. + /// @return the drive kind (ATA, Flash, NVM) + const Char* io_drv_kind(Void); + + /// @brief Makes a new drive. + /// @return the new drive as a trait. + DriveTrait io_construct_blank_drive(Void) noexcept; + + /// @brief Fetches the main drive. + /// @return the new drive as a trait. + DriveTrait io_construct_main_drive(Void) noexcept; +} // namespace Kernel + +#endif /* ifndef INC_DRIVE_MANAGER_H */ |
