A directory entry associating a name directly with an existing file. In the inode-based example, successful link("a", "b") adds the second name for inode 42 and increases its hard link count from 1 to 2. Both directory entries have equal status; removing a leaves b usable. This example assumes both names are in the same file system, the destination name is unused, and the operation is permitted. [ref]
For an ordinary file under the POSIX rules used here, successful unlink("a") removes the named directory entry and decreases the hard link count. An existing open file description still refers to the same file; removing a name does not detach an already open file descriptor. When the final hard link disappears, the contents remain available through open references until those references close. This distinction is between the lifetime of a name and the lifetime of the underlying file. [ref]
Start with names a and b for inode 42 and one file descriptor 3 referring to one open file description. Let count hard links and count live open file descriptions for this file. Assume successful operations, no additional references, and no memory-mapped file. The stages are
After the first removal, b still works. After the second, neither name works, but a read through the existing file descriptor can still obtain all six bytes if its open file description's current position is at the beginning. The final close releases the last open reference, allowing the inode and its file data blocks to be reclaimed. Freed storage is reusable; this does not promise that old bytes are securely erased. [ref]
The reasoning is bookkeeping rather than a long proof: each successful removal subtracts one from and leaves unchanged; closing the only file descriptor in this example releases the sole open file description. Storage is reclaimable only at the last stage. is a teaching count, not a count of file descriptors or an asserted internal inode field: several file descriptors can share one open file description, and other references such as a memory-mapped file require additional lifetime accounting. The diagrams are abstract models, not operations on actual user files.

Articles by others on the same topic (0)

There are currently no matching articles.