The layout
On disk a file is split in three. Its name sits in a directory. Its inode, a small fixed-size record, holds the facts about it and where its bytes are. The bytes themselves sit in data blocks of 4096 bytes.
Our small disk has 64 blocks of 4 KB. Block 0 is the superblock, block 1 the inode bitmap, block 2 the data bitmap. Blocks 3 to 7 hold 80 inodes of 256 bytes. Blocks 8 to 63 hold data.
An inode records the file's type, size, owner and permissions, times, link count, and a list of block pointers. Pointer 0 names the disk block holding bytes 0 to 4095, pointer 1 the next 4096, and so on. It never stores the name.
Opening a file
open() gets a path, but the disk finds files by inode number. Every path starts at the root directory, whose inode number is always known: 2. So the kernel reads inode 2 from block 3.
A directory is a file whose data is a list of name and inode number pairs. Inode 2's pointer leads to block 8. The kernel scans it for "notes" and finds inode 20.
Inodes are numbered slots, so finding one is arithmetic: 20 × 256 = 5120 bytes into the table, which is block 4, byte 1024. The kernel reads it, checks the permissions and returns file descriptor 3.
Reading and growing
pread asks for 100 bytes starting at byte 5000. 5000 ÷ 4096 is 1 remainder 904, so pointer 1 tells the kernel: block 10. It reads that block and copies bytes 904 to 1003 into the buffer.
pwrite puts 4000 bytes at byte 6000, so the last byte is 9999. 9999 ÷ 4096 is 2, but pointer 2 is empty. The kernel scans the data bitmap for the first 0, finds block 11 free, and sets its bit to 1.
The bytes go into block 10 (2192 bytes) and block 11 (1808). Then the inode changes: pointer 2 = 11, size = 10000. One call wrote four blocks: bitmap, two data blocks, inode. A crash midway leaves them disagreeing.
Bigger files
An inode has room for few pointers. ext2 and ext3 keep 15: twelve direct ones cover 48 KB. The 13th points to an indirect block holding 1024 more pointers, about 4 MB. A double indirect block passes 4 GB. ext4 uses extents instead.
Because names and files are separate, two names can point to one inode (a hard link; the link count says how many). Fixed-size inodes are found by arithmetic, and pointers let a file's blocks sit anywhere on the disk.
What happens
;; step 1/11 · three-parts
name in a directory: "notes" -> inode 20
inode number 20: type, size, owner, times, links,
and pointers to its data blocks
data blocks 9 and 10: the 6000 bytes of the file
the inode number is the file's real identity;
the name is just an entry that points to it
The disk is the "very simple file system" from OSTEP chapter 40: 64 blocks of 4 KB with the same regions in the same order. Real file systems are bigger and split the disk into groups, but the parts are the same. The bitmaps on the figure show only the eight bits that matter: inodes 16 to 23 and data blocks 8 to 15. Each real bitmap fills a whole 4 KB block.