3 * Copyright (C) 2000 David Welch <welch@cwcom.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: include/internal/io.h
24 * PURPOSE: Internal io manager declarations
25 * PROGRAMMER: David Welch (welch@mcmail.com)
30 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_IO_H
31 #define __NTOSKRNL_INCLUDE_INTERNAL_IO_H
33 #include <ddk/ntddk.h>
34 #include <internal/ob.h>
35 #include <internal/module.h>
39 #define DEVICE_TYPE_FROM_CTL_CODE(ctlCode) (((ULONG)(ctlCode&0xffff0000))>>16)
42 #define IO_METHOD_FROM_CTL_CODE(ctlCode) (ctlCode&0x00000003)
45 typedef struct _IO_COMPLETION_PACKET
{
48 IO_STATUS_BLOCK IoStatus
;
50 } IO_COMPLETION_PACKET
, *PIO_COMPLETION_PACKET
;
52 typedef struct _DEVOBJ_EXTENSION
{
55 PDEVICE_OBJECT DeviceObject
;
57 struct _DEVICE_NODE
*DeviceNode
;
58 } DEVOBJ_EXTENSION
, *PDEVOBJ_EXTENSION
;
60 typedef struct _PRIVATE_DRIVER_EXTENSIONS
{
61 struct _PRIVATE_DRIVER_EXTENSIONS
*Link
;
62 PVOID ClientIdentificationAddress
;
64 } PRIVATE_DRIVER_EXTENSIONS
, *PPRIVATE_DRIVER_EXTENSIONS
;
66 typedef struct _DEVICE_NODE
68 /* A tree structure. */
69 struct _DEVICE_NODE
*Parent
;
70 struct _DEVICE_NODE
*PrevSibling
;
71 struct _DEVICE_NODE
*NextSibling
;
72 struct _DEVICE_NODE
*Child
;
73 /* The level of deepness in the tree. */
76 // PPO_DEVICE_NOTIFY Notify;
78 // PNP_DEVNODE_STATE State;
79 // PNP_DEVNODE_STATE PreviousState;
80 // PNP_DEVNODE_STATE StateHistory[20];
81 // UINT StateHistoryEntry;
86 /* See DNF_* flags below (WinDBG documentation has WRONG values) */
88 /* See DNUF_* flags below (and IRP_MN_QUERY_PNP_DEVICE_STATE) */
90 /* See CM_PROB_* values are defined in cfg.h */
92 /* Pointer to the PDO corresponding to the device node. */
93 PDEVICE_OBJECT PhysicalDeviceObject
;
94 /* Resource list as assigned by the PnP arbiter. See IRP_MN_START_DEVICE
95 and ARBITER_INTERFACE (not documented in DDK, but present in headers). */
96 PCM_RESOURCE_LIST ResourceList
;
97 /* Resource list as assigned by the PnP arbiter (translated version). */
98 PCM_RESOURCE_LIST ResourceListTranslated
;
99 /* Instance path relative to the Enum key in registry. */
100 UNICODE_STRING InstancePath
;
101 /* Name of the driver service. */
102 UNICODE_STRING ServiceName
;
104 PDEVICE_OBJECT DuplicatePDO
;
105 /* See IRP_MN_QUERY_RESOURCE_REQUIREMENTS. */
106 PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements
;
107 /* Information about bus for bus drivers. */
108 INTERFACE_TYPE InterfaceType
;
110 /* Information about underlying bus for child devices. */
111 INTERFACE_TYPE ChildInterfaceType
;
112 ULONG ChildBusNumber
;
113 USHORT ChildBusTypeIndex
;
116 UCHAR HardwareRemovalPolicy
;
117 LIST_ENTRY TargetDeviceNotify
;
118 LIST_ENTRY DeviceArbiterList
;
119 LIST_ENTRY DeviceTranslatorList
;
120 USHORT NoTranslatorMask
;
121 USHORT QueryTranslatorMask
;
122 USHORT NoArbiterMask
;
123 USHORT QueryArbiterMask
;
125 struct _DEVICE_NODE
*LegacyDeviceNode
;
126 PDEVICE_RELATIONS PendingDeviceRelations
;
129 struct _DEVICE_NODE
*NextResourceDeviceNode
;
131 /* See IRP_MN_QUERY_RESOURCES/IRP_MN_FILTER_RESOURCES. */
132 PCM_RESOURCE_LIST BootResources
;
133 /* See the bitfields in DEVICE_CAPABILITIES structure. */
134 ULONG CapabilityFlags
;
138 LIST_ENTRY ListEntry
;
141 ULONG DisableableDepends
;
142 LIST_ENTRY PendedSetInterfaceState
;
143 LIST_ENTRY LegacyBusListEntry
;
144 ULONG DriverUnloadRetryCount
;
149 } DEVICE_NODE
, *PDEVICE_NODE
;
151 /* For Flags field */
152 #define DNF_PROCESSED 0x00000001
153 #define DNF_STARTED 0x00000002
154 #define DNF_START_FAILED 0x00000004
155 #define DNF_ENUMERATED 0x00000008
156 #define DNF_DELETED 0x00000010
157 #define DNF_MADEUP 0x00000020
158 #define DNF_START_REQUEST_PENDING 0x00000040
159 #define DNF_NO_RESOURCE_REQUIRED 0x00000080
160 #define DNF_INSUFFICIENT_RESOURCES 0x00000100
161 #define DNF_RESOURCE_ASSIGNED 0x00000200
162 #define DNF_RESOURCE_REPORTED 0x00000400
163 #define DNF_HAL_NODE 0x00000800 // ???
164 #define DNF_ADDED 0x00001000
165 #define DNF_ADD_FAILED 0x00002000
166 #define DNF_LEGACY_DRIVER 0x00004000
167 #define DNF_STOPPED 0x00008000
168 #define DNF_WILL_BE_REMOVED 0x00010000
169 #define DNF_NEED_TO_ENUM 0x00020000
170 #define DNF_NOT_CONFIGURED 0x00040000
171 #define DNF_REINSTALL 0x00080000
172 #define DNF_RESOURCE_REQUIREMENTS_NEED_FILTERED 0x00100000 // ???
173 #define DNF_DISABLED 0x00200000
174 #define DNF_RESTART_OK 0x00400000
175 #define DNF_NEED_RESTART 0x00800000
176 #define DNF_VISITED 0x01000000
177 #define DNF_ASSIGNING_RESOURCES 0x02000000
178 #define DNF_BEEING_ENUMERATED 0x04000000
179 #define DNF_NEED_ENUMERATION_ONLY 0x08000000
180 #define DNF_LOCKED 0x10000000
181 #define DNF_HAS_BOOT_CONFIG 0x20000000
182 #define DNF_BOOT_CONFIG_RESERVED 0x40000000
183 #define DNF_HAS_PROBLEM 0x80000000 // ???
185 /* For UserFlags field */
186 #define DNUF_DONT_SHOW_IN_UI 0x0002
187 #define DNUF_NOT_DISABLEABLE 0x0008
189 /* For Problem field */
190 #define CM_PROB_NOT_CONFIGURED 1
191 #define CM_PROB_FAILED_START 10
192 #define CM_PROB_NORMAL_CONFLICT 12
193 #define CM_PROB_NEED_RESTART 14
194 #define CM_PROB_REINSTALL 18
195 #define CM_PROB_WILL_BE_REMOVED 21
196 #define CM_PROB_DISABLED 22
197 #define CM_PROB_FAILED_INSTALL 28
198 #define CM_PROB_FAILED_ADD 31
202 * IopDeviceNodeSetFlag(
203 * PDEVICE_NODE DeviceNode,
206 #define IopDeviceNodeSetFlag(DeviceNode, Flag)((DeviceNode)->Flags |= (Flag))
210 * IopDeviceNodeClearFlag(
211 * PDEVICE_NODE DeviceNode,
214 #define IopDeviceNodeClearFlag(DeviceNode, Flag)((DeviceNode)->Flags &= ~(Flag))
218 * IopDeviceNodeHasFlag(
219 * PDEVICE_NODE DeviceNode,
222 #define IopDeviceNodeHasFlag(DeviceNode, Flag)(((DeviceNode)->Flags & (Flag)) > 0)
226 * IopDeviceNodeSetUserFlag(
227 * PDEVICE_NODE DeviceNode,
230 #define IopDeviceNodeSetUserFlag(DeviceNode, UserFlag)((DeviceNode)->UserFlags |= (UserFlag))
234 * IopDeviceNodeClearUserFlag(
235 * PDEVICE_NODE DeviceNode,
238 #define IopDeviceNodeClearUserFlag(DeviceNode, UserFlag)((DeviceNode)->UserFlags &= ~(UserFlag))
242 * IopDeviceNodeHasUserFlag(
243 * PDEVICE_NODE DeviceNode,
246 #define IopDeviceNodeHasUserFlag(DeviceNode, UserFlag)(((DeviceNode)->UserFlags & (UserFlag)) > 0)
250 * IopDeviceNodeSetProblem(
251 * PDEVICE_NODE DeviceNode,
254 #define IopDeviceNodeSetProblem(DeviceNode, Problem)((DeviceNode)->Problem |= (Problem))
258 * IopDeviceNodeClearProblem(
259 * PDEVICE_NODE DeviceNode,
262 #define IopDeviceNodeClearProblem(DeviceNode, Problem)((DeviceNode)->Problem &= ~(Problem))
266 * IopDeviceNodeHasProblem(
267 * PDEVICE_NODE DeviceNode,
270 #define IopDeviceNodeHasProblem(DeviceNode, Problem)(((DeviceNode)->Problem & (Problem)) > 0)
274 Called on every visit of a node during a preorder-traversal of the device
276 If the routine returns STATUS_UNSUCCESSFUL the traversal will stop and
277 STATUS_SUCCESS is returned to the caller who initiated the tree traversal.
278 Any other returned status code will be returned to the caller. If a status
279 code that indicates an error (other than STATUS_UNSUCCESSFUL) is returned,
280 the traversal is stopped immediately and the status code is returned to
283 typedef NTSTATUS (*DEVICETREE_TRAVERSE_ROUTINE
)(
284 PDEVICE_NODE DeviceNode
,
287 /* Context information for traversing the device tree */
288 typedef struct _DEVICETREE_TRAVERSE_CONTEXT
290 /* Current device node during a traversal */
291 PDEVICE_NODE DeviceNode
;
292 /* Initial device node where we start the traversal */
293 PDEVICE_NODE FirstDeviceNode
;
294 /* Action routine to be called for every device node */
295 DEVICETREE_TRAVERSE_ROUTINE Action
;
296 /* Context passed to the action routine */
298 } DEVICETREE_TRAVERSE_CONTEXT
, *PDEVICETREE_TRAVERSE_CONTEXT
;
302 * IopInitDeviceTreeTraverseContext(
303 * PDEVICETREE_TRAVERSE_CONTEXT DeviceTreeTraverseContext,
304 * PDEVICE_NODE DeviceNode,
305 * DEVICETREE_TRAVERSE_ROUTINE Action,
308 #define IopInitDeviceTreeTraverseContext( \
309 _DeviceTreeTraverseContext, _DeviceNode, _Action, _Context) { \
310 (_DeviceTreeTraverseContext)->FirstDeviceNode = (_DeviceNode); \
311 (_DeviceTreeTraverseContext)->Action = (_Action); \
312 (_DeviceTreeTraverseContext)->Context = (_Context); }
315 extern PDEVICE_NODE IopRootDeviceNode
;
316 extern ULONG IoOtherOperationCount
;
317 extern ULONGLONG IoOtherTransferCount
;
323 IopInitDriverImplementation(VOID
);
326 IopGetSystemPowerDeviceObject(PDEVICE_OBJECT
*DeviceObject
);
328 IopCreateDeviceNode(PDEVICE_NODE ParentNode
,
329 PDEVICE_OBJECT PhysicalDeviceObject
,
330 PDEVICE_NODE
*DeviceNode
);
332 IopFreeDeviceNode(PDEVICE_NODE DeviceNode
);
335 IoInitCancelHandling(VOID
);
337 IoInitFileSystemImplementation(VOID
);
339 IoInitVpbImplementation(VOID
);
342 IoMountVolume(IN PDEVICE_OBJECT DeviceObject
,
343 IN BOOLEAN AllowRawMount
);
344 POBJECT
IoOpenSymlink(POBJECT SymbolicLink
);
345 POBJECT
IoOpenFileOnDevice(POBJECT SymbolicLink
, PWCHAR Name
);
348 IoSecondStageCompletion(
350 PKNORMAL_ROUTINE
* NormalRoutine
,
351 PVOID
* NormalContext
,
352 PVOID
* SystemArgument1
,
353 PVOID
* SystemArgument2
);
356 IopCreateFile(PVOID ObjectBody
,
359 POBJECT_ATTRIBUTES ObjectAttributes
);
361 IopCreateDevice(PVOID ObjectBody
,
364 POBJECT_ATTRIBUTES ObjectAttributes
);
365 NTSTATUS
IoAttachVpb(PDEVICE_OBJECT DeviceObject
);
367 PIRP
IoBuildSynchronousFsdRequestWithMdl(ULONG MajorFunction
,
368 PDEVICE_OBJECT DeviceObject
,
370 PLARGE_INTEGER StartingOffset
,
372 PIO_STATUS_BLOCK IoStatusBlock
,
375 VOID
IoInitShutdownNotification(VOID
);
376 VOID
IoShutdownRegisteredDevices(VOID
);
377 VOID
IoShutdownRegisteredFileSystems(VOID
);
380 IoPageWrite(PFILE_OBJECT FileObject
,
382 PLARGE_INTEGER Offset
,
384 PIO_STATUS_BLOCK StatusBlock
);
387 IoCreateArcNames(VOID
);
390 IoCreateSystemRootLink(PCHAR ParameterLine
);
394 PDEVICE_OBJECT DeviceObject
,
395 PIO_STATUS_BLOCK IoStatusBlock
,
397 PIO_STACK_LOCATION Stack
);
400 IopCreateUnicodeString(
401 PUNICODE_STRING Destination
,
407 IoCreateDriverList(VOID
);
410 IoDestroyDriverList(VOID
);
415 IopInitBootLog(VOID
);
418 IopStartBootLog(VOID
);
421 IopStopBootLog(VOID
);
424 IopBootLog(PUNICODE_STRING DriverName
, BOOLEAN Success
);
427 IopSaveBootLogToFile(VOID
);
432 IopInitErrorLog(VOID
);
438 RawFsIsRawFileSystemDeviceObject(IN PDEVICE_OBJECT DeviceObject
);
441 RawFsDriverEntry(PDRIVER_OBJECT DriverObject
,
442 PUNICODE_STRING RegistryPath
);
450 IN PDRIVER_OBJECT DriverObject
,
451 IN PUNICODE_STRING RegistryPath
);
455 PDEVICE_OBJECT
*PhysicalDeviceObject
);
461 PDEVICE_NODE DeviceNode
,
462 PDRIVER_OBJECT DriverObject
);
467 IopInitializeBootDrivers(VOID
);
470 IopInitializeSystemDrivers(VOID
);
473 IopCreateDriverObject(
474 PDRIVER_OBJECT
*DriverObject
,
475 PUNICODE_STRING ServiceName
,
476 BOOLEAN FileSystemDriver
,
477 PVOID DriverImageStart
,
478 ULONG DriverImageSize
);
481 IopLoadServiceModule(
482 IN PUNICODE_STRING ServiceName
,
483 OUT PMODULE_OBJECT
*ModuleObject
);
486 IopInitializeDriverModule(
487 IN PDEVICE_NODE DeviceNode
,
488 IN PMODULE_OBJECT ModuleObject
,
489 IN BOOLEAN FileSystemDriver
,
490 OUT PDRIVER_OBJECT
*DriverObject
);
493 IopAttachFilterDrivers(
494 PDEVICE_NODE DeviceNode
,
498 IopMarkLastReinitializeDriver(VOID
);
501 IopReinitializeDrivers(VOID
);
506 NTSTATUS INIT_FUNCTION
507 IopInitPlugPlayEvents(VOID
);
510 IopQueueTargetDeviceEvent(const GUID
*Guid
,
511 PUNICODE_STRING DeviceIds
);
517 IopInitializePnpServices(
518 IN PDEVICE_NODE DeviceNode
,
519 IN BOOLEAN BootDrivers
);
522 IopInvalidateDeviceRelations(
523 IN PDEVICE_NODE DeviceNode
,
524 IN DEVICE_RELATION_TYPE Type
);
529 IopInitTimerImplementation(VOID
);
533 IopRemoveTimerFromTimerList(
540 IopInitIoCompletionImplementation(VOID
);
542 #define CM_RESOURCE_LIST_SIZE(ResList) \
543 (ResList->Count == 1) ? \
544 FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList. \
545 PartialDescriptors[(ResList)->List[0].PartialResourceList.Count]) \
547 FIELD_OFFSET(CM_RESOURCE_LIST, List)