2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/include/io.h
5 * PURPOSE: Internal header for the I/O Manager
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
11 // Define this if you want debugging support
13 #define _IO_DEBUG_ 0x01
16 // These define the Debug Masks Supported
18 #define IO_IRP_DEBUG 0x01
19 #define IO_FILE_DEBUG 0x02
20 #define IO_API_DEBUG 0x04
21 #define IO_CTL_DEBUG 0x08
24 // Debug/Tracing support
27 #ifdef NEW_DEBUG_SYSTEM_IMPLEMENTED // enable when Debug Filters are implemented
28 #define IOTRACE(x, ...) \
30 DbgPrintEx("%s [%.16s] - ", \
32 PsGetCurrentProcess()->ImageFileName); \
33 DbgPrintEx(__VA_ARGS__); \
36 #define IOTRACE(x, ...) \
37 if (x & IopTraceLevel) \
39 DbgPrint("%s [%.16s] - ", \
41 PsGetCurrentProcess()->ImageFileName); \
42 DbgPrint(__VA_ARGS__); \
46 #define IOTRACE(x, ...) DPRINT(__VA_ARGS__);
50 // Registry path to the enumeration root key
52 #define ENUM_ROOT L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum"
55 // Returns the type of METHOD_ used in this IOCTL
57 #define IO_METHOD_FROM_CTL_CODE(c) (c & 0x00000003)
60 // Packet Types when piggybacking on the IRP Overlay
62 #define IrpCompletionPacket 0x1
63 #define IrpMiniCompletionPacket 0x2
66 // We can call the Ob Inlined API, it's the same thing
68 #define IopAllocateMdlFromLookaside \
69 ObpAllocateObjectCreateInfoBuffer
70 #define IopFreeMdlFromLookaside \
71 ObpFreeCapturedAttributes
74 // Returns the size of a CM_RESOURCE_LIST
76 #define CM_RESOURCE_LIST_SIZE(ResList) \
77 (ResList->Count == 1) ? \
80 List[0].PartialResourceList. \
81 PartialDescriptors[(ResList)-> \
83 PartialResourceList. \
86 FIELD_OFFSET(CM_RESOURCE_LIST, List)
89 // Determines if the IRP is Synchronous
91 #define IsIrpSynchronous(Irp, FileObject) \
92 ((Irp->Flags & IRP_SYNCHRONOUS_API) || \
95 FileObject->Flags & FO_SYNCHRONOUS_IO)) \
98 // Returns the internal Device Object Extension
100 #define IoGetDevObjExtension(DeviceObject) \
101 ((PEXTENDED_DEVOBJ_EXTENSION) \
102 (DeviceObject->DeviceObjectExtension)) \
105 // Returns the internal Driver Object Extension
107 #define IoGetDrvObjExtension(DriverObject) \
108 ((PEXTENDED_DRIVER_EXTENSION) \
109 (DriverObject->DriverExtension)) \
113 * IopDeviceNodeSetFlag(
114 * PDEVICE_NODE DeviceNode,
117 #define IopDeviceNodeSetFlag(DeviceNode, Flag) \
118 ((DeviceNode)->Flags |= (Flag))
122 * IopDeviceNodeClearFlag(
123 * PDEVICE_NODE DeviceNode,
126 #define IopDeviceNodeClearFlag(DeviceNode, Flag) \
127 ((DeviceNode)->Flags &= ~(Flag))
131 * IopDeviceNodeHasFlag(
132 * PDEVICE_NODE DeviceNode,
135 #define IopDeviceNodeHasFlag(DeviceNode, Flag) \
136 (((DeviceNode)->Flags & (Flag)) > 0)
140 * IopDeviceNodeSetUserFlag(
141 * PDEVICE_NODE DeviceNode,
144 #define IopDeviceNodeSetUserFlag(DeviceNode, UserFlag) \
145 ((DeviceNode)->UserFlags |= (UserFlag))
149 * IopDeviceNodeClearUserFlag(
150 * PDEVICE_NODE DeviceNode,
153 #define IopDeviceNodeClearUserFlag(DeviceNode, UserFlag)\
154 ((DeviceNode)->UserFlags &= ~(UserFlag))
158 * IopDeviceNodeHasUserFlag(
159 * PDEVICE_NODE DeviceNode,
162 #define IopDeviceNodeHasUserFlag(DeviceNode, UserFlag) \
163 (((DeviceNode)->UserFlags & (UserFlag)) > 0)
167 * IopDeviceNodeSetProblem(
168 * PDEVICE_NODE DeviceNode,
171 #define IopDeviceNodeSetProblem(DeviceNode, Problem) \
172 ((DeviceNode)->Problem |= (Problem))
176 * IopDeviceNodeClearProblem(
177 * PDEVICE_NODE DeviceNode,
180 #define IopDeviceNodeClearProblem(DeviceNode, Problem) \
181 ((DeviceNode)->Problem &= ~(Problem))
185 * IopDeviceNodeHasProblem(
186 * PDEVICE_NODE DeviceNode,
189 #define IopDeviceNodeHasProblem(DeviceNode, Problem) \
190 (((DeviceNode)->Problem & (Problem)) > 0)
194 * IopInitDeviceTreeTraverseContext(
195 * PDEVICETREE_TRAVERSE_CONTEXT DeviceTreeTraverseContext,
196 * PDEVICE_NODE DeviceNode,
197 * DEVICETREE_TRAVERSE_ROUTINE Action,
200 #define IopInitDeviceTreeTraverseContext( \
201 _DeviceTreeTraverseContext, _DeviceNode, _Action, \
203 (_DeviceTreeTraverseContext)->FirstDeviceNode = \
205 (_DeviceTreeTraverseContext)->Action = (_Action); \
206 (_DeviceTreeTraverseContext)->Context = (_Context); }
209 // Device List Operations
211 typedef enum _IOP_DEVICE_LIST_OPERATION
215 } IOP_DEVICE_LIST_OPERATION
, *PIOP_DEVICE_LIST_OPERATION
;
218 // Transfer statistics
220 typedef enum _IOP_TRANSFER_TYPE
225 } IOP_TRANSFER_TYPE
, *PIOP_TRANSFER_TYPE
;
228 // Special version of the IRP Overlay used to optimize I/O completion
229 // by not using up a separate structure.
231 typedef struct _IO_COMPLETION_PACKET
235 LIST_ENTRY ListEntry
;
238 struct _IO_STACK_LOCATION
*CurrentStackLocation
;
244 IO_STATUS_BLOCK IoStatus
;
245 } IO_COMPLETION_PACKET
, *PIO_COMPLETION_PACKET
;
248 // I/O Completion Context for IoSetIoCompletionRoutineEx
250 typedef struct _IO_UNLOAD_SAFE_COMPLETION_CONTEXT
252 PDEVICE_OBJECT DeviceObject
;
254 PIO_COMPLETION_ROUTINE CompletionRoutine
;
255 } IO_UNLOAD_SAFE_COMPLETION_CONTEXT
, *PIO_UNLOAD_SAFE_COMPLETION_CONTEXT
;
258 // I/O Wrapper around the Executive Work Item
260 typedef struct _IO_WORKITEM
262 WORK_QUEUE_ITEM Item
;
263 PDEVICE_OBJECT DeviceObject
;
264 PIO_WORKITEM_ROUTINE WorkerRoutine
;
266 } IO_WORKITEM
, *PIO_WORKITEM
;
269 // I/O Wrapper around the Kernel Interrupt
271 typedef struct _IO_INTERRUPT
273 KINTERRUPT FirstInterrupt
;
274 PKINTERRUPT Interrupt
[MAXIMUM_PROCESSORS
];
276 } IO_INTERRUPT
, *PIO_INTERRUPT
;
279 // I/O Error Log Packet Header
281 typedef struct _ERROR_LOG_ENTRY
285 LIST_ENTRY ListEntry
;
286 PDEVICE_OBJECT DeviceObject
;
287 PDRIVER_OBJECT DriverObject
;
288 LARGE_INTEGER TimeStamp
;
289 } ERROR_LOG_ENTRY
, *PERROR_LOG_ENTRY
;
292 // Event Log LPC Message
294 typedef struct _ELF_API_MSG
298 IO_ERROR_LOG_MESSAGE IoErrorMessage
;
299 } ELF_API_MSG
, *PELF_API_MSG
;
302 // To simplify matters, the kernel is made to support both the checked and free
303 // version of the I/O Remove Lock in the same binary. This structure includes
304 // both, since the DDK has the structure with a compile-time #ifdef.
306 typedef struct _EXTENDED_IO_REMOVE_LOCK
308 IO_REMOVE_LOCK_COMMON_BLOCK Common
;
309 IO_REMOVE_LOCK_DBG_BLOCK Dbg
;
310 } EXTENDED_IO_REMOVE_LOCK
, *PEXTENDED_IO_REMOVE_LOCK
;
313 // Dummy File Object used inside the Open Packet so that OB knows how to
314 // deal with the Object Pointer even though it's not a real file.
316 typedef struct _DUMMY_FILE_OBJECT
318 OBJECT_HEADER ObjectHeader
;
319 CHAR FileObjectBody
[sizeof(FILE_OBJECT
)];
320 } DUMMY_FILE_OBJECT
, *PDUMMY_FILE_OBJECT
;
323 // Open packet used as a context for Device/File parsing so that the parse
324 // routine can know what operation is being requested.
326 typedef struct _OPEN_PACKET
330 PFILE_OBJECT FileObject
;
331 NTSTATUS FinalStatus
;
332 ULONG_PTR Information
;
334 PFILE_OBJECT RelatedFileObject
;
335 OBJECT_ATTRIBUTES OriginalAttributes
;
336 LARGE_INTEGER AllocationSize
;
338 USHORT FileAttributes
;
344 PFILE_BASIC_INFORMATION BasicInformation
;
345 PFILE_NETWORK_OPEN_INFORMATION NetworkInformation
;
346 CREATE_FILE_TYPE CreateFileType
;
347 PVOID MailslotOrPipeParameters
;
351 BOOLEAN FullAttributes
;
352 PDUMMY_FILE_OBJECT DummyFileObject
;
354 //PIO_DRIVER_CREATE_CONTEXT DriverCreateContext; Vista only, needs ROS DDK Update
355 } OPEN_PACKET
, *POPEN_PACKET
;
358 // Parameters packet for Load/Unload work item's context
360 typedef struct _LOAD_UNLOAD_PARAMS
363 PUNICODE_STRING ServiceName
;
364 WORK_QUEUE_ITEM WorkItem
;
366 PDRIVER_OBJECT DriverObject
;
367 } LOAD_UNLOAD_PARAMS
, *PLOAD_UNLOAD_PARAMS
;
370 // List of Bus Type GUIDs
372 typedef struct _IO_BUS_TYPE_GUID_LIST
377 } IO_BUS_TYPE_GUID_LIST
, *PIO_BUS_TYPE_GUID_LIST
;
378 extern PIO_BUS_TYPE_GUID_LIST IopBusTypeGuidList
;
381 // Shutdown entry for registed devices
383 typedef struct _SHUTDOWN_ENTRY
385 LIST_ENTRY ShutdownList
;
386 PDEVICE_OBJECT DeviceObject
;
387 } SHUTDOWN_ENTRY
, *PSHUTDOWN_ENTRY
;
390 // F/S Notification entry for registered File Systems
392 typedef struct _FS_CHANGE_NOTIFY_ENTRY
394 LIST_ENTRY FsChangeNotifyList
;
395 PDRIVER_OBJECT DriverObject
;
396 PDRIVER_FS_NOTIFICATION FSDNotificationProc
;
397 } FS_CHANGE_NOTIFY_ENTRY
, *PFS_CHANGE_NOTIFY_ENTRY
;
400 // Driver (Boot) Re-Initialization Entry
402 typedef struct _DRIVER_REINIT_ITEM
404 LIST_ENTRY ItemEntry
;
405 PDRIVER_OBJECT DriverObject
;
406 PDRIVER_REINITIALIZE ReinitRoutine
;
408 } DRIVER_REINIT_ITEM
, *PDRIVER_REINIT_ITEM
;
411 // Called on every visit of a node during a preorder-traversal of the device
413 // If the routine returns STATUS_UNSUCCESSFUL the traversal will stop and
414 // STATUS_SUCCESS is returned to the caller who initiated the tree traversal.
415 // Any other returned status code will be returned to the caller. If a status
416 // code that indicates an error (other than STATUS_UNSUCCESSFUL) is returned,
417 // the traversal is stopped immediately and the status code is returned to
422 (*DEVICETREE_TRAVERSE_ROUTINE
)(
423 IN PDEVICE_NODE DeviceNode
,
428 // Context information for traversing the device tree
430 typedef struct _DEVICETREE_TRAVERSE_CONTEXT
433 // Current device node during a traversal
435 PDEVICE_NODE DeviceNode
;
438 // Initial device node where we start the traversal
440 PDEVICE_NODE FirstDeviceNode
;
443 // Action routine to be called for every device node
445 DEVICETREE_TRAVERSE_ROUTINE Action
;
448 // Context passed to the action routine
451 } DEVICETREE_TRAVERSE_CONTEXT
, *PDEVICETREE_TRAVERSE_CONTEXT
;
473 IopInitDriverImplementation(
478 IopInitPnpNotificationImplementation(
483 IopNotifyPlugPlayNotification(
484 IN PDEVICE_OBJECT DeviceObject
,
485 IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory
,
487 IN PVOID EventCategoryData1
,
488 IN PVOID EventCategoryData2
492 IopGetSystemPowerDeviceObject(
493 IN PDEVICE_OBJECT
*DeviceObject
498 IN PDEVICE_NODE ParentNode
,
499 IN PDEVICE_OBJECT PhysicalDeviceObject
,
500 IN PUNICODE_STRING ServiceName
,
501 OUT PDEVICE_NODE
*DeviceNode
506 IN PDEVICE_NODE DeviceNode
511 IN PDEVICE_OBJECT DeviceObject
,
512 IN PIO_STATUS_BLOCK IoStatusBlock
,
513 IN ULONG MinorFunction
,
514 IN PIO_STACK_LOCATION Stack
520 IN PDEVICE_OBJECT DeviceObject
524 IopActionConfigureChildServices(
525 IN PDEVICE_NODE DeviceNode
,
530 IopActionInitChildServices(
531 IN PDEVICE_NODE DeviceNode
,
533 IN BOOLEAN BootDrivers
548 IopInitPlugPlayEvents(VOID
);
551 IopQueueTargetDeviceEvent(
553 PUNICODE_STRING DeviceIds
557 IopInitializePnpServices(
558 IN PDEVICE_NODE DeviceNode
,
559 IN BOOLEAN BootDrivers
);
562 IopOpenRegistryKeyEx(
565 PUNICODE_STRING Name
,
566 ACCESS_MASK DesiredAccess
);
569 // Initialization Routines
574 IN PLOADER_PARAMETER_BLOCK LoaderBlock
579 IopReassignSystemRoot(
580 IN PLOADER_PARAMETER_BLOCK LoaderBlock
,
581 OUT PANSI_STRING NtBootPath
587 IN PLOADER_PARAMETER_BLOCK LoaderBlock
591 // Device/Volume Routines
596 IN PDEVICE_NODE DeviceNode
,
597 IN PDRIVER_OBJECT DriverObject
602 IN PDEVICE_NODE DeviceNode
608 IN POPEN_PACKET OpenPacket
,
609 IN PDEVICE_OBJECT DeviceObject
,
610 IN PUNICODE_STRING RemainingName
,
617 IN PDEVICE_OBJECT DeviceObject
,
618 IN BOOLEAN AllowRawMount
,
619 IN BOOLEAN DeviceIsLocked
,
620 IN BOOLEAN Alertable
,
626 IN PVOID SymbolicLink
631 IN PVOID SymbolicLink
,
638 IN PDEVICE_OBJECT DeviceObject
649 IoInitFileSystemImplementation(
655 IoInitVpbImplementation(
661 IopReferenceDeviceObject(
662 IN PDEVICE_OBJECT DeviceObject
667 IopDereferenceDeviceObject(
668 IN PDEVICE_OBJECT DeviceObject
,
669 IN BOOLEAN ForceUnload
678 IN PFILE_OBJECT FileObject
,
679 IN PKEVENT EventObject
,
680 IN PVOID Buffer OPTIONAL
685 IopAbortInterruptedIrp(
686 IN PKEVENT EventObject
,
694 IoInitShutdownNotification(
700 IoShutdownRegisteredDevices(
706 IoShutdownRegisteredFileSystems(
711 // Boot logging support
715 IN BOOLEAN StartBootLog
730 IN PUNICODE_STRING DriverName
,
735 IopSaveBootLogToFile(
740 // I/O Cancellation Routines
749 IoInitCancelHandling(
760 IN PKNORMAL_ROUTINE
* NormalRoutine
,
761 IN PVOID
* NormalContext
,
762 IN PVOID
* SystemArgument1
,
763 IN PVOID
* SystemArgument2
767 // Error Logging Routines
782 // Raw File System MiniDriver
785 RawFsIsRawFileSystemDeviceObject(
786 IN PDEVICE_OBJECT DeviceObject
792 IN PDRIVER_OBJECT DriverObject
,
793 IN PUNICODE_STRING RegistryPath
797 // PnP Root MiniDriver
802 IN PDRIVER_OBJECT DriverObject
,
803 IN PUNICODE_STRING RegistryPath
808 IN PUNICODE_STRING ServiceName
,
809 IN OUT PDEVICE_OBJECT
*PhysicalDeviceObject
817 IopInitializeBootDrivers(
823 IopInitializeSystemDrivers(
829 IopCreateDriver(IN PUNICODE_STRING DriverName OPTIONAL
,
830 IN PDRIVER_INITIALIZE InitializationFunction
,
831 IN PUNICODE_STRING RegistryPath
,
833 IN ULONG SizeOfImage
,
834 OUT PDRIVER_OBJECT
*pDriverObject
);
845 OUT PDRIVER_OBJECT
*DriverObject
,
846 IN PUNICODE_STRING ServiceName
,
847 IN BOOLEAN FileSystem
852 IopLoadServiceModule(
853 IN PUNICODE_STRING ServiceName
,
854 OUT PLDR_DATA_TABLE_ENTRY
*ModuleObject
860 IN OUT PLOAD_UNLOAD_PARAMS LoadParams
865 IopInitializeDriverModule(
866 IN PDEVICE_NODE DeviceNode
,
867 IN PLDR_DATA_TABLE_ENTRY ModuleObject
,
868 IN PUNICODE_STRING ServiceName
,
869 IN BOOLEAN FileSystemDriver
,
870 OUT PDRIVER_OBJECT
*DriverObject
875 IopAttachFilterDrivers(
876 IN PDEVICE_NODE DeviceNode
,
882 IopReinitializeDrivers(
888 IopReinitializeBootDrivers(
898 IN PVOID ParseObject
,
900 IN OUT PACCESS_STATE AccessState
,
901 IN KPROCESSOR_MODE AccessMode
,
903 IN OUT PUNICODE_STRING CompleteName
,
904 IN OUT PUNICODE_STRING RemainingName
,
905 IN OUT PVOID Context OPTIONAL
,
906 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL
,
913 IN PVOID ParseObject
,
915 IN OUT PACCESS_STATE AccessState
,
916 IN KPROCESSOR_MODE AccessMode
,
918 IN OUT PUNICODE_STRING CompleteName
,
919 IN OUT PUNICODE_STRING RemainingName
,
920 IN OUT PVOID Context OPTIONAL
,
921 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL
,
935 IN SECURITY_OPERATION_CODE OperationCode
,
936 IN PSECURITY_INFORMATION SecurityInformation
,
937 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor
,
938 IN OUT PULONG BufferLength
,
939 OUT PSECURITY_DESCRIPTOR
*OldSecurityDescriptor
,
940 IN POOL_TYPE PoolType
,
941 IN OUT PGENERIC_MAPPING GenericMapping
949 OUT POBJECT_NAME_INFORMATION ObjectNameInfo
,
951 OUT PULONG ReturnLength
,
952 IN KPROCESSOR_MODE PreviousMode
958 IN PEPROCESS Process OPTIONAL
,
960 IN ACCESS_MASK GrantedAccess
,
961 IN ULONG ProcessHandleCount
,
962 IN ULONG SystemHandleCount
966 // I/O Timer Routines
970 IopInitTimerImplementation(
976 IopRemoveTimerFromTimerList(
981 // I/O Completion Routines
985 IopDeleteIoCompletion(
992 extern POBJECT_TYPE IoCompletionType
;
993 extern PDEVICE_NODE IopRootDeviceNode
;
994 extern ULONG IopTraceLevel
;
995 extern NPAGED_LOOKASIDE_LIST IopMdlLookasideList
;
996 extern GENERIC_MAPPING IopCompletionMapping
;
997 extern GENERIC_MAPPING IopFileMapping
;
998 extern POBJECT_TYPE _IoFileObjectType
;
999 extern HAL_DISPATCH _HalDispatchTable
;
1000 extern LIST_ENTRY IopErrorLogListHead
;
1003 // Inlined Functions