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.
Learning goal
Understand how small, composable Unix tools work together via pipes.
Category
productivity
Components touched
Builds on
Unlocked by this phase
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, anduptimeread the Phase 38/procfiles, while new kernel work stays limited to thedmesgring buffer andumount. - 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
bccalculator (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
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
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
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
Phase 40
CompleteThreading Primitives
The OS supports kernel-level threads via `clone()` with `CLONE_THREAD` and `CLONE_VM`. Multiple threads share an address space and can synchronize via `futex()`. Thread-local storage works via `arch_prctl(ARCH_SET_FS)`. This enables multi-threaded C programs and improves musl libc compatibility (which uses threads internally even for single-threaded programs).
Phase 42
CompleteCrypto Primitives
The OS has a cryptography library providing hash functions, symmetric encryption, and asymmetric key operations. This is the foundation layer that SSH (Phase 43) and future security features build upon.