1 /* IO MANAGER ***************************************************************/
3 BOOLEAN
IoRaiseInformationalHardError(NTSTATUS ErrorStatus
,
4 PUNICODE_STRING String
,
9 * FUNCTION: Registers the driver with WMI
11 * DeviceObject = Device to register
12 * Action = Action to take
15 //NTSTATUS IoWMIRegistrationControl(DeviceObject, WMIREGACTION Action);
18 * FUNCTION: Synchronizes cancelable-state transistions for IRPs in a
19 * multiprocessor-safe way
21 * Irpl = Variable to store the current IRQ level
23 VOID
IoAcquireCancelSpinLock(PKIRQL Irpl
);
25 typedef IO_ALLOCATION_ACTION (*PDRIVER_CONTROL
)(PDEVICE_OBJECT DeviceObject
,
27 PVOID MapRegisterBase
,
31 * FUNCTION: Allocates an adaptor object for a DMA operation on the target
34 * Adaptor = Adapter channel or busmaster adapter to be allocated
35 * DeviceObject = Target device for DMA
36 * NumberOfMapRegisters = Number of map registers
37 * ExecutionRoutine = Routine to be called when the adaptor is
39 * Context = driver defined contex that will be passed to the
41 * RETURNS: Success or failure code
43 NTSTATUS
IoAllocateAdapterChannel(PADAPTER_OBJECT AdaperObject
,
44 PDEVICE_OBJECT DeviceObject
,
45 ULONG NumberOfMapRegisters
,
46 PDRIVER_CONTROL ExecutionRoutine
,
50 * FUNCTION: Sets up a call to a driver supplied controller object as
51 * soon as it is available
53 * ControllerObject = Driver created controller object
54 * DeviceObject = target device
55 * ExecutionObject = Routine to be called
56 * Context = Driver determined context to be based to the routine
58 VOID
IoAllocateController(PCONTROLLER_OBJECT ControllerObject
,
59 PDEVICE_OBJECT DeviceObject
,
60 PDRIVER_CONTROL ExecutionRoutine
,
64 * FUNCTION: Allocates an error log packet
66 * IoObject = Object which found the error
67 * EntrySize = Size in bytes of the packet to be allocated
68 * RETURNS: On success a pointer to the allocated packet
69 * On failure returns NULL
71 PVOID
IoAllocateErrorLogEntry(PVOID IoObject
, UCHAR EntrySize
);
74 * FUNCTION: Allocates an IRP
76 * StackSize = number of stack locations to allocate
77 * ChargeQuota = Who knows
78 * RETURNS: On success the allocated IRP
81 PIRP
IoAllocateIrp(CCHAR StackSize
, BOOLEAN ChargeQuota
);
84 * FUNCTION: Allocates an MDL large enough to map the supplied buffer
86 * VirtualAddress = base virtual address of the buffer to be mapped
87 * Length = length of the buffer to be mapped
88 * SecondaryBuffer = Whether the buffer is primary or secondary
89 * ChargeQuota = Charge non-paged pool quota to current thread
90 * Irp = Optional irp to be associated with the MDL
91 * RETURNS: On the success the allocated MDL
94 PMDL
IoAllocateMdl(PVOID VirtualAddress
, ULONG Length
,
95 BOOLEAN SecondaryBuffer
, BOOLEAN ChargeQuota
,
99 * FUNCTION: Creates a symbolic link between the ARC name of a physical
100 * device and the name of the corresponding device object
102 * ArcName = ARC name of the device
103 * DeviceName = Name of the device object
105 VOID
IoAssignArcName(PUNICODE_STRING ArcName
, PUNICODE_STRING DeviceName
);
113 * FUNCTION: Takes a list of requested hardware resources and allocates them
117 * DriverObject = Driver object passed to the DriverEntry routine
119 * RequestedResources = List of resources
122 NTSTATUS
IoAssignResources(PUNICODE_STRING RegistryPath
,
123 PUNICODE_STRING DriverClassName
,
124 PDRIVER_OBJECT DriverObject
,
125 PDEVICE_OBJECT DeviceObject
,
126 PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources
,
127 PCM_RESOURCE_LIST
* AllocatedResources
);
130 * FUNCTION: Attaches the callers device object to a named target device
132 * SourceDevice = caller's device
133 * TargetDevice = Name of the target device
134 * AttachedDevice = Caller allocated storage. On return contains
135 * a pointer to the target device
136 * RETURNS: Success or failure code
138 NTSTATUS
IoAttachDevice(PDEVICE_OBJECT SourceDevice
,
139 PUNICODE_STRING TargetDevice
,
140 PDEVICE_OBJECT
* AttachedDevice
);
145 * SourceDevice = device to attach
146 * TargetDevice = device to be attached to
147 * RETURNS: Success or failure code
149 NTSTATUS
IoAttachDeviceByPointer(PDEVICE_OBJECT SourceDevice
,
150 PDEVICE_OBJECT TargetDevice
);
153 * FUNCTION: Attaches the callers device to the highest device in the chain
155 * SourceDevice = caller's device
156 * TargetDevice = Device to attach
157 * RETURNS: On success the previously highest device
160 PDEVICE_OBJECT
IoAttachDeviceToDeviceStack(PDEVICE_OBJECT SourceDevice
,
161 PDEVICE_OBJECT TargetDevice
);
164 * FUNCTION: Builds a irp to be sent to lower level drivers
166 * MajorFunction = Major function code to be set in the IRP
167 * DeviceObject = Next lower device object
168 * Buffer = Buffer (only required for some major function codes)
169 * Length = Length in bytes of the buffer
170 * StartingOffset = Starting offset on the target device
171 * IoStatusBlock = Storage for status about the operation (optional)
172 * RETURNS: On success the IRP allocated
175 PIRP
IoBuildAsynchronousFsdRequest(ULONG MajorFunction
,
176 PDEVICE_OBJECT DeviceObject
,
179 PLARGE_INTEGER StartingOffset
,
180 PIO_STATUS_BLOCK IoStatusBlock
);
183 * FUNCTION: Allocates and sets up an IRP for a device control request
185 * IoControlCode = Type of request
186 * DeviceObject = Target device
187 * InputBuffer = Optional input buffer to the driver
188 * InputBufferLength = Length of the input buffer
189 * OutputBuffer = Optional output buffer
190 * OutputBufferLength = Length of the output buffer
191 * InternalDeviceIoControl = TRUE if the request is internal
192 * Event = Initialized event for the caller to wait for the request
194 * IoStatusBlock = I/O status block to be set when the request is
196 * RETURNS: Returns the IRP created
198 PIRP
IoBuildDeviceIoControlRequest(ULONG IoControlCode
,
199 PDEVICE_OBJECT DeviceObject
,
201 ULONG InputBufferLength
,
203 ULONG OutputBufferLength
,
204 BOOLEAN InternalDeviceIoControl
,
206 PIO_STATUS_BLOCK IoStatusBlock
);
209 VOID
IoBuildPartialMdl(PMDL SourceMdl
,
211 PVOID VirtualAddress
,
214 PIRP
IoBuildSynchronousFsdRequest(ULONG MajorFunction
,
215 PDEVICE_OBJECT DeviceObject
,
218 PLARGE_INTEGER StartingOffset
,
220 PIO_STATUS_BLOCK IoStatusBlock
);
223 * FUNCTION: Sends an irp to the next lower driver
225 NTSTATUS
IoCallDriver(PDEVICE_OBJECT DeviceObject
, PIRP irp
);
227 BOOLEAN
IoCancelIrp(PIRP Irp
);
229 NTSTATUS
IoCheckShareAccess(ACCESS_MASK DesiredAccess
,
230 ULONG DesiredShareAccess
,
231 PFILE_OBJECT FileObject
,
232 PSHARE_ACCESS ShareAccess
,
236 * FUNCTION: Indicates the caller has finished all processing for a given
237 * I/O request and is returning the given IRP to the I/O manager
239 * Irp = Irp to be cancelled
240 * PriorityBoost = Increment by which to boost the priority of the
241 * thread making the request
243 VOID
IoCompleteRequest(PIRP Irp
, CCHAR PriorityBoost
);
245 NTSTATUS
IoConnectInterrupt(PKINTERRUPT
* InterruptObject
,
246 PKSERVICE_ROUTINE ServiceRoutine
,
247 PVOID ServiceContext
,
248 PKSPIN_LOCK SpinLock
,
251 KIRQL SynchronizeIrql
,
252 KINTERRUPT_MODE InterruptMode
,
254 KAFFINITY ProcessorEnableMask
,
255 BOOLEAN FloatingSave
);
257 PCONTROLLER_OBJECT
IoCreateController(ULONG Size
);
260 * FUNCTION: Allocates memory for and intializes a device object for use for
263 * DriverObject : Driver object passed by iomgr when the driver was
265 * DeviceExtensionSize : Number of bytes for the device extension
266 * DeviceName : Unicode name of device
267 * DeviceType : Device type
268 * DeviceCharacteristics : Bit mask of device characteristics
269 * Exclusive : True if only one thread can access the device at a
273 * DeviceObject : Contains a pointer to allocated device object
274 * if the call succeeded
275 * NOTES: See the DDK documentation for more information
277 NTSTATUS
IoCreateDevice(PDRIVER_OBJECT DriverObject
,
278 ULONG DeviceExtensionSize
,
279 PUNICODE_STRING DeviceName
,
280 DEVICE_TYPE DeviceType
,
281 ULONG DeviceCharacteristics
,
283 PDEVICE_OBJECT
* DeviceObject
);
286 PKEVENT
IoCreateNotificationEvent(PUNICODE_STRING EventName
,
287 PHANDLE EventHandle
);
289 NTSTATUS
IoCreateSymbolicLink(PUNICODE_STRING SymbolicLinkName
,
290 PUNICODE_STRING DeviceName
);
292 PKEVENT
IoCreateSynchronizationEvent(PUNICODE_STRING EventName
,
293 PHANDLE EventHandle
);
295 NTSTATUS
IoCreateUnprotectedSymbolicLink(PUNICODE_STRING SymbolicLinkName
,
296 PUNICODE_STRING DeviceName
);
299 VOID
IoDeassignArcName(PUNICODE_STRING ArcName
);
301 VOID
IoDeleteController(PCONTROLLER_OBJECT ControllerObject
);
303 VOID
IoDeleteDevice(PDEVICE_OBJECT DeviceObject
);
305 NTSTATUS
IoDeleteSymbolicLink(PUNICODE_STRING SymbolicLinkName
);
307 VOID
IoDetachDevice(PDEVICE_OBJECT TargetDevice
);
309 VOID
IoDisconnectInterrupt(PKINTERRUPT InterruptObject
);
311 BOOLEAN
IoFlushAdapterBuffers(PADAPTER_OBJECT AdapterObject
,
313 PVOID MapRegisterBase
,
316 BOOLEAN WriteToDevice
);
318 VOID
IoFreeAdapterChannel(PADAPTER_OBJECT AdapterObject
);
319 VOID
IoFreeController(PCONTROLLER_OBJECT ControllerObject
);
320 VOID
IoFreeIrp(PIRP Irp
);
321 VOID
IoFreeMapRegisters(PADAPTER_OBJECT AdapterObject
,
322 PVOID MapRegisterBase
,
323 ULONG NumberOfMapRegisters
);
324 VOID
IoFreeMdl(PMDL Mdl
);
325 PCONFIGURATION_INFORMATION
IoGetConfigurationInformation(VOID
);
329 * FUNCTION: Returns a pointer to the callers stack location in the irp
331 PIO_STACK_LOCATION
IoGetCurrentIrpStackLocation(IRP
* irp
);
333 struct _EPROCESS
* IoGetCurrentProcess(VOID
);
335 NTSTATUS
IoGetDeviceObjectPointer(PUNICODE_STRING ObjectName
,
336 ACCESS_MASK DesiredAccess
,
337 PFILE_OBJECT
* FileObject
,
338 PDEVICE_OBJECT
* DeviceObject
);
340 PDEVICE_OBJECT
IoGetDeviceToVerify(PETHREAD Thread
);
342 PGENERIC_MAPPING
IoGetFileObjectGenericMapping(VOID
);
344 ULONG
IoGetFunctionCodeFromCtlCode(ULONG ControlCode
);
346 PVOID
IoGetInitialStack(VOID
);
351 PIO_STACK_LOCATION
IoGetNextIrpStackLocation(IRP
* irp
);
353 PDEVICE_OBJECT
IoGetRelatedDeviceObject(PFILE_OBJECT FileObject
);
355 VOID
IoInitializeDpcRequest(PDEVICE_OBJECT DeviceObject
,
356 PIO_DPC_ROUTINE DpcRoutine
);
359 * FUNCTION: Initalizes an irp allocated by the caller
361 * Irp = IRP to initalize
362 * PacketSize = Size in bytes of the IRP
363 * StackSize = Number of stack locations in the IRP
365 VOID
IoInitializeIrp(PIRP Irp
, USHORT PacketSize
, CCHAR StackSize
);
367 NTSTATUS
IoInitializeTimer(PDEVICE_OBJECT DeviceObject
,
368 PIO_TIMER_ROUTINE TimerRoutine
,
371 BOOLEAN
IoIsErrorUserInduced(NTSTATUS Status
);
373 BOOLEAN
IoIsTotalDeviceFailure(NTSTATUS Status
);
375 PIRP
IoMakeAssociatedIrp(PIRP Irp
, CCHAR StackSize
);
377 PHYSICAL_ADDRESS
IoMapTransfer(PADAPTER_OBJECT AdapterObject
,
379 PVOID MapRegisterBase
,
382 BOOLEAN WriteToDevice
);
385 * FUNCTION: Marks an IRP as pending
388 * NOTE: If a driver doesn't complete the irp in its dispatch routine it
389 * must mark it pending otherwise the I/O manager will complete it on
390 * return from the dispatch routine.
392 VOID
IoMarkIrpPending(PIRP Irp
);
394 NTSTATUS
IoQueryDeviceDescription(PINTERFACE_TYPE BusType
,
396 PCONFIGURATION_TYPE ControllerType
,
397 PULONG ControllerNumber
,
398 PCONFIGURATION_TYPE PeripheralType
,
399 PULONG PeripheralNumber
,
400 PIO_QUERY_DEVICE_ROUTINE CalloutRoutine
,
403 VOID
IoRaiseHardError(PIRP Irp
, PVPB Vpb
, PDEVICE_OBJECT RealDeviceObject
);
405 BOOLEAN
IoRaiseHardInformationalError(NTSTATUS ErrorStatus
,
406 PUNICODE_STRING String
,
409 NTSTATUS
IoReadPartitionTable(PDEVICE_OBJECT DeviceObject
,
411 BOOLEAN ReturnedRecognizedPartitions
,
412 struct _DRIVE_LAYOUT_INFORMATION
** PBuffer
);
414 VOID
IoRegisterDriverReinitialization(PDRIVER_OBJECT DriverObject
,
415 PDRIVER_REINITIALIZE ReinitRoutine
,
418 NTSTATUS
IoRegisterShutdownNotification(PDEVICE_OBJECT DeviceObject
);
420 VOID
IoReleaseCancelSpinLock(KIRQL Irql
);
422 VOID
IoRemoveShareAccess(PFILE_OBJECT FileObject
,
423 PSHARE_ACCESS ShareAccess
);
425 NTSTATUS
IoReportResourceUsage(PUNICODE_STRING DriverClassName
,
426 PDRIVER_OBJECT DriverObject
,
427 PCM_RESOURCE_LIST DriverList
,
428 ULONG DriverListSize
,
429 PDEVICE_OBJECT DeviceObject
,
430 PCM_RESOURCE_LIST DeviceList
,
431 ULONG DeviceListSize
,
432 BOOLEAN OverrideConflict
,
433 PBOOLEAN ConflictDetected
);
435 VOID
IoRequestDpc(PDEVICE_OBJECT DeviceObject
,
439 PDRIVER_CANCEL
IoSetCancelRoutine(PIRP Irp
, PDRIVER_CANCEL CancelRoutine
);
441 VOID
IoSetCompletionRoutine(PIRP Irp
,
442 PIO_COMPLETION_ROUTINE CompletionRoutine
,
444 BOOLEAN InvokeOnSuccess
,
445 BOOLEAN InvokeOnError
,
446 BOOLEAN InvokeOnCancel
);
448 VOID
IoSetHardErrorOrVerifyDevice(PIRP Irp
, PDEVICE_OBJECT DeviceObject
);
450 VOID
IoSetNextIrpStackLocation(PIRP Irp
);
452 NTSTATUS
IoSetPartitionInformation(PDEVICE_OBJECT DeviceObject
,
454 ULONG PartitionNumber
,
455 ULONG PartitionType
);
457 VOID
IoSetShareAccess(ACCESS_MASK DesiredAccess
,
458 ULONG DesiredShareAccess
,
459 PFILE_OBJECT FileObject
,
460 PSHARE_ACCESS ShareAccess
);
463 * FUNCTION: Determines the size of an IRP
465 * StackSize = number of stack locations in the IRP
466 * RETURNS: The size of the IRP in bytes
468 USHORT
IoSizeOfIrp(CCHAR StackSize
);
471 * FUNCTION: Dequeues the next IRP from the device's associated queue and
472 * calls its StartIo routine
474 * DeviceObject = Device object
475 * Cancelable = True if IRPs in the queue can be cancelled
477 VOID
IoStartNextPacket(PDEVICE_OBJECT DeviceObject
, BOOLEAN Cancelable
);
479 VOID
IoStartNextPacketByKey(PDEVICE_OBJECT DeviceObject
,
484 * FUNCTION: Calls the drivers StartIO routine with the IRP or queues it if
487 * DeviceObject = Device to pass the IRP to
488 * Irp = Irp to be processed
489 * Key = Optional value for where to insert the IRP
490 * CancelFunction = Entry point for a driver supplied cancel function
492 VOID
IoStartPacket(PDEVICE_OBJECT DeviceObject
, PIRP Irp
, PULONG Key
,
493 PDRIVER_CANCEL CancelFunction
);
495 VOID
IoStartTimer(PDEVICE_OBJECT DeviceObject
);
497 VOID
IoStopTimer(PDEVICE_OBJECT DeviceObject
);
499 VOID
IoUnregisterShutdownNotification(PDEVICE_OBJECT DeviceObject
);
501 VOID
IoUpdateShareAccess(PFILE_OBJECT FileObject
, PSHARE_ACCESS ShareAccess
);
503 VOID
IoWriteErrorLogEntry(PVOID ElEntry
);
505 NTSTATUS
IoWritePartitionTable(PDEVICE_OBJECT DeviceObject
,
507 ULONG SectorsPerTrack
,
509 struct _DRIVE_LAYOUT_INFORMATION
* PBuffer
);
513 NTKERNELAPI NTSTATUS
IoQueryFileVolumeInformation(IN PFILE_OBJECT FileObject
,
514 IN FS_INFORMATION_CLASS FsInformationClass
,
516 OUT PVOID FsInformation
,
517 OUT PULONG ReturnedLength
);
519 NTKERNELAPI
// confirmed - Undocumented because it does not require a valid file handle
521 IoQueryFileInformation(
522 IN PFILE_OBJECT FileObject
,
523 IN FILE_INFORMATION_CLASS FileInformationClass
,
525 OUT PVOID FileInformation
,
526 OUT PULONG ReturnedLength
528 VOID
IoRegisterFileSystem(PDEVICE_OBJECT DeviceObject
);
529 PDEVICE_OBJECT
IoGetAttachedDevice(PDEVICE_OBJECT DeviceObject
);
530 PFILE_OBJECT
IoCreateStreamFileObject(PFILE_OBJECT FileObject
,
531 PDEVICE_OBJECT DeviceObject
);