NKFS is NKLegacy’s built-in RAM-based filesystem. It uses a static pool of 256 nodes and a 512 KB data buffer — no dynamic allocation — and exposes a tree-structured filesystem rooted atDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/pastaboy12345/NKLegacy/llms.txt
Use this file to discover all available pages before exploring further.
C:. All files and directories live entirely in memory and are accessible through a small C API defined in ntoskrnl/fs/nkfs/nkfs.h.
Data Model
Node Structure
Every file and directory in NKFS is represented by a singlenkfs_node_t struct:
Static Limits
Both pools are statically allocated in.bss — no malloc is ever called:
| Constant | Value | Meaning |
|---|---|---|
MAX_NODES | 256 | Maximum total nodes (files + dirs) |
DATA_POOL_SIZE | 512 * 1024 (512 KB) | Total capacity for all file data |
Linked-List Tree
NKFS uses a left-child / right-sibling tree structure:- A directory’s first child is stored in
first_child. - Each child’s next sibling (another child of the same parent) is reached via
next_sibling. - Every node holds a back-pointer to its
parent.
dir listing order is reverse-insertion order.
NKFS lives entirely in
.bss — both the 256-node pool and the 512 KB data pool are zero-initialized at boot by the bootloader/startup code and do not occupy space inside the kernel binary image on disk.API Reference
nkfs_init
C: of type NKFS_DIR. Prints a capacity confirmation via kprintf:
nkfs_get_root
C: directory node. This is the entry point for all path traversal. The returned pointer is valid for the lifetime of the kernel session.
nkfs_find_child
parent, comparing each child’s name field against name using strcmp. Returns the matching node, or NULL if:
parentisNULL.parent->typeis notNKFS_DIR.- No child with the given name exists.
nkfs_mkdir
name under parent. Returns a pointer to the new node on success, or NULL if:
parentisNULLor not a directory.- The node pool is full (
node_count >= MAX_NODES). - A child with the same name already exists (checked via
nkfs_find_child).
parent->first_child and parent->size is incremented.
nkfs_create_file
name under parent. If a file with name already exists it is reopened — its size is reset to 0 and its data pointer is cleared. Returns NULL if:
parentisNULLor not a directory.- The node pool is full.
- A directory with the same name already exists (type collision).
nkfs_write_file
size bytes from data into the shared data pool starting at the current data_pool_used offset. Updates file->data to point at the newly written region and sets file->size = size. Returns 0 on success, or -1 if:
fileisNULLorfile->type != NKFS_FILE.- The data pool would overflow (
data_pool_used + size > DATA_POOL_SIZE).
nkfs_write_file always appends to the pool at data_pool_used and advances the pointer. Calling it again on the same node allocates a new region — the old data remains in the pool but is no longer referenced by the node. There is no free or reuse mechanism.Usage Example
The following snippet creates adocs directory under the root, creates a file inside it, writes a string, and reads it back byte-by-byte:
Limitations
No deletion or rename
There is no
nkfs_delete or nkfs_rename. Nodes and their data pool allocations are permanent for the lifetime of the session.Single-write semantics
nkfs_write_file does not overwrite in-place. Each call advances data_pool_used and allocates a new region; old data is leaked in the pool.No persistence
All data is stored in RAM. Everything is lost on reboot or power-off — there is no disk backing.
Name length cap
Node names are stored in a fixed
char name[32] buffer. Names are truncated to 31 characters via strncpy.