m³OS docs GitHub

Phase 41

Expanded Coreutils

The OS ships with a comprehensive set of Unix utilities sufficient for daily development work. Moving beyond the minimal set from Phase 14, this phase adds text processing, file inspection, and system administration tools that developers expect.

Complete

Learning goal

Understand how small, composable Unix tools work together via pipes.

Category

productivity

Why this phase matters

The OS ships with a comprehensive set of Unix utilities sufficient for daily development work. Moving beyond the minimal set from Phase 14, this phase adds text processing, file inspection, and system administration tools that developers expect.

How it works in m3OS

The roadmap entry defines the learning scope for this phase; a deeper implementation doc has not been matched yet.

How it builds on earlier phases

This phase builds on Threading Primitives and turns that foundation into Expanded Coreutils.

Implementation outline

  • Set up sbase cross-compilation with musl on the host.
  • Port text processing tools first (head, tail, sort, uniq — most immediately useful).
  • Port file tools (find, xargs, tee).
  • Build the system tools around existing procfs and syscall support: ps, free, mount, and uptime read the Phase 38 /proc files, while new kernel work stays limited to the dmesg ring buffer and umount.
  • Port diff and patch — essential for development workflows.
  • Port or write a pager (less/more).
  • Port remaining tools.
  • Test each tool with shell pipelines to verify composability.

Task progress snapshot

131 of 131 tracked tasks are complete.

Documentation targets

  • Documentation deliverables have not been listed yet.

Deferred follow-on work

  • Full GNU coreutils compatibility
  • Locale and internationalization support
  • BusyBox-style multicall binary
  • man pages
  • bc calculator (complex parser; deferred to a later follow-up once the text and file toolchain lands)

Source materials

Important code

Code spotlight cards

Code spotlight

`head`: print first N lines

userspace/coreutils/head.c See file

read(), write(), and basic argument parsing — all already available. Why it matters: head is one of the most-used pipeline filters. It needs. Focus on `head` and `main` in `userspace/coreutils/head.c` while you trace the snippet.

Code spotlight

`tail`: print last N lines

userspace/coreutils/tail.c See file

lines of input — a different read pattern that exercises ring-buffer thinking. Why it matters: tail complements head and requires buffering the last N. Focus on `tail` and `main` in `userspace/coreutils/tail.c` while you trace the snippet.

Code spotlight

`sort`: sort lines alphabetically

userspace/coreutils/sort.c See file

requires reading all input into memory then sorting — exercises malloc/heap. Why it matters: sort is essential for sort | uniq pipelines and. Focus on `sort` and `main` in `userspace/coreutils/sort.c` while you trace the snippet.

Key files

  • kernel/src/serial.rs — Kernel log ring buffer in kernel/src/serial.rs so dmesg can read boot messages.
  • kernel/src/fs/procfs.rs — /proc/kmsg virtual file in kernel/src/fs/procfs.rs to expose the ring buffer.
  • xtask/src/main.rs — libc. The xtask/src/main.rs function build_musl_bins() already cross-compiles C
  • kernel/initrd/ — sources with musl-gcc -static and copies the resulting ELFs to kernel/initrd/. New

How real OSes differ

  • Real systems use GNU coreutils (or BusyBox on embedded systems), which have decades of feature additions, locale support, and edge case handling. Our sbase-based utilities are intentionally minimal — they handle the common cases and skip exotic options.
  • Real systems also have a `/proc` filesystem providing rich kernel introspection. Our approach may use either a simplified `/proc` or dedicated syscalls, depending on what is simpler to implement.

Success criteria

  • All listed tools are present in `/bin` or `/usr/bin` and work from the shell.
  • Pipelines work: `cat file | sort | uniq -c | sort -rn | head -10`.
  • `find . -name "*.c" | xargs grep "main"` works.
  • `ps` shows running processes with PID, name, and status.
  • `free` shows total and available memory.
  • `uptime` reports time since boot via the existing Rust utility and is available from the default shell PATH.
  • `diff file1 file2` shows differences; `patch` can apply the diff.
  • `less` provides scrollable file viewing with search.

Related phases

Keep exploring the roadmap