ReactOS 0.4.15-dev-7704-gc07eb9f
resrcsup.c
Go to the documentation of this file.
1/*++
2
3Copyright (c) 1989-2000 Microsoft Corporation
4
5Module Name:
6
7 ResrcSup.c
8
9Abstract:
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, CdFilterCallbackAcquireForCreateSection)
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
35
36_Requires_lock_held_(_Global_critical_region_)
42CdAcquireResource (
43 _In_ PIRP_CONTEXT IrpContext,
47 )
48
49/*++
50
51Routine Description:
52
53 This is the single routine used to acquire file system resources. It
54 looks at the IgnoreWait flag to determine whether to try to acquire the
55 resource without waiting. Returning TRUE/FALSE to indicate success or
56 failure. Otherwise it is driven by the WAIT flag in the IrpContext and
57 will raise CANT_WAIT on a failure.
58
59Arguments:
60
61 Resource - This is the resource to try and acquire.
62
63 IgnoreWait - If TRUE then this routine will not wait to acquire the
64 resource and will return a boolean indicating whether the resource was
65 acquired. Otherwise we use the flag in the IrpContext and raise
66 if the resource is not acquired.
67
68 Type - Indicates how we should try to get the resource.
69
70Return Value:
71
72 BOOLEAN - TRUE if the resource is acquired. FALSE if not acquired and
73 IgnoreWait is specified. Otherwise we raise CANT_WAIT.
74
75--*/
76
77{
79 BOOLEAN Acquired;
80 PAGED_CODE();
81
82 //
83 // We look first at the IgnoreWait flag, next at the flag in the Irp
84 // Context to decide how to acquire this resource.
85 //
86
87 if (!IgnoreWait && FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT )) {
88
89 Wait = TRUE;
90 }
91
92 //
93 // Attempt to acquire the resource either shared or exclusively.
94 //
95
96 switch (Type) {
98
99#ifdef _MSC_VER
100#pragma prefast( suppress:28137, "prefast believes Wait should be a constant, but this is ok for CDFS" )
101#endif
103 break;
104
105 case AcquireShared:
106
108 break;
109
111
113 break;
114
115 default:
116 Acquired = FALSE;
117 NT_ASSERT( FALSE );
118 }
119
120 //
121 // If not acquired and the user didn't specifiy IgnoreWait then
122 // raise CANT_WAIT.
123 //
124
125 if (!Acquired && !IgnoreWait) {
126
127 CdRaiseStatus( IrpContext, STATUS_CANT_WAIT );
128 }
129
130 return Acquired;
131}
132
133
134
135_Requires_lock_held_(_Global_critical_region_)
136_When_(return!=0, _Acquires_shared_lock_(*Fcb->Resource))
138NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
142 )
143
144/*++
145
146Routine Description:
147
148 The address of this routine is specified when creating a CacheMap for
149 a file. It is subsequently called by the Lazy Writer for synchronization.
150
151Arguments:
152
153 Fcb - The pointer supplied as context to the cache initialization
154 routine.
155
156 Wait - TRUE if the caller is willing to block.
157
158Return Value:
159
160 None
161
162--*/
163
164{
165 PAGED_CODE();
166
167 if (!ExAcquireResourceSharedLite( Fcb->Resource, Wait )) {
168
169 return FALSE;
170 }
171
174
175 return TRUE;
176}
177
178
179_Requires_lock_held_(_Global_critical_region_)
180_Releases_lock_(*Fcb->Resource)
181VOID
182NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
183CdReleaseFromCache (
185 )
186
187/*++
188
189Routine Description:
190
191 The address of this routine is specified when creating a CacheMap for
192 a virtual file. It is subsequently called by the Lazy Writer to release
193 a resource acquired above.
194
195Arguments:
196
197 Fcb - The pointer supplied as context to the cache initialization
198 routine.
199
200Return Value:
201
202 None
203
204--*/
205
206{
207 PAGED_CODE();
208
211
212 ExReleaseResourceLite( Fcb->Resource );
213}
214
215
217NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
219 _In_ PVOID Fcb,
221 )
222
223/*++
224
225Routine Description:
226
227 This routine does nothing.
228
229Arguments:
230
231 Fcb - The Fcb/Vcb which was specified as a context parameter for this
232 routine.
233
234 Wait - TRUE if the caller is willing to block.
235
236Return Value:
237
238 TRUE
239
240--*/
241
242{
243 PAGED_CODE();
244
247
248 return TRUE;
249}
250
251
252VOID
253NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
256 )
257
258/*++
259
260Routine Description:
261
262 This routine does nothing.
263
264Arguments:
265
266 Fcb - The Fcb/Vcb which was specified as a context parameter for this
267 routine.
268
269Return Value:
270
271 None
272
273--*/
274
275{
276 PAGED_CODE();
277
279}
280
281
282_Requires_lock_held_(_Global_critical_region_)
284NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
285CdFilterCallbackAcquireForCreateSection (
288 )
289
290/*++
291
292Routine Description:
293
294 This is the callback routine for MM to use to acquire the file exclusively.
295
296Arguments:
297
298 FS_FILTER_CALLBACK_DATA - Filter based callback data that provides the file object we
299 want to acquire.
300
301 CompletionContext - Ignored.
302
303Return Value:
304
305 On success we return STATUS_FSFILTER_OP_COMPLETED_SUCCESSFULLY.
306
307 If SyncType is SyncTypeCreateSection, we return a status that indicates there are no
308 writers to this file.
309
310--*/
311
312{
314
315
316 PAGED_CODE();
317
319 NT_ASSERT( CallbackData->SizeOfFsFilterCallbackData == sizeof(FS_FILTER_CALLBACK_DATA) );
320
321 //
322 // Get the file object from the callback data.
323 //
324
325 FileObject = CallbackData->FileObject;
326
327 //
328 // Get the Fcb resource exclusively.
329 //
330
331 ExAcquireResourceExclusiveLite( &((PFCB) FileObject->FsContext)->FcbNonpaged->FcbResource,
332 TRUE );
333
334 //
335 // Take the File resource shared. We need this later on when MM calls
336 // QueryStandardInfo to get the file size.
337 //
338 // If we don't use StarveExclusive, then we can get wedged behind an
339 // exclusive waiter who is waiting on someone else holding it shared in the
340 // read->initializecachemap path (which calls createsection) who is in turn
341 // waiting on us to finish the create section.
342 //
343
344 ExAcquireSharedStarveExclusive( ((PFCB) FileObject->FsContext)->Resource,
345 TRUE );
346
347 //
348 // CDFS is a read-only file system, so we can always indicate no writers.
349 // We only do this for create section synchronization. For others we
350 // return the generic success STATUS_FSFILTER_OP_COMPLETED_SUCCESSFULLY.
351 //
352
353 if (CallbackData->Parameters.AcquireForSectionSynchronization.SyncType == SyncTypeCreateSection) {
354
356
357 } else {
358
360 }
361
363}
364
365
366_Function_class_(FAST_IO_RELEASE_FILE)
367_Requires_lock_held_(_Global_critical_region_)
368VOID
369NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
370CdReleaseForCreateSection (
372 )
373
374/*++
375
376Routine Description:
377
378 This is the callback routine for MM to use to release a file acquired with
379 the AcquireForCreateSection call above.
380
381Arguments:
382
383 FileObject - File object for a Cdfs stream.
384
385Return Value:
386
387 None
388
389--*/
390
391{
392 PAGED_CODE();
393
394 //
395 // Release the resources.
396 //
397
398 ExReleaseResourceLite( &((PFCB) FileObject->FsContext)->FcbNonpaged->FcbResource );
399 ExReleaseResourceLite( ((PFCB) FileObject->FsContext)->Resource);
400}
401
#define PAGED_CODE()
unsigned char BOOLEAN
Type
Definition: Type.h:7
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI CdNoopRelease(_In_ PVOID Fcb)
Definition: resrcsup.c:254
BOOLEAN NTAPI CdNoopAcquire(_In_ PVOID Fcb, _In_ BOOLEAN Wait)
Definition: resrcsup.c:218
enum _TYPE_OF_ACQUIRE TYPE_OF_ACQUIRE
@ AcquireShared
Definition: cdprocs.h:830
@ AcquireExclusive
Definition: cdprocs.h:829
@ AcquireSharedStarveExclusive
Definition: cdprocs.h:831
_In_ PFCB Fcb
Definition: cdprocs.h:159
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE _In_ BOOLEAN IgnoreWait
Definition: cdprocs.h:844
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
Definition: cdprocs.h:843
#define CdRaiseStatus(IC, S)
Definition: cdprocs.h:1859
_Acquires_shared_lock_ Fcb BOOLEAN NTAPI CdAcquireForCache(_Inout_ PFCB Fcb, _In_ BOOLEAN Wait)
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1215
#define _Requires_lock_held_(lock)
#define _Acquires_exclusive_lock_(lock)
#define _Acquires_shared_lock_(lock)
#define _Releases_lock_(lock)
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
ERESOURCE * PERESOURCE
Definition: env_spec_w32.h:595
#define ExAcquireResourceSharedLite(res, wait)
Definition: env_spec_w32.h:621
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define FSRTL_CACHE_TOP_LEVEL_IRP
Definition: fsrtltypes.h:60
#define _Function_class_(x)
Definition: ms_sal.h:2946
#define _Inout_
Definition: ms_sal.h:378
#define _When_(expr, annos)
Definition: ms_sal.h:254
#define _In_
Definition: ms_sal.h:308
#define _Post_satisfies_(cond)
Definition: ms_sal.h:588
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
BOOLEAN NTAPI ExAcquireSharedStarveExclusive(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:1068
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1822
PIRP NTAPI IoGetTopLevelIrp(VOID)
Definition: irp.c:1843
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define STATUS_FILE_LOCKED_WITH_ONLY_READERS
Definition: ntstatus.h:111
#define STATUS_CANT_WAIT
Definition: ntstatus.h:452
#define STATUS_FSFILTER_OP_COMPLETED_SUCCESSFULLY
Definition: ntstatus.h:110
#define _Unreferenced_parameter_
Definition: specstrings.h:396
Definition: cdstruc.h:902
#define NTAPI
Definition: typedefs.h:36
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:170
_In_ WDFREQUEST _In_opt_ PFN_WDF_REQUEST_COMPLETION_ROUTINE _In_opt_ __drv_aliasesMem WDFCONTEXT CompletionContext
Definition: wdfrequest.h:898
@ SyncTypeCreateSection
Definition: iotypes.h:7365
* PFILE_OBJECT
Definition: iotypes.h:1998
#define FS_FILTER_ACQUIRE_FOR_SECTION_SYNCHRONIZATION
Definition: iotypes.h:7398
#define NT_ASSERT
Definition: rtlfuncs.h:3310