3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/io/irp.c
7 * PROGRAMMER: David Welch (welch@mcmail.com)
12 /* NOTES *******************************************************************
31 /* INCLUDES ****************************************************************/
33 #include <ddk/ntddk.h>
34 #include <internal/io.h>
35 #include <internal/ps.h>
36 #include <internal/pool.h>
39 #include <internal/debug.h>
41 /* GLOBALS *******************************************************************/
43 #define TAG_IRP TAG('I', 'R', 'P', ' ')
46 /* FUNCTIONS ****************************************************************/
52 * FUNCTION: Releases a caller allocated irp
63 IoMakeAssociatedIrp(PIRP Irp,
66 * FUNCTION: Allocates and initializes an irp to associated with a master irp
69 * StackSize = Number of stack locations to be allocated in the irp
70 * RETURNS: The irp allocated
75 AssocIrp = IoAllocateIrp(StackSize,FALSE);
79 #endif /* LIBCAPTIVE */
82 IoInitializeIrp(PIRP Irp,
86 * FUNCTION: Initalizes an irp allocated by the caller
88 * Irp = IRP to initalize
89 * PacketSize = Size in bytes of the IRP
90 * StackSize = Number of stack locations in the IRP
95 memset(Irp, 0, PacketSize);
96 Irp->Size = PacketSize;
97 Irp->StackCount = StackSize;
98 Irp->CurrentLocation = StackSize;
99 Irp->Tail.Overlay.CurrentStackLocation = &Irp->Stack[(ULONG)StackSize];
104 IofCallDriver(PDEVICE_OBJECT DeviceObject,
107 * FUNCTION: Sends an IRP to the next lower driver
111 PDRIVER_OBJECT DriverObject;
112 PIO_STACK_LOCATION Param;
114 DPRINT("IofCallDriver(DeviceObject %x, Irp %x)\n",DeviceObject,Irp);
117 assert(DeviceObject);
119 DriverObject = DeviceObject->DriverObject;
121 assert(DriverObject);
123 Param = IoGetNextIrpStackLocation(Irp);
125 DPRINT("IrpSp 0x%X\n", Param);
127 Irp->Tail.Overlay.CurrentStackLocation--;
128 Irp->CurrentLocation--;
130 DPRINT("MajorFunction %d\n", Param->MajorFunction);
131 DPRINT("DriverObject->MajorFunction[Param->MajorFunction] %x\n",
132 DriverObject->MajorFunction[Param->MajorFunction]);
133 Status = DriverObject->MajorFunction[Param->MajorFunction](DeviceObject,
142 IoCallDriver (PDEVICE_OBJECT DeviceObject, PIRP Irp)
144 return(IofCallDriver(DeviceObject,
150 IoAllocateIrp(CCHAR StackSize,
153 * FUNCTION: Allocates an IRP
155 * StackSize = the size of the stack required for the irp
156 * ChargeQuota = Charge allocation to current threads quota
157 * RETURNS: Irp allocated
163 DbgPrint("IoAllocateIrp(StackSize %d ChargeQuota %d)\n",
166 KeDumpStackFrames(0,8);
171 // Irp = ExAllocatePoolWithQuota(NonPagedPool,IoSizeOfIrp(StackSize));
172 Irp = ExAllocatePoolWithTag(NonPagedPool,
173 IoSizeOfIrp(StackSize),
178 Irp = ExAllocatePoolWithTag(NonPagedPool,
179 IoSizeOfIrp(StackSize),
189 IoSizeOfIrp(StackSize),
192 // DPRINT("Irp %x Irp->StackPtr %d\n", Irp, Irp->CurrentLocation);
200 IopCompleteRequest(struct _KAPC* Apc,
201 PKNORMAL_ROUTINE* NormalRoutine,
202 PVOID* NormalContext,
203 PVOID* SystemArgument1,
204 PVOID* SystemArgument2)
206 DPRINT("IopCompleteRequest(Apc %x, SystemArgument1 %x, (*SystemArgument1) %x\n",
210 IoSecondStageCompletion((PIRP)(*SystemArgument1),
211 (KPRIORITY)(*SystemArgument2));
214 #endif /* LIBCAPTIVE */
217 IofCompleteRequest(PIRP Irp,
220 * FUNCTION: Indicates the caller has finished all processing for a given
221 * I/O request and is returning the given IRP to the I/O manager
223 * Irp = Irp to be cancelled
224 * PriorityBoost = Increment by which to boost the priority of the
225 * thread making the request
231 DPRINT("IoCompleteRequest(Irp %x, PriorityBoost %d) Event %x THread %x\n",
232 Irp,PriorityBoost, Irp->UserEvent, PsGetCurrentThread());
234 for (i=Irp->CurrentLocation;i<(int)Irp->StackCount;i++)
236 if (Irp->Stack[i].CompletionRoutine != NULL)
238 Status = Irp->Stack[i].CompletionRoutine(
239 Irp->Stack[i].DeviceObject,
241 Irp->Stack[i].CompletionContext);
242 if (Status == STATUS_MORE_PROCESSING_REQUIRED)
247 if (Irp->Stack[i].Control & SL_PENDING_RETURNED)
249 Irp->PendingReturned = TRUE;
251 if (Irp->CurrentLocation < Irp->StackCount - 1)
253 IoSkipCurrentIrpStackLocation(Irp);
256 if (Irp->PendingReturned)
258 DPRINT("Dispatching APC\n");
260 KeInitializeApc(&Irp->Tail.Apc,
261 &Irp->Tail.Overlay.Thread->Tcb,
269 KeInsertQueueApc(&Irp->Tail.Apc,
271 (PVOID)(ULONG)PriorityBoost,
273 DPRINT("Finished dispatching APC\n");
274 #else /* !LIBCAPTIVE */
276 #endif /* !LIBCAPTIVE */
280 DPRINT("Calling completion routine directly\n");
281 IoSecondStageCompletion(Irp,PriorityBoost);
282 DPRINT("Finished completition routine\n");
288 IoCompleteRequest(PIRP Irp,
291 IofCompleteRequest(Irp,
297 /**********************************************************************
299 * IoIsOperationSynchronous@4
302 * Check if the I/O operation associated with the given IRP
306 * Irp Packet to check.
309 * TRUE if Irp's operation is synchronous; otherwise FALSE.
312 IoIsOperationSynchronous(IN PIRP Irp)
314 PFILE_OBJECT FileObject = NULL;
317 /* Check the FILE_OBJECT's flags first. */
318 FileObject = IoGetCurrentIrpStackLocation(Irp)->FileObject;
319 if (!(FO_SYNCHRONOUS_IO & FileObject->Flags))
321 /* Check IRP's flags. */
323 if (!((IRP_SYNCHRONOUS_API | IRP_SYNCHRONOUS_PAGING_IO) & Flags))
329 /* Check more IRP's flags. */
331 if (!(IRP_PAGING_IO & Flags)
332 || (IRP_SYNCHRONOUS_PAGING_IO & Flags))
337 /* Otherwise, it is an asynchronous operation. */
343 IoEnqueueIrp(IN PIRP Irp)
348 #endif /* LIBCAPTIVE */
351 IoSetTopLevelIrp(IN PIRP Irp)
355 Thread = PsGetCurrentThread();
356 Thread->TopLevelIrp->TopLevelIrp = Irp;
361 IoGetTopLevelIrp(VOID)
363 return(PsGetCurrentThread()->TopLevelIrp->TopLevelIrp);
369 IoQueueThreadIrp(IN PIRP Irp)
377 IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
386 IN PDEVICE_OBJECT DeviceObject,
387 IN DEVICE_REGISTRY_PROPERTY DeviceProperty,
388 IN ULONG BufferLength,
389 OUT PVOID PropertyBuffer,
390 OUT PULONG ResultLength)
398 IoOpenDeviceRegistryKey(
399 IN PDEVICE_OBJECT DeviceObject,
400 IN ULONG DevInstKeyType,
401 IN ACCESS_MASK DesiredAccess,
402 OUT PHANDLE DevInstRegKey)
409 #endif /* LIBCAPTIVE */