Interview Prep Zoneby CuriouserLabs

Question 2 of 5 · senior level

What are inodes and directories really? And what problem does journaling solve?

🎤 Say this first

An inode is the file: metadata (size, permissions, timestamps) plus pointers to its data blocks — everything except the name. A directory is just a file mapping names → inode numbers; a hard link is a second name for the same inode (files die when link count AND open-FD count hit zero — the Unix unlink-while-open trick). Journaling fixes crash consistency: multi-block updates (allocate block + update inode + update directory) can be half-done at power loss; the FS first writes an intent record to a journal, then applies it — recovery replays or discards whole entries, never leaving half-states. Same idea as a database WAL, one layer down.

The full picture

  • Name resolution: /var/log/app.log = walk root dir file → find 'var' inode → read that dir → 'log' → dir → 'app.log' inode — cached aggressively in the dentry cache (why first ls -R is slow, second is instant).
  • Unlink-while-open, the ops classic: delete a 50GB log the process still has open → df shows no space freed (inode alive via FD) but du can't see it. Find with lsof +L1; fix by truncating or bouncing the process. This feature is also how tmpfile security works.
  • Journal modes matter operationally: metadata-only journaling (ext4 default data=ordered) guarantees FS structure survives crashes — not your latest file contents; full-data journaling is safer and slower. Copy-on-write file systems (ZFS, btrfs) get atomicity differently — never overwrite in place, flip a root pointer.
  • The WAL isomorphism: journal = redo log; checkpoint = applying it; replay-on-mount = crash recovery. If you understand Postgres WAL or Kafka's log, you already understand ext4's journal — say so, it collapses the question.

🔄 Likely follow-up questions

  • Why can't hard links cross file systems or point to directories?
  • What's an extent vs block pointers, and why did ext4 switch?
  • How do inode exhaustion outages happen with millions of tiny files?