File Systems & I/O
The problem
Data needs to survive after a program exits and a machine restarts, which memory (RAM) cannot do — file systems give a persistent, hierarchical way to name, store, and retrieve data on durable storage, and I/O is the disciplined interface every program uses to reach it.
Why now
Trees already gave the hierarchical structure a file system's directories use; virtual memory already showed how the OS mediates access to a resource through an abstraction layer. File I/O is that same mediation pattern, applied to durable storage instead of RAM.
Mental model
A file system is a tree (directories containing files and more directories) laid on top of a flat block device, with a lookup table mapping paths to physical disk locations. I/O is always mediated by the OS — a program never touches the disk directly, it asks the kernel via a system call, which is what makes permissions, caching, and safety enforceable in one place.
Requires
- TreesComputer Science Fundamentals
A file system's directory structure is literally a tree — files are leaves, directories are internal nodes — so file system navigation is tree traversal by another name.
- Processes & ThreadsOperating Systems
File I/O is always performed on behalf of a process, mediated through OS-managed file descriptors scoped to that process; you need the process concept before 'a process's open files' means anything.
Unlocks
Used in
- Every file read/write operation in every application
- Databases, which often manage their own storage on top of the raw file system for performance
- Log files and append-only writes in production systems
- Understanding why file I/O is slow relative to memory access, and why caching matters
Projects
- Write a program that opens, writes, and reads back a file, then inspect its raw bytes on disk to confirm what was actually stored
- Measure and compare the time cost of many small writes versus one large buffered write to the same file
Examples
- A file path like /home/user/notes.txt is a walk down the file system tree from root to leaf
- Buffered writes batch many small writes into fewer, larger disk operations because each I/O operation has fixed overhead
Resources
- File Systems — MIT 6.033course
Mastery checklist
- I can explain a file system's directory structure as a tree
- I can explain why file I/O goes through the OS rather than directly to hardware
- I can explain why buffering reduces the cost of many small I/O operations
- I can predict the relative performance of memory access versus disk I/O