= File system
{wiki}
A <file system> organizes <files>, their <file metadata>, and the names through which they can be found. In the <Unix> model used here, a <file-system directory> contains <directory entries> associating names with <inodes>; an <inode> describes the underlying <file> and how to locate its contents. The <file-system namespace> answers "what does this name reach?", while the <inode> answers "which <file> is it?". These are distinct responsibilities, even though they cooperate on every lookup.
For a computed toy example, let one <file-system directory> contain names `a` and `b`, both referring to <inode> 42 in the same <file system>. That <inode> has size 6 <bytes> and two <hard links>. Its direct references lead to four-<byte> <file data blocks> 7 and 9: block 7 holds `hell`, while block 9 holds `o` followed by a newline, with two unused slots. Reading either name therefore obtains the same six-<byte> contents `hello` followed by a newline. There is one <file> with two names, not two copies. This direct-reference layout and tiny block size are teaching choices, not requirements on every <file system>.
\Image[/file-system-inodes-and-hard-links.png]
{title=Two <hard links> reach one <inode>; a <file descriptor> reaches it through an <open file description>}
The separation is useful because a rename within this <file system>, from `a` to a previously unused name `c`, can change a <directory entry> without copying the six <bytes> of contents. The remaining name `b` still reaches <inode> 42. A successful write changing the first <byte> through either name changes what both names subsequently read, to `jello` followed by a newline. This sharing is the attraction of <hard links>, and also why a <hard link> is not an independent backup. A program that replaces a named <file> with a different <file> can instead make the names diverge. https://pubs.opengroup.org/onlinepubs/9799919799/functions/rename.html[The Open Group, POSIX.1-2024, rename: changing names and replacing directory entries]{ref}
Back to article page