Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.

Subsystems

dany edited this page Jan 15, 2026 · 3 revisions

keonOS Subsystems ⚙️

This section dives deeper into some of the main kernel subsystems, including the Virtual File System (VFS), device drivers, and the initrd packing system.


🔹 Virtual File System (VFS)

keonOS implements a modular Virtual File System layer that abstracts filesystem operations behind a unified interface.
This allows multiple filesystem implementations (RAMFS, FAT32, device nodes, etc.) to coexist transparently.

Core Concepts:

  • vfs_root – the root node of the filesystem (/)
  • cwd_node – current working directory
  • VFSNode – base class for files, directories, and devices

Filesystem traversal, creation, and I/O are all routed through VFSNode virtual methods.

Example: opening a file

VFSNode* file = vfs_open("/initrd/readme.txt");
if (file) 
{
    uint8_t buffer[128];
    uint32_t read_bytes = vfs_read(file, 0, sizeof(buffer), buffer);
    vfs_close(file);
}

Mounting a filesystem:

init_file_system(ramdisk_vaddr);  // mounts initrd and FAT32 partitions

Creating directories and files:

vfs_mkdir("/mnt/fat32/new_folder", 0);
VFSNode* new_file = vfs_create("/mnt/fat32/new_file.txt", 0);

Note: fopen and others works as a perfect alternative to the low-level vfs management.


🔹 Device & Disk Drivers

keonOS uses device nodes to abstract hardware access. For example, the ATA disk driver:

Reading from a device node:

uint32_t DeviceNode::read(uint32_t offset, uint32_t size, uint8_t* buffer) 
{
    uint32_t start_sector = offset / 512;
    uint32_t num_sectors = (size + 511) / 512;

    uint8_t* temp_buffer = (uint8_t*)kmalloc(num_sectors * 512);
    ATADriver::read_sectors(start_sector, num_sectors, temp_buffer);
    memcpy(buffer, temp_buffer + (offset % 512), size);
    kfree(temp_buffer);
    return size;
}

This allows any filesystem mounted on top of keon_disk to access the hardware transparently.


🔹 Initrd & KeonFS

The initrd (initial RAM disk) is a RAM-based filesystem loaded at boot. keonOS packs files from initrd/ into a single image (initrd.img) using a Python script:

Packing the initrd:

python3 scripts/pack_keonfs.py

Example Python snippet:

superblock = struct.pack("<IIIIIIII", MAGIC, file_count, VERSION, total_size, 0, 0, 0, 0)
with open("iso/boot/initrd.img", "wb") as f:
    f.write(superblock)
    for h in headers: f.write(h)
    for p in payloads: f.write(p)

This creates a single memory-mapped filesystem that the kernel can mount at /initrd at boot time.


🔹 Summary

  • VFS: abstracts filesystems and devices with a unified interface
  • Device Drivers: ATA and other devices expose hardware through VFSNodes
  • Initrd / KeonFS: packed RAM-based filesystem for early boot and system files

Tip: Every VFS operation (open, read, write, mkdir, unlink) works on any mounted filesystem transparently, thanks to the modular VFS design.

Clone this wiki locally