xref: /reactos/ntoskrnl/include/internal/io.h (revision ea3c56b6)
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 // Boot Driver List Entry
396 //
397 typedef struct _DRIVER_INFORMATION
398 {
399     LIST_ENTRY Link;
400     PDRIVER_OBJECT DriverObject;
401     PBOOT_DRIVER_LIST_ENTRY DataTableEntry;
402     HANDLE ServiceHandle;
403     USHORT TagPosition;
404     ULONG Failed;
405     ULONG Processed;
406     NTSTATUS Status;
407 } DRIVER_INFORMATION, *PDRIVER_INFORMATION;
408 
409 //
410 // Boot Driver Node
411 //
412 typedef struct _BOOT_DRIVER_NODE
413 {
414     BOOT_DRIVER_LIST_ENTRY ListEntry;
415     UNICODE_STRING Group;
416     UNICODE_STRING Name;
417     ULONG Tag;
418     ULONG ErrorControl;
419 } BOOT_DRIVER_NODE, *PBOOT_DRIVER_NODE;
420 
421 //
422 // List of Bus Type GUIDs
423 //
424 typedef struct _IO_BUS_TYPE_GUID_LIST
425 {
426     ULONG GuidCount;
427     FAST_MUTEX Lock;
428     GUID Guids[1];
429 } IO_BUS_TYPE_GUID_LIST, *PIO_BUS_TYPE_GUID_LIST;
430 extern PIO_BUS_TYPE_GUID_LIST IopBusTypeGuidList;
431 
432 //
433 // Shutdown entry for registed devices
434 //
435 typedef struct _SHUTDOWN_ENTRY
436 {
437     LIST_ENTRY ShutdownList;
438     PDEVICE_OBJECT DeviceObject;
439 } SHUTDOWN_ENTRY, *PSHUTDOWN_ENTRY;
440 
441 //
442 // F/S Notification entry for registered File Systems
443 //
444 typedef struct _FS_CHANGE_NOTIFY_ENTRY
445 {
446     LIST_ENTRY FsChangeNotifyList;
447     PDRIVER_OBJECT DriverObject;
448     PDRIVER_FS_NOTIFICATION FSDNotificationProc;
449 } FS_CHANGE_NOTIFY_ENTRY, *PFS_CHANGE_NOTIFY_ENTRY;
450 
451 //
452 // Driver (Boot) Re-Initialization Entry
453 //
454 typedef struct _DRIVER_REINIT_ITEM
455 {
456     LIST_ENTRY ItemEntry;
457     PDRIVER_OBJECT DriverObject;
458     PDRIVER_REINITIALIZE ReinitRoutine;
459     PVOID Context;
460 } DRIVER_REINIT_ITEM, *PDRIVER_REINIT_ITEM;
461 
462 //
463 // Called on every visit of a node during a preorder-traversal of the device
464 // node tree.
465 // If the routine returns STATUS_UNSUCCESSFUL the traversal will stop and
466 // STATUS_SUCCESS is returned to the caller who initiated the tree traversal.
467 // Any other returned status code will be returned to the caller. If a status
468 // code that indicates an error (other than STATUS_UNSUCCESSFUL) is returned,
469 // the traversal is stopped immediately and the status code is returned to
470 // the caller.
471 //
472 typedef
473 NTSTATUS
474 (*DEVICETREE_TRAVERSE_ROUTINE)(
475     IN PDEVICE_NODE DeviceNode,
476     IN PVOID Context
477 );
478 
479 //
480 // Context information for traversing the device tree
481 //
482 typedef struct _DEVICETREE_TRAVERSE_CONTEXT
483 {
484     //
485     // Current device node during a traversal
486     //
487     PDEVICE_NODE DeviceNode;
488 
489     //
490     // Initial device node where we start the traversal
491     //
492     PDEVICE_NODE FirstDeviceNode;
493 
494     //
495     // Action routine to be called for every device node
496     //
497     DEVICETREE_TRAVERSE_ROUTINE Action;
498 
499     //
500     // Context passed to the action routine
501     //
502     PVOID Context;
503 } DEVICETREE_TRAVERSE_CONTEXT, *PDEVICETREE_TRAVERSE_CONTEXT;
504 
505 //
506 // Reserve IRP allocator
507 // Used for read paging IOs in low-memory situations
508 //
509 typedef struct _RESERVE_IRP_ALLOCATOR
510 {
511     PIRP ReserveIrp;
512     volatile LONG ReserveIrpInUse;
513     KEVENT WaitEvent;
514     CCHAR StackSize;
515 } RESERVE_IRP_ALLOCATOR, *PRESERVE_IRP_ALLOCATOR;
516 
517 //
518 // Type selection for IopCreateSecurityDescriptorPerType()
519 //
520 typedef enum _SECURITY_DESCRIPTOR_TYPE
521 {
522     RestrictedPublic = 1,
523     UnrestrictedPublic,
524     RestrictedPublicOpen,
525     UnrestrictedPublicOpen,
526     SystemDefault,
527 } SECURITY_DESCRIPTOR_TYPE, *PSECURITY_DESCRIPTOR_TYPE;
528 
529 //
530 // Action types and data for PiQueueDeviceAction()
531 //
532 typedef enum _DEVICE_ACTION
533 {
534     PiActionEnumDeviceTree,
535     PiActionEnumRootDevices,
536     PiActionResetDevice,
537     PiActionAddBootDevices,
538     PiActionStartDevice
539 } DEVICE_ACTION;
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 IopInitializePlugPlayServices(
575     VOID
576 );
577 
578 BOOLEAN
579 NTAPI
580 PpInitSystem(
581     VOID
582 );
583 
584 VOID
585 PnpInit2(
586     VOID
587 );
588 
589 VOID
590 IopInitDriverImplementation(
591     VOID
592 );
593 
594 NTSTATUS
595 IopGetSystemPowerDeviceObject(
596     IN PDEVICE_OBJECT *DeviceObject
597 );
598 
599 PDEVICE_NODE
600 PipAllocateDeviceNode(
601     IN PDEVICE_OBJECT PhysicalDeviceObject
602 );
603 
604 VOID
605 PiInsertDevNode(
606     _In_ PDEVICE_NODE DeviceNode,
607     _In_ PDEVICE_NODE ParentNode);
608 
609 PNP_DEVNODE_STATE
610 PiSetDevNodeState(
611     _In_ PDEVICE_NODE DeviceNode,
612     _In_ PNP_DEVNODE_STATE NewState);
613 
614 VOID
615 PiSetDevNodeProblem(
616     _In_ PDEVICE_NODE DeviceNode,
617     _In_ UINT32 Problem);
618 
619 VOID
620 PiClearDevNodeProblem(
621     _In_ PDEVICE_NODE DeviceNode);
622 
623 NTSTATUS
624 IopFreeDeviceNode(
625     IN PDEVICE_NODE DeviceNode
626 );
627 
628 NTSTATUS
629 NTAPI
630 IopQueryDeviceCapabilities(PDEVICE_NODE DeviceNode,
631                            PDEVICE_CAPABILITIES DeviceCaps);
632 
633 NTSTATUS
634 IopSynchronousCall(
635     IN PDEVICE_OBJECT DeviceObject,
636     IN PIO_STACK_LOCATION IoStackLocation,
637     OUT PVOID *Information
638 );
639 
640 NTSTATUS
641 NTAPI
642 IopInitiatePnpIrp(
643     IN PDEVICE_OBJECT DeviceObject,
644     IN PIO_STATUS_BLOCK IoStatusBlock,
645     IN UCHAR MinorFunction,
646     IN PIO_STACK_LOCATION Stack
647 );
648 
649 PDEVICE_NODE
650 FASTCALL
651 IopGetDeviceNode(
652     IN PDEVICE_OBJECT DeviceObject
653 );
654 
655 NTSTATUS
656 IoCreateDriverList(
657     VOID
658 );
659 
660 NTSTATUS
661 IoDestroyDriverList(
662     VOID
663 );
664 
665 NTSTATUS
666 IopInitPlugPlayEvents(VOID);
667 
668 NTSTATUS
669 IopQueueTargetDeviceEvent(
670     const GUID *Guid,
671     PUNICODE_STRING DeviceIds
672 );
673 
674 NTSTATUS
675 NTAPI
676 IopOpenRegistryKeyEx(
677     PHANDLE KeyHandle,
678     HANDLE ParentKey,
679     PUNICODE_STRING Name,
680     ACCESS_MASK DesiredAccess);
681 
682 NTSTATUS
683 NTAPI
684 IopGetRegistryValue(
685     IN HANDLE Handle,
686     IN PWSTR ValueName,
687     OUT PKEY_VALUE_FULL_INFORMATION *Information
688 );
689 
690 NTSTATUS
691 NTAPI
692 IopCreateRegistryKeyEx(
693     OUT PHANDLE Handle,
694     IN HANDLE BaseHandle OPTIONAL,
695     IN PUNICODE_STRING KeyName,
696     IN ACCESS_MASK DesiredAccess,
697     IN ULONG CreateOptions,
698     OUT PULONG Disposition OPTIONAL
699 );
700 
701 
702 NTSTATUS
703 IopTraverseDeviceTree(
704     PDEVICETREE_TRAVERSE_CONTEXT Context);
705 
706 NTSTATUS
707 NTAPI
708 IopCreateDeviceKeyPath(
709     IN PCUNICODE_STRING RegistryPath,
710     IN ULONG CreateOptions,
711     OUT PHANDLE Handle);
712 
713 //
714 // PnP Routines
715 //
716 NTSTATUS
717 NTAPI
718 IopUpdateRootKey(
719     VOID
720 );
721 
722 NTSTATUS
723 NTAPI
724 PiInitCacheGroupInformation(
725     VOID
726 );
727 
728 USHORT
729 NTAPI
730 PpInitGetGroupOrderIndex(
731     IN HANDLE ServiceHandle
732 );
733 
734 USHORT
735 NTAPI
736 PipGetDriverTagPriority(
737     IN HANDLE ServiceHandle
738 );
739 
740 NTSTATUS
741 NTAPI
742 PnpRegMultiSzToUnicodeStrings(
743     IN PKEY_VALUE_FULL_INFORMATION KeyValueInformation,
744     OUT PUNICODE_STRING *UnicodeStringList,
745     OUT PULONG UnicodeStringCount
746 );
747 
748 BOOLEAN
749 NTAPI
750 PnpRegSzToString(
751     IN PWCHAR RegSzData,
752     IN ULONG RegSzLength,
753     OUT PUSHORT StringLength OPTIONAL
754 );
755 
756 //
757 // Initialization Routines
758 //
759 NTSTATUS
760 NTAPI
761 IopCreateArcNames(
762     IN PLOADER_PARAMETER_BLOCK LoaderBlock
763 );
764 
765 NTSTATUS
766 NTAPI
767 IopReassignSystemRoot(
768     IN PLOADER_PARAMETER_BLOCK LoaderBlock,
769     OUT PANSI_STRING NtBootPath
770 );
771 
772 BOOLEAN
773 NTAPI
774 IoInitSystem(
775     IN PLOADER_PARAMETER_BLOCK LoaderBlock
776 );
777 
778 BOOLEAN
779 NTAPI
780 IopVerifyDiskSignature(
781     IN PDRIVE_LAYOUT_INFORMATION_EX DriveLayout,
782     IN PARC_DISK_SIGNATURE ArcDiskSignature,
783     OUT PULONG Signature
784 );
785 
786 BOOLEAN
787 NTAPI
788 IoInitializeCrashDump(
789     IN HANDLE PageFileHandle
790 );
791 
792 VOID
793 PiInitializeNotifications(
794     VOID);
795 
796 //
797 // Device/Volume Routines
798 //
799 VOID
800 NTAPI
801 IopReadyDeviceObjects(
802     IN PDRIVER_OBJECT Driver
803 );
804 
805 PVPB
806 NTAPI
807 IopCheckVpbMounted(
808     IN POPEN_PACKET OpenPacket,
809     IN PDEVICE_OBJECT DeviceObject,
810     IN PUNICODE_STRING RemainingName,
811     OUT PNTSTATUS Status
812 );
813 
814 NTSTATUS
815 NTAPI
816 IopMountVolume(
817     IN PDEVICE_OBJECT DeviceObject,
818     IN BOOLEAN AllowRawMount,
819     IN BOOLEAN DeviceIsLocked,
820     IN BOOLEAN Alertable,
821     OUT PVPB *Vpb
822 );
823 
824 PVOID
825 IoOpenSymlink(
826     IN PVOID SymbolicLink
827 );
828 
829 PVOID
830 IoOpenFileOnDevice(
831     IN PVOID SymbolicLink,
832     IN PWCHAR Name
833 );
834 
835 NTSTATUS
836 NTAPI
837 IopCreateVpb(
838     IN PDEVICE_OBJECT DeviceObject
839 );
840 
841 VOID
842 NTAPI
843 IopDereferenceVpbAndFree(
844     IN PVPB Vpb
845 );
846 
847 VOID
848 NTAPI
849 IoInitFileSystemImplementation(
850     VOID
851 );
852 
853 VOID
854 NTAPI
855 IoInitVpbImplementation(
856     VOID
857 );
858 
859 NTSTATUS
860 NTAPI
861 IopReferenceDeviceObject(
862     IN PDEVICE_OBJECT DeviceObject
863 );
864 
865 VOID
866 NTAPI
867 IopDereferenceDeviceObject(
868     IN PDEVICE_OBJECT DeviceObject,
869     IN BOOLEAN ForceUnload
870 );
871 
872 NTSTATUS
873 NTAPI
874 IopGetRelatedTargetDevice(
875     IN PFILE_OBJECT FileObject,
876     OUT PDEVICE_NODE *DeviceNode);
877 
878 NTSTATUS
879 NTAPI
880 IoGetRelatedTargetDevice(
881     IN PFILE_OBJECT FileObject,
882     OUT PDEVICE_OBJECT *DeviceObject
883 );
884 
885 VOID
886 NTAPI
887 IopUnloadDevice(
888     IN PDEVICE_OBJECT DeviceObject
889 );
890 
891 PDEVICE_OBJECT
892 NTAPI
893 IopGetDeviceAttachmentBase(
894     IN PDEVICE_OBJECT DeviceObject
895 );
896 
897 //
898 // IRP Routines
899 //
900 NTSTATUS
901 NTAPI
902 IopCleanupFailedIrp(
903     IN PFILE_OBJECT FileObject,
904     IN PKEVENT EventObject,
905     IN PVOID Buffer OPTIONAL
906 );
907 
908 VOID
909 NTAPI
910 IopAbortInterruptedIrp(
911     IN PKEVENT EventObject,
912     IN PIRP Irp
913 );
914 
915 PIRP
916 NTAPI
917 IopAllocateIrpMustSucceed(
918     IN CCHAR StackSize
919 );
920 
921 BOOLEAN
922 NTAPI
923 IopInitializeReserveIrp(
924     IN PRESERVE_IRP_ALLOCATOR ReserveIrpAllocator
925 );
926 
927 PIRP
928 NTAPI
929 IopAllocateReserveIrp(
930     IN CCHAR StackSize
931 );
932 
933 //
934 // Shutdown routines
935 //
936 VOID
937 IoInitShutdownNotification(
938     VOID
939 );
940 
941 VOID
942 NTAPI
943 IoShutdownSystem(
944     IN ULONG Phase
945 );
946 
947 VOID
948 NTAPI
949 IopShutdownBaseFileSystems(
950     IN PLIST_ENTRY ListHead
951 );
952 
953 //
954 // Boot logging support
955 //
956 VOID
957 IopInitBootLog(
958     IN BOOLEAN StartBootLog
959 );
960 
961 VOID
962 IopStartBootLog(
963     VOID
964 );
965 
966 VOID
967 IopStopBootLog(
968     VOID
969 );
970 
971 VOID
972 IopBootLog(
973     IN PUNICODE_STRING DriverName,
974     IN BOOLEAN Success
975 );
976 
977 VOID
978 IopSaveBootLogToFile(
979     VOID
980 );
981 
982 //
983 // I/O Cancellation Routines
984 //
985 VOID
986 NTAPI
987 IoCancelThreadIo(
988     IN PETHREAD Thread
989 );
990 
991 VOID
992 IoInitCancelHandling(
993     VOID
994 );
995 
996 //
997 // I/O Completion
998 //
999 VOID
1000 NTAPI
1001 IopCompleteRequest(
1002     IN PKAPC Apc,
1003     IN PKNORMAL_ROUTINE* NormalRoutine,
1004     IN PVOID* NormalContext,
1005     IN PVOID* SystemArgument1,
1006     IN PVOID* SystemArgument2
1007 );
1008 
1009 //
1010 // Error Logging Routines
1011 //
1012 VOID
1013 NTAPI
1014 IopInitErrorLog(
1015     VOID
1016 );
1017 
1018 VOID
1019 NTAPI
1020 IopLogWorker(
1021     IN PVOID Parameter
1022 );
1023 
1024 //
1025 // Raw File System MiniDriver
1026 //
1027 BOOLEAN
1028 RawFsIsRawFileSystemDeviceObject(
1029     IN PDEVICE_OBJECT DeviceObject
1030 );
1031 
1032 NTSTATUS
1033 NTAPI
1034 RawFsDriverEntry(
1035     IN PDRIVER_OBJECT DriverObject,
1036     IN PUNICODE_STRING RegistryPath
1037 );
1038 
1039 //
1040 // PnP Root MiniDriver
1041 //
1042 NTSTATUS
1043 NTAPI
1044 PnpRootDriverEntry(
1045    IN PDRIVER_OBJECT DriverObject,
1046    IN PUNICODE_STRING RegistryPath
1047 );
1048 
1049 NTSTATUS
1050 PnpRootCreateDevice(
1051     IN PUNICODE_STRING ServiceName,
1052     IN OPTIONAL PDRIVER_OBJECT DriverObject,
1053     OUT PDEVICE_OBJECT *PhysicalDeviceObject,
1054     OUT OPTIONAL PUNICODE_STRING FullInstancePath
1055 );
1056 
1057 NTSTATUS
1058 PnpRootRegisterDevice(
1059     IN PDEVICE_OBJECT DeviceObject);
1060 
1061 //
1062 // Driver Routines
1063 //
1064 VOID
1065 FASTCALL
1066 IopInitializeBootDrivers(
1067     VOID
1068 );
1069 
1070 VOID
1071 FASTCALL
1072 IopInitializeSystemDrivers(
1073     VOID
1074 );
1075 
1076 VOID
1077 NTAPI
1078 IopDeleteDriver(
1079     IN PVOID ObjectBody
1080 );
1081 
1082 NTSTATUS
1083 IopLoadDriver(
1084     _In_ HANDLE ServiceHandle,
1085     _Out_ PDRIVER_OBJECT *DriverObject);
1086 
1087 NTSTATUS
1088 IopGetDriverNames(
1089     _In_ HANDLE ServiceHandle,
1090     _Out_ PUNICODE_STRING DriverName,
1091     _Out_opt_ PUNICODE_STRING ServiceName);
1092 
1093 NTSTATUS
1094 IopInitializeDriverModule(
1095     _In_ PLDR_DATA_TABLE_ENTRY ModuleObject,
1096     _In_ HANDLE ServiceHandle,
1097     _Out_ PDRIVER_OBJECT *DriverObject,
1098     _Out_ NTSTATUS *DriverEntryStatus);
1099 
1100 NTSTATUS
1101 FASTCALL
1102 IopAttachFilterDrivers(
1103     IN PDEVICE_NODE DeviceNode,
1104     IN HANDLE EnumSubKey,
1105     IN HANDLE ClassKey,
1106     IN BOOLEAN Lower
1107 );
1108 
1109 VOID
1110 NTAPI
1111 IopReinitializeDrivers(
1112     VOID
1113 );
1114 
1115 VOID
1116 NTAPI
1117 IopReinitializeBootDrivers(
1118     VOID
1119 );
1120 
1121 //
1122 // File Routines
1123 //
1124 VOID
1125 NTAPI
1126 IopDeleteDevice(IN PVOID ObjectBody);
1127 
1128 NTSTATUS
1129 NTAPI
1130 IopParseDevice(
1131     IN PVOID ParseObject,
1132     IN PVOID ObjectType,
1133     IN OUT PACCESS_STATE AccessState,
1134     IN KPROCESSOR_MODE AccessMode,
1135     IN ULONG Attributes,
1136     IN OUT PUNICODE_STRING CompleteName,
1137     IN OUT PUNICODE_STRING RemainingName,
1138     IN OUT PVOID Context,
1139     IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
1140     OUT PVOID *Object
1141 );
1142 
1143 NTSTATUS
1144 NTAPI
1145 IopParseFile(
1146     IN PVOID ParseObject,
1147     IN PVOID ObjectType,
1148     IN OUT PACCESS_STATE AccessState,
1149     IN KPROCESSOR_MODE AccessMode,
1150     IN ULONG Attributes,
1151     IN OUT PUNICODE_STRING CompleteName,
1152     IN OUT PUNICODE_STRING RemainingName,
1153     IN OUT PVOID Context OPTIONAL,
1154     IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
1155     OUT PVOID *Object
1156 );
1157 
1158 VOID
1159 NTAPI
1160 IopDeleteFile(
1161     IN PVOID ObjectBody
1162 );
1163 
1164 NTSTATUS
1165 NTAPI
1166 IopGetSetSecurityObject(
1167     IN PVOID ObjectBody,
1168     IN SECURITY_OPERATION_CODE OperationCode,
1169     IN PSECURITY_INFORMATION SecurityInformation,
1170     IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
1171     IN OUT PULONG BufferLength,
1172     OUT PSECURITY_DESCRIPTOR *OldSecurityDescriptor,
1173     IN POOL_TYPE PoolType,
1174     IN OUT PGENERIC_MAPPING GenericMapping
1175 );
1176 
1177 NTSTATUS
1178 NTAPI
1179 IopQueryName(
1180     IN PVOID ObjectBody,
1181     IN BOOLEAN HasName,
1182     OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
1183     IN ULONG Length,
1184     OUT PULONG ReturnLength,
1185     IN KPROCESSOR_MODE PreviousMode
1186 );
1187 
1188 NTSTATUS
1189 NTAPI
1190 IopQueryNameInternal(
1191     IN PVOID ObjectBody,
1192     IN BOOLEAN HasName,
1193     IN BOOLEAN QueryDosName,
1194     OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
1195     IN ULONG Length,
1196     OUT PULONG ReturnLength,
1197     IN KPROCESSOR_MODE PreviousMode
1198 );
1199 
1200 VOID
1201 NTAPI
1202 IopCloseFile(
1203     IN PEPROCESS Process OPTIONAL,
1204     IN PVOID Object,
1205     IN ACCESS_MASK GrantedAccess,
1206     IN ULONG ProcessHandleCount,
1207     IN ULONG SystemHandleCount
1208 );
1209 
1210 NTSTATUS
1211 NTAPI
1212 IopAcquireFileObjectLock(
1213     _In_ PFILE_OBJECT FileObject,
1214     _In_ KPROCESSOR_MODE AccessMode,
1215     _In_ BOOLEAN Alertable,
1216     _Out_ PBOOLEAN LockFailed
1217 );
1218 
1219 PVOID
1220 NTAPI
1221 IoGetFileObjectFilterContext(
1222     IN PFILE_OBJECT FileObject
1223 );
1224 
1225 NTSTATUS
1226 NTAPI
1227 IoChangeFileObjectFilterContext(
1228     IN PFILE_OBJECT FileObject,
1229     IN PVOID FilterContext,
1230     IN BOOLEAN Define
1231 );
1232 
1233 VOID
1234 NTAPI
1235 IopDoNameTransmogrify(
1236     IN PIRP Irp,
1237     IN PFILE_OBJECT FileObject,
1238     IN PREPARSE_DATA_BUFFER DataBuffer
1239 );
1240 
1241 NTSTATUS
1242 NTAPI
1243 IoComputeDesiredAccessFileObject(
1244     IN PFILE_OBJECT FileObject,
1245     IN PACCESS_MASK DesiredAccess
1246 );
1247 
1248 NTSTATUS
1249 NTAPI
1250 IopGetFileInformation(
1251     IN PFILE_OBJECT FileObject,
1252     IN ULONG Length,
1253     IN FILE_INFORMATION_CLASS FileInfoClass,
1254     OUT PVOID Buffer,
1255     OUT PULONG ReturnedLength
1256 );
1257 
1258 BOOLEAN
1259 NTAPI
1260 IopVerifyDeviceObjectOnStack(
1261     IN PDEVICE_OBJECT BaseDeviceObject,
1262     IN PDEVICE_OBJECT TopDeviceObjectHint
1263 );
1264 
1265 //
1266 // I/O Timer Routines
1267 //
1268 VOID
1269 FASTCALL
1270 IopInitTimerImplementation(
1271     VOID
1272 );
1273 
1274 VOID
1275 NTAPI
1276 IopRemoveTimerFromTimerList(
1277     IN PIO_TIMER Timer
1278 );
1279 
1280 //
1281 // I/O Completion Routines
1282 //
1283 VOID
1284 NTAPI
1285 IopDeleteIoCompletion(
1286     PVOID ObjectBody
1287 );
1288 
1289 NTSTATUS
1290 NTAPI
1291 IoSetIoCompletion(
1292     IN PVOID IoCompletion,
1293     IN PVOID KeyContext,
1294     IN PVOID ApcContext,
1295     IN NTSTATUS IoStatus,
1296     IN ULONG_PTR IoStatusInformation,
1297     IN BOOLEAN Quota
1298 );
1299 
1300 //
1301 // Ramdisk Routines
1302 //
1303 NTSTATUS
1304 NTAPI
1305 IopStartRamdisk(
1306     IN PLOADER_PARAMETER_BLOCK LoaderBlock
1307 );
1308 
1309 //
1310 // Configuration Routines
1311 //
1312 NTSTATUS
1313 NTAPI
1314 IopFetchConfigurationInformation(OUT PWSTR * SymbolicLinkList,
1315                                  IN GUID Guid,
1316                                  IN ULONG ExpectedInterfaces,
1317                                  IN PULONG Interfaces
1318 );
1319 
1320 VOID
1321 NTAPI
1322 IopStoreSystemPartitionInformation(IN PUNICODE_STRING NtSystemPartitionDeviceName,
1323                                    IN PUNICODE_STRING OsLoaderPathName
1324 );
1325 
1326 //
1327 // Device action
1328 //
1329 VOID
1330 PiQueueDeviceAction(
1331     _In_ PDEVICE_OBJECT DeviceObject,
1332     _In_ DEVICE_ACTION Action,
1333     _In_opt_ PKEVENT CompletionEvent,
1334     _Out_opt_ NTSTATUS *CompletionStatus);
1335 
1336 NTSTATUS
1337 PiPerformSyncDeviceAction(
1338     _In_ PDEVICE_OBJECT DeviceObject,
1339     _In_ DEVICE_ACTION Action);
1340 
1341 //
1342 // PnP notifications
1343 //
1344 VOID
1345 PiNotifyDeviceInterfaceChange(
1346     _In_ LPCGUID Event,
1347     _In_ LPCGUID InterfaceClassGuid,
1348     _In_ PUNICODE_STRING SymbolicLinkName);
1349 
1350 VOID
1351 PiNotifyHardwareProfileChange(
1352     _In_ LPCGUID Event);
1353 
1354 VOID
1355 PiNotifyTargetDeviceChange(
1356     _In_ LPCGUID Event,
1357     _In_ PDEVICE_OBJECT DeviceObject,
1358     _In_opt_ PTARGET_DEVICE_CUSTOM_NOTIFICATION CustomNotification);
1359 
1360 //
1361 // PnP IRPs
1362 //
1363 NTSTATUS
1364 PiIrpStartDevice(
1365     _In_ PDEVICE_NODE DeviceNode);
1366 
1367 NTSTATUS
1368 PiIrpStopDevice(
1369     _In_ PDEVICE_NODE DeviceNode);
1370 
1371 NTSTATUS
1372 PiIrpQueryStopDevice(
1373     _In_ PDEVICE_NODE DeviceNode);
1374 
1375 NTSTATUS
1376 PiIrpCancelStopDevice(
1377     _In_ PDEVICE_NODE DeviceNode);
1378 
1379 NTSTATUS
1380 PiIrpQueryDeviceRelations(
1381     _In_ PDEVICE_NODE DeviceNode,
1382     _In_ DEVICE_RELATION_TYPE Type);
1383 
1384 NTSTATUS
1385 PiIrpQueryPnPDeviceState(
1386     _In_ PDEVICE_NODE DeviceNode,
1387     _Out_ PPNP_DEVICE_STATE DeviceState);
1388 
1389 //
1390 // Global I/O Data
1391 //
1392 extern POBJECT_TYPE IoCompletionType;
1393 extern PDEVICE_NODE IopRootDeviceNode;
1394 extern KSPIN_LOCK IopDeviceTreeLock;
1395 extern ULONG IopTraceLevel;
1396 extern GENERAL_LOOKASIDE IopMdlLookasideList;
1397 extern GENERIC_MAPPING IopCompletionMapping;
1398 extern GENERIC_MAPPING IopFileMapping;
1399 extern POBJECT_TYPE _IoFileObjectType;
1400 extern HAL_DISPATCH _HalDispatchTable;
1401 extern LIST_ENTRY IopErrorLogListHead;
1402 extern ULONG IopNumTriageDumpDataBlocks;
1403 extern PVOID IopTriageDumpDataBlocks[64];
1404 extern PIO_BUS_TYPE_GUID_LIST PnpBusTypeGuidList;
1405 extern PDRIVER_OBJECT IopRootDriverObject;
1406 extern KSPIN_LOCK IopDeviceActionLock;
1407 extern LIST_ENTRY IopDeviceActionRequestList;
1408 extern RESERVE_IRP_ALLOCATOR IopReserveIrpAllocator;
1409 extern BOOLEAN IoRemoteBootClient;
1410 
1411 //
1412 // Inlined Functions
1413 //
1414 #include "io_x.h"
1415