diff --git a/crates/platform/tablecraft-io/src/publication/windows.rs b/crates/platform/tablecraft-io/src/publication/windows.rs index d0a170b47..b6afa73d0 100644 --- a/crates/platform/tablecraft-io/src/publication/windows.rs +++ b/crates/platform/tablecraft-io/src/publication/windows.rs @@ -10,7 +10,7 @@ use std::io::ErrorKind; use std::mem::size_of; use std::path::Path; use tablecraft_core::limits::{Resource, ResourceBudget}; -use windows_sys::Win32::Storage::FileSystem::FILE_RENAME_INFO; +use windows_sys::Wdk::Storage::FileSystem::FILE_RENAME_INFORMATION; const MAX_COMPONENT_UNITS: usize = filesystem::MAX_COMPONENT_UNITS; const RANDOM_BYTES: usize = 16; @@ -86,7 +86,7 @@ impl Backend for Windows { fn terminal_work(&self) -> u64 { // Fixed rename-buffer initialization plus bounded UTF-16 copy. Reserve // this before publication, when caller cancellation/budgets still apply. - (size_of::() + MAX_COMPONENT_UNITS * size_of::()) as u64 + (size_of::() + MAX_COMPONENT_UNITS * size_of::()) as u64 + self.final_name.len() as u64 } diff --git a/crates/platform/tablecraft-io/src/windows_fs.rs b/crates/platform/tablecraft-io/src/windows_fs.rs index 3f0f31f4b..86f48d927 100644 --- a/crates/platform/tablecraft-io/src/windows_fs.rs +++ b/crates/platform/tablecraft-io/src/windows_fs.rs @@ -10,8 +10,9 @@ use std::os::windows::io::{AsRawHandle, FromRawHandle}; use std::ptr::{null, null_mut}; use windows_sys::Wdk::Foundation::OBJECT_ATTRIBUTES; use windows_sys::Wdk::Storage::FileSystem::{ - FILE_CREATE, FILE_NON_DIRECTORY_FILE, FILE_OPEN_REPARSE_POINT, FILE_SYNCHRONOUS_IO_NONALERT, - FILE_WRITE_THROUGH, FileFsDeviceInformation, NtCreateFile, NtQueryVolumeInformationFile, + FILE_CREATE, FILE_NON_DIRECTORY_FILE, FILE_OPEN_REPARSE_POINT, FILE_RENAME_INFORMATION, + FILE_SYNCHRONOUS_IO_NONALERT, FILE_WRITE_THROUGH, FileFsDeviceInformation, + FileRenameInformation, NtCreateFile, NtQueryVolumeInformationFile, NtSetInformationFile, }; use windows_sys::Wdk::System::SystemServices::FILE_FS_DEVICE_INFORMATION; use windows_sys::Win32::Foundation::{ @@ -22,10 +23,10 @@ use windows_sys::Win32::Storage::FileSystem::{ CreateFileW, DELETE, FILE_ADD_FILE, FILE_ATTRIBUTE_DIRECTORY, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_REPARSE_POINT, FILE_ATTRIBUTE_TAG_INFO, FILE_DISPOSITION_INFO, FILE_FLAG_BACKUP_SEMANTICS, FILE_FLAG_OPEN_REPARSE_POINT, FILE_ID_INFO, - FILE_INFO_BY_HANDLE_CLASS, FILE_LIST_DIRECTORY, FILE_READ_ATTRIBUTES, FILE_RENAME_INFO, - FILE_SHARE_READ, FILE_SHARE_WRITE, FILE_TRAVERSE, FileAttributeTagInfo, FileDispositionInfo, - FileIdInfo, FileRenameInfo, GetFileInformationByHandleEx, GetVolumeInformationByHandleW, - OPEN_EXISTING, SYNCHRONIZE, SetFileInformationByHandle, + FILE_INFO_BY_HANDLE_CLASS, FILE_LIST_DIRECTORY, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, + FILE_SHARE_WRITE, FILE_TRAVERSE, FileAttributeTagInfo, FileDispositionInfo, FileIdInfo, + GetFileInformationByHandleEx, GetVolumeInformationByHandleW, OPEN_EXISTING, SYNCHRONIZE, + SetFileInformationByHandle, }; use windows_sys::Win32::System::IO::IO_STATUS_BLOCK; @@ -320,22 +321,31 @@ fn relative_file( /// Rename through the retained file into a retained parent without replacement. /// The caller supplies a prevalidated ordinary component and handles uncertain /// visibility on failure; success alone is not a terminal durability barrier. +/// +/// The native rename class resolves the name relative to RootDirectory. +/// SetFileInformationByHandle refuses a non-null RootDirectory with +/// ERROR_INVALID_PARAMETER, so it cannot express this descriptor-relative rename. pub(crate) fn rename_no_replace(file: &File, parent: &File, name: &[u16]) -> Result<(), IoError> { if name.is_empty() || name.len() > MAX_COMPONENT_UNITS { return Err(invalid()); } - // Fixed maximum buffer retains FILE_RENAME_INFO alignment and avoids + + // Fixed maximum buffer retains FILE_RENAME_INFORMATION alignment and avoids // any allocation beyond the visibility boundary. Only initialized bytes // through the supplied UTF-16 name are passed to Windows. let mut storage = [0usize; - (size_of::() + MAX_COMPONENT_UNITS * size_of::()) + (size_of::() + MAX_COMPONENT_UNITS * size_of::()) .div_ceil(size_of::())]; - let header = storage.as_mut_ptr().cast::(); + let header = storage.as_mut_ptr().cast::(); + let name_offset = offset_of!(FILE_RENAME_INFORMATION, FileName); let name_bytes = size_of_val(name); - let length = offset_of!(FILE_RENAME_INFO, FileName) + name_bytes; + let length = name_offset + name_bytes; + let mut status = IO_STATUS_BLOCK::default(); + // SAFETY: storage is sufficiently sized/aligned for header plus bounded - // name. RootDirectory remains alive and ReplaceIfExists stays false. - let success = unsafe { + // name. RootDirectory remains alive and ReplaceIfExists stays false. The + // file handle is synchronous, so status and storage outlive the call. + let result = unsafe { (*header).Anonymous.ReplaceIfExists = false; (*header).RootDirectory = handle(parent); (*header).FileNameLength = name_bytes as u32; @@ -344,14 +354,20 @@ pub(crate) fn rename_no_replace(file: &File, parent: &File, name: &[u16]) -> Res storage .as_mut_ptr() .cast::() - .add(offset_of!(FILE_RENAME_INFO, FileName)) + .add(name_offset) .cast::(), name.len(), ); - SetFileInformationByHandle(handle(file), FileRenameInfo, header.cast(), length as u32) + NtSetInformationFile( + handle(file), + &mut status, + header.cast(), + length as u32, + FileRenameInformation, + ) }; - if success == 0 { - return Err(last_error()); + if result < 0 { + return Err(nt_error(result)); } Ok(()) } diff --git a/docs/development/DEPENDENCIES.md b/docs/development/DEPENDENCIES.md index d598b14cb..3c837aae4 100644 --- a/docs/development/DEPENDENCIES.md +++ b/docs/development/DEPENDENCIES.md @@ -1915,7 +1915,7 @@ disabled. Its target-local WDK Foundation/Storage FileSystem and Win32 Foundation/Security/Storage FileSystem/System IO/System Threading features expose the working handle-relative local-NTFS publisher: exclusive `NtCreateFile` staging, file/device identity and filesystem qualification, -no-replacement `FILE_RENAME_INFO`, owned temporary disposition and retained-handle +no-replacement `FILE_RENAME_INFORMATION`, owned temporary disposition and retained-handle flushes. The existing `windows-link` dependency supplies import linkage. Neither a new registry version nor a GUI/network runtime is introduced into IO or the CLI. Existing getrandom supplies the Windows staging name as well. diff --git a/docs/foundation/IO.md b/docs/foundation/IO.md index 2484f6308..6847f54c2 100644 --- a/docs/foundation/IO.md +++ b/docs/foundation/IO.md @@ -245,13 +245,15 @@ parent actually captured, not a later interpretation of its path. A random staging file is created exclusively relative to that parent through `NtCreateFile`, with synchronous write-through I/O and no sharing. The retained file is written and flushed, then renamed through the same handle using -`SetFileInformationByHandle(FileRenameInfo)`, a parent-relative final name and +`NtSetInformationFile(FileRenameInformation)`, a parent-relative final name and replacement disabled. A known successful rename consumes the temporary name; cleanup never deletes that final file. The terminal operation flushes the retained renamed file. A collision refuses without replacing the existing output; other unresolved rename failures retain the visibility-uncertain outcome. -[FILE_RENAME_INFO](https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-file_rename_info) -documents parent-relative names and no-replacement behavior. +[FILE_RENAME_INFORMATION](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_rename_information) +documents the RootDirectory-relative name and no-replacement behavior. The Win32 +`SetFileInformationByHandle(FileRenameInfo)` wrapper refuses a non-null +RootDirectory with `ERROR_INVALID_PARAMETER`, so it cannot express this rename. The receipt exposes `PublicationGuarantee`: Unix returns `CapturedParentBarrier`; the Windows route returns `NtfsWriteThroughRename`. @@ -349,7 +351,7 @@ rename with failed flush permits one explicit held-file barrier retry. Retired confirmation verifies identities and flushes without renaming or replaying a native edit. Known native completion survives every namespace failure. This is `RetirementGuarantee::NtfsWriteThroughRename`, not a fabricated Unix directory -barrier. See [FILE_RENAME_INFO](https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-file_rename_info) +barrier. See [FILE_RENAME_INFORMATION](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_rename_information) and [write-through metadata behavior](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#caching-behavior). Windows uses `RetiredCleanupPolicy::RetainIntact`. Successful strict