#!/usr/bin/env python3 """Run pinned Linux ATA-to-sense routines on invented inputs, without hardware. Usage: python3 reproduce.py > results.json Requires Python 3, cc and raw.githubusercontent.com access. GPL-2.0-only upstream C is downloaded to temporary storage, not redistributed. This is not a kernel boot, recovery simulation, incident sample or failure rate. """ import hashlib import json import platform import re import subprocess import tempfile from datetime import datetime, timezone from pathlib import Path from urllib.request import urlopen REVISIONS = [ ("v6.12", "adc218676eef25575469234709c2d87185ca223a"), ("2026-10-10 reference", "3857c2fe5449541e24afc5efdb0f81a8a8f9a3a0"), ] CASES = [ ("UNC", 0x41, 0x40, "03/11/04", "03/11/04"), ("ICRC with ABRT", 0x41, 0x84, "0b/47/00", "0b/47/00"), ("AMNF", 0x41, 0x01, "03/13/00", "03/13/00"), ("IDNF", 0x41, 0x10, "05/21/00", "05/21/00"), ("Device fault", 0x20, 0x00, "04/44/00", "04/44/00"), ("Busy; error ignored", 0x80, 0x40, "0b/47/00", "0b/00/00"), ("DRQ status only", 0x08, 0x00, "0b/47/00", "0b/00/00"), ("UNC plus ICRC/ABRT", 0x41, 0xC4, "0b/47/00", "0b/47/00"), ("Earlier composite-mask match", 0x41, 0xD4, "0b/00/00", "0b/00/00"), ("ABRT with DRDY/ERR", 0x41, 0x04, "05/21/04", "0b/00/00"), ] PATHS = ["drivers/ata/libata-scsi.c", "drivers/ata/libata-eh.c", "include/scsi/scsi_proto.h", "include/linux/ata.h"] def sha(data): return hashlib.sha256(data).hexdigest() def constants(proto, ata): lines = [] for name in ["RECOVERED_ERROR", "NOT_READY", "MEDIUM_ERROR", "HARDWARE_ERROR", "ILLEGAL_REQUEST", "UNIT_ATTENTION", "ABORTED_COMMAND"]: match = re.search(r"^#define\s+" + name + r"\s+(0x[0-9a-fA-F]+)\s*$", proto, re.MULTILINE) if not match: raise ValueError(name) lines.append("#define " + name + " " + match[1]) for name in ["ATA_BUSY", "ATA_DF", "ATA_CORR"]: match = re.search(r"^\s*" + name + r"\s*=\s*(\(1\s*<<\s*[0-9]+\)),", ata, re.MULTILINE) if not match: raise ValueError(name) lines.append("#define " + name + " " + match[1]) return "\n".join(lines) def main(): report = { "schemaVersion": 1, "generatedAt": datetime.now(timezone.utc).isoformat(), "method": "Compile unchanged ata_to_sense_error at two pinned revisions; execute ten invented byte-pair inputs per revision.", "limits": "Userspace source-function check, not a recovery simulation, hardware test, incident sample or failure probability.", "scriptSha256": sha(Path(__file__).read_bytes()), "python": platform.python_version(), "compiler": subprocess.check_output(["cc", "--version"], text=True).splitlines()[0], "revisions": [], } with tempfile.TemporaryDirectory(prefix="hesela-libata-") as directory: work = Path(directory) for index, (label, commit) in enumerate(REVISIONS): sources, provenance = {}, [] for path in PATHS: url = "https://raw.githubusercontent.com/torvalds/linux/" + commit + "/" + path with urlopen(url, timeout=30) as response: data = response.read() sources[path] = data.decode() provenance.append({"path": path, "url": url, "sha256": sha(data)}) text = sources[PATHS[0]] # Exact top-level function boundaries for these pinned files only. start = text.index("static void ata_to_sense_error(") routine = text[start:text.index("\n}\n", start) + 3] rows = ",".join("{%d,%d}" % (c[1], c[2]) for c in CASES) harness = ( "#include \ntypedef unsigned char u8;\n" + constants(sources[PATHS[2]], sources[PATHS[3]]) + "\n" + routine + "\nint main(void) {\nu8 cases[][2] = {" + rows + "};\n" + "for (unsigned i=0; i