[CDFS_NEW] Remove a no longer required build hack
[reactos.git] / drivers / filesystems / cdfs_new / resrcsup.c
1 /*++
2
3 Copyright (c) 1989-2000 Microsoft Corporation
4
5 Module Name:
6
7 ResrcSup.c
8
9 Abstract:
10
11 This module implements the Cdfs Resource acquisition routines
12
13
14 --*/
15
16 #include "cdprocs.h"
17
18 //
19 // The Bug check file id for this module
20 //
21
22 #define BugCheckFileId (CDFS_BUG_CHECK_RESRCSUP)
23
24 #ifdef ALLOC_PRAGMA
25 #pragma alloc_text(PAGE, CdAcquireForCache)
26 #pragma alloc_text(PAGE, CdAcquireForCreateSection)
27 #pragma alloc_text(PAGE, CdAcquireResource)
28 #pragma alloc_text(PAGE, CdNoopAcquire)
29 #pragma alloc_text(PAGE, CdNoopRelease)
30 #pragma alloc_text(PAGE, CdReleaseForCreateSection)
31 #pragma alloc_text(PAGE, CdReleaseFromCache)
32 #endif
33
34 \f
35 BOOLEAN
36 CdAcquireResource (
37 IN PIRP_CONTEXT IrpContext,
38 IN PERESOURCE Resource,
39 IN BOOLEAN IgnoreWait,
40 IN TYPE_OF_ACQUIRE Type
41 )
42
43 /*++
44
45 Routine Description:
46
47 This is the single routine used to acquire file system resources. It
48 looks at the IgnoreWait flag to determine whether to try to acquire the
49 resource without waiting. Returning TRUE/FALSE to indicate success or
50 failure. Otherwise it is driven by the WAIT flag in the IrpContext and
51 will raise CANT_WAIT on a failure.
52
53 Arguments:
54
55 Resource - This is the resource to try and acquire.
56
57 IgnoreWait - If TRUE then this routine will not wait to acquire the
58 resource and will return a boolean indicating whether the resource was
59 acquired. Otherwise we use the flag in the IrpContext and raise
60 if the resource is not acquired.
61
62 Type - Indicates how we should try to get the resource.
63
64 Return Value:
65
66 BOOLEAN - TRUE if the resource is acquired. FALSE if not acquired and
67 IgnoreWait is specified. Otherwise we raise CANT_WAIT.
68
69 --*/
70
71 {
72 BOOLEAN Wait = FALSE;
73 BOOLEAN Acquired;
74 PAGED_CODE();
75
76 //
77 // We look first at the IgnoreWait flag, next at the flag in the Irp
78 // Context to decide how to acquire this resource.
79 //
80
81 if (!IgnoreWait && FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT )) {
82
83 Wait = TRUE;
84 }
85
86 //
87 // Attempt to acquire the resource either shared or exclusively.
88 //
89
90 switch (Type) {
91 case AcquireExclusive:
92
93 Acquired = ExAcquireResourceExclusiveLite( Resource, Wait );
94 break;
95
96 case AcquireShared:
97
98 Acquired = ExAcquireResourceSharedLite( Resource, Wait );
99 break;
100
101 case AcquireSharedStarveExclusive:
102
103 Acquired = ExAcquireSharedStarveExclusive( Resource, Wait );
104 break;
105
106 default:
107 Acquired = FALSE;
108 ASSERT( FALSE );
109 }
110
111 //
112 // If not acquired and the user didn't specify IgnoreWait then
113 // raise CANT_WAIT.
114 //
115
116 if (!Acquired && !IgnoreWait) {
117
118 CdRaiseStatus( IrpContext, STATUS_CANT_WAIT );
119 }
120
121 return Acquired;
122 }
123
124 \f
125 BOOLEAN
126 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
127 CdAcquireForCache (
128 IN PFCB Fcb,
129 IN BOOLEAN Wait
130 )
131
132 /*++
133
134 Routine Description:
135
136 The address of this routine is specified when creating a CacheMap for
137 a file. It is subsequently called by the Lazy Writer for synchronization.
138
139 Arguments:
140
141 Fcb - The pointer supplied as context to the cache initialization
142 routine.
143
144 Wait - TRUE if the caller is willing to block.
145
146 Return Value:
147
148 None
149
150 --*/
151
152 {
153 PAGED_CODE();
154
155 ASSERT(IoGetTopLevelIrp() == NULL);
156 IoSetTopLevelIrp((PIRP)FSRTL_CACHE_TOP_LEVEL_IRP);
157
158 return ExAcquireResourceSharedLite( Fcb->Resource, Wait );
159 }
160
161 \f
162 VOID
163 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
164 CdReleaseFromCache (
165 IN PFCB Fcb
166 )
167
168 /*++
169
170 Routine Description:
171
172 The address of this routine is specified when creating a CacheMap for
173 a virtual file. It is subsequently called by the Lazy Writer to release
174 a resource acquired above.
175
176 Arguments:
177
178 Fcb - The pointer supplied as context to the cache initialization
179 routine.
180
181 Return Value:
182
183 None
184
185 --*/
186
187 {
188 PAGED_CODE();
189
190 ASSERT(IoGetTopLevelIrp() == (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP);
191 IoSetTopLevelIrp( NULL );
192
193 ExReleaseResourceLite( Fcb->Resource );
194 }
195
196 \f
197 BOOLEAN
198 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
199 CdNoopAcquire (
200 IN PVOID Fcb,
201 IN BOOLEAN Wait
202 )
203
204 /*++
205
206 Routine Description:
207
208 This routine does nothing.
209
210 Arguments:
211
212 Fcb - The Fcb/Vcb which was specified as a context parameter for this
213 routine.
214
215 Wait - TRUE if the caller is willing to block.
216
217 Return Value:
218
219 TRUE
220
221 --*/
222
223 {
224 PAGED_CODE();
225 return TRUE;
226 }
227
228 \f
229 VOID
230 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
231 CdNoopRelease (
232 IN PVOID Fcb
233 )
234
235 /*++
236
237 Routine Description:
238
239 This routine does nothing.
240
241 Arguments:
242
243 Fcb - The Fcb/Vcb which was specified as a context parameter for this
244 routine.
245
246 Return Value:
247
248 None
249
250 --*/
251
252 {
253 PAGED_CODE();
254 }
255
256 \f
257 VOID
258 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
259 CdAcquireForCreateSection (
260 IN PFILE_OBJECT FileObject
261 )
262
263 /*++
264
265 Routine Description:
266
267 This is the callback routine for MM to use to acquire the file exclusively.
268
269 Arguments:
270
271 FileObject - File object for a Cdfs stream.
272
273 Return Value:
274
275 None
276
277 --*/
278
279 {
280 PAGED_CODE();
281
282
283 //
284 // Get the Fcb resource exclusively.
285 //
286
287 ExAcquireResourceExclusiveLite( &((PFCB) FileObject->FsContext)->FcbNonpaged->FcbResource,
288 TRUE );
289
290 //
291 // Take the File resource shared. We need this later on when MM calls
292 // QueryStandardInfo to get the file size.
293 //
294 // If we don't use StarveExclusive, then we can get wedged behind an
295 // exclusive waiter who is waiting on someone else holding it shared in the
296 // read->initializecachemap path (which calls createsection) who is in turn
297 // waiting on us to finish the create section.
298 //
299
300 ExAcquireSharedStarveExclusive( ((PFCB) FileObject->FsContext)->Resource,
301 TRUE );
302 }
303
304 \f
305 VOID
306 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
307 CdReleaseForCreateSection (
308 IN PFILE_OBJECT FileObject
309 )
310
311 /*++
312
313 Routine Description:
314
315 This is the callback routine for MM to use to release a file acquired with
316 the AcquireForCreateSection call above.
317
318 Arguments:
319
320 FileObject - File object for a Cdfs stream.
321
322 Return Value:
323
324 None
325
326 --*/
327
328 {
329 PAGED_CODE();
330
331 //
332 // Release the resources.
333 //
334
335 ExReleaseResourceLite( &((PFCB) FileObject->FsContext)->FcbNonpaged->FcbResource );
336 ExReleaseResourceLite( ((PFCB) FileObject->FsContext)->Resource);
337 }
338