File systems
The conceptHow a drive that only stores numbered blocks shows you folders
A drive knows nothing about files: it is a long row of fixed-size blocks, typically 4 KiB each, numbered 0, 1, 2 and so on. A file system is the kernel code and the on-disk layout that turns those blocks into named files inside folders.
On Linux's ext4, each file has an inode: a record of its size, owner, permissions and which blocks hold its bytes. A folder is a file listing entries like "cv.pdf → inode 812"; a bitmap marks free blocks.
When an app calls read() on cv.pdf at some byte offset, the kernel works out which of the file's blocks holds that byte, looks up that block's number in the inode, and reads it from the drive.
What it’s forFinds where on the drive a given byte of a file lives.
disk byte = ptr[⌊offset ÷ B⌋] × B + (offset mod B)
- offset
- position of the byte inside the file, counting from 0
- B
- block size, typically 4096 bytes
- ptr[i]
- the drive block number the inode lists for the file's i-th block
- mod
- the remainder after dividing
What it givesThe exact spot on the drive to read, found from the inode without searching.
- B = 4096, offset = 10000
- 10000 ÷ 4096 = 2 remainder 1808 → file block 2
- If ptr[2] = 500, read block 500 at byte 1808