Skip to content

Filesystem

kazah-png edited this page Jul 11, 2026 · 2 revisions

Filesystem

Layered VFS over ramdisk, EXT2, generated pseudo-filesystems (/proc), and special device nodes (/dev). POSIX-like API with 128-node pool + free-list.

See also: Drivers, Shell, GUI Subsystem, Architecture

VFS (vfs.c)

Unified namespace with node pool (128 nodes + free-list for transient mount-backed nodes). Path resolution relative to CWD.

  • vfs_open/read/write/close — file I/O
  • vfs_pread/pwrite — offset-aware I/O (used by the per-fd offset tracker and by mmap)
  • vfs_readdir — directory listing (ramdisk, EXT2, and now /proc per-pid dirs)
  • vfs_mkdir/vfs_unlink — directory creation and removal
  • vfs_getcwd/vfs_chdir — directory navigation (full absolute path)
  • vfs_isdir — directory test (used by chdir)
  • Per-terminal CWD (each shell tracks its own directory; kernel shell uses a single global)

Ramdisk

Default filesystem from CPIO initramfs. Default tree:

/  bin/  dev/  etc/  home/user/  mnt/  proc/  root/  tmp/  usr/  var/

Initramfs (initramfs.c)

CPIO newc format (070701) embedded as C byte array. Generated by tools/mkinitramfs.py. Loaded at boot — creates all files and directories in the VFS ramdisk tree.

/dev special files

Real VFS nodes whose read/write is intercepted by a dev_type field (no new syscalls):

  • /dev/null — reads return EOF (0), writes are discarded
  • /dev/zero — reads return endless null bytes
  • /dev/random and /dev/urandom — reads yield pseudo-random bytes from a lazily-seeded xorshift64 PRNG (seeded from get_ticks())
  • Created at boot in vfs_init via O_CREAT + manual dev_type assignment

/proc pseudo-filesystem

Generated VFS nodes whose content is synthesized on read by proc_generate() (no storage in ino->data):

  • Static files: /proc/version (kernel banner), /proc/meminfo (MemTotal/Used/Free), /proc/uptime (tick_count → seconds), /proc/cpuinfo
  • Per-process dirs: /proc/<pid>/status (Name, Pid, PPid, State) and /proc/<pid>/cmdline (command-line with argv)
  • Synchronised with the live process table by proc_sync(), called at vfs_open/vfs_isdir — no new syscalls, everything is plain open/read/getdents

EXT2 (ext2.c)

Read/write EXT2 driver via ATA PIO:

  • Superblock, block groups, inode tables, directory entries
  • Inode/block allocation, directory creation, file writes
  • Mount at /mnt via vfs_mount
  • Fd-based I/O flushes to disk on close (persistent across reboot)
  • Fd-based readdir (vfs_readdir on /mnt)

ATA driver (ata.c)

PIO mode, primary channel 0x1F0, IRQ 14, 28-bit LBA (up to 128 GB), polled I/O.

Clone this wiki locally