procfs - synthetic /proc filesystem
src/kernel/include/kernel/procfs.h + src/kernel/arch/i386/fs/procfs.c.
Purpose
Linux-style read-only view of kernel state. Each entry is generated on read by a small renderer that walks live kernel state and writes ASCII into the caller’s buffer. No on-disk storage; nothing is cached between reads.
Entries
| Path | Renderer | Content |
|---|---|---|
/proc/cpuinfo |
CPUID leaves 0 + 1 | vendor_id, cpu family, model, stepping, flags (fpu/tsc/msr/pae/apic/cmov/mmx/sse/sse2/sse3/sse4_1/sse4_2), arch i386 (protected mode) |
/proc/meminfo |
pmm_managed_count() + pmm_free_count() + heap_used/free() |
Linux-style key/value: MemTotal, MemFree, MemAvailable, MemUsed, Buffers (0), Cached (0), HeapTotal, HeapUsed, HeapFree, PageSize, FreeFrames, TotalFrames. MemTotal reflects the bootloader-available frame pool minus the null page + kernel image (cached at pmm_init). MemUsed folds in HeapUsed (and MemFree subtracts it): the 16 MiB kernel heap is identity-mapped on top of PMM frames the allocator never reserved, so without this it read near-zero on a fresh boot. |
/proc/tasks |
Walk task_pool[], skip TASK_DEAD |
PID NAME STATE TTY TICKS MEMKB CWD. MEMKB is the per-task memory: the 8 KiB kernel stack plus resident user pages (vmm_count_user_pages(page_dir) * 4), so kernel-only tasks (idle, shells) report their stack baseline and ring-3 apps report stack + RSS. Dead-but-not-yet-reclaimed slots are filtered so userspace tools (maktop / cat /proc/tasks) only see live work; TASK_ZOMBIE slots (slice 16b: children awaiting parent wait4) DO appear so the parent can see them. |
/proc/uname |
MAKAR_VERSION + build macros + timer_get_ticks() |
Makar <MAKAR_VERSION> (i386) built <date> <time> + uptime ticks |
/proc/rtc |
CMOS RTC read | One line YYYY-MM-DD HH:MM:SS (local wall-clock). Read by the GUI dock clock/date tray, the mxclock/clock apps, and about/hwspecs. |
VFS integration
Wired in vfs.c as a new backend (VFS_FS_PROC = 3):
vfs_route()recognises any path under/proc.vfs_ls("/proc")callsprocfs_ls()to print the entry list.vfs_cat()/vfs_read_file()route toprocfs_read_file().vfs_complete()lets tab-completion enumerate/proc/<entry>.vfs_file_exists()returns 1 for known entries.
procfs is flat (no subdirectories) and read-only (no vfs_write_file
path). cd /proc is allowed; cd /proc/cpuinfo is rejected as not-a-dir.
Adding a new entry
- Add a
PROC_XXXenum value and an entry to thes_entries[]table. - Write a
render_xxx(pf_writer_t *w)function usingpf_puts,pf_putu,pf_putc. - Add a dispatch case in
procfs_read_file.
No changes to vfs.c are needed.