5835c66aa310fb915bdce1cd18562304962806eb
[reactos.git] / ntoskrnl / include / internal / io.h
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/include/internal/io.h
5 * PURPOSE: Internal header for the I/O Manager
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 #include "ntdddisk.h"
10
11 //
12 // Define this if you want debugging support
13 //
14 #define _IO_DEBUG_ 0x00
15
16 //
17 // These define the Debug Masks Supported
18 //
19 #define IO_IRP_DEBUG 0x01
20 #define IO_FILE_DEBUG 0x02
21 #define IO_API_DEBUG 0x04
22 #define IO_CTL_DEBUG 0x08
23
24 //
25 // Debug/Tracing support
26 //
27 #if _IO_DEBUG_
28 #ifdef NEW_DEBUG_SYSTEM_IMPLEMENTED // enable when Debug Filters are implemented
29 #define IOTRACE(x, ...) \
30 { \
31 DbgPrintEx("%s [%.16s] - ", \
32 __FUNCTION__, \
33 PsGetCurrentProcess()->ImageFileName); \
34 DbgPrintEx(__VA_ARGS__); \
35 }
36 #else
37 #define IOTRACE(x, ...) \
38 if (x & IopTraceLevel) \
39 { \
40 DbgPrint("%s [%.16s] - ", \
41 __FUNCTION__, \
42 PsGetCurrentProcess()->ImageFileName); \
43 DbgPrint(__VA_ARGS__); \
44 }
45 #endif
46 #else
47 #define IOTRACE(x, fmt, ...) DPRINT(fmt, ##__VA_ARGS__)
48 #endif
49
50 //
51 // Registry path to the enumeration root key
52 //
53 #define ENUM_ROOT L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum"
54
55 //
56 // Returns the type of METHOD_ used in this IOCTL
57 //
58 #define IO_METHOD_FROM_CTL_CODE(c) (c & 0x00000003)
59
60 //
61 // Bugcheck codes for RAM disk booting
62 //
63 //
64 // No LoaderXIPRom descriptor was found in the loader memory list
65 //
66 #define RD_NO_XIPROM_DESCRIPTOR 1
67 //
68 // Unable to open the RAM disk driver (ramdisk.sys or \Device\Ramdisk)
69 //
70 #define RD_NO_RAMDISK_DRIVER 2
71 //
72 // FSCTL_CREATE_RAM_DISK failed
73 //
74 #define RD_FSCTL_FAILED 3
75 //
76 // Unable to create GUID string from binary GUID
77 //
78 #define RD_GUID_CONVERT_FAILED 4
79 //
80 // Unable to create symbolic link pointing to the RAM disk device
81 //
82 #define RD_SYMLINK_CREATE_FAILED 5
83
84 //
85 // Max traversal of reparse points for a single open in IoParseDevice
86 //
87 #define IOP_MAX_REPARSE_TRAVERSAL 0x20
88
89 //
90 // Private flags for IoCreateFile / IoParseDevice
91 //
92 #define IOP_USE_TOP_LEVEL_DEVICE_HINT 0x01
93 #define IOP_CREATE_FILE_OBJECT_EXTENSION 0x02
94
95
96 typedef struct _FILE_OBJECT_EXTENSION
97 {
98 PDEVICE_OBJECT TopDeviceObjectHint;
99 PVOID FilterContext;
100
101 } FILE_OBJECT_EXTENSION, *PFILE_OBJECT_EXTENSION;
102
103
104
105 //
106 // We can call the Ob Inlined API, it's the same thing
107 //
108 #define IopAllocateMdlFromLookaside \
109 ObpAllocateObjectCreateInfoBuffer
110 #define IopFreeMdlFromLookaside \
111 ObpFreeCapturedAttributes
112
113 //
114 // Determines if the IRP is Synchronous
115 //
116 #define IsIrpSynchronous(Irp, FileObject) \
117 ((Irp->Flags & IRP_SYNCHRONOUS_API) || \
118 (!(FileObject) ? \
119 FALSE : \
120 FileObject->Flags & FO_SYNCHRONOUS_IO)) \
121
122 //
123 // Returns the internal Device Object Extension
124 //
125 #define IoGetDevObjExtension(DeviceObject) \
126 ((PEXTENDED_DEVOBJ_EXTENSION) \
127 (DeviceObject->DeviceObjectExtension)) \
128
129 //
130 // Returns the internal Driver Object Extension
131 //
132 #define IoGetDrvObjExtension(DriverObject) \
133 ((PEXTENDED_DRIVER_EXTENSION) \
134 (DriverObject->DriverExtension)) \
135
136 /*
137 * VOID
138 * IopDeviceNodeSetFlag(
139 * PDEVICE_NODE DeviceNode,
140 * ULONG Flag);
141 */
142 #define IopDeviceNodeSetFlag(DeviceNode, Flag) \
143 ((DeviceNode)->Flags |= (Flag))
144
145 /*
146 * VOID
147 * IopDeviceNodeClearFlag(
148 * PDEVICE_NODE DeviceNode,
149 * ULONG Flag);
150 */
151 #define IopDeviceNodeClearFlag(DeviceNode, Flag) \
152 ((DeviceNode)->Flags &= ~(Flag))
153
154 /*
155 * BOOLEAN
156 * IopDeviceNodeHasFlag(
157 * PDEVICE_NODE DeviceNode,
158 * ULONG Flag);
159 */
160 #define IopDeviceNodeHasFlag(DeviceNode, Flag) \
161 (((DeviceNode)->Flags & (Flag)) > 0)
162
163 /*
164 * VOID
165 * IopDeviceNodeSetUserFlag(
166 * PDEVICE_NODE DeviceNode,
167 * ULONG UserFlag);
168 */
169 #define IopDeviceNodeSetUserFlag(DeviceNode, UserFlag) \
170 ((DeviceNode)->UserFlags |= (UserFlag))
171
172 /*
173 * VOID
174 * IopDeviceNodeClearUserFlag(
175 * PDEVICE_NODE DeviceNode,
176 * ULONG UserFlag);
177 */
178 #define IopDeviceNodeClearUserFlag(DeviceNode, UserFlag)\
179 ((DeviceNode)->UserFlags &= ~(UserFlag))
180
181 /*
182 * BOOLEAN
183 * IopDeviceNodeHasUserFlag(
184 * PDEVICE_NODE DeviceNode,
185 * ULONG UserFlag);
186 */
187 #define IopDeviceNodeHasUserFlag(DeviceNode, UserFlag) \
188 (((DeviceNode)->UserFlags & (UserFlag)) > 0)
189
190 /*
191 * VOID
192 * IopDeviceNodeSetProblem(
193 * PDEVICE_NODE DeviceNode,
194 * ULONG Problem);
195 */
196 #define IopDeviceNodeSetProblem(DeviceNode, Problem) \
197 ((DeviceNode)->Problem |= (Problem))
198
199 /*
200 * VOID
201 * IopDeviceNodeClearProblem(
202 * PDEVICE_NODE DeviceNode,
203 * ULONG Problem);
204 */
205 #define IopDeviceNodeClearProblem(DeviceNode, Problem) \
206 ((DeviceNode)->Problem &= ~(Problem))
207
208 /*
209 * BOOLEAN
210 * IopDeviceNodeHasProblem(
211 * PDEVICE_NODE DeviceNode,
212 * ULONG Problem);
213 */
214 #define IopDeviceNodeHasProblem(DeviceNode, Problem) \
215 (((DeviceNode)->Problem & (Problem)) > 0)
216
217 /*
218 * VOID
219 * IopInitDeviceTreeTraverseContext(
220 * PDEVICETREE_TRAVERSE_CONTEXT DeviceTreeTraverseContext,
221 * PDEVICE_NODE DeviceNode,
222 * DEVICETREE_TRAVERSE_ROUTINE Action,
223 * PVOID Context);
224 */
225 #define IopInitDeviceTreeTraverseContext( \
226 _DeviceTreeTraverseContext, _DeviceNode, _Action, \
227 _Context) { \
228 (_DeviceTreeTraverseContext)->FirstDeviceNode = \
229 (_DeviceNode); \
230 (_DeviceTreeTraverseContext)->Action = (_Action); \
231 (_DeviceTreeTraverseContext)->Context = (_Context); }
232
233 /*
234 * BOOLEAN
235 * IopIsValidPhysicalDeviceObject(
236 * IN PDEVICE_OBJECT PhysicalDeviceObject);
237 */
238 #define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject) \
239 (((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject) && \
240 (((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode) && \
241 (((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode->Flags & DNF_ENUMERATED))
242
243 //
244 // Device List Operations
245 //
246 typedef enum _IOP_DEVICE_LIST_OPERATION
247 {
248 IopRemove,
249 IopAdd
250 } IOP_DEVICE_LIST_OPERATION, *PIOP_DEVICE_LIST_OPERATION;
251
252 //
253 // Transfer statistics
254 //
255 typedef enum _IOP_TRANSFER_TYPE
256 {
257 IopReadTransfer,
258 IopWriteTransfer,
259 IopOtherTransfer
260 } IOP_TRANSFER_TYPE, *PIOP_TRANSFER_TYPE;
261
262 //
263 // Packet Types when piggybacking on the IRP Overlay
264 //
265 typedef enum _COMPLETION_PACKET_TYPE
266 {
267 IopCompletionPacketIrp,
268 IopCompletionPacketMini,
269 IopCompletionPacketQuota
270 } COMPLETION_PACKET_TYPE, *PCOMPLETION_PACKET_TYPE;
271
272 //
273 // Special version of the IRP Overlay used to optimize I/O completion
274 // by not using up a separate structure.
275 //
276 typedef struct _IOP_MINI_COMPLETION_PACKET
277 {
278 struct
279 {
280 LIST_ENTRY ListEntry;
281 union
282 {
283 struct _IO_STACK_LOCATION *CurrentStackLocation;
284 ULONG PacketType;
285 };
286 };
287 PVOID KeyContext;
288 PVOID ApcContext;
289 NTSTATUS IoStatus;
290 ULONG_PTR IoStatusInformation;
291 } IOP_MINI_COMPLETION_PACKET, *PIOP_MINI_COMPLETION_PACKET;
292
293 //
294 // I/O Completion Context for IoSetIoCompletionRoutineEx
295 //
296 typedef struct _IO_UNLOAD_SAFE_COMPLETION_CONTEXT
297 {
298 PDEVICE_OBJECT DeviceObject;
299 PVOID Context;
300 PIO_COMPLETION_ROUTINE CompletionRoutine;
301 } IO_UNLOAD_SAFE_COMPLETION_CONTEXT, *PIO_UNLOAD_SAFE_COMPLETION_CONTEXT;
302
303 //
304 // I/O Wrapper around the Executive Work Item
305 //
306 typedef struct _IO_WORKITEM
307 {
308 WORK_QUEUE_ITEM Item;
309 PDEVICE_OBJECT DeviceObject;
310 PIO_WORKITEM_ROUTINE WorkerRoutine;
311 PVOID Context;
312 } IO_WORKITEM;
313
314 //
315 // I/O Wrapper around the Kernel Interrupt
316 //
317 typedef struct _IO_INTERRUPT
318 {
319 KINTERRUPT FirstInterrupt;
320 PKINTERRUPT Interrupt[MAXIMUM_PROCESSORS];
321 KSPIN_LOCK SpinLock;
322 } IO_INTERRUPT, *PIO_INTERRUPT;
323
324 //
325 // I/O Error Log Packet Header
326 //
327 typedef struct _ERROR_LOG_ENTRY
328 {
329 CSHORT Type;
330 CSHORT Size;
331 LIST_ENTRY ListEntry;
332 PDEVICE_OBJECT DeviceObject;
333 PDRIVER_OBJECT DriverObject;
334 LARGE_INTEGER TimeStamp;
335 } ERROR_LOG_ENTRY, *PERROR_LOG_ENTRY;
336
337 //
338 // To simplify matters, the kernel is made to support both the checked and free
339 // version of the I/O Remove Lock in the same binary. This structure includes
340 // both, since the DDK has the structure with a compile-time #ifdef.
341 //
342 typedef struct _EXTENDED_IO_REMOVE_LOCK
343 {
344 IO_REMOVE_LOCK_COMMON_BLOCK Common;
345 IO_REMOVE_LOCK_DBG_BLOCK Dbg;
346 } EXTENDED_IO_REMOVE_LOCK, *PEXTENDED_IO_REMOVE_LOCK;
347
348 //
349 // Dummy File Object used inside the Open Packet so that OB knows how to
350 // deal with the Object Pointer even though it's not a real file.
351 //
352 typedef struct _DUMMY_FILE_OBJECT
353 {
354 OBJECT_HEADER ObjectHeader;
355 CHAR FileObjectBody[sizeof(FILE_OBJECT)];
356 } DUMMY_FILE_OBJECT, *PDUMMY_FILE_OBJECT;
357
358 //
359 // Open packet used as a context for Device/File parsing so that the parse
360 // routine can know what operation is being requested.
361 //
362 typedef struct _OPEN_PACKET
363 {
364 CSHORT Type;
365 CSHORT Size;
366 PFILE_OBJECT FileObject;
367 NTSTATUS FinalStatus;
368 ULONG_PTR Information;
369 ULONG ParseCheck;
370 PFILE_OBJECT RelatedFileObject;
371 OBJECT_ATTRIBUTES OriginalAttributes;
372 LARGE_INTEGER AllocationSize;
373 ULONG CreateOptions;
374 USHORT FileAttributes;
375 USHORT ShareAccess;
376 PVOID EaBuffer;
377 ULONG EaLength;
378 ULONG Options;
379 ULONG Disposition;
380 PFILE_BASIC_INFORMATION BasicInformation;
381 PFILE_NETWORK_OPEN_INFORMATION NetworkInformation;
382 CREATE_FILE_TYPE CreateFileType;
383 PVOID ExtraCreateParameters;
384 BOOLEAN Override;
385 BOOLEAN QueryOnly;
386 BOOLEAN DeleteOnly;
387 BOOLEAN FullAttributes;
388 PDUMMY_FILE_OBJECT LocalFileObject;
389 BOOLEAN TraversedMountPoint;
390 ULONG InternalFlags;
391 PDEVICE_OBJECT TopDeviceObjectHint;
392 } OPEN_PACKET, *POPEN_PACKET;
393
394 //
395 // Parameters packet for Load/Unload work item's context
396 //
397 typedef struct _LOAD_UNLOAD_PARAMS
398 {
399 NTSTATUS Status;
400 PCUNICODE_STRING RegistryPath;
401 WORK_QUEUE_ITEM WorkItem;
402 KEVENT Event;
403 PDRIVER_OBJECT DriverObject;
404 } LOAD_UNLOAD_PARAMS, *PLOAD_UNLOAD_PARAMS;
405
406 //
407 // Boot Driver List Entry
408 //
409 typedef struct _DRIVER_INFORMATION
410 {
411 LIST_ENTRY Link;
412 PDRIVER_OBJECT DriverObject;
413 PBOOT_DRIVER_LIST_ENTRY DataTableEntry;
414 HANDLE ServiceHandle;
415 USHORT TagPosition;
416 ULONG Failed;
417 ULONG Processed;
418 NTSTATUS Status;
419 } DRIVER_INFORMATION, *PDRIVER_INFORMATION;
420
421 //
422 // Boot Driver Node
423 //
424 typedef struct _BOOT_DRIVER_NODE
425 {
426 BOOT_DRIVER_LIST_ENTRY ListEntry;
427 UNICODE_STRING Group;
428 UNICODE_STRING Name;
429 ULONG Tag;
430 ULONG ErrorControl;
431 } BOOT_DRIVER_NODE, *PBOOT_DRIVER_NODE;
432
433 //
434 // List of Bus Type GUIDs
435 //
436 typedef struct _IO_BUS_TYPE_GUID_LIST
437 {
438 ULONG GuidCount;
439 FAST_MUTEX Lock;
440 GUID Guids[1];
441 } IO_BUS_TYPE_GUID_LIST, *PIO_BUS_TYPE_GUID_LIST;
442 extern PIO_BUS_TYPE_GUID_LIST IopBusTypeGuidList;
443
444 //
445 // Shutdown entry for registed devices
446 //
447 typedef struct _SHUTDOWN_ENTRY
448 {
449 LIST_ENTRY ShutdownList;
450 PDEVICE_OBJECT DeviceObject;
451 } SHUTDOWN_ENTRY, *PSHUTDOWN_ENTRY;
452
453 //
454 // F/S Notification entry for registered File Systems
455 //
456 typedef struct _FS_CHANGE_NOTIFY_ENTRY
457 {
458 LIST_ENTRY FsChangeNotifyList;
459 PDRIVER_OBJECT DriverObject;
460 PDRIVER_FS_NOTIFICATION FSDNotificationProc;
461 } FS_CHANGE_NOTIFY_ENTRY, *PFS_CHANGE_NOTIFY_ENTRY;
462
463 //
464 // Driver (Boot) Re-Initialization Entry
465 //
466 typedef struct _DRIVER_REINIT_ITEM
467 {
468 LIST_ENTRY ItemEntry;
469 PDRIVER_OBJECT DriverObject;
470 PDRIVER_REINITIALIZE ReinitRoutine;
471 PVOID Context;
472 } DRIVER_REINIT_ITEM, *PDRIVER_REINIT_ITEM;
473
474 //
475 // Called on every visit of a node during a preorder-traversal of the device
476 // node tree.
477 // If the routine returns STATUS_UNSUCCESSFUL the traversal will stop and
478 // STATUS_SUCCESS is returned to the caller who initiated the tree traversal.
479 // Any other returned status code will be returned to the caller. If a status
480 // code that indicates an error (other than STATUS_UNSUCCESSFUL) is returned,
481 // the traversal is stopped immediately and the status code is returned to
482 // the caller.
483 //
484 typedef
485 NTSTATUS
486 (*DEVICETREE_TRAVERSE_ROUTINE)(
487 IN PDEVICE_NODE DeviceNode,
488 IN PVOID Context
489 );
490
491 //
492 // Context information for traversing the device tree
493 //
494 typedef struct _DEVICETREE_TRAVERSE_CONTEXT
495 {
496 //
497 // Current device node during a traversal
498 //
499 PDEVICE_NODE DeviceNode;
500
501 //
502 // Initial device node where we start the traversal
503 //
504 PDEVICE_NODE FirstDeviceNode;
505
506 //
507 // Action routine to be called for every device node
508 //
509 DEVICETREE_TRAVERSE_ROUTINE Action;
510
511 //
512 // Context passed to the action routine
513 //
514 PVOID Context;
515 } DEVICETREE_TRAVERSE_CONTEXT, *PDEVICETREE_TRAVERSE_CONTEXT;
516
517 //
518 // Reserve IRP allocator
519 // Used for read paging IOs in low-memory situations
520 //
521 typedef struct _RESERVE_IRP_ALLOCATOR
522 {
523 PIRP ReserveIrp;
524 volatile LONG ReserveIrpInUse;
525 KEVENT WaitEvent;
526 CCHAR StackSize;
527 } RESERVE_IRP_ALLOCATOR, *PRESERVE_IRP_ALLOCATOR;
528
529 //
530 //
531 //
532 typedef enum _SECURITY_DESCRIPTOR_TYPE
533 {
534 RestrictedPublic = 1,
535 UnrestrictedPublic,
536 RestrictedPublicOpen,
537 UnrestrictedPublicOpen,
538 SystemDefault,
539 } SECURITY_DESCRIPTOR_TYPE, *PSECURITY_DESCRIPTOR_TYPE;
540
541 //
542 // Resource code
543 //
544 ULONG
545 NTAPI
546 PnpDetermineResourceListSize(IN PCM_RESOURCE_LIST ResourceList);
547
548 NTSTATUS
549 NTAPI
550 IopAssignDeviceResources(
551 IN PDEVICE_NODE DeviceNode
552 );
553
554 NTSTATUS
555 NTAPI
556 IopFixupResourceListWithRequirements(
557 IN PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList,
558 OUT PCM_RESOURCE_LIST *ResourceList
559 );
560
561 NTSTATUS
562 NTAPI
563 IopDetectResourceConflict(
564 IN PCM_RESOURCE_LIST ResourceList,
565 IN BOOLEAN Silent,
566 OUT OPTIONAL PCM_PARTIAL_RESOURCE_DESCRIPTOR ConflictingDescriptor
567 );
568
569 //
570 // PNP Routines
571 //
572 NTSTATUS
573 NTAPI
574 PipCallDriverAddDevice(
575 IN PDEVICE_NODE DeviceNode,
576 IN BOOLEAN LoadDriver,
577 IN PDRIVER_OBJECT DriverObject
578 );
579
580 NTSTATUS
581 NTAPI
582 IopInitializePlugPlayServices(
583 VOID
584 );
585
586 BOOLEAN
587 NTAPI
588 PpInitSystem(
589 VOID
590 );
591
592 VOID
593 PnpInit2(
594 VOID
595 );
596
597 VOID
598 IopInitDriverImplementation(
599 VOID
600 );
601
602 VOID
603 IopInitPnpNotificationImplementation(
604 VOID
605 );
606
607 VOID
608 IopNotifyPlugPlayNotification(
609 IN PDEVICE_OBJECT DeviceObject,
610 IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory,
611 IN LPCGUID Event,
612 IN PVOID EventCategoryData1,
613 IN PVOID EventCategoryData2
614 );
615
616 NTSTATUS
617 IopGetSystemPowerDeviceObject(
618 IN PDEVICE_OBJECT *DeviceObject
619 );
620
621 PDEVICE_NODE
622 NTAPI
623 PipAllocateDeviceNode(
624 IN PDEVICE_OBJECT PhysicalDeviceObject
625 );
626
627 NTSTATUS
628 IopCreateDeviceNode(
629 IN PDEVICE_NODE ParentNode,
630 IN PDEVICE_OBJECT PhysicalDeviceObject,
631 IN PUNICODE_STRING ServiceName,
632 OUT PDEVICE_NODE *DeviceNode
633 );
634
635 NTSTATUS
636 IopFreeDeviceNode(
637 IN PDEVICE_NODE DeviceNode
638 );
639
640 NTSTATUS
641 NTAPI
642 IopQueryDeviceCapabilities(PDEVICE_NODE DeviceNode,
643 PDEVICE_CAPABILITIES DeviceCaps);
644
645 NTSTATUS
646 NTAPI
647 IopSynchronousCall(
648 IN PDEVICE_OBJECT DeviceObject,
649 IN PIO_STACK_LOCATION IoStackLocation,
650 OUT PVOID *Information
651 );
652
653 NTSTATUS
654 NTAPI
655 IopInitiatePnpIrp(
656 IN PDEVICE_OBJECT DeviceObject,
657 IN PIO_STATUS_BLOCK IoStatusBlock,
658 IN UCHAR MinorFunction,
659 IN PIO_STACK_LOCATION Stack
660 );
661
662 PDEVICE_NODE
663 FASTCALL
664 IopGetDeviceNode(
665 IN PDEVICE_OBJECT DeviceObject
666 );
667
668 NTSTATUS
669 IopActionConfigureChildServices(
670 IN PDEVICE_NODE DeviceNode,
671 IN PVOID Context
672 );
673
674 NTSTATUS
675 IopActionInitChildServices(
676 IN PDEVICE_NODE DeviceNode,
677 IN PVOID Context
678 );
679
680 NTSTATUS
681 IopEnumerateDevice(
682 IN PDEVICE_OBJECT DeviceObject
683 );
684
685 NTSTATUS
686 IoCreateDriverList(
687 VOID
688 );
689
690 NTSTATUS
691 IoDestroyDriverList(
692 VOID
693 );
694
695 NTSTATUS
696 IopInitPlugPlayEvents(VOID);
697
698 NTSTATUS
699 IopQueueTargetDeviceEvent(
700 const GUID *Guid,
701 PUNICODE_STRING DeviceIds
702 );
703
704 NTSTATUS
705 IopInitializePnpServices(
706 IN PDEVICE_NODE DeviceNode);
707
708 NTSTATUS
709 NTAPI
710 IopOpenRegistryKeyEx(
711 PHANDLE KeyHandle,
712 HANDLE ParentKey,
713 PUNICODE_STRING Name,
714 ACCESS_MASK DesiredAccess);
715
716 NTSTATUS
717 NTAPI
718 IopGetRegistryValue(
719 IN HANDLE Handle,
720 IN PWSTR ValueName,
721 OUT PKEY_VALUE_FULL_INFORMATION *Information
722 );
723
724 NTSTATUS
725 NTAPI
726 IopCreateRegistryKeyEx(
727 OUT PHANDLE Handle,
728 IN HANDLE BaseHandle OPTIONAL,
729 IN PUNICODE_STRING KeyName,
730 IN ACCESS_MASK DesiredAccess,
731 IN ULONG CreateOptions,
732 OUT PULONG Disposition OPTIONAL
733 );
734
735
736 NTSTATUS
737 IopTraverseDeviceTree(
738 PDEVICETREE_TRAVERSE_CONTEXT Context);
739
740 //
741 // PnP Routines
742 //
743 NTSTATUS
744 NTAPI
745 IopUpdateRootKey(
746 VOID
747 );
748
749 NTSTATUS
750 NTAPI
751 PiInitCacheGroupInformation(
752 VOID
753 );
754
755 USHORT
756 NTAPI
757 PpInitGetGroupOrderIndex(
758 IN HANDLE ServiceHandle
759 );
760
761 USHORT
762 NTAPI
763 PipGetDriverTagPriority(
764 IN HANDLE ServiceHandle
765 );
766
767 NTSTATUS
768 NTAPI
769 PnpRegMultiSzToUnicodeStrings(
770 IN PKEY_VALUE_FULL_INFORMATION KeyValueInformation,
771 OUT PUNICODE_STRING *UnicodeStringList,
772 OUT PULONG UnicodeStringCount
773 );
774
775 BOOLEAN
776 NTAPI
777 PnpRegSzToString(
778 IN PWCHAR RegSzData,
779 IN ULONG RegSzLength,
780 OUT PUSHORT StringLength OPTIONAL
781 );
782
783 //
784 // Initialization Routines
785 //
786 NTSTATUS
787 NTAPI
788 IopCreateArcNames(
789 IN PLOADER_PARAMETER_BLOCK LoaderBlock
790 );
791
792 NTSTATUS
793 NTAPI
794 IopReassignSystemRoot(
795 IN PLOADER_PARAMETER_BLOCK LoaderBlock,
796 OUT PANSI_STRING NtBootPath
797 );
798
799 BOOLEAN
800 NTAPI
801 IoInitSystem(
802 IN PLOADER_PARAMETER_BLOCK LoaderBlock
803 );
804
805 BOOLEAN
806 NTAPI
807 IopVerifyDiskSignature(
808 IN PDRIVE_LAYOUT_INFORMATION_EX DriveLayout,
809 IN PARC_DISK_SIGNATURE ArcDiskSignature,
810 OUT PULONG Signature
811 );
812
813 BOOLEAN
814 NTAPI
815 IoInitializeCrashDump(
816 IN HANDLE PageFileHandle
817 );
818
819 //
820 // Device/Volume Routines
821 //
822 VOID
823 NTAPI
824 IopReadyDeviceObjects(
825 IN PDRIVER_OBJECT Driver
826 );
827
828 NTSTATUS
829 FASTCALL
830 IopInitializeDevice(
831 IN PDEVICE_NODE DeviceNode,
832 IN PDRIVER_OBJECT DriverObject
833 );
834
835 NTSTATUS
836 IopStartDevice(
837 IN PDEVICE_NODE DeviceNode
838 );
839
840 NTSTATUS
841 IopStopDevice(
842 IN PDEVICE_NODE DeviceNode
843 );
844
845 NTSTATUS
846 IopRemoveDevice(
847 IN PDEVICE_NODE DeviceNode
848 );
849
850 PVPB
851 NTAPI
852 IopCheckVpbMounted(
853 IN POPEN_PACKET OpenPacket,
854 IN PDEVICE_OBJECT DeviceObject,
855 IN PUNICODE_STRING RemainingName,
856 OUT PNTSTATUS Status
857 );
858
859 NTSTATUS
860 NTAPI
861 IopMountVolume(
862 IN PDEVICE_OBJECT DeviceObject,
863 IN BOOLEAN AllowRawMount,
864 IN BOOLEAN DeviceIsLocked,
865 IN BOOLEAN Alertable,
866 OUT PVPB *Vpb
867 );
868
869 PVOID
870 IoOpenSymlink(
871 IN PVOID SymbolicLink
872 );
873
874 PVOID
875 IoOpenFileOnDevice(
876 IN PVOID SymbolicLink,
877 IN PWCHAR Name
878 );
879
880 NTSTATUS
881 NTAPI
882 IopCreateVpb(
883 IN PDEVICE_OBJECT DeviceObject
884 );
885
886 VOID
887 NTAPI
888 IopDereferenceVpbAndFree(
889 IN PVPB Vpb
890 );
891
892 VOID
893 NTAPI
894 IoInitFileSystemImplementation(
895 VOID
896 );
897
898 VOID
899 NTAPI
900 IoInitVpbImplementation(
901 VOID
902 );
903
904 NTSTATUS
905 NTAPI
906 IopReferenceDeviceObject(
907 IN PDEVICE_OBJECT DeviceObject
908 );
909
910 VOID
911 NTAPI
912 IopDereferenceDeviceObject(
913 IN PDEVICE_OBJECT DeviceObject,
914 IN BOOLEAN ForceUnload
915 );
916
917 NTSTATUS
918 NTAPI
919 IoGetRelatedTargetDevice(
920 IN PFILE_OBJECT FileObject,
921 OUT PDEVICE_OBJECT *DeviceObject
922 );
923
924 VOID
925 NTAPI
926 IopUnloadDevice(
927 IN PDEVICE_OBJECT DeviceObject
928 );
929
930 //
931 // IRP Routines
932 //
933 NTSTATUS
934 NTAPI
935 IopCleanupFailedIrp(
936 IN PFILE_OBJECT FileObject,
937 IN PKEVENT EventObject,
938 IN PVOID Buffer OPTIONAL
939 );
940
941 VOID
942 NTAPI
943 IopAbortInterruptedIrp(
944 IN PKEVENT EventObject,
945 IN PIRP Irp
946 );
947
948 PIRP
949 NTAPI
950 IopAllocateIrpMustSucceed(
951 IN CCHAR StackSize
952 );
953
954 BOOLEAN
955 NTAPI
956 IopInitializeReserveIrp(
957 IN PRESERVE_IRP_ALLOCATOR ReserveIrpAllocator
958 );
959
960 PIRP
961 NTAPI
962 IopAllocateReserveIrp(
963 IN CCHAR StackSize
964 );
965
966 //
967 // Shutdown routines
968 //
969 VOID
970 IoInitShutdownNotification(
971 VOID
972 );
973
974 VOID
975 NTAPI
976 IoShutdownSystem(
977 IN ULONG Phase
978 );
979
980 VOID
981 NTAPI
982 IopShutdownBaseFileSystems(
983 IN PLIST_ENTRY ListHead
984 );
985
986 //
987 // Boot logging support
988 //
989 VOID
990 IopInitBootLog(
991 IN BOOLEAN StartBootLog
992 );
993
994 VOID
995 IopStartBootLog(
996 VOID
997 );
998
999 VOID
1000 IopStopBootLog(
1001 VOID
1002 );
1003
1004 VOID
1005 IopBootLog(
1006 IN PUNICODE_STRING DriverName,
1007 IN BOOLEAN Success
1008 );
1009
1010 VOID
1011 IopSaveBootLogToFile(
1012 VOID
1013 );
1014
1015 //
1016 // I/O Cancellation Routines
1017 //
1018 VOID
1019 NTAPI
1020 IoCancelThreadIo(
1021 IN PETHREAD Thread
1022 );
1023
1024 VOID
1025 IoInitCancelHandling(
1026 VOID
1027 );
1028
1029 //
1030 // I/O Completion
1031 //
1032 VOID
1033 NTAPI
1034 IopCompleteRequest(
1035 IN PKAPC Apc,
1036 IN PKNORMAL_ROUTINE* NormalRoutine,
1037 IN PVOID* NormalContext,
1038 IN PVOID* SystemArgument1,
1039 IN PVOID* SystemArgument2
1040 );
1041
1042 //
1043 // Error Logging Routines
1044 //
1045 VOID
1046 NTAPI
1047 IopInitErrorLog(
1048 VOID
1049 );
1050
1051 VOID
1052 NTAPI
1053 IopLogWorker(
1054 IN PVOID Parameter
1055 );
1056
1057 //
1058 // Raw File System MiniDriver
1059 //
1060 BOOLEAN
1061 RawFsIsRawFileSystemDeviceObject(
1062 IN PDEVICE_OBJECT DeviceObject
1063 );
1064
1065 NTSTATUS
1066 NTAPI
1067 RawFsDriverEntry(
1068 IN PDRIVER_OBJECT DriverObject,
1069 IN PUNICODE_STRING RegistryPath
1070 );
1071
1072 //
1073 // PnP Root MiniDriver
1074 //
1075 NTSTATUS
1076 NTAPI
1077 PnpRootDriverEntry(
1078 IN PDRIVER_OBJECT DriverObject,
1079 IN PUNICODE_STRING RegistryPath
1080 );
1081
1082 NTSTATUS
1083 PnpRootCreateDevice(
1084 IN PUNICODE_STRING ServiceName,
1085 IN OPTIONAL PDRIVER_OBJECT DriverObject,
1086 OUT PDEVICE_OBJECT *PhysicalDeviceObject,
1087 OUT OPTIONAL PUNICODE_STRING FullInstancePath
1088 );
1089
1090 NTSTATUS
1091 PnpRootRegisterDevice(
1092 IN PDEVICE_OBJECT DeviceObject);
1093
1094 //
1095 // Driver Routines
1096 //
1097 VOID
1098 FASTCALL
1099 IopInitializeBootDrivers(
1100 VOID
1101 );
1102
1103 VOID
1104 FASTCALL
1105 IopInitializeSystemDrivers(
1106 VOID
1107 );
1108
1109 NTSTATUS
1110 NTAPI
1111 IopCreateDriver(IN PUNICODE_STRING DriverName OPTIONAL,
1112 IN PDRIVER_INITIALIZE InitializationFunction,
1113 IN PUNICODE_STRING RegistryPath OPTIONAL,
1114 IN PCUNICODE_STRING ServiceName,
1115 IN PLDR_DATA_TABLE_ENTRY ModuleObject OPTIONAL,
1116 OUT PDRIVER_OBJECT *pDriverObject);
1117
1118 VOID
1119 NTAPI
1120 IopDeleteDriver(
1121 IN PVOID ObjectBody
1122 );
1123
1124 NTSTATUS
1125 FASTCALL
1126 IopGetDriverObject(
1127 OUT PDRIVER_OBJECT *DriverObject,
1128 IN PUNICODE_STRING ServiceName,
1129 IN BOOLEAN FileSystem
1130 );
1131
1132 NTSTATUS
1133 FASTCALL
1134 IopLoadServiceModule(
1135 IN PUNICODE_STRING ServiceName,
1136 OUT PLDR_DATA_TABLE_ENTRY *ModuleObject
1137 );
1138
1139 NTSTATUS
1140 NTAPI
1141 IopLoadUnloadDriver(
1142 _In_opt_ PCUNICODE_STRING RegistryPath,
1143 _Inout_ PDRIVER_OBJECT *DriverObject
1144 );
1145
1146 NTSTATUS
1147 FASTCALL
1148 IopInitializeDriverModule(
1149 IN PDEVICE_NODE DeviceNode,
1150 IN PLDR_DATA_TABLE_ENTRY ModuleObject,
1151 IN PUNICODE_STRING ServiceName,
1152 IN BOOLEAN FileSystemDriver,
1153 OUT PDRIVER_OBJECT *DriverObject
1154 );
1155
1156 NTSTATUS
1157 FASTCALL
1158 IopAttachFilterDrivers(
1159 IN PDEVICE_NODE DeviceNode,
1160 IN HANDLE EnumSubKey,
1161 IN HANDLE ClassKey,
1162 IN BOOLEAN Lower
1163 );
1164
1165 VOID
1166 NTAPI
1167 IopReinitializeDrivers(
1168 VOID
1169 );
1170
1171 VOID
1172 NTAPI
1173 IopReinitializeBootDrivers(
1174 VOID
1175 );
1176
1177 //
1178 // File Routines
1179 //
1180 VOID
1181 NTAPI
1182 IopDeleteDevice(IN PVOID ObjectBody);
1183
1184 NTSTATUS
1185 NTAPI
1186 IopParseDevice(
1187 IN PVOID ParseObject,
1188 IN PVOID ObjectType,
1189 IN OUT PACCESS_STATE AccessState,
1190 IN KPROCESSOR_MODE AccessMode,
1191 IN ULONG Attributes,
1192 IN OUT PUNICODE_STRING CompleteName,
1193 IN OUT PUNICODE_STRING RemainingName,
1194 IN OUT PVOID Context,
1195 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
1196 OUT PVOID *Object
1197 );
1198
1199 NTSTATUS
1200 NTAPI
1201 IopParseFile(
1202 IN PVOID ParseObject,
1203 IN PVOID ObjectType,
1204 IN OUT PACCESS_STATE AccessState,
1205 IN KPROCESSOR_MODE AccessMode,
1206 IN ULONG Attributes,
1207 IN OUT PUNICODE_STRING CompleteName,
1208 IN OUT PUNICODE_STRING RemainingName,
1209 IN OUT PVOID Context OPTIONAL,
1210 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
1211 OUT PVOID *Object
1212 );
1213
1214 VOID
1215 NTAPI
1216 IopDeleteFile(
1217 IN PVOID ObjectBody
1218 );
1219
1220 NTSTATUS
1221 NTAPI
1222 IopGetSetSecurityObject(
1223 IN PVOID ObjectBody,
1224 IN SECURITY_OPERATION_CODE OperationCode,
1225 IN PSECURITY_INFORMATION SecurityInformation,
1226 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
1227 IN OUT PULONG BufferLength,
1228 OUT PSECURITY_DESCRIPTOR *OldSecurityDescriptor,
1229 IN POOL_TYPE PoolType,
1230 IN OUT PGENERIC_MAPPING GenericMapping
1231 );
1232
1233 NTSTATUS
1234 NTAPI
1235 IopQueryName(
1236 IN PVOID ObjectBody,
1237 IN BOOLEAN HasName,
1238 OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
1239 IN ULONG Length,
1240 OUT PULONG ReturnLength,
1241 IN KPROCESSOR_MODE PreviousMode
1242 );
1243
1244 NTSTATUS
1245 NTAPI
1246 IopQueryNameInternal(
1247 IN PVOID ObjectBody,
1248 IN BOOLEAN HasName,
1249 IN BOOLEAN QueryDosName,
1250 OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
1251 IN ULONG Length,
1252 OUT PULONG ReturnLength,
1253 IN KPROCESSOR_MODE PreviousMode
1254 );
1255
1256 VOID
1257 NTAPI
1258 IopCloseFile(
1259 IN PEPROCESS Process OPTIONAL,
1260 IN PVOID Object,
1261 IN ACCESS_MASK GrantedAccess,
1262 IN ULONG ProcessHandleCount,
1263 IN ULONG SystemHandleCount
1264 );
1265
1266 NTSTATUS
1267 NTAPI
1268 IopAcquireFileObjectLock(
1269 _In_ PFILE_OBJECT FileObject,
1270 _In_ KPROCESSOR_MODE AccessMode,
1271 _In_ BOOLEAN Alertable,
1272 _Out_ PBOOLEAN LockFailed
1273 );
1274
1275 PVOID
1276 NTAPI
1277 IoGetFileObjectFilterContext(
1278 IN PFILE_OBJECT FileObject
1279 );
1280
1281 NTSTATUS
1282 NTAPI
1283 IoChangeFileObjectFilterContext(
1284 IN PFILE_OBJECT FileObject,
1285 IN PVOID FilterContext,
1286 IN BOOLEAN Define
1287 );
1288
1289 VOID
1290 NTAPI
1291 IopDoNameTransmogrify(
1292 IN PIRP Irp,
1293 IN PFILE_OBJECT FileObject,
1294 IN PREPARSE_DATA_BUFFER DataBuffer
1295 );
1296
1297 NTSTATUS
1298 NTAPI
1299 IoComputeDesiredAccessFileObject(
1300 IN PFILE_OBJECT FileObject,
1301 IN PACCESS_MASK DesiredAccess
1302 );
1303
1304 NTSTATUS
1305 NTAPI
1306 IopGetFileInformation(
1307 IN PFILE_OBJECT FileObject,
1308 IN ULONG Length,
1309 IN FILE_INFORMATION_CLASS FileInfoClass,
1310 OUT PVOID Buffer,
1311 OUT PULONG ReturnedLength
1312 );
1313
1314 BOOLEAN
1315 NTAPI
1316 IopVerifyDeviceObjectOnStack(
1317 IN PDEVICE_OBJECT BaseDeviceObject,
1318 IN PDEVICE_OBJECT TopDeviceObjectHint
1319 );
1320
1321 //
1322 // I/O Timer Routines
1323 //
1324 VOID
1325 FASTCALL
1326 IopInitTimerImplementation(
1327 VOID
1328 );
1329
1330 VOID
1331 NTAPI
1332 IopRemoveTimerFromTimerList(
1333 IN PIO_TIMER Timer
1334 );
1335
1336 //
1337 // I/O Completion Routines
1338 //
1339 VOID
1340 NTAPI
1341 IopDeleteIoCompletion(
1342 PVOID ObjectBody
1343 );
1344
1345 NTSTATUS
1346 NTAPI
1347 IoSetIoCompletion(
1348 IN PVOID IoCompletion,
1349 IN PVOID KeyContext,
1350 IN PVOID ApcContext,
1351 IN NTSTATUS IoStatus,
1352 IN ULONG_PTR IoStatusInformation,
1353 IN BOOLEAN Quota
1354 );
1355
1356 //
1357 // Ramdisk Routines
1358 //
1359 NTSTATUS
1360 NTAPI
1361 IopStartRamdisk(
1362 IN PLOADER_PARAMETER_BLOCK LoaderBlock
1363 );
1364
1365 //
1366 // Configuration Routines
1367 //
1368 NTSTATUS
1369 NTAPI
1370 IopFetchConfigurationInformation(OUT PWSTR * SymbolicLinkList,
1371 IN GUID Guid,
1372 IN ULONG ExpectedInterfaces,
1373 IN PULONG Interfaces
1374 );
1375
1376 VOID
1377 NTAPI
1378 IopStoreSystemPartitionInformation(IN PUNICODE_STRING NtSystemPartitionDeviceName,
1379 IN PUNICODE_STRING OsLoaderPathName
1380 );
1381
1382 //
1383 // Global I/O Data
1384 //
1385 extern POBJECT_TYPE IoCompletionType;
1386 extern PDEVICE_NODE IopRootDeviceNode;
1387 extern KSPIN_LOCK IopDeviceTreeLock;
1388 extern ULONG IopTraceLevel;
1389 extern GENERAL_LOOKASIDE IopMdlLookasideList;
1390 extern GENERIC_MAPPING IopCompletionMapping;
1391 extern GENERIC_MAPPING IopFileMapping;
1392 extern POBJECT_TYPE _IoFileObjectType;
1393 extern HAL_DISPATCH _HalDispatchTable;
1394 extern LIST_ENTRY IopErrorLogListHead;
1395 extern ULONG IopNumTriageDumpDataBlocks;
1396 extern PVOID IopTriageDumpDataBlocks[64];
1397 extern PIO_BUS_TYPE_GUID_LIST PnpBusTypeGuidList;
1398 extern PDRIVER_OBJECT IopRootDriverObject;
1399 extern KSPIN_LOCK IopDeviceActionLock;
1400 extern LIST_ENTRY IopDeviceActionRequestList;
1401 extern RESERVE_IRP_ALLOCATOR IopReserveIrpAllocator;
1402
1403 //
1404 // Inlined Functions
1405 //
1406 #include "io_x.h"