1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/* -------------------------------------------
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 kDriveManagerCount (4U)
#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 << "newoskrnl: 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__ */
|