summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel
diff options
context:
space:
mode:
authorAmlal <amlal@nekernel.org>2025-04-29 08:54:34 +0200
committerAmlal <amlal@nekernel.org>2025-04-29 08:54:34 +0200
commitaa50b4980a84128fed32139758a00e215ee54a78 (patch)
treec199b57917210d66669e5771cd1ce67202ea225a /dev/kernel
parenta435ad97c1dac5282e148e6dac2d82aabcb553e5 (diff)
kernel: Figuring out the EPM header bug; where it gets duplicated when writing an IND. (HeFS)
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel')
-rw-r--r--dev/kernel/FSKit/HeFS.h10
-rw-r--r--dev/kernel/HALKit/AMD64/HalDebugOutput.cc31
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc1
-rw-r--r--dev/kernel/KernelKit/DebugOutput.h43
-rw-r--r--dev/kernel/KernelKit/DriveMgr.h8
-rw-r--r--dev/kernel/src/FS/HeFS.cc127
-rw-r--r--dev/kernel/src/FS/NeFS.cc22
7 files changed, 144 insertions, 98 deletions
diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h
index b236ff7b..80ef6646 100644
--- a/dev/kernel/FSKit/HeFS.h
+++ b/dev/kernel/FSKit/HeFS.h
@@ -28,7 +28,7 @@
#define kHeFSDefaultVoluneName u8"HeFS Volume"
-#define kHeFSINDStartLBA (sizeof(HEFS_BOOT_NODE))
+#define kHeFSINDStartOffset (sizeof(HEFS_INDEX_NODE_DIRECTORY))
#define kHeFSSearchAllStr u8"*"
@@ -131,7 +131,7 @@ inline constexpr Kernel::ATime kHeFSTimeMax = 0xFFFFFFFFFFFFFFFF - 1;
/// @details This structure is used to store the file information of a file.
/// @note The index node is a special type of INode that contains the file information.
/// @note The index node is used to store the file information of a file.
-struct PACKED ALIGN(8) HEFS_INDEX_NODE final {
+struct PACKED HEFS_INDEX_NODE final {
Kernel::Utf8Char fName[kHeFSFileNameLen]; /// @brief File name.
Kernel::UInt32 fFlags; /// @brief File flags.
Kernel::UInt16 fKind; /// @brief File kind. (Regular, Directory, Block, Character, FIFO, Socket,
@@ -148,7 +148,7 @@ struct PACKED ALIGN(8) HEFS_INDEX_NODE final {
Kernel::UInt64 fBlock[kHeFSBlockCount]; /// @brief block slice.
- Kernel::Char fPad[62];
+ Kernel::Char fPad[69];
};
enum {
@@ -161,7 +161,7 @@ enum {
/// @brief HeFS directory node.
/// @details This structure is used to store the directory information of a file.
/// @note The directory node is a special type of INode that contains the directory entries.
-struct PACKED ALIGN(8) HEFS_INDEX_NODE_DIRECTORY final {
+struct PACKED HEFS_INDEX_NODE_DIRECTORY final {
Kernel::Utf8Char fName[kHeFSFileNameLen]; /// @brief Directory name.
Kernel::UInt32 fFlags; /// @brief File flags.
@@ -185,7 +185,7 @@ struct PACKED ALIGN(8) HEFS_INDEX_NODE_DIRECTORY final {
Kernel::UInt8 fColor; /// @brief Color of the node. (Red or Black).
Kernel::Lba fNext, fPrev, fChild, fParent; /// @brief Red-black tree pointers.
- Kernel::Char fPad[32];
+ Kernel::Char fPad[33];
};
namespace Kernel::Detail {
diff --git a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc
index 9d290708..5d09f8b4 100644
--- a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc
+++ b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc
@@ -13,19 +13,19 @@
namespace Kernel {
enum CommStatus : UInt16 {
- kStateInvalid,
+ kStateInvalid = 0x64,
kStateReady = 0xCF,
kStateTransmit = 0xFC,
kStateCnt = 3
};
namespace Detail {
- constexpr const UInt16 kPort = 0x3F8;
- static UInt16 kState = kStateInvalid;
+ constexpr ATTRIBUTE(unused) const UInt16 kPort = 0x3F8;
+ STATIC ATTRIBUTE(unused) UInt16 kState = kStateInvalid;
/// @brief Init COM1.
/// @return
- template <Int16 PORT>
+ template <UInt16 PORT>
bool hal_serial_init() noexcept {
if (kState == kStateReady || kState == kStateTransmit) return true;
@@ -58,6 +58,7 @@ namespace Detail {
TerminalDevice::~TerminalDevice() = default;
EXTERN_C void ke_io_write(IDeviceObject<const Char*>* obj, const Char* bytes) {
+ NE_UNUSED(bytes);
NE_UNUSED(obj);
#ifdef __DEBUG__
@@ -127,6 +128,8 @@ EXTERN_C void ke_io_write(IDeviceObject<const Char*>* obj, const Char* bytes) {
}
EXTERN_C void ke_io_read(IDeviceObject<const Char*>*, const Char* bytes) {
+ NE_UNUSED(bytes);
+
#ifdef __DEBUG__
Detail::hal_serial_init<Detail::kPort>();
@@ -167,4 +170,24 @@ TerminalDevice TerminalDevice::The() noexcept {
return out;
}
+Utf8TerminalDevice::~Utf8TerminalDevice() = default;
+
+STATIC Void ke_io_write_utf(IDeviceObject<const Utf8Char*>*, const Utf8Char* str) {
+ auto len = urt_string_len(str);
+
+ for (auto size = 0ul; size < len; ++size) {
+ Char buf[2];
+ buf[0] = str[size];
+ buf[1] = 0;
+
+ Kernel::ke_io_write(nullptr, buf);
+ }
+}
+
+Utf8TerminalDevice Utf8TerminalDevice::The() noexcept {
+ Utf8TerminalDevice out(Kernel::ke_io_write_utf,
+ [](IDeviceObject<const Utf8Char*>*, const Utf8Char*) -> Void {});
+ return out;
+}
+
} // namespace Kernel
diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
index 4391bd40..b767e79c 100644
--- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
+++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
@@ -146,6 +146,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
volatile HbaCmdHeader* command_header =
(volatile HbaCmdHeader*) ((UInt64) kSATAHba->Ports[kSATAIndex].Clb);
+
command_header += slot;
MUST_PASS(command_header);
diff --git a/dev/kernel/KernelKit/DebugOutput.h b/dev/kernel/KernelKit/DebugOutput.h
index 7110a941..f6cfa027 100644
--- a/dev/kernel/KernelKit/DebugOutput.h
+++ b/dev/kernel/KernelKit/DebugOutput.h
@@ -10,6 +10,7 @@
#include <KernelKit/DeviceMgr.h>
#include <NewKit/OwnPtr.h>
#include <NewKit/Stream.h>
+#include <NewKit/Utils.h>
#define kDebugUnboundPort 0x0FEED
@@ -26,6 +27,8 @@
namespace Kernel {
class TerminalDevice;
class DTraceDevice;
+class DebugDevice;
+class Utf8TerminalDevice;
inline TerminalDevice end_line();
inline TerminalDevice number(const Long& x);
@@ -49,6 +52,23 @@ class TerminalDevice final NE_DEVICE<const Char*> {
STATIC TerminalDevice The() noexcept;
};
+class Utf8TerminalDevice final NE_DEVICE<const Utf8Char*> {
+ public:
+ Utf8TerminalDevice(void (*print)(IDeviceObject*, const Utf8Char*),
+ void (*gets)(IDeviceObject*, const Utf8Char*))
+ : IDeviceObject<const Utf8Char*>(print, gets) {}
+
+ ~Utf8TerminalDevice() override;
+
+ /// @brief returns device name (terminal name)
+ /// @return string type (const Char*)
+ const Char* Name() const override { return ("Utf8TerminalDevice"); }
+
+ NE_COPY_DEFAULT(Utf8TerminalDevice)
+
+ STATIC Utf8TerminalDevice The() noexcept;
+};
+
inline TerminalDevice end_line() {
TerminalDevice self = TerminalDevice::The();
@@ -56,6 +76,13 @@ inline TerminalDevice end_line() {
return self;
}
+inline Utf8TerminalDevice utf_end_line() {
+ Utf8TerminalDevice self = Utf8TerminalDevice::The();
+
+ self.operator<<(u8"\r");
+ return self;
+}
+
inline TerminalDevice carriage_return() {
TerminalDevice self = TerminalDevice::The();
@@ -175,4 +202,20 @@ inline TerminalDevice& operator<<(TerminalDevice& src, const Long& num) {
#define kout TerminalDevice::The()
+#ifdef kendl
+#undef kendl
+#endif // ifdef kendl
+
#define kendl end_line()
+
+#ifdef kout8
+#undef kout8
+#endif // ifdef kout8
+
+#define kout8 Utf8TerminalDevice::The()
+
+#ifdef kendl8
+#undef kendl8
+#endif // ifdef kendl8
+
+#define kendl8 utf_end_line()
diff --git a/dev/kernel/KernelKit/DriveMgr.h b/dev/kernel/KernelKit/DriveMgr.h
index b40cf0ad..d287a345 100644
--- a/dev/kernel/KernelKit/DriveMgr.h
+++ b/dev/kernel/KernelKit/DriveMgr.h
@@ -156,14 +156,18 @@ namespace Detect {
Void io_detect_drive(DriveTrait& trait);
}
-/// @brief Read from newfs disk.
+Void io_drv_input(DriveTrait::DrivePacket pckt);
+
+Void io_drv_output(DriveTrait::DrivePacket pckt);
+
+/// @brief Read from IFS disk.
/// @param Mnt mounted interface.
/// @param DrvTrait drive info
/// @param DrvIndex drive index.
/// @return
Int32 fs_ifs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex);
-/// @brief Write to ifs disk.
+/// @brief Write to IFS disk.
/// @param Mnt mounted interface.
/// @param DrvTrait drive info
/// @param DrvIndex drive index.
diff --git a/dev/kernel/src/FS/HeFS.cc b/dev/kernel/src/FS/HeFS.cc
index f0bb5d78..0efd499b 100644
--- a/dev/kernel/src/FS/HeFS.cc
+++ b/dev/kernel/src/FS/HeFS.cc
@@ -38,7 +38,7 @@ namespace Detail {
/// @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(
+ STATIC ATTRIBUTE(unused) _Output HEFS_INDEX_NODE* hefsi_fetch_index_node(
HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf8Char* dir_name, const Utf8Char* file_name,
UInt8 kind, SizeT* cnt) noexcept;
@@ -50,8 +50,8 @@ namespace Detail {
/// @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 Utf8Char* dir_name,
- const Utf8Char* file_name, UInt8 kind) noexcept;
+ hefsi_fetch_index_node_size(HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf8Char* dir_name,
+ const Utf8Char* file_name, UInt8 kind) noexcept;
/// @brief Allocate a new index node.
/// @param root The root node of the filesystem.
@@ -59,8 +59,8 @@ namespace Detail {
/// @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 Utf8Char* parent_dir_name, HEFS_INDEX_NODE* node) noexcept;
+ hefsi_allocate_index_node(HEFS_BOOT_NODE* root, DriveTrait* mnt,
+ const Utf8Char* parent_dir_name, HEFS_INDEX_NODE* node) noexcept;
/// @brief Balance RB-Tree of the filesystem.
/// @param root The root node of the filesystem.
@@ -91,7 +91,7 @@ namespace Detail {
} else if (dir->fPrev != 0) {
start = dir->fPrev;
} else {
- start += sizeof(HEFS_INDEX_NODE_DIRECTORY);
+ start += kHeFSINDStartOffset;
}
kout << "Traversing RB-Tree...\r";
@@ -210,8 +210,8 @@ namespace Detail {
/// @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 Utf8Char* dir_name,
- const Utf8Char* file_name, UInt8 kind) noexcept {
+ hefsi_fetch_index_node_size(HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf8Char* dir_name,
+ const Utf8Char* 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();
@@ -250,7 +250,7 @@ namespace Detail {
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);
+ sz += hefsi_fetch_index_node_size(root, mnt, dir_name, file_name, kind);
} else {
sz = node->fSize;
}
@@ -270,8 +270,9 @@ namespace Detail {
return 0;
}
- STATIC _Output BOOL hefs_allocate_index_directory_node(HEFS_BOOT_NODE* root, DriveTrait* mnt,
- const Utf8Char* dir_name) noexcept {
+ STATIC _Output BOOL hefsi_allocate_index_directory_node(HEFS_BOOT_NODE* root, DriveTrait* mnt,
+ const Utf8Char* dir_name,
+ UInt16 flags) noexcept {
if (root && mnt) {
HEFS_INDEX_NODE_DIRECTORY* tmpdir = new HEFS_INDEX_NODE_DIRECTORY();
@@ -293,7 +294,7 @@ namespace Detail {
break;
}
- if ((!tmpdir->fCreated && tmpdir->fDeleted) || *tmpdir->fName == u8'\0') {
+ if ((!tmpdir->fCreated && tmpdir->fDeleted) || *tmpdir->fName == 0) {
HEFS_INDEX_NODE_DIRECTORY* dirent = new HEFS_INDEX_NODE_DIRECTORY();
rt_set_memory(dirent, 0, sizeof(HEFS_INDEX_NODE_DIRECTORY));
@@ -301,13 +302,13 @@ namespace Detail {
urt_copy_memory((VoidPtr) dir_name, dirent->fName, urt_string_len(dir_name));
dirent->fAccessed = 0;
- dirent->fCreated = 1UL; /// TODO: Add the current time.
+ dirent->fCreated = 1UL;
dirent->fDeleted = 0;
dirent->fModified = 0;
dirent->fEntryCount = 0;
dirent->fKind = kHeFSFileKindDirectory;
- dirent->fFlags = kHeFSEncodingUTF8;
+ dirent->fFlags = flags;
dirent->fChecksum = 0;
dirent->fChecksum = ke_calculate_crc32((Char*) dirent, sizeof(HEFS_INDEX_NODE_DIRECTORY));
@@ -322,8 +323,10 @@ namespace Detail {
}
if (dirent->fNext == 0) {
- if (start == root->fEndIND) {
+ if (start < root->fEndIND) {
dirent->fNext = start + sizeof(HEFS_INDEX_NODE_DIRECTORY);
+ } else {
+ dirent->fNext = 0;
}
}
@@ -334,24 +337,28 @@ namespace Detail {
if (tmpdir->fChild == 0) {
auto child = root->fEndIND;
+ auto tmpend = new HEFS_INDEX_NODE_DIRECTORY();
+
while (YES) {
mnt->fPacket.fPacketLba = child;
mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY);
- mnt->fPacket.fPacketContent = tmpdir;
+ mnt->fPacket.fPacketContent = tmpend;
mnt->fInput(mnt->fPacket);
- if ((!tmpdir->fCreated && tmpdir->fDeleted) || *tmpdir->fName == u8'\0') {
+ if ((!tmpend->fCreated && tmpend->fDeleted) || *tmpend->fName == 0) {
break;
}
child -= sizeof(HEFS_INDEX_NODE_DIRECTORY);
- if (child > root->fEndIND) break;
+ if (child < root->fStartIND || child > root->fEndIND) break;
}
dirent->fColor = kHeFSRed;
dirent->fChild = child;
+ delete tmpend;
+
if (child > root->fEndIND) dirent->fChild = root->fEndIND;
} else {
dirent->fColor = tmpdir->fColor;
@@ -394,7 +401,7 @@ namespace Detail {
return NO;
}
- STATIC _Output HEFS_INDEX_NODE_DIRECTORY* hefs_fetch_index_node_directory(
+ STATIC _Output HEFS_INDEX_NODE_DIRECTORY* hefsi_fetch_index_node_directory(
HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf8Char* dir_name) {
if (root && mnt) {
HEFS_INDEX_NODE_DIRECTORY* dir = new HEFS_INDEX_NODE_DIRECTORY();
@@ -443,7 +450,7 @@ namespace Detail {
/// @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(
+ STATIC ATTRIBUTE(unused) _Output HEFS_INDEX_NODE* hefsi_fetch_index_node(
HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf8Char* dir_name, const Utf8Char* file_name,
UInt8 kind, SizeT* cnt) noexcept {
if (root && mnt) {
@@ -548,8 +555,8 @@ namespace Detail {
/// @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 Utf8Char* parent_dir_name, HEFS_INDEX_NODE* node) noexcept {
+ hefsi_allocate_index_node(HEFS_BOOT_NODE* root, DriveTrait* mnt,
+ const Utf8Char* parent_dir_name, HEFS_INDEX_NODE* node) noexcept {
if (root && mnt) {
HEFS_INDEX_NODE_DIRECTORY* dir = new HEFS_INDEX_NODE_DIRECTORY();
@@ -813,6 +820,7 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input
}
rt_set_memory(root, 0, sizeof(HEFS_BOOT_NODE));
+ rt_set_memory(root->fPad, 0, sizeof(root->fPad));
rt_copy_memory((VoidPtr) "fs/hefs-packet", drive->fPacket.fPacketMime,
rt_string_len("fs/hefs-packet"));
@@ -820,9 +828,7 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input
urt_copy_memory((VoidPtr) part_name, root->fVolName, urt_string_len(part_name));
rt_copy_memory((VoidPtr) kHeFSMagic, root->fMagic, kHeFSMagicLen - 1);
- SizeT start = drive->fLbaStart + kHeFSINDStartLBA;
-
- if (start > drive->fLbaEnd) {
+ if (drive->fLbaStart > drive->fLbaEnd) {
delete root;
root = nullptr;
@@ -836,18 +842,22 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input
root->fSectorCount = drv_std_get_sector_count();
root->fSectorSize = drive->fSectorSz;
- SizeT disk_sectors = drv_std_get_size() / drive->fSectorSz; // Get total sectors
+ MUST_PASS(root->fSectorSize);
+
+ SizeT disk_sectors = drv_std_get_size() / root->fSectorSize; // Get total sectors
SizeT dir_sectors = disk_sectors / 20; // 5% for directory metadata
SizeT inode_sectors = disk_sectors / 10; // 10% for inodes
- root->fStartIND = start;
- root->fEndIND = root->fStartIND + dir_sectors - sizeof(HEFS_INDEX_NODE_DIRECTORY);
+ root->fStartIND = drive->fLbaStart + kHeFSINDStartOffset;
+ root->fEndIND = root->fStartIND + dir_sectors;
- root->fStartIN = root->fEndIND + 1;
- root->fEndIN = root->fStartIN + inode_sectors - sizeof(HEFS_INDEX_NODE);
+ root->fStartIN = root->fEndIND - kHeFSINDStartOffset;
+ root->fEndIN = root->fStartIN + inode_sectors;
- root->fINDCount = 0;
+ constexpr SizeT kHeFSPreallocateCount = 0x7UL;
+
+ root->fINDCount = kHeFSPreallocateCount;
root->fDiskSize = drv_std_get_size();
root->fDiskStatus = kHeFSStatusUnlocked;
@@ -876,6 +886,12 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input
drive->fOutput(drive->fPacket);
+ (Void)(kout << "Drive kind: " << drive->fProtocol() << kendl);
+ (Void)(kout8 << u8"Partition name: " << root->fVolName << kendl8);
+ (Void)(kout << "Start IND: " << hex_number(root->fStartIND) << kendl);
+ (Void)(kout << "Number of catalogs: " << hex_number(root->fINDCount) << kendl);
+ (Void)(kout << "Sector size: " << hex_number(root->fSectorCount) << kendl);
+
if (!drive->fPacket.fPacketGood) {
delete root;
root = nullptr;
@@ -885,47 +901,6 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input
return NO;
}
- start = root->fStartIND;
-
- HEFS_INDEX_NODE_DIRECTORY* dir = new HEFS_INDEX_NODE_DIRECTORY();
-
- rt_set_memory(dir, 0, sizeof(HEFS_INDEX_NODE_DIRECTORY));
- urt_copy_memory((VoidPtr) u8".CoreFS", dir->fName, urt_string_len(u8".CoreFS"));
-
- dir->fFlags = flags;
- dir->fKind = kHeFSFileKindDirectory;
-
- dir->fCreated = 0;
- dir->fDeleted = kHeFSTimeMax; /// TODO: Add current time.
-
- dir->fEntryCount = 0;
-
- dir->fIndexNodeChecksum = 0;
-
- dir->fUID = 0;
- dir->fGID = 0;
- dir->fMode = 0;
-
- dir->fColor = kHeFSBlack;
- dir->fChild = root->fStartIND;
- dir->fParent = root->fStartIND;
- dir->fNext = root->fStartIND;
- dir->fPrev = root->fStartIND;
-
- dir->fChecksum = ke_calculate_crc32((Char*) dir, sizeof(HEFS_INDEX_NODE_DIRECTORY));
-
- drive->fPacket.fPacketLba = start;
- drive->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY);
- drive->fPacket.fPacketContent = dir;
-
- start += sizeof(HEFS_INDEX_NODE_DIRECTORY);
-
- drive->fOutput(drive->fPacket);
-
- delete dir;
-
- constexpr SizeT kHeFSPreallocateCount = 0x7UL;
-
const Utf8Char* kFileMap[kHeFSPreallocateCount] = {
u8"/", u8"/boot", u8"/system", u8"/devices", u8"/network", u8"/users", u8"/home",
};
@@ -934,6 +909,8 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input
this->CreateDirectory(drive, kHeFSEncodingUTF8, kFileMap[i]);
}
+ Detail::hefsi_balance_filesystem(root, drive);
+
delete root;
root = nullptr;
@@ -987,7 +964,7 @@ _Output Bool HeFileSystemParser::CreateDirectory(_Input DriveTrait* drive, _Inpu
return NO;
}
- if (Detail::hefs_allocate_index_directory_node(root, drive, dir)) {
+ if (Detail::hefsi_allocate_index_directory_node(root, drive, dir, flags)) {
Detail::hefsi_balance_filesystem(root, drive);
delete root;
@@ -1041,7 +1018,7 @@ _Output Bool HeFileSystemParser::CreateFile(_Input DriveTrait* drive, _Input con
drive->fInput(drive->fPacket);
- auto dirent = Detail::hefs_fetch_index_node_directory(root, drive, dir);
+ auto dirent = Detail::hefsi_fetch_index_node_directory(root, drive, dir);
if (!dirent) {
kout << "Error: Directory not found.\r";
@@ -1078,7 +1055,7 @@ _Output Bool HeFileSystemParser::CreateFile(_Input DriveTrait* drive, _Input con
urt_copy_memory((VoidPtr) name, node->fName, urt_string_len(name));
- if (Detail::hefs_allocate_index_node(root, drive, dir, node)) {
+ if (Detail::hefsi_allocate_index_node(root, drive, dir, node)) {
delete node;
delete root;
diff --git a/dev/kernel/src/FS/NeFS.cc b/dev/kernel/src/FS/NeFS.cc
index d572bffc..e61a7c8a 100644
--- a/dev/kernel/src/FS/NeFS.cc
+++ b/dev/kernel/src/FS/NeFS.cc
@@ -275,8 +275,6 @@ _Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char
auto& drive = kMountpoint.A();
- constexpr auto kNeFSCatalogPadding = 4;
-
if (catalog && catalog->Kind == kNeFSCatalogKindFile) {
kout << "Parent is a file.\r";
delete catalog;
@@ -357,7 +355,7 @@ _Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char
// Allocate catalog now...
// ========================== //
if ((temporary_catalog.Flags & kNeFSFlagCreated) == 0) {
- child_catalog->NextSibling = start_free + (sizeof(NEFS_CATALOG_STRUCT) * kNeFSCatalogPadding);
+ child_catalog->NextSibling = start_free + sizeof(NEFS_CATALOG_STRUCT);
drive.fPacket.fPacketContent = &temporary_catalog;
drive.fPacket.fPacketSize = sizeof(NEFS_CATALOG_STRUCT);
@@ -402,7 +400,7 @@ _Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char
return child_catalog;
}
- start_free = start_free + (sizeof(NEFS_CATALOG_STRUCT) * kNeFSCatalogPadding);
+ start_free = start_free + sizeof(NEFS_CATALOG_STRUCT);
drive.fPacket.fPacketContent = &temporary_catalog;
drive.fPacket.fPacketSize = sizeof(NEFS_CATALOG_STRUCT);
@@ -461,7 +459,7 @@ bool NeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input const I
part_block->Version = kNeFSVersionInteger;
part_block->Kind = kNeFSPartitionTypeStandard;
- part_block->StartCatalog = start + sizeof(NEFS_ROOT_PARTITION_BLOCK);
+ part_block->StartCatalog = start + sizeof(NEFS_CATALOG_STRUCT);
part_block->Flags = 0UL;
part_block->CatalogCount = sectorCount / sizeof(NEFS_CATALOG_STRUCT);
part_block->FreeSectors = sectorCount / sizeof(NEFS_CATALOG_STRUCT);
@@ -475,14 +473,14 @@ bool NeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input const I
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);