KEMBAR78
Win8 baseline: Simplify `<filesystem>` API calls by StephanTLavavej · Pull Request #5434 · microsoft/STL · GitHub
Skip to content

Conversation

@StephanTLavavej
Copy link
Member

@StephanTLavavej StephanTLavavej commented Apr 25, 2025

🗺️ Overview

  • Will be merged after Win8 baseline: Drop support for Win7 / Server 2008 R2 #5432.
  • These changes are somewhat daring, hence the isolated PR. Our <filesystem> implementation (and older <experimental/filesystem>) contains several codepaths of the form "if we're a UWP app, call a modern API, otherwise call a legacy API". This is not only twice as much code to maintain, but we don't have automated test coverage for UWP apps, which greatly increases risk. Now that our baseline OS is Win8, we can send everything through the modern APIs.
  • The change I'm the least certain about is in Standard filesystem.cpp, where _Get_file_id_by_handle() has the unusual pattern of calling modern GetFileInformationByHandleEx() and then falling back to legacy GetFileInformationByHandle(). See the commit notes below for why I suspect this is unnecessary. This code was moved around by [copy_file] allow FILE_SHARE_* #2718 but the original logic dates back to the initial GitHub commit.
  • By front-loading this change, we'll have the most time available to gather and react to feedback (including from our Real World Code test suite). If issues are encountered, we can selectively or entirely revert these changes, and we can add comments explaining why the codepaths are necessary.

⚙️ Commits

  • Filesystem: Unconditionally call CopyFile2 instead of CopyFileW.
    • CopyFile2 is "Windows 8 [desktop apps | UWP apps]".
    • CopyFileW is "Windows XP [desktop apps | UWP apps]".
    • We were inconsistently guarding this with defined(_ONECORE) versus defined(_CRT_APP).
  • Filesystem: Unconditionally call CreateFile2 instead of CreateFileW.
  • Filesystem: Unconditionally call GetFileInformationByHandleEx instead of GetFileInformationByHandle.
    • GetFileInformationByHandleEx is "Windows Vista [desktop apps | UWP apps]".
    • GetFileInformationByHandle is "Windows XP [desktop apps only]".
    • The documentation around FileIdInfo/FILE_ID_INFO is confusing. It claims "Minimum supported client: None supported" and "Minimum supported server: Windows Server 2012 [desktop apps only]", but in modern filesystem.cpp it is our only codepath when defined(_CRT_APP). That suggests that it works on Client and works for UWP apps, so I think it might actually be "Windows 8 [desktop apps | UWP apps]". This PR certainly appears to work on my client Windows 11 machine.

📜 Changelog

  • The STL no longer supports targeting Windows 7 and Server 2008 R2:
    • Simplified the <filesystem> implementation by unconditionally calling APIs that were added in Windows 8.

+ [`CopyFile2`](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-copyfile2) is "Windows 8 \[desktop apps | UWP apps\]".
+ [`CopyFileW`](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-copyfilew) is "Windows XP \[desktop apps | UWP apps\]".
+ We were inconsistently guarding this with `defined(_ONECORE)` versus `defined(_CRT_APP)`.
…ad of `GetFileInformationByHandle`.

+ [`GetFileInformationByHandleEx`](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getfileinformationbyhandleex) is "Windows Vista \[desktop apps | UWP apps\]".
+ [`GetFileInformationByHandle`](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfileinformationbyhandle) is "Windows XP \[desktop apps only\]".
+ The documentation around `FileIdInfo`/[`FILE_ID_INFO`](https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-file_id_info) is confusing. It claims "Minimum supported client: None supported" and "Minimum supported server: Windows Server 2012 \[desktop apps only\]", but in modern `filesystem.cpp` it is our only codepath when `defined(_CRT_APP)`. That suggests that it works on Client and works for UWP apps, so I think it might actually be "Windows 8 \[desktop apps | UWP apps\]".
@StephanTLavavej StephanTLavavej added enhancement Something can be improved filesystem C++17 filesystem labels Apr 25, 2025
@StephanTLavavej StephanTLavavej requested a review from a team as a code owner April 25, 2025 00:12
@github-project-automation github-project-automation bot moved this to Initial Review in STL Code Reviews Apr 25, 2025
@StephanTLavavej StephanTLavavej moved this from Initial Review to Final Review in STL Code Reviews Apr 25, 2025
@StephanTLavavej
Copy link
Member Author

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

Copy link
Member

@zacklj89 zacklj89 left a comment

Choose a reason for hiding this comment

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

Love the 🟥

@StephanTLavavej StephanTLavavej moved this from Final Review to Merging in STL Code Reviews Apr 29, 2025
@StephanTLavavej StephanTLavavej merged commit 0c85611 into microsoft:main Apr 29, 2025
39 checks passed
@github-project-automation github-project-automation bot moved this from Merging to Done in STL Code Reviews Apr 29, 2025
@StephanTLavavej StephanTLavavej deleted the doom-3-filesystem branch April 29, 2025 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Something can be improved filesystem C++17 filesystem

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants