diff options
Diffstat (limited to 'dev/kernel')
| -rw-r--r-- | dev/kernel/FSKit/HeFS.h | 7 | ||||
| -rw-r--r-- | dev/kernel/NewKit/KString.h | 1 | ||||
| -rw-r--r-- | dev/kernel/amd64-desktop.make | 2 | ||||
| -rw-r--r-- | dev/kernel/src/FS/Ext2.cc | 1 | ||||
| -rw-r--r-- | dev/kernel/src/FS/HeFS.cc | 134 | ||||
| -rw-r--r-- | dev/kernel/src/KString.cc | 12 |
6 files changed, 148 insertions, 9 deletions
diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index 41ae615a..b1a0d1d6 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -327,15 +327,10 @@ namespace Kernel::Detail }
}
- inline Lba hefs_get_block_size(Lba block_size) noexcept
+ inline SizeT hefs_get_block_size(SizeT 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
diff --git a/dev/kernel/NewKit/KString.h b/dev/kernel/NewKit/KString.h index 938096d5..e182fd30 100644 --- a/dev/kernel/NewKit/KString.h +++ b/dev/kernel/NewKit/KString.h @@ -89,6 +89,7 @@ namespace Kernel static const Char* FromBool(const Char* fmt, bool n); static const Char* Format(const Char* fmt, const Char* from); static bool Equals(const Char* lhs, const Char* rhs); + static bool Equals(const Utf16Char* lhs, const Utf16Char* rhs); static bool Equals(const WideChar* lhs, const WideChar* rhs); }; } // namespace Kernel diff --git a/dev/kernel/amd64-desktop.make b/dev/kernel/amd64-desktop.make index 9993796c..714b045d 100644 --- a/dev/kernel/amd64-desktop.make +++ b/dev/kernel/amd64-desktop.make @@ -5,7 +5,7 @@ CXX = x86_64-w64-mingw32-g++ LD = x86_64-w64-mingw32-ld -CCFLAGS = -fshort-wchar -c -D__NE_AMD64__ -Wall -Wpedantic -Wextra -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__NE_SUPPORT_NX__ -O0 -I../vendor -D__FSKIT_INCLUDES_NEFS__ -D__NEOSKRNL__ -D__HAVE_NE_APIS__ -D__FREESTANDING__ -D__NE_VIRTUAL_MEMORY_SUPPORT__ -D__NE_AUTO_FORMAT__ -D__NE__ -I./ -I../ -I../boot +CCFLAGS = -fshort-wchar -c -D__NE_AMD64__ -Wall -Wpedantic -Wextra -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__FSKIT_INCLUDES_HeFS__ -D__NE_SUPPORT_NX__ -O0 -I../vendor -D__FSKIT_INCLUDES_NEFS__ -D__NEOSKRNL__ -D__HAVE_NE_APIS__ -D__FREESTANDING__ -D__NE_VIRTUAL_MEMORY_SUPPORT__ -D__NE_AUTO_FORMAT__ -D__NE__ -I./ -I../ -I../boot ASM = nasm diff --git a/dev/kernel/src/FS/Ext2.cc b/dev/kernel/src/FS/Ext2.cc index 5de8c842..8331f506 100644 --- a/dev/kernel/src/FS/Ext2.cc +++ b/dev/kernel/src/FS/Ext2.cc @@ -8,7 +8,6 @@ #include <modules/AHCI/AHCI.h> #include <modules/ATA/ATA.h> -#include <modules/Flash/Flash.h> #include <FSKit/Ext2.h> #include <KernelKit/KPC.h> #include <NewKit/Crc32.h> diff --git a/dev/kernel/src/FS/HeFS.cc b/dev/kernel/src/FS/HeFS.cc index 1c82548c..0344309e 100644 --- a/dev/kernel/src/FS/HeFS.cc +++ b/dev/kernel/src/FS/HeFS.cc @@ -8,7 +8,6 @@ #include <modules/AHCI/AHCI.h> #include <modules/ATA/ATA.h> -#include <modules/Flash/Flash.h> #include <FSKit/HeFS.h> #include <KernelKit/KPC.h> #include <NewKit/Crc32.h> @@ -19,4 +18,137 @@ #include <KernelKit/ProcessScheduler.h> #include <KernelKit/User.h> +namespace Kernel +{ + namespace Detail + { + STATIC HeFS_INDEX_NODE* hefs_get_index_node(HeFS_BOOT_NODE* root, DriveTrait* mnt, const Utf16Char* dir_name, const Utf16Char* file_name, UInt8 kind) noexcept + { + if (root) + { + HeFS_INDEX_NODE* node = new HeFS_INDEX_NODE(); + HeFS_INDEX_NODE_DIRECTORY* dir = new HeFS_INDEX_NODE_DIRECTORY(); + + if (!node) + { + kout << "Error: Failed to allocate memory for index node.\r"; + return nullptr; + } + + auto start = root->fStartIND; + auto end = root->fEndIND; + + auto hop_watch = 0; + + while (start != end) + { + if (hop_watch++ > 100) + { + kout << "Error: Hop watch exceeded.\r"; + + break; + } + + if (start == 0) + { + ++hop_watch; + start = root->fStartIND; + } + + mnt->fPacket.fPacketLba = start; + mnt->fPacket.fPacketSize = sizeof(HeFS_INDEX_NODE_DIRECTORY); + mnt->fPacket.fPacketContent = dir; + + mnt->fInput(mnt->fPacket); + + if (!mnt->fPacket.fPacketGood) + { + delete node; + delete dir; + + err_global_get() = kErrorFileNotFound; + + + return nullptr; + } + + if (dir->fKind == kHeFSFileKindDirectory) + { + if (KStringBuilder::Equals(dir_name, dir->fName)) + { + for (SizeT inode_index = 0UL; inode_index < kHeFSBlockCount; ++inode_index) + { + if (dir->fIndexNodeStart[inode_index] != 0) + { + mnt->fPacket.fPacketLba = dir->fIndexNodeStart[inode_index]; + mnt->fPacket.fPacketSize = sizeof(HeFS_INDEX_NODE); + mnt->fPacket.fPacketContent = node; + + mnt->fInput(mnt->fPacket); + + if (mnt->fPacket.fPacketGood) + { + if (KStringBuilder::Equals(file_name, node->fName) && node->fKind == kind) + { + delete dir; + + return node; + } + } + else + { + break; + } + } + else if (dir->fIndexNodeEnd[inode_index] != 0) + { + mnt->fPacket.fPacketLba = dir->fIndexNodeEnd[inode_index]; + mnt->fPacket.fPacketSize = sizeof(HeFS_INDEX_NODE); + mnt->fPacket.fPacketContent = node; + + mnt->fInput(mnt->fPacket); + + if (mnt->fPacket.fPacketGood) + { + if (KStringBuilder::Equals(file_name, node->fName) && node->fKind == kind) + { + delete dir; + + return node; + } + } + else + { + break; + } + } + } + } + } + + start = dir->fNext; + + if (start == 0) + start = dir->fChild; + + if (start == 0) + start = dir->fParent; + } + + delete dir; + delete node; + + dir = nullptr; + node = nullptr; + } + + kout << "Error: Failed to find index node.\r"; + + err_global_get() = kErrorFileNotFound; + + return nullptr; + } + } // namespace Detail +} // namespace Kernel + #endif // ifdef __FSKIT_INCLUDES_HeFS__ diff --git a/dev/kernel/src/KString.cc b/dev/kernel/src/KString.cc index c1a8db65..2f81ad3d 100644 --- a/dev/kernel/src/KString.cc +++ b/dev/kernel/src/KString.cc @@ -143,6 +143,18 @@ namespace Kernel return true; } + /// @note This is unsafe!!! + bool KStringBuilder::Equals(const Utf16Char* lhs, const Utf16Char* rhs) + { + for (Size index = 0; index[rhs] != 0; ++index) + { + if (rhs[index] != lhs[index]) + return false; + } + + return true; + } + bool KStringBuilder::Equals(const WideChar* lhs, const WideChar* rhs) { for (Size index = 0; rhs[index] != 0; ++index) |
