Skip to content

Small fixes in FileSystemEnumerator for Windows.#126544

Open
teo-tsirpanis wants to merge 4 commits intodotnet:mainfrom
teo-tsirpanis:copilot/update-filesystem-enumerator-edits
Open

Small fixes in FileSystemEnumerator for Windows.#126544
teo-tsirpanis wants to merge 4 commits intodotnet:mainfrom
teo-tsirpanis:copilot/update-filesystem-enumerator-edits

Conversation

@teo-tsirpanis
Copy link
Copy Markdown
Contributor

Note

This PR was created with the assistance of GitHub Copilot.

  • Replaced ineffective use of default(DisableMediaInsertionPrompt), with DisableMediaInsertionPrompt.Create().
    • No other similar cases were found.
  • The _buffer was updated to be backed by NativeMemory.AlignedAlloc instead of Marshal.AllocHGlobal. This makes the alignment requirement explicit and might increase performance.

Copilot AI review requested due to automatic review settings April 4, 2026 16:16
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 4, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Windows-specific implementation details in FileSystemEnumerator<TResult> to ensure the intended OS behaviors are actually applied and to make the NT query buffer’s alignment requirement explicit.

Changes:

  • Replace using (default(DisableMediaInsertionPrompt)) with using (DisableMediaInsertionPrompt.Create()) so the media insertion prompt suppression is actually enabled.
  • Allocate the directory query buffer via NativeMemory.AlignedAlloc(..., sizeof(ulong)) and free it via NativeMemory.AlignedFree, switching _buffer from IntPtr to void*.
  • Update the NtQueryDirectoryFile interop signature to accept void* for FileInformation, matching the updated buffer type.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerator.Windows.cs Uses the correct prompt-suppression factory and switches the query buffer to explicitly aligned native allocation.
src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtQueryDirectoryFile.cs Updates the P/Invoke signature to take a raw pointer for the output buffer.

Comment on lines 109 to +112
// NtQueryDirectoryFile needs its buffer to be 64bit aligned to work
// successfully with FileFullDirectoryInformation on ARM32. AllocHGlobal
// will return pointers aligned as such, new byte[] does not.
_buffer = Marshal.AllocHGlobal(_bufferLength);
// successfully with FileFullDirectoryInformation on ARM32. AlignedAlloc
// guarantees the required alignment, new byte[] does not.
_buffer = NativeMemory.AlignedAlloc((nuint)_bufferLength, sizeof(ulong));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we switch to just Alloc now that win-arm is not supported?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.IO community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants