Skip to content

Small fixes in FileSystemEnumerator for Windows. - #126544

Merged
jkotas merged 8 commits into
dotnet:mainfrom
teo-tsirpanis:copilot/update-filesystem-enumerator-edits
Oct 31, 2026
Merged

jkotas merged 8 commits into
dotnet:mainfrom
teo-tsirpanis:copilot/update-filesystem-enumerator-edits

Conversation

@teo-tsirpanis

@teo-tsirpanis teo-tsirpanis commented Apr 4, 2026 •

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(). Removed, after PR feedback.
    • 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

@adamsitnik adamsitnik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@JeremyKuhne PTAL

Thank you for your contribution @teo-tsirpanis !

@adamsitnik
adamsitnik requested a review from JeremyKuhne April 15, 2026 08:32

@JeremyKuhne JeremyKuhne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Generally looks fine, see my comment on removing the broken suppression.

Copilot AI review requested due to automatic review settings April 15, 2026 22:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

@adamsitnik adamsitnik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thank you @teo-tsirpanis !

@github-actions

github-actions Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow state for the Holistic Review Orchestrator.

{
  "version": 5,
  "last_dispatched_commit": "c7575244ccabb4805405dfff2f6eebfec123eec7",
  "last_dispatched_base_ref": "main",
  "last_dispatched_base_sha": "cb84c8521ce6a4cbde63cb1a700fcb850be791ae",
  "last_reviewed_commit": "c7575244ccabb4805405dfff2f6eebfec123eec7",
  "last_reviewed_base_ref": "main",
  "last_reviewed_base_sha": "cb84c8521ce6a4cbde63cb1a700fcb850be791ae",
  "last_recorded_worker_run_id": "29689521922",
  "review_attempt_commit": "",
  "review_attempt_base_ref": "",
  "review_attempt_count": 0,
  "max_review_attempts": 5,
  "review_history_format": "holistic-review-disclosure-v1",
  "review_history": [
    {
      "commit": "567dacdda9f2fc7b65576203789ac94e117cfbe9",
      "review_id": 4730178051
    },
    {
      "commit": "c7575244ccabb4805405dfff2f6eebfec123eec7",
      "review_id": 4730872254
    }
  ]
}

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Holistic Review

Motivation: Small cleanups in the Windows FileSystemEnumerator implementation: remove an ineffective use of DisableMediaInsertionPrompt, make the NtQueryDirectoryFile buffer's alignment requirement explicit, and modernize the interop signature.

Approach: The default(DisableMediaInsertionPrompt) guard in Init() is removed. Because it was constructed via default, its _disableSuccess field was always false, so SetThreadErrorMode was never called and Dispose() was a no-op — the prompt was never actually suppressed. Removing it is therefore behavior-preserving. The buffer is switched from Marshal.AllocHGlobal/FreeHGlobal to NativeMemory.AlignedAlloc/AlignedFree with an explicit 8-byte (sizeof(ulong)) alignment, documenting the LONGLONG alignment requirement of FILE_FULL_DIR_INFORMATION. The _buffer field and the NtQueryDirectoryFile FileInformation parameter change from IntPtr to void*, and disposal null checks are updated accordingly.

Summary: The change is correct and self-consistent. NativeMemory.AlignedAlloc guarantees the required 8-byte alignment (stronger than the previous implicit LocalAlloc alignment) and does not require the size to be a multiple of the alignment, so the existing _bufferLength values are fine. The try/catch around allocation still frees on failure, and disposal now correctly pairs AlignedFree with AlignedAlloc and null-checks the pointer. The interop signature change to void* is confined to the single caller. No functional regression is apparent and the alignment intent is now clearer. LGTM.

Note

This review was generated by this repository's Holistic Review agentic workflow to complement the built-in Copilot review.

Generated by Holistic Review · 47.6 AIC · ⌖ 14.5 AIC · ⊞ 10K

Copilot AI review requested due to automatic review settings July 19, 2026 05:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Holistic Review

Motivation: Small cleanups in the Windows FileSystemEnumerator implementation: remove an ineffective use of DisableMediaInsertionPrompt, make the NtQueryDirectoryFile buffer's alignment requirement explicit, and modernize the interop signature.

Approach: The default(DisableMediaInsertionPrompt) guard in Init() is removed (behavior-preserving, since the default-constructed value never called SetThreadErrorMode). The buffer moves from Marshal.AllocHGlobal/FreeHGlobal to NativeMemory.AlignedAlloc/AlignedFree with an explicit 8-byte (sizeof(ulong)) alignment documenting the LONGLONG alignment requirement of FILE_FULL_DIR_INFORMATION, and the _buffer field plus the NtQueryDirectoryFile FileInformation parameter change from IntPtr to void*.

Summary: The PR patch has not changed since the prior review: the current and previous patch IDs are identical (a113cb1d), and only the merge base moved, indicating the PR was retargeted/rebased onto main with no new commits. There are no incremental changes to review and no new actionable findings. The cumulative assessment is unchanged: the change is correct, self-consistent, and behavior-preserving, with the alignment intent now clearer. LGTM.

Assessment History:

  • review 4730178051 (commit 567dacd): verdict LGTM. Current verdict: LGTM. Unchanged — the PR patch is identical after the retarget, so motivation, approach, and risk assessment all remain the same.

Note

This review was generated by this repository's Holistic Review agentic workflow to complement the built-in Copilot review.

Generated by Holistic Review · 29 AIC · ⌖ 10.4 AIC · ⊞ 10K

@adamsitnik

Copy link
Copy Markdown
Member

@JeremyKuhne could you please re-approve the PR? I can't merge it after you have requested changes. Thanks!

@MichalPetryka

Copy link
Copy Markdown
Contributor

NativeMemory.AlignedAlloc/AlignedFree with an explicit 8-byte (sizeof(ulong)) alignment, documenting the LONGLONG alignment requirement of FILE_FULL_DIR_INFORMATION

Since the code is windows only, it can just use Alloc: The storage space pointed to by the return value is suitably aligned for storage of any type of object that has an alignment requirement less than or equal to that of the fundamental alignment. (In Visual C++, the fundamental alignment is the alignment that's required for a double, or 8 bytes. In code that targets 64-bit platforms, it's 16 bytes.)

@jkotas
jkotas enabled auto-merge (squash) October 31, 2026 17:50
@jkotas
jkotas merged commit 92e5bfd into dotnet:main Oct 31, 2026
135 checks passed
@teo-tsirpanis
teo-tsirpanis deleted the copilot/update-filesystem-enumerator-edits branch October 31, 2026 18:37
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 4, 2026
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.

8 participants