[VFD] Import the VFD project (Virtual Floppy Drive) which allows creating virtual
[reactos.git] / modules / rosapps / drivers / vfd / imports.h
1 /*
2 imports.h
3
4 Virtual Floppy Drive for Windows NT platform
5 Kernel mode driver: imported elements from various sources
6
7 Copyright (C) 2003-2005 Ken Kato
8
9 This file contains:
10
11 a) #include directive for system headers
12
13 b) Stuff imported from newer DDKs so that the driver built with older
14 DDKs can run on newer Windows.
15
16 c) Stuff imported from ntifs.h (http://www.acc.umu.se/~bosse/) so that
17 the driver can be compiled without it.
18
19 d) Prototypes of standard functions which are exported from ntoskrnl.exe
20 but not declared in regular DDK header files.
21 */
22
23 #ifndef _IMPORTS_H_
24 #define _IMPORTS_H_
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif // __cplusplus
29
30 #ifdef _MSC_VER
31 #pragma warning(push,3)
32 #endif
33 #include <ntddk.h>
34 #include <ntdddisk.h>
35 #include <ntverp.h>
36 #ifdef _MSC_VER
37 #pragma warning(pop)
38 #endif
39
40 #ifdef _MSC_VER
41 // disable unwanted (and trivial) warnings :
42 // 4054 - type cast from a function pointer to a data pointer
43 // 4201 - anonymous structure
44 // 4514 - unreferenced inline function
45 #pragma warning(disable: 4054 4201 4514)
46 #endif
47
48 #if (VER_PRODUCTBUILD >= 2195)
49 #include <mountdev.h>
50 #else // (VER_PRODUCTBUILD < 2195)
51 //
52 // Imports from Windows 2000 DDK <ntddk.h>
53 //
54 typedef enum _MM_PAGE_PRIORITY {
55 LowPagePriority = 0,
56 NormalPagePriority = 16,
57 HighPagePriority = 32
58 } MM_PAGE_PRIORITY;
59
60 #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
61
62 #define FILE_DEVICE_MASS_STORAGE 0x0000002d
63
64 //
65 // Imports from Windows 2000 DDK <ntddstor.h>
66 //
67 #define IOCTL_STORAGE_CHECK_VERIFY2 CTL_CODE( \
68 IOCTL_STORAGE_BASE, \
69 0x0200, \
70 METHOD_BUFFERED, \
71 FILE_ANY_ACCESS)
72
73 //
74 // Imports from Windows 2000 DDK <mountmgr.h>, <mountdev.h>
75 //
76 #define MOUNTMGR_DEVICE_NAME L"\\Device\\MountPointManager"
77 #define MOUNTMGRCONTROLTYPE ((ULONG) 'm')
78 #define MOUNTDEVCONTROLTYPE ((ULONG) 'M')
79
80 #define IOCTL_MOUNTDEV_QUERY_UNIQUE_ID CTL_CODE( \
81 MOUNTDEVCONTROLTYPE,\
82 0, \
83 METHOD_BUFFERED, \
84 FILE_ANY_ACCESS)
85
86 #define IOCTL_MOUNTDEV_UNIQUE_ID_CHANGE_NOTIFY \
87 CTL_CODE( \
88 MOUNTDEVCONTROLTYPE,\
89 1, \
90 METHOD_BUFFERED, \
91 FILE_ANY_ACCESS)
92
93 #define IOCTL_MOUNTDEV_QUERY_DEVICE_NAME CTL_CODE( \
94 MOUNTDEVCONTROLTYPE,\
95 2, \
96 METHOD_BUFFERED, \
97 FILE_ANY_ACCESS)
98
99 #define IOCTL_MOUNTDEV_QUERY_SUGGESTED_LINK_NAME \
100 CTL_CODE( \
101 MOUNTDEVCONTROLTYPE,\
102 3, \
103 METHOD_BUFFERED, \
104 FILE_ANY_ACCESS)
105
106 #define IOCTL_MOUNTDEV_LINK_CREATED CTL_CODE( \
107 MOUNTDEVCONTROLTYPE,\
108 4, \
109 METHOD_BUFFERED, \
110 FILE_ANY_ACCESS)
111
112 #define IOCTL_MOUNTDEV_LINK_DELETED CTL_CODE( \
113 MOUNTDEVCONTROLTYPE,\
114 5, \
115 METHOD_BUFFERED, \
116 FILE_ANY_ACCESS)
117
118 #define IOCTL_MOUNTMGR_CREATE_POINT CTL_CODE( \
119 MOUNTMGRCONTROLTYPE,\
120 0, \
121 METHOD_BUFFERED, \
122 FILE_READ_ACCESS | FILE_WRITE_ACCESS)
123
124 #define IOCTL_MOUNTMGR_DELETE_POINTS CTL_CODE( \
125 MOUNTMGRCONTROLTYPE,\
126 1, \
127 METHOD_BUFFERED, \
128 FILE_READ_ACCESS | FILE_WRITE_ACCESS)
129
130 #define IOCTL_MOUNTMGR_VOLUME_ARRIVAL_NOTIFICATION \
131 CTL_CODE( \
132 MOUNTMGRCONTROLTYPE,\
133 11, \
134 METHOD_BUFFERED, \
135 FILE_READ_ACCESS)
136
137 typedef struct _MOUNTDEV_UNIQUE_ID {
138 USHORT UniqueIdLength;
139 UCHAR UniqueId[1];
140 } MOUNTDEV_UNIQUE_ID, *PMOUNTDEV_UNIQUE_ID;
141
142 typedef struct _MOUNTDEV_NAME {
143 USHORT NameLength;
144 WCHAR Name[1];
145 } MOUNTDEV_NAME, *PMOUNTDEV_NAME;
146
147 typedef struct _MOUNTDEV_SUGGESTED_LINK_NAME {
148 BOOLEAN UseOnlyIfThereAreNoOtherLinks;
149 USHORT NameLength;
150 WCHAR Name[1];
151 } MOUNTDEV_SUGGESTED_LINK_NAME, *PMOUNTDEV_SUGGESTED_LINK_NAME;
152
153 typedef struct _MOUNTMGR_TARGET_NAME {
154 USHORT DeviceNameLength;
155 WCHAR DeviceName[1];
156 } MOUNTMGR_TARGET_NAME, *PMOUNTMGR_TARGET_NAME;
157
158 typedef struct _MOUNTMGR_CREATE_POINT_INPUT {
159 USHORT SymbolicLinkNameOffset;
160 USHORT SymbolicLinkNameLength;
161 USHORT DeviceNameOffset;
162 USHORT DeviceNameLength;
163 } MOUNTMGR_CREATE_POINT_INPUT, *PMOUNTMGR_CREATE_POINT_INPUT;
164
165 typedef struct _MOUNTMGR_MOUNT_POINT {
166 ULONG SymbolicLinkNameOffset;
167 USHORT SymbolicLinkNameLength;
168 ULONG UniqueIdOffset;
169 USHORT UniqueIdLength;
170 ULONG DeviceNameOffset;
171 USHORT DeviceNameLength;
172 } MOUNTMGR_MOUNT_POINT, *PMOUNTMGR_MOUNT_POINT;
173
174 typedef struct _MOUNTMGR_MOUNT_POINTS {
175 ULONG Size;
176 ULONG NumberOfMountPoints;
177 MOUNTMGR_MOUNT_POINT MountPoints[1];
178 } MOUNTMGR_MOUNT_POINTS, *PMOUNTMGR_MOUNT_POINTS;
179
180 #endif // (VER_PRODUCTBUILD < 2195)
181
182 #if (VER_PRODUCTBUILD < 2600)
183 //
184 // Imports from Windows XP DDK <ntdddisk.h>
185 //
186 #define IOCTL_DISK_GET_PARTITION_INFO_EX CTL_CODE( \
187 IOCTL_DISK_BASE, \
188 0x0012, \
189 METHOD_BUFFERED, \
190 FILE_ANY_ACCESS)
191
192 #define IOCTL_DISK_GET_LENGTH_INFO CTL_CODE( \
193 IOCTL_DISK_BASE, \
194 0x0017, \
195 METHOD_BUFFERED, \
196 FILE_READ_ACCESS)
197
198 typedef unsigned __int64 ULONG64, *PULONG64;
199
200 typedef enum _PARTITION_STYLE {
201 PARTITION_STYLE_MBR,
202 PARTITION_STYLE_GPT
203 } PARTITION_STYLE;
204
205 typedef struct _PARTITION_INFORMATION_MBR {
206 UCHAR PartitionType;
207 BOOLEAN BootIndicator;
208 BOOLEAN RecognizedPartition;
209 ULONG HiddenSectors;
210 } PARTITION_INFORMATION_MBR, *PPARTITION_INFORMATION_MBR;
211
212 typedef struct _PARTITION_INFORMATION_GPT {
213 GUID PartitionType;
214 GUID PartitionId;
215 ULONG64 Attributes;
216 WCHAR Name[36];
217 } PARTITION_INFORMATION_GPT, *PPARTITION_INFORMATION_GPT;
218
219 typedef struct _PARTITION_INFORMATION_EX {
220 PARTITION_STYLE PartitionStyle;
221 LARGE_INTEGER StartingOffset;
222 LARGE_INTEGER PartitionLength;
223 ULONG PartitionNumber;
224 BOOLEAN RewritePartition;
225 union {
226 PARTITION_INFORMATION_MBR Mbr;
227 PARTITION_INFORMATION_GPT Gpt;
228 };
229 } PARTITION_INFORMATION_EX, *PPARTITION_INFORMATION_EX;
230
231 typedef struct _GET_LENGTH_INFORMATION {
232 LARGE_INTEGER Length;
233 } GET_LENGTH_INFORMATION, *PGET_LENGTH_INFORMATION;
234
235 //
236 // Imports from Windows XP DDK <ntddstor.h>
237 //
238 #define IOCTL_STORAGE_GET_HOTPLUG_INFO CTL_CODE( \
239 IOCTL_STORAGE_BASE, \
240 0x0305, \
241 METHOD_BUFFERED, \
242 FILE_ANY_ACCESS)
243
244 typedef struct _STORAGE_HOTPLUG_INFO {
245 ULONG Size;
246 BOOLEAN MediaRemovable;
247 BOOLEAN MediaHotplug;
248 BOOLEAN DeviceHotplug;
249 BOOLEAN WriteCacheEnableOverride;
250 } STORAGE_HOTPLUG_INFO, *PSTORAGE_HOTPLUG_INFO;
251
252 //
253 // Imports from Windows XP DDK <mountdev.h>
254 //
255 #define IOCTL_MOUNTDEV_QUERY_STABLE_GUID CTL_CODE( \
256 MOUNTDEVCONTROLTYPE,\
257 6, \
258 METHOD_BUFFERED, \
259 FILE_ANY_ACCESS)
260
261 typedef struct _MOUNTDEV_STABLE_GUID {
262 GUID StableGuid;
263 } MOUNTDEV_STABLE_GUID, *PMOUNTDEV_STABLE_GUID;
264
265 #endif // (VER_PRODUCTBUILD < 2600)
266
267 //
268 // Imports from ntifs.h
269 //
270 #define TOKEN_SOURCE_LENGTH 8
271
272 typedef enum _TOKEN_TYPE {
273 TokenPrimary = 1,
274 TokenImpersonation
275 } TOKEN_TYPE;
276
277 typedef struct _TOKEN_SOURCE {
278 CCHAR SourceName[TOKEN_SOURCE_LENGTH];
279 LUID SourceIdentifier;
280 } TOKEN_SOURCE, *PTOKEN_SOURCE;
281
282 typedef struct _TOKEN_CONTROL {
283 LUID TokenId;
284 LUID AuthenticationId;
285 LUID ModifiedId;
286 TOKEN_SOURCE TokenSource;
287 } TOKEN_CONTROL, *PTOKEN_CONTROL;
288
289 typedef struct _SECURITY_CLIENT_CONTEXT {
290 SECURITY_QUALITY_OF_SERVICE SecurityQos;
291 PACCESS_TOKEN ClientToken;
292 BOOLEAN DirectlyAccessClientToken;
293 BOOLEAN DirectAccessEffectiveOnly;
294 BOOLEAN ServerIsRemote;
295 TOKEN_CONTROL ClientTokenControl;
296 } SECURITY_CLIENT_CONTEXT, *PSECURITY_CLIENT_CONTEXT;
297
298 #define PsDereferenceImpersonationToken(T) \
299 if (ARGUMENT_PRESENT(T)) (ObDereferenceObject((T)))
300
301 #define PsDereferencePrimaryToken(T) (ObDereferenceObject((T)))
302
303 NTKERNELAPI
304 VOID
305 NTAPI
306 PsRevertToSelf (
307 VOID
308 );
309
310 NTKERNELAPI
311 NTSTATUS
312 NTAPI
313 SeCreateClientSecurity (
314 IN PETHREAD Thread,
315 IN PSECURITY_QUALITY_OF_SERVICE QualityOfService,
316 IN BOOLEAN RemoteClient,
317 OUT PSECURITY_CLIENT_CONTEXT ClientContext
318 );
319
320 #define SeDeleteClientSecurity(C) \
321 { \
322 if (SeTokenType((C)->ClientToken) == TokenPrimary) { \
323 PsDereferencePrimaryToken((C)->ClientToken); \
324 } \
325 else { \
326 PsDereferenceImpersonationToken((C)->ClientToken); \
327 } \
328 }
329
330 NTKERNELAPI
331 VOID
332 NTAPI
333 SeImpersonateClient (
334 IN PSECURITY_CLIENT_CONTEXT ClientContext,
335 IN PETHREAD ServerThread OPTIONAL
336 );
337
338 NTKERNELAPI
339 TOKEN_TYPE
340 NTAPI
341 SeTokenType (
342 IN PACCESS_TOKEN Token
343 );
344
345 //
346 // Functions exported by ntoskrnl.exe, but not declared in DDK headers
347 //
348 int _snprintf(char *buffer, size_t count, const char *format, ...);
349 int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format, ...);
350 int sprintf(char *buffer, const char *format, ...);
351 int _swprintf(wchar_t *buffer, const wchar_t *format, ...);
352
353 #ifdef __cplusplus
354 }
355 #endif // __cplusplus
356
357 #endif // _IMPORTS_H_