Part 1 of 7 · 1 min read
Why this page comes first
In this module you will
- Say what a file is to the OS: a numbered object with metadata and bytes, separate from its names.
- Read the fields of
stat, including the inode number, the link count and the size. - Explain a directory as a table from names to inode numbers, and walk a path through it.
- Tell a hard link from a symbolic link, and predict link counts after
link,unlinkandmkdir. - Explain why
unlinkdoes not always free the data.
Level 8 ended with devices that store numbered blocks. A program does not want blocks. It wants named files that grow, shrink and survive a reboot. A file system is the part of the OS that builds files and directories on top of blocks. This page gives the view that programs see. Page 2 shows the structures on the disk that make the view real, and later pages show how they stay correct after a crash.
About this example About this example
Real: The C program in section 3 was compiled with gcc -Wall -Wextra and run in a fresh ext4 file system (4 KiB blocks, made on a 16 MiB image and mounted through a loop device) on a Linux test machine (2 processors, kernel 6.18). The stat figures in section 2 came from the same file system.
Scripted: The path /home/ann/notes.txt in section 5 and the symlink target in the exercises are made up to show the idea.
Not real: The inode numbers (12 and 13) are the first free ones on that new file system. On a real disk they are larger and less tidy. Other file systems behave alike, but they may number inodes differently or have no inode numbers at all.