File Systems
A file system answers one question: how do you turn a flat, numbered sequence of disk blocks into a hierarchy of named files and directories that persists across reboots?
What's on Disk
A hard drive or SSD is a sequence of blocks (typically 512 bytes or 4 KB). Everything the file system does — storing metadata, data, directory entries — maps onto these blocks.
- Boot sector: code to load the OS
- Superblock: file system metadata — total blocks, free blocks, inode count, block size
- Inode table: one inode per file/directory
- Data blocks: actual file content
Inodes (Unix / ext4)
Every file and directory is represented by an inode — a fixed-size structure that stores all metadata except the file name:
| Field | Value |
|---|---|
| File type | Regular, directory, symlink, device |
| Owner (uid, gid) | Who owns it |
| Permissions | rwxrwxrwx bitmask |
| Size | Bytes |
| Timestamps | created, modified, accessed |
| Link count | Number of hard links |
| Block pointers | Where data lives on disk |
The directory is just a file — a list of (name, inode_number) pairs. The name lives in the directory; the inode holds everything else.
Hard Links vs Soft Links
Hard link: a new directory entry pointing to the same inode. The file isn't duplicated — two names, one inode. Deleting one name decrements the link count; the data is freed when count reaches 0.
Soft link (symlink): a file whose content is a path to another file. If the target moves, the symlink breaks.
Block Pointers & Large Files
An inode can't hold an arbitrarily large list of block pointers. ext4 uses a three-level indirection scheme:
Modern ext4 uses extents instead — a range (start_block, length) — which is far more efficient for large contiguous files.
Directories
A directory is a file containing an array of directory entries:
Each entry is: {filename, inode_number}. When you open("/home/alice/notes.txt"), the OS:
- Starts at
/(inode 2, always) - Looks up
homein root directory → inode N - Looks up
alicein inode N → inode M - Looks up
notes.txtin inode M → inode 4821 - Opens inode 4821
File System Types
| FS | OS | Journaling | Max file size | Notes |
|---|---|---|---|---|
| FAT32 | All | No | 4 GB | Simple; widely compatible; no permissions |
| NTFS | Windows | Yes (metadata) | 16 TB | Permissions, compression, encryption |
| ext4 | Linux | Yes (full) | 16 TB | Linux standard; journaling for crash safety |
| APFS | macOS | Yes | 8 EB | Snapshots, copy-on-write, space sharing |
| ZFS | Linux/BSD | Copy-on-write | 16 EB | Data integrity, RAID-Z, snapshots |
Journaling
Without journaling, a crash mid-write can leave the file system in an inconsistent state (e.g., data written but directory not updated). Journaling writes a log of intended changes before applying them:
- Write intention to journal (commit)
- Apply changes to actual data
- Clear journal entry
On crash recovery: replay or discard journal entries. Reduces fsck time from hours to seconds.
File Permissions (Unix)
Key Takeaways
- A file system maps block devices to named, hierarchical files
- Inodes store all file metadata except the name — names live in directory files
- Hard links share an inode; soft links are just paths
- Journaling makes file systems crash-safe by logging intentions before acting
- ext4 uses extents for efficient storage of large files; FAT32 uses simple chains