Small fixes in FileSystemEnumerator for Windows.#126544
Open
teo-tsirpanis wants to merge 4 commits intodotnet:mainfrom
Open
Small fixes in FileSystemEnumerator for Windows.#126544teo-tsirpanis wants to merge 4 commits intodotnet:mainfrom
FileSystemEnumerator for Windows.#126544teo-tsirpanis wants to merge 4 commits intodotnet:mainfrom
Conversation
…temEnumerator buffer Agent-Logs-Url: https://github.com/teo-tsirpanis/dotnet-runtime/sessions/233c35f2-6fa4-4409-b093-93f4a80a0598 Co-authored-by: teo-tsirpanis <12659251+teo-tsirpanis@users.noreply.github.com>
… cast Agent-Logs-Url: https://github.com/teo-tsirpanis/dotnet-runtime/sessions/c20f57ce-bd4d-4583-90a1-c799d80ee39e Co-authored-by: teo-tsirpanis <12659251+teo-tsirpanis@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-io |
Contributor
There was a problem hiding this comment.
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))withusing (DisableMediaInsertionPrompt.Create())so the media insertion prompt suppression is actually enabled. - Allocate the directory query buffer via
NativeMemory.AlignedAlloc(..., sizeof(ulong))and free it viaNativeMemory.AlignedFree, switching_bufferfromIntPtrtovoid*. - Update the
NtQueryDirectoryFileinterop signature to acceptvoid*forFileInformation, 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. |
teo-tsirpanis
commented
Apr 5, 2026
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)); |
Contributor
Author
There was a problem hiding this comment.
Could we switch to just Alloc now that win-arm is not supported?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This PR was created with the assistance of GitHub Copilot.
default(DisableMediaInsertionPrompt), withDisableMediaInsertionPrompt.Create()._bufferwas updated to be backed byNativeMemory.AlignedAllocinstead ofMarshal.AllocHGlobal. This makes the alignment requirement explicit and might increase performance.