[CDFS_NEW] Fix headers inclusion so that it can work on a *nix platform
[reactos.git] / drivers / filesystems / cdfs_new / fspdisp.c
1 /*++
2
3 Copyright (c) 1989-2000 Microsoft Corporation
4
5 Module Name:
6
7 FspDisp.c
8
9 Abstract:
10
11 This module implements the main dispatch procedure/thread for the Cdfs
12 Fsp
13
14
15 --*/
16
17 #include "cdprocs.h"
18
19 //
20 // The Bug check file id for this module
21 //
22
23 #define BugCheckFileId (CDFS_BUG_CHECK_FSPDISP)
24
25 \f
26 VOID
27 CdFspDispatch (
28 IN PIRP_CONTEXT IrpContext
29 )
30
31 /*++
32
33 Routine Description:
34
35 This is the main FSP thread routine that is executed to receive
36 and dispatch IRP requests. Each FSP thread begins its execution here.
37 There is one thread created at system initialization time and subsequent
38 threads created as needed.
39
40 Arguments:
41
42 IrpContext - IrpContext for a request to process.
43
44 Return Value:
45
46 None
47
48 --*/
49
50 {
51 THREAD_CONTEXT ThreadContext;
52 NTSTATUS Status;
53
54 PIRP Irp = IrpContext->Irp;
55 PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( Irp );
56
57 PVOLUME_DEVICE_OBJECT VolDo = NULL;
58
59 //
60 // If this request has an associated volume device object, remember it.
61 //
62
63 if (IrpSp->FileObject != NULL) {
64
65 VolDo = CONTAINING_RECORD( IrpSp->DeviceObject,
66 VOLUME_DEVICE_OBJECT,
67 DeviceObject );
68 }
69
70 //
71 // Now case on the function code. For each major function code,
72 // either call the appropriate worker routine. This routine that
73 // we call is responsible for completing the IRP, and not us.
74 // That way the routine can complete the IRP and then continue
75 // post processing as required. For example, a read can be
76 // satisfied right away and then read can be done.
77 //
78 // We'll do all of the work within an exception handler that
79 // will be invoked if ever some underlying operation gets into
80 // trouble.
81 //
82
83 while ( TRUE ) {
84
85 //
86 // Set all the flags indicating we are in the Fsp.
87 //
88
89 SetFlag( IrpContext->Flags, IRP_CONTEXT_FSP_FLAGS );
90
91 FsRtlEnterFileSystem();
92
93 CdSetThreadContext( IrpContext, &ThreadContext );
94
95 while (TRUE) {
96
97 try {
98
99 //
100 // Reinitialize for the next try at completing this
101 // request.
102 //
103
104 Status =
105 IrpContext->ExceptionStatus = STATUS_SUCCESS;
106
107 //
108 // Initialize the Io status field in the Irp.
109 //
110
111 Irp->IoStatus.Status = STATUS_SUCCESS;
112 Irp->IoStatus.Information = 0;
113
114 //
115 // Case on the major irp code.
116 //
117
118 switch (IrpContext->MajorFunction) {
119
120 case IRP_MJ_CREATE :
121
122 CdCommonCreate( IrpContext, Irp );
123 break;
124
125 case IRP_MJ_CLOSE :
126
127 ASSERT( FALSE );
128 break;
129
130 case IRP_MJ_READ :
131
132 CdCommonRead( IrpContext, Irp );
133 break;
134
135 case IRP_MJ_QUERY_INFORMATION :
136
137 CdCommonQueryInfo( IrpContext, Irp );
138 break;
139
140 case IRP_MJ_SET_INFORMATION :
141
142 CdCommonSetInfo( IrpContext, Irp );
143 break;
144
145 case IRP_MJ_QUERY_VOLUME_INFORMATION :
146
147 CdCommonQueryVolInfo( IrpContext, Irp );
148 break;
149
150 case IRP_MJ_DIRECTORY_CONTROL :
151
152 CdCommonDirControl( IrpContext, Irp );
153 break;
154
155 case IRP_MJ_FILE_SYSTEM_CONTROL :
156
157 CdCommonFsControl( IrpContext, Irp );
158 break;
159
160 case IRP_MJ_DEVICE_CONTROL :
161
162 CdCommonDevControl( IrpContext, Irp );
163 break;
164
165 case IRP_MJ_LOCK_CONTROL :
166
167 CdCommonLockControl( IrpContext, Irp );
168 break;
169
170 case IRP_MJ_CLEANUP :
171
172 CdCommonCleanup( IrpContext, Irp );
173 break;
174
175 case IRP_MJ_PNP :
176
177 ASSERT( FALSE );
178 CdCommonPnp( IrpContext, Irp );
179 break;
180
181 default :
182
183 Status = STATUS_INVALID_DEVICE_REQUEST;
184 CdCompleteRequest( IrpContext, Irp, Status );
185 }
186
187 } except( CdExceptionFilter( IrpContext, GetExceptionInformation() )) {
188
189 Status = CdProcessException( IrpContext, Irp, GetExceptionCode() );
190 }
191
192 //
193 // Break out of the loop if we didn't get CANT_WAIT.
194 //
195
196 if (Status != STATUS_CANT_WAIT) { break; }
197
198 //
199 // We are retrying this request. Cleanup the IrpContext for the retry.
200 //
201
202 SetFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_MORE_PROCESSING );
203 CdCleanupIrpContext( IrpContext, FALSE );
204 }
205
206 FsRtlExitFileSystem();
207
208 //
209 // If there are any entries on this volume's overflow queue, service
210 // them.
211 //
212
213 if (VolDo != NULL) {
214
215 KIRQL SavedIrql;
216 PVOID Entry = NULL;
217
218 //
219 // We have a volume device object so see if there is any work
220 // left to do in its overflow queue.
221 //
222
223 KeAcquireSpinLock( &VolDo->OverflowQueueSpinLock, &SavedIrql );
224
225 if (VolDo->OverflowQueueCount > 0) {
226
227 //
228 // There is overflow work to do in this volume so we'll
229 // decrement the Overflow count, dequeue the IRP, and release
230 // the Event
231 //
232
233 VolDo->OverflowQueueCount -= 1;
234
235 Entry = RemoveHeadList( &VolDo->OverflowQueue );
236 }
237
238 KeReleaseSpinLock( &VolDo->OverflowQueueSpinLock, SavedIrql );
239
240 //
241 // There wasn't an entry, break out of the loop and return to
242 // the Ex Worker thread.
243 //
244
245 if (Entry == NULL) { break; }
246
247 //
248 // Extract the IrpContext , Irp, set wait to TRUE, and loop.
249 //
250
251 IrpContext = CONTAINING_RECORD( Entry,
252 IRP_CONTEXT,
253 WorkQueueItem.List );
254
255 Irp = IrpContext->Irp;
256 IrpSp = IoGetCurrentIrpStackLocation( Irp );
257
258 continue;
259 }
260
261 break;
262 }
263
264 //
265 // Decrement the PostedRequestCount if there was a volume device object.
266 //
267
268 if (VolDo) {
269
270 InterlockedDecrement( &VolDo->PostedRequestCount );
271 }
272
273 return;
274 }
275
276
277
278