VirtualBox

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

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

kmk/WindowsNT: Avoiding unnecessary stat() calls. Reimplemented stat(), lstat(), fstat(), opendir(), readdir(), and closedir() using native NT APIs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 13.6 KB
Line 
1/* $Id: ntstuff.h 2702 2013-11-21 00:11:08Z bird $ */
2/** @file
3 * Definitions, types, prototypes and globals for NT.
4 */
5
6/*
7 * Copyright (c) 2005-2013 knut st. osmundsen <[email protected]>
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 enum MY_FILE_INFORMATION_CLASS
184{
185 MyFileDirectoryInformation = 1,
186 MyFileFullDirectoryInformation, /* = 2 */
187 MyFileBothDirectoryInformation, /* = 3 */
188 MyFileBasicInformation, /* = 4 */
189 MyFileStandardInformation, /* = 5 */
190 MyFileInternalInformation, /* = 6 */
191 MyFileEaInformation, /* = 7 */
192 MyFileAccessInformation, /* = 8 */
193 MyFileNameInformation, /* = 9 */
194 MyFileRenameInformation, /* = 10 */
195 MyFileLinkInformation, /* = 11 */
196 MyFileNamesInformation, /* = 12 */
197 MyFileDispositionInformation, /* = 13 */
198 MyFilePositionInformation, /* = 14 */
199 MyFileFullEaInformation, /* = 15 */
200 MyFileModeInformation, /* = 16 */
201 MyFileAlignmentInformation, /* = 17 */
202 MyFileAllInformation, /* = 18 */
203 MyFileAllocationInformation, /* = 19 */
204 MyFileEndOfFileInformation, /* = 20 */
205 MyFileAlternateNameInformation, /* = 21 */
206 MyFileStreamInformation, /* = 22 */
207 MyFilePipeInformation, /* = 23 */
208 MyFilePipeLocalInformation, /* = 24 */
209 MyFilePipeRemoteInformation, /* = 25 */
210 MyFileMailslotQueryInformation, /* = 26 */
211 MyFileMailslotSetInformation, /* = 27 */
212 MyFileCompressionInformation, /* = 28 */
213 MyFileObjectIdInformation, /* = 29 */
214 MyFileCompletionInformation, /* = 30 */
215 MyFileMoveClusterInformation, /* = 31 */
216 MyFileQuotaInformation, /* = 32 */
217 MyFileReparsePointInformation, /* = 33 */
218 MyFileNetworkOpenInformation, /* = 34 */
219 MyFileAttributeTagInformation, /* = 35 */
220 MyFileTrackingInformation, /* = 36 */
221 MyFileIdBothDirectoryInformation, /* = 37 */
222 MyFileIdFullDirectoryInformation, /* = 38 */
223 MyFileValidDataLengthInformation, /* = 39 */
224 MyFileShortNameInformation, /* = 40 */
225 MyFileIoCompletionNotificationInformation, /* = 41 */
226 MyFileIoStatusBlockRangeInformation, /* = 42 */
227 MyFileIoPriorityHintInformation, /* = 43 */
228 MyFileSfioReserveInformation, /* = 44 */
229 MyFileSfioVolumeInformation, /* = 45 */
230 MyFileHardLinkInformation, /* = 46 */
231 MyFileProcessIdsUsingFileInformation, /* = 47 */
232 MyFileNormalizedNameInformation, /* = 48 */
233 MyFileNetworkPhysicalNameInformation, /* = 49 */
234 MyFileIdGlobalTxDirectoryInformation, /* = 50 */
235 MyFileIsRemoteDeviceInformation, /* = 51 */
236 MyFileAttributeCacheInformation, /* = 52 */
237 MyFileNumaNodeInformation, /* = 53 */
238 MyFileStandardLinkInformation, /* = 54 */
239 MyFileRemoteProtocolInformation, /* = 55 */
240 MyFileMaximumInformation
241} MY_FILE_INFORMATION_CLASS;
242
243
244typedef struct MY_FILE_FS_VOLUME_INFORMATION
245{
246 LARGE_INTEGER VolumeCreationTime;
247 ULONG VolumeSerialNumber;
248 ULONG VolumeLabelLength;
249 BOOLEAN SupportsObjects;
250 WCHAR VolumeLabel[1];
251} MY_FILE_FS_VOLUME_INFORMATION;
252
253typedef enum MY_FSINFOCLASS
254{
255 MyFileFsVolumeInformation = 1,
256 MyFileFsLabelInformation, /* = 2 */
257 MyFileFsSizeInformation, /* = 3 */
258 MyFileFsDeviceInformation, /* = 4 */
259 MyFileFsAttributeInformation, /* = 5 */
260 MyFileFsControlInformation, /* = 6 */
261 MyFileFsFullSizeInformation, /* = 7 */
262 MyFileFsObjectIdInformation, /* = 8 */
263 MyFileFsDriverPathInformation, /* = 9 */
264 MyFileFsVolumeFlagsInformation, /* = 10 */
265 MyFileFsMaximumInformation
266} MY_FS_INFORMATION_CLASS;
267
268
269typedef struct MY_RTLP_CURDIR_REF
270{
271 LONG RefCount;
272 HANDLE Handle;
273} MY_RTLP_CURDIR_REF;
274
275typedef struct MY_RTL_RELATIVE_NAME_U
276{
277 MY_UNICODE_STRING RelativeName;
278 HANDLE ContainingDirectory;
279 MY_RTLP_CURDIR_REF CurDirRef;
280} MY_RTL_RELATIVE_NAME_U;
281
282
283#ifndef OBJ_INHERIT
284# define OBJ_INHERIT 0x00000002U
285# define OBJ_PERMANENT 0x00000010U
286# define OBJ_EXCLUSIVE 0x00000020U
287# define OBJ_CASE_INSENSITIVE 0x00000040U
288# define OBJ_OPENIF 0x00000080U
289# define OBJ_OPENLINK 0x00000100U
290# define OBJ_KERNEL_HANDLE 0x00000200U
291# define OBJ_FORCE_ACCESS_CHECK 0x00000400U
292# define OBJ_VALID_ATTRIBUTES 0x000007f2U
293#endif
294
295#ifndef FILE_OPEN
296# define FILE_SUPERSEDE 0x00000000U
297# define FILE_OPEN 0x00000001U
298# define FILE_CREATE 0x00000002U
299# define FILE_OPEN_IF 0x00000003U
300# define FILE_OVERWRITE 0x00000004U
301# define FILE_OVERWRITE_IF 0x00000005U
302# define FILE_MAXIMUM_DISPOSITION 0x00000005U
303#endif
304
305#ifndef FILE_DIRECTORY_FILE
306# define FILE_DIRECTORY_FILE 0x00000001U
307# define FILE_WRITE_THROUGH 0x00000002U
308# define FILE_SEQUENTIAL_ONLY 0x00000004U
309# define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008U
310# define FILE_SYNCHRONOUS_IO_ALERT 0x00000010U
311# define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020U
312# define FILE_NON_DIRECTORY_FILE 0x00000040U
313# define FILE_CREATE_TREE_CONNECTION 0x00000080U
314# define FILE_COMPLETE_IF_OPLOCKED 0x00000100U
315# define FILE_NO_EA_KNOWLEDGE 0x00000200U
316# define FILE_OPEN_REMOTE_INSTANCE 0x00000400U
317# define FILE_RANDOM_ACCESS 0x00000800U
318# define FILE_DELETE_ON_CLOSE 0x00001000U
319# define FILE_OPEN_BY_FILE_ID 0x00002000U
320# define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000U
321# define FILE_NO_COMPRESSION 0x00008000U
322# define FILE_RESERVE_OPFILTER 0x00100000U
323# define FILE_OPEN_REPARSE_POINT 0x00200000U
324# define FILE_OPEN_NO_RECALL 0x00400000U
325# define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000U
326#endif
327
328
329/** @name NT status codes and associated macros.
330 * @{ */
331#define MY_NT_SUCCESS(a_ntRc) ((MY_NTSTATUS)(a_ntRc) >= 0)
332#define MY_NT_FAILURE(a_ntRc) ((MY_NTSTATUS)(a_ntRc) < 0)
333#define MY_STATUS_NO_MORE_FILES ((MY_NTSTATUS)0x80000006)
334/** @} */
335
336
337/*******************************************************************************
338* Global Variables *
339*******************************************************************************/
340extern MY_NTSTATUS (WINAPI * g_pfnNtClose)(HANDLE);
341extern MY_NTSTATUS (WINAPI * g_pfnNtCreateFile)(PHANDLE, MY_ACCESS_MASK, MY_OBJECT_ATTRIBUTES *, MY_IO_STATUS_BLOCK *,
342 PLARGE_INTEGER, ULONG, ULONG, ULONG, ULONG, PVOID, ULONG);
343extern MY_NTSTATUS (WINAPI * g_pfnNtQueryInformationFile)(HANDLE, MY_IO_STATUS_BLOCK *,
344 PVOID, LONG, MY_FILE_INFORMATION_CLASS);
345extern MY_NTSTATUS (WINAPI * g_pfnNtQueryVolumeInformationFile)(HANDLE, MY_IO_STATUS_BLOCK *,
346 PVOID, LONG, MY_FS_INFORMATION_CLASS);
347extern MY_NTSTATUS (WINAPI * g_pfnNtQueryDirectoryFile)(HANDLE, HANDLE, MY_IO_APC_ROUTINE *, PVOID, MY_IO_STATUS_BLOCK *,
348 PVOID, ULONG, MY_FILE_INFORMATION_CLASS, BOOLEAN,
349 MY_UNICODE_STRING *, BOOLEAN);
350extern BOOLEAN (WINAPI * g_pfnRtlDosPathNameToNtPathName_U)(PCWSTR, MY_UNICODE_STRING *, PCWSTR *, MY_RTL_RELATIVE_NAME_U *);
351extern MY_NTSTATUS (WINAPI * g_pfnRtlAnsiStringToUnicodeString)(MY_UNICODE_STRING *, MY_ANSI_STRING const *, BOOLEAN);
352
353
354/** @} */
355
356#endif
357
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