◐ Off-By-One · answer catalog

shell-overlayfs-whiteout-opaque-xattr-merged-view-exactness

1 answer(s)shellbash

shell-overlayfs-whiteout-opaque-xattr-merged-view-exactness

📦 Source in repository (JSON)

Answer

The solution is complete and verified. Here's a summary of what I produced.

Deliverables (in ~/)

File Purpose
SOLUTION.md Self-contained writeup: problem, root-cause analysis, full code, verification
overlay_resolve.sh Pure-Bash 5.2+ overlayfs merged-view resolver
run_tests.sh 61 exact-line assertions across 11 scenarios (A–K)
ref_overlay.py + fuzz_compare.py Independent Python model + differential fuzzer

Root causes identified

The task cannot be solved by resolving each path in the union of layer paths. The actual failure modes:

  1. Redirects synthesize paths present in no layer (/redir/child from redirect=/target) — a tree walk is required, not union resolution.
  2. Redirect override applied at the wrong level — P→R must replace the whole child path for lower layers, not be concatenated as R/name.
  3. Lower non-directory stealing the win from a higher directory — only the first (topmost) match may set the winner.
  4. Whiteout below a surviving directory cuts layers but must not delete the directory.
  5. Opaque hides descendants, which still must be reported hidden; the opaque layer's own entries stay visible, and a lower entry whose logical path is won by a higher layer must not be double-reported.
  6. Redirect chains + whiteouts require carrying a per-layer real path and updating it on each redirect.
  7. Root opacity/redirect off-by-ones, relative redirects, and 0:0 whiteout spelling.

Approach

For each logical directory, carry an effective stack (layer, realpath) and a shadow/cut stack (layer, realpath, cause). descend() resolves one component top-down; walk() recurses the merged tree, hiding shadow subtrees and filtering visible paths out of the hidden set.

Verification

$ bash run_tests.sh
61 passed, 0 failed

$ python3 fuzz_compare.py
all 5000 random cases match exactly (merged, hidden causes, redirects)

The embedded scripts in SOLUTION.md were extracted and re-run to confirm they are byte-identical to the tested versions.

Evidence & signatures

# Evidence
- Problem class: shell-overlayfs-whiteout-opaque-xattr-merged-view-exactness
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-10-01T04:35:12.134Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Implement overlayfs merged-view resolution in pure Bash: given several lower layers plus one upper layer, each supplied as metadata lines describing entries and their xattrs, compute the exact merged directory view honoring whiteout entries (char device 0:0), opaque directory xattrs (trusted.overlay.opaque=y) that hide every lower entry beneath them, and redirect xattrs (trusted.overlay.redirect) that relocate an entry's contents. Emit the winning layer for every path, the hidden and redirected path sets, and the removal semantics when a lower entry is whiteouted while an ancestor directory is also opaque, including the overlapping-redirect chain case where one layer redirects to a path that another layer also redirects or whiteouts.", "environment": "bash", "language": "shell", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "shell-overlayfs-whiteout-opaque-xattr-merged-view-exactness", "provider": "openrouter", "solved_at": "2026-10-01T04:35:12.134Z", "version": "5.2"}
Generated from the verified corpus · MIT licensedBack to the catalog