summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal <amlal@nekernel.org>2025-05-09 20:22:01 +0200
committerAmlal <amlal@nekernel.org>2025-05-09 20:23:52 +0200
commit1391fa1bdc1cfe864596d3120bda12590131bc62 (patch)
tree103f36459712cd3af1af8d603404684ce41718b4
parent902bafa5dc8c3ac5fcbf13a5af73e016e9c64685 (diff)
dev(kernel, tooling): better code quality inside the codebase and more checks inside the kernel, and cli.
also: - make use _NeMain for the mk_fwrk tool. Signed-off-by: Amlal <amlal@nekernel.org>
-rw-r--r--.gitignore3
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc10
-rw-r--r--dev/kernel/kernel_rsrc.rsrc2
-rw-r--r--dev/kernel/src/FS/HeFS+FileSystemParser.cc8
-rw-r--r--dev/kernel/src/UserProcessScheduler.cc5
-rw-r--r--docs/tex/hefs.tex27
-rw-r--r--public/tools/mgmt/src/CommandLine.cc6
-rw-r--r--tooling/fsck.hefs.cc11
-rwxr-xr-xtooling/mk_fwrk.py2
-rw-r--r--tooling/mkfs.hefs.cc11
10 files changed, 55 insertions, 30 deletions
diff --git a/.gitignore b/.gitignore
index 4d8b3ddf..01c18138 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,7 +22,8 @@ public/frameworks/*/dist/*
neoskrnl/neoskrnl.xcodeproj/project.xcworkspace/xcshareddata/
-tooling/dist/mkfs.hefs
+tooling/dist/mkfs.*
+tooling/dist/fsck.*
html/
latex/
diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
index 2b7aec14..ad4f9eeb 100644
--- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
+++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
@@ -160,10 +160,12 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
UInt16 timeout = 0;
+ constexpr static UInt16 kTimeout = 0x7000;
+
while (slot == ~0UL) {
kout << "No free command slot found, AHCI disk is busy!\r";
- if (timeout > 0x1000) {
+ if (timeout > kTimeout) {
err_global_get() = kErrorDisk;
return;
}
@@ -183,6 +185,8 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
volatile HbaCmdTbl* command_table =
(volatile HbaCmdTbl*) (((UInt64) command_header->Ctbau << 32) | command_header->Ctba);
+ MUST_PASS(command_table);
+
rt_set_memory((VoidPtr) command_table, 0, sizeof(HbaCmdTbl));
VoidPtr ptr = rtl_dma_alloc(size_buffer, kib_cast(4));
@@ -195,7 +199,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
rtl_dma_flush(ptr, size_buffer);
- // Build the PRDT
+ // Build the PRD table.
SizeT bytes_remaining = size_buffer;
SizeT prdt_index = 0;
UIntPtr buffer_phys = (UIntPtr) ptr;
@@ -216,11 +220,13 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
++prdt_index;
}
+ // Mark the last PRD entry, for the FIS to process the table.
command_table->Prdt[prdt_index - 1].Ie = YES;
if (bytes_remaining > 0) {
kout << "Warning: AHCI PRDT overflow, cannot map full buffer.\r";
err_global_get() = kErrorDisk;
+ rtl_dma_free(size_buffer);
return;
}
diff --git a/dev/kernel/kernel_rsrc.rsrc b/dev/kernel/kernel_rsrc.rsrc
index 69922999..b7a11036 100644
--- a/dev/kernel/kernel_rsrc.rsrc
+++ b/dev/kernel/kernel_rsrc.rsrc
@@ -8,7 +8,7 @@ BEGIN
BEGIN
BLOCK "080904E4"
BEGIN
- VALUE "CompanyName", "Amlal El Mahrouss."
+ VALUE "CompanyName", "Amlal El Mahrouss"
VALUE "FileDescription", "NeKernel"
VALUE "FileVersion", KERNEL_VERSION
VALUE "InternalName", "neoskrnl"
diff --git a/dev/kernel/src/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/HeFS+FileSystemParser.cc
index d66c4a53..da55432a 100644
--- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc
+++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc
@@ -1037,14 +1037,14 @@ _Output Bool HeFileSystemParser::INodeManip(_Input DriveTrait* mnt, VoidPtr bloc
goto inode_manip_fail;
}
- in ? mnt->fInput(mnt->fPacket) : mnt->fOutput(mnt->fPacket);
-
- sz_out += kHeFSBlockLen;
-
if (!in) {
+ mnt->fOutput(mnt->fPacket);
delete[] nodes;
return YES;
} else {
+ mnt->fInput(mnt->fPacket);
+ sz_out += kHeFSBlockLen;
+
if (sz_out >= block_sz) {
delete[] nodes;
return YES;
diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc
index dbe3882f..2082642c 100644
--- a/dev/kernel/src/UserProcessScheduler.cc
+++ b/dev/kernel/src/UserProcessScheduler.cc
@@ -3,7 +3,7 @@
Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
FILE: UserProcessScheduler.cc
- PURPOSE: Low level/Ring-3 process scheduler.
+ PURPOSE: Low-Privilege/Ring-3 process scheduler.
------------------------------------------- */
@@ -14,12 +14,13 @@
/***********************************************************************************/
#include <ArchKit/ArchKit.h>
+#include <NewKit/KString.h>
+
#include <KernelKit/HardwareThreadScheduler.h>
#include <KernelKit/IPEFDylibObject.h>
#include <KernelKit/KPC.h>
#include <KernelKit/MemoryMgr.h>
#include <KernelKit/ProcessScheduler.h>
-#include <NewKit/KString.h>
///! BUGS: 0
diff --git a/docs/tex/hefs.tex b/docs/tex/hefs.tex
index 6daf5d87..29370fbc 100644
--- a/docs/tex/hefs.tex
+++ b/docs/tex/hefs.tex
@@ -33,9 +33,9 @@ The High-throughput Extended File System (HeFS) is a custom filesystem tailored
\hline
\end{longtable}
-\section{Disk and File Metadata Enums}
+\section{Disk and File Metadata Enums}\label{sec:disk-and-file-metadata-enums}
-\subsection{Drive Kind (\texttt{UInt8})}
+\subsection{Drive Kind (\texttt{UInt8})}\label{subsec:drive-kind-(texttt{uint8})}
\begin{itemize}
\item 0xC0: Hard Drive
\item 0xC1: Solid State Drive
@@ -46,7 +46,7 @@ The High-throughput Extended File System (HeFS) is a custom filesystem tailored
\item 0xFF: Unknown
\end{itemize}
-\subsection{Disk Status (\texttt{UInt8})}
+\subsection{Disk Status (\texttt{UInt8})}\label{subsec:disk-status-(texttt{uint8})}
\begin{itemize}
\item 0x18: Unlocked
\item 0x19: Locked
@@ -54,7 +54,7 @@ The High-throughput Extended File System (HeFS) is a custom filesystem tailored
\item 0x1B: Invalid
\end{itemize}
-\subsection{Encoding Flags (\texttt{UInt16})}
+\subsection{Encoding Flags (\texttt{UInt16})}\label{subsec:encoding-flags-(texttt{uint16})}
\begin{itemize}
\item UTF-8
\item UTF-16
@@ -68,7 +68,7 @@ The High-throughput Extended File System (HeFS) is a custom filesystem tailored
\item Binary
\end{itemize}
-\subsection{File Kinds (\texttt{UInt16})}
+\subsection{File Kinds (\texttt{UInt16})}\label{subsec:file-kinds-(texttt{uint16})}
\begin{itemize}
\item 0x00: Regular File
\item 0x01: Directory
@@ -80,7 +80,7 @@ The High-throughput Extended File System (HeFS) is a custom filesystem tailored
\item 0x07: Unknown
\end{itemize}
-\subsection{File Flags (\texttt{UInt32})}
+\subsection{File Flags (\texttt{UInt32})}\label{subsec:file-flags-(texttt{uint32})}
\begin{itemize}
\item 0x000: None
\item 0x100: ReadOnly
@@ -90,9 +90,9 @@ The High-throughput Extended File System (HeFS) is a custom filesystem tailored
\item 0x104: Device
\end{itemize}
-\section{Structures}
+\section{Structures}\label{sec:structures}
-\subsection{HEFS\_BOOT\_NODE}
+\subsection{HEFS\_BOOT\_NODE}\label{subsec:hefs_boot_node}
Acts as the superblock.
\begin{itemize}
@@ -103,7 +103,7 @@ Acts as the superblock.
\item Reserved: \texttt{fStartIN}, \texttt{fEndIN}, \texttt{fStartBlock}, \texttt{fEndBlock}
\end{itemize}
-\subsection{HEFS\_INDEX\_NODE}
+\subsection{HEFS\_INDEX\_NODE}\label{subsec:hefs_index_node}
Contains file metadata and block layout.
\begin{itemize}
@@ -114,7 +114,7 @@ Contains file metadata and block layout.
\item Block data: \texttt{fOffsetSlices}, \texttt{fSlices[kHeFSSliceCount]} as (base, length) pairs
\end{itemize}
-\subsection{HEFS\_INDEX\_NODE\_DIRECTORY}
+\subsection{HEFS\_INDEX\_NODE\_DIRECTORY}\label{subsec:hefs_index_node_directory}
Red-black tree based directory node.
\begin{itemize}
@@ -124,7 +124,7 @@ Red-black tree based directory node.
\item Tree links: \texttt{fColor}, \texttt{fNext}, \texttt{fPrev}, \texttt{fChild}, \texttt{fParent}
\end{itemize}
-\section{Timestamp Layout (ATime)}
+\section{Timestamp Layout (ATime)}\label{sec:timestamp-layout-(atime)}
\texttt{ATime} is a 64-bit timestamp and allocation status tracker with the following structure:
@@ -142,7 +142,7 @@ Constants:
\item \texttt{kHeFSTimeMax = 0xFFFFFFFFFFFFFFFF - 1}
\end{itemize}
-\section{Filesystem API}
+\section{Filesystem API}\label{sec:filesystem-api}
Provided by \texttt{Kernel::HeFS::HeFileSystemParser}.
@@ -161,6 +161,7 @@ Internal helpers:
\end{itemize}
\section{Conclusion}
-HeFS provides a modern and compact approach to high-performance file storage. Its use of red-black trees, fixed-size metadata, slice-based sparse files, and minimal overhead makes it a strong candidate for embedded and performance-sensitive use cases.
+HeFS provides a modern and compact approach to high-performance file storage.
+Its use of red-black trees, fixed-size metadata, slice-based sparse files, and minimal overhead makes it a strong candidate for embedded and performance-sensitive use cases.
\end{document}
diff --git a/public/tools/mgmt/src/CommandLine.cc b/public/tools/mgmt/src/CommandLine.cc
index d269c894..45990d08 100644
--- a/public/tools/mgmt/src/CommandLine.cc
+++ b/public/tools/mgmt/src/CommandLine.cc
@@ -1,3 +1,5 @@
-int main() {
- return 0;
+#include <user/SystemCalls.h>
+
+SInt32 _NeMain(SInt32 argc, Char* argv[]) {
+ return EXIT_FAILURE;
} \ No newline at end of file
diff --git a/tooling/fsck.hefs.cc b/tooling/fsck.hefs.cc
index 05cf0660..9d67aa38 100644
--- a/tooling/fsck.hefs.cc
+++ b/tooling/fsck.hefs.cc
@@ -5,11 +5,16 @@
------------------------------------------- */
#include <tooling/hefs.h>
+#include <tooling/mkfs.h>
#include <cstdlib>
int main(int argc, char** argv) {
- (void) (argc);
- (void) (argv);
+ if (argc < 2) {
+ mkfs::console_out() << "fsck: hefs: usage: fsck.hefs i <input_device>" << "\n";
+ return EXIT_FAILURE;
+ }
- return EXIT_FAILURE;
+ (void) argv;
+
+ return EXIT_SUCCESS;
} \ No newline at end of file
diff --git a/tooling/mk_fwrk.py b/tooling/mk_fwrk.py
index 36cc4e8e..9bc132e6 100755
--- a/tooling/mk_fwrk.py
+++ b/tooling/mk_fwrk.py
@@ -64,7 +64,7 @@ def create_directory_structure(base_path, project_name):
proj_cpp_path = os.path.join(base_path, project_name, f"src/CommandLine.cc")
- cpp_file = "int main() {\n\treturn 0;\n}"
+ cpp_file = "#include <user/SystemCalls.h>\n\nSInt32 _NeMain(SInt32 argc, Char* argv[]) {\n\treturn EXIT_FAILURE;\n}"
with open(proj_cpp_path, 'w') as cpp_file_io:
cpp_file_io.write(cpp_file)
diff --git a/tooling/mkfs.hefs.cc b/tooling/mkfs.hefs.cc
index c8243b5c..3dcfd11b 100644
--- a/tooling/mkfs.hefs.cc
+++ b/tooling/mkfs.hefs.cc
@@ -9,11 +9,20 @@
#include <cstdlib>
#include <fstream>
-static size_t kDiskSize = 1024 * 1024 * 1024 * 4UL;
+namespace detail {
+/// @interal
+/// @brief GB equation formula.
+static constexpr size_t gib_cast(uint32_t gb) {
+ return ((1024 ^ 3) * gb);
+}
+} // namespace detail
+
+static size_t kDiskSize = detail::gib_cast(4UL);
static uint16_t kVersion = kHeFSVersion;
static std::u8string kLabel = kHeFSDefaultVolumeName;
static size_t kSectorSize = 512;
+/// @brief Entrypoint of tool.
int main(int argc, char** argv) {
if (argc < 2) {
mkfs::console_out()