diff options
| author | Amlal <amlal@nekernel.org> | 2025-04-25 13:08:33 +0200 |
|---|---|---|
| committer | Amlal <amlal@nekernel.org> | 2025-04-25 13:08:33 +0200 |
| commit | fb790b07aeba8e22e4190cf3e1834d11ecde6c96 (patch) | |
| tree | 4cec7d1b321307b1d5935577631dae116a658a37 /dev/kernel/src/FS | |
| parent | 63a2d92c5dfe976175cda024ec01905d11b43738 (diff) | |
dev: better .clang-format, ran format command.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/src/FS')
| -rw-r--r-- | dev/kernel/src/FS/Ext2+FileMgr.cc | 6 | ||||
| -rw-r--r-- | dev/kernel/src/FS/Ext2.cc | 16 | ||||
| -rw-r--r-- | dev/kernel/src/FS/HeFS+FileMgr.cc | 6 | ||||
| -rw-r--r-- | dev/kernel/src/FS/HeFS.cc | 1251 | ||||
| -rw-r--r-- | dev/kernel/src/FS/NeFS+FileMgr.cc | 421 | ||||
| -rw-r--r-- | dev/kernel/src/FS/NeFS.cc | 1280 |
6 files changed, 1402 insertions, 1578 deletions
diff --git a/dev/kernel/src/FS/Ext2+FileMgr.cc b/dev/kernel/src/FS/Ext2+FileMgr.cc index cb17b587..a55d917a 100644 --- a/dev/kernel/src/FS/Ext2+FileMgr.cc +++ b/dev/kernel/src/FS/Ext2+FileMgr.cc @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ @@ -10,5 +10,5 @@ #include <KernelKit/FileMgr.h> #include <KernelKit/MemoryMgr.h> -#endif // ifdef __FSKIT_INCLUDES_EXT2__ -#endif // ifndef __NE_MINIMAL_OS__ +#endif // ifdef __FSKIT_INCLUDES_EXT2__ +#endif // ifndef __NE_MINIMAL_OS__ diff --git a/dev/kernel/src/FS/Ext2.cc b/dev/kernel/src/FS/Ext2.cc index 8331f506..b6d04f46 100644 --- a/dev/kernel/src/FS/Ext2.cc +++ b/dev/kernel/src/FS/Ext2.cc @@ -1,21 +1,21 @@ /* ------------------------------------------- - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ #ifdef __FSKIT_INCLUDES_EXT2__ -#include <modules/AHCI/AHCI.h> -#include <modules/ATA/ATA.h> #include <FSKit/Ext2.h> +#include <FirmwareKit/EPM.h> #include <KernelKit/KPC.h> +#include <KernelKit/ProcessScheduler.h> +#include <KernelKit/User.h> #include <NewKit/Crc32.h> -#include <NewKit/KernelPanic.h> #include <NewKit/KString.h> +#include <NewKit/KernelPanic.h> #include <NewKit/Utils.h> -#include <FirmwareKit/EPM.h> -#include <KernelKit/ProcessScheduler.h> -#include <KernelKit/User.h> +#include <modules/AHCI/AHCI.h> +#include <modules/ATA/ATA.h> -#endif // ifdef __FSKIT_INCLUDES_EXT2__ +#endif // ifdef __FSKIT_INCLUDES_EXT2__ diff --git a/dev/kernel/src/FS/HeFS+FileMgr.cc b/dev/kernel/src/FS/HeFS+FileMgr.cc index e6719e1b..e0b92a8d 100644 --- a/dev/kernel/src/FS/HeFS+FileMgr.cc +++ b/dev/kernel/src/FS/HeFS+FileMgr.cc @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ @@ -10,5 +10,5 @@ #include <KernelKit/FileMgr.h> #include <KernelKit/MemoryMgr.h> -#endif // ifdef __FSKIT_INCLUDES_HEFS__ -#endif // ifndef __NE_MINIMAL_OS__ +#endif // ifdef __FSKIT_INCLUDES_HEFS__ +#endif // ifndef __NE_MINIMAL_OS__ diff --git a/dev/kernel/src/FS/HeFS.cc b/dev/kernel/src/FS/HeFS.cc index 7864bc6f..88837273 100644 --- a/dev/kernel/src/FS/HeFS.cc +++ b/dev/kernel/src/FS/HeFS.cc @@ -1,714 +1,669 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ #ifdef __FSKIT_INCLUDES_HEFS__ -#include <modules/AHCI/AHCI.h> -#include <modules/ATA/ATA.h> #include <FSKit/HeFS.h> -#include <KernelKit/KPC.h> -#include <NewKit/Crc32.h> -#include <NewKit/KernelPanic.h> -#include <NewKit/KString.h> -#include <NewKit/Utils.h> #include <FirmwareKit/EPM.h> #include <FirmwareKit/GPT.h> +#include <KernelKit/KPC.h> #include <KernelKit/ProcessScheduler.h> #include <KernelKit/User.h> +#include <NewKit/Crc32.h> +#include <NewKit/KString.h> +#include <NewKit/KernelPanic.h> +#include <NewKit/Utils.h> +#include <modules/AHCI/AHCI.h> +#include <modules/ATA/ATA.h> + +namespace Kernel { +namespace Detail { + /// @brief Forward declarations of internal functions. + + /// @brief Traverse the RB-Tree of the filesystem. + /// @param dir The directory to traverse. + /// @param start The starting point of the traversal. + /// @note This function is used to traverse the RB-Tree of the filesystem. + /// @internal Internal filesystem use only. + STATIC ATTRIBUTE(unused) _Output Void + hefsi_traverse_tree(HEFS_INDEX_NODE_DIRECTORY* dir, Lba& start); + + /// @brief Get the index node of a file or directory. + /// @param root The root node of the filesystem. + /// @param mnt The drive to read from. + /// @param dir_name The name of the directory. + /// @param file_name The name of the file. + /// @param kind The kind of the file (regular, directory, block, character, FIFO, socket, symbolic + /// link, unknown). + STATIC ATTRIBUTE(unused) _Output HEFS_INDEX_NODE* hefs_fetch_index_node( + HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf16Char* dir_name, const Utf16Char* file_name, + UInt8 kind, SizeT* cnt) noexcept; + + /// @brief Get the index node size. + /// @param root The root node of the filesystem. + /// @param mnt The drive to read from. + /// @param dir_name The name of the directory. + /// @param file_name The name of the file. + /// @param kind The kind of the file (regular, directory, block, character, FIFO, socket, symbolic + /// link, unknown). + STATIC ATTRIBUTE(unused) _Output SizeT + hefs_fetch_index_node_size(HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf16Char* dir_name, + const Utf16Char* file_name, UInt8 kind) noexcept; + + /// @brief Allocate a new index node. + /// @param root The root node of the filesystem. + /// @param mnt The drive to read/write from. + /// @param parent_dir_name The name of the parent directory. + /// @return Status, see err_global_get(). + STATIC ATTRIBUTE(unused) _Output BOOL + hefs_allocate_index_node(HEFS_BOOT_NODE* root, DriveTrait* mnt, + const Utf16Char* parent_dir_name, HEFS_INDEX_NODE* node) noexcept; + + /// @brief Balance RB-Tree of the filesystem. + /// @param root The root node of the filesystem. + /// @param mnt The drive to read/write from. + /// @return Status, see err_global_get(). + STATIC ATTRIBUTE(unused) _Output BOOL + hefsi_balance_filesystem(HEFS_BOOT_NODE* root, DriveTrait* mnt); + + /// @brief Traverse the RB-Tree of the filesystem. + /// @param dir The directory to traverse. + /// @param start The starting point of the traversal. + /// @note This function is used to traverse the RB-Tree of the filesystem. + /// @internal Internal filesystem use only. + STATIC ATTRIBUTE(unused) _Output Void + hefsi_traverse_tree(HEFS_INDEX_NODE_DIRECTORY* dir, Lba& start) { + start = dir->fNext; + + if (dir->fColor == kHeFSBlack && start == 0) { + if (dir->fParent != 0) start = dir->fParent; + } else if (dir->fColor == kHeFSRed && start == 0) { + if (dir->fChild != 0) + start = dir->fChild; + else if (dir->fNext != 0) + start = dir->fNext; + else if (dir->fPrev != 0) + start = dir->fPrev; + else + start = dir->fParent; + } + } + + /***********************************************************************************/ + /// @brief Rotate the RB-Tree to the left. + /// @internal + /***********************************************************************************/ + STATIC ATTRIBUTE(unused) _Output Void + hefsi_rotate_left(HEFS_INDEX_NODE_DIRECTORY* dir, Lba& start, DriveTrait* mnt) { + HEFS_INDEX_NODE_DIRECTORY* parent = new HEFS_INDEX_NODE_DIRECTORY(); + + if (!parent) { + kout << "Error: Failed to allocate memory for index node.\r"; + return; + } + + mnt->fPacket.fPacketLba = dir->fParent; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); + mnt->fPacket.fPacketContent = parent; + + mnt->fInput(mnt->fPacket); + + HEFS_INDEX_NODE_DIRECTORY* grand_parent = new HEFS_INDEX_NODE_DIRECTORY(); + + if (!grand_parent) { + delete parent; + kout << "Error: Failed to allocate memory for index node.\r"; + + return; + } + + mnt->fPacket.fPacketLba = parent->fParent; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); + mnt->fPacket.fPacketContent = grand_parent; + + mnt->fInput(mnt->fPacket); + + dir->fParent = parent->fParent; + parent->fParent = start; + parent->fNext = dir->fChild; + dir->fChild = dir->fParent; + + mnt->fPacket.fPacketLba = parent->fParent; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); + mnt->fPacket.fPacketContent = grand_parent; + + mnt->fOutput(mnt->fPacket); + + mnt->fPacket.fPacketLba = dir->fParent; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); + mnt->fPacket.fPacketContent = parent; + + mnt->fOutput(mnt->fPacket); + + delete parent; + parent = nullptr; + + delete grand_parent; + grand_parent = nullptr; + + dir->fColor = kHeFSBlack; + } + + /***********************************************************************************/ + /// @brief Rotate the RB-Tree to the right. + /// @internal + /***********************************************************************************/ + STATIC ATTRIBUTE(unused) _Output Void + hefsi_rotate_right(HEFS_INDEX_NODE_DIRECTORY* dir, Lba& start, DriveTrait* mnt) { + HEFS_INDEX_NODE_DIRECTORY* parent = new HEFS_INDEX_NODE_DIRECTORY(); + + if (!parent) { + kout << "Error: Failed to allocate memory for index node.\r"; + + return; + } + + mnt->fPacket.fPacketLba = dir->fParent; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); + mnt->fPacket.fPacketContent = parent; + + mnt->fInput(mnt->fPacket); + + parent->fParent = dir->fParent; + dir->fParent = parent->fParent; + dir->fNext = parent->fChild; + parent->fChild = start; + + mnt->fPacket.fPacketLba = dir->fParent; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); + mnt->fPacket.fPacketContent = parent; + + mnt->fOutput(mnt->fPacket); + + delete parent; + parent = nullptr; + + dir->fColor = kHeFSBlack; + + mnt->fPacket.fPacketLba = start; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); + mnt->fPacket.fPacketContent = dir; + + mnt->fOutput(mnt->fPacket); + } + + /// @brief Get the index node size. + /// @param root The root node of the filesystem. + /// @param mnt The drive to read from. + /// @param dir_name The name of the directory. + /// @param file_name The name of the file. + /// @param kind The kind of the file (regular, directory, block, character, FIFO, socket, symbolic + /// link, unknown). + STATIC ATTRIBUTE(unused) _Output SizeT + hefs_fetch_index_node_size(HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf16Char* dir_name, + const Utf16Char* file_name, UInt8 kind) noexcept { + if (root && mnt) { + HEFS_INDEX_NODE* node = new HEFS_INDEX_NODE(); + HEFS_INDEX_NODE_DIRECTORY* dir = new HEFS_INDEX_NODE_DIRECTORY(); + + SizeT sz = 0UL; + + auto start = root->fStartIND; + auto end = root->fEndIND; + + auto hop_watch = 0; + + while (YES) { + if (start > end) { + kout << "Error: Invalid start/end values.\r"; + break; + } + + if (hop_watch > 100) { + kout << "Error: Hop watch exceeded, filesystem is stalling.\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; + + dir = nullptr; + node = nullptr; + + err_global_get() = kErrorFileNotFound; + + return 0; + } + + if (dir->fKind == kHeFSFileKindDirectory) { + if (KStringBuilder::Equals(dir_name, dir->fName) || + KStringBuilder::Equals(dir_name, kHeFSSearchAllStr)) { + for (SizeT inode_index = 0UL; inode_index < kHeFSBlockCount; inode_index += 2) { + if (dir->fIndexNodeStart[inode_index]) { + mnt->fPacket.fPacketLba = dir->fIndexNodeStart[inode_index]; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE); + mnt->fPacket.fPacketContent = node; + mnt->fInput(mnt->fPacket); + } else if (dir->fIndexNodeEnd[inode_index]) { + mnt->fPacket.fPacketLba = dir->fIndexNodeEnd[inode_index]; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE); + mnt->fPacket.fPacketContent = node; + mnt->fInput(mnt->fPacket); + } + + if (KStringBuilder::Equals(file_name, node->fName) && node->fKind == kind) { + if (node->fKind == kHeFSFileKindDirectory) { + sz += hefs_fetch_index_node_size(root, mnt, dir_name, file_name, kind); + } else { + sz = node->fSize; + } + + return sz; + } + } + } + } + } + + err_global_get() = kErrorSuccess; + return sz; + } + + err_global_get() = kErrorFileNotFound; + return 0; + } + + /// @brief Get the index node of a file or directory. + /// @param root The root node of the filesystem. + /// @param mnt The drive to read from. + /// @param dir_name The name of the directory. + /// @param file_name The name of the file. + /// @param kind The kind of the file (regular, directory, block, character, FIFO, socket, symbolic + /// link, unknown). + STATIC ATTRIBUTE(unused) _Output HEFS_INDEX_NODE* hefs_fetch_index_node( + HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf16Char* dir_name, const Utf16Char* file_name, + UInt8 kind, SizeT* cnt) noexcept { + if (root && mnt) { + HEFS_INDEX_NODE* node_arr = new HEFS_INDEX_NODE[*cnt]; + + 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 start_cnt = 0UL; + + auto hop_watch = 0; + + while (YES) { + if (start > end) { + kout << "Error: Invalid start/end values.\r"; + break; + } + + if (hop_watch > 100) { + kout << "Error: Hop watch exceeded, filesystem is stalling.\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; + + dir = nullptr; + node = nullptr; + + err_global_get() = kErrorFileNotFound; + + return nullptr; + } + + if (dir->fKind == kHeFSFileKindDirectory) { + if (KStringBuilder::Equals(dir_name, dir->fName) || + KStringBuilder::Equals(dir_name, kHeFSSearchAllStr)) { + for (SizeT inode_index = 0UL; inode_index < kHeFSBlockCount; inode_index += 2) { + if (dir->fIndexNodeStart[inode_index] != 0 || dir->fIndexNodeEnd[inode_index] != 0) { + mnt->fPacket.fPacketLba = (!dir->fIndexNodeStart[inode_index]) + ? dir->fIndexNodeEnd[inode_index] + : 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; + dir = nullptr; + + node_arr[start_cnt] = *node; + ++start_cnt; + + if (start_cnt > *cnt) { + delete node; + return node_arr; + } + } + } else { + err_global_get() = kErrorDiskIsCorrupted; + + delete dir; + delete node; + delete[] node_arr; + + dir = nullptr; + node = nullptr; + node_arr = nullptr; + + return nullptr; + } + } + } + } + } + + hefsi_traverse_tree(dir, start); + } + + delete dir; + delete node; + delete[] node_arr; + + dir = nullptr; + node = nullptr; + node_arr = nullptr; + } + + kout << "Error: Failed to find index node.\r"; + + err_global_get() = kErrorFileNotFound; + + return nullptr; + } + + /// @brief Allocate a new index node. + /// @param root The root node of the filesystem. + /// @param mnt The drive to read from. + /// @param parent_dir_name The name of the parent directory. + /// @return Status, see err_global_get(). + STATIC ATTRIBUTE(unused) _Output BOOL + hefs_allocate_index_node(HEFS_BOOT_NODE* root, DriveTrait* mnt, + const Utf16Char* parent_dir_name, HEFS_INDEX_NODE* node) noexcept { + if (root && mnt) { + HEFS_INDEX_NODE_DIRECTORY* dir = new HEFS_INDEX_NODE_DIRECTORY(); + + auto start = root->fStartIND; + + auto hop_watch = 0; + + while (YES) { + if (hop_watch > 100) { + kout << "Error: Hop watch exceeded, filesystem is stalling.\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 (KStringBuilder::Equals(dir->fName, parent_dir_name)) { + for (SizeT inode_index = 0UL; inode_index < kHeFSBlockCount; inode_index += 2) { + if (dir->fIndexNodeStart[inode_index] != 0 || dir->fIndexNodeEnd[inode_index] != 0) { + HEFS_INDEX_NODE prev_node; + + auto lba = (!dir->fIndexNodeStart[inode_index]) ? dir->fIndexNodeEnd[inode_index] + : dir->fIndexNodeStart[inode_index]; + + mnt->fPacket.fPacketLba = lba; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE); + mnt->fPacket.fPacketContent = &prev_node; + + mnt->fInput(mnt->fPacket); + + if (prev_node.fDeleted > 0 && !prev_node.fAccessed) { + mnt->fPacket.fPacketLba = lba; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE); + mnt->fPacket.fPacketContent = node; -namespace Kernel -{ - namespace Detail - { - /// @brief Forward declarations of internal functions. - - /// @brief Traverse the RB-Tree of the filesystem. - /// @param dir The directory to traverse. - /// @param start The starting point of the traversal. - /// @note This function is used to traverse the RB-Tree of the filesystem. - /// @internal Internal filesystem use only. - STATIC ATTRIBUTE(unused) _Output Void hefsi_traverse_tree(HEFS_INDEX_NODE_DIRECTORY* dir, Lba& start); - - /// @brief Get the index node of a file or directory. - /// @param root The root node of the filesystem. - /// @param mnt The drive to read from. - /// @param dir_name The name of the directory. - /// @param file_name The name of the file. - /// @param kind The kind of the file (regular, directory, block, character, FIFO, socket, symbolic link, unknown). - STATIC ATTRIBUTE(unused) _Output HEFS_INDEX_NODE* hefs_fetch_index_node(HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf16Char* dir_name, const Utf16Char* file_name, UInt8 kind, SizeT* cnt) noexcept; - - /// @brief Get the index node size. - /// @param root The root node of the filesystem. - /// @param mnt The drive to read from. - /// @param dir_name The name of the directory. - /// @param file_name The name of the file. - /// @param kind The kind of the file (regular, directory, block, character, FIFO, socket, symbolic link, unknown). - STATIC ATTRIBUTE(unused) _Output SizeT hefs_fetch_index_node_size(HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf16Char* dir_name, const Utf16Char* file_name, UInt8 kind) noexcept; - - /// @brief Allocate a new index node. - /// @param root The root node of the filesystem. - /// @param mnt The drive to read/write from. - /// @param parent_dir_name The name of the parent directory. - /// @return Status, see err_global_get(). - STATIC ATTRIBUTE(unused) _Output BOOL hefs_allocate_index_node(HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf16Char* parent_dir_name, HEFS_INDEX_NODE* node) noexcept; - - /// @brief Balance RB-Tree of the filesystem. - /// @param root The root node of the filesystem. - /// @param mnt The drive to read/write from. - /// @return Status, see err_global_get(). - STATIC ATTRIBUTE(unused) _Output BOOL hefsi_balance_filesystem(HEFS_BOOT_NODE* root, DriveTrait* mnt); - - /// @brief Traverse the RB-Tree of the filesystem. - /// @param dir The directory to traverse. - /// @param start The starting point of the traversal. - /// @note This function is used to traverse the RB-Tree of the filesystem. - /// @internal Internal filesystem use only. - STATIC ATTRIBUTE(unused) _Output Void hefsi_traverse_tree(HEFS_INDEX_NODE_DIRECTORY* dir, Lba& start) - { - start = dir->fNext; - - if (dir->fColor == kHeFSBlack && start == 0) - { - if (dir->fParent != 0) - start = dir->fParent; - } - else if (dir->fColor == kHeFSRed && start == 0) - { - if (dir->fChild != 0) - start = dir->fChild; - else if (dir->fNext != 0) - start = dir->fNext; - else if (dir->fPrev != 0) - start = dir->fPrev; - else - start = dir->fParent; - } - } - - /***********************************************************************************/ - /// @brief Rotate the RB-Tree to the left. - /// @internal - /***********************************************************************************/ - STATIC ATTRIBUTE(unused) _Output Void hefsi_rotate_left(HEFS_INDEX_NODE_DIRECTORY* dir, Lba& start, DriveTrait* mnt) - { - HEFS_INDEX_NODE_DIRECTORY* parent = new HEFS_INDEX_NODE_DIRECTORY(); - - if (!parent) - { - kout << "Error: Failed to allocate memory for index node.\r"; - return; - } - - mnt->fPacket.fPacketLba = dir->fParent; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); - mnt->fPacket.fPacketContent = parent; - - mnt->fInput(mnt->fPacket); - - HEFS_INDEX_NODE_DIRECTORY* grand_parent = new HEFS_INDEX_NODE_DIRECTORY(); - - if (!grand_parent) - { - delete parent; - kout << "Error: Failed to allocate memory for index node.\r"; - - return; - } - - mnt->fPacket.fPacketLba = parent->fParent; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); - mnt->fPacket.fPacketContent = grand_parent; - - mnt->fInput(mnt->fPacket); - - dir->fParent = parent->fParent; - parent->fParent = start; - parent->fNext = dir->fChild; - dir->fChild = dir->fParent; - - mnt->fPacket.fPacketLba = parent->fParent; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); - mnt->fPacket.fPacketContent = grand_parent; - - mnt->fOutput(mnt->fPacket); - - mnt->fPacket.fPacketLba = dir->fParent; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); - mnt->fPacket.fPacketContent = parent; - - mnt->fOutput(mnt->fPacket); - - delete parent; - parent = nullptr; - - delete grand_parent; - grand_parent = nullptr; - - dir->fColor = kHeFSBlack; - } - - /***********************************************************************************/ - /// @brief Rotate the RB-Tree to the right. - /// @internal - /***********************************************************************************/ - STATIC ATTRIBUTE(unused) _Output Void hefsi_rotate_right(HEFS_INDEX_NODE_DIRECTORY* dir, Lba& start, DriveTrait* mnt) - { - HEFS_INDEX_NODE_DIRECTORY* parent = new HEFS_INDEX_NODE_DIRECTORY(); - - if (!parent) - { - kout << "Error: Failed to allocate memory for index node.\r"; - - return; - } - - mnt->fPacket.fPacketLba = dir->fParent; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); - mnt->fPacket.fPacketContent = parent; - - mnt->fInput(mnt->fPacket); - - parent->fParent = dir->fParent; - dir->fParent = parent->fParent; - dir->fNext = parent->fChild; - parent->fChild = start; - - mnt->fPacket.fPacketLba = dir->fParent; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); - mnt->fPacket.fPacketContent = parent; - - mnt->fOutput(mnt->fPacket); - - delete parent; - parent = nullptr; - - dir->fColor = kHeFSBlack; - - mnt->fPacket.fPacketLba = start; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); - mnt->fPacket.fPacketContent = dir; - - mnt->fOutput(mnt->fPacket); - } - - /// @brief Get the index node size. - /// @param root The root node of the filesystem. - /// @param mnt The drive to read from. - /// @param dir_name The name of the directory. - /// @param file_name The name of the file. - /// @param kind The kind of the file (regular, directory, block, character, FIFO, socket, symbolic link, unknown). - STATIC ATTRIBUTE(unused) _Output SizeT hefs_fetch_index_node_size(HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf16Char* dir_name, const Utf16Char* file_name, UInt8 kind) noexcept - { - if (root && mnt) - { - HEFS_INDEX_NODE* node = new HEFS_INDEX_NODE(); - HEFS_INDEX_NODE_DIRECTORY* dir = new HEFS_INDEX_NODE_DIRECTORY(); - - SizeT sz = 0UL; - - auto start = root->fStartIND; - auto end = root->fEndIND; - - auto hop_watch = 0; - - while (YES) - { - if (start > end) - { - kout << "Error: Invalid start/end values.\r"; - break; - } - - if (hop_watch > 100) - { - kout << "Error: Hop watch exceeded, filesystem is stalling.\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; - - dir = nullptr; - node = nullptr; - - err_global_get() = kErrorFileNotFound; - - return 0; - } - - if (dir->fKind == kHeFSFileKindDirectory) - { - if (KStringBuilder::Equals(dir_name, dir->fName) || - KStringBuilder::Equals(dir_name, kHeFSSearchAllStr)) - { - for (SizeT inode_index = 0UL; inode_index < kHeFSBlockCount; inode_index += 2) - { - if (dir->fIndexNodeStart[inode_index]) - { - mnt->fPacket.fPacketLba = dir->fIndexNodeStart[inode_index]; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE); - mnt->fPacket.fPacketContent = node; - mnt->fInput(mnt->fPacket); - } - else if (dir->fIndexNodeEnd[inode_index]) - { - mnt->fPacket.fPacketLba = dir->fIndexNodeEnd[inode_index]; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE); - mnt->fPacket.fPacketContent = node; - mnt->fInput(mnt->fPacket); - } - - if (KStringBuilder::Equals(file_name, node->fName) && node->fKind == kind) - { - if (node->fKind == kHeFSFileKindDirectory) - { - sz += hefs_fetch_index_node_size(root, mnt, dir_name, file_name, kind); - } - else - { - sz = node->fSize; - } - - return sz; - } - } - } - } - } - - err_global_get() = kErrorSuccess; - return sz; - } - - err_global_get() = kErrorFileNotFound; - return 0; - } - - /// @brief Get the index node of a file or directory. - /// @param root The root node of the filesystem. - /// @param mnt The drive to read from. - /// @param dir_name The name of the directory. - /// @param file_name The name of the file. - /// @param kind The kind of the file (regular, directory, block, character, FIFO, socket, symbolic link, unknown). - STATIC ATTRIBUTE(unused) _Output HEFS_INDEX_NODE* hefs_fetch_index_node(HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf16Char* dir_name, const Utf16Char* file_name, UInt8 kind, SizeT* cnt) noexcept - { - if (root && mnt) - { - HEFS_INDEX_NODE* node_arr = new HEFS_INDEX_NODE[*cnt]; - - 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 start_cnt = 0UL; - - auto hop_watch = 0; - - while (YES) - { - if (start > end) - { - kout << "Error: Invalid start/end values.\r"; - break; - } - - if (hop_watch > 100) - { - kout << "Error: Hop watch exceeded, filesystem is stalling.\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; - - dir = nullptr; - node = nullptr; - - err_global_get() = kErrorFileNotFound; - - return nullptr; - } - - if (dir->fKind == kHeFSFileKindDirectory) - { - if (KStringBuilder::Equals(dir_name, dir->fName) || - KStringBuilder::Equals(dir_name, kHeFSSearchAllStr)) - { - for (SizeT inode_index = 0UL; inode_index < kHeFSBlockCount; inode_index += 2) - { - if (dir->fIndexNodeStart[inode_index] != 0 || - dir->fIndexNodeEnd[inode_index] != 0) - { - mnt->fPacket.fPacketLba = (!dir->fIndexNodeStart[inode_index]) ? dir->fIndexNodeEnd[inode_index] : 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; - dir = nullptr; - - node_arr[start_cnt] = *node; - ++start_cnt; - - if (start_cnt > *cnt) - { - delete node; - return node_arr; - } - } - } - else - { - err_global_get() = kErrorDiskIsCorrupted; - - delete dir; - delete node; - delete[] node_arr; - - dir = nullptr; - node = nullptr; - node_arr = nullptr; - - return nullptr; - } - } - } - } - } - - hefsi_traverse_tree(dir, start); - } - - delete dir; - delete node; - delete[] node_arr; - - dir = nullptr; - node = nullptr; - node_arr = nullptr; - } - - kout << "Error: Failed to find index node.\r"; - - err_global_get() = kErrorFileNotFound; - - return nullptr; - } - - /// @brief Allocate a new index node. - /// @param root The root node of the filesystem. - /// @param mnt The drive to read from. - /// @param parent_dir_name The name of the parent directory. - /// @return Status, see err_global_get(). - STATIC ATTRIBUTE(unused) _Output BOOL hefs_allocate_index_node(HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf16Char* parent_dir_name, HEFS_INDEX_NODE* node) noexcept - { - if (root && mnt) - { - HEFS_INDEX_NODE_DIRECTORY* dir = new HEFS_INDEX_NODE_DIRECTORY(); - - auto start = root->fStartIND; - - auto hop_watch = 0; - - while (YES) - { - if (hop_watch > 100) - { - kout << "Error: Hop watch exceeded, filesystem is stalling.\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 (KStringBuilder::Equals(dir->fName, parent_dir_name)) - { - for (SizeT inode_index = 0UL; inode_index < kHeFSBlockCount; inode_index += 2) - { - if (dir->fIndexNodeStart[inode_index] != 0 || - dir->fIndexNodeEnd[inode_index] != 0) - { - HEFS_INDEX_NODE prev_node; - - auto lba = (!dir->fIndexNodeStart[inode_index]) ? dir->fIndexNodeEnd[inode_index] : dir->fIndexNodeStart[inode_index]; - - mnt->fPacket.fPacketLba = lba; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE); - mnt->fPacket.fPacketContent = &prev_node; - - mnt->fInput(mnt->fPacket); - - if (prev_node.fDeleted > 0 && - !prev_node.fAccessed) - { - mnt->fPacket.fPacketLba = lba; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE); - mnt->fPacket.fPacketContent = node; - - mnt->fOutput(mnt->fPacket); + mnt->fOutput(mnt->fPacket); - if (mnt->fPacket.fPacketGood) - { - delete dir; - dir = nullptr; + if (mnt->fPacket.fPacketGood) { + delete dir; + dir = nullptr; - return YES; - } - } - } - } - } + return YES; + } + } + } + } + } - hefsi_traverse_tree(dir, start); - } + hefsi_traverse_tree(dir, start); + } - delete dir; - dir = nullptr; + delete dir; + dir = nullptr; - return YES; - } + return YES; + } - return NO; - } + return NO; + } - /// @brief Balance RB-Tree of the filesystem. - /// @param root The root node of the filesystem. - /// @param mnt The drive to read/write from. - /// @return Status, see err_global_get(). - STATIC ATTRIBUTE(unused) _Output BOOL hefsi_balance_filesystem(HEFS_BOOT_NODE* root, DriveTrait* mnt) - { - if (root && mnt) - { - HEFS_INDEX_NODE_DIRECTORY* dir = new HEFS_INDEX_NODE_DIRECTORY(); - HEFS_INDEX_NODE_DIRECTORY* dir_parent = new HEFS_INDEX_NODE_DIRECTORY(); + /// @brief Balance RB-Tree of the filesystem. + /// @param root The root node of the filesystem. + /// @param mnt The drive to read/write from. + /// @return Status, see err_global_get(). + STATIC ATTRIBUTE(unused) _Output BOOL + hefsi_balance_filesystem(HEFS_BOOT_NODE* root, DriveTrait* mnt) { + if (root && mnt) { + HEFS_INDEX_NODE_DIRECTORY* dir = new HEFS_INDEX_NODE_DIRECTORY(); + HEFS_INDEX_NODE_DIRECTORY* dir_parent = new HEFS_INDEX_NODE_DIRECTORY(); - auto start = root->fStartIND; + auto start = root->fStartIND; - while (YES) - { - mnt->fPacket.fPacketLba = start; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); - mnt->fPacket.fPacketContent = dir; + while (YES) { + mnt->fPacket.fPacketLba = start; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); + mnt->fPacket.fPacketContent = dir; - mnt->fInput(mnt->fPacket); + mnt->fInput(mnt->fPacket); - if (!mnt->fPacket.fPacketGood) - { - delete dir; - dir = nullptr; + if (!mnt->fPacket.fPacketGood) { + delete dir; + dir = nullptr; - err_global_get() = kErrorDiskIsCorrupted; + err_global_get() = kErrorDiskIsCorrupted; - return NO; - } + return NO; + } - if (start == root->fStartIND) - { - dir->fColor = kHeFSBlack; + if (start == root->fStartIND) { + dir->fColor = kHeFSBlack; - mnt->fPacket.fPacketLba = start; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); - mnt->fPacket.fPacketContent = dir; + mnt->fPacket.fPacketLba = start; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); + mnt->fPacket.fPacketContent = dir; - mnt->fOutput(mnt->fPacket); - } + mnt->fOutput(mnt->fPacket); + } - mnt->fPacket.fPacketLba = dir->fParent; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); - mnt->fPacket.fPacketContent = dir_parent; + mnt->fPacket.fPacketLba = dir->fParent; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); + mnt->fPacket.fPacketContent = dir_parent; - mnt->fInput(mnt->fPacket); + mnt->fInput(mnt->fPacket); - if (!mnt->fPacket.fPacketGood) - { - delete dir; - dir = nullptr; + if (!mnt->fPacket.fPacketGood) { + delete dir; + dir = nullptr; - err_global_get() = kErrorDiskIsCorrupted; + err_global_get() = kErrorDiskIsCorrupted; - return NO; - } + return NO; + } - HEFS_INDEX_NODE_DIRECTORY dir_uncle{}; + HEFS_INDEX_NODE_DIRECTORY dir_uncle{}; - mnt->fPacket.fPacketLba = dir_parent->fNext; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); - mnt->fPacket.fPacketContent = &dir_uncle; + mnt->fPacket.fPacketLba = dir_parent->fNext; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); + mnt->fPacket.fPacketContent = &dir_uncle; - mnt->fInput(mnt->fPacket); + mnt->fInput(mnt->fPacket); - if (!mnt->fPacket.fPacketGood) - { - delete dir; - dir = nullptr; + if (!mnt->fPacket.fPacketGood) { + delete dir; + dir = nullptr; - err_global_get() = kErrorDiskIsCorrupted; + err_global_get() = kErrorDiskIsCorrupted; - return NO; - } + return NO; + } - if (dir_uncle.fColor == kHeFSRed) - { - dir_parent->fColor = kHeFSBlack; - dir_uncle.fColor = kHeFSBlack; + if (dir_uncle.fColor == kHeFSRed) { + dir_parent->fColor = kHeFSBlack; + dir_uncle.fColor = kHeFSBlack; - mnt->fPacket.fPacketLba = dir->fParent; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); - mnt->fPacket.fPacketContent = dir_parent; + mnt->fPacket.fPacketLba = dir->fParent; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); + mnt->fPacket.fPacketContent = dir_parent; - mnt->fOutput(mnt->fPacket); + mnt->fOutput(mnt->fPacket); - mnt->fPacket.fPacketLba = dir_uncle.fParent; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); - mnt->fPacket.fPacketContent = &dir_uncle; + mnt->fPacket.fPacketLba = dir_uncle.fParent; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); + mnt->fPacket.fPacketContent = &dir_uncle; - mnt->fOutput(mnt->fPacket); + mnt->fOutput(mnt->fPacket); - if (!mnt->fPacket.fPacketGood) - { - delete dir; - dir = nullptr; + if (!mnt->fPacket.fPacketGood) { + delete dir; + dir = nullptr; - err_global_get() = kErrorDiskIsCorrupted; + err_global_get() = kErrorDiskIsCorrupted; - return NO; - } + return NO; + } - hefsi_traverse_tree(dir, start); + hefsi_traverse_tree(dir, start); - continue; - } - else - { - if (dir_parent->fNext == start) - { - hefsi_rotate_left(dir, start, mnt); - hefsi_traverse_tree(dir, start); + continue; + } else { + if (dir_parent->fNext == start) { + hefsi_rotate_left(dir, start, mnt); + hefsi_traverse_tree(dir, start); - continue; - } + continue; + } - dir_parent->fColor = kHeFSBlack; + dir_parent->fColor = kHeFSBlack; - mnt->fPacket.fPacketLba = dir->fParent; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); - mnt->fPacket.fPacketContent = dir_parent; + mnt->fPacket.fPacketLba = dir->fParent; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); + mnt->fPacket.fPacketContent = dir_parent; - mnt->fOutput(mnt->fPacket); + mnt->fOutput(mnt->fPacket); - if (!mnt->fPacket.fPacketGood) - { - delete dir; - dir = nullptr; + if (!mnt->fPacket.fPacketGood) { + delete dir; + dir = nullptr; - err_global_get() = kErrorDiskIsCorrupted; + err_global_get() = kErrorDiskIsCorrupted; - return NO; - } + return NO; + } - hefsi_rotate_right(dir, start, mnt); - hefsi_traverse_tree(dir, start); + hefsi_rotate_right(dir, start, mnt); + hefsi_traverse_tree(dir, start); - continue; - } + continue; + } - hefsi_traverse_tree(dir, start); - } + hefsi_traverse_tree(dir, start); + } - delete dir; - dir = nullptr; + delete dir; + dir = nullptr; - return YES; - } + return YES; + } - return NO; - } - } // namespace Detail -} // namespace Kernel + return NO; + } +} // namespace Detail +} // namespace Kernel -/// @note HeFS will allocate inodes and ind in advance, to avoid having to allocate them in real-time. +/// @note HeFS will allocate inodes and ind in advance, to avoid having to allocate them in +/// real-time. /// @note This is certainly take longer to format a disk with it, but worth-it in the long run. -namespace Kernel -{ - /// @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 HeFileSystemParser::FormatEPM(_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); - - return NO; - } - - /// @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 HeFileSystemParser::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); - - return NO; - } -} // namespace Kernel - -#endif // ifdef __FSKIT_INCLUDES_HEFS__ +namespace Kernel { +/// @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 HeFileSystemParser::FormatEPM(_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); + + return NO; +} + +/// @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 HeFileSystemParser::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); + + return NO; +} +} // namespace Kernel + +#endif // ifdef __FSKIT_INCLUDES_HEFS__ diff --git a/dev/kernel/src/FS/NeFS+FileMgr.cc b/dev/kernel/src/FS/NeFS+FileMgr.cc index 348ae61b..56fc2dbb 100644 --- a/dev/kernel/src/FS/NeFS+FileMgr.cc +++ b/dev/kernel/src/FS/NeFS+FileMgr.cc @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ @@ -13,233 +13,192 @@ /// @brief NeFS File manager. /// BUGS: 0 -namespace Kernel -{ - /// @brief C++ constructor - NeFileSystemMgr::NeFileSystemMgr() - { - NeFileSystemParser* mParser = new NeFileSystemParser(); - MUST_PASS(mParser); - - kout << "We are done allocating NeFileSystemParser...\r"; - } - - NeFileSystemMgr::~NeFileSystemMgr() - { - if (mParser) - { - kout << "Destroying NeFileSystemParser...\r"; - mm_delete_class(&mParser); - } - } - - /// @brief Removes a node from the filesystem. - /// @param path The filename - /// @return If it was deleted or not. - bool NeFileSystemMgr::Remove(_Input const Char* path) - { - if (path == nullptr || *path == 0) - return false; - - return mParser->RemoveCatalog(path); - } - - /// @brief Creates a node with the specified. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NeFileSystemMgr::Create(_Input const Char* path) - { - return node_cast(mParser->CreateCatalog(path)); - } - - /// @brief Creates a node with is a directory. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NeFileSystemMgr::CreateDirectory(const Char* path) - { - return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindDir)); - } - - /// @brief Creates a node with is a alias. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NeFileSystemMgr::CreateAlias(const Char* path) - { - return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); - } - - /// @brief Creates a node with is a page file. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NeFileSystemMgr::CreateSwapFile(const Char* path) - { - return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindPage)); - } - - /// @brief Gets the root directory. - /// @return - const Char* NeFileSystemHelper::Root() - { - return kNeFSRoot; - } - - /// @brief Gets the up-dir directory. - /// @return - const Char* NeFileSystemHelper::UpDir() - { - return kNeFSUpDir; - } - - /// @brief Gets the separator character. - /// @return - Char NeFileSystemHelper::Separator() - { - return kNeFSSeparator; - } - - /// @brief Gets the metafile character. - /// @return - Char NeFileSystemHelper::MetaFile() - { - return kNeFSMetaFilePrefix; - } - - /// @brief Opens a new file. - /// @param path - /// @param r - /// @return - _Output NodePtr NeFileSystemMgr::Open(_Input const Char* path, _Input const Char* r) - { - if (!path || *path == 0) - return nullptr; - - if (!r || *r == 0) - return nullptr; - - auto catalog = mParser->GetCatalog(path); - - return node_cast(catalog); - } - - /// @brief Writes to a catalog's fork. - /// @param node the node ptr. - /// @param data the data. - /// @param flags the size. - /// @return - Void NeFileSystemMgr::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) - { - if (!node) - return; - if (!size) - return; - - constexpr auto kDataForkName = kNeFSDataFork; - this->Write(kDataForkName, node, data, flags, size); - } - - /// @brief Read from filesystem fork. - /// @param node the catalog node. - /// @param flags the flags with it. - /// @param sz the size to read. - /// @return - _Output VoidPtr NeFileSystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) - { - if (!node) - return nullptr; - if (!size) - return nullptr; - - constexpr auto kDataForkName = kNeFSDataFork; - return this->Read(kDataForkName, node, flags, size); - } - - Void NeFileSystemMgr::Write(_Input const Char* name, - _Input NodePtr node, - _Input VoidPtr data, - _Input Int32 flags, - _Input SizeT size) - { - if (!size || - size > kNeFSForkSize) - return; - - if (!data) - return; - - NE_UNUSED(flags); - - if ((reinterpret_cast<NEFS_CATALOG_STRUCT*>(node))->Kind == kNeFSCatalogKindFile) - mParser->WriteCatalog(reinterpret_cast<NEFS_CATALOG_STRUCT*>(node)->Name, (flags & kFileFlagRsrc ? true : false), data, size, - name); - } - - _Output VoidPtr NeFileSystemMgr::Read(_Input const Char* name, - _Input NodePtr node, - _Input Int32 flags, - _Input SizeT sz) - { - if (sz > kNeFSForkSize) - return nullptr; - - if (!sz) - return nullptr; - - NE_UNUSED(flags); - - if ((reinterpret_cast<NEFS_CATALOG_STRUCT*>(node))->Kind == kNeFSCatalogKindFile) - return mParser->ReadCatalog(reinterpret_cast<NEFS_CATALOG_STRUCT*>(node), (flags & kFileFlagRsrc ? true : false), sz, - name); - - return nullptr; - } - - /// @brief Seek from Catalog. - /// @param node - /// @param off - /// @retval true always returns false, this is unimplemented. - /// @retval false always returns this, it is unimplemented. - - _Output Bool NeFileSystemMgr::Seek(NodePtr node, SizeT off) - { - if (!node || off == 0) - return false; - - return mParser->Seek(reinterpret_cast<NEFS_CATALOG_STRUCT*>(node), off); - } - - /// @brief Tell where the catalog is. - /// @param node - /// @retval true always returns false, this is unimplemented. - /// @retval false always returns this, it is unimplemented. - - _Output SizeT NeFileSystemMgr::Tell(NodePtr node) - { - if (!node) - return kNPos; - - return mParser->Tell(reinterpret_cast<NEFS_CATALOG_STRUCT*>(node)); - } - - /// @brief Rewinds the catalog. - /// @param node - /// @retval true always returns false, this is unimplemented. - /// @retval false always returns this, it is unimplemented. - - _Output Bool NeFileSystemMgr::Rewind(NodePtr node) - { - if (!node) - return false; - - return this->Seek(node, 0); - } - - /// @brief Returns the filesystem parser. - /// @return the Filesystem parser class. - _Output NeFileSystemParser* NeFileSystemMgr::GetParser() noexcept - { - return mParser; - } -} // namespace Kernel - -#endif // ifdef __FSKIT_INCLUDES_NEFS__ -#endif // ifndef __NE_MINIMAL_OS__ +namespace Kernel { +/// @brief C++ constructor +NeFileSystemMgr::NeFileSystemMgr() { + NeFileSystemParser* mParser = new NeFileSystemParser(); + MUST_PASS(mParser); + + kout << "We are done allocating NeFileSystemParser...\r"; +} + +NeFileSystemMgr::~NeFileSystemMgr() { + if (mParser) { + kout << "Destroying NeFileSystemParser...\r"; + mm_delete_class(&mParser); + } +} + +/// @brief Removes a node from the filesystem. +/// @param path The filename +/// @return If it was deleted or not. +bool NeFileSystemMgr::Remove(_Input const Char* path) { + if (path == nullptr || *path == 0) return false; + + return mParser->RemoveCatalog(path); +} + +/// @brief Creates a node with the specified. +/// @param path The filename path. +/// @return The Node pointer. +NodePtr NeFileSystemMgr::Create(_Input const Char* path) { + return node_cast(mParser->CreateCatalog(path)); +} + +/// @brief Creates a node with is a directory. +/// @param path The filename path. +/// @return The Node pointer. +NodePtr NeFileSystemMgr::CreateDirectory(const Char* path) { + return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindDir)); +} + +/// @brief Creates a node with is a alias. +/// @param path The filename path. +/// @return The Node pointer. +NodePtr NeFileSystemMgr::CreateAlias(const Char* path) { + return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); +} + +/// @brief Creates a node with is a page file. +/// @param path The filename path. +/// @return The Node pointer. +NodePtr NeFileSystemMgr::CreateSwapFile(const Char* path) { + return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindPage)); +} + +/// @brief Gets the root directory. +/// @return +const Char* NeFileSystemHelper::Root() { + return kNeFSRoot; +} + +/// @brief Gets the up-dir directory. +/// @return +const Char* NeFileSystemHelper::UpDir() { + return kNeFSUpDir; +} + +/// @brief Gets the separator character. +/// @return +Char NeFileSystemHelper::Separator() { + return kNeFSSeparator; +} + +/// @brief Gets the metafile character. +/// @return +Char NeFileSystemHelper::MetaFile() { + return kNeFSMetaFilePrefix; +} + +/// @brief Opens a new file. +/// @param path +/// @param r +/// @return +_Output NodePtr NeFileSystemMgr::Open(_Input const Char* path, _Input const Char* r) { + if (!path || *path == 0) return nullptr; + + if (!r || *r == 0) return nullptr; + + auto catalog = mParser->GetCatalog(path); + + return node_cast(catalog); +} + +/// @brief Writes to a catalog's fork. +/// @param node the node ptr. +/// @param data the data. +/// @param flags the size. +/// @return +Void NeFileSystemMgr::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, + _Input SizeT size) { + if (!node) return; + if (!size) return; + + constexpr auto kDataForkName = kNeFSDataFork; + this->Write(kDataForkName, node, data, flags, size); +} + +/// @brief Read from filesystem fork. +/// @param node the catalog node. +/// @param flags the flags with it. +/// @param sz the size to read. +/// @return +_Output VoidPtr NeFileSystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) { + if (!node) return nullptr; + if (!size) return nullptr; + + constexpr auto kDataForkName = kNeFSDataFork; + return this->Read(kDataForkName, node, flags, size); +} + +Void NeFileSystemMgr::Write(_Input const Char* name, _Input NodePtr node, _Input VoidPtr data, + _Input Int32 flags, _Input SizeT size) { + if (!size || size > kNeFSForkSize) return; + + if (!data) return; + + NE_UNUSED(flags); + + if ((reinterpret_cast<NEFS_CATALOG_STRUCT*>(node))->Kind == kNeFSCatalogKindFile) + mParser->WriteCatalog(reinterpret_cast<NEFS_CATALOG_STRUCT*>(node)->Name, + (flags & kFileFlagRsrc ? true : false), data, size, name); +} + +_Output VoidPtr NeFileSystemMgr::Read(_Input const Char* name, _Input NodePtr node, + _Input Int32 flags, _Input SizeT sz) { + if (sz > kNeFSForkSize) return nullptr; + + if (!sz) return nullptr; + + NE_UNUSED(flags); + + if ((reinterpret_cast<NEFS_CATALOG_STRUCT*>(node))->Kind == kNeFSCatalogKindFile) + return mParser->ReadCatalog(reinterpret_cast<NEFS_CATALOG_STRUCT*>(node), + (flags & kFileFlagRsrc ? true : false), sz, name); + + return nullptr; +} + +/// @brief Seek from Catalog. +/// @param node +/// @param off +/// @retval true always returns false, this is unimplemented. +/// @retval false always returns this, it is unimplemented. + +_Output Bool NeFileSystemMgr::Seek(NodePtr node, SizeT off) { + if (!node || off == 0) return false; + + return mParser->Seek(reinterpret_cast<NEFS_CATALOG_STRUCT*>(node), off); +} + +/// @brief Tell where the catalog is. +/// @param node +/// @retval true always returns false, this is unimplemented. +/// @retval false always returns this, it is unimplemented. + +_Output SizeT NeFileSystemMgr::Tell(NodePtr node) { + if (!node) return kNPos; + + return mParser->Tell(reinterpret_cast<NEFS_CATALOG_STRUCT*>(node)); +} + +/// @brief Rewinds the catalog. +/// @param node +/// @retval true always returns false, this is unimplemented. +/// @retval false always returns this, it is unimplemented. + +_Output Bool NeFileSystemMgr::Rewind(NodePtr node) { + if (!node) return false; + + return this->Seek(node, 0); +} + +/// @brief Returns the filesystem parser. +/// @return the Filesystem parser class. +_Output NeFileSystemParser* NeFileSystemMgr::GetParser() noexcept { + return mParser; +} +} // namespace Kernel + +#endif // ifdef __FSKIT_INCLUDES_NEFS__ +#endif // ifndef __NE_MINIMAL_OS__ diff --git a/dev/kernel/src/FS/NeFS.cc b/dev/kernel/src/FS/NeFS.cc index 8ebd551f..d0934f94 100644 --- a/dev/kernel/src/FS/NeFS.cc +++ b/dev/kernel/src/FS/NeFS.cc @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ @@ -9,23 +9,23 @@ #include <FSKit/NeFS.h> #include <FirmwareKit/EPM.h> -#include <modules/AHCI/AHCI.h> -#include <modules/ATA/ATA.h> +#include <KernelKit/DriveMgr.h> #include <KernelKit/KPC.h> +#include <KernelKit/ProcessScheduler.h> +#include <KernelKit/User.h> #include <NewKit/Crc32.h> -#include <NewKit/KernelPanic.h> #include <NewKit/KString.h> +#include <NewKit/KernelPanic.h> #include <NewKit/Utils.h> -#include <KernelKit/ProcessScheduler.h> -#include <KernelKit/User.h> -#include <KernelKit/DriveMgr.h> +#include <modules/AHCI/AHCI.h> +#include <modules/ATA/ATA.h> using namespace Kernel; #ifdef __NE_NO_BUILTIN__ /***********************************************************************************/ /** - Define those external symbols, to make the editor shutup + Define those external symbols, to make the editor shutup */ /***********************************************************************************/ @@ -60,99 +60,87 @@ STATIC MountpointInterface kMountpoint; /// @param the_fork the fork itself. /// @return the fork /***********************************************************************************/ -_Output BOOL NeFileSystemParser::CreateFork(_Input NEFS_FORK_STRUCT& the_fork) -{ - if (the_fork.ForkName[0] != 0 && - the_fork.CatalogName[0] != 0 && - the_fork.DataSize > 0) - { - auto catalog = this->GetCatalog(the_fork.CatalogName); +_Output BOOL NeFileSystemParser::CreateFork(_Input NEFS_FORK_STRUCT& the_fork) { + if (the_fork.ForkName[0] != 0 && the_fork.CatalogName[0] != 0 && the_fork.DataSize > 0) { + auto catalog = this->GetCatalog(the_fork.CatalogName); - if (!catalog) - return NO; + if (!catalog) return NO; - Lba lba = catalog->DataFork; + Lba lba = catalog->DataFork; - (Void)(kout << "Fork LBA: " << hex_number(lba) << kendl); + (Void)(kout << "Fork LBA: " << hex_number(lba) << kendl); - if (lba < kNeFSCatalogStartAddress) - return NO; + if (lba < kNeFSCatalogStartAddress) return NO; - auto& drv = kMountpoint.A(); + auto& drv = kMountpoint.A(); - Lba lba_prev = lba; + Lba lba_prev = lba; - NEFS_FORK_STRUCT prev_fork; - NEFS_FORK_STRUCT cur_fork; + NEFS_FORK_STRUCT prev_fork; + NEFS_FORK_STRUCT cur_fork; - /// do not check for anything. Loop until we get what we want, that is a free fork zone. - while (drv.fPacket.fPacketGood) - { - drv.fPacket.fPacketLba = lba; - drv.fPacket.fPacketSize = sizeof(NEFS_FORK_STRUCT); - drv.fPacket.fPacketContent = &cur_fork; + /// do not check for anything. Loop until we get what we want, that is a free fork zone. + while (drv.fPacket.fPacketGood) { + drv.fPacket.fPacketLba = lba; + drv.fPacket.fPacketSize = sizeof(NEFS_FORK_STRUCT); + drv.fPacket.fPacketContent = &cur_fork; - drv.fInput(drv.fPacket); + drv.fInput(drv.fPacket); - (Void)(kout << "Next fork: " << hex_number(cur_fork.NextSibling) << kendl); + (Void)(kout << "Next fork: " << hex_number(cur_fork.NextSibling) << kendl); - if (cur_fork.Flags & kNeFSFlagCreated) - { - kout << "Error: Fork does exists, not overwriting this one.\r"; + if (cur_fork.Flags & kNeFSFlagCreated) { + kout << "Error: Fork does exists, not overwriting this one.\r"; - /// sanity check. - if (KStringBuilder::Equals(cur_fork.ForkName, the_fork.ForkName) && - KStringBuilder::Equals(cur_fork.CatalogName, the_fork.CatalogName)) - break; + /// sanity check. + if (KStringBuilder::Equals(cur_fork.ForkName, the_fork.ForkName) && + KStringBuilder::Equals(cur_fork.CatalogName, the_fork.CatalogName)) + break; - lba_prev = lba; - lba = cur_fork.NextSibling; + lba_prev = lba; + lba = cur_fork.NextSibling; - prev_fork = cur_fork; - } - else - { - /// This is a check that we have, in order to link the previous fork - /// entry. - if (lba >= kNeFSCatalogStartAddress) - { - drv.fPacket.fPacketLba = lba_prev; - drv.fPacket.fPacketSize = sizeof(NEFS_FORK_STRUCT); - drv.fPacket.fPacketContent = &prev_fork; + prev_fork = cur_fork; + } else { + /// This is a check that we have, in order to link the previous fork + /// entry. + if (lba >= kNeFSCatalogStartAddress) { + drv.fPacket.fPacketLba = lba_prev; + drv.fPacket.fPacketSize = sizeof(NEFS_FORK_STRUCT); + drv.fPacket.fPacketContent = &prev_fork; - prev_fork.NextSibling = lba; + prev_fork.NextSibling = lba; - /// write to disk. - drv.fOutput(drv.fPacket); - } + /// write to disk. + drv.fOutput(drv.fPacket); + } - break; - } - } + break; + } + } - the_fork.Flags |= kNeFSFlagCreated; - the_fork.DataOffset = lba - sizeof(NEFS_FORK_STRUCT); - the_fork.PreviousSibling = lba_prev; - the_fork.NextSibling = the_fork.DataOffset - the_fork.DataSize; + the_fork.Flags |= kNeFSFlagCreated; + the_fork.DataOffset = lba - sizeof(NEFS_FORK_STRUCT); + the_fork.PreviousSibling = lba_prev; + the_fork.NextSibling = the_fork.DataOffset - the_fork.DataSize; - drv.fPacket.fPacketLba = lba; - drv.fPacket.fPacketSize = sizeof(NEFS_FORK_STRUCT); - drv.fPacket.fPacketContent = &the_fork; + drv.fPacket.fPacketLba = lba; + drv.fPacket.fPacketSize = sizeof(NEFS_FORK_STRUCT); + drv.fPacket.fPacketContent = &the_fork; - drv.fOutput(drv.fPacket); + drv.fOutput(drv.fPacket); - fs_ifs_write(&kMountpoint, drv, MountpointInterface::kDriveIndexA); + fs_ifs_write(&kMountpoint, drv, MountpointInterface::kDriveIndexA); - /// log what we have now. - (Void)(kout << "Fork offset is at: " << hex_number(the_fork.DataOffset) - << kendl); + /// log what we have now. + (Void)(kout << "Fork offset is at: " << hex_number(the_fork.DataOffset) << kendl); - (Void)(kout << "Wrote fork metadata at: " << hex_number(lba) << kendl); + (Void)(kout << "Wrote fork metadata at: " << hex_number(lba) << kendl); - return YES; - } + return YES; + } - return NO; + return NO; } /***********************************************************************************/ @@ -162,53 +150,46 @@ _Output BOOL NeFileSystemParser::CreateFork(_Input NEFS_FORK_STRUCT& the_fork) /// @return the newly found fork. /***********************************************************************************/ _Output NEFS_FORK_STRUCT* NeFileSystemParser::FindFork(_Input NEFS_CATALOG_STRUCT* catalog, - _Input const Char* name, - _Input Boolean is_data) -{ - auto& drive = kMountpoint.A(); - NEFS_FORK_STRUCT* the_fork = nullptr; - - Lba lba = is_data ? catalog->DataFork : catalog->ResourceFork; - - while (lba != 0) - { - drive.fPacket.fPacketLba = lba; - drive.fPacket.fPacketSize = sizeof(NEFS_FORK_STRUCT); - drive.fPacket.fPacketContent = (VoidPtr)the_fork; - - rt_copy_memory((VoidPtr) "fs/nefs-packet", drive.fPacket.fPacketMime, 16); - - if (auto res = - fs_ifs_read(&kMountpoint, drive, this->mDriveIndex); - res) - { - switch (res) - { - case 1: - err_global_get() = kErrorDiskReadOnly; - break; - case 2: - err_global_get() = kErrorDiskIsFull; - break; - case 3: - err_global_get() = kErrorNoSuchDisk; - break; - - default: - break; - } - return nullptr; - } - - if (KStringBuilder::Equals(the_fork->ForkName, name)) - { - break; - } - - lba = the_fork->NextSibling; - } - - return the_fork; + _Input const Char* name, + _Input Boolean is_data) { + auto& drive = kMountpoint.A(); + NEFS_FORK_STRUCT* the_fork = nullptr; + + Lba lba = is_data ? catalog->DataFork : catalog->ResourceFork; + + while (lba != 0) { + drive.fPacket.fPacketLba = lba; + drive.fPacket.fPacketSize = sizeof(NEFS_FORK_STRUCT); + drive.fPacket.fPacketContent = (VoidPtr) the_fork; + + rt_copy_memory((VoidPtr) "fs/nefs-packet", drive.fPacket.fPacketMime, 16); + + if (auto res = fs_ifs_read(&kMountpoint, drive, this->mDriveIndex); res) { + switch (res) { + case 1: + err_global_get() = kErrorDiskReadOnly; + break; + case 2: + err_global_get() = kErrorDiskIsFull; + break; + case 3: + err_global_get() = kErrorNoSuchDisk; + break; + + default: + break; + } + return nullptr; + } + + if (KStringBuilder::Equals(the_fork->ForkName, name)) { + break; + } + + lba = the_fork->NextSibling; + } + + return the_fork; } /***********************************************************************************/ @@ -217,9 +198,8 @@ _Output NEFS_FORK_STRUCT* NeFileSystemParser::FindFork(_Input NEFS_CATALOG_STRUC /// @param name /// @return catalog pointer. /***********************************************************************************/ -_Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* name) -{ - return this->CreateCatalog(name, 0, kNeFSCatalogKindFile); +_Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* name) { + return this->CreateCatalog(name, 0, kNeFSCatalogKindFile); } /***********************************************************************************/ @@ -229,729 +209,668 @@ _Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char /// @param kind the catalog kind. /// @return catalog pointer. /***********************************************************************************/ -_Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* name, - _Input const Int32& flags, - _Input const Int32& kind) -{ - kout << "CreateCatalog(*...*)\r"; +_Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* name, + _Input const Int32& flags, + _Input const Int32& kind) { + kout << "CreateCatalog(*...*)\r"; - Lba out_lba = 0UL; + Lba out_lba = 0UL; - kout << "Checking for path separator...\r"; + kout << "Checking for path separator...\r"; - /// a directory should have a slash in the end. - if (kind == kNeFSCatalogKindDir && - name[rt_string_len(name) - 1] != NeFileSystemHelper::Separator()) - return nullptr; + /// a directory should have a slash in the end. + if (kind == kNeFSCatalogKindDir && + name[rt_string_len(name) - 1] != NeFileSystemHelper::Separator()) + return nullptr; - /// a file shouldn't have a slash in the end. - if (kind != kNeFSCatalogKindDir && - name[rt_string_len(name) - 1] == NeFileSystemHelper::Separator()) - return nullptr; + /// a file shouldn't have a slash in the end. + if (kind != kNeFSCatalogKindDir && + name[rt_string_len(name) - 1] == NeFileSystemHelper::Separator()) + return nullptr; - NEFS_CATALOG_STRUCT* catalog_copy = this->FindCatalog(name, out_lba); + NEFS_CATALOG_STRUCT* catalog_copy = this->FindCatalog(name, out_lba); - if (catalog_copy) - { - kout << "Catalog already exists: " << name << ".\r"; - err_global_get() = kErrorFileExists; + if (catalog_copy) { + kout << "Catalog already exists: " << name << ".\r"; + err_global_get() = kErrorFileExists; - delete catalog_copy; - catalog_copy = nullptr; + delete catalog_copy; + catalog_copy = nullptr; - return nullptr; - } + return nullptr; + } - Char parent_name[kNeFSCatalogNameLen] = {0}; + Char parent_name[kNeFSCatalogNameLen] = {0}; - for (SizeT indexName = 0UL; indexName < rt_string_len(name); ++indexName) - { - parent_name[indexName] = name[indexName]; - } + for (SizeT indexName = 0UL; indexName < rt_string_len(name); ++indexName) { + parent_name[indexName] = name[indexName]; + } - if (*parent_name == 0) - { - kout << "Parent name is NUL.\r"; - err_global_get() = kErrorFileNotFound; - return nullptr; - } + if (*parent_name == 0) { + kout << "Parent name is NUL.\r"; + err_global_get() = kErrorFileNotFound; + return nullptr; + } - /// Locate parent catalog, to then allocate right after it. + /// Locate parent catalog, to then allocate right after it. - for (SizeT index_fill = 0; index_fill < rt_string_len(name); ++index_fill) - { - parent_name[index_fill] = name[index_fill]; - } + for (SizeT index_fill = 0; index_fill < rt_string_len(name); ++index_fill) { + parent_name[index_fill] = name[index_fill]; + } - SizeT index_reverse_copy = rt_string_len(parent_name); + SizeT index_reverse_copy = rt_string_len(parent_name); - // zero character it. - parent_name[--index_reverse_copy] = 0; + // zero character it. + parent_name[--index_reverse_copy] = 0; - // mandatory / character, zero it. - parent_name[--index_reverse_copy] = 0; + // mandatory / character, zero it. + parent_name[--index_reverse_copy] = 0; - while (parent_name[index_reverse_copy] != NeFileSystemHelper::Separator()) - { - parent_name[index_reverse_copy] = 0; - --index_reverse_copy; - } + while (parent_name[index_reverse_copy] != NeFileSystemHelper::Separator()) { + parent_name[index_reverse_copy] = 0; + --index_reverse_copy; + } - NEFS_CATALOG_STRUCT* catalog = this->FindCatalog(parent_name, out_lba); + NEFS_CATALOG_STRUCT* catalog = this->FindCatalog(parent_name, out_lba); - auto& drive = kMountpoint.A(); + auto& drive = kMountpoint.A(); - constexpr auto kNeFSCatalogPadding = 4; + constexpr auto kNeFSCatalogPadding = 4; - if (catalog && catalog->Kind == kNeFSCatalogKindFile) - { - kout << "Parent is a file.\r"; - delete catalog; + if (catalog && catalog->Kind == kNeFSCatalogKindFile) { + kout << "Parent is a file.\r"; + delete catalog; - return nullptr; - } - else if (!catalog) - { - Char part_block[sizeof(NEFS_ROOT_PARTITION_BLOCK)] = {0}; + return nullptr; + } else if (!catalog) { + Char part_block[sizeof(NEFS_ROOT_PARTITION_BLOCK)] = {0}; - drive.fPacket.fPacketContent = part_block; - drive.fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); - drive.fPacket.fPacketLba = kNeFSRootCatalogStartAddress; + drive.fPacket.fPacketContent = part_block; + drive.fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); + drive.fPacket.fPacketLba = kNeFSRootCatalogStartAddress; - drive.fInput(drive.fPacket); + drive.fInput(drive.fPacket); - NEFS_ROOT_PARTITION_BLOCK* blk_nefs = (NEFS_ROOT_PARTITION_BLOCK*)part_block; - out_lba = blk_nefs->StartCatalog; - } + NEFS_ROOT_PARTITION_BLOCK* blk_nefs = (NEFS_ROOT_PARTITION_BLOCK*) part_block; + out_lba = blk_nefs->StartCatalog; + } - if (drive.fPacket.fPacketReadOnly) - return nullptr; + if (drive.fPacket.fPacketReadOnly) return nullptr; - NEFS_CATALOG_STRUCT* child_catalog = new NEFS_CATALOG_STRUCT(); + NEFS_CATALOG_STRUCT* child_catalog = new NEFS_CATALOG_STRUCT(); - child_catalog->Checksum = 0; - child_catalog->ResourceForkSize = 0UL; - child_catalog->DataForkSize = 0UL; - child_catalog->CatalogFlags = kNeFSStatusUnlocked; - child_catalog->NextSibling = out_lba; - child_catalog->PrevSibling = out_lba; - child_catalog->Kind = kind; - child_catalog->Flags |= kNeFSFlagCreated; - child_catalog->CatalogFlags = flags; + child_catalog->Checksum = 0; + child_catalog->ResourceForkSize = 0UL; + child_catalog->DataForkSize = 0UL; + child_catalog->CatalogFlags = kNeFSStatusUnlocked; + child_catalog->NextSibling = out_lba; + child_catalog->PrevSibling = out_lba; + child_catalog->Kind = kind; + child_catalog->Flags |= kNeFSFlagCreated; + child_catalog->CatalogFlags = flags; - SizeT i = rt_string_len(name); + SizeT i = rt_string_len(name); - // get rid pf \0 - --i; + // get rid pf \0 + --i; - if (kind == kNeFSCatalogKindDir) - --i; + if (kind == kNeFSCatalogKindDir) --i; - while (name[i] != '/') - --i; + while (name[i] != '/') --i; - rt_copy_memory((VoidPtr)(name + i), (VoidPtr)child_catalog->Name, - rt_string_len(name)); + rt_copy_memory((VoidPtr) (name + i), (VoidPtr) child_catalog->Name, rt_string_len(name)); - NEFS_CATALOG_STRUCT temporary_catalog{}; + NEFS_CATALOG_STRUCT temporary_catalog{}; - Lba start_free = out_lba; + Lba start_free = out_lba; - rt_copy_memory((VoidPtr) "fs/nefs-packet", drive.fPacket.fPacketMime, - rt_string_len("fs/nefs-packet")); + rt_copy_memory((VoidPtr) "fs/nefs-packet", drive.fPacket.fPacketMime, + rt_string_len("fs/nefs-packet")); - Char buf_part_block[sizeof(NEFS_ROOT_PARTITION_BLOCK)] = {0}; + Char buf_part_block[sizeof(NEFS_ROOT_PARTITION_BLOCK)] = {0}; - drive.fPacket.fPacketContent = buf_part_block; - drive.fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); - drive.fPacket.fPacketLba = kNeFSRootCatalogStartAddress; + drive.fPacket.fPacketContent = buf_part_block; + drive.fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); + drive.fPacket.fPacketLba = kNeFSRootCatalogStartAddress; - drive.fInput(drive.fPacket); + drive.fInput(drive.fPacket); - NEFS_ROOT_PARTITION_BLOCK* part_block = (NEFS_ROOT_PARTITION_BLOCK*)buf_part_block; + NEFS_ROOT_PARTITION_BLOCK* part_block = (NEFS_ROOT_PARTITION_BLOCK*) buf_part_block; - drive.fPacket.fPacketContent = &temporary_catalog; - drive.fPacket.fPacketSize = sizeof(NEFS_CATALOG_STRUCT); - drive.fPacket.fPacketLba = start_free; + drive.fPacket.fPacketContent = &temporary_catalog; + drive.fPacket.fPacketSize = sizeof(NEFS_CATALOG_STRUCT); + drive.fPacket.fPacketLba = start_free; - drive.fInput(drive.fPacket); + drive.fInput(drive.fPacket); - if (part_block->FreeCatalog < 1) - { - delete child_catalog; - child_catalog = nullptr; + if (part_block->FreeCatalog < 1) { + delete child_catalog; + child_catalog = nullptr; - return nullptr; - } + return nullptr; + } - kout << "Start finding catalog to allocate or empty space...\r"; + kout << "Start finding catalog to allocate or empty space...\r"; - while (start_free >= part_block->StartCatalog) - { - // ========================== // - // Allocate catalog now... - // ========================== // - if ((temporary_catalog.Flags & kNeFSFlagCreated) == 0) - { - child_catalog->NextSibling = - start_free + (sizeof(NEFS_CATALOG_STRUCT) * kNeFSCatalogPadding); + while (start_free >= part_block->StartCatalog) { + // ========================== // + // Allocate catalog now... + // ========================== // + if ((temporary_catalog.Flags & kNeFSFlagCreated) == 0) { + child_catalog->NextSibling = start_free + (sizeof(NEFS_CATALOG_STRUCT) * kNeFSCatalogPadding); - drive.fPacket.fPacketContent = &temporary_catalog; - drive.fPacket.fPacketSize = sizeof(NEFS_CATALOG_STRUCT); - drive.fPacket.fPacketLba = start_free; + drive.fPacket.fPacketContent = &temporary_catalog; + drive.fPacket.fPacketSize = sizeof(NEFS_CATALOG_STRUCT); + drive.fPacket.fPacketLba = start_free; - drive.fOutput(drive.fPacket); + drive.fOutput(drive.fPacket); - child_catalog->DataFork = part_block->DiskSize - start_free; - child_catalog->ResourceFork = child_catalog->DataFork; + child_catalog->DataFork = part_block->DiskSize - start_free; + child_catalog->ResourceFork = child_catalog->DataFork; - drive.fPacket.fPacketContent = child_catalog; - drive.fPacket.fPacketSize = sizeof(NEFS_CATALOG_STRUCT); - drive.fPacket.fPacketLba = start_free; + drive.fPacket.fPacketContent = child_catalog; + drive.fPacket.fPacketSize = sizeof(NEFS_CATALOG_STRUCT); + drive.fPacket.fPacketLba = start_free; - drive.fOutput(drive.fPacket); + drive.fOutput(drive.fPacket); - // Get NeFS partition's block. + // Get NeFS partition's block. - drive.fPacket.fPacketContent = buf_part_block; - drive.fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); - drive.fPacket.fPacketLba = kNeFSRootCatalogStartAddress; + drive.fPacket.fPacketContent = buf_part_block; + drive.fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); + drive.fPacket.fPacketLba = kNeFSRootCatalogStartAddress; - drive.fInput(drive.fPacket); + drive.fInput(drive.fPacket); - part_block->FreeSectors -= 1; - part_block->CatalogCount += 1; - part_block->FreeCatalog -= 1; + part_block->FreeSectors -= 1; + part_block->CatalogCount += 1; + part_block->FreeCatalog -= 1; - drive.fOutput(drive.fPacket); + drive.fOutput(drive.fPacket); - delete catalog; - catalog = nullptr; + delete catalog; + catalog = nullptr; - NEFS_CATALOG_STRUCT* found_catalog = new NEFS_CATALOG_STRUCT(); - rt_copy_memory(&temporary_catalog, found_catalog, sizeof(NEFS_CATALOG_STRUCT)); + NEFS_CATALOG_STRUCT* found_catalog = new NEFS_CATALOG_STRUCT(); + rt_copy_memory(&temporary_catalog, found_catalog, sizeof(NEFS_CATALOG_STRUCT)); - return found_catalog; - } - else if ((temporary_catalog.Flags & kNeFSFlagCreated) && - KStringBuilder::Equals(temporary_catalog.Name, name)) - { - rt_copy_memory(&temporary_catalog, child_catalog, sizeof(NEFS_CATALOG_STRUCT)); + return found_catalog; + } else if ((temporary_catalog.Flags & kNeFSFlagCreated) && + KStringBuilder::Equals(temporary_catalog.Name, name)) { + rt_copy_memory(&temporary_catalog, child_catalog, sizeof(NEFS_CATALOG_STRUCT)); - return child_catalog; - } + return child_catalog; + } - start_free = start_free + (sizeof(NEFS_CATALOG_STRUCT) * kNeFSCatalogPadding); + start_free = start_free + (sizeof(NEFS_CATALOG_STRUCT) * kNeFSCatalogPadding); - drive.fPacket.fPacketContent = &temporary_catalog; - drive.fPacket.fPacketSize = sizeof(NEFS_CATALOG_STRUCT); - drive.fPacket.fPacketLba = start_free; + drive.fPacket.fPacketContent = &temporary_catalog; + drive.fPacket.fPacketSize = sizeof(NEFS_CATALOG_STRUCT); + drive.fPacket.fPacketLba = start_free; - drive.fInput(drive.fPacket); - } + drive.fInput(drive.fPacket); + } - delete catalog; - return nullptr; + delete catalog; + 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); +_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"); + (Void)(kout << "FormatGPT: Not implemented yet.\r"); - return NO; + 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::FormatEPM(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name) -{ - if (*part_name == 0 || - endLba == 0) - return false; +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) return false; - // verify disk. - drive->fVerify(drive->fPacket); + // verify disk. + drive->fVerify(drive->fPacket); - rt_copy_memory((VoidPtr) "fs/nefs-packet", drive->fPacket.fPacketMime, - rt_string_len("fs/nefs-packet")); + rt_copy_memory((VoidPtr) "fs/nefs-packet", drive->fPacket.fPacketMime, + rt_string_len("fs/nefs-packet")); - // if disk isn't good, then error out. - if (false == drive->fPacket.fPacketGood) - { - err_global_get() = kErrorDiskIsCorrupted; - return false; - } + // if disk isn't good, then error out. + if (false == drive->fPacket.fPacketGood) { + err_global_get() = kErrorDiskIsCorrupted; + return false; + } - Char fs_buf[sizeof(NEFS_ROOT_PARTITION_BLOCK)] = {0}; + Char fs_buf[sizeof(NEFS_ROOT_PARTITION_BLOCK)] = {0}; - Lba start = kNeFSRootCatalogStartAddress; + Lba start = kNeFSRootCatalogStartAddress; - drive->fPacket.fPacketContent = fs_buf; - drive->fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); - drive->fPacket.fPacketLba = start; + drive->fPacket.fPacketContent = fs_buf; + drive->fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); + drive->fPacket.fPacketLba = start; - drive->fInput(drive->fPacket); + drive->fInput(drive->fPacket); - if (flags & kNeFSPartitionTypeBoot) - { - // make it bootable when needed. - Char buf_epm[kNeFSSectorSz] = {0}; + if (flags & kNeFSPartitionTypeBoot) { + // make it bootable when needed. + Char buf_epm[kNeFSSectorSz] = {0}; - EPM_PART_BLOCK* epm_boot = (EPM_PART_BLOCK*)buf_epm; + EPM_PART_BLOCK* epm_boot = (EPM_PART_BLOCK*) buf_epm; - // Write a new EPM entry. + // Write a new EPM entry. - constexpr auto kFsName = "NeFS"; - constexpr auto kBlockName = "NeKernel:"; + constexpr auto kFsName = "NeFS"; + constexpr auto kBlockName = "NeKernel:"; - epm_boot->FsVersion = kNeFSVersionInteger; - epm_boot->LbaStart = start; - epm_boot->SectorSz = kNeFSSectorSz; + epm_boot->FsVersion = kNeFSVersionInteger; + epm_boot->LbaStart = start; + epm_boot->SectorSz = kNeFSSectorSz; - rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(kFsName)), epm_boot->Fs, rt_string_len(kFsName)); - rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(kBlockName)), epm_boot->Name, rt_string_len(kBlockName)); - rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(kEPMMagic)), epm_boot->Magic, rt_string_len(kEPMMagic)); + rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(kFsName)), epm_boot->Fs, + rt_string_len(kFsName)); + rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(kBlockName)), epm_boot->Name, + rt_string_len(kBlockName)); + rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(kEPMMagic)), epm_boot->Magic, + rt_string_len(kEPMMagic)); - Lba outEpmLba = kEPMBootBlockLba; + Lba outEpmLba = kEPMBootBlockLba; - Char buf[kNeFSSectorSz] = {0}; + Char buf[kNeFSSectorSz] = {0}; - Lba prevStart = 0; - SizeT cnt = 0; + Lba prevStart = 0; + SizeT cnt = 0; - while (drive->fPacket.fPacketGood) - { - drive->fPacket.fPacketContent = buf; - drive->fPacket.fPacketSize = sizeof(EPM_PART_BLOCK); - drive->fPacket.fPacketLba = outEpmLba; + while (drive->fPacket.fPacketGood) { + drive->fPacket.fPacketContent = buf; + drive->fPacket.fPacketSize = sizeof(EPM_PART_BLOCK); + drive->fPacket.fPacketLba = outEpmLba; - drive->fInput(drive->fPacket); + drive->fInput(drive->fPacket); - if (buf[0] == 0) - { - epm_boot->LbaStart = prevStart; + if (buf[0] == 0) { + epm_boot->LbaStart = prevStart; - if (epm_boot->LbaStart) - epm_boot->LbaStart = outEpmLba; + if (epm_boot->LbaStart) epm_boot->LbaStart = outEpmLba; - epm_boot->LbaEnd = endLba; - epm_boot->NumBlocks = cnt; + epm_boot->LbaEnd = endLba; + epm_boot->NumBlocks = cnt; - drive->fPacket.fPacketContent = buf_epm; - drive->fPacket.fPacketSize = sizeof(EPM_PART_BLOCK); - drive->fPacket.fPacketLba = outEpmLba; + drive->fPacket.fPacketContent = buf_epm; + drive->fPacket.fPacketSize = sizeof(EPM_PART_BLOCK); + drive->fPacket.fPacketLba = outEpmLba; - drive->fOutput(drive->fPacket); + drive->fOutput(drive->fPacket); - break; - } - else - { - prevStart = ((EPM_PART_BLOCK*)buf)->LbaStart + ((EPM_PART_BLOCK*)buf)->LbaEnd; - } + break; + } else { + prevStart = ((EPM_PART_BLOCK*) buf)->LbaStart + ((EPM_PART_BLOCK*) buf)->LbaEnd; + } - outEpmLba += sizeof(EPM_PART_BLOCK); - ++cnt; - } - } + outEpmLba += sizeof(EPM_PART_BLOCK); + ++cnt; + } + } - // disk isnt faulty and data has been fetched. - while (drive->fPacket.fPacketGood) - { - NEFS_ROOT_PARTITION_BLOCK* part_block = (NEFS_ROOT_PARTITION_BLOCK*)fs_buf; + // disk isnt faulty and data has been fetched. + while (drive->fPacket.fPacketGood) { + NEFS_ROOT_PARTITION_BLOCK* part_block = (NEFS_ROOT_PARTITION_BLOCK*) fs_buf; - // check for an empty partition here. - if (part_block->PartitionName[0] == 0 && - rt_string_cmp(part_block->Ident, kNeFSIdent, kNeFSIdentLen)) - { - // partition is free and valid. + // check for an empty partition here. + if (part_block->PartitionName[0] == 0 && + rt_string_cmp(part_block->Ident, kNeFSIdent, kNeFSIdentLen)) { + // partition is free and valid. - part_block->Version = kNeFSVersionInteger; + part_block->Version = kNeFSVersionInteger; - const auto kNeFSUntitledHD = part_name; + const auto kNeFSUntitledHD = part_name; - rt_copy_memory((VoidPtr)kNeFSIdent, (VoidPtr)part_block->Ident, - kNeFSIdentLen); + rt_copy_memory((VoidPtr) kNeFSIdent, (VoidPtr) part_block->Ident, kNeFSIdentLen); - rt_copy_memory((VoidPtr)kNeFSUntitledHD, (VoidPtr)part_block->PartitionName, - rt_string_len(kNeFSUntitledHD)); + rt_copy_memory((VoidPtr) kNeFSUntitledHD, (VoidPtr) part_block->PartitionName, + rt_string_len(kNeFSUntitledHD)); - SizeT sectorCount = drv_get_sector_count(); - SizeT diskSize = drv_get_size(); + SizeT sectorCount = drv_get_sector_count(); + SizeT diskSize = drv_get_size(); - part_block->Kind = kNeFSPartitionTypeStandard; - part_block->StartCatalog = kNeFSCatalogStartAddress; - part_block->Flags = kNeFSPartitionTypeStandard; - part_block->CatalogCount = sectorCount / sizeof(NEFS_CATALOG_STRUCT); - part_block->FreeSectors = sectorCount / sizeof(NEFS_CATALOG_STRUCT); - part_block->SectorCount = sectorCount; - part_block->DiskSize = diskSize; - part_block->FreeCatalog = sectorCount / sizeof(NEFS_CATALOG_STRUCT); + part_block->Kind = kNeFSPartitionTypeStandard; + part_block->StartCatalog = kNeFSCatalogStartAddress; + part_block->Flags = kNeFSPartitionTypeStandard; + part_block->CatalogCount = sectorCount / sizeof(NEFS_CATALOG_STRUCT); + part_block->FreeSectors = sectorCount / sizeof(NEFS_CATALOG_STRUCT); + part_block->SectorCount = sectorCount; + part_block->DiskSize = diskSize; + part_block->FreeCatalog = sectorCount / sizeof(NEFS_CATALOG_STRUCT); - drive->fPacket.fPacketContent = fs_buf; - drive->fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); - drive->fPacket.fPacketLba = kNeFSRootCatalogStartAddress; + drive->fPacket.fPacketContent = fs_buf; + drive->fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); + drive->fPacket.fPacketLba = kNeFSRootCatalogStartAddress; - drive->fOutput(drive->fPacket); + drive->fOutput(drive->fPacket); - (Void)(kout << "drive kind: " << drive->fProtocol() << kendl); + (Void)(kout << "drive kind: " << drive->fProtocol() << kendl); - (Void)(kout << "partition name: " << part_block->PartitionName << kendl); - (Void)(kout << "start: " << hex_number(part_block->StartCatalog) << kendl); - (Void)(kout << "number of catalogs: " << hex_number(part_block->CatalogCount) << kendl); - (Void)(kout << "free catalog: " << hex_number(part_block->FreeCatalog) << kendl); - (Void)(kout << "free sectors: " << hex_number(part_block->FreeSectors) << kendl); - (Void)(kout << "sector size: " << hex_number(part_block->SectorSize) << kendl); + (Void)(kout << "partition name: " << part_block->PartitionName << kendl); + (Void)(kout << "start: " << hex_number(part_block->StartCatalog) << kendl); + (Void)(kout << "number of catalogs: " << hex_number(part_block->CatalogCount) << kendl); + (Void)(kout << "free catalog: " << hex_number(part_block->FreeCatalog) << kendl); + (Void)(kout << "free sectors: " << hex_number(part_block->FreeSectors) << kendl); + (Void)(kout << "sector size: " << hex_number(part_block->SectorSize) << kendl); - // write the root catalog. - this->CreateCatalog(kNeFSRoot, 0, kNeFSCatalogKindDir); + // write the root catalog. + this->CreateCatalog(kNeFSRoot, 0, kNeFSCatalogKindDir); - return true; - } + return true; + } - kout << "partition block already exists.\r"; + kout << "partition block already exists.\r"; - start += part_block->DiskSize; + start += part_block->DiskSize; - drive->fPacket.fPacketContent = fs_buf; - drive->fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); - drive->fPacket.fPacketLba = start; + drive->fPacket.fPacketContent = fs_buf; + drive->fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); + drive->fPacket.fPacketLba = start; - drive->fInput(drive->fPacket); - } + drive->fInput(drive->fPacket); + } - return false; + return false; } /// @brief Writes the data fork into a specific catalog. /// @param catalog the catalog itself /// @param data the data. /// @return if the catalog w rote the contents successfully. -bool NeFileSystemParser::WriteCatalog(_Input const Char* catalog_name, Bool is_rsrc_fork, _Input VoidPtr data, _Input SizeT size_of_data, _Input const Char* fork_name) -{ - if (size_of_data < 1) - return No; +bool NeFileSystemParser::WriteCatalog(_Input const Char* catalog_name, Bool is_rsrc_fork, + _Input VoidPtr data, _Input SizeT size_of_data, + _Input const Char* fork_name) { + if (size_of_data < 1) return No; - auto buf = new UInt8[size_of_data]; - rt_set_memory(buf, 0, size_of_data); + auto buf = new UInt8[size_of_data]; + rt_set_memory(buf, 0, size_of_data); - rt_copy_memory(data, buf, size_of_data); + rt_copy_memory(data, buf, size_of_data); - auto& drive = kMountpoint.A(); + auto& drive = kMountpoint.A(); - rt_copy_memory((VoidPtr) "fs/nefs-packet", drive.fPacket.fPacketMime, - rt_string_len("fs/nefs-packet")); + rt_copy_memory((VoidPtr) "fs/nefs-packet", drive.fPacket.fPacketMime, + rt_string_len("fs/nefs-packet")); - auto catalog = this->GetCatalog(catalog_name); + auto catalog = this->GetCatalog(catalog_name); - if (!catalog) - { - delete[] buf; - buf = nullptr; - return NO; - } + if (!catalog) { + delete[] buf; + buf = nullptr; + return NO; + } - auto startFork = (!is_rsrc_fork) ? catalog->DataFork - : catalog->ResourceFork; + auto startFork = (!is_rsrc_fork) ? catalog->DataFork : catalog->ResourceFork; - delete catalog; - catalog = nullptr; + delete catalog; + catalog = nullptr; - NEFS_FORK_STRUCT* fork_data_input = new NEFS_FORK_STRUCT(); - NEFS_FORK_STRUCT prev_fork{}; + NEFS_FORK_STRUCT* fork_data_input = new NEFS_FORK_STRUCT(); + NEFS_FORK_STRUCT prev_fork{}; - (Void)(kout << hex_number(startFork) << kendl); + (Void)(kout << hex_number(startFork) << kendl); - // sanity check of the fork position as the condition to run the loop. - while (startFork >= kNeFSCatalogStartAddress) - { - drive.fPacket.fPacketContent = fork_data_input; - drive.fPacket.fPacketSize = sizeof(NEFS_FORK_STRUCT); - drive.fPacket.fPacketLba = startFork; + // sanity check of the fork position as the condition to run the loop. + while (startFork >= kNeFSCatalogStartAddress) { + drive.fPacket.fPacketContent = fork_data_input; + drive.fPacket.fPacketSize = sizeof(NEFS_FORK_STRUCT); + drive.fPacket.fPacketLba = startFork; - drive.fInput(drive.fPacket); + drive.fInput(drive.fPacket); - (Void)(kout << hex_number(fork_data_input->DataSize) << kendl); - (Void)(kout << hex_number(size_of_data) << kendl); - (Void)(kout << hex_number(fork_data_input->Flags) << kendl); - (Void)(kout << fork_name << kendl); - (Void)(kout << fork_data_input->ForkName << kendl); - (Void)(kout << fork_data_input->CatalogName << kendl); - (Void)(kout << catalog_name << kendl); + (Void)(kout << hex_number(fork_data_input->DataSize) << kendl); + (Void)(kout << hex_number(size_of_data) << kendl); + (Void)(kout << hex_number(fork_data_input->Flags) << kendl); + (Void)(kout << fork_name << kendl); + (Void)(kout << fork_data_input->ForkName << kendl); + (Void)(kout << fork_data_input->CatalogName << kendl); + (Void)(kout << catalog_name << kendl); - if ((fork_data_input->Flags & kNeFSFlagCreated) && - KStringBuilder::Equals(fork_data_input->ForkName, fork_name) && - KStringBuilder::Equals(fork_data_input->CatalogName, catalog_name) && - fork_data_input->DataSize == size_of_data) - { - // ===================================================== // - // Store the blob now. - // ===================================================== // + if ((fork_data_input->Flags & kNeFSFlagCreated) && + KStringBuilder::Equals(fork_data_input->ForkName, fork_name) && + KStringBuilder::Equals(fork_data_input->CatalogName, catalog_name) && + fork_data_input->DataSize == size_of_data) { + // ===================================================== // + // Store the blob now. + // ===================================================== // - drive.fPacket.fPacketContent = buf; - drive.fPacket.fPacketSize = size_of_data; - drive.fPacket.fPacketLba = fork_data_input->DataOffset; + drive.fPacket.fPacketContent = buf; + drive.fPacket.fPacketSize = size_of_data; + drive.fPacket.fPacketLba = fork_data_input->DataOffset; - (Void)(kout << "data offset: " << hex_number(fork_data_input->DataOffset) << kendl); + (Void)(kout << "data offset: " << hex_number(fork_data_input->DataOffset) << kendl); - drive.fOutput(drive.fPacket); + drive.fOutput(drive.fPacket); - (Void)(kout << "wrote data at offset: " << hex_number(fork_data_input->DataOffset) << kendl); + (Void)(kout << "wrote data at offset: " << hex_number(fork_data_input->DataOffset) << kendl); - delete fork_data_input; - delete[] buf; + delete fork_data_input; + delete[] buf; - return true; - } + return true; + } - // stumble upon a fork, store it. + // stumble upon a fork, store it. - prev_fork = *fork_data_input; + prev_fork = *fork_data_input; - startFork = fork_data_input->NextSibling; - } + startFork = fork_data_input->NextSibling; + } - delete[] buf; - delete fork_data_input; + delete[] buf; + delete fork_data_input; - return false; + return false; } /// @brief /// @param catalog_name the catalog name. /// @return the newly found catalog. _Output NEFS_CATALOG_STRUCT* NeFileSystemParser::FindCatalog(_Input const Char* catalog_name, - Lba& out_lba, - Bool search_hidden, - Bool local_search) -{ - if (!catalog_name || - *catalog_name == 0) - return nullptr; + Lba& out_lba, Bool search_hidden, + Bool local_search) { + if (!catalog_name || *catalog_name == 0) return nullptr; - NEFS_ROOT_PARTITION_BLOCK part{}; - auto& drive = kMountpoint.A(); + NEFS_ROOT_PARTITION_BLOCK part{}; + auto& drive = kMountpoint.A(); - rt_copy_memory((VoidPtr) "fs/nefs-packet", drive.fPacket.fPacketMime, - rt_string_len("fs/nefs-packet")); + rt_copy_memory((VoidPtr) "fs/nefs-packet", drive.fPacket.fPacketMime, + rt_string_len("fs/nefs-packet")); - drive.fPacket.fPacketContent = ∂ - drive.fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); - drive.fPacket.fPacketLba = kNeFSRootCatalogStartAddress; + drive.fPacket.fPacketContent = ∂ + drive.fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); + drive.fPacket.fPacketLba = kNeFSRootCatalogStartAddress; - drive.fInput(drive.fPacket); + drive.fInput(drive.fPacket); - auto start_catalog_lba = kNeFSCatalogStartAddress; + auto start_catalog_lba = kNeFSCatalogStartAddress; - if (!KStringBuilder::Equals(catalog_name, NeFileSystemHelper::Root()) && local_search) - { - Char parent_name[kNeFSCatalogNameLen] = {0}; + if (!KStringBuilder::Equals(catalog_name, NeFileSystemHelper::Root()) && local_search) { + Char parent_name[kNeFSCatalogNameLen] = {0}; - for (SizeT indexFill = 0; indexFill < rt_string_len(catalog_name); ++indexFill) - { - parent_name[indexFill] = catalog_name[indexFill]; - } + for (SizeT indexFill = 0; indexFill < rt_string_len(catalog_name); ++indexFill) { + parent_name[indexFill] = catalog_name[indexFill]; + } - SizeT indexReverseCopy = rt_string_len(parent_name); + SizeT indexReverseCopy = rt_string_len(parent_name); - // zero character. - parent_name[--indexReverseCopy] = 0; + // zero character. + parent_name[--indexReverseCopy] = 0; - // mandatory '/' character. - parent_name[--indexReverseCopy] = 0; + // mandatory '/' character. + parent_name[--indexReverseCopy] = 0; - while (parent_name[indexReverseCopy] != NeFileSystemHelper::Separator()) - { - parent_name[indexReverseCopy] = 0; - --indexReverseCopy; - } + while (parent_name[indexReverseCopy] != NeFileSystemHelper::Separator()) { + parent_name[indexReverseCopy] = 0; + --indexReverseCopy; + } - NEFS_CATALOG_STRUCT* parent_catalog = this->FindCatalog(parent_name, out_lba); + NEFS_CATALOG_STRUCT* parent_catalog = this->FindCatalog(parent_name, out_lba); - if (parent_catalog && - !KStringBuilder::Equals(parent_name, NeFileSystemHelper::Root())) - { - start_catalog_lba = parent_catalog->NextSibling; + if (parent_catalog && !KStringBuilder::Equals(parent_name, NeFileSystemHelper::Root())) { + start_catalog_lba = parent_catalog->NextSibling; - delete parent_catalog; - parent_catalog = nullptr; + delete parent_catalog; + parent_catalog = nullptr; - local_search = YES; - } - else if (parent_catalog) - { - start_catalog_lba = parent_catalog->NextSibling; + local_search = YES; + } else if (parent_catalog) { + start_catalog_lba = parent_catalog->NextSibling; - local_search = YES; + local_search = YES; - delete parent_catalog; - parent_catalog = nullptr; - } - else if (!parent_catalog) - { - return nullptr; - } - } + delete parent_catalog; + parent_catalog = nullptr; + } else if (!parent_catalog) { + return nullptr; + } + } - NEFS_CATALOG_STRUCT temporary_catalog{}; + NEFS_CATALOG_STRUCT temporary_catalog{}; - SizeT i = rt_string_len(catalog_name); + SizeT i = rt_string_len(catalog_name); - // get rid of \0 - --i; + // get rid of \0 + --i; - if (catalog_name[i] == '/') - --i; + if (catalog_name[i] == '/') --i; - while (catalog_name[i] != '/') - --i; + while (catalog_name[i] != '/') --i; - const Char* tmp_name = (catalog_name + i); + const Char* tmp_name = (catalog_name + i); kNeFSSearchThroughCatalogList: - while (drive.fPacket.fPacketGood) - { - drive.fPacket.fPacketLba = start_catalog_lba; - drive.fPacket.fPacketContent = &temporary_catalog; - drive.fPacket.fPacketSize = sizeof(NEFS_CATALOG_STRUCT); + while (drive.fPacket.fPacketGood) { + drive.fPacket.fPacketLba = start_catalog_lba; + drive.fPacket.fPacketContent = &temporary_catalog; + drive.fPacket.fPacketSize = sizeof(NEFS_CATALOG_STRUCT); - drive.fInput(drive.fPacket); + drive.fInput(drive.fPacket); - if (KStringBuilder::Equals(tmp_name, temporary_catalog.Name)) - { - if (temporary_catalog.Status == kNeFSStatusLocked && - !search_hidden) - { - err_global_get() = kErrorFileLocked; + if (KStringBuilder::Equals(tmp_name, temporary_catalog.Name)) { + if (temporary_catalog.Status == kNeFSStatusLocked && !search_hidden) { + err_global_get() = kErrorFileLocked; - goto NeFSContinueSearch; - } + goto NeFSContinueSearch; + } - /// ignore unallocated catalog, break - if (!(temporary_catalog.Flags & kNeFSFlagCreated)) - { - err_global_get() = kErrorFileNotFound; + /// ignore unallocated catalog, break + if (!(temporary_catalog.Flags & kNeFSFlagCreated)) { + err_global_get() = kErrorFileNotFound; - goto NeFSContinueSearch; - } + goto NeFSContinueSearch; + } - (Void)(kout << "Found available catalog at: " << hex_number(start_catalog_lba) << kendl); - (Void)(kout << "Found available catalog at: " << temporary_catalog.Name << kendl); + (Void)(kout << "Found available catalog at: " << hex_number(start_catalog_lba) << kendl); + (Void)(kout << "Found available catalog at: " << temporary_catalog.Name << kendl); - NEFS_CATALOG_STRUCT* catalog_ptr = new NEFS_CATALOG_STRUCT(); - rt_copy_memory(&temporary_catalog, catalog_ptr, sizeof(NEFS_CATALOG_STRUCT)); + NEFS_CATALOG_STRUCT* catalog_ptr = new NEFS_CATALOG_STRUCT(); + rt_copy_memory(&temporary_catalog, catalog_ptr, sizeof(NEFS_CATALOG_STRUCT)); - out_lba = start_catalog_lba; - return catalog_ptr; - } + out_lba = start_catalog_lba; + return catalog_ptr; + } - NeFSContinueSearch: - start_catalog_lba = temporary_catalog.NextSibling; + NeFSContinueSearch: + start_catalog_lba = temporary_catalog.NextSibling; - if (start_catalog_lba < part.StartCatalog) - break; - } + if (start_catalog_lba < part.StartCatalog) break; + } - if (local_search) - { - local_search = false; - start_catalog_lba = part.StartCatalog; + if (local_search) { + local_search = false; + start_catalog_lba = part.StartCatalog; - goto kNeFSSearchThroughCatalogList; - } + goto kNeFSSearchThroughCatalogList; + } - err_global_get() = kErrorFileNotFound; + err_global_get() = kErrorFileNotFound; - out_lba = 0UL; + out_lba = 0UL; - return nullptr; + return nullptr; } /// @brief Get catalog from filesystem. /// @param name the catalog's name/ /// @return -_Output NEFS_CATALOG_STRUCT* NeFileSystemParser::GetCatalog(_Input const Char* name) -{ - Lba unused = 0; - return this->FindCatalog(name, unused, YES); +_Output NEFS_CATALOG_STRUCT* NeFileSystemParser::GetCatalog(_Input const Char* name) { + Lba unused = 0; + return this->FindCatalog(name, unused, YES); } /// @brief Closes a catalog, (frees it). /// @param catalog the catalog to close. /// @return -_Output Boolean NeFileSystemParser::CloseCatalog(_Input _Output NEFS_CATALOG_STRUCT* catalog) -{ - if (!catalog) - return false; +_Output Boolean NeFileSystemParser::CloseCatalog(_Input _Output NEFS_CATALOG_STRUCT* catalog) { + if (!catalog) return false; - delete catalog; - catalog = nullptr; + delete catalog; + catalog = nullptr; - return true; + return true; } /// @brief Mark catalog as removed. /// @param catalog The catalog structure. /// @return if the catalog was removed or not. -_Output Boolean NeFileSystemParser::RemoveCatalog(_Input const Char* catalog_name) -{ - if (!catalog_name || - KStringBuilder::Equals(catalog_name, NeFileSystemHelper::Root())) - { - err_global_get() = kErrorInternal; - return false; - } +_Output Boolean NeFileSystemParser::RemoveCatalog(_Input const Char* catalog_name) { + if (!catalog_name || KStringBuilder::Equals(catalog_name, NeFileSystemHelper::Root())) { + err_global_get() = kErrorInternal; + return false; + } - Lba out_lba = 0; - auto catalog = this->FindCatalog(catalog_name, out_lba); + Lba out_lba = 0; + auto catalog = this->FindCatalog(catalog_name, out_lba); - if (out_lba >= kNeFSCatalogStartAddress || - catalog->Flags & kNeFSFlagCreated) - { - catalog->Flags &= (~kNeFSFlagCreated); - catalog->Flags |= kNeFSFlagDeleted; + if (out_lba >= kNeFSCatalogStartAddress || catalog->Flags & kNeFSFlagCreated) { + catalog->Flags &= (~kNeFSFlagCreated); + catalog->Flags |= kNeFSFlagDeleted; - auto& drive = kMountpoint.A(); + auto& drive = kMountpoint.A(); - rt_copy_memory((VoidPtr) "fs/nefs-packet", drive.fPacket.fPacketMime, - rt_string_len("fs/nefs-packet")); + rt_copy_memory((VoidPtr) "fs/nefs-packet", drive.fPacket.fPacketMime, + rt_string_len("fs/nefs-packet")); - drive.fPacket.fPacketLba = out_lba; // the catalog position. - drive.fPacket.fPacketSize = - sizeof(NEFS_CATALOG_STRUCT); // size of catalog. roughly the sector size. - drive.fPacket.fPacketContent = catalog; // the catalog itself. + drive.fPacket.fPacketLba = out_lba; // the catalog position. + drive.fPacket.fPacketSize = + sizeof(NEFS_CATALOG_STRUCT); // size of catalog. roughly the sector size. + drive.fPacket.fPacketContent = catalog; // the catalog itself. - drive.fOutput(drive.fPacket); // send packet. + drive.fOutput(drive.fPacket); // send packet. - Char partitionBlockBuf[sizeof(NEFS_ROOT_PARTITION_BLOCK)] = {0}; + Char partitionBlockBuf[sizeof(NEFS_ROOT_PARTITION_BLOCK)] = {0}; - drive.fPacket.fPacketLba = kNeFSRootCatalogStartAddress; - drive.fPacket.fPacketContent = partitionBlockBuf; - drive.fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); + drive.fPacket.fPacketLba = kNeFSRootCatalogStartAddress; + drive.fPacket.fPacketContent = partitionBlockBuf; + drive.fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); - drive.fInput(drive.fPacket); + drive.fInput(drive.fPacket); - NEFS_ROOT_PARTITION_BLOCK* part_block = - reinterpret_cast<NEFS_ROOT_PARTITION_BLOCK*>(partitionBlockBuf); + NEFS_ROOT_PARTITION_BLOCK* part_block = + reinterpret_cast<NEFS_ROOT_PARTITION_BLOCK*>(partitionBlockBuf); - --part_block->CatalogCount; - ++part_block->FreeSectors; + --part_block->CatalogCount; + ++part_block->FreeSectors; - drive.fOutput(drive.fPacket); + drive.fOutput(drive.fPacket); - return true; - } + return true; + } - delete catalog; - catalog = nullptr; + delete catalog; + catalog = nullptr; - return false; + return false; } /// ***************************************************************** /// @@ -966,55 +885,50 @@ _Output Boolean NeFileSystemParser::RemoveCatalog(_Input const Char* catalog_nam /***********************************************************************************/ VoidPtr NeFileSystemParser::ReadCatalog(_Input _Output NEFS_CATALOG_STRUCT* catalog, - _Input Bool is_rsrc_fork, - _Input SizeT dataSz, - _Input const Char* forkName) -{ - if (!catalog) - { - err_global_get() = kErrorInvalidData; - return nullptr; - } + _Input Bool is_rsrc_fork, _Input SizeT dataSz, + _Input const Char* forkName) { + if (!catalog) { + err_global_get() = kErrorInvalidData; + return nullptr; + } - NE_UNUSED(dataSz); + NE_UNUSED(dataSz); - Lba dataForkLba = (!is_rsrc_fork) ? catalog->DataFork : catalog->ResourceFork; + Lba dataForkLba = (!is_rsrc_fork) ? catalog->DataFork : catalog->ResourceFork; - NEFS_FORK_STRUCT* fs_buf = new NEFS_FORK_STRUCT(); - auto& drive = kMountpoint.A(); + NEFS_FORK_STRUCT* fs_buf = new NEFS_FORK_STRUCT(); + auto& drive = kMountpoint.A(); - rt_copy_memory((VoidPtr) "fs/nefs-packet", drive.fPacket.fPacketMime, - rt_string_len("fs/nefs-packet")); + rt_copy_memory((VoidPtr) "fs/nefs-packet", drive.fPacket.fPacketMime, + rt_string_len("fs/nefs-packet")); - NEFS_FORK_STRUCT* fs_fork_data = nullptr; + NEFS_FORK_STRUCT* fs_fork_data = nullptr; - while (dataForkLba > kNeFSCatalogStartAddress) - { - drive.fPacket.fPacketLba = dataForkLba; - drive.fPacket.fPacketSize = sizeof(NEFS_FORK_STRUCT); - drive.fPacket.fPacketContent = fs_buf; + while (dataForkLba > kNeFSCatalogStartAddress) { + drive.fPacket.fPacketLba = dataForkLba; + drive.fPacket.fPacketSize = sizeof(NEFS_FORK_STRUCT); + drive.fPacket.fPacketContent = fs_buf; - drive.fInput(drive.fPacket); + drive.fInput(drive.fPacket); - fs_fork_data = fs_buf; + fs_fork_data = fs_buf; - (Void)(kout << "ForkName: " << fs_fork_data->ForkName << kendl); - (Void)(kout << "CatalogName: " << fs_fork_data->CatalogName << kendl); + (Void)(kout << "ForkName: " << fs_fork_data->ForkName << kendl); + (Void)(kout << "CatalogName: " << fs_fork_data->CatalogName << kendl); - if (KStringBuilder::Equals(forkName, fs_fork_data->ForkName) && - KStringBuilder::Equals(catalog->Name, fs_fork_data->CatalogName)) - break; + if (KStringBuilder::Equals(forkName, fs_fork_data->ForkName) && + KStringBuilder::Equals(catalog->Name, fs_fork_data->CatalogName)) + break; - dataForkLba = fs_fork_data->NextSibling; - } + dataForkLba = fs_fork_data->NextSibling; + } - if (dataForkLba < kNeFSCatalogStartAddress) - { - delete fs_buf; - return nullptr; - } + if (dataForkLba < kNeFSCatalogStartAddress) { + delete fs_buf; + return nullptr; + } - return fs_fork_data; + return fs_fork_data; } /***********************************************************************************/ @@ -1024,13 +938,12 @@ VoidPtr NeFileSystemParser::ReadCatalog(_Input _Output NEFS_CATALOG_STRUCT* cata /// @return if the seeking was successful. /***********************************************************************************/ -bool NeFileSystemParser::Seek(_Input _Output NEFS_CATALOG_STRUCT* catalog, SizeT off) -{ - NE_UNUSED(catalog); - NE_UNUSED(off); +bool NeFileSystemParser::Seek(_Input _Output NEFS_CATALOG_STRUCT* catalog, SizeT off) { + NE_UNUSED(catalog); + NE_UNUSED(off); - err_global_get() = kErrorUnimplemented; - return false; + err_global_get() = kErrorUnimplemented; + return false; } /***********************************************************************************/ @@ -1039,30 +952,27 @@ bool NeFileSystemParser::Seek(_Input _Output NEFS_CATALOG_STRUCT* catalog, SizeT /// @return The position on the file. /***********************************************************************************/ -SizeT NeFileSystemParser::Tell(_Input _Output NEFS_CATALOG_STRUCT* catalog) -{ - NE_UNUSED(catalog); +SizeT NeFileSystemParser::Tell(_Input _Output NEFS_CATALOG_STRUCT* catalog) { + NE_UNUSED(catalog); - err_global_get() = kErrorUnimplemented; - return 0; + err_global_get() = kErrorUnimplemented; + return 0; } -namespace Kernel::NeFS -{ - /***********************************************************************************/ - /// @brief Construct NeFS drives. - /***********************************************************************************/ - Boolean fs_init_nefs(Void) noexcept - { - kout << "Creating main disk...\r"; +namespace Kernel::NeFS { +/***********************************************************************************/ +/// @brief Construct NeFS drives. +/***********************************************************************************/ +Boolean fs_init_nefs(Void) noexcept { + kout << "Creating main disk...\r"; - kMountpoint.A() = io_construct_main_drive(); + kMountpoint.A() = io_construct_main_drive(); - if (kMountpoint.A().fPacket.fPacketReadOnly == YES) - ke_panic(RUNTIME_CHECK_FILESYSTEM, "Main filesystem cannot be mounted."); + if (kMountpoint.A().fPacket.fPacketReadOnly == YES) + ke_panic(RUNTIME_CHECK_FILESYSTEM, "Main filesystem cannot be mounted."); - return YES; - } -} // namespace Kernel::NeFS + return YES; +} +} // namespace Kernel::NeFS -#endif // ifdef __FSKIT_INCLUDES_NEFS__ +#endif // ifdef __FSKIT_INCLUDES_NEFS__ |
