Corrected the handle generation algorithm in the kernel and csrss
[reactos.git] / reactos / include / ddk / iotypes.h
1 /* $Id: iotypes.h,v 1.15 2000/03/26 22:00:06 dwelch Exp $
2 *
3 */
4
5 #ifndef __INCLUDE_DDK_IOTYPES_H
6 #define __INCLUDE_DDK_IOTYPES_H
7
8 /*
9 * These are referenced before they can be fully defined
10 */
11 struct _DRIVER_OBJECT;
12 struct _FILE_OBJECT;
13 struct _DEVICE_OBJECT;
14 struct _IRP;
15 struct _IO_STATUS_BLOCK;
16
17 /* SIMPLE TYPES *************************************************************/
18
19 enum
20 {
21 DeallocateObject,
22 KeepObject,
23 };
24
25
26 typedef enum _CREATE_FILE_TYPE
27 {
28 CreateFileTypeNone,
29 CreateFileTypeNamedPipe,
30 CreateFileTypeMailslot
31 } CREATE_FILE_TYPE;
32
33
34 /*
35 * FIXME: Definition needed
36 */
37 typedef struct _SHARE_ACCESS
38 {
39 } SHARE_ACCESS, *PSHARE_ACCESS;
40
41 /* FUNCTION TYPES ************************************************************/
42
43 typedef VOID (*PDRIVER_REINITIALIZE)(struct _DRIVER_OBJECT* DriverObject,
44 PVOID Context,
45 ULONG Count);
46
47 typedef NTSTATUS (*PIO_QUERY_DEVICE_ROUTINE)(PVOID Context,
48 PUNICODE_STRING Pathname,
49 INTERFACE_TYPE BusType,
50 ULONG BusNumber,
51 PKEY_VALUE_FULL_INFORMATION* BI,
52 CONFIGURATION_TYPE ControllerType,
53 ULONG ControllerNumber,
54 PKEY_VALUE_FULL_INFORMATION* CI,
55 CONFIGURATION_TYPE PeripheralType,
56 ULONG PeripheralNumber,
57 PKEY_VALUE_FULL_INFORMATION* PI);
58
59 typedef NTSTATUS (*PIO_COMPLETION_ROUTINE)(struct _DEVICE_OBJECT* DeviceObject,
60 struct _IRP* Irp,
61 PVOID Context);
62
63 typedef VOID (*PIO_APC_ROUTINE) (PVOID ApcContext,
64 struct _IO_STATUS_BLOCK* IoStatusBlock,
65 ULONG Reserved);
66
67
68 /* STRUCTURE TYPES ***********************************************************/
69
70 typedef struct _ADAPTER_OBJECT
71 {
72 } ADAPTER_OBJECT, *PADAPTER_OBJECT;
73
74 /*
75 * PURPOSE: Special timer associated with each device
76 * NOTES: This is a guess
77 */
78 typedef struct _IO_TIMER
79 {
80 KTIMER timer;
81 KDPC dpc;
82 } IO_TIMER, *PIO_TIMER;
83
84 typedef struct _IO_SECURITY_CONTEXT
85 {
86 PSECURITY_QUALITY_OF_SERVICE SecurityQos;
87 PACCESS_STATE AccessState;
88 ACCESS_MASK DesiredAccess;
89 ULONG FullCreateOptions;
90 } IO_SECURITY_CONTEXT, *PIO_SECURITY_CONTEXT;
91
92 /*
93 * PURPOSE: IRP stack location
94 */
95 typedef struct _IO_STACK_LOCATION
96 {
97 UCHAR MajorFunction;
98 UCHAR MinorFunction;
99 UCHAR Flags;
100 UCHAR Control;
101
102 union
103 {
104 struct
105 {
106 PIO_SECURITY_CONTEXT SecurityContext;
107 ULONG Options;
108 USHORT FileAttributes;
109 USHORT ShareAccess;
110 ULONG EaLength;
111 } Create;
112 struct
113 {
114 ULONG Length;
115 ULONG Key;
116 LARGE_INTEGER ByteOffset;
117 } Read;
118 struct
119 {
120 ULONG Length;
121 ULONG Key;
122 LARGE_INTEGER ByteOffset;
123 } Write;
124 struct
125 {
126 ULONG OutputBufferLength;
127 ULONG InputBufferLength;
128 ULONG IoControlCode;
129 PVOID Type3InputBuffer;
130 } DeviceIoControl;
131 struct
132 {
133 struct _VPB* Vpb;
134 struct _DEVICE_OBJECT* DeviceObject;
135 } Mount;
136 struct {
137 ULONG Length;
138 FILE_INFORMATION_CLASS FileInformationClass;
139 } QueryFile;
140 struct {
141 ULONG Length;
142 FS_INFORMATION_CLASS FileInformationClass;
143 } QueryVolume;
144 struct {
145 ULONG Length;
146 FS_INFORMATION_CLASS FileInformationClass;
147 } SetVolume;
148 struct {
149 ULONG Length;
150 FILE_INFORMATION_CLASS FileInformationClass;
151 struct _FILE_OBJECT* FileObject;
152 union {
153 struct {
154 BOOLEAN ReplaceIfExists;
155 BOOLEAN AdvanceOnly;
156 } d;
157 ULONG ClusterCount;
158 HANDLE DeleteHandle;
159 } u;
160 } SetFile;
161 struct
162 {
163 ULONG Length;
164 PUNICODE_STRING FileName;
165 FILE_INFORMATION_CLASS FileInformationClass;
166 ULONG FileIndex;
167 } QueryDirectory;
168 struct
169 {
170 ULONG FileAttributes;
171 ULONG OpenMode;
172 ULONG PipeType;
173 ULONG PipeRead;
174 ULONG PipeWait;
175 ULONG MaxInstances;
176 ULONG InBufferSize;
177 ULONG OutBufferSize;
178 LARGE_INTEGER Timeout;
179 } CreateNamedPipe;
180 } Parameters;
181
182 PIO_COMPLETION_ROUTINE CompletionRoutine;
183 PVOID CompletionContext;
184
185 struct _DEVICE_OBJECT* DeviceObject;
186
187 struct _FILE_OBJECT* FileObject;
188 } IO_STACK_LOCATION, *PIO_STACK_LOCATION;
189
190 typedef struct _IO_STATUS_BLOCK
191 {
192 NTSTATUS Status;
193 ULONG Information;
194 } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
195
196 /*
197 * Driver entry point declaration
198 */
199 typedef NTSTATUS (*PDRIVER_INITIALIZE)(struct _DRIVER_OBJECT* DriverObject,
200 PUNICODE_STRING RegistryPath);
201
202 /*
203 * Driver cancel declaration
204 */
205 typedef NTSTATUS (*PDRIVER_CANCEL)(struct _DEVICE_OBJECT* DeviceObject,
206 struct _IRP* RegistryPath);
207
208
209 typedef struct _SECTION_OBJECT_POINTERS
210 {
211 PVOID DataSectionObject;
212 PVOID SharedCacheMap;
213 PVOID ImageSectionObject;
214 } SECTION_OBJECT_POINTERS, *PSECTION_OBJECT_POINTERS;
215
216 typedef struct _IO_COMPLETION_CONTEXT
217 {
218 PVOID Port;
219 ULONG Key;
220 } IO_COMPLETION_CONTEXT, *PIO_COMPLETION_CONTEXT;
221
222 #define FO_FILE_OPEN 0x00000001
223 #define FO_SYNCHRONOUS_IO 0x00000002
224 #define FO_ALERTABLE_IO 0x00000004
225 #define FO_NO_INTERMEDIATE_BUFFERING 0x00000008
226 #define FO_WRITE_THROUGH 0x00000010
227 #define FO_SEQUENTIAL_ONLY 0x00000020
228 #define FO_CACHE_SUPPORTED 0x00000040
229 #define FO_NAMED_PIPE 0x00000080
230 #define FO_STREAM_FILE 0x00000100
231 #define FO_MAILSLOT 0x00000200
232 #define FO_GENERATE_AUDIT_ON_CLOSE 0x00000400
233 #define FO_DIRECT_DEVICE_OPEN 0x00000800
234 #define FO_FILE_MODIFIED 0x00001000
235 #define FO_FILE_SIZE_CHANGED 0x00002000
236 #define FO_CLEANUP_COMPLETE 0x00004000
237 #define FO_TEMPORARY_FILE 0x00008000
238 #define FO_DELETE_ON_CLOSE 0x00010000
239 #define FO_OPENED_CASE_SENSITIVE 0x00020000
240 #define FO_HANDLE_CREATED 0x00040000
241 #define FO_FILE_FAST_IO_READ 0x00080000
242
243 typedef struct _FILE_OBJECT
244 {
245 CSHORT Type;
246 CSHORT Size;
247 struct _DEVICE_OBJECT* DeviceObject;
248 struct _VPB* Vpb;
249 PVOID FsContext;
250 PVOID FsContext2;
251 PSECTION_OBJECT_POINTERS SectionObjectPointers;
252 PVOID PrivateCacheMap;
253 NTSTATUS FinalStatus;
254 struct _FILE_OBJECT* RelatedFileObject;
255 BOOLEAN LockOperation;
256 BOOLEAN DeletePending;
257 BOOLEAN ReadAccess;
258 BOOLEAN WriteAccess;
259 BOOLEAN DeleteAccess;
260 BOOLEAN SharedRead;
261 BOOLEAN SharedWrite;
262 BOOLEAN SharedDelete;
263 ULONG Flags;
264 UNICODE_STRING FileName;
265 LARGE_INTEGER CurrentByteOffset;
266 ULONG Waiters;
267 ULONG Busy;
268 PVOID LastLock;
269 KEVENT Lock;
270 KEVENT Event;
271 PIO_COMPLETION_CONTEXT CompletionContext;
272 } FILE_OBJECT, *PFILE_OBJECT;
273
274
275 typedef struct _IRP
276 {
277 CSHORT Type;
278 USHORT Size;
279 PMDL MdlAddress;
280 ULONG Flags;
281 union
282 {
283 struct _IRP* MasterIrp;
284 LONG IrpCount;
285 PVOID SystemBuffer;
286 } AssociatedIrp;
287 LIST_ENTRY ThreadListEntry;
288 IO_STATUS_BLOCK IoStatus;
289 KPROCESSOR_MODE RequestorMode;
290 BOOLEAN PendingReturned;
291 BOOLEAN Cancel;
292 KIRQL CancelIrql;
293 PDRIVER_CANCEL CancelRoutine;
294 PVOID UserBuffer;
295 PVOID ApcEnvironment;
296 ULONG AllocationFlags;
297 PIO_STATUS_BLOCK UserIosb;
298 PKEVENT UserEvent;
299 union
300 {
301 struct
302 {
303 PIO_APC_ROUTINE UserApcRoutine;
304 PVOID UserApcContext;
305 } AsynchronousParameters;
306 LARGE_INTEGER AllocationSize;
307 } Overlay;
308 union
309 {
310 struct
311 {
312 KDEVICE_QUEUE_ENTRY DeviceQueueEntry;
313 struct _ETHREAD* Thread;
314 PCHAR AuxiliaryBuffer;
315 LIST_ENTRY ListEntry;
316 struct _IO_STACK_LOCATION* CurrentStackLocation;
317 PFILE_OBJECT OriginalFileObject;
318 } Overlay;
319 KAPC Apc;
320 ULONG CompletionKey;
321 } Tail;
322 CHAR StackCount;
323 CHAR CurrentLocation;
324 IO_STACK_LOCATION Stack[1];
325 } IRP, *PIRP;
326
327 #define VPB_MOUNTED 0x00000001
328 #define VPB_LOCKED 0x00000002
329 #define VPB_PERSISTENT 0x00000004
330 #define VPB_REMOVE_PENDING 0x00000008
331
332 typedef struct _VPB
333 {
334 CSHORT Type;
335 CSHORT Size;
336 USHORT Flags;
337 USHORT VolumeLabelLength;
338 struct _DEVICE_OBJECT* DeviceObject;
339 struct _DEVICE_OBJECT* RealDevice;
340 ULONG SerialNumber;
341 ULONG ReferenceCount;
342 WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH];
343 } VPB, *PVPB;
344
345
346 typedef struct _DEVICE_OBJECT
347 {
348 CSHORT Type;
349 CSHORT Size;
350 LONG ReferenceCount;
351 struct _DRIVER_OBJECT* DriverObject;
352 struct _DEVICE_OBJECT* NextDevice;
353 struct _DEVICE_OBJECT* AttachedDevice;
354 struct _IRP* CurrentIrp;
355 PIO_TIMER Timer;
356 ULONG Flags;
357 ULONG Characteristics;
358 PVPB Vpb;
359 PVOID DeviceExtension;
360 DEVICE_TYPE DeviceType;
361 CCHAR StackSize;
362 union
363 {
364 LIST_ENTRY ListHead;
365 WAIT_CONTEXT_BLOCK Wcb;
366 } Queue;
367 ULONG AlignmentRequirement;
368 KDEVICE_QUEUE DeviceQueue;
369 KDPC Dpc;
370 ULONG ActiveThreadCount;
371 PSECURITY_DESCRIPTOR SecurityDescriptor;
372 KEVENT DeviceLock;
373 USHORT SectorSize;
374 USHORT Spare1;
375 struct _DEVOBJ_EXTENSION* DeviceObjectExtension;
376 PVOID Reserved;
377 } DEVICE_OBJECT, *PDEVICE_OBJECT;
378
379 /*
380 * Dispatch routine type declaration
381 */
382 typedef NTSTATUS (*PDRIVER_DISPATCH)(struct _DEVICE_OBJECT*, IRP*);
383
384 /*
385 * Fast i/o routine type declaration
386 */
387 typedef NTSTATUS (*PFAST_IO_DISPATCH)(struct _DEVICE_OBJECT*, IRP*);
388
389 /*
390 * Dispatch routine type declaration
391 */
392 typedef VOID (*PDRIVER_STARTIO)(struct _DEVICE_OBJECT*, IRP*);
393
394 /*
395 * Dispatch routine type declaration
396 */
397 typedef NTSTATUS (*PDRIVER_UNLOAD)(struct _DRIVER_OBJECT*);
398
399 typedef struct _DRIVER_EXTENSION
400 {
401 struct _DRIVER_OBJECT* DriverObject;
402 PDRIVER_ADD_DEVICE AddDevice;
403 ULONG Count;
404 UNICODE_STRING ServiceKeyName;
405 } DRIVER_EXTENSION, *PDRIVER_EXTENSION;
406
407 #if 0
408 typedef
409 struct _FAST_IO_DISPATCH_TABLE
410 {
411 ULONG Count;
412 PFAST_IO_DISPATCH Dispatch;
413
414 } FAST_IO_DISPATCH_TABLE, * PFAST_IO_DISPATCH_TABLE;
415 #endif
416
417 typedef struct _DRIVER_OBJECT
418 {
419 CSHORT Type;
420 CSHORT Size;
421 PDEVICE_OBJECT DeviceObject;
422 ULONG Flags;
423 PVOID DriverStart;
424 ULONG DriverSize;
425 PVOID DriverSection;
426 PDRIVER_EXTENSION DriverExtension;
427 UNICODE_STRING DriverName;
428 PUNICODE_STRING HardwareDatabase;
429 #if 0
430 PFAST_IO_DISPATCH_TABLE FastIoDispatch;
431 #else
432 PFAST_IO_DISPATCH FastIoDispatch;
433 #endif
434 PDRIVER_INITIALIZE DriverInit;
435 PDRIVER_STARTIO DriverStartIo;
436 PDRIVER_UNLOAD DriverUnload;
437 PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1];
438 } DRIVER_OBJECT, *PDRIVER_OBJECT;
439
440
441 typedef struct _CONFIGURATION_INFORMATION
442 {
443 ULONG DiskCount;
444 ULONG FloppyCount;
445 ULONG CDRomCount;
446 ULONG TapeCount;
447 ULONG ScsiPortCount;
448 ULONG SerialCount;
449 ULONG ParallelCount;
450 BOOLEAN AtDiskPrimaryAddressClaimed;
451 BOOLEAN AtDiskSecondaryAddressClaimed;
452 } CONFIGURATION_INFORMATION, *PCONFIGURATION_INFORMATION;
453
454 typedef VOID (*PIO_DPC_ROUTINE)(PKDPC Dpc,
455 PDEVICE_OBJECT DeviceObject,
456 PIRP Irp,
457 PVOID Context);
458
459 typedef VOID (*PIO_TIMER_ROUTINE)(PDEVICE_OBJECT DeviceObject,
460 PVOID Context);
461
462 #if WINDOWS_STRUCTS_DOESNT_ALREADY_DEFINE_THIS
463 typedef struct _PARTITION_INFORMATION
464 {
465 LARGE_INTEGER StartingOffset;
466 LARGE_INTEGER PartitionLength;
467 ULONG HiddenSectors;
468 ULONG PartitionNumber;
469 UCHAR PartitionType;
470 BOOLEAN BootIndicator;
471 BOOLEAN RecognizedPartition;
472 BOOLEAN RewritePartition;
473 } PARTITION_INFORMATION, *PPARTITION_INFORMATION;
474 #endif
475
476 typedef struct _DRIVER_LAYOUT_INFORMATION
477 {
478 ULONG PartitionCount;
479 ULONG Signature;
480 PARTITION_INFORMATION PartitionEntry[1];
481 } DRIVER_LAYOUT_INFORMATION, *PDRIVER_LAYOUT_INFORMATION;
482
483
484
485
486
487 typedef struct _IO_RESOURCE_DESCRIPTOR
488 {
489 UCHAR Option;
490 UCHAR Type;
491 UCHAR SharedDisposition;
492
493 /*
494 * Reserved for system use
495 */
496 UCHAR Spare1;
497
498 USHORT Flags;
499
500 /*
501 * Reserved for system use
502 */
503 UCHAR Spare2;
504
505 union
506 {
507 struct
508 {
509 ULONG Length;
510 ULONG Alignment;
511 PHYSICAL_ADDRESS MinimumAddress;
512 PHYSICAL_ADDRESS MaximumAddress;
513 } Port;
514 struct
515 {
516 ULONG Length;
517 ULONG Alignment;
518 PHYSICAL_ADDRESS MinimumAddress;
519 PHYSICAL_ADDRESS MaximumAddress;
520 } Memory;
521 struct
522 {
523 ULONG MinimumVector;
524 ULONG MaximumVector;
525 } Interrupt;
526 struct
527 {
528 ULONG MinimumChannel;
529 ULONG MaximumChannel;
530 } Dma;
531 } u;
532 } IO_RESOURCE_DESCRIPTOR, *PIO_RESOURCE_DESCRIPTOR;
533
534 typedef struct _IO_RESOURCE_LIST
535 {
536 USHORT Version;
537 USHORT Revision;
538 ULONG Count;
539 IO_RESOURCE_DESCRIPTOR Descriptors[1];
540 } IO_RESOURCE_LIST, *PIO_RESOURCE_LIST;
541
542 typedef struct _IO_RESOURCES_REQUIREMENTS_LIST
543 {
544 /*
545 * List size in bytes
546 */
547 ULONG ListSize;
548
549 /*
550 * System defined enum for the bus
551 */
552 INTERFACE_TYPE InterfaceType;
553
554 ULONG BusNumber;
555 ULONG SlotNumber;
556 ULONG Reserved[3];
557 ULONG AlternativeLists;
558 IO_RESOURCE_LIST List[1];
559 } IO_RESOURCES_REQUIREMENTS_LIST, *PIO_RESOURCE_REQUIREMENTS_LIST;
560
561 typedef struct
562 {
563 UCHAR Type;
564 UCHAR ShareDisposition;
565 USHORT Flags;
566 union
567 {
568 struct
569 {
570 PHYSICAL_ADDRESS Start;
571 ULONG Length;
572 } Port;
573 struct
574 {
575 ULONG Level;
576 ULONG Vector;
577 ULONG Affinity;
578 } Interrupt;
579 struct
580 {
581 PHYSICAL_ADDRESS Start;
582 ULONG Length;
583 } Memory;
584 struct
585 {
586 ULONG Channel;
587 ULONG Port;
588 ULONG Reserved1;
589 } Dma;
590 struct
591 {
592 ULONG DataSize;
593 ULONG Reserved1;
594 ULONG Reserved2;
595 } DeviceSpecificData;
596 } u;
597 } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
598
599 typedef struct
600 {
601 USHORT Version;
602 USHORT Revision;
603 ULONG Count;
604 CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
605 } CM_PARTIAL_RESOURCE_LIST;
606
607 typedef struct
608 {
609 INTERFACE_TYPE InterfaceType;
610 ULONG BusNumber;
611 CM_PARTIAL_RESOURCE_LIST PartialResourceList;
612 } CM_FULL_RESOURCE_DESCRIPTOR;
613
614 typedef struct
615 {
616 ULONG Count;
617 CM_FULL_RESOURCE_DESCRIPTOR List[1];
618 } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
619
620
621 typedef
622 IO_ALLOCATION_ACTION
623 (*PDRIVER_CONTROL) (
624 PDEVICE_OBJECT DeviceObject,
625 PIRP irp,
626 PVOID MapRegisterBase,
627 PVOID Context
628 );
629 #if (_WIN32_WINNT >= 0x0400)
630 typedef
631 VOID
632 (*PFSDNOTIFICATIONPROC) (
633 IN PDEVICE_OBJECT PtrTargetFileSystemDeviceObject,
634 IN BOOLEAN DriverActive
635 );
636 #endif // (_WIN32_WINNT >= 0x0400)
637
638 enum
639 {
640 IO_NO_INCREMENT,
641 };
642
643 #endif __INCLUDE_DDK_IOTYPES_H