Repository navigation
Kernel32: drop the unused Win32 declarations - #243
Merged
Merged
Conversation
Remove the constants and enum members of TruePath.Kernel32 that nothing in the codebase uses, as recommended by the maintainer in ForNeVeR#241. Among the dropped members are the two whose values did not match the Windows headers: FileShare.Delete (0x03 instead of 0x04) and FileAttributes.PosixSemantics (0x0100000 instead of 0x01000000). The remaining declarations are now covered by Kernel32ConstantsTests, pinning their values to the Windows headers so hand-copied constants cannot silently go stale again. Closes ForNeVeR#241
ForNeVeR
approved these changes
Oct 24, 2026
ForNeVeR
left a comment
Owner
There was a problem hiding this comment.
Thanks! I decided to migrate to CsWin32 in the end of this commit chain, thus eliminating the problem at hand.
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.
Problem
TruePath/Kernel32.cshand-rolls Win32 interop constants, and two of them do not match the Windows headers (#241):FileShare.Deletewas0x03鈥?that isRead | Write;FILE_SHARE_DELETEis0x04.FileAttributes.PosixSemanticswas0x0100000(one digit short) 鈥?it collides withOpenNoRecall;FILE_FLAG_POSIX_SEMANTICSis0x01000000.Both members are dead code today, but the wrong values are a trap for whoever uses them first:
CreateFilewould silently get a different sharing/behavior combination than the name suggests.The maintainer's call on the issue was broader than fixing the two numbers: "A huge portion of the
Kernel32type (including but not limited to the mentioned flags) is completely unused 鈥?let's clean it up and drop all the unused constants/flags."What this PR does
Kernel32that nothing in the codebase references 鈥?156 lines removed. That includes both wrong-valued members listed above, so the trap is gone along with the dead weight. What remains is exactly whatDiskUtils.csuses: theGetFinalPathNameByHandle/CreateFile/DeviceIoControlP/Invokes, theFSCTL_GET_REPARSE_POINT,MAXIMUM_REPARSE_DATA_BUFFER_SIZEandIO_REPARSE_TAG_MOUNT_POINTconstants, theSymbolicLinkReparseBufferstruct, and the enum members actually passed toCreateFile(BackupSemantics,OpenReparsePoint,ReadEa,ReadAttributes,Read).winnt.h,winioctl.h).Kernel32ConstantsTests(5 tests) pinning the surviving constant values and the reparse-buffer size to the header values, so a future typo in one of these numbers fails the build instead of waiting for someone to hit it at runtime.Verification
Commands run locally on Windows (net8.0|x64), .NET SDK 10.0.402, from the repo root. Baseline (
master@682b3256, before my change):The 2 baseline failures are
AbsolutePathTests.ReadKind_IsSymlink/OnWindows_ReadKind_IsJunction鈥?Directory.CreateSymbolicLinkthrowsUnauthorizedAccessExceptionin a non-elevated shell, exactly the environment limitation CONTRIBUTING.md warns about; they are unrelated to this change.After the change:
Same 2 pre-existing symlink-permission failures as the baseline, nothing new; the 5 added tests pass, and the
DiskUtilstests that actually exercise the survivingCreateFile/GetFinalPathNameByHandle/DeviceIoControlpaths still pass.scripts/Test-Encoding.ps1(the encoding CI gate) also passes: no UTF-8 BOM, LF endings.Closes #241