Skip to content

Commit 1691c1b

Browse files
benrr101MichelZ
authored andcommitted
Merge | Interop NtDll Namespace (#2983)
* Create NtDll class, move NtCreateFile into it, migrate usages * Moving ObjectAttributes to Interop namespace, migrating usages * Move ObjectAttributeFlags to Interop namespace, migrate usage * Moving CreateDisposition to Interop namespace, migrating usages * Moving CreateOptions into Interop namespace, migrating usages * Moving DesiredAccess into Interop namespace, migrating usages * Moving SecurityQualityOfService to Interop namespace, migrating usages * Moving ImpersonationLevel into Interop namespace, migrating usages * Moving RtlNtStatusToDosError to NtDll, MID_NOT_FOUND error moved to SystemErrors, migrating usages * Moving FileFullEaInformation to Interop namespace, migrating usages * Moving IoStatusBlock to Interop namespace, migrating usages
1 parent 51b523a commit 1691c1b

18 files changed

+878
-822
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -697,22 +697,37 @@
697697
<Link>Interop\Windows\Kernel32\IoControlTransferType.cs</Link>
698698
</Compile>
699699
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Kernel32\Kernel32.cs">
700-
<Link>Common\Interop\Windows\Kernel32\Kernel32.cs</Link>
700+
<Link>Interop\Windows\Kernel32\Kernel32.cs</Link>
701701
</Compile>
702-
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\Interop.FILE_FULL_EA_INFORMATION.cs">
703-
<Link>Interop\Windows\NtDll\Interop.FILE_FULL_EA_INFORMATION.cs</Link>
702+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\CreateDisposition.cs">
703+
<Link>Interop\Windows\NtDll\Interop\Windows\NtDll\CreateDisposition.cs</Link>
704704
</Compile>
705-
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\Interop.IO_STATUS_BLOCK.cs">
706-
<Link>Interop\Windows\NtDll\Interop.IO_STATUS_BLOCK.cs</Link>
705+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\CreateOptions.cs">
706+
<Link>Interop\Windows\NtDll\Interop\Windows\NtDll\CreateOptions.cs</Link>
707707
</Compile>
708-
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\Interop.NtCreateFile.cs">
709-
<Link>Interop\Windows\NtDll\Interop.NtCreateFile.cs</Link>
708+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\DesiredAccess.cs">
709+
<Link>Interop\Windows\NtDll\Interop\Windows\NtDll\DesiredAccess.cs</Link>
710710
</Compile>
711-
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\Interop.RtlNtStatusToDosError.cs">
712-
<Link>Interop\Windows\NtDll\Interop.RtlNtStatusToDosError.cs</Link>
711+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\FileFullEaInformation.cs">
712+
<Link>Interop\Windows\NtDll\Interop\Windows\NtDll\FileFullEaInformation.cs</Link>
713713
</Compile>
714-
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\Interop.SecurityQualityOfService.cs">
715-
<Link>Interop\Windows\NtDll\Interop.SecurityQualityOfService.cs</Link>
714+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\ImpersonationLevel.cs">
715+
<Link>Interop\Windows\NtDll\ImpersonaltionLevel.cs</Link>
716+
</Compile>
717+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\IoStatusBlock.cs">
718+
<Link>Interop\Windows\NtDll\IoStatusBlock.cs</Link>
719+
</Compile>
720+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\NtDll.cs">
721+
<Link>Interop\Windows\NtDll\Interop\Windows\NtDll\NtDll.cs</Link>
722+
</Compile>
723+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\ObjectAttributeFlags.cs">
724+
<Link>Interop\Windows\NtDll\Interop\Windows\NtDll\ObjectAttributes.cs</Link>
725+
</Compile>
726+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\ObjectAttributes.cs">
727+
<Link>Interop\Windows\NtDll\Interop\Windows\NtDll\ObjectAttributes.cs</Link>
728+
</Compile>
729+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\SecurityQualityOfService.cs">
730+
<Link>Interop\Windows\NtDll\Interop\Windows\NtDll\SecurityQualityOfService.cs</Link>
716731
</Compile>
717732
<Compile Include="$(CommonSourceRoot)\Interop\Windows\SChannel\Interop.SecPkgContext_ApplicationProtocol.netcore.cs">
718733
<Link>Interop\Windows\SChannel\Interop.SecPkgContext_ApplicationProtocol.netcore.cs</Link>

src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,35 @@
118118
<Compile Include="$(CommonSourceRoot)Interop\Windows\Interop.Libraries.cs">
119119
<Link>Interop\Interop.Libraries.cs</Link>
120120
</Compile>
121-
<Compile Include="$(CommonSourceRoot)Interop\Windows\NtDll\Interop.FILE_FULL_EA_INFORMATION.cs">
122-
<Link>Interop\NtDll\Interop.FILE_FULL_EA_INFORMATION.cs</Link>
121+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\CreateDisposition.cs">
122+
<Link>Common\Interop\Windows\NtDll\Interop\Windows\NtDll\CreateDisposition.cs</Link>
123123
</Compile>
124-
<Compile Include="$(CommonSourceRoot)Interop\Windows\NtDll\Interop.IO_STATUS_BLOCK.cs">
125-
<Link>Interop\NtDll\Interop.IO_STATUS_BLOCK.cs</Link>
124+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\CreateOptions.cs">
125+
<Link>Common\Interop\Windows\NtDll\Interop\Windows\NtDll\CreateOptions.cs</Link>
126126
</Compile>
127-
<Compile Include="$(CommonSourceRoot)Interop\Windows\NtDll\Interop.NtCreateFile.cs">
128-
<Link>Interop\NtDll\Interop.NtCreateFile.cs</Link>
127+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\DesiredAccess.cs">
128+
<Link>Common\Interop\Windows\NtDll\Interop\Windows\NtDll\DesiredAccess.cs</Link>
129129
</Compile>
130-
<Compile Include="$(CommonSourceRoot)Interop\Windows\NtDll\Interop.RtlNtStatusToDosError.cs">
131-
<Link>Interop\NtDll\Interop.RtlNtStatusToDosError.cs</Link>
130+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\FileFullEaInformation.cs">
131+
<Link>Common\Interop\Windows\NtDll\Interop\Windows\NtDll\FileFullEaInformation.cs</Link>
132132
</Compile>
133-
<Compile Include="$(CommonSourceRoot)Interop\Windows\NtDll\Interop.SecurityQualityOfService.cs">
134-
<Link>Interop\NtDll\Interop.SecurityQualityOfService.cs</Link>
133+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\ImpersonationLevel.cs">
134+
<Link>Common\Interop\Windows\NtDll\ImpersonaltionLevel.cs</Link>
135+
</Compile>
136+
<Compile Include="$(CommonSourceRoot)Interop\Windows\NtDll\IoStatusBlock.cs">
137+
<Link>Interop\NtDll\IoStatusBlock.cs</Link>
138+
</Compile>
139+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\NtDll.cs">
140+
<Link>Common\Interop\Windows\NtDll\Interop\Windows\NtDll\NtDll.cs</Link>
141+
</Compile>
142+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\ObjectAttributeFlags.cs">
143+
<Link>Common\Interop\Windows\NtDll\Interop\Windows\NtDll\ObjectAttributes.cs</Link>
144+
</Compile>
145+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\ObjectAttributes.cs">
146+
<Link>Common\Interop\Windows\NtDll\Interop\Windows\NtDll\ObjecAttributes.cs</Link>
147+
</Compile>
148+
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\SecurityQualityOfService.cs">
149+
<Link>Common\Interop\Windows\NtDll\Interop\Windows\NtDll\SecurityQualityOfService.cs</Link>
135150
</Compile>
136151
<Compile Include="$(CommonSourceRoot)Interop\Windows\UnicodeString.cs">
137152
<Link>Interop\UnicodeString.cs</Link>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Interop_TEMP.Windows.NtDll
6+
{
7+
/// <summary>
8+
/// File creation disposition when calling directly to NT APIs.
9+
/// </summary>
10+
internal enum CreateDisposition : uint
11+
{
12+
/// <summary>
13+
/// Default. Replace or create. Deletes existing file instead of overwriting.
14+
/// </summary>
15+
/// <remarks>
16+
/// As this potentially deletes it requires that DesiredAccess must include Delete.
17+
/// This has no equivalent in CreateFile.
18+
/// </remarks>
19+
FILE_SUPERSEDE = 0,
20+
21+
/// <summary>
22+
/// Open if the file exists or fail if it doesn't exist. Equivalent to OPEN_EXISTING or
23+
/// <see cref="System.IO.FileMode.Open"/>.
24+
/// </summary>
25+
/// <remarks>
26+
/// TruncateExisting also uses Open and then manually truncates the file
27+
/// by calling NtSetInformationFile with FileAllocationInformation and an
28+
/// allocation size of 0.
29+
/// </remarks>
30+
FILE_OPEN = 1,
31+
32+
/// <summary>
33+
/// Create if the file doesn't exist or fail if it does exist. Equivalent to CREATE_NEW
34+
/// or <see cref="System.IO.FileMode.CreateNew"/>.
35+
/// </summary>
36+
FILE_CREATE = 2,
37+
38+
/// <summary>
39+
/// Open if the file exists or create if it doesn't exist. Equivalent to OPEN_ALWAYS or
40+
/// <see cref="System.IO.FileMode.OpenOrCreate"/>.
41+
/// </summary>
42+
FILE_OPEN_IF = 3,
43+
44+
/// <summary>
45+
/// Open and overwrite if the file exists or fail if it doesn't exist. Equivalent to
46+
/// TRUNCATE_EXISTING or <see cref="System.IO.FileMode.Truncate"/>.
47+
/// </summary>
48+
FILE_OVERWRITE = 4,
49+
50+
/// <summary>
51+
/// Open and overwrite if the file exists or create if it doesn't exist. Equivalent to
52+
/// CREATE_ALWAYS or <see cref="System.IO.FileMode.Create"/>.
53+
/// </summary>
54+
FILE_OVERWRITE_IF = 5
55+
}
56+
}
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
7+
namespace Interop_TEMP.Windows.NtDll
8+
{
9+
/// <summary>
10+
/// Options for creating/opening files with NtCreateFile.
11+
/// </summary>
12+
[Flags]
13+
internal enum CreateOptions : uint
14+
{
15+
/// <summary>
16+
/// File being created or opened must be a directory file. Disposition must be FILE_CREATE, FILE_OPEN,
17+
/// or FILE_OPEN_IF.
18+
/// </summary>
19+
/// <remarks>
20+
/// Can only be used with FILE_SYNCHRONOUS_IO_ALERT/NONALERT, FILE_WRITE_THROUGH, FILE_OPEN_FOR_BACKUP_INTENT,
21+
/// and FILE_OPEN_BY_FILE_ID flags.
22+
/// </remarks>
23+
FILE_DIRECTORY_FILE = 0x00000001,
24+
25+
/// <summary>
26+
/// Applications that write data to the file must actually transfer the data into
27+
/// the file before any requested write operation is considered complete. This flag
28+
/// is set automatically if FILE_NO_INTERMEDIATE_BUFFERING is set.
29+
/// </summary>
30+
FILE_WRITE_THROUGH = 0x00000002,
31+
32+
/// <summary>
33+
/// All accesses to the file are sequential.
34+
/// </summary>
35+
FILE_SEQUENTIAL_ONLY = 0x00000004,
36+
37+
/// <summary>
38+
/// File cannot be cached in driver buffers. Cannot use with AppendData desired access.
39+
/// </summary>
40+
FILE_NO_INTERMEDIATE_BUFFERING = 0x00000008,
41+
42+
/// <summary>
43+
/// All operations are performed synchronously. Any wait on behalf of the caller is
44+
/// subject to premature termination from alerts.
45+
/// </summary>
46+
/// <remarks>
47+
/// Cannot be used with FILE_SYNCHRONOUS_IO_NONALERT.
48+
/// Synchronous DesiredAccess flag is required. I/O system will maintain file position context.
49+
/// </remarks>
50+
FILE_SYNCHRONOUS_IO_ALERT = 0x00000010,
51+
52+
/// <summary>
53+
/// All operations are performed synchronously. Waits in the system to synchronize I/O queuing
54+
/// and completion are not subject to alerts.
55+
/// </summary>
56+
/// <remarks>
57+
/// Cannot be used with FILE_SYNCHRONOUS_IO_ALERT.
58+
/// Synchronous DesiredAccess flag is required. I/O system will maintain file position context.
59+
/// </remarks>
60+
FILE_SYNCHRONOUS_IO_NONALERT = 0x00000020,
61+
62+
/// <summary>
63+
/// File being created or opened must not be a directory file. Can be a data file, device,
64+
/// or volume.
65+
/// </summary>
66+
FILE_NON_DIRECTORY_FILE = 0x00000040,
67+
68+
/// <summary>
69+
/// Create a tree connection for this file in order to open it over the network.
70+
/// </summary>
71+
/// <remarks>
72+
/// Not used by device and intermediate drivers.
73+
/// </remarks>
74+
FILE_CREATE_TREE_CONNECTION = 0x00000080,
75+
76+
/// <summary>
77+
/// Complete the operation immediately with a success code of STATUS_OPLOCK_BREAK_IN_PROGRESS if
78+
/// the target file is oplocked.
79+
/// </summary>
80+
/// <remarks>
81+
/// Not compatible with ReserveOpfilter or OpenRequiringOplock.
82+
/// Not used by device and intermediate drivers.
83+
/// </remarks>
84+
FILE_COMPLETE_IF_OPLOCKED = 0x00000100,
85+
86+
/// <summary>
87+
/// If the extended attributes on an existing file being opened indicate that the caller must
88+
/// understand extended attributes to properly interpret the file, fail the request.
89+
/// </summary>
90+
/// <remarks>
91+
/// Not used by device and intermediate drivers.
92+
/// </remarks>
93+
FILE_NO_EA_KNOWLEDGE = 0x00000200,
94+
95+
// Behavior undocumented, defined in headers
96+
// FILE_OPEN_REMOTE_INSTANCE = 0x00000400,
97+
98+
/// <summary>
99+
/// Accesses to the file can be random, so no sequential read-ahead operations should be performed
100+
/// on the file by FSDs or the system.
101+
/// </summary>
102+
FILE_RANDOM_ACCESS = 0x00000800,
103+
104+
/// <summary>
105+
/// Delete the file when the last handle to it is passed to NtClose. Requires Delete flag in
106+
/// DesiredAccess parameter.
107+
/// </summary>
108+
FILE_DELETE_ON_CLOSE = 0x00001000,
109+
110+
/// <summary>
111+
/// Open the file by reference number or object ID. The file name that is specified by the ObjectAttributes
112+
/// name parameter includes the 8 or 16 byte file reference number or ID for the file in the ObjectAttributes
113+
/// name field. The device name can optionally be prefixed.
114+
/// </summary>
115+
/// <remarks>
116+
/// NTFS supports both reference numbers and object IDs. 16 byte reference numbers are 8 byte numbers padded
117+
/// with zeros. ReFS only supports reference numbers (not object IDs). 8 byte and 16 byte reference numbers
118+
/// are not related. Note that as the UNICODE_STRING will contain raw byte data, it may not be a "valid" string.
119+
/// Not used by device and intermediate drivers.
120+
/// </remarks>
121+
/// <example>
122+
/// \??\C:\{8 bytes of binary FileID}
123+
/// \device\HardDiskVolume1\{16 bytes of binary ObjectID}
124+
/// {8 bytes of binary FileID}
125+
/// </example>
126+
FILE_OPEN_BY_FILE_ID = 0x00002000,
127+
128+
/// <summary>
129+
/// The file is being opened for backup intent. Therefore, the system should check for certain access rights
130+
/// and grant the caller the appropriate access to the file before checking the DesiredAccess parameter
131+
/// against the file's security descriptor.
132+
/// </summary>
133+
/// <remarks>
134+
/// Not used by device and intermediate drivers.
135+
/// </remarks>
136+
FILE_OPEN_FOR_BACKUP_INTENT = 0x00004000,
137+
138+
/// <summary>
139+
/// When creating a file, specifies that it should not inherit the compression bit from the parent directory.
140+
/// </summary>
141+
FILE_NO_COMPRESSION = 0x00008000,
142+
143+
/// <summary>
144+
/// The file is being opened and an opportunistic lock (oplock) on the file is being requested as a single atomic
145+
/// operation.
146+
/// </summary>
147+
/// <remarks>
148+
/// The file system checks for oplocks before it performs the create operation and will fail the create with a
149+
/// return code of STATUS_CANNOT_BREAK_OPLOCK if the result would be to break an existing oplock.
150+
/// Not compatible with CompleteIfOplocked or ReserveOpFilter. Windows 7 and up.
151+
/// </remarks>
152+
FILE_OPEN_REQUIRING_OPLOCK = 0x00010000,
153+
154+
/// <summary>
155+
/// CreateFile2 uses this flag to prevent opening a file that you don't have access to without specifying
156+
/// FILE_SHARE_READ. (Preventing users that can only read a file from denying access to other readers.)
157+
/// </summary>
158+
/// <remarks>
159+
/// Windows 7 and up.
160+
/// </remarks>
161+
FILE_DISALLOW_EXCLUSIVE = 0x00020000,
162+
163+
/// <summary>
164+
/// The client opening the file or device is session aware and per session access is validated if necessary.
165+
/// </summary>
166+
/// <remarks>
167+
/// Windows 8 and up.
168+
/// </remarks>
169+
FILE_SESSION_AWARE = 0x00040000,
170+
171+
/// <summary>
172+
/// This flag allows an application to request a filter opportunistic lock (oplock) to prevent other applications
173+
/// from getting share violations.
174+
/// </summary>
175+
/// <remarks>
176+
/// Not compatible with CompleteIfOplocked or OpenRequiringOplock.
177+
/// If there are already open handles, the create request will fail with STATUS_OPLOCK_NOT_GRANTED.
178+
/// </remarks>
179+
FILE_RESERVE_OPFILTER = 0x00100000,
180+
181+
/// <summary>
182+
/// Open a file with a reparse point attribute, bypassing the normal reparse point processing.
183+
/// </summary>
184+
FILE_OPEN_REPARSE_POINT = 0x00200000,
185+
186+
/// <summary>
187+
/// Causes files that are marked with the Offline attribute not to be recalled from remote storage.
188+
/// </summary>
189+
/// <remarks>
190+
/// More details can be found in Remote Storage documentation (see Basic Concepts).
191+
/// https://technet.microsoft.com/en-us/library/cc938459.aspx
192+
/// </remarks>
193+
FILE_OPEN_NO_RECALL = 0x00400000
194+
195+
// Behavior undocumented, defined in headers
196+
// FILE_OPEN_FOR_FREE_SPACE_QUERY = 0x00800000
197+
}
198+
}

0 commit comments

Comments
 (0)