THE
GHOSTFILE.
Deleted. Invisible. Still alive.
Meet the original file.
Inside
the kernel.
A pathname is resolved once when a file is opened. Reading through a descriptor uses the existing open file description, not a fresh lookup of the old name.
When can
the file die?
The last name can disappear before the last open reference. The OS must retain the original file until both are gone.
*The demo counts one persistent shell reference. Temporary references during reads are omitted. Other kernel references, mappings and snapshots can complicate real storage reclamation.
if (links == 0
&& refs == 0) {
reclaim(file);
}
Reclamation ≠ secure erasure.
Change the file.
Don't interrupt the reader.
A same-filesystem atomic rename can replace a published pathname with a new file while existing readers keep their old open references.
Version A
Continues reading the original open file object.
Version B
Resolves the same pathname to the newly published file.
Another consequence: deleted but open files can still consume storage until their remaining references are released.
A filename
is not the file.
On UNIX, a file can outlive its last name. Its storage becomes reclaimable only when the remaining references are released.