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.

BootsectorSuperblockFS metadataInode tableone per fileData blocksactual file contentDisk layout (simplified, low address → high address)
  • 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:

FieldValue
File typeRegular, directory, symlink, device
Owner (uid, gid)Who owns it
Permissionsrwxrwxrwx bitmask
SizeBytes
Timestampscreated, modified, accessed
Link countNumber of hard links
Block pointersWhere data lives on disk
text
Loading...

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 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.

python
Loading...

Block Pointers & Large Files

An inode can't hold an arbitrarily large list of block pointers. ext4 uses a three-level indirection scheme:

text
Loading...

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:

text
Loading...

Each entry is: {filename, inode_number}. When you open("/home/alice/notes.txt"), the OS:

  1. Starts at / (inode 2, always)
  2. Looks up home in root directory → inode N
  3. Looks up alice in inode N → inode M
  4. Looks up notes.txt in inode M → inode 4821
  5. Opens inode 4821

File System Types

FSOSJournalingMax file sizeNotes
FAT32AllNo4 GBSimple; widely compatible; no permissions
NTFSWindowsYes (metadata)16 TBPermissions, compression, encryption
ext4LinuxYes (full)16 TBLinux standard; journaling for crash safety
APFSmacOSYes8 EBSnapshots, copy-on-write, space sharing
ZFSLinux/BSDCopy-on-write16 EBData 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:

  1. Write intention to journal (commit)
  2. Apply changes to actual data
  3. Clear journal entry

On crash recovery: replay or discard journal entries. Reduces fsck time from hours to seconds.

File Permissions (Unix)

text
Loading...
python
Loading...

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