From 71d183545b2779b5f2c3f896d243dbf8d2c276f7 Mon Sep 17 00:00:00 2001 From: Garret Buell Date: Sat, 14 Nov 2026 09:11:56 -0800 Subject: [PATCH] heliopause: open Windows direct writers without FILE_APPEND_DATA Core export on Windows fails when Heliopause writes a payload through its direct (unbuffered) path. direct_reopen reopens the output file with ReOpenFile, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, and FILE_GENERIC_WRITE access. FILE_GENERIC_WRITE includes FILE_APPEND_DATA, and the unbuffered reopen fails with ERROR_INVALID_PARAMETER (os error 87) whenever the requested access includes it. The direct writer issues writes at explicit offsets and never appends, so it does not need append access. Direct writers now request FILE_GENERIC_WRITE without FILE_APPEND_DATA. Read reopens keep FILE_GENERIC_READ. Sharing flags, the unbuffered and overlapped flags, and the alignment the writer applies are unchanged. Expected result: export::io's direct-write tests pass on Windows, and core exports on Windows write their payloads through the unbuffered path instead of failing. Evidence, on Windows 11 build 26200 with an NTFS volume, Rust 1.100.0 and MSVC: - ReOpenFile with FILE_FLAG_NO_BUFFERING fails with error 87 for FILE_GENERIC_WRITE and for FILE_GENERIC_READ | FILE_GENERIC_WRITE, for handles originally opened read-only or read-write; it succeeds for the same masks with FILE_APPEND_DATA cleared and for FILE_GENERIC_READ. - `cargo test --release --manifest-path heliopause/Cargo.toml --lib --no-default-features export::io::tests`: with the preceding Helios import fix alone, five tests that write through the direct path fail with os error 87 (direct_tail_reads_and_writes_preserve_exact_length, one_buffer_without_scratch_transfers_exact_unaligned_tails, writes_progress_while_producer_fills_subsequent_block, unaligned_bulk_uses_reserved_direct_scratch_with_one_output_slot, unaligned_destination_preserves_neighbors_and_existing_extent); with this change all ten export::io tests pass. - The full heliopause library suite passes with this change except export::core::payload_export_tests::sync_parent_normalizes_a_relative_basename, which fails with "open export parent: Access is denied. (os error 5)" with and without this change. - A 15.5 GiB core exported through export_capture on Windows wrote its payload through this path and replays bit-identically to the exporting process. That export ran on an RTX 3090 (SM86, not a supported GPU) with local platform patches; no export on a supported GPU under Windows was run. Design-Signed-Off-By: Claude Opus 5.5 (Claude Code); design-review=ed22 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Garret Buell --- heliopause/src/export/io.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/heliopause/src/export/io.rs b/heliopause/src/export/io.rs index 20bf3631a..f39d25ff7 100644 --- a/heliopause/src/export/io.rs +++ b/heliopause/src/export/io.rs @@ -780,8 +780,10 @@ fn direct_reopen(file: &File, write: bool) -> Result { fn direct_reopen(file: &File, write: bool) -> Result { use std::os::windows::io::{AsRawHandle, FromRawHandle}; use windows_sys::Win32::{Foundation::INVALID_HANDLE_VALUE, Storage::FileSystem::*}; + // An unbuffered reopen whose access includes FILE_APPEND_DATA fails with ERROR_INVALID_PARAMETER + // (Windows 11, NTFS). Direct writes address explicit offsets and never append. let access = if write { - FILE_GENERIC_WRITE + FILE_GENERIC_WRITE & !FILE_APPEND_DATA } else { FILE_GENERIC_READ };