1 /* IO MANAGER ***************************************************************/
4 * FUNCTION: Registers the driver with WMI
6 * DeviceObject = Device to register
7 * Action = Action to take
10 //NTSTATUS IoWMIRegistrationControl(DeviceObject, WMIREGACTION Action);
13 * FUNCTION: Synchronizes cancelable-state transistions for IRPs in a
14 * multiprocessor-safe way
16 * Irpl = Variable to store the current IRQ level
18 VOID
IoAcquireCancelSpinLock(PKIRQL Irpl
);
20 typedef IO_ALLOCATION_ACTION (*PDRIVER_CONTROL
)(PDEVICE_OBJECT DeviceObject
,
22 PVOID MapRegisterBase
,
26 * FUNCTION: Allocates an adaptor object for a DMA operation on the target
29 * Adaptor = Adapter channel or busmaster adapter to be allocated
30 * DeviceObject = Target device for DMA
31 * NumberOfMapRegisters = Number of map registers
32 * ExecutionRoutine = Routine to be called when the adaptor is
34 * Context = driver defined contex that will be passed to the
36 * RETURNS: Success or failure code
38 NTSTATUS
IoAllocateAdapterChannel(PADAPTER_OBJECT AdaperObject
,
39 PDEVICE_OBJECT DeviceObject
,
40 ULONG NumberOfMapRegisters
,
41 PDRIVER_CONTROL ExecutionRoutine
,
45 * FUNCTION: Sets up a call to a driver supplied controller object as
46 * soon as it is available
48 * ControllerObject = Driver created controller object
49 * DeviceObject = target device
50 * ExecutionObject = Routine to be called
51 * Context = Driver determined context to be based to the routine
53 VOID
IoAllocateController(PCONTROLLER_OBJECT ControllerObject
,
54 PDEVICE_OBJECT DeviceObject
,
55 PDRIVER_CONTROL ExecutionRoutine
,
59 * FUNCTION: Allocates an error log packet
61 * IoObject = Object which found the error
62 * EntrySize = Size in bytes of the packet to be allocated
63 * RETURNS: On success a pointer to the allocated packet
64 * On failure returns NULL
66 PVOID
IoAllocateErrorLogEntry(PVOID IoObject
, UCHAR EntrySize
);
69 * FUNCTION: Allocates an IRP
71 * StackSize = number of stack locations to allocate
72 * ChargeQuota = Who knows
73 * RETURNS: On success the allocated IRP
76 PIRP
IoAllocateIrp(CCHAR StackSize
, BOOLEAN ChargeQuota
);
79 * FUNCTION: Allocates an MDL large enough to map the supplied buffer
81 * VirtualAddress = base virtual address of the buffer to be mapped
82 * Length = length of the buffer to be mapped
83 * SecondaryBuffer = Whether the buffer is primary or secondary
84 * ChargeQuota = Charge non-paged pool quota to current thread
85 * Irp = Optional irp to be associated with the MDL
86 * RETURNS: On the success the allocated MDL
89 PMDL
IoAllocateMdl(PVOID VirtualAddress
, ULONG Length
,
90 BOOLEAN SecondaryBuffer
, BOOLEAN ChargeQuota
,
94 * FUNCTION: Creates a symbolic link between the ARC name of a physical
95 * device and the name of the corresponding device object
97 * ArcName = ARC name of the device
98 * DeviceName = Name of the device object
100 VOID
IoAssignArcName(PUNICODE_STRING ArcName
, PUNICODE_STRING DeviceName
);
108 * FUNCTION: Takes a list of requested hardware resources and allocates them
112 * DriverObject = Driver object passed to the DriverEntry routine
114 * RequestedResources = List of resources
117 NTSTATUS
IoAssignResources(PUNICODE_STRING RegistryPath
,
118 PUNICODE_STRING DriverClassName
,
119 PDRIVER_OBJECT DriverObject
,
120 PDEVICE_OBJECT DeviceObject
,
121 PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources
,
122 PCM_RESOURCE_LIST
* AllocatedResources
);
125 * FUNCTION: Attaches the callers device object to a named target device
127 * SourceDevice = caller's device
128 * TargetDevice = Name of the target device
129 * AttachedDevice = Caller allocated storage. On return contains
130 * a pointer to the target device
131 * RETURNS: Success or failure code
133 NTSTATUS
IoAttachDevice(PDEVICE_OBJECT SourceDevice
,
134 PUNICODE_STRING TargetDevice
,
135 PDEVICE_OBJECT
* AttachedDevice
);
140 * SourceDevice = device to attach
141 * TargetDevice = device to be attached to
142 * RETURNS: Success or failure code
144 NTSTATUS
IoAttachDeviceByPointer(PDEVICE_OBJECT SourceDevice
,
145 PDEVICE_OBJECT TargetDevice
);
148 * FUNCTION: Attaches the callers device to the highest device in the chain
150 * SourceDevice = caller's device
151 * TargetDevice = Device to attach
152 * RETURNS: On success the previously highest device
155 PDEVICE_OBJECT
IoAttachDeviceToDeviceStack(PDEVICE_OBJECT SourceDevice
,
156 PDEVICE_OBJECT TargetDevice
);
159 * FUNCTION: Builds a irp to be sent to lower level drivers
161 * MajorFunction = Major function code to be set in the IRP
162 * DeviceObject = Next lower device object
163 * Buffer = Buffer (only required for some major function codes)
164 * Length = Length in bytes of the buffer
165 * StartingOffset = Starting offset on the target device
166 * IoStatusBlock = Storage for status about the operation (optional)
167 * RETURNS: On success the IRP allocated
170 PIRP
IoBuildAsynchronousFsdRequest(ULONG MajorFunction
,
171 PDEVICE_OBJECT DeviceObject
,
174 PLARGE_INTEGER StartingOffset
,
175 PIO_STATUS_BLOCK IoStatusBlock
);
178 * FUNCTION: Allocates and sets up an IRP for a device control request
180 * IoControlCode = Type of request
181 * DeviceObject = Target device
182 * InputBuffer = Optional input buffer to the driver
183 * InputBufferLength = Length of the input buffer
184 * OutputBuffer = Optional output buffer
185 * OutputBufferLength = Length of the output buffer
186 * InternalDeviceIoControl = TRUE if the request is internal
187 * Event = Initialized event for the caller to wait for the request
189 * IoStatusBlock = I/O status block to be set when the request is
191 * RETURNS: Returns the IRP created
193 PIRP
IoBuildDeviceIoControlRequest(ULONG IoControlCode
,
194 PDEVICE_OBJECT DeviceObject
,
196 ULONG InputBufferLength
,
198 ULONG OutputBufferLength
,
199 BOOLEAN InternalDeviceIoControl
,
201 PIO_STATUS_BLOCK IoStatusBlock
);
204 VOID
IoBuildPartialMdl(PMDL SourceMdl
,
206 PVOID VirtualAddress
,
209 PIRP
IoBuildSynchronousFsdRequest(ULONG MajorFunction
,
210 PDEVICE_OBJECT DeviceObject
,
213 PLARGE_INTEGER StartingOffset
,
215 PIO_STATUS_BLOCK IoStatusBlock
);
218 * FUNCTION: Sends an irp to the next lower driver
220 NTSTATUS
IoCallDriver(PDEVICE_OBJECT DeviceObject
, PIRP irp
);
222 BOOLEAN
IoCancelIrp(PIRP Irp
);
224 NTSTATUS
IoCheckShareAccess(ACCESS_MASK DesiredAccess
,
225 ULONG DesiredShareAccess
,
226 PFILE_OBJECT FileObject
,
227 // PSHARE_ACCESS ShareAccess,
231 * FUNCTION: Indicates the caller has finished all processing for a given
232 * I/O request and is returning the given IRP to the I/O manager
234 * Irp = Irp to be cancelled
235 * PriorityBoost = Increment by which to boost the priority of the
236 * thread making the request
238 VOID
IoCompleteRequest(PIRP Irp
, CCHAR PriorityBoost
);
240 NTSTATUS
IoConnectInterrupt(PKINTERRUPT
* InterruptObject
,
241 PKSERVICE_ROUTINE ServiceRoutine
,
242 PVOID ServiceContext
,
243 PKSPIN_LOCK SpinLock
,
246 KIRQL SynchronizeIrql
,
247 KINTERRUPT_MODE InterruptMode
,
249 KAFFINITY ProcessorEnableMask
,
250 BOOLEAN FloatingSave
);
252 PCONTROLLER_OBJECT
IoCreateController(ULONG Size
);
255 * FUNCTION: Allocates memory for and intializes a device object for use for
258 * DriverObject : Driver object passed by iomgr when the driver was
260 * DeviceExtensionSize : Number of bytes for the device extension
261 * DeviceName : Unicode name of device
262 * DeviceType : Device type
263 * DeviceCharacteristics : Bit mask of device characteristics
264 * Exclusive : True if only one thread can access the device at a
268 * DeviceObject : Contains a pointer to allocated device object
269 * if the call succeeded
270 * NOTES: See the DDK documentation for more information
272 NTSTATUS
IoCreateDevice(PDRIVER_OBJECT DriverObject
,
273 ULONG DeviceExtensionSize
,
274 PUNICODE_STRING DeviceName
,
275 DEVICE_TYPE DeviceType
,
276 ULONG DeviceCharacteristics
,
278 PDEVICE_OBJECT
* DeviceObject
);
281 PKEVENT
IoCreateNotificationEvent(PUNICODE_STRING EventName
,
282 PHANDLE EventHandle
);
284 NTSTATUS
IoCreateSymbolicLink(PUNICODE_STRING SymbolicLinkName
,
285 PUNICODE_STRING DeviceName
);
287 PKEVENT
IoCreateSynchronizationEvent(PUNICODE_STRING EventName
,
288 PHANDLE EventHandle
);
290 NTSTATUS
IoCreateUnprotectedSymbolicLink(PUNICODE_STRING SymbolicLinkName
,
291 PUNICODE_STRING DeviceName
);
294 VOID
IoDeassignArcName(PUNICODE_STRING ArcName
);
296 VOID
IoDeleteController(PCONTROLLER_OBJECT ControllerObject
);
298 VOID
IoDeleteDevice(PDEVICE_OBJECT DeviceObject
);
300 NTSTATUS
IoDeleteSymbolicLink(PUNICODE_STRING SymbolicLinkName
);
302 VOID
IoDetachDevice(PDEVICE_OBJECT TargetDevice
);
304 VOID
IoDisconnectInterrupt(PKINTERRUPT InterruptObject
);
306 BOOLEAN
IoFlushAdapterBuffers(PADAPTER_OBJECT AdapterObject
,
308 PVOID MapRegisterBase
,
311 BOOLEAN WriteToDevice
);
313 VOID
IoFreeAdapterChannel(PADAPTER_OBJECT AdapterObject
);
314 VOID
IoFreeController(PCONTROLLER_OBJECT ControllerObject
);
315 VOID
IoFreeIrp(PIRP Irp
);
316 VOID
IoFreeMapRegisters(PADAPTER_OBJECT AdapterObject
,
317 PVOID MapRegisterBase
,
318 ULONG NumberOfMapRegisters
);
319 VOID
IoFreeMdl(PMDL Mdl
);
320 PCONFIGURATION_INFORMATION
IoGetConfigurationInformation(VOID
);
324 * FUNCTION: Returns a pointer to the callers stack location in the irp
326 PIO_STACK_LOCATION
IoGetCurrentIrpStackLocation(IRP
* irp
);
328 PEPROCESS
IoGetCurrentProcess(VOID
);
330 NTSTATUS
IoGetDeviceObjectPointer(PUNICODE_STRING ObjectName
,
331 ACCESS_MASK DesiredAccess
,
332 PFILE_OBJECT
* FileObject
,
333 PDEVICE_OBJECT
* DeviceObject
);
335 PDEVICE_OBJECT
IoGetDeviceToVerify(PETHREAD Thread
);
337 PGENERIC_MAPPING
IoGetFileObjectGenericMapping(VOID
);
339 ULONG
IoGetFunctionCodeFromCtlCode(ULONG ControlCode
);
341 PVOID
IoGetInitialStack(VOID
);
346 PIO_STACK_LOCATION
IoGetNextIrpStackLocation(IRP
* irp
);
348 PDEVICE_OBJECT
IoGetRelatedDeviceObject(PFILE_OBJECT FileObject
);
350 VOID
IoInitializeDpcRequest(PDEVICE_OBJECT DeviceObject
,
351 PIO_DPC_ROUTINE DpcRoutine
);
354 * FUNCTION: Initalizes an irp allocated by the caller
356 * Irp = IRP to initalize
357 * PacketSize = Size in bytes of the IRP
358 * StackSize = Number of stack locations in the IRP
360 VOID
IoInitializeIrp(PIRP Irp
, USHORT PacketSize
, CCHAR StackSize
);
362 NTSTATUS
IoInitializeTimer(PDEVICE_OBJECT DeviceObject
,
363 PIO_TIMER_ROUTINE TimerRoutine
,
366 BOOLEAN
IoIsErrorUserInduced(NTSTATUS Status
);
368 BOOLEAN
IoIsTotalDeviceFailure(NTSTATUS Status
);
370 PIRP
IoMakeAssociatedIrp(PIRP Irp
, CCHAR StackSize
);
372 PHYSICAL_ADDRESS
IoMapTransfer(PADAPTER_OBJECT AdapterObject
,
374 PVOID MapRegisterBase
,
377 BOOLEAN WriteToDevice
);
380 * FUNCTION: Marks an IRP as pending
383 * NOTE: If a driver doesn't complete the irp in its dispatch routine it
384 * must mark it pending otherwise the I/O manager will complete it on
385 * return from the dispatch routine.
387 VOID
IoMarkIrpPending(PIRP Irp
);
389 NTSTATUS
IoQueryDeviceDescription(PINTERFACE_TYPE BusType
,
391 PCONFIGURATION_TYPE ControllerType
,
392 PULONG ControllerNumber
,
393 PCONFIGURATION_TYPE PeripheralType
,
394 PULONG PeripheralNumber
,
395 PIO_QUERY_DEVICE_ROUTINE CalloutRoutine
,
398 VOID
IoRaiseHardError(PIRP Irp
, PVPB Vpb
, PDEVICE_OBJECT RealDeviceObject
);
400 BOOLEAN
IoRaiseHardInformationalError(NTSTATUS ErrorStatus
,
401 PUNICODE_STRING String
,
404 NTSTATUS
IoReadPartitionTable(PDEVICE_OBJECT DeviceObject
,
406 BOOLEAN ReturnedRecognizedPartitions
,
407 struct _DRIVER_LAYOUT_INFORMATION
** PBuffer
);
409 VOID
IoRegisterDriverReinitialization(PDRIVER_OBJECT DriverObject
,
410 PDRIVER_REINITIALIZE ReinitRoutine
,
413 NTSTATUS
IoRegisterShutdownNotification(PDEVICE_OBJECT DeviceObject
);
415 VOID
IoReleaseCancelSpinLock(KIRQL Irql
);
417 VOID
IoRemoveShareAccess(PFILE_OBJECT FileObject
,
418 PSHARE_ACCESS ShareAccess
);
420 NTSTATUS
IoReportResourceUsage(PUNICODE_STRING DriverClassName
,
421 PDRIVER_OBJECT DriverObject
,
422 PCM_RESOURCE_LIST DriverList
,
423 ULONG DriverListSize
,
424 PDEVICE_OBJECT DeviceObject
,
425 PCM_RESOURCE_LIST DeviceList
,
426 ULONG DeviceListSize
,
427 BOOLEAN OverrideConflict
,
428 PBOOLEAN ConflictDetected
);
430 VOID
IoRequestDpc(PDEVICE_OBJECT DeviceObject
,
434 PDRIVER_CANCEL
IoSetCancelRoutine(PIRP Irp
, PDRIVER_CANCEL CancelRoutine
);
436 VOID
IoSetCompletionRoutine(PIRP Irp
,
437 PIO_COMPLETION_ROUTINE CompletionRoutine
,
439 BOOLEAN InvokeOnSuccess
,
440 BOOLEAN InvokeOnError
,
441 BOOLEAN InvokeOnCancel
);
443 VOID
IoSetHardErrorOrVerifyDevice(PIRP Irp
, PDEVICE_OBJECT DeviceObject
);
445 VOID
IoSetNextIrpStackLocation(PIRP Irp
);
447 NTSTATUS
IoSetPartitionInformation(PDEVICE_OBJECT DeviceObject
,
449 ULONG PartitionNumber
,
450 ULONG PartitionType
);
452 VOID
IoSetShareAccess(ACCESS_MASK DesiredAccess
,
453 ULONG DesiredShareAccess
,
454 PFILE_OBJECT FileObject
,
455 PSHARE_ACCESS ShareAccess
);
458 * FUNCTION: Determines the size of an IRP
460 * StackSize = number of stack locations in the IRP
461 * RETURNS: The size of the IRP in bytes
463 USHORT
IoSizeOfIrp(CCHAR StackSize
);
466 * FUNCTION: Dequeues the next IRP from the device's associated queue and
467 * calls its StartIo routine
469 * DeviceObject = Device object
470 * Cancelable = True if IRPs in the queue can be cancelled
472 VOID
IoStartNextPacket(PDEVICE_OBJECT DeviceObject
, BOOLEAN Cancelable
);
474 VOID
IoStartNextPacketByKey(PDEVICE_OBJECT DeviceObject
,
479 * FUNCTION: Calls the drivers StartIO routine with the IRP or queues it if
482 * DeviceObject = Device to pass the IRP to
483 * Irp = Irp to be processed
484 * Key = Optional value for where to insert the IRP
485 * CancelFunction = Entry point for a driver supplied cancel function
487 VOID
IoStartPacket(PDEVICE_OBJECT DeviceObject
, PIRP Irp
, PULONG Key
,
488 PDRIVER_CANCEL CancelFunction
);
490 VOID
IoStartTimer(PDEVICE_OBJECT DeviceObject
);
492 VOID
IoStopTimer(PDEVICE_OBJECT DeviceObject
);
494 VOID
IoUnregisterShutdownNotification(PDEVICE_OBJECT DeviceObject
);
496 VOID
IoUpdateShareAccess(PFILE_OBJECT FileObject
, PSHARE_ACCESS ShareAccess
);
498 VOID
IoWriteErrorLogEntry(PVOID ElEntry
);
500 NTSTATUS
IoWritePartitionTable(PDEVICE_OBJECT DeviceObject
,
502 ULONG SectorsPerTrack
,
504 struct _DRIVE_LAYOUT_INFORMATION
* PBuffer
);