From 4d1a1aa6862737b77f128f4d17caaa81acfe312f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 19 Apr 2025 10:10:09 +0200 Subject: dev, fs: document HeFS, add Ext2 C++ source file. Signed-off-by: Amlal El Mahrouss --- dev/kernel/FSKit/HeFS.h | 128 ++++++++++++++++++++++++++++------------------ dev/kernel/FSKit/NeFS.h | 8 +-- dev/kernel/src/FS/Ext2.cc | 22 ++++++++ 3 files changed, 105 insertions(+), 53 deletions(-) create mode 100644 dev/kernel/src/FS/Ext2.cc (limited to 'dev/kernel') diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index 8fdf933e..15ed5ac2 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -79,24 +79,29 @@ inline constexpr UInt16 kHeFSFileKindCount = 0x08; /// @details The blocks are used to store the data of a file. Each block is a pointer to a block of data on the disk. inline constexpr UInt16 kHeFSBlockCount = 0x10; +inline constexpr UInt16 kHeFSInvalidVID = 0xFFFF; + +/// @brief HeFS Boot node. +/// @details Acts like a superblock, it contains the information about the filesystem. +/// @note The boot node is the first block of the filesystem. struct PACKED HeFS_BOOT_NODE final { - Kernel::Char fMagic[kHeFSMagicLen]; - Kernel::Utf16Char fVolName[kHeFSPartNameLen]; - Kernel::UInt32 fVersion; - Kernel::UInt64 fBadSectors; - Kernel::UInt64 fSectorCount; - Kernel::UInt64 fSectorSize; - Kernel::UInt32 fChecksum; - Kernel::UInt8 fDriveKind; - Kernel::UInt8 fEncoding; - Kernel::UInt64 fStartIND; - Kernel::UInt64 fEndIND; - Kernel::UInt64 fINodeCount; - Kernel::UInt64 fDiskSize; - Kernel::UInt16 fDiskStatus; - Kernel::UInt16 fDiskFlags; - Kernel::UInt16 fVID; // virtual identification number within an EPM disk. + Kernel::Char fMagic[kHeFSMagicLen]; /// @brief Magic number of the filesystem. + Kernel::Utf16Char fVolName[kHeFSPartNameLen]; /// @brief Volume name. + Kernel::UInt32 fVersion; /// @brief Version of the filesystem. + Kernel::UInt64 fBadSectors; /// @brief Number of bad sectors in the filesystem. + Kernel::UInt64 fSectorCount; /// @brief Number of sectors in the filesystem. + Kernel::UInt64 fSectorSize; /// @brief Size of the sector. + Kernel::UInt32 fChecksum; /// @brief Checksum of the boot node. + Kernel::UInt8 fDriveKind; /// @brief Kind of the drive. (Hard Drive, Solid State Drive, Optical Drive, etc). + Kernel::UInt8 fEncoding; /// @brief Encoding of the filesystem. (UTF-8, UTF-16, etc). + Kernel::UInt64 fStartIND; /// @brief Start of the INode tree. + Kernel::UInt64 fEndIND; /// @brief End of the INode tree. + Kernel::UInt64 fINDCount; /// @brief Number of leafs in the INode tree. + Kernel::UInt64 fDiskSize; /// @brief Size of the disk. (Could be a virtual size, that is not the real size of the disk.) + Kernel::UInt16 fDiskStatus; /// @brief Status of the disk. (locked, unlocked, error, invalid). + Kernel::UInt16 fDiskFlags; /// @brief Flags of the disk. (read-only, read-write, etc). + Kernel::UInt16 fVID; /// @brief Virtual Identification Number within an EPM disk. (0xFFFF if not used). }; /// @brief Access time type. @@ -112,27 +117,26 @@ inline constexpr ATime kHeFSTimeMax = 0xFFFFFFFFFFFFFFFF; /// @note The index node is used to store the file information of a file. struct PACKED HeFS_INDEX_NODE final { - Kernel::Utf16Char fName[kHeFSFileNameLen]; - Kernel::UInt32 fFlags; - Kernel::UInt16 fKind; - Kernel::UInt32 fSize; - Kernel::UInt32 fChecksum, fRecoverChecksum, fBlockChecksum, fLinkChecksum; + Kernel::Utf16Char fName[kHeFSFileNameLen]; /// @brief File name. + Kernel::UInt32 fFlags; /// @brief File flags. + Kernel::UInt16 fKind; /// @brief File kind. (Regular, Directory, Block, Character, FIFO, Socket, Symbolic Link, Unknown). + Kernel::UInt32 fSize; /// @brief File size. + Kernel::UInt32 fChecksum, fRecoverChecksum, fBlockChecksum, fLinkChecksum; /// @brief Checksum of the file, recovery checksum, block checksum, link checksum. - ATime fCreated, fAccessed, fModified, fDeleted; - Kernel::UInt32 fUID, fGID; - Kernel::UInt32 fMode; + 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). - Kernel::UInt64 fBlockLinkStart[kHeFSBlockCount]; - Kernel::UInt64 fBlockLinkEnd[kHeFSBlockCount]; + Kernel::UInt64 fBlockLinkStart[kHeFSBlockCount]; /// @brief Start of the block link. + Kernel::UInt64 fBlockLinkEnd[kHeFSBlockCount]; /// @brief End of the block link. - Kernel::UInt64 fBlockStart[kHeFSBlockCount]; - Kernel::UInt64 fBlockEnd[kHeFSBlockCount]; + Kernel::UInt64 fBlockStart[kHeFSBlockCount]; /// @brief Start of the block. + Kernel::UInt64 fBlockEnd[kHeFSBlockCount]; /// @brief End of the block. - Kernel::UInt64 fBlockRecoveryStart[kHeFSBlockCount]; - Kernel::UInt64 fBlockRecoveryEnd[kHeFSBlockCount]; + Kernel::UInt64 fBlockRecoveryStart[kHeFSBlockCount]; /// @brief Start of the block recovery. + Kernel::UInt64 fBlockRecoveryEnd[kHeFSBlockCount]; /// @brief End of the block recovery. - /// @brief Red-black tree pointers. - Kernel::Lba fNext, fPrev, fChild, fParent; + Kernel::Lba fNext, fPrev, fChild, fParent; /// @brief Red-black tree pointers. }; /// @brief HeFS directory node. @@ -140,22 +144,21 @@ struct PACKED HeFS_INDEX_NODE final /// @note The directory node is a special type of INode that contains the directory entries. struct PACKED HeFS_INDEX_NODE_DIRECTORY final { - Kernel::Utf16Char fName[kHeFSFileNameLen]; + Kernel::Utf16Char fName[kHeFSFileNameLen]; /// @brief Directory name. - Kernel::UInt32 fFlags; - Kernel::UInt16 fKind; - Kernel::UInt32 fSize; - Kernel::UInt32 fChecksum, fIndexNodeChecksum; + Kernel::UInt32 fFlags; /// @brief File flags. + Kernel::UInt16 fKind; /// @brief File kind. (Regular, Directory, Block, Character, FIFO, Socket, Symbolic Link, Unknown). + Kernel::UInt32 fSize; /// @brief Size of the directory. + Kernel::UInt32 fChecksum, fIndexNodeChecksum; /// @brief Checksum of the file, index node checksum. - ATime fCreated, fAccessed, fModified, fDeleted; - Kernel::UInt32 fUID, fGID; - Kernel::UInt32 fMode; + 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). - Kernel::UInt64 fIndexNodeStart[kHeFSBlockCount]; - Kernel::UInt64 fIndexNodeEnd[kHeFSBlockCount]; + Kernel::UInt64 fIndexNodeStart[kHeFSBlockCount]; /// @brief Start of the index node. + Kernel::UInt64 fIndexNodeEnd[kHeFSBlockCount]; /// @brief End of the index node. - /// @brief Red-black tree pointers. - Kernel::Lba fNext, fPrev, fChild, fParent; + Kernel::Lba fNext, fPrev, fChild, fParent; /// @brief Red-black tree pointers. }; namespace Kernel::Detail @@ -166,7 +169,7 @@ namespace Kernel::Detail /// @note The year is stored in the upper 32 bits of the ATime value. inline UInt32 hefs_year_get(ATime raw_atime) noexcept { - return (raw_atime & 0x00000000FFFFFFFF) >> 32; + return (raw_atime) >> 32; } /// @brief HeFS get month from ATime. @@ -175,7 +178,7 @@ namespace Kernel::Detail /// @note The month is stored in the upper 24 bits of the ATime value. inline UInt32 hefs_month_get(ATime raw_atime) noexcept { - return (raw_atime & 0x00000000FFFFFFFF) >> 24; + return (raw_atime) >> 24; } /// @brief HeFS get day from ATime. @@ -184,7 +187,7 @@ namespace Kernel::Detail /// @note The day is stored in the upper 16 bits of the ATime value. inline UInt32 hefs_day_get(ATime raw_atime) noexcept { - return (raw_atime & 0x00000000FFFFFFFF) >> 16; + return (raw_atime) >> 16; } /// @brief HeFS get hour from ATime. @@ -193,7 +196,7 @@ namespace Kernel::Detail /// @note The hour is stored in the upper 8 bits of the ATime value. inline UInt32 hefs_hour_get(ATime raw_atime) noexcept { - return (raw_atime & 0x00000000FFFFFFFF) >> 8; + return (raw_atime) >> 8; } /// @brief HeFS get minute from ATime. @@ -202,7 +205,7 @@ namespace Kernel::Detail /// @note The minute is stored in the lower 8 bits of the ATime value. inline UInt32 hefs_minute_get(ATime raw_atime) noexcept { - return (raw_atime & 0x00000000FFFFFFFF); + return (raw_atime) & 0xFF; } inline constexpr UInt32 kHeFSBaseYear = 1970; @@ -210,4 +213,31 @@ namespace Kernel::Detail inline constexpr UInt32 kHeFSBaseDay = 1; inline constexpr UInt32 kHeFSBaseHour = 0; inline constexpr UInt32 kHeFSBaseMinute = 0; + + inline const Char* hefs_status_to_string(UInt16 status) noexcept + { + switch (status) + { + case kHeFSStatusUnlocked: return "Unlocked"; + case kHeFSStatusLocked: return "Locked"; + case kHeFSStatusError: return "Error"; + case kHeFSStatusInvalid: return "Invalid"; + default: return "Unknown"; + } + } + + inline const Char* hefs_drive_kind_to_string(UInt8 kind) noexcept + { + switch (kind) + { + case kHeFSHardDrive: return "Hard Drive"; + case kHeFSSolidStateDrive: return "Solid State Drive"; + case kHeFSOpticalDrive: return "Optical Drive"; + case kHeFSMassStorageDevice: return "Mass Storage Device"; + case kHeFSScsiDrive: return "SCSI/SAS Drive"; + case kHeFSFlashDrive: return "Flash Drive"; + case kHeFSUnknown: return "Unknown"; + default: return "Unknown"; + } + } } // namespace Kernel::Detail \ No newline at end of file diff --git a/dev/kernel/FSKit/NeFS.h b/dev/kernel/FSKit/NeFS.h index 747af16b..e4002f42 100644 --- a/dev/kernel/FSKit/NeFS.h +++ b/dev/kernel/FSKit/NeFS.h @@ -329,7 +329,7 @@ namespace Kernel /// /// \name NeFileSystemHelper - /// \brief Filesystem helper and utils. + /// \brief Filesystem helper class. /// class NeFileSystemHelper final @@ -352,11 +352,11 @@ namespace Kernel { if (!stamp) { - kout << "Invalid: Journal Stamp, using default name.\r"; + kout << "Invalid: Journal stamp, using default name.\r"; return; } - (void)(kout << "Info: Journal stamp: " << stamp << kendl); + (Void)(kout << "Info: Journal stamp: " << stamp << kendl); rt_copy_memory((VoidPtr)stamp, this->mStamp, rt_string_len(stamp)); } @@ -428,7 +428,7 @@ namespace Kernel if (!parser->CreateFork(new_fork)) return NO; - (void)(kout << "XML Commited: " << xml_data << "\r\nTo Journal Fork: " << journal_name << kendl); + (void)(kout << "XML commit: " << xml_data << " to fork: " << journal_name << kendl); auto ret = parser->WriteCatalog(new_fork.CatalogName, YES, xml_data, rt_string_len(xml_data), new_fork.ForkName); diff --git a/dev/kernel/src/FS/Ext2.cc b/dev/kernel/src/FS/Ext2.cc new file mode 100644 index 00000000..5de8c842 --- /dev/null +++ b/dev/kernel/src/FS/Ext2.cc @@ -0,0 +1,22 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#ifdef __FSKIT_INCLUDES_EXT2__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // ifdef __FSKIT_INCLUDES_EXT2__ -- cgit v1.2.3 From b1f19b23148e895d8e0e235af328a9b36f556a40 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 19 Apr 2025 13:33:35 +0200 Subject: dev, kernel, ahci: AHCI related fixes. Signed-off-by: Amlal El Mahrouss --- dev/boot/amd64-desktop.make | 4 +-- dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc | 9 ++++--- dev/kernel/HALKit/AMD64/Processor.h | 1 + dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 33 ++++++++++++++----------- dev/kernel/src/DriveMgr.cc | 1 - 5 files changed, 27 insertions(+), 21 deletions(-) (limited to 'dev/kernel') diff --git a/dev/boot/amd64-desktop.make b/dev/boot/amd64-desktop.make index 21a99941..45446333 100644 --- a/dev/boot/amd64-desktop.make +++ b/dev/boot/amd64-desktop.make @@ -119,11 +119,11 @@ run-efi-amd64-ahci: .PHONY: run-efi-amd64-ata-pio run-efi-amd64-ata-pio: - $(EMU) $(EMU_FLAGS) -device piix3-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -s -S -d int + $(EMU) $(EMU_FLAGS) -device piix3-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -s -S -d int -boot menu=on .PHONY: run-efi-amd64-ata-dma run-efi-amd64-ata-dma: - $(EMU) $(EMU_FLAGS) -device piix4-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -s -S + $(EMU) $(EMU_FLAGS) -device piix4-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -s -S -boot menu=on .PHONY: run-efi-amd64-ata run-efi-amd64-ata: run-efi-amd64-ata-dma diff --git a/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc b/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc index 16fe843a..c6c24be1 100644 --- a/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc +++ b/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc @@ -143,13 +143,14 @@ namespace Kernel::HAL pte->Wr = !!(flags & kMMFlagsWr); pte->User = !!(flags & kMMFlagsUser); pte->Nx = !!(flags & kMMFlagsNX); - pte->Pcd = !(flags & kMMFlagsPCD); - pte->PhysicalAddress = (UIntPtr)(physical_address); - - mmi_page_status(pte); + pte->Pcd = !!(flags & kMMFlagsPCD); + pte->Pwt = !!(flags & kMMFlagsPwt); + pte->PhysicalAddress = ((UIntPtr)(physical_address)); hal_invl_tlb(virtual_address); + mmi_page_status(pte); + return kErrorSuccess; } } // namespace Kernel::HAL diff --git a/dev/kernel/HALKit/AMD64/Processor.h b/dev/kernel/HALKit/AMD64/Processor.h index f2e9c2ea..13819f3e 100644 --- a/dev/kernel/HALKit/AMD64/Processor.h +++ b/dev/kernel/HALKit/AMD64/Processor.h @@ -74,6 +74,7 @@ namespace Kernel::HAL kMMFlagsUser = 1 << 3, kMMFlagsNX = 1 << 4, kMMFlagsPCD = 1 << 5, + kMMFlagsPwt = 1 << 6, kMMFlagsCount = 4, }; diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index 08fd02ab..3955dd78 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -74,10 +74,10 @@ STATIC Void drv_compute_disk_ahci() noexcept const UInt16 kSzIdent = 512; /// Push it to the stack - UInt16* identify_data = new UInt16[kSzIdent]; + UInt8* identify_data = new UInt8[kSzIdent]; /// Send AHCI command for identification. - drv_std_input_output_ahci(0, (UInt8*)identify_data, kAHCISectorSize, kSzIdent); + drv_std_input_output_ahci(0, identify_data, kAHCISectorSize, kSzIdent); /// Extract 48-bit LBA. UInt64 lba48_sectors = 0; @@ -91,7 +91,16 @@ STATIC Void drv_compute_disk_ahci() noexcept else kSATASectorCount = lba48_sectors; - (Void)(kout << "Device: " << kCurrentDiskModel << kendl); + for (Int32 i = 0; i < 20; i++) + { + kCurrentDiskModel[i * 2] = (identify_data[27 + i] >> 8) & 0xFF; + kCurrentDiskModel[i * 2 + 1] = identify_data[27 + i] & 0xFF; + } + + kCurrentDiskModel[40] = '\0'; + + (Void)(kout << "SATA Sector Count: " << hex_number(kSATASectorCount) << kendl); + (Void)(kout << "SATA Disk Model: " << kCurrentDiskModel << kendl); delete[] identify_data; identify_data = nullptr; @@ -102,17 +111,15 @@ STATIC Void drv_compute_disk_ahci() noexcept /// @return The slot, or ~0. STATIC Int32 drv_find_cmd_slot_ahci(HbaPort* port) noexcept { - UInt32 slots = (port->Sact | port->Ci); + UInt32 slots = port->Sact | port->Ci; - for (Int32 i = 0; i < kSATAPortCnt; ++i) + for (Int32 i = 0; i < kSATAPortCnt; ++i) // AHCI supports up to 32 slots { - if ((slots & 1) == 0) + if ((slots & (1U << i)) == 0) return i; - - slots >>= 1; } - return ~0; + return -1; // no free slot found } /// @brief Send an AHCI command, according to the template parameters. @@ -159,8 +166,6 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz auto ctba_phys = ((UInt64)command_header->Ctbau << 32) | command_header->Ctba; auto command_table = reinterpret_cast(ctba_phys); - rt_set_memory((HbaCmdTbl*)command_table, 0, sizeof(HbaCmdTbl) + (command_header->Prdtl - 1) * sizeof(HbaPrdtEntry)); - MUST_PASS(command_table); UIntPtr buffer_phys = HAL::hal_get_phys_address(buffer); @@ -278,12 +283,12 @@ STATIC Bool drv_std_init_ahci(UInt16& pi, BOOL& atapi) if (kSATADev.Subclass() == kSATASubClass && kSATADev.ProgIf() == kSATAProgIfAHCI) { - HbaMem* mem_ahci = (HbaMem*)kSATADev.Bar(kSATABar5); - kSATADev.EnableMmio(); kSATADev.BecomeBusMaster(); - HAL::mm_map_page((VoidPtr)mem_ahci, (VoidPtr)mem_ahci, HAL::kMMFlagsPresent | HAL::kMMFlagsWr | HAL::kMMFlagsPCD); + HbaMem* mem_ahci = (HbaMem*)kSATADev.Bar(kSATABar5); + + HAL::mm_map_page((VoidPtr)mem_ahci, (VoidPtr)mem_ahci, HAL::kMMFlagsPresent | HAL::kMMFlagsWr | HAL::kMMFlagsPCD | HAL::kMMFlagsPwt); UInt32 ports_implemented = mem_ahci->Pi; UInt16 ahci_index = 0; diff --git a/dev/kernel/src/DriveMgr.cc b/dev/kernel/src/DriveMgr.cc index f958a33f..b5a8e9e4 100644 --- a/dev/kernel/src/DriveMgr.cc +++ b/dev/kernel/src/DriveMgr.cc @@ -96,7 +96,6 @@ namespace Kernel { pckt.fPacketGood = YES; } - #endif // if defined(__ATA_PIO__) || defined (__ATA_DMA__) } -- cgit v1.2.3 From 78b14fac0eb63614c1d091f68170f5fd5d3bb9d5 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 19 Apr 2025 18:15:43 +0200 Subject: dev, kernel: Working on a 0.0.1e (for Errata) Signed-off-by: Amlal El Mahrouss --- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 1 - dev/kernel/src/Gfx/FBDeviceInterface.cc | 7 +-- dev/modules/CoreGfx/CoreWindow.h | 85 -------------------------------- 3 files changed, 2 insertions(+), 91 deletions(-) delete mode 100644 dev/modules/CoreGfx/CoreWindow.h (limited to 'dev/kernel') diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 7f3d4137..ce8c1245 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -14,7 +14,6 @@ #include #include #include -#include #include #include diff --git a/dev/kernel/src/Gfx/FBDeviceInterface.cc b/dev/kernel/src/Gfx/FBDeviceInterface.cc index c2eb2ca7..b3b52934 100644 --- a/dev/kernel/src/Gfx/FBDeviceInterface.cc +++ b/dev/kernel/src/Gfx/FBDeviceInterface.cc @@ -36,7 +36,7 @@ FBDeviceInterface& FBDeviceInterface::operator<<(FBDevicePacket* pckt) pckt->fY > kHandoverHeader->f_GOP.f_Height) return *this; - FBDrawInRegion(pckt->fColor, pckt->fHeight, pckt->fWidth, pckt->fY, pckt->fX); + this->fOut(this, pckt); return *this; } @@ -53,10 +53,7 @@ FBDeviceInterface& FBDeviceInterface::operator>>(FBDevicePacket* pckt) pckt->fY > kHandoverHeader->f_GOP.f_Height) return *this; - pckt->fColor = *(((Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + - 4 * kHandoverHeader->f_GOP.f_PixelPerLine * - pckt->fX + - 4 * pckt->fY))); + this->fIn(this, pckt); return *this; } diff --git a/dev/modules/CoreGfx/CoreWindow.h b/dev/modules/CoreGfx/CoreWindow.h deleted file mode 100644 index b1581f65..00000000 --- a/dev/modules/CoreGfx/CoreWindow.h +++ /dev/null @@ -1,85 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -/// @note this file is experimental and not used yet. -/// @file CoreWindow.h -/// @brief Core window drawing functions. - -#pragma once - -#include -#include - -namespace UI -{ - struct UIRect final - { - Kernel::UInt32 x, y, height, width; - }; - - inline void draw_beveled_rect(const UIRect& rect, Kernel::UInt32 topLeftColor, Kernel::UInt32 bottomRightColor) - { - // Top edge - FBDrawInRegion(topLeftColor, rect.height, 1, rect.y, rect.x); - // Left edge - FBDrawInRegion(topLeftColor, 1, rect.width, rect.y, rect.x); - - // Bottom edge - FBDrawInRegion(bottomRightColor, rect.height, 1, rect.y + rect.width - 1, rect.x); - // Right edge - FBDrawInRegion(bottomRightColor, 1, rect.width, rect.y, rect.x + rect.height - 1); - } - - inline void draw_close_button(Kernel::UInt32 x, Kernel::UInt32 y) - { - const Kernel::UInt32 border = fb_color(0x00, 0x00, 0x00); - const Kernel::UInt32 fill = fb_color(0xD0, 0xD0, 0xD0); - - // A simple square for close button, 10x10 px - FBDrawInRegion(border, 10, 10, y, x); // Outer border - FBDrawInRegion(fill, 8, 8, y + 1, x + 1); // Inner fill - } - - inline void draw_title_bar(const UIRect& rect, const char* title) - { - const Kernel::Int32 barHeight = 22; - - Kernel::UInt32 lightEdge = fb_color(0xF0, 0xF0, 0xF0); // Light gray top - Kernel::UInt32 darkEdge = fb_color(0x40, 0x40, 0x40); // Shadow - Kernel::UInt32 fillColor = fb_color(0xA0, 0xA0, 0xA0); // Mid-gray - - // Title bar fill - FBDrawInRegion(fillColor, rect.height - 2, barHeight, rect.y + 1, rect.x + 1); - - // Beveled edges (top, left bright; right, bottom dark) - UIRect bevel = {rect.x + 1, rect.y + 1, rect.height - 2, barHeight}; - draw_beveled_rect(bevel, lightEdge, darkEdge); - - // Title text - fb_render_string(title, rect.y + 8, rect.x + 24, fb_color(0x00, 0x00, 0x00)); - - // Close button - draw_close_button(rect.x + 6, rect.y + 6); - } - - inline void draw_window(const UIRect& rect, const Char* title) - { - Kernel::UInt32 windowFill = fb_color(0xC0, 0xC0, 0xC0); // Body color - Kernel::UInt32 borderDark = fb_color(0x60, 0x60, 0x60); - Kernel::UInt32 borderHighlight = fb_color(0xE0, 0xE0, 0xE0); - - // Fill window body (excluding title bar) - const Kernel::Int32 titleBarHeight = 22; - - FBDrawInRegion(windowFill, rect.height - 2, rect.width - titleBarHeight - 1, rect.y + titleBarHeight + 1, rect.x + 1); - - // Full window bevel border - draw_beveled_rect(rect, borderHighlight, borderDark); - - // Title bar - draw_title_bar(rect, title); - } -} \ No newline at end of file -- cgit v1.2.3 From 6402e4cdbe4a7f5189501204b151d7accde474a3 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 19 Apr 2025 18:28:18 +0200 Subject: 0.0.1e: Last commit regarding 0.0.1 Signed-off-by: Amlal El Mahrouss --- dev/kernel/FSKit/HeFS.h | 225 ++++++++++++++++++++++++++++++++++++---------- dev/kernel/FSKit/NeFS.h | 4 +- dev/kernel/src/FS/NeFS.cc | 15 +++- 3 files changed, 193 insertions(+), 51 deletions(-) (limited to 'dev/kernel') diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index 15ed5ac2..fae33072 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -86,22 +86,22 @@ inline constexpr UInt16 kHeFSInvalidVID = 0xFFFF; /// @note The boot node is the first block of the filesystem. struct PACKED HeFS_BOOT_NODE final { - Kernel::Char fMagic[kHeFSMagicLen]; /// @brief Magic number of the filesystem. + Kernel::Char fMagic[kHeFSMagicLen]; /// @brief Magic number of the filesystem. Kernel::Utf16Char fVolName[kHeFSPartNameLen]; /// @brief Volume name. - Kernel::UInt32 fVersion; /// @brief Version of the filesystem. - Kernel::UInt64 fBadSectors; /// @brief Number of bad sectors in the filesystem. - Kernel::UInt64 fSectorCount; /// @brief Number of sectors in the filesystem. - Kernel::UInt64 fSectorSize; /// @brief Size of the sector. - Kernel::UInt32 fChecksum; /// @brief Checksum of the boot node. - Kernel::UInt8 fDriveKind; /// @brief Kind of the drive. (Hard Drive, Solid State Drive, Optical Drive, etc). - Kernel::UInt8 fEncoding; /// @brief Encoding of the filesystem. (UTF-8, UTF-16, etc). - Kernel::UInt64 fStartIND; /// @brief Start of the INode tree. - Kernel::UInt64 fEndIND; /// @brief End of the INode tree. - Kernel::UInt64 fINDCount; /// @brief Number of leafs in the INode tree. - Kernel::UInt64 fDiskSize; /// @brief Size of the disk. (Could be a virtual size, that is not the real size of the disk.) - Kernel::UInt16 fDiskStatus; /// @brief Status of the disk. (locked, unlocked, error, invalid). - Kernel::UInt16 fDiskFlags; /// @brief Flags of the disk. (read-only, read-write, etc). - Kernel::UInt16 fVID; /// @brief Virtual Identification Number within an EPM disk. (0xFFFF if not used). + Kernel::UInt32 fVersion; /// @brief Version of the filesystem. + Kernel::UInt64 fBadSectors; /// @brief Number of bad sectors in the filesystem. + Kernel::UInt64 fSectorCount; /// @brief Number of sectors in the filesystem. + Kernel::UInt64 fSectorSize; /// @brief Size of the sector. + Kernel::UInt32 fChecksum; /// @brief Checksum of the boot node. + Kernel::UInt8 fDriveKind; /// @brief Kind of the drive. (Hard Drive, Solid State Drive, Optical Drive, etc). + Kernel::UInt8 fEncoding; /// @brief Encoding of the filesystem. (UTF-8, UTF-16, etc). + Kernel::UInt64 fStartIND; /// @brief Start of the INode tree. + Kernel::UInt64 fEndIND; /// @brief End of the INode tree. + Kernel::UInt64 fINDCount; /// @brief Number of leafs in the INode tree. + Kernel::UInt64 fDiskSize; /// @brief Size of the disk. (Could be a virtual size, that is not the real size of the disk.) + Kernel::UInt16 fDiskStatus; /// @brief Status of the disk. (locked, unlocked, error, invalid). + Kernel::UInt16 fDiskFlags; /// @brief Flags of the disk. (read-only, read-write, etc). + Kernel::UInt16 fVID; /// @brief Virtual Identification Number within an EPM disk. (0xFFFF if not used). }; /// @brief Access time type. @@ -117,24 +117,24 @@ inline constexpr ATime kHeFSTimeMax = 0xFFFFFFFFFFFFFFFF; /// @note The index node is used to store the file information of a file. struct PACKED HeFS_INDEX_NODE final { - Kernel::Utf16Char fName[kHeFSFileNameLen]; /// @brief File name. - Kernel::UInt32 fFlags; /// @brief File flags. - Kernel::UInt16 fKind; /// @brief File kind. (Regular, Directory, Block, Character, FIFO, Socket, Symbolic Link, Unknown). - Kernel::UInt32 fSize; /// @brief File size. + Kernel::Utf16Char fName[kHeFSFileNameLen]; /// @brief File name. + Kernel::UInt32 fFlags; /// @brief File flags. + Kernel::UInt16 fKind; /// @brief File kind. (Regular, Directory, Block, Character, FIFO, Socket, Symbolic Link, Unknown). + Kernel::UInt32 fSize; /// @brief File size. Kernel::UInt32 fChecksum, fRecoverChecksum, fBlockChecksum, fLinkChecksum; /// @brief Checksum of the file, recovery checksum, block checksum, link checksum. 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). + Kernel::UInt32 fUID, fGID; /// @brief User ID and Group ID of the file. + Kernel::UInt32 fMode; /// @brief File mode. (read, write, execute, etc). Kernel::UInt64 fBlockLinkStart[kHeFSBlockCount]; /// @brief Start of the block link. - Kernel::UInt64 fBlockLinkEnd[kHeFSBlockCount]; /// @brief End of the block link. + Kernel::UInt64 fBlockLinkEnd[kHeFSBlockCount]; /// @brief End of the block link. Kernel::UInt64 fBlockStart[kHeFSBlockCount]; /// @brief Start of the block. - Kernel::UInt64 fBlockEnd[kHeFSBlockCount]; /// @brief End of the block. + Kernel::UInt64 fBlockEnd[kHeFSBlockCount]; /// @brief End of the block. Kernel::UInt64 fBlockRecoveryStart[kHeFSBlockCount]; /// @brief Start of the block recovery. - Kernel::UInt64 fBlockRecoveryEnd[kHeFSBlockCount]; /// @brief End of the block recovery. + Kernel::UInt64 fBlockRecoveryEnd[kHeFSBlockCount]; /// @brief End of the block recovery. Kernel::Lba fNext, fPrev, fChild, fParent; /// @brief Red-black tree pointers. }; @@ -146,17 +146,17 @@ struct PACKED HeFS_INDEX_NODE_DIRECTORY final { Kernel::Utf16Char fName[kHeFSFileNameLen]; /// @brief Directory name. - Kernel::UInt32 fFlags; /// @brief File flags. - Kernel::UInt16 fKind; /// @brief File kind. (Regular, Directory, Block, Character, FIFO, Socket, Symbolic Link, Unknown). - Kernel::UInt32 fSize; /// @brief Size of the directory. + Kernel::UInt32 fFlags; /// @brief File flags. + Kernel::UInt16 fKind; /// @brief File kind. (Regular, Directory, Block, Character, FIFO, Socket, Symbolic Link, Unknown). + Kernel::UInt32 fSize; /// @brief Size of the directory. Kernel::UInt32 fChecksum, fIndexNodeChecksum; /// @brief Checksum of the file, index node checksum. 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). + Kernel::UInt32 fUID, fGID; /// @brief User ID and Group ID of the file. + Kernel::UInt32 fMode; /// @brief File mode. (read, write, execute, etc). Kernel::UInt64 fIndexNodeStart[kHeFSBlockCount]; /// @brief Start of the index node. - Kernel::UInt64 fIndexNodeEnd[kHeFSBlockCount]; /// @brief End of the index node. + Kernel::UInt64 fIndexNodeEnd[kHeFSBlockCount]; /// @brief End of the index node. Kernel::Lba fNext, fPrev, fChild, fParent; /// @brief Red-black tree pointers. }; @@ -205,24 +205,29 @@ namespace Kernel::Detail /// @note The minute is stored in the lower 8 bits of the ATime value. inline UInt32 hefs_minute_get(ATime raw_atime) noexcept { - return (raw_atime) & 0xFF; + return (raw_atime)&0xFF; } - inline constexpr UInt32 kHeFSBaseYear = 1970; - inline constexpr UInt32 kHeFSBaseMonth = 1; - inline constexpr UInt32 kHeFSBaseDay = 1; - inline constexpr UInt32 kHeFSBaseHour = 0; + inline constexpr UInt32 kHeFSBaseYear = 1970; + inline constexpr UInt32 kHeFSBaseMonth = 1; + inline constexpr UInt32 kHeFSBaseDay = 1; + inline constexpr UInt32 kHeFSBaseHour = 0; inline constexpr UInt32 kHeFSBaseMinute = 0; inline const Char* hefs_status_to_string(UInt16 status) noexcept { switch (status) { - case kHeFSStatusUnlocked: return "Unlocked"; - case kHeFSStatusLocked: return "Locked"; - case kHeFSStatusError: return "Error"; - case kHeFSStatusInvalid: return "Invalid"; - default: return "Unknown"; + case kHeFSStatusUnlocked: + return "Unlocked"; + case kHeFSStatusLocked: + return "Locked"; + case kHeFSStatusError: + return "Error"; + case kHeFSStatusInvalid: + return "Invalid"; + default: + return "Unknown"; } } @@ -230,14 +235,136 @@ namespace Kernel::Detail { switch (kind) { - case kHeFSHardDrive: return "Hard Drive"; - case kHeFSSolidStateDrive: return "Solid State Drive"; - case kHeFSOpticalDrive: return "Optical Drive"; - case kHeFSMassStorageDevice: return "Mass Storage Device"; - case kHeFSScsiDrive: return "SCSI/SAS Drive"; - case kHeFSFlashDrive: return "Flash Drive"; - case kHeFSUnknown: return "Unknown"; - default: return "Unknown"; + case kHeFSHardDrive: + return "Hard Drive"; + case kHeFSSolidStateDrive: + return "Solid State Drive"; + case kHeFSOpticalDrive: + return "Optical Drive"; + case kHeFSMassStorageDevice: + return "Mass Storage Device"; + case kHeFSScsiDrive: + return "SCSI/SAS Drive"; + case kHeFSFlashDrive: + return "Flash Drive"; + case kHeFSUnknown: + return "Unknown"; + default: + return "Unknown"; } } -} // namespace Kernel::Detail \ No newline at end of file + + inline const Char* hefs_encoding_to_string(UInt8 encoding) noexcept + { + switch (encoding) + { + case kHeFSEncodingUTF8: + return "UTF-8"; + case kHeFSEncodingUTF16: + return "UTF-16"; + case kHeFSEncodingUTF32: + return "UTF-32"; + case kHeFSEncodingUTF16BE: + return "UTF-16BE"; + case kHeFSEncodingUTF16LE: + return "UTF-16LE"; + case kHeFSEncodingUTF32BE: + return "UTF-32BE"; + case kHeFSEncodingUTF32LE: + return "UTF-32LE"; + case kHeFSEncodingUTF8BE: + return "UTF-8BE"; + case kHeFSEncodingUTF8LE: + return "UTF-8LE"; + default: + return "Unknown"; + } + } + + inline const Char* hefs_file_kind_to_string(UInt16 kind) noexcept + { + switch (kind) + { + case kHeFSFileKindRegular: + return "Regular File"; + case kHeFSFileKindDirectory: + return "Directory"; + case kHeFSFileKindBlock: + return "Block Device"; + case kHeFSFileKindCharacter: + return "Character Device"; + case kHeFSFileKindFIFO: + return "FIFO"; + case kHeFSFileKindSocket: + return "Socket"; + case kHeFSFileKindSymbolicLink: + return "Symbolic Link"; + case kHeFSFileKindUnknown: + return "Unknown"; + default: + return "Unknown"; + } + } + + inline const Char* hefs_file_flags_to_string(UInt32 flags) noexcept + { + switch (flags) + { + case 0x00: + return "No Flags"; + case 0x01: + return "Read Only"; + case 0x02: + return "Hidden"; + case 0x04: + return "System"; + case 0x08: + return "Archive"; + case 0x10: + return "Device"; + default: + return "Unknown"; + } + } + + inline Lba hefs_get_block_size(Lba block_size) noexcept + { + return block_size * kHeFSBlockCount; + } + + inline Lba hefs_get_block_count(Lba block_size, Lba block_count) noexcept + { + return block_size / block_count; + } +} // namespace Kernel::Detail + +namespace Kernel +{ + class HeFSFileSystemParser final + { + public: + HeFSFileSystemParser() = default; + ~HeFSFileSystemParser() = default; + + public: + HeFSFileSystemParser(const HeFSFileSystemParser&) = delete; + HeFSFileSystemParser& operator=(const HeFSFileSystemParser&) = delete; + + HeFSFileSystemParser(HeFSFileSystemParser&&) = delete; + HeFSFileSystemParser& operator=(HeFSFileSystemParser&&) = delete; + + public: + /// @brief Make a EPM+HeFS drive out of the disk. + /// @param drive The drive to write on. + /// @return If it was sucessful, see err_local_get(). + _Output Bool FormatEPM(_Input _Output DriveTrait* drive, _Input const Lba end_lba, _Input const Int32 flags, const Char* part_name); + + /// @brief Make a GPT+HeFS drive out of the disk. + /// @param drive The drive to write on. + /// @return If it was sucessful, see err_local_get(). + _Output Bool FormatGPT(_Input _Output DriveTrait* drive, _Input const Lba end_lba, _Input const Int32 flags, const Char* part_name); + + public: + UInt32 mDriveIndex{MountpointInterface::kDriveIndexA}; /// @brief Drive index. + }; +} // namespace Kernel \ No newline at end of file diff --git a/dev/kernel/FSKit/NeFS.h b/dev/kernel/FSKit/NeFS.h index e4002f42..4f4151d7 100644 --- a/dev/kernel/FSKit/NeFS.h +++ b/dev/kernel/FSKit/NeFS.h @@ -321,7 +321,9 @@ namespace Kernel /// @brief Make a EPM+NeFS drive out of the disk. /// @param drive The drive to write on. /// @return If it was sucessful, see err_local_get(). - _Output Bool Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name); + _Output Bool FormatEPM(_Input _Output DriveTrait* drive, _Input const Lba end_lba, _Input const Int32 flags, const Char* part_name); + + _Output Bool FormatGPT(_Input _Output DriveTrait* drive, _Input const Lba end_lba, _Input const Int32 flags, const Char* part_name); public: UInt32 mDriveIndex{kNeFSSubDriveA}; diff --git a/dev/kernel/src/FS/NeFS.cc b/dev/kernel/src/FS/NeFS.cc index 8bbec1d2..9cab99c5 100644 --- a/dev/kernel/src/FS/NeFS.cc +++ b/dev/kernel/src/FS/NeFS.cc @@ -4,6 +4,7 @@ ------------------------------------------- */ +#include "NewKit/Macros.h" #ifdef __FSKIT_INCLUDES_NEFS__ #include @@ -454,10 +455,22 @@ _Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char return nullptr; } +_Output Bool NeFileSystemParser::FormatGPT(_Input _Output DriveTrait* drive, _Input const Lba end_lba, _Input const Int32 flags, const Char* part_name) +{ + NE_UNUSED(drive); + NE_UNUSED(end_lba); + NE_UNUSED(flags); + NE_UNUSED(part_name); + + (void)(kout << "FormatGPT: Not implemented yet.\r"); + + return NO; +} + /// @brief Make a EPM+NeFS drive out of the disk. /// @param drive The drive to write on. /// @return If it was sucessful, see err_global_get(). -bool NeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name) +bool NeFileSystemParser::FormatEPM(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name) { if (*part_name == 0 || endLba == 0) -- cgit v1.2.3