rm, rm -r, and why removal needs a directory
Milestone 47. Built 2026-07-31. The contract side is file_system_contract::file_system::RMDIR; the program is
components/src/rm.rs; the grant is grant_contract::DirectoryGrantDeclaration.
Removal is an operation on the directory, not on the file
The thing that shapes everything here: no per-file capability can express "take this name away."
A name lives in a directory, so removing it is an operation on the directory that holds it. wc report.txt can be granted the file; rm report.txt cannot.
So rm is the first program granted a directory rather than a file, which is why Manifest
grew DirectoryGrantDeclaration alongside FileGrantDeclaration. The child receives a capability to the directory the name is
in, plus the name.
-r widens the grant, and that is the whole safety property
DirectoryGrantDeclaration::Required { subtree_option: Some(b'r') }. Without the flag, the capability carries the
authority to take names out of one directory and nothing else: it cannot list what is under a
subdirectory and cannot descend into one. With the flag, it widens to walking and listing underneath,
which is what a recursive removal needs at every level.
The consequence is worth stating precisely, because it is the difference between this and every other
rm:
A program run without
-rholds no way to descend, so its recursion is not disabled by a branch anybody has to get right.
Unix's rm decides not to recurse. This one cannot. And because the widening happens at the
prompt, caps rm -r logs/ shows strictly more authority than caps rm logs/: typing -r is
visibly handing over more, rather than setting a flag whose consequences are elsewhere.
RMDIR is empty-only, which is Unix's choice and the reason the rest is safe
RMDIR removes an empty directory, requires REMOVE on the parent, and answers ENOTEMPTY
otherwise. No single call in the contract can take a subtree away. The recursion lives in
userspace as a loop of individually safe single-step operations: walk, unlink files, remove empty
directories bottom-up.
It is not revocation, for §48's reason: the FS server's handle table is per server, so handles cannot be invalidated for clients the server cannot enumerate. Removing a name is not destroying an object.
The walk stops where the capabilities stop
rm -r needs ENUMERATE to see, DESCEND to recurse, and REMOVE to delete, at every level. So
the bound is structural rather than a check.
rm(1) ships a literal special case: "it is an error to attempt to remove the files /, . or
..", because Unix needs one. We have no such case and need none: a shell holding a subtree
cannot name the root, so there is nothing to special-case. If a future change makes such a guard feel
necessary, that is a signal something else broke, not a license to add it.
Unix semantics, checked against rm(1) rather than remembered
- Silent on success.
-vexists precisely because the default prints nothing. - Failure is a diagnostic plus a non-zero exit. Exit 0 only if everything named was removed.
-fignores a nonexistent file, does not prompt, and for a missing name suppresses both the diagnostic and its effect on the exit status. Its real value is idempotency:rm -f maybe-theresucceeding is what makes a script re-runnable, and "absence is the desired state" is not a lie about failure. An earlier draft of milestone 47 argued-fshould not exist, on the reasoning that with no prompting its only meaning is suppressing errors. That was wrong about what-fdoes.rmon a directory without-ris a refusal (EISDIR), never a silent escalation.- An interrupted
rm -rleaves a partial tree, reports what failed, and exits non-zero. There is no transaction spanning requests, and adding one would mean the server holding a transaction open across receives, which breaks the serve-loop-runs-one-request-to-completion property §47 relies on for concurrency atomicity.
The fixture detail that makes -f testable
RM_MISSING is deliberately a name the fixture never stages. Without that, the -f run and the
plain run would be indistinguishable, because the whole of -f is that a name which is not there is
not an error. A fixture that accidentally shipped that name would make the test pass while proving
nothing, and file_system_contract has a host test asserting it is never staged.
rm *.txt: the operand can be a set, and then it is the namespace
Milestone 47's globbing lane, glob-grant.md. rm old.txt grants the directory
holding one name; rm *.txt grants that directory attenuated to the names the pattern matched,
served by components/src/fs_nameset_caretaker.rs. The over-grant this note used to declare (the
capability could remove anything else in that directory) is closed for a pattern operand and remains
for a literal one, which is the honest state: a single name still travels through
fs_subtree_caretaker.
rm is started with a grant whose name is zero bytes long
(file_system_contract::grant::WHOLE_NAMESPACE), whether the operand is a set or one literal name:
the shell grants the set of that one name, and rm sweeps it. It means "the operand is your
namespace", and rm learns the names by enumerating the capability it holds, which reveals exactly
what the command line already printed. No name rides in rm's START words, and rm refuses words
that carry one (milestone 1122 (every name travels on a page)).
It sweeps in one listing with no rounds, and the contrast with the recursive walk is a fact about the namespace rather than an optimization. That walk must re-read from cursor 0, because removing a name shifts a real directory's entries; a set namespace is fixed, so re-reading would hand the loop the names this run has already taken away.
The program's shape
rm is a program, not a shell builtin, and that is Unix's shape rather than a divergence from it.
cd, pwd and ls are builtins here because the shell is rebinding a capability it already
holds. rm is a destructive loop, not a rebinding. A builtin would run with the shell's entire
endowment, where a program takes an explicit attenuated grant. So caps rm -r logs prints the
subtree at risk before anything happens, and a bug in the recursion can only reach what the
process was handed.
The shell resolves any leading path at the prompt and grants the directory the name is in, at
slot 0. The report endpoint is slot 1, and every other program in this tree takes its output at
slot 0. The order is this way round so the two slots mean one thing on both wirings. The kernel's
start_granted_dir puts the narrowed endpoint at slot 0 and a report endpoint at slot 1.
system_initializer's spawn service puts the caretaker it built at slot 0 and the shell's output
at slot 1, ahead of every other grant. The options ride in the START specification word
(file_system_contract::grant), and the names are on the caretaker's grant page. So the program
costs no extra frame of its own, and holds nothing that names a progenitor, a terminal, or the filesystem
above its grant.
The report is a byte sink and ends as every sink stream does, with (end_of_stream(), 0, 0). The exit
status and the count of names removed go after it, once, to a verdict endpoint at slot 2
(grant_plan::rm_report::VERDICT_SLOT). A SEND returns only once a receiver takes its message, so
the verdict cannot overtake the text: a reader drains the report to its end, then receives the
verdict. The kernel's start_granted_dir and start_granted_set grant that endpoint when the
caller asks (verdict: true). The spawn service leaves slot 2 empty, so at the prompt the kernel
refuses the second SEND and rm exits.
BUGS
rm a/b/c.txtis refused at the interactive prompt (phase 3 of the capability shell). The progenitor builds onefs_subtree_caretakerper grant, so a deeper grant, a chain of caretakers, is not built.rm rmtree/rm-soloandrm gate.txtboth work andscript/swish-checkgates both on every architecture: the first descends one name withOPENDIR, the second narrows the root withNARROW, the verb §173 (narrowing the root of the shell's namespace) ruled. See notes/dir-capability.md's BUGS.- The shell does not see
rm's exit status. The spawn service grants no verdict endpoint, and the shell reads no exit status from any program it spawns (SYSTEM_CALL_EXITcarries none). The status and count reach a guest test, through the verdict endpoint, and nothing at the prompt. A status carried on the death message would reach every program at once; that is a change to the system call surface and has no milestone yet. - A report that holds only its end means the run printed nothing, and that is checkable because a text frame's first word is a byte count of at most 16, which no end of stream equals. The status cannot ride the end of stream's other two words, since the sink contract reserves them and a sink refuses a message that sets them.
- No
rm -i. There is no prompting anywhere in this system, so the flag has nothing to mean. - Recursion depth is real stack, since the program has no allocator and each level holds a listing
buffer by value.
rmasks for 4 stack pages. A deep enough tree will exhaust it, and the failure will be a data abort rather than a diagnostic. rmremoves nothing this contract has since grown, and that is now checked rather than assumed. Milestone 61 (the caretakers: one verb table, and names that say what you get) made the caretakers dispatch offfile_system_contract::verb. A verb added to the contract is forwarded by them from the day its row exists;rmstill holdsREMOVEand nothing else, so what it can send is unchanged. The two facts are independent and it is worth saying so: the caretaker got wider, the grant did not.
See also
- DECISIONS §47 (a directory capability carries six rights), §48 (navigation is the shell rebinding what it holds), §42 (a filesystem declares what it offers and must be truthful).
- Milestone 47 (navigation and naming)'s "
rmdirandrm -r: Unix already made the safe choice" indesign/roadmap/0047-navigation-and-naming/mkdir-and-rm.md. notes/dir-capability.mdfor the rights ladder andfs_subtree_caretaker, andnotes/glob-grant.mdfor the nameset caretaker a pattern operand is served by.