Lab 6: Crash-Consistent CRC32 Write-Ahead Log & KV Engine

90 minfree previewLinux 6.12C11glibc 2.39← module 6

Master kernel page-cache writeback barriers (fsync, fdatasync, directory sync), sector-aligned O_DIRECT DMA, user-space setvbuf/fflush/fdopen ownership rules, and synthesize a crash-safe CRC32 Write-Ahead Log storage engine.

Prerequisites in this module

What ./check.sh verifies

  • Clean C11 build with -std=c11 -Wall -Wextra -Werror and zero warnings.
  • Runtime behavior, exit status, and output match the automated ./check.sh assertions.
step 1/15

step 1/15 · inspect starter files and specification

Every production embedded database, OTA boot-state manager, and distributed consensus log (SQLite WAL, RocksDB, etcd, U-Boot redundant environment) confronts the same physical law: power can vanish mid-sector at any microsecond. Overwriting records in place destroys committed state, calling fclose(fp) without fflush(fp) + fdatasync(fileno(fp)) leaves acknowledged commits in volatile DRAM, and reading with stateful read() clobbers concurrent cursors. In this capstone project, you will synthesize all six modules of GL-C01 into durable_wal, a crash-consistent IEEE 802.3 CRC32 Write-Ahead Log and key-value engine.

learner@ksa: ~/gl-c01/lab-m06
learner@ksa:~/gl-c01/lab-m06ls -lastarter/durable_wal.clearner@ksa:~/gl-c01/lab-m06
starter: starter/durable_wal.c
learner@ksa: ~/gl-c01/lab-m06
learner@ksa:~/gl-c01/lab-m06$ bat starter/durable_wal.c File: starter/durable_wal.c    #define _POSIX_C_SOURCE 200809L    #include <fcntl.h>    #include <stdint.h>    #include <stdio.h>    #include <stdlib.h>    #include <string.h>    #include <sys/stat.h>    #include <unistd.h>        enum { WAL_MAGIC = 0x4B57414CU, KEY_CAP = 64, VAL_CAP = 256 };        struct wal_hdr {        uint32_t magic;        uint32_t crc32;        uint32_t key_len;        uint32_t val_len;    };        /*     * STARTER BASELINE (contains intentional durability & recovery bugs):     * 1. append leaves crc32 = 0 and omits fflush() + fdatasync() durability barrier.     * 2. recover never validates CRC32 or repairs torn tail frames with ftruncate().     * 3. get uses stateful read(), mutating f_pos and stopping on the first match.     */    int main(int argc, char **argv) {        if (argc < 3) return 2;            if (strcmp(argv[1], "append") == 0 && argc == 5) {            FILE *fp = fopen(argv[2], "ab");            if (!fp) return 1;            struct wal_hdr h = {WAL_MAGIC, 0U, (uint32_t)strlen(argv[3]), (uint32_t)strlen(argv[4])};            fwrite(&h, sizeof(h), 1, fp);            fwrite(argv[3], 1, h.key_len, fp);            fwrite(argv[4], 1, h.val_len, fp);            fclose(fp);            printf("COMMIT key=%s bytes=%u\n", argv[3], (unsigned)(sizeof(h) + h.key_len + h.val_len));            return 0;        }            if (strcmp(argv[1], "recover") == 0 && argc == 3) {            struct stat st;            if (stat(argv[2], &st) < 0) return 1;            printf("RECOVER valid_records=0 truncated_from=%lld to=%lld\n",                   (long long)st.st_size, (long long)st.st_size);            return 0;        }            if (strcmp(argv[1], "get") == 0 && argc == 4) {            int fd = open(argv[2], O_RDONLY);            if (fd < 0) return 1;            struct wal_hdr h;            char k[KEY_CAP + 1];            char v[VAL_CAP + 1];            while (read(fd, &h, sizeof(h)) == (ssize_t)sizeof(h)) {                if (h.key_len > KEY_CAP || h.val_len > VAL_CAP) break;                if (read(fd, k, h.key_len) != (ssize_t)h.key_len) break;                if (read(fd, v, h.val_len) != (ssize_t)h.val_len) break;                k[h.key_len] = '\0';                v[h.val_len] = '\0';                if (strcmp(k, argv[3]) == 0) {                    off_t cur = lseek(fd, 0, SEEK_CUR);                    close(fd);                    printf("VALUE %s f_pos=%lld\n", v, (long long)cur);                    return 0;                }            }            close(fd);            printf("NOT_FOUND\n");            return 1;        }            return 2;    }

step 2/15 · 2. learning objectives

  1. Commit length-prefixed, IEEE 802.3 CRC32-protected binary frames via the complete two-stage durability barrier (fwrite -> fflush -> fdatasync(fileno(fp)) -> single-owner fclose, plus parent-directory fsync on initial creation).
  2. Recover crashed logs deterministically by scanning frames from offset 0 via stateless pread(), detecting torn headers, torn payloads, or single-bit CRC32 corruptions, and healing the file via ftruncate(fd, valid_offset) + fdatasync(fd).
  3. Serve log-structured latest-wins get queries via pread() while proving struct file.f_pos remains untouched at 0.

step 3/15 · 3. environment requirements

  • Host Execution Environment (Tested): Linux 6.12 LTS (x86_64, glibc 2.39+), #define _POSIX_C_SOURCE 200809L and #define _FILE_OFFSET_BITS 64.
  • Target Board Portability (ARMv7 Cortex-A7): The 16-byte struct wal_hdr (magic, crc32, key_len, val_len), branchless reflected 0xEDB88320U CRC32, and pread/ftruncate/fdatasync calls behave identically on embedded ARMv7 ext4/f2fs partitions (where fdatasync() flushes the eMMC controller cache).

step 4/15 · 4. required software & hardware

  • Software Toolchain: gcc (-std=c11 -Wall -Wextra -Werror), strace, dd / python3 (for fault-injection corruption tests), and /bin/sh.
  • Hardware: Standard Linux host environment (tmpfs or NVMe/SSD filesystem).

step 5/15 · 5. complete executable commands

Run from labs/lab_m06_durable_wal/:

learner@ksa: ~/gl-c01/lab-m06
learner@ksa:~/gl-c01/lab-m06$ bat script.sh File: script.sh    # 1. Compile the capstone WAL engine with strict C11 warning flags    gcc -std=c11 -O2 -Wall -Wextra -Werror files/durable_wal.c -o /tmp/durable_wal    rm -f /tmp/engine.wal        # 2. Commit three mutations (including an update to boot.mode) and verify latest-wins GET    /tmp/durable_wal append /tmp/engine.wal boot.mode primary    /tmp/durable_wal append /tmp/engine.wal vcore_mv 1200    /tmp/durable_wal append /tmp/engine.wal boot.mode fallback    /tmp/durable_wal get /tmp/engine.wal boot.mode        # 3. Inject a 9-byte torn power-loss tail and verify ftruncate() heals back to 95 bytes!    printf 'TORN_TAIL' >> /tmp/engine.wal    /tmp/durable_wal recover /tmp/engine.wal    /tmp/durable_wal get /tmp/engine.wal boot.mode        # 4. Trace exact fflush -> write -> fdatasync -> close syscall sequence on append    strace -e trace=openat,write,fdatasync,fsync,close /tmp/durable_wal append /tmp/engine.wal watchdog on        # 5. Clean up and run the full TAP 13 fault-injection suite    rm -f /tmp/durable_wal /tmp/engine.wal    sh check.sh

*Why each command runs:* Step 2 appends immutable frames (32 + 30 + 33 = 95 bytes) and verifies "boot.mode" resolves to "fallback" with f_pos=0; Step 3 simulates an interrupted write (104 bytes) and proves recover heals 104 -> 95 (valid_records=3); Step 4 proves fflush() issues write() before fdatasync() and fclose() closes fd once; and Step 5 executes all TAP 13 checks including mid-payload CRC32 bit-flip injection.

step 6/15 · 6. annotated source code (`starter/` flaws vs `files/` reference)

Flawed Baseline (starter/durable_wal.c)

  1. Zero durability & fake checksum (append): Writes crc32 = 0U, omits O_CLOEXEC, and omits fflush() + fdatasync() + parent directory fsync().
  2. No-op recover: Prints st.st_size without reading headers, recomputing CRC32, or calling ftruncate().
  3. Stateful first-match get: Uses read() (advancing f_pos to 32) and returns on the first matching key ("primary") instead of scanning to EOF for latest-wins ("fallback").

Warning-Clean Reference (files/durable_wal.c)

  • Branchless IEEE 802.3 CRC32 (crc32_update / compute_frame_crc): Computes uint32_t mask = -(crc & 1U); crc = (crc >> 1) ^ (0xEDB88320U & mask); over [key_len, val_len, key, val] (including lengths inside the checksum envelope!).
  • Two-Stage Commit + Dir Sync (cmd_append): Opens O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC (0644), transfers ownership to fdopen(fd, "wb"), runs fwrite -> fflush(fp) -> fdatasync(fileno(fp)) -> single fclose(fp), and calls sync_parent_dir(wal_path) when creating a brand-new WAL file.
  • Stateless Recovery & Lookup (cmd_recover, cmd_get): Uses pread_exact() from off = 0, validates WAL_MAGIC, bounds (1 <= key_len <= 64, val_len <= 256), full payload availability, and expect_crc == hdr.crc32, heals mismatches via ftruncate(fd, valid_off) + fdatasync(fd), and updates latest_val across all valid frames while lseek(fd, 0, SEEK_CUR) stays 0!

step 7/15 · 7. expected output

learner@ksa: ~/gl-c01/lab-m06
learner@ksa:~/gl-c01/lab-m06$ bat listing.txt File: listing.txt    $ ./durable_wal append engine.wal boot.mode primary && ./durable_wal append engine.wal boot.mode fallback && ./durable_wal get engine.wal boot.mode    COMMIT key=boot.mode bytes=32    COMMIT key=boot.mode bytes=33    VALUE fallback f_pos=0        $ sh check.sh    TAP version 13    1..5    ok 1 - builds with -std=c11 -Wall -Wextra and no warnings    ok 2 - flushes and fdatasyncs 3 CRC32-framed WAL commits (95 bytes)    ok 3 - scans WAL statelessly via pread leaving f_pos=0 with latest-wins semantics    ok 4 - truncates torn power-loss tail back to last valid frame boundary    ok 5 - detects CRC32 payload corruption, truncates bad frame, and keeps prior commits    # pass 5/5

step 8/15 · 8. explanation of observed behavior

Look at Test 5 inside check.sh: after three committed frames (95 bytes), a 4th 40-byte frame (135 bytes total) has 1 bit flipped inside its value payload. During recover, pread_exact() reads frames 1..3 (valid_off advances 0 -> 32 -> 62 -> 95); at valid_off = 95, compute_frame_crc() mismatches hdr.crc32, breaking out of the scan loop at valid_off = 95. ftruncate(fd, 95) + fdatasync(fd) then snips the corrupted 40-byte tail atomically on storage while all 3 earlier committed frames remain 100% intact!

step 9/15 · 9. experiment variations

  1. Single-Write Coalescing Optimization: Coalesce [hdr, key, val] into one stack uint8_t frame[16 + KEY_CAP + VAL_CAP] buffer before fwrite() (or use writev()), confirming under strace that fflush(fp) already coalesces the three fwrite() calls into one write() syscall thanks to _IOFBF!
  2. Header Length Bit-Flip Test: Flip 1 bit inside hdr.key_len (changing 5 to 37 within <= 64) on a 4th frame and verify that including key_len inside compute_frame_crc() catches the corruption even if 95 + 16 + 37 <= st_size.
  3. 256-entry CRC32 Lookup Table: Precompute a uint32_t crc_tab[256] table inside an __attribute__((constructor)) or static const array (1 table lookup per byte instead of 8 bit loops) and compare CPU throughput on 1 MiB payloads.

step 10/15 · 10. performance measurements

Measured on Host x86_64 Linux 6.12 LTS (CLOCK_MONOTONIC, 5 warmup runs, N = 35 paired append + get durable CLI commits):

MetricMeasured Host (x86_64 Linux 6.12)Target Board Expectation (ARMv7 Cortex-A7 Industrial eMMC)
Durable append + get (p50 / p95 / p99)3,346.2 us / 5,287.6 us / 5,400.4 us~14,000–24,000 us CLI (1.5–6.0 ms per hardware eMMC fdatasync barrier)
Syscalls per existing-WAL append1 openat + 1 write + 1 fdatasync + 1 closeIdentical 4-syscall commit path
Stateless get cursor mutation (f_pos)0 -> 0 (pread64 only)0 -> 0 (pread64 only)

step 11/15 · 11. troubleshooting

SymptomRoot CauseFix
EBADF or crashed fd in multithreaded testCalled close(fd) after fclose(fp) on fp = fdopen(fd, "wb")Let fclose(fp) close fd once; only close(fd) if fdopen() returned NULL
fdatasync runs while WAL file on disk is still 0 bytesCalled fdatasync(fileno(fp)) before fflush(fp)Always call fflush(fp) first, then fdatasync(fileno(fp))
get returns "primary" instead of "fallback"Returned immediately on first key match instead of scanning to EOFKeep updating latest_val until the scan reaches the end of valid frames
get prints f_pos=95 instead of f_pos=0Used stateful read()/fread() instead of pread()Read headers and payloads exclusively via pread_exact()

step 12/15 · 12. guided questions

  1. Why does cmd_append() check int existed = (stat(wal_path, &before_st) == 0); and call sync_parent_dir(wal_path) when !existed?
  • *Hint 1:* Does fdatasync(fileno(fp)) sync the parent directory's dentry table?
  • *Hint 2:* What happens on sudden power loss right after creating engine.wal if engine.wal's blocks are on NVMe media but the parent directory's new "engine.wal" -> st_ino entry was still in volatile DRAM?
  1. Why does cmd_append() combine O_APPEND on open() with fdopen(fd, "wb")?
  • *Hint 1:* When fflush(fp) drains the Ring 3 buffer via a single write(fd, buf, frame_len) syscall (frame_len <= 336 bytes), what lock does O_APPEND acquire inside Ring 0?
  • *Hint 2:* Why would two separate write() syscalls (header in write #1, payload in write #2) break multi-process O_APPEND atomicity without _IOFBF coalescing them into a single write()?

step 13/15 · 13. independent challenges

  1. Near Transfer — Monotonic 64-Bit Epoch Header & Tombstone Deletes (del <wal_path> <key>): Upgrade struct wal_hdr to 24 bytes by adding uint64_t seq (1, 2, ..., verified during recover to block stale recycled-segment frames as in m06-l03) and uint32_t tombstone (0xFFFFFFFFU val_len sentinel) so del removes keys cleanly without in-place mutation.
  2. Far Transfer — Crash-Safe WAL Compaction (compact <wal_path>): Implement atomic log compaction using directory-pinned openat(..., "wal.compact.tmp", O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW | O_CLOEXEC, 0644), writing only live non-deleted keys, committing via fflush + fdatasync + checked fclose, swapping via renameat(), and hardening via fsync(dir_fd).

step 14/15 · 14. solutions & explanations

  • Guided Question 1: fdatasync(fd) only persists fd's own data blocks and size metadata; syncing the parent directory (fsync(dfd)) on initial creation commits the directory entry so the newly created WAL file cannot vanish across power loss.
  • Guided Question 2: Because _IOFBF coalesces the 16-byte header, <= 64-byte key, and <= 256-byte value (<= 336 bytes << BUFSIZ) into one write() syscall inside fflush(fp), O_APPEND positions ki_pos = i_size and copies the entire frame atomically under inode->i_rwsem!

step 15/15 · run verification and inspect output

Run the verification command and confirm the output matches the expected contract.

learner@ksa: ~/gl-c01/lab-m06
learner@ksa:~/gl-c01/lab-m06./durable_wal append engine.wal boot.mode primary && ./durable_wal append engine.wal boot.mode fallback && ./durable_wal get engine.wal boot.modelearner@ksa:~/gl-c01/lab-m06
expected output
COMMIT key=boot.mode bytes=32COMMIT key=boot.mode bytes=33VALUE fallback f_pos=0

Progressive hints & solution

hint 1

Compare starter/durable_wal.c against the module lessons. Focus first on: Clean C11 build with -std=c11 -Wall -Wextra -Werror and zero warnings.

hint 2

Compile with -std=c11 -Wall -Wextra -Werror, check every system-call return value before touching output buffers, and verify cleanup on error paths.

solution

Run the check

From labs/lab_m06_durable_wal/, run ./check.sh. A complete solution emits TAP version 13 with every test point marked ok and exits 0:

./check.sh — lab m06
learner@ksa:~/gl-c01/lab-m06./check.shTAP version 131..5ok 1 - builds with -std=c11 -Wall -Wextra and no warningsok 2 - flushes and fdatasyncs 3 CRC32-framed WAL commits (95 bytes)ok 3 - scans WAL statelessly via pread leaving f_pos=0 with latest-wins semanticsok 4 - truncates torn power-loss tail back to last valid frame boundaryok 5 - detects CRC32 payload corruption, truncates bad frame, and keeps prior commits# pass 5/5

On an incomplete starter tree, ./check.sh exits non-zero and marks the unmet assertion not ok with an indented YAML diagnostic block:

./check.sh — lab m06 (starter)
learner@ksa:~/gl-c01/lab-m06./check.shTAP version 131..5ok 1 - builds with -std=c11 -Wall -Wextra and no warningsok 2 - flushes and fdatasyncs 3 CRC32-framed WAL commits (95 bytes)not ok 3 - scans WAL statelessly via pread leaving f_pos=0 with latest-wins semantics  ---  message: 'get returned VALUE primary f_pos=32 , expected VALUE fallback f_pos=0'  hint: 'scan records with pread() so f_pos stays 0 and keep updating match until EOF'  ...not ok 4 - truncates torn power-loss tail back to last valid frame boundary  ---  message: 'recover= RECOVER valid_records=0 truncated_from=104 to=104 after_bytes=104 (expected 95)'  hint: 'ftruncate(fd, last_valid_offset) and fdatasync(fd) when a trailing header or payload is incomplete'  ...not ok 5 - detects CRC32 payload corruption, truncates bad frame, and keeps prior commits  ---  message: 'recover= RECOVER valid_records=0 truncated_from=135 to=135 after=135 survive= VALUE 30 f_pos=62'  hint: 'recompute CRC32 over key+value bytes and ftruncate() at the corrupt frame offset'  ...# pass 2/5

note: How to read TAP diagnostics: 1..N states the total test plan; each ok k confirms a passed check; not ok k pinpoints the failing check alongside message: (what went wrong) and hint: (where to look next) between --- and ....

inspect harness: check.sh
learner@ksa: ~/gl-c01/lab-m06
learner@ksa:~/gl-c01/lab-m06$ bat check.sh File: check.sh    #!/bin/sh    set -u        PASS=0    TOTAL=5        tap_ok() {        PASS=$((PASS + 1))        printf 'ok %s - %s\n' "$1" "$2"    }        tap_not_ok() {        msg=$(printf '%s' "$3" | tr "\n\r'" "   " | sed "s/  */ /g; s/^ //; s/ \$//")        hnt=$(printf '%s' "$4" | tr "\n\r'" "   " | sed "s/  */ /g; s/^ //; s/ \$//")        printf 'not ok %s - %s\n' "$1" "$2"        printf '  ---\n'        printf "  message: '%s'\n" "$msg"        printf "  hint: '%s'\n" "$hnt"        printf '  ...\n'    }        printf 'TAP version 13\n'    printf '1..%s\n' "$TOTAL"        WORK="$(mktemp -d "${TMPDIR:-/tmp}/ksa_lab_m06.XXXXXX")"    trap 'rm -rf "$WORK"' EXIT        BUILT=0    if [ ! -f files/durable_wal.c ]; then        tap_not_ok 1 "builds with -std=c11 -Wall -Wextra and no warnings" \            "missing files/durable_wal.c" \            "place your implementation in files/durable_wal.c"    elif gcc -std=c11 -Wall -Wextra -Werror files/durable_wal.c -o "$WORK/durable_wal" 2>"$WORK/gcc.err"; then        BUILT=1        tap_ok 1 "builds with -std=c11 -Wall -Wextra and no warnings"    else        tap_not_ok 1 "builds with -std=c11 -Wall -Wextra and no warnings" \            "gcc failed: $(cat "$WORK/gcc.err")" \            "fix all C11 warnings and errors in files/durable_wal.c"    fi        WAL="$WORK/engine.wal"    C1=""    C3=""    CLEAN_BYTES=0    if [ "$BUILT" -eq 1 ]; then        C1="$(timeout 3 "$WORK/durable_wal" append "$WAL" "boot.mode" "primary" 2>/dev/null || true)"        timeout 3 "$WORK/durable_wal" append "$WAL" "watchdog.sec" "30" >/dev/null 2>&1 || true        C3="$(timeout 3 "$WORK/durable_wal" append "$WAL" "boot.mode" "fallback" 2>/dev/null || true)"        [ -f "$WAL" ] && CLEAN_BYTES="$(wc -c < "$WAL" | tr -d ' ')"    fi        if [ "$C1" = "COMMIT key=boot.mode bytes=32" ] && [ "$C3" = "COMMIT key=boot.mode bytes=33" ] && [ "$CLEAN_BYTES" = "95" ]; then        tap_ok 2 "flushes and fdatasyncs 3 CRC32-framed WAL commits (95 bytes)"    else        tap_not_ok 2 "flushes and fdatasyncs 3 CRC32-framed WAL commits (95 bytes)" \            "c1='${C1:-empty}' c3='${C3:-empty}' wal_bytes=${CLEAN_BYTES} (expected 95)" \            "call fflush(fp) before fdatasync(fileno(fp)) so user-space stdio buffers reach the kernel"    fi        G_LATEST=""    if [ "$BUILT" -eq 1 ] && [ -f "$WAL" ]; then        G_LATEST="$(timeout 3 "$WORK/durable_wal" get "$WAL" "boot.mode" 2>/dev/null || true)"    fi    if [ "$G_LATEST" = "VALUE fallback f_pos=0" ]; then        tap_ok 3 "scans WAL statelessly via pread leaving f_pos=0 with latest-wins semantics"    else        tap_not_ok 3 "scans WAL statelessly via pread leaving f_pos=0 with latest-wins semantics" \            "get returned '${G_LATEST:-empty}', expected 'VALUE fallback f_pos=0'" \            "scan records with pread() so f_pos stays 0 and keep updating match until EOF"    fi        REC_TORN=""    AFTER_TORN=0    TORN_BYTES=0    if [ "$BUILT" -eq 1 ] && [ -f "$WAL" ]; then        printf 'TORN_TAIL' >> "$WAL"        TORN_BYTES="$(wc -c < "$WAL" | tr -d ' ')"        REC_TORN="$(timeout 3 "$WORK/durable_wal" recover "$WAL" 2>/dev/null || true)"        AFTER_TORN="$(wc -c < "$WAL" | tr -d ' ')"    fi    if [ "$TORN_BYTES" -gt 0 ] && [ "$REC_TORN" = "RECOVER valid_records=3 truncated_from=${TORN_BYTES} to=95" ] && [ "$AFTER_TORN" = "95" ]; then        tap_ok 4 "truncates torn power-loss tail back to last valid frame boundary"    else        tap_not_ok 4 "truncates torn power-loss tail back to last valid frame boundary" \            "recover='${REC_TORN:-empty}' after_bytes=${AFTER_TORN} (expected 95)" \            "ftruncate(fd, last_valid_offset) and fdatasync(fd) when a trailing header or payload is incomplete"    fi        REC_CRC=""    AFTER_CRC=0    CORR_SIZE=0    G_SURVIVE=""    CORR_GONE=0    if [ "$BUILT" -eq 1 ] && [ -f "$WAL" ]; then        timeout 3 "$WORK/durable_wal" append "$WAL" "psu.rail" "12000mV" >/dev/null 2>&1 || true        CORR_SIZE="$(wc -c < "$WAL" | tr -d ' ')"        if [ "$CORR_SIZE" -gt 95 ]; then            printf 'X' | dd of="$WAL" bs=1 seek=$((CORR_SIZE - 1)) conv=notrunc status=none 2>/dev/null || true        fi        REC_CRC="$(timeout 3 "$WORK/durable_wal" recover "$WAL" 2>/dev/null || true)"        AFTER_CRC="$(wc -c < "$WAL" | tr -d ' ')"        if ! timeout 3 "$WORK/durable_wal" get "$WAL" "psu.rail" >/dev/null 2>&1; then            CORR_GONE=1        fi        G_SURVIVE="$(timeout 3 "$WORK/durable_wal" get "$WAL" "watchdog.sec" 2>/dev/null || true)"    fi        if [ "$CORR_SIZE" -gt 95 ] && [ "$REC_CRC" = "RECOVER valid_records=3 truncated_from=${CORR_SIZE} to=95" ] && [ "$AFTER_CRC" = "95" ] && [ "$CORR_GONE" -eq 1 ] && [ "$G_SURVIVE" = "VALUE 30 f_pos=0" ]; then        tap_ok 5 "detects CRC32 payload corruption, truncates bad frame, and keeps prior commits"    else        tap_not_ok 5 "detects CRC32 payload corruption, truncates bad frame, and keeps prior commits" \            "recover='${REC_CRC:-empty}' after=${AFTER_CRC} survive='${G_SURVIVE:-empty}'" \            "recompute CRC32 over key+value bytes and ftruncate() at the corrupt frame offset"    fi        printf '# pass %s/%s\n' "$PASS" "$TOTAL"    [ "$PASS" -eq "$TOTAL" ]

Definition of done

Verification checklist

status: 0/3 checks verified

Troubleshooting

Compiler fails under -Werror on sign conversion or unused args

Use exact POSIX return types (ssize_t for read()/write(), size_t for byte counts) rather than relaxing flags.

./check.sh reports missing files in files/

Invoke ./check.sh from inside labs/lab_m06_durable_wal/ so relative paths to files/ resolve directly.

Progress is saved on this device.

search — fzf

0/0 ───────────────────────────────────────────

keyboard shortcuts — less

/
search
f
focus mode
[
previous
]
next
?
help
Esc
close

figure