ReactOS  0.4.13-dev-563-g0561610
dispatcher.cpp
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Kernel Streaming
4  * FILE: drivers/wdm/audio/backpln/portcls/dispatcher.c
5  * PURPOSE: portcls generic dispatcher
6  * PROGRAMMER: Johannes Anderwald
7  */
8 
9 #include "private.hpp"
10 
11 #ifndef YDEBUG
12 #define NDEBUG
13 #endif
14 
15 #include <debug.h>
16 
18 NTAPI
21  PIRP Irp)
22 {
23  PIO_STACK_LOCATION IoStack;
24  PDISPATCH_CONTEXT DispatchContext;
25 
26  // get current irp stack
28 
29  // get dispatch context
30  DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
31 
32  // let IrpTarget handle request
33  return DispatchContext->Target->DeviceIoControl(DeviceObject, Irp);
34 }
35 
37 NTAPI
40  PIRP Irp)
41 {
42  PIO_STACK_LOCATION IoStack;
43  PDISPATCH_CONTEXT DispatchContext;
44 
45  // get current irp stack
47 
48  // get dispatch context
49  DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
50 
51 
52  // let IrpTarget handle request
53  return DispatchContext->Target->Read(DeviceObject, Irp);
54 }
55 
57 NTAPI
60  PIRP Irp)
61 {
62  PIO_STACK_LOCATION IoStack;
63  PDISPATCH_CONTEXT DispatchContext;
64 
65  // get current irp stack
67 
68  // get dispatch context
69  DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
70 
71 
72  // let IrpTarget handle request
73  return DispatchContext->Target->Write(DeviceObject, Irp);
74 }
75 
77 NTAPI
80  PIRP Irp)
81 {
82  PIO_STACK_LOCATION IoStack;
83  PDISPATCH_CONTEXT DispatchContext;
84 
85  // get current irp stack
87 
88  // get dispatch context
89  DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
90 
91 
92  // let IrpTarget handle request
93  return DispatchContext->Target->Flush(DeviceObject, Irp);
94 }
95 
97 NTAPI
100  PIRP Irp)
101 {
102  PIO_STACK_LOCATION IoStack;
103  PDISPATCH_CONTEXT DispatchContext;
105 
106  // get current irp stack
108  // get dispatch context
109  DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
110 
111  // let IrpTarget handle request
112  Status = DispatchContext->Target->Close(DeviceObject, Irp);
113 
114  if (NT_SUCCESS(Status))
115  {
116  KsFreeObjectHeader(DispatchContext->ObjectHeader);
117  FreeItem(DispatchContext, TAG_PORTCLASS);
118  }
119  // done
120  return Status;
121 }
122 
123 NTSTATUS
124 NTAPI
127  PIRP Irp)
128 {
129  PIO_STACK_LOCATION IoStack;
130  PDISPATCH_CONTEXT DispatchContext;
131 
132  // get current irp stack
134 
135  // get dispatch context
136  DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
137 
138 
139  // let IrpTarget handle request
140  return DispatchContext->Target->QuerySecurity(DeviceObject, Irp);
141 }
142 
143 NTSTATUS
144 NTAPI
147  PIRP Irp)
148 {
149  PIO_STACK_LOCATION IoStack;
150  PDISPATCH_CONTEXT DispatchContext;
151 
152  // get current irp stack
154 
155  // get dispatch context
156  DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
157 
158  // let IrpTarget handle request
159  return DispatchContext->Target->SetSecurity(DeviceObject, Irp);
160 }
161 
162 BOOLEAN
163 NTAPI
166  BOOLEAN Wait,
174 {
175  PDISPATCH_CONTEXT DispatchContext;
176 
177  // get dispatch context
178  DispatchContext = (PDISPATCH_CONTEXT)FileObject->FsContext;
179 
180  // let IrpTarget handle request
182 }
183 
184 
185 BOOLEAN
186 NTAPI
190  ULONG Length,
191  BOOLEAN Wait,
192  ULONG LockKey,
193  PVOID Buffer,
196 {
197  PDISPATCH_CONTEXT DispatchContext;
198 
199  // get dispatch context
200  DispatchContext = (PDISPATCH_CONTEXT)FileObject->FsContext;
201 
202  // let IrpTarget handle request
203  return DispatchContext->Target->FastRead(FileObject, FileOffset, Length, Wait, LockKey, Buffer, IoStatus, DeviceObject);
204 }
205 
206 BOOLEAN
207 NTAPI
211  ULONG Length,
212  BOOLEAN Wait,
213  ULONG LockKey,
214  PVOID Buffer,
217 {
218  PDISPATCH_CONTEXT DispatchContext;
219 
220  // get dispatch context
221  DispatchContext = (PDISPATCH_CONTEXT)FileObject->FsContext;
222  // let IrpTarget handle request
223  return DispatchContext->Target->FastWrite(FileObject, FileOffset, Length, Wait, LockKey, Buffer, IoStatus, DeviceObject);
224 }
225 
226 static KSDISPATCH_TABLE DispatchTable =
227 {
238 };
239 
240 NTSTATUS
241 NTAPI
243  IN PIRP Irp,
244  IN IIrpTarget * Target,
245  IN ULONG CreateItemCount,
246  IN PKSOBJECT_CREATE_ITEM CreateItem)
247 {
249  KSOBJECT_HEADER ObjectHeader;
250  PIO_STACK_LOCATION IoStack;
251  PDISPATCH_CONTEXT DispatchContext;
252 
253  // get current irp stack location
255 
257  if (!DispatchContext)
259 
260  // allocate object header
261  Status = KsAllocateObjectHeader(&ObjectHeader, CreateItemCount, CreateItem, Irp, &DispatchTable);
262 
263  if (!NT_SUCCESS(Status))
264  {
265  // free dispatch context
266  FreeItem(DispatchContext, TAG_PORTCLASS);
267  // done
268  return Status;
269  }
270 
271  // initialize dispatch context
272  DispatchContext->ObjectHeader = ObjectHeader;
273  DispatchContext->Target = Target;
274  DispatchContext->CreateItem = CreateItem;
275 
276  // store dispatch context
277  IoStack->FileObject->FsContext = DispatchContext;
278 
279  DPRINT("KsAllocateObjectHeader result %x Target %p Context %p\n", Status, Target, DispatchContext);
280  return Status;
281 }
282 
#define IN
Definition: typedefs.h:38
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
_In_ PIRP Irp
Definition: csq.h:116
#define TAG_PORTCLASS
Definition: private.hpp:24
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
static KSDISPATCH_TABLE DispatchTable
Definition: dispatcher.cpp:226
NTSTATUS NTAPI Dispatch_fnRead(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatcher.cpp:38
CHAR InputBuffer[80]
Definition: conmgr.c:33
KSDDKAPI VOID NTAPI KsFreeObjectHeader(IN PVOID Header)
Definition: api.c:720
NTSTATUS NTAPI Dispatch_fnFlush(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatcher.cpp:78
IIrpTarget * Target
Definition: private.hpp:438
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG LockKey
Definition: fatprocs.h:2650
struct DISPATCH_CONTEXT * PDISPATCH_CONTEXT
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI Dispatch_fnDeviceIoControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatcher.cpp:19
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_Must_inspect_result_ typedef _In_ ULONG _In_ BOOLEAN Target
Definition: iotypes.h:1067
* PFILE_OBJECT
Definition: iotypes.h:1954
NTSTATUS NTAPI Dispatch_fnWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatcher.cpp:58
NTSTATUS NTAPI Dispatch_fnClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatcher.cpp:98
NTSTATUS NTAPI Dispatch_fnSetSecurity(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatcher.cpp:145
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
Status
Definition: gdiplustypes.h:24
BOOLEAN NTAPI Dispatch_fnFastDeviceIoControl(PFILE_OBJECT FileObject, BOOLEAN Wait, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength, ULONG IoControlCode, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject)
Definition: dispatcher.cpp:164
BOOLEAN NTAPI Dispatch_fnFastWrite(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, ULONG LockKey, PVOID Buffer, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject)
Definition: dispatcher.cpp:208
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
KSDDKAPI NTSTATUS NTAPI KsAllocateObjectHeader(OUT KSOBJECT_HEADER *Header, IN ULONG ItemsCount, IN PKSOBJECT_CREATE_ITEM ItemsList OPTIONAL, IN PIRP Irp, IN KSDISPATCH_TABLE *Table)
Definition: api.c:610
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN NTAPI Dispatch_fnFastRead(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, ULONG LockKey, PVOID Buffer, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject)
Definition: dispatcher.cpp:187
KSOBJECT_HEADER ObjectHeader
Definition: private.hpp:437
NTSTATUS NTAPI NewDispatchObject(IN PIRP Irp, IN IIrpTarget *Target, IN ULONG CreateItemCount, IN PKSOBJECT_CREATE_ITEM CreateItem)
Definition: dispatcher.cpp:242
PKSOBJECT_CREATE_ITEM CreateItem
Definition: private.hpp:439
NTSTATUS NTAPI Dispatch_fnQuerySecurity(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatcher.cpp:125
IN BOOLEAN Wait
Definition: fatprocs.h:1529