← Back to Universe Map

💾 Storage & File Systems Planet

Persistent Storage, File Systems, Inodes, and Block Management

🌟 What is This Planet?

The Storage planet explores how data persists on disk, how file systems organize files and directories, and how the OS reads/writes to storage devices.

You'll understand:

  • File systems (ext4, NTFS, etc.)
  • Inodes and file metadata
  • Blocks and allocation
  • Directories as special files
  • Hard links vs symbolic links
  • File descriptors and open file table

📚 Core Concepts

File System: OS layer that organizes files on disk

Inode: Metadata structure (size, permissions, block pointers)

Block: Fixed-size chunk of disk (e.g., 4KB)

Directory: Special file mapping names to inodes

File Descriptor: Integer handle to open file (per-process)

Path Resolution: Walking directory tree to find inode

🧠 The Mental Model

Think of a file system like a library:

  • Files = books
  • Inodes = catalog cards (metadata about books)
  • Blocks = shelves holding book pages
  • Directories = sections of the library
  • File path = address to find a book
  • Hard link = multiple catalog cards for same book

⚡ Key Flows

Opening a File:

  1. Process calls open("/path/to/file")
  2. Kernel resolves path (walks directories)
  3. Finds inode number
  4. Creates file descriptor
  5. Returns FD to process

Reading a File:

  1. Process calls read(fd, buffer, size)
  2. Kernel looks up inode via FD
  3. Finds block numbers for data
  4. Reads blocks from disk
  5. Copies to process buffer
  6. Updates file offset

🔗 Connection to Other Planets

Storage connects to everything:

  • Memory: File contents cached in RAM (page cache)
  • OS: Kernel manages file system, open file table
  • I/O: Disk drivers handle block read/write
  • Processes: Each process has file descriptor table

When you write code that opens files, you're using this entire stack!

🎯 File System Hierarchy

Typical Unix-like structure:

  • / - root directory
  • /bin - essential binaries
  • /etc - configuration files
  • /home - user directories
  • /usr - user programs
  • /var - variable data (logs)
  • /dev - device files
  • /tmp - temporary files

📖 Important Syscalls

open(): Open file, returns file descriptor

read(): Read bytes from file

write(): Write bytes to file

close(): Close file descriptor

lseek(): Change file offset (seek to position)

stat(): Get file metadata (size, permissions)

mkdir(): Create directory

unlink(): Delete file

⚙️ Behind the Scenes

What happens during open("/home/user/file.txt"):

  1. Kernel reads root inode
  2. Finds "home" entry → reads its inode
  3. Finds "user" entry → reads its inode
  4. Finds "file.txt" entry → reads its inode
  5. Allocates file descriptor
  6. Creates open file entry in kernel
  7. Returns FD to process

🚧 Interactive File System Simulator Coming Soon

We're building an interactive file system visualization that will let you: