download irp.c
Language: C
LOC: 223
Project Info
owp
Server: SourceForge
Type: cvs
...owp\owp\kernel\ntoskrnl\io\
   .cvsignore
   adapter.c
   buildirp.c
   cancel.c
   cleanup.c
   cntrller.c
   create.c
   device.c
   dir.c
   drvlck.c
   errlog.c
   error.c
   event.c
   file.c
   flush.c
   fs.c
   iocomp.c
   ioctrl.c
   iomgr.c
   irp.c
   lock.c
   mailslot.c
   mdl.c
   npipe.c
   page.c
   pnpmgr.c
   pnproot.c
   process.c
   queue.c
   resource.c
   rw.c
   share.c
   shutdown.c
   symlink.c
   timer.c
   vpb.c
   xhaldisp.c
   xhaldrv.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/* $Id: irp.c,v 1.1.1.1 2001/12/18 23:40:40 brandon6684 Exp $
 *
 * COPYRIGHT:       See COPYING in the top level directory
 * PROJECT:         ReactOS kernel
 * FILE:            ntoskrnl/io/irp.c
 * PURPOSE:         Handle IRPs
 * PROGRAMMER:      David Welch (welch@mcmail.com)
 * UPDATE HISTORY: 
 *                  24/05/98: Created 
 */

/* NOTES *******************************************************************
 * 
 * Layout of an IRP 
 * 
 *             ################
 *             #    Headers   #
 *             ################
 *             #              #
 *             #   Variable   #
 *             # length list  #
 *             # of io stack  #
 *             #  locations   #
 *             #              #
 *             ################
 * 
 * 
 * 
 */

/* INCLUDES ****************************************************************/

#include <ddk/ntddk.h>
#include <internal/io.h>
#include <internal/ps.h>
#include <internal/pool.h>

#define NDEBUG
#include <internal/debug.h>

/* GLOBALS *******************************************************************/

#define TAG_IRP     TAG('I', 'R', 'P', ' ')

/* FUNCTIONS ****************************************************************/


VOID STDCALL
IoFreeIrp (PIRP Irp)
/*
 * FUNCTION: Releases a caller allocated irp
 * ARGUMENTS:
 *      Irp = Irp to free
 */
{
   ExFreePool(Irp);
}


PIRP STDCALL
IoMakeAssociatedIrp (PIRP Irp, CCHAR StackSize)
/*
 * FUNCTION: Allocates and initializes an irp to associated with a master irp
 * ARGUMENTS:
 *       Irp = Master irp
 *       StackSize = Number of stack locations to be allocated in the irp
 * RETURNS: The irp allocated
 */
{
   PIRP AssocIrp;
   
   AssocIrp = IoAllocateIrp(StackSize,FALSE);
   UNIMPLEMENTED;
}


VOID STDCALL
IoInitializeIrp (PIRP Irp, USHORT PacketSize, CCHAR StackSize)
/*
 * FUNCTION: Initalizes an irp allocated by the caller
 * ARGUMENTS:
 *          Irp = IRP to initalize
 *          PacketSize = Size in bytes of the IRP
 *          StackSize = Number of stack locations in the IRP
 */
{
   assert(Irp != NULL);

   memset(Irp, 0, PacketSize);
   Irp->Size = PacketSize;
   Irp->StackCount = StackSize;
   Irp->CurrentLocation = StackSize;
   Irp->Tail.Overlay.CurrentStackLocation = IoGetCurrentIrpStackLocation(Irp);
}


NTSTATUS FASTCALL
IofCallDriver (PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
  * FUNCTION: Sends an IRP to the next lower driver
 */
{
   NTSTATUS Status;
   PDRIVER_OBJECT DriverObject;
   PIO_STACK_LOCATION Param;
   
   DPRINT("IofCallDriver(DeviceObject %x, Irp %x)\n",DeviceObject,Irp);
   
   assert(Irp);
   assert(DeviceObject);

   DriverObject = DeviceObject->DriverObject;

   assert(DriverObject);

   Param = IoGetNextIrpStackLocation(Irp);

   DPRINT("IrpSp 0x%X\n", Param);
   
   Irp->Tail.Overlay.CurrentStackLocation--;
   Irp->CurrentLocation--;
   
   DPRINT("MajorFunction %d\n", Param->MajorFunction);
   DPRINT("DriverObject->MajorFunction[Param->MajorFunction] %x\n",
	    DriverObject->MajorFunction[Param->MajorFunction]);
   Status = DriverObject->MajorFunction[Param->MajorFunction](DeviceObject,
							      Irp);
   return Status;
}


NTSTATUS
STDCALL
IoCallDriver (PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
	return IofCallDriver (
			DeviceObject,
			Irp
			);
}


PIRP
STDCALL
IoAllocateIrp (CCHAR StackSize, BOOLEAN ChargeQuota)
/*
 * FUNCTION: Allocates an IRP
 * ARGUMENTS:
 *          StackSize = the size of the stack required for the irp
 *          ChargeQuota = Charge allocation to current threads quota
 * RETURNS: Irp allocated
 */
{
   PIRP Irp;

#if 0
   DbgPrint("IoAllocateIrp(StackSize %d ChargeQuota %d)\n",
          StackSize,
	  ChargeQuota);
   KeDumpStackFrames(0,8);
#endif
   
   if (ChargeQuota)
     {
//	Irp = ExAllocatePoolWithQuota(NonPagedPool,IoSizeOfIrp(StackSize));
	Irp = ExAllocatePoolWithTag(NonPagedPool, IoSizeOfIrp(StackSize), 
				    TAG_IRP);
     }
   else
     {	
	Irp = ExAllocatePoolWithTag(NonPagedPool,IoSizeOfIrp(StackSize),
				    TAG_IRP);
     }
      
   if (Irp==NULL)
     {
	return(NULL);
     }
   
   IoInitializeIrp(Irp, IoSizeOfIrp(StackSize), StackSize);

//   DPRINT("Irp %x Irp->StackPtr %d\n", Irp, Irp->CurrentLocation);

   return Irp;
}


VOID IopCompleteRequest(struct _KAPC* Apc,
			PKNORMAL_ROUTINE* NormalRoutine,
			PVOID* NormalContext,
			PVOID* SystemArgument1,
			PVOID* SystemArgument2)
{
   DPRINT("IopCompleteRequest(Apc %x, SystemArgument1 %x, "
	  "(*SystemArgument1) %x\n", Apc, SystemArgument1,
	  *SystemArgument1);
   IoSecondStageCompletion((PIRP)(*SystemArgument1),
                           (KPRIORITY)(*SystemArgument2));
}


VOID
FASTCALL
IofCompleteRequest (PIRP Irp, CCHAR PriorityBoost)
/*
 * FUNCTION: Indicates the caller has finished all processing for a given
 * I/O request and is returning the given IRP to the I/O manager
 * ARGUMENTS:
 *         Irp = Irp to be cancelled
 *         PriorityBoost = Increment by which to boost the priority of the
 *                         thread making the request
 */
{
   unsigned int i;
   NTSTATUS Status;
   
   DPRINT("IoCompleteRequest(Irp %x, PriorityBoost %d) Event %x THread %x\n",
	   Irp,PriorityBoost, Irp->UserEvent, PsGetCurrentThread());

   for (i=0;i<Irp->StackCount;i++)
     {
	if (Irp->Stack[i].CompletionRoutine != NULL)
	  {
	     Status = Irp->Stack[i].CompletionRoutine(
					     Irp->Stack[i].DeviceObject,
					     Irp,
					     Irp->Stack[i].CompletionContext);
	     if (Status == STATUS_MORE_PROCESSING_REQUIRED)
	       {
		  return;
	       }
	  }
	if (Irp->Stack[i].Control & SL_PENDING_RETURNED)
	  {
	     Irp->PendingReturned = TRUE;
	  }
     }
   if (Irp->PendingReturned)
     {
	DPRINT("Dispatching APC\n");
	KeInitializeApc(&Irp->Tail.Apc,
			&Irp->Tail.Overlay.Thread->Tcb,
			0,
			IopCompleteRequest,
			NULL,
			(PKNORMAL_ROUTINE)
			NULL,
			KernelMode,
			NULL);
	KeInsertQueueApc(&Irp->Tail.Apc,
			 (PVOID)Irp,
			 (PVOID)(ULONG)PriorityBoost,
			 KernelMode);
	DPRINT("Finished dispatching APC\n");
     }
   else
     {
	DPRINT("Calling completion routine directly\n");
	IoSecondStageCompletion(Irp,PriorityBoost);
	DPRINT("Finished completition routine\n");
     }
}


VOID
STDCALL
IoCompleteRequest (PIRP Irp, CCHAR PriorityBoost)
{
	IofCompleteRequest (
		Irp,
		PriorityBoost
		);
}


/**********************************************************************
 * NAME							EXPORTED
 * 	IoIsOperationSynchronous@4
 *
 * DESCRIPTION
 *	Check if the I/O operation associated with the given IRP
 *	is synchronous.
 *
 * ARGUMENTS
 * 	Irp 	Packet to check.
 *
 * RETURN VALUE
 * 	TRUE if Irp's operation is synchronous; otherwise FALSE.
 */
BOOLEAN
STDCALL
IoIsOperationSynchronous (
	IN	PIRP	Irp
	)
{
	ULONG		Flags = 0;
	PFILE_OBJECT	FileObject = NULL;
	
	/*
	 * Check the associated FILE_OBJECT's
	 * flags first.
	 */
	FileObject = Irp->Tail.Overlay.OriginalFileObject;
	if (!(FO_SYNCHRONOUS_IO & FileObject->Flags))
	{
		/* Check IRP's flags. */
		Flags = Irp->Flags;
		if (!(	(IRP_SYNCHRONOUS_API | IRP_SYNCHRONOUS_PAGING_IO)
			& Flags
			))
		{
			return FALSE;
		}
	}
	/*
	 * Check more IRP's flags.
	 */
	Flags = Irp->Flags;
	if (	!(IRP_MOUNT_COMPLETION & Flags)
		|| (IRP_SYNCHRONOUS_PAGING_IO & Flags)
		)
	{
		return TRUE;
	}
	/*
	 * Otherwise, it is an
	 * asynchronous operation.
	 */
	return FALSE;
}


VOID
STDCALL
IoEnqueueIrp (
	PIRP	Irp
	)
{
	UNIMPLEMENTED;
}


VOID
STDCALL
IoSetTopLevelIrp (
	IN	PIRP	Irp
	)
{
	PETHREAD Thread;

	Thread = PsGetCurrentThread ();
	Thread->TopLevelIrp->TopLevelIrp = Irp;
}


PIRP
STDCALL
IoGetTopLevelIrp (
	VOID
	)
{
	return (PsGetCurrentThread ()->TopLevelIrp->TopLevelIrp);
}


VOID
STDCALL
IoQueueThreadIrp (
	PVOID	Unknown0
	)
{
	UNIMPLEMENTED;
}

/* EOF */

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us