summaryrefslogtreecommitdiffhomepage
path: root/Kernel/KernelKit/DriveManager.hxx
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-09 00:42:44 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-09 00:42:44 +0200
commitaf8a516fc22865abd80d6e26f1541fa3d6bebfdc (patch)
tree96d42a10945fc03df022389aef54708383c1d616 /Kernel/KernelKit/DriveManager.hxx
parenta874e9cc98df994178d55996943fe81799c61d2f (diff)
MHR-23: :boom:, refactors.
- Move NewBoot to /Boot, thus making Kernel directory only containing the kernel. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel/KernelKit/DriveManager.hxx')
-rw-r--r--Kernel/KernelKit/DriveManager.hxx146
1 files changed, 146 insertions, 0 deletions
diff --git a/Kernel/KernelKit/DriveManager.hxx b/Kernel/KernelKit/DriveManager.hxx
new file mode 100644
index 00000000..ad77958e
--- /dev/null
+++ b/Kernel/KernelKit/DriveManager.hxx
@@ -0,0 +1,146 @@
+/* -------------------------------------------
+
+ Copyright SoftwareLabs
+
+------------------------------------------- */
+
+#ifndef __DRIVE_MANAGER__
+#define __DRIVE_MANAGER__
+
+#include <CompilerKit/CompilerKit.hxx>
+#include <KernelKit/DebugOutput.hpp>
+#include <KernelKit/DeviceManager.hpp>
+#include <KernelKit/HError.hpp>
+#include <NewKit/Defines.hpp>
+#include <NewKit/String.hpp>
+
+#define kDriveInvalidID -1
+#define kDriveNameLen 32
+
+namespace NewOS
+{
+ enum
+ {
+ kInvalidDrive = -1,
+ kBlockDevice = 0xAD,
+ kMassStorage = 0xDA,
+ kFloppyDisc = 0xCD,
+ kOpticalDisc = 0xDC, // CD-ROM/DVD-ROM/Blu-Ray
+ /// combine with below.
+ kReadOnly = 0x10, // Read only drive
+ kEPMDrive = 0x11, // Explicit Partition Map.
+ kEPTDrive = 0x12, // ESP w/ EPM partition.
+ kMBRDrive = 0x13, // IBM PC classic partition scheme
+ kDriveCnt = 9,
+ };
+
+ typedef Int64 rt_drive_id_type;
+
+ /// @brief Media drive trait type.
+ struct DriveTrait final
+ {
+ Char fName[kDriveNameLen]; // /System, /Boot, //./Devices/USB...
+ Int32 fKind; // fMassStorage, fFloppy, fOpticalDisc.
+ rt_drive_id_type fId; // Drive id.
+ Int32 fFlags; // fReadOnly, fXPMDrive, fXPTDrive
+
+ /// @brief Packet drive (StorageKit compilant.)
+ struct DrivePacket final
+ {
+ VoidPtr fPacketContent; //! packet body.
+ Char fPacketMime[kDriveNameLen]; //! identify what we're sending.
+ SizeT fPacketSize; //! packet size
+ UInt32 fPacketCRC32; //! sanity crc, in case if good is set to false
+ Boolean fPacketGood;
+ Lba fLba;
+ } fPacket;
+
+ Void (*fInput)(DrivePacket* packetPtr);
+ Void (*fOutput)(DrivePacket* packetPtr);
+ Void (*fVerify)(DrivePacket* packetPtr);
+ 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;
+
+ NEWOS_COPY_DEFAULT(MountpointInterface);
+
+ public:
+ DriveTrait& A()
+ {
+ return mA;
+ }
+ DriveTrait& B()
+ {
+ return mB;
+ }
+ DriveTrait& C()
+ {
+ return mC;
+ }
+ DriveTrait& D()
+ {
+ return mD;
+ }
+
+ DriveTraitPtr GetAddressOf(Int32 index)
+ {
+ DbgLastError() = kErrorSuccess;
+
+ switch (index)
+ {
+ case 0:
+ return &mA;
+ case 1:
+ return &mB;
+ case 2:
+ return &mC;
+ case 3:
+ return &mD;
+ default: {
+ DbgLastError() = kErrorNoSuchDisk;
+ kcout << "New OS: No such disk.\n";
+
+ break;
+ }
+ }
+
+ return nullptr;
+ }
+
+ private:
+ DriveTrait mA, mB, mC, mD;
+ };
+
+ /// @brief Unimplemented drive.
+ /// @param pckt
+ /// @return
+ Void ke_drv_unimplemented(DriveTrait::DrivePacket* pckt);
+
+ /// @brief Gets the drive kind (ATA, SCSI, AHCI...)
+ /// @param
+ /// @return
+ const Char* ke_drive_kind(Void);
+
+ /// @brief Makes a new drive.
+ /// @return the new drive.
+ DriveTrait construct_drive(void) noexcept;
+
+ /// @brief Fetches the main drive.
+ /// @return the new drive.
+ DriveTrait construct_main_drive(void) noexcept;
+} // namespace NewOS
+
+#endif /* ifndef __DRIVE_MANAGER__ */