notes

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 -r holds 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

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

See also