File Systems
The on-disk (and in-memory) structures that turn bytes into files, directories, and mounts.
Level: intermediate
What is it?
A filesystem defines how bytes on a storage device are organized into named files and directories, how metadata and permissions are stored, and how writes are made visible and recoverable. Common designs use inodes or equivalent objects, directory mappings, allocation structures, caches, and journaling or copy-on-write metadata.
Why does it matter?
Without a filesystem, applications would need to manage raw storage blocks and metadata themselves. Filesystems provide naming, ownership, space allocation, and recovery behavior, but durability depends on the filesystem, device, and how applications issue writes.
Mental model
Think of storage as a set of numbered blocks. A filesystem maintains a directory index from names to file objects, and from file objects to the blocks or extents that contain content.
How it works
- A directory maps names to filesystem objects; the exact metadata model differs by filesystem.
- An inode-like object commonly stores metadata and references to data blocks, while directory entries connect names to object identifiers.
- Page cache and write-back buffers improve performance but mean a successful write call may not equal durable media persistence.
- Journaling or copy-on-write techniques help keep metadata structures consistent after a crash.
- Mounts compose multiple filesystems into one namespace; permissions and ownership still need to be enforced.
Steps
- A user calls open('/home/a.txt'); the VFS resolves components of the path.
- The filesystem checks directory entries and access permissions, then returns an open file descriptor.
- Reads may be satisfied from the page cache or trigger block I/O.
- Writes update cached pages and metadata; sync/fsync semantics influence when data is requested to become durable.
Real-world usage
- Investigating disk-full errors, permissions, mount points, and slow I/O.
- Choosing file-oriented storage versus a database for application data.
- Understanding crash consistency and durability of file writes.
Common mistakes
- Assuming write() always means bytes are safely on durable media.
- Confusing a path name with an open file descriptor.
- Ignoring permissions on parent directories when diagnosing path access.
Interview questions
What is the difference between a directory entry and an inode-like object?
A directory entry associates a name with an object identifier; the inode-like object stores metadata and references to file data, depending on filesystem design.
Why might fsync be needed after a write?
Buffered writes may still reside in cache. fsync requests that file data and metadata needed for retrieval be synchronized to durable storage, subject to the device and filesystem contract.