Systems study
Offline — showing the cached copy.
Home / Operating Systems / 8. Filesystem internals

8. Filesystem internals

One-liner. VFS gives one interface; the filesystem decides how blocks, metadata and crash safety work.

Memorize

  • VFS layer: inode, dentry, file, superblock objects; each filesystem implements operations on them.
  • Journaling (ext4): metadata (and optionally data) writes to a journal first, then to final locations — crash recovery replays it.
  • COW (btrfs/ZFS): never overwrite live blocks; snapshots are cheap; fragmentation is the cost.
  • fsync flushes data + metadata for that file; the directory must also be synced for a new name to be durable.
  • Write barriers stop the device reordering flushes; disabling them can corrupt on power loss.
  • mount -o noatime reduces metadata writes; discard/fstrim matters for SSDs.
WRITE WITH JOURNAL APP write + fsync VFS inode/dentry up… JOURNAL intent record checksummed FILESYSTEM commit to final… DEVICE cache flush / b…
Write with journal

Trap. Assuming fsync on a new file makes it appear after a crash — the directory entry is separate. Do this. fsync(file) then fsync(dir) when creating durable files.

Check

Why must the parent directory be synced after creating a file, if the file itself was fsynced?