a copy-on-write filesystem
/ ZFS = zee-eff-ess; Btrfs = BUT-ter-eff-ess /
Most older filesystems update a file by overwriting its blocks in place: to change a block, you write new bytes on top of the old ones at the same disk location. That is efficient but dangerous - if power dies mid-overwrite you can end up with neither the old block nor a complete new one, a torn block. A copy-on-write filesystem refuses to overwrite live data at all. To change anything, it writes the new version to a fresh, unused location and only then flips a pointer to make the new version official. The old data is left untouched until it is no longer referenced.
Walk through editing one block of a file in a CoW filesystem like ZFS or Btrfs. The data is reachable through a tree of pointers from a root. To modify a leaf block, the filesystem (1) writes the changed block to a new free location, (2) writes a new copy of its parent pointer block pointing at the new leaf, and so on up to a new root - this is called writing up the tree. (3) Finally it atomically updates the single superblock pointer to the new root. Until that last flip, the entire old tree is still valid and consistent; after it, the new tree is. There is no in-place edit at any level, so a crash simply leaves the old consistent tree intact. These filesystems also checksum every block and store the checksum in the parent pointer, so corruption (a flipped bit, a misdirected write) is detected on read and, with redundancy, self-healed from a good copy.
Why it matters: copy-on-write gives crash consistency almost for free (the old state is never destroyed until the new one is complete) and makes snapshots nearly instant - a snapshot is just keeping the old root pointer around, sharing all unchanged blocks. The honest trade-offs: writes amplify (changing one block can dirty a chain of parent blocks up to the root), free space can fragment because new versions land wherever there is room, and reasoning about free space is harder because a block cannot be reused while any snapshot still references it.
edit one leaf block in a CoW tree: old: root -> ... -> parent -> leaf(v1) write leaf(v2) to a NEW block, write parent' -> leaf(v2), ... new root' atomically: superblock pointer = root' <- old tree stays valid until this flip
Never overwrite in place: write the new version elsewhere and atomically flip the root pointer.
Copy-on-write trades write amplification and harder free-space accounting for crash safety and cheap snapshots. A common myth is that CoW makes fsync() unnecessary - it does not; you still must flush to disk to know your data is durable. CoW guarantees the on-disk tree is always consistent, not that your unflushed writes reached it.