diff options
| author | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-11-21 15:48:03 +0100 |
|---|---|---|
| committer | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-11-21 15:48:03 +0100 |
| commit | 779b66cef292e1b52bce4599c9dfe1e0c10858eb (patch) | |
| tree | 8011852695f113c012315514986f6428f06b2155 /dev/ZKAKit/KernelKit | |
| parent | dc008570233d0dbfac32eb87367b7e4a08302e32 (diff) | |
IMP: Improvements over the microkernel, did lots of refactors.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKAKit/KernelKit')
| -rw-r--r-- | dev/ZKAKit/KernelKit/DriveMgr.h | 39 | ||||
| -rw-r--r-- | dev/ZKAKit/KernelKit/FileMgr.h | 93 | ||||
| -rw-r--r-- | dev/ZKAKit/KernelKit/User.h | 6 |
3 files changed, 71 insertions, 67 deletions
diff --git a/dev/ZKAKit/KernelKit/DriveMgr.h b/dev/ZKAKit/KernelKit/DriveMgr.h index 204e90b2..f96a35ff 100644 --- a/dev/ZKAKit/KernelKit/DriveMgr.h +++ b/dev/ZKAKit/KernelKit/DriveMgr.h @@ -4,8 +4,8 @@ ------------------------------------------- */ -#ifndef __INC_DRIVE_MANAGER_H__ -#define __INC_DRIVE_MANAGER_H__ +#ifndef INC_DRIVE_MANAGER_H +#define INC_DRIVE_MANAGER_H #include <KernelKit/UserProcessScheduler.h> #include <CompilerKit/CompilerKit.h> @@ -16,25 +16,28 @@ #include <NewKit/KString.h> #include <NewKit/Ref.h> -#define kMaxDriveCountPerMountpoint (4U) +#define kDriveMaxCount (4U) #define kDriveSectorSz (512U) #define kDriveInvalidID (-1) #define kDriveNameLen (32) -#define DrvSectorCnt(SIZE, SECTOR_SZ) (((SIZE) + (SECTOR_SZ)) / (SECTOR_SZ)) +#define drv_sector_cnt(SIZE, SECTOR_SZ) (((SIZE) + (SECTOR_SZ)) / (SECTOR_SZ)) namespace Kernel { enum { - /// Storage type. - kInvalidStorage = -1, + kInvalidDisc = -1, + + /// Storage types, combine with flags. kBlockDevice = 0xAD, - kMassStorage = 0xDA, + kMassStorageDisc = 0xDA, kFloppyDisc = 0xCD, kOpticalDisc = 0xDC, // CD-ROM/DVD-ROM/Blu-Ray - /// Storage flags, combine with below. - kReadOnly = 0x10, // Read only drive + 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 @@ -43,25 +46,23 @@ namespace Kernel kStorageCount = 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; + 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* packetPtr); @@ -153,4 +154,4 @@ namespace Kernel DriveTrait io_construct_main_drive(void) noexcept; } // namespace Kernel -#endif /* ifndef __INC_DRIVE_MANAGER_H__ */ +#endif /* ifndef INC_DRIVE_MANAGER_H */ diff --git a/dev/ZKAKit/KernelKit/FileMgr.h b/dev/ZKAKit/KernelKit/FileMgr.h index 9a283e9d..9b05fb09 100644 --- a/dev/ZKAKit/KernelKit/FileMgr.h +++ b/dev/ZKAKit/KernelKit/FileMgr.h @@ -17,7 +17,8 @@ ------------------------------------------- */ -#pragma once +#ifndef INC_FILEMGR_H +#define INC_FILEMGR_H #ifdef __FSKIT_INCLUDES_NEFS__ #include <FSKit/NeFS.h> @@ -210,10 +211,10 @@ namespace Kernel public: ErrorOr<Int64> WriteAll(const VoidPtr data) noexcept { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictWrite && - this->fFileRestrict != eRestrictWriteBinary) + if (this->fFileRestrict != kFileMgrRestrictReadWrite && + this->fFileRestrict != kFileMgrRestrictReadWriteBinary && + this->fFileRestrict != kFileMgrRestrictWrite && + this->fFileRestrict != kFileMgrRestrictWriteBinary) return ErrorOr<Int64>(kErrorInvalidData); if (data == nullptr) @@ -232,10 +233,10 @@ namespace Kernel VoidPtr ReadAll() noexcept { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictRead && - this->fFileRestrict != eRestrictReadBinary) + if (this->fFileRestrict != kFileMgrRestrictReadWrite && + this->fFileRestrict != kFileMgrRestrictReadWriteBinary && + this->fFileRestrict != kFileMgrRestrictRead && + this->fFileRestrict != kFileMgrRestrictReadBinary) return nullptr; auto man = FSClass::GetMounted(); @@ -251,10 +252,10 @@ namespace Kernel ErrorOr<Int64> WriteAll(const Char* fName, const VoidPtr data) noexcept { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictWrite && - this->fFileRestrict != eRestrictWriteBinary) + if (this->fFileRestrict != kFileMgrRestrictReadWrite && + this->fFileRestrict != kFileMgrRestrictReadWriteBinary && + this->fFileRestrict != kFileMgrRestrictWrite && + this->fFileRestrict != kFileMgrRestrictWriteBinary) return ErrorOr<Int64>(kErrorInvalidData); if (data == nullptr) @@ -273,10 +274,10 @@ namespace Kernel VoidPtr Read(const Char* fName) noexcept { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictRead && - this->fFileRestrict != eRestrictReadBinary) + if (this->fFileRestrict != kFileMgrRestrictReadWrite && + this->fFileRestrict != kFileMgrRestrictReadWriteBinary && + this->fFileRestrict != kFileMgrRestrictRead && + this->fFileRestrict != kFileMgrRestrictReadBinary) return nullptr; auto man = FSClass::GetMounted(); @@ -292,10 +293,10 @@ namespace Kernel VoidPtr Read(SizeT offset, SizeT sz) { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictRead && - this->fFileRestrict != eRestrictReadBinary) + if (this->fFileRestrict != kFileMgrRestrictReadWrite && + this->fFileRestrict != kFileMgrRestrictReadWriteBinary && + this->fFileRestrict != kFileMgrRestrictRead && + this->fFileRestrict != kFileMgrRestrictReadBinary) return nullptr; auto man = FSClass::GetMounted(); @@ -313,10 +314,10 @@ namespace Kernel Void Write(SizeT offset, voidPtr data, SizeT sz) { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictWrite && - this->fFileRestrict != eRestrictWriteBinary) + if (this->fFileRestrict != kFileMgrRestrictReadWrite && + this->fFileRestrict != kFileMgrRestrictReadWriteBinary && + this->fFileRestrict != kFileMgrRestrictWrite && + this->fFileRestrict != kFileMgrRestrictWriteBinary) return; auto man = FSClass::GetMounted(); @@ -340,22 +341,22 @@ namespace Kernel /// @return The MIME. Char* MIME() noexcept { - return const_cast<char*>(fMime); + return const_cast<Char*>(fMime); } enum { - eRestrictRead, - eRestrictReadBinary, - eRestrictWrite, - eRestrictWriteBinary, - eRestrictReadWrite, - eRestrictReadWriteBinary, + kFileMgrRestrictRead, + kFileMgrRestrictReadBinary, + kFileMgrRestrictWrite, + kFileMgrRestrictWriteBinary, + kFileMgrRestrictReadWrite, + kFileMgrRestrictReadWriteBinary, }; private: NodePtr fFile{nullptr}; - Int32 fFileRestrict{}; + Int32 fFileRestrict{kFileMgrRestrictReadBinary | kFileMgrRestrictRead}; const Char* fMime{kFileMimeGeneric}; }; @@ -370,37 +371,37 @@ namespace Kernel const Encoding* restrict_type) : fFile(Class::GetMounted()->Open(path, restrict_type)) { - static const auto cLength = 255; + static const auto kLength = 255U; /// @brief restrict information about the file descriptor. - struct RESTRICT_MAP final + struct FileRestrictKind final { - Char fRestrict[cLength]; - Int32 fMappedTo; + Char fRestrict[kLength] = ""; + Int32 fMappedTo{0U}; }; const SizeT kRestrictCount = kRestrictMax; - const RESTRICT_MAP kRestrictList[] = { + const FileRestrictKind kRestrictList[] = { { .fRestrict = kRestrictR, - .fMappedTo = eRestrictRead, + .fMappedTo = kFileMgrRestrictRead, }, { .fRestrict = kRestrictRB, - .fMappedTo = eRestrictReadBinary, + .fMappedTo = kFileMgrRestrictReadBinary, }, { .fRestrict = kRestrictRWB, - .fMappedTo = eRestrictReadWriteBinary, + .fMappedTo = kFileMgrRestrictReadWriteBinary, }, { .fRestrict = kRestrictW, - .fMappedTo = eRestrictWrite, + .fMappedTo = kFileMgrRestrictWrite, }, { .fRestrict = kRestrictWB, - .fMappedTo = eRestrictReadWrite, - }}; + .fMappedTo = kFileMgrRestrictReadWrite, + }}; for (SizeT index = 0; index < kRestrictCount; ++index) { @@ -415,10 +416,12 @@ namespace Kernel kcout << "new file: " << path << ".\r"; } - /// @brief destructor + /// @brief destructor of the file stream. template <typename Encoding, typename Class> FileStream<Encoding, Class>::~FileStream() { mm_delete_heap(fFile); } } // namespace Kernel + +#endif // ifndef INC_FILEMGR_H diff --git a/dev/ZKAKit/KernelKit/User.h b/dev/ZKAKit/KernelKit/User.h index 04b0cf66..997cab14 100644 --- a/dev/ZKAKit/KernelKit/User.h +++ b/dev/ZKAKit/KernelKit/User.h @@ -12,14 +12,14 @@ #include <NewKit/KString.h> #include <NewKit/Defines.h> -// user mode users. +///! We got the Super and guest user, both used to make authorization operations on the OS. #define kSuperUser "OS AUTHORITY/SUPER" #define kGuestUser "OS AUTHORITY/GUEST" #define kUsersDir "/Users/" -#define kMaxUserNameLen (255) -#define kMaxUserTokenLen (4096) +#define kMaxUserNameLen (255U) +#define kMaxUserTokenLen (255U) namespace Kernel { |
