4.2.36 · D1Operating Systems

Foundations — Journaling — why, how it works

1,809 words8 min readBack to topic

This page assumes nothing. Before you read the main note, every word, symbol, and picture it leans on is built here from the ground up. Read top to bottom; each block earns the next.


0. What is a disk, physically?

Before we can talk about "writes" we need a picture of the thing being written to.

Look at the figure: the shelf is a row of little boxes with addresses (block 9, block 12, block 50…). "Writing block 50" means walking to box 50 and replacing its whole contents. Why this matters: the topic keeps saying "the inode block", "the bitmap block", "the data block" — those are just named boxes on this one shelf.


1. The atomic write — the ONE guarantee the hardware gives

Contrast to keep straight:

Atomic (guaranteed)
one sector — all-or-nothing, always.
Atomic (NOT guaranteed)
two or more writes happening "together" — the disk gives no such promise.

2. Filesystem structures — the boxes that get changed

A "create file" or "append" touches several named boxes. You must know each by sight.

In the figure, appending one block to notes.txt changes three of these at once: the data block (new bytes), the inode (bigger size + a pointer to the new block), and the bitmap (mark the new block used). Why the topic needs this: "one logical operation = many writes" is literally these three arrows firing separately. That is the crash-consistency problem in one picture. See File Systems for the fuller anatomy.


3. Inconsistency — what "corrupt" actually looks like

Two contradictions the main note names — now picture them:

  • Lost block (left): the bitmap says block 12 is used, but no inode points to it. The space is leaked — reserved forever for nobody. Caused by writing the bitmap but crashing before the inode.
  • Dangling pointer (right): a directory says "file → inode 9", but inode 9 was never written. Following it reads garbage — corruption. Caused by writing the directory before the inode.

The concept that a group of writes should be "all or nothing" has a name — Atomicity — and journaling is how a filesystem manufactures it.


4. The symbol — "must finish strictly before"

The main note writes the core rule as . This is not multiplication or a less-than on numbers.


5. The symbol — "exactly when, both directions"

The recovery rule uses ("if and only if").

Why the topic needs it: it turns a scary "did the crash break things?" into a mechanical yes/no lookup — the presence of one block.


6. Idempotent — "doing it twice = doing it once"


7. Durable vs consistent — the trap word

Two promises people constantly confuse.


8. Circular log — the shape of the journal


Prerequisite map

Disk = numbered boxes

Atomic single-sector write

FS structures: inode bitmap data dir

Inconsistency: lost block, dangling pointer

Symbol happens-before

Write-Ahead Logging rule

Commit block and iff recovery rule

Idempotent replay

Circular log

Consistent vs durable

Journaling topic 4.2.36

Read it as: the disk and its atomicity guarantee sit at the root; the structures create the problem (inconsistency); the happens-before symbol powers the rule (WAL); the commit block and idempotency make recovery correct — and all of it feeds the main journaling topic.


Equipment checklist

Test yourself — you're ready for the main note when each reveal matches your own words.

What single write does the disk guarantee is all-or-nothing?
A single-sector write — it ends up fully old or fully new, never smeared.
What is an inode, in one line?
An index card holding a file's facts (size) and pointers to its data blocks.
What does the bitmap store?
One bit per block: 1 = in use, 0 = free — a used/free map of the whole disk.
Give one concrete example of an inconsistent filesystem.
Lost block (bitmap says used, no inode points to it) or dangling pointer (directory points to an unwritten inode).
Read the symbol aloud and say what it demands.
"A happens-before B" — A must be durably on disk before B is allowed to start.
What does add over a one-way ?
Both directions: present ⇒ replay AND absent ⇒ discard, so every case is decided.
Define idempotent and why replay needs it.
Doing it twice = doing it once; recovery may re-copy blocks after a second crash, so repeats must be harmless.
Consistent vs durable — the difference in one line each?
Consistent = structures don't contradict; durable = a specific write is guaranteed on the platter.
Why is the journal a circular buffer and not endless?
It's a temporary intent log; checkpointed slots are freed and reused, keeping it small and recovery fast.