VirtualBox

source: kBuild/trunk/src/lib/nt/ntstuff.h@ 2704

Last change on this file since 2704 was 2704, checked in by bird, 12 years ago

Drop the w32 createfile option, implemented sharing-violation fallback for stat() and lstat().

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 14.1 KB
Line 
1/* $Id: ntstuff.h 2704 2013-11-21 01:26:52Z bird $ */
2/** @file
3 * Definitions, types, prototypes and globals for NT.
4 */
5
6/*
7 * Copyright (c) 2005-2013 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * IN THE SOFTWARE.
26 *
27 * Alternatively, the content of this file may be used under the terms of the
28 * GPL version 2 or later, or LGPL version 2.1 or later.
29 */
30
31
32#ifndef ___nt_ntstuff_h
33#define ___nt_ntstuff_h
34
35#define timeval timeval_Windows
36#define WIN32_NO_STATUS
37#include <Windows.h>
38#undef WIN32_NO_STATUS
39#include <ntstatus.h>
40#undef timeval
41
42
43/** @defgroup grp_nt_ntstuff NT Stuff
44 * @{ */
45
46typedef LONG MY_NTSTATUS;
47typedef ULONG MY_ACCESS_MASK;
48
49typedef struct MY_IO_STATUS_BLOCK
50{
51 union
52 {
53 MY_NTSTATUS Status;
54 PVOID Pointer;
55 } u;
56 ULONG_PTR Information;
57} MY_IO_STATUS_BLOCK;
58
59typedef VOID WINAPI MY_IO_APC_ROUTINE(PVOID, MY_IO_STATUS_BLOCK *, ULONG);
60
61typedef struct MY_UNICODE_STRING
62{
63 USHORT Length;
64 USHORT MaximumLength;
65 PWSTR Buffer;
66} MY_UNICODE_STRING;
67
68typedef struct MY_STRING
69{
70 USHORT Length;
71 USHORT MaximumLength;
72 PCHAR Buffer;
73} MY_STRING;
74typedef MY_STRING MY_ANSI_STRING;
75
76typedef struct MY_OBJECT_ATTRIBUTES
77{
78 ULONG Length;
79 HANDLE RootDirectory;
80 MY_UNICODE_STRING *ObjectName;
81 ULONG Attributes;
82 PVOID SecurityDescriptor;
83 PVOID SecurityQualityOfService;
84} MY_OBJECT_ATTRIBUTES;
85
86#define MyInitializeObjectAttributes(a_pAttr, a_pName, a_fAttribs, a_hRoot, a_pSecDesc) \
87 do { \
88 (a_pAttr)->Length = sizeof(MY_OBJECT_ATTRIBUTES); \
89 (a_pAttr)->RootDirectory = (a_hRoot); \
90 (a_pAttr)->Attributes = (a_fAttribs); \
91 (a_pAttr)->ObjectName = (a_pName); \
92 (a_pAttr)->SecurityDescriptor = (a_pSecDesc); \
93 (a_pAttr)->SecurityQualityOfService = NULL; \
94 } while (0)
95
96
97
98typedef struct MY_FILE_BASIC_INFORMATION
99{
100 LARGE_INTEGER CreationTime;
101 LARGE_INTEGER LastAccessTime;
102 LARGE_INTEGER LastWriteTime;
103 LARGE_INTEGER ChangeTime;
104 ULONG FileAttributes;
105} MY_FILE_BASIC_INFORMATION;
106
107typedef struct MY_FILE_STANDARD_INFORMATION
108{
109 LARGE_INTEGER AllocationSize;
110 LARGE_INTEGER EndOfFile;
111 ULONG NumberOfLinks;
112 BOOLEAN DeletePending;
113 BOOLEAN Directory;
114} MY_FILE_STANDARD_INFORMATION;
115
116typedef struct MY_FILE_INTERNAL_INFORMATION
117{
118 LARGE_INTEGER IndexNumber;
119} MY_FILE_INTERNAL_INFORMATION;
120
121typedef struct MY_FILE_EA_INFORMATION
122{
123 ULONG EaSize;
124} MY_FILE_EA_INFORMATION;
125
126typedef struct MY_FILE_ACCESS_INFORMATION
127{
128 ACCESS_MASK AccessFlags;
129} MY_FILE_ACCESS_INFORMATION;
130
131typedef struct MY_FILE_POSITION_INFORMATION
132{
133 LARGE_INTEGER CurrentByteOffset;
134} MY_FILE_POSITION_INFORMATION;
135
136typedef struct MY_FILE_MODE_INFORMATION
137{
138 ULONG Mode;
139} MY_FILE_MODE_INFORMATION;
140
141typedef struct MY_FILE_ALIGNMENT_INFORMATION
142{
143 ULONG AlignmentRequirement;
144} MY_FILE_ALIGNMENT_INFORMATION;
145
146typedef struct MY_FILE_NAME_INFORMATION
147{
148 ULONG FileNameLength;
149 WCHAR FileName[1];
150} MY_FILE_NAME_INFORMATION;
151
152typedef struct MY_FILE_ALL_INFORMATION
153{
154 MY_FILE_BASIC_INFORMATION BasicInformation;
155 MY_FILE_STANDARD_INFORMATION StandardInformation;
156 MY_FILE_INTERNAL_INFORMATION InternalInformation;
157 MY_FILE_EA_INFORMATION EaInformation;
158 MY_FILE_ACCESS_INFORMATION AccessInformation;
159 MY_FILE_POSITION_INFORMATION PositionInformation;
160 MY_FILE_MODE_INFORMATION ModeInformation;
161 MY_FILE_ALIGNMENT_INFORMATION AlignmentInformation;
162 MY_FILE_NAME_INFORMATION NameInformation;
163} MY_FILE_ALL_INFORMATION;
164
165typedef struct MY_FILE_ATTRIBUTE_TAG_INFORMATION
166{
167 ULONG FileAttributes;
168 ULONG ReparseTag;
169} MY_FILE_ATTRIBUTE_TAG_INFORMATION;
170
171
172typedef struct MY_FILE_NAMES_INFORMATION
173{
174 ULONG NextEntryOffset;
175 ULONG FileIndex;
176 ULONG FileNameLength;
177 WCHAR FileName[1];
178} MY_FILE_NAMES_INFORMATION;
179/** The sizeof(MY_FILE_NAMES_INFORMATION) without the FileName. */
180#define MIN_SIZEOF_MY_FILE_NAMES_INFORMATION (4 + 4 + 4)
181
182
183typedef struct MY_FILE_ID_FULL_DIR_INFORMATION
184{
185 ULONG NextEntryOffset;
186 ULONG FileIndex;
187 LARGE_INTEGER CreationTime;
188 LARGE_INTEGER LastAccessTime;
189 LARGE_INTEGER LastWriteTime;
190 LARGE_INTEGER ChangeTime;
191 LARGE_INTEGER EndOfFile;
192 LARGE_INTEGER AllocationSize;
193 ULONG FileAttributes;
194 ULONG FileNameLength;
195 ULONG EaSize;
196 LARGE_INTEGER FileId;
197 WCHAR FileName[1];
198} MY_FILE_ID_FULL_DIR_INFORMATION;
199
200
201typedef enum MY_FILE_INFORMATION_CLASS
202{
203 MyFileDirectoryInformation = 1,
204 MyFileFullDirectoryInformation, /* = 2 */
205 MyFileBothDirectoryInformation, /* = 3 */
206 MyFileBasicInformation, /* = 4 */
207 MyFileStandardInformation, /* = 5 */
208 MyFileInternalInformation, /* = 6 */
209 MyFileEaInformation, /* = 7 */
210 MyFileAccessInformation, /* = 8 */
211 MyFileNameInformation, /* = 9 */
212 MyFileRenameInformation, /* = 10 */
213 MyFileLinkInformation, /* = 11 */
214 MyFileNamesInformation, /* = 12 */
215 MyFileDispositionInformation, /* = 13 */
216 MyFilePositionInformation, /* = 14 */
217 MyFileFullEaInformation, /* = 15 */
218 MyFileModeInformation, /* = 16 */
219 MyFileAlignmentInformation, /* = 17 */
220 MyFileAllInformation, /* = 18 */
221 MyFileAllocationInformation, /* = 19 */
222 MyFileEndOfFileInformation, /* = 20 */
223 MyFileAlternateNameInformation, /* = 21 */
224 MyFileStreamInformation, /* = 22 */
225 MyFilePipeInformation, /* = 23 */
226 MyFilePipeLocalInformation, /* = 24 */
227 MyFilePipeRemoteInformation, /* = 25 */
228 MyFileMailslotQueryInformation, /* = 26 */
229 MyFileMailslotSetInformation, /* = 27 */
230 MyFileCompressionInformation, /* = 28 */
231 MyFileObjectIdInformation, /* = 29 */
232 MyFileCompletionInformation, /* = 30 */
233 MyFileMoveClusterInformation, /* = 31 */
234 MyFileQuotaInformation, /* = 32 */
235 MyFileReparsePointInformation, /* = 33 */
236 MyFileNetworkOpenInformation, /* = 34 */
237 MyFileAttributeTagInformation, /* = 35 */
238 MyFileTrackingInformation, /* = 36 */
239 MyFileIdBothDirectoryInformation, /* = 37 */
240 MyFileIdFullDirectoryInformation, /* = 38 */
241 MyFileValidDataLengthInformation, /* = 39 */
242 MyFileShortNameInformation, /* = 40 */
243 MyFileIoCompletionNotificationInformation, /* = 41 */
244 MyFileIoStatusBlockRangeInformation, /* = 42 */
245 MyFileIoPriorityHintInformation, /* = 43 */
246 MyFileSfioReserveInformation, /* = 44 */
247 MyFileSfioVolumeInformation, /* = 45 */
248 MyFileHardLinkInformation, /* = 46 */
249 MyFileProcessIdsUsingFileInformation, /* = 47 */
250 MyFileNormalizedNameInformation, /* = 48 */
251 MyFileNetworkPhysicalNameInformation, /* = 49 */
252 MyFileIdGlobalTxDirectoryInformation, /* = 50 */
253 MyFileIsRemoteDeviceInformation, /* = 51 */
254 MyFileAttributeCacheInformation, /* = 52 */
255 MyFileNumaNodeInformation, /* = 53 */
256 MyFileStandardLinkInformation, /* = 54 */
257 MyFileRemoteProtocolInformation, /* = 55 */
258 MyFileMaximumInformation
259} MY_FILE_INFORMATION_CLASS;
260
261
262typedef struct MY_FILE_FS_VOLUME_INFORMATION
263{
264 LARGE_INTEGER VolumeCreationTime;
265 ULONG VolumeSerialNumber;
266 ULONG VolumeLabelLength;
267 BOOLEAN SupportsObjects;
268 WCHAR VolumeLabel[1];
269} MY_FILE_FS_VOLUME_INFORMATION;
270
271typedef enum MY_FSINFOCLASS
272{
273 MyFileFsVolumeInformation = 1,
274 MyFileFsLabelInformation, /* = 2 */
275 MyFileFsSizeInformation, /* = 3 */
276 MyFileFsDeviceInformation, /* = 4 */
277 MyFileFsAttributeInformation, /* = 5 */
278 MyFileFsControlInformation, /* = 6 */
279 MyFileFsFullSizeInformation, /* = 7 */
280 MyFileFsObjectIdInformation, /* = 8 */
281 MyFileFsDriverPathInformation, /* = 9 */
282 MyFileFsVolumeFlagsInformation, /* = 10 */
283 MyFileFsMaximumInformation
284} MY_FS_INFORMATION_CLASS;
285
286
287typedef struct MY_RTLP_CURDIR_REF
288{
289 LONG RefCount;
290 HANDLE Handle;
291} MY_RTLP_CURDIR_REF;
292
293typedef struct MY_RTL_RELATIVE_NAME_U
294{
295 MY_UNICODE_STRING RelativeName;
296 HANDLE ContainingDirectory;
297 MY_RTLP_CURDIR_REF CurDirRef;
298} MY_RTL_RELATIVE_NAME_U;
299
300
301#ifndef OBJ_INHERIT
302# define OBJ_INHERIT 0x00000002U
303# define OBJ_PERMANENT 0x00000010U
304# define OBJ_EXCLUSIVE 0x00000020U
305# define OBJ_CASE_INSENSITIVE 0x00000040U
306# define OBJ_OPENIF 0x00000080U
307# define OBJ_OPENLINK 0x00000100U
308# define OBJ_KERNEL_HANDLE 0x00000200U
309# define OBJ_FORCE_ACCESS_CHECK 0x00000400U
310# define OBJ_VALID_ATTRIBUTES 0x000007f2U
311#endif
312
313#ifndef FILE_OPEN
314# define FILE_SUPERSEDE 0x00000000U
315# define FILE_OPEN 0x00000001U
316# define FILE_CREATE 0x00000002U
317# define FILE_OPEN_IF 0x00000003U
318# define FILE_OVERWRITE 0x00000004U
319# define FILE_OVERWRITE_IF 0x00000005U
320# define FILE_MAXIMUM_DISPOSITION 0x00000005U
321#endif
322
323#ifndef FILE_DIRECTORY_FILE
324# define FILE_DIRECTORY_FILE 0x00000001U
325# define FILE_WRITE_THROUGH 0x00000002U
326# define FILE_SEQUENTIAL_ONLY 0x00000004U
327# define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008U
328# define FILE_SYNCHRONOUS_IO_ALERT 0x00000010U
329# define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020U
330# define FILE_NON_DIRECTORY_FILE 0x00000040U
331# define FILE_CREATE_TREE_CONNECTION 0x00000080U
332# define FILE_COMPLETE_IF_OPLOCKED 0x00000100U
333# define FILE_NO_EA_KNOWLEDGE 0x00000200U
334# define FILE_OPEN_REMOTE_INSTANCE 0x00000400U
335# define FILE_RANDOM_ACCESS 0x00000800U
336# define FILE_DELETE_ON_CLOSE 0x00001000U
337# define FILE_OPEN_BY_FILE_ID 0x00002000U
338# define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000U
339# define FILE_NO_COMPRESSION 0x00008000U
340# define FILE_RESERVE_OPFILTER 0x00100000U
341# define FILE_OPEN_REPARSE_POINT 0x00200000U
342# define FILE_OPEN_NO_RECALL 0x00400000U
343# define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000U
344#endif
345
346
347/** @name NT status codes and associated macros.
348 * @{ */
349#define MY_NT_SUCCESS(a_ntRc) ((MY_NTSTATUS)(a_ntRc) >= 0)
350#define MY_NT_FAILURE(a_ntRc) ((MY_NTSTATUS)(a_ntRc) < 0)
351#define MY_STATUS_NO_MORE_FILES ((MY_NTSTATUS)0x80000006)
352/** @} */
353
354
355/*******************************************************************************
356* Global Variables *
357*******************************************************************************/
358extern MY_NTSTATUS (WINAPI * g_pfnNtClose)(HANDLE);
359extern MY_NTSTATUS (WINAPI * g_pfnNtCreateFile)(PHANDLE, MY_ACCESS_MASK, MY_OBJECT_ATTRIBUTES *, MY_IO_STATUS_BLOCK *,
360 PLARGE_INTEGER, ULONG, ULONG, ULONG, ULONG, PVOID, ULONG);
361extern MY_NTSTATUS (WINAPI * g_pfnNtQueryInformationFile)(HANDLE, MY_IO_STATUS_BLOCK *,
362 PVOID, LONG, MY_FILE_INFORMATION_CLASS);
363extern MY_NTSTATUS (WINAPI * g_pfnNtQueryVolumeInformationFile)(HANDLE, MY_IO_STATUS_BLOCK *,
364 PVOID, LONG, MY_FS_INFORMATION_CLASS);
365extern MY_NTSTATUS (WINAPI * g_pfnNtQueryDirectoryFile)(HANDLE, HANDLE, MY_IO_APC_ROUTINE *, PVOID, MY_IO_STATUS_BLOCK *,
366 PVOID, ULONG, MY_FILE_INFORMATION_CLASS, BOOLEAN,
367 MY_UNICODE_STRING *, BOOLEAN);
368extern BOOLEAN (WINAPI * g_pfnRtlDosPathNameToNtPathName_U)(PCWSTR, MY_UNICODE_STRING *, PCWSTR *, MY_RTL_RELATIVE_NAME_U *);
369extern MY_NTSTATUS (WINAPI * g_pfnRtlAnsiStringToUnicodeString)(MY_UNICODE_STRING *, MY_ANSI_STRING const *, BOOLEAN);
370
371
372/** @} */
373
374#endif
375
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette