From fb790b07aeba8e22e4190cf3e1834d11ecde6c96 Mon Sep 17 00:00:00 2001 From: Amlal Date: Fri, 25 Apr 2025 13:08:33 +0200 Subject: dev: better .clang-format, ran format command. Signed-off-by: Amlal --- dev/kernel/KernelKit/DeviceMgr.h | 207 ++++++++++++++++++--------------------- 1 file changed, 93 insertions(+), 114 deletions(-) (limited to 'dev/kernel/KernelKit/DeviceMgr.h') diff --git a/dev/kernel/KernelKit/DeviceMgr.h b/dev/kernel/KernelKit/DeviceMgr.h index 9cfc54dd..8da52699 100644 --- a/dev/kernel/KernelKit/DeviceMgr.h +++ b/dev/kernel/KernelKit/DeviceMgr.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ @@ -8,8 +8,8 @@ Revision History: - 31/01/24: Add kDeviceCnt (amlel) - 15/11/24: Add NE_DEVICE macro, to inherit from device object. + 31/01/24: Add kDeviceCnt (amlel) + 15/11/24: Add NE_DEVICE macro, to inherit from device object. ------------------------------------------- */ @@ -28,114 +28,93 @@ // Last Rev: Wed, Apr 3, 2024 9:09:41 AM -namespace Kernel -{ - template - class IDeviceObject; - - /***********************************************************************************/ - /// @brief Device contract interface, represents an HW device. - /***********************************************************************************/ - template - class IDeviceObject - { - public: - explicit IDeviceObject(void (*Out)(IDeviceObject*, T), void (*In)(IDeviceObject*, T)) - : fOut(Out), fIn(In) - { - } - - virtual ~IDeviceObject() = default; - - public: - IDeviceObject& operator=(const IDeviceObject&) = default; - IDeviceObject(const IDeviceObject&) = default; - - public: - virtual IDeviceObject& operator<<(T Data) - { - fOut(this, Data); - return *this; - } - - virtual IDeviceObject& operator>>(T Data) - { - fIn(this, Data); - return *this; - } - - virtual const char* Name() const - { - return "/dev/null"; - } - - operator bool() - { - return fOut && fIn; - } - - Bool operator!() - { - return !fOut || !fIn; - } - - protected: - Void (*fOut)(IDeviceObject*, T Data) = {nullptr}; - Void (*fIn)(IDeviceObject*, T Data) = {nullptr}; - }; - - /// - /// @brief Input Output abstract class. - /// Used mainly to communicate between OS to hardware. - /// - template - class IOBuf final - { - public: - explicit IOBuf(T dma_addr) - : fData(dma_addr) - { - // At least pass something valid when instancating this struct. - MUST_PASS(fData); - } - - IOBuf& operator=(const IOBuf&) = default; - IOBuf(const IOBuf&) = default; - - ~IOBuf() = default; - - public: - template - R operator->() const - { - return fData; - } - - template - R& operator[](Size index) const - { - return fData[index]; - } - - private: - T fData; - }; - - ///! @brief Device enum types. - enum - { - kDeviceTypeIDE, - kDeviceTypeEthernet, - kDeviceTypeWiFi, - kDeviceTypeFW, - kDeviceTypeBT, - kDeviceTypeRS232, - kDeviceTypeSCSI, - kDeviceTypeAHCI, - kDeviceTypeMBCI, - kDeviceTypeATA, - kDeviceTypeUSB, - kDeviceTypeMediaCtrl, // MM controller - kDeviceTypeCount, - }; -} // namespace Kernel +namespace Kernel { +template +class IDeviceObject; + +/***********************************************************************************/ +/// @brief Device contract interface, represents an HW device. +/***********************************************************************************/ +template +class IDeviceObject { + public: + explicit IDeviceObject(void (*Out)(IDeviceObject*, T), void (*In)(IDeviceObject*, T)) + : fOut(Out), fIn(In) {} + + virtual ~IDeviceObject() = default; + + public: + IDeviceObject& operator=(const IDeviceObject&) = default; + IDeviceObject(const IDeviceObject&) = default; + + public: + virtual IDeviceObject& operator<<(T Data) { + fOut(this, Data); + return *this; + } + + virtual IDeviceObject& operator>>(T Data) { + fIn(this, Data); + return *this; + } + + virtual const char* Name() const { return "/dev/null"; } + + operator bool() { return fOut && fIn; } + + Bool operator!() { return !fOut || !fIn; } + + protected: + Void (*fOut)(IDeviceObject*, T Data) = {nullptr}; + Void (*fIn)(IDeviceObject*, T Data) = {nullptr}; +}; + +/// +/// @brief Input Output abstract class. +/// Used mainly to communicate between OS to hardware. +/// +template +class IOBuf final { + public: + explicit IOBuf(T dma_addr) : fData(dma_addr) { + // At least pass something valid when instancating this struct. + MUST_PASS(fData); + } + + IOBuf& operator=(const IOBuf&) = default; + IOBuf(const IOBuf&) = default; + + ~IOBuf() = default; + + public: + template + R operator->() const { + return fData; + } + + template + R& operator[](Size index) const { + return fData[index]; + } + + private: + T fData; +}; + +///! @brief Device enum types. +enum { + kDeviceTypeIDE, + kDeviceTypeEthernet, + kDeviceTypeWiFi, + kDeviceTypeFW, + kDeviceTypeBT, + kDeviceTypeRS232, + kDeviceTypeSCSI, + kDeviceTypeAHCI, + kDeviceTypeMBCI, + kDeviceTypeATA, + kDeviceTypeUSB, + kDeviceTypeMediaCtrl, // MM controller + kDeviceTypeCount, +}; +} // namespace Kernel -- cgit v1.2.3 From 9c33e844d76f9db6d7110de4f05cbe2084cdbca1 Mon Sep 17 00:00:00 2001 From: Amlal Date: Sat, 26 Apr 2025 13:44:35 +0200 Subject: dev, kernel and user: codebase additions and work in progress 'tactical pause' why? - HeFS's Formating needs some thought before being layed out, that's the kind of thing that bites hard in the ass. - Alongside those changes I improved parts of the kernel too. Signed-off-by: Amlal --- dev/kernel/FSKit/HeFS.h | 10 ++++++ dev/kernel/KernelKit/DeviceMgr.h | 4 +-- dev/kernel/src/DriveMgr.cc | 2 +- dev/kernel/src/FS/HeFS.cc | 51 +++++++++++++++++++++++---- dev/kernel/src/Gfx/FBDeviceInterface.cc | 10 ++---- dev/kernel/src/Storage/AHCIDeviceInterface.cc | 2 +- dev/kernel/src/Storage/ATADeviceInterface.cc | 2 +- dev/kernel/src/Storage/NVMEDeviceInterface.cc | 2 +- dev/user/SystemCalls.h | 10 ++++++ 9 files changed, 73 insertions(+), 20 deletions(-) (limited to 'dev/kernel/KernelKit/DeviceMgr.h') diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index 895422a6..693ec2d3 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -28,6 +28,9 @@ #define kHeFSDefaultVoluneName u"HeFS Volume" +#define kHeFSDIMBootDir u"boot-x/dir" +#define kHeFSDIMBootFile u"boot-x/file" + #define kHeFSSearchAllStr u"*" struct HEFS_BOOT_NODE; @@ -63,6 +66,7 @@ enum { kHeFSEncodingUTF32LE, kHeFSEncodingUTF8BE, kHeFSEncodingUTF8LE, + kHeFSEncodingBinary, kHeFSEncodingCount, }; @@ -135,6 +139,10 @@ struct PACKED ALIGN(8) HEFS_INDEX_NODE final { fLinkChecksum; /// @brief Checksum of the file, recovery checksum, block checksum, link /// checksum. + Kernel::Utf16Char fMime[kHeFSFileNameLen]; /// @brief File mime type. + + Kernel::Boolean fSymLink; /// @brief Is this a symbolic link? (if yes, the fName is the path to the file and blocklinkstart and end contains it's inodes.) + Kernel::ATime fCreated, fAccessed, fModified, fDeleted; /// @brief File timestamps. Kernel::UInt32 fUID, fGID; /// @brief User ID and Group ID of the file. Kernel::UInt32 fMode; /// @brief File mode. (read, write, execute, etc). @@ -168,6 +176,8 @@ struct PACKED ALIGN(8) HEFS_INDEX_NODE_DIRECTORY final { Kernel::UInt32 fChecksum, fIndexNodeChecksum; /// @brief Checksum of the file, index node checksum. + Kernel::Utf16Char fDim[kHeFSFileNameLen]; /// @brief Directiory Immatriculation magic. + Kernel::ATime fCreated, fAccessed, fModified, fDeleted; /// @brief File timestamps and allocation status. Kernel::UInt32 fUID, fGID; /// @brief User ID and Group ID of the file. Kernel::UInt32 fMode; /// @brief File mode. (read, write, execute, etc). diff --git a/dev/kernel/KernelKit/DeviceMgr.h b/dev/kernel/KernelKit/DeviceMgr.h index 8da52699..210cef2a 100644 --- a/dev/kernel/KernelKit/DeviceMgr.h +++ b/dev/kernel/KernelKit/DeviceMgr.h @@ -22,7 +22,7 @@ #include #include -#define kDeviceMgrRootDirPath "/dev/" +#define kDeviceMgrRootDirPath "/devices/" #define NE_DEVICE : public ::Kernel::IDeviceObject @@ -58,7 +58,7 @@ class IDeviceObject { return *this; } - virtual const char* Name() const { return "/dev/null"; } + virtual const char* Name() const { return "/devices/null"; } operator bool() { return fOut && fIn; } diff --git a/dev/kernel/src/DriveMgr.cc b/dev/kernel/src/DriveMgr.cc index 17c6c8cc..46a5c588 100644 --- a/dev/kernel/src/DriveMgr.cc +++ b/dev/kernel/src/DriveMgr.cc @@ -25,7 +25,7 @@ STATIC UInt8 kATAMaster = 0U; #endif #if defined(__AHCI__) -STATIC UInt16 kAHCIPortsImplemented = 0UL; +STATIC UInt16 kAHCIPortsImplemented [[maybe_unused]] = 0UL; #endif /// @brief reads from an ATA drive. diff --git a/dev/kernel/src/FS/HeFS.cc b/dev/kernel/src/FS/HeFS.cc index 1da886c4..81316ba5 100644 --- a/dev/kernel/src/FS/HeFS.cc +++ b/dev/kernel/src/FS/HeFS.cc @@ -756,7 +756,7 @@ namespace Kernel::HeFS { /// @param drive The drive to write on. /// @return If it was sucessful, see err_local_get(). _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input const Int32 flags, - const Utf16Char* part_name) { + _Input const Utf16Char* part_name) { NE_UNUSED(drive); NE_UNUSED(flags); NE_UNUSED(part_name); @@ -779,6 +779,34 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input rt_set_memory(root, 0, sizeof(HEFS_BOOT_NODE)); + drive->fPacket.fPacketLba = drive->fLbaStart; + drive->fPacket.fPacketSize = sizeof(HEFS_BOOT_NODE); + drive->fPacket.fPacketContent = root; + + drive->fInput(drive->fPacket); + + if (!drive->fPacket.fPacketGood) { + delete root; + root = nullptr; + + err_global_get() = kErrorDiskIsCorrupted; + + return NO; + } + + // Check if the disk is already formatted. + + if (KStringBuilder::Equals(root->fMagic, kHeFSMagic)) { + delete root; + root = nullptr; + + err_global_get() = kErrorSuccess; + + return YES; + } + + rt_set_memory(root, 0, sizeof(HEFS_BOOT_NODE)); + rt_copy_memory((VoidPtr) "fs/hefs-packet", drive->fPacket.fPacketMime, rt_string_len("fs/hefs-packet")); @@ -836,9 +864,10 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input rt_set_memory(root_dir, 0, sizeof(HEFS_INDEX_NODE_DIRECTORY)); wrt_copy_memory((VoidPtr) u"/", root_dir->fName, wrt_string_len(u"/")); + wrt_copy_memory((VoidPtr) kHeFSDIMBootDir, root_dir->fDim, wrt_string_len(kHeFSDIMBootDir)); root_dir->fKind = kHeFSFileKindDirectory; - root_dir->fColor = kHeFSBlack; + root_dir->fColor = kHeFSBlack; // Every RB-Tree root starts black. (a condition of the algorithm) root_dir->fParent = 0; // No parent (it's the real root) root_dir->fChild = 0; // No children yet root_dir->fNext = 0; // No next @@ -858,6 +887,19 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input root = nullptr; root_dir = nullptr; + // Create the directories, something UNIX inspired but more explicit and forward looking. + + this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/boot"); + this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/netdevices"); + this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/binaries"); + this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/users"); + this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/config"); + this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/config/xml"); + this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/config/json"); + this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/devices"); + this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/media"); + this->CreateFile(drive, kHeFSEncodingBinary, u"/", u"mk.hefs"); + if (drive->fPacket.fPacketGood) return YES; err_global_get() = kErrorDiskIsCorrupted; @@ -1036,7 +1078,7 @@ _Output Bool HeFileSystemParser::CreateFile(_Input DriveTrait* drive, _Input con } Boolean fs_init_hefs(Void) noexcept { - kout << "Creating main disk...\r"; + kout << "Creating main disk with HeFS in it...\r"; auto drv = io_construct_main_drive(); @@ -1047,9 +1089,6 @@ Boolean fs_init_hefs(Void) noexcept { parser.Format(&drv, kHeFSEncodingUTF16, kHeFSDefaultVoluneName); - parser.CreateDirectory(&drv, kHeFSEncodingUTF16, u"boot"); - parser.CreateFile(&drv, kHeFSEncodingUTF16, u"boot", u".hefs"); - return YES; } } // namespace Kernel::HeFS diff --git a/dev/kernel/src/Gfx/FBDeviceInterface.cc b/dev/kernel/src/Gfx/FBDeviceInterface.cc index 185b22b0..be52655d 100644 --- a/dev/kernel/src/Gfx/FBDeviceInterface.cc +++ b/dev/kernel/src/Gfx/FBDeviceInterface.cc @@ -27,9 +27,6 @@ FBDeviceInterface& FBDeviceInterface::operator<<(FBDevicePacket* pckt) { if (pckt->fHeight == 0 || pckt->fWidth == 0) return *this; - if (pckt->fX > kHandoverHeader->f_GOP.f_Width || pckt->fY > kHandoverHeader->f_GOP.f_Height) - return *this; - this->fOut(this, pckt); return *this; @@ -40,10 +37,7 @@ FBDeviceInterface& FBDeviceInterface::operator<<(FBDevicePacket* pckt) { /// @return the class itself after operation. FBDeviceInterface& FBDeviceInterface::operator>>(FBDevicePacket* pckt) { if (!pckt) return *this; - - if (pckt->fX > kHandoverHeader->f_GOP.f_Width || pckt->fY > kHandoverHeader->f_GOP.f_Height) - return *this; - + this->fIn(this, pckt); return *this; @@ -52,5 +46,5 @@ FBDeviceInterface& FBDeviceInterface::operator>>(FBDevicePacket* pckt) { /// @brief Returns the name of the device interface. /// @return it's name as a string. const Char* FBDeviceInterface::Name() const { - return "/dev/fb{}"; + return "/devices/fb{}"; } \ No newline at end of file diff --git a/dev/kernel/src/Storage/AHCIDeviceInterface.cc b/dev/kernel/src/Storage/AHCIDeviceInterface.cc index d5c1e5c6..2d97eee7 100644 --- a/dev/kernel/src/Storage/AHCIDeviceInterface.cc +++ b/dev/kernel/src/Storage/AHCIDeviceInterface.cc @@ -24,7 +24,7 @@ AHCIDeviceInterface::~AHCIDeviceInterface() = default; /// @brief Returns the name of the device interface. /// @return it's name as a string. const Char* AHCIDeviceInterface::Name() const { - return "/dev/sda{}"; + return "/devices/sda{}"; } /// @brief Output operator. diff --git a/dev/kernel/src/Storage/ATADeviceInterface.cc b/dev/kernel/src/Storage/ATADeviceInterface.cc index f38d5359..a66d812b 100644 --- a/dev/kernel/src/Storage/ATADeviceInterface.cc +++ b/dev/kernel/src/Storage/ATADeviceInterface.cc @@ -22,7 +22,7 @@ ATADeviceInterface::~ATADeviceInterface() = default; /// @brief Returns the name of the device interface. /// @return it's name as a string. const Char* ATADeviceInterface::Name() const { - return "/dev/hda{}"; + return "/devices/hda{}"; } /// @brief Output operator. diff --git a/dev/kernel/src/Storage/NVMEDeviceInterface.cc b/dev/kernel/src/Storage/NVMEDeviceInterface.cc index edec6d6d..cff776c9 100644 --- a/dev/kernel/src/Storage/NVMEDeviceInterface.cc +++ b/dev/kernel/src/Storage/NVMEDeviceInterface.cc @@ -18,6 +18,6 @@ NVMEDeviceInterface::~NVMEDeviceInterface() { } const Char* NVMEDeviceInterface::Name() const { - return ("/dev/nvme{}"); + return ("/devices/nvme{}"); } } // namespace Kernel diff --git a/dev/user/SystemCalls.h b/dev/user/SystemCalls.h index 1e391d8a..4ff7de11 100644 --- a/dev/user/SystemCalls.h +++ b/dev/user/SystemCalls.h @@ -60,6 +60,16 @@ IMPORT_C Ref IoOpenFile(const Char* fs_path, const Char* drive_letter); /// @return Function doesn't return a type. IMPORT_C Void IoCloseFile(_Input Ref file_desc); +/// @brief I/O control (ioctl) on a file. +/// @param file_desc the file descriptor. +/// @param ioctl_code the ioctl code. +/// @param in_data the input data. +/// @param out_data the output data. +/// @return the number of bytes written. +/// @note This function is used to control the file descriptor, introduced for HeFS. +IMPORT_C SInt32 IoCTLFile(_Input Ref file_desc, _Input UInt32 ioctl_code, _Input VoidPtr in_data, + _Output VoidPtr out_data); + /// @brief Gets the file mime (if any) /// @param file_desc the file descriptor. IMPORT_C const Char* IoMimeFile(_Input Ref file_desc); -- cgit v1.2.3