3 Copyright (c) 1989-2000 Microsoft Corporation
11 This module implements the Cdfs Resource acquisition routines
19 // The Bug check file id for this module
22 #define BugCheckFileId (CDFS_BUG_CHECK_RESRCSUP)
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)
36 _Requires_lock_held_(_Global_critical_region_
)
37 _When_(Type
== AcquireExclusive
&& return != FALSE
, _Acquires_exclusive_lock_(*Resource
))
38 _When_(Type
== AcquireShared
&& return != FALSE
, _Acquires_shared_lock_(*Resource
))
39 _When_(Type
== AcquireSharedStarveExclusive
&& return != FALSE
, _Acquires_shared_lock_(*Resource
))
40 _When_(IgnoreWait
== FALSE
, _Post_satisfies_(return == TRUE
))
43 _In_ PIRP_CONTEXT IrpContext
,
44 _Inout_ PERESOURCE Resource
,
45 _In_ BOOLEAN IgnoreWait
,
46 _In_ TYPE_OF_ACQUIRE Type
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.
61 Resource - This is the resource to try and acquire.
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.
68 Type - Indicates how we should try to get the resource.
72 BOOLEAN - TRUE if the resource is acquired. FALSE if not acquired and
73 IgnoreWait is specified. Otherwise we raise CANT_WAIT.
83 // We look first at the IgnoreWait flag, next at the flag in the Irp
84 // Context to decide how to acquire this resource.
87 if (!IgnoreWait
&& FlagOn( IrpContext
->Flags
, IRP_CONTEXT_FLAG_WAIT
)) {
93 // Attempt to acquire the resource either shared or exclusively.
97 case AcquireExclusive
:
100 #pragma prefast( suppress:28137, "prefast believes Wait should be a constant, but this is ok for CDFS" )
102 Acquired
= ExAcquireResourceExclusiveLite( Resource
, Wait
);
107 Acquired
= ExAcquireResourceSharedLite( Resource
, Wait
);
110 case AcquireSharedStarveExclusive
:
112 Acquired
= ExAcquireSharedStarveExclusive( Resource
, Wait
);
121 // If not acquired and the user didn't specifiy IgnoreWait then
125 if (!Acquired
&& !IgnoreWait
) {
127 CdRaiseStatus( IrpContext
, STATUS_CANT_WAIT
);
135 _Requires_lock_held_(_Global_critical_region_
)
136 _When_(return!=0, _Acquires_shared_lock_(*Fcb
->Resource
))
138 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
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.
153 Fcb - The pointer supplied as context to the cache initialization
156 Wait - TRUE if the caller is willing to block.
167 NT_ASSERT(IoGetTopLevelIrp() == NULL
);
168 IoSetTopLevelIrp((PIRP
)FSRTL_CACHE_TOP_LEVEL_IRP
);
170 return ExAcquireResourceSharedLite( Fcb
->Resource
, Wait
);
174 _Requires_lock_held_(_Global_critical_region_
)
175 _Releases_lock_(*Fcb
->Resource
)
177 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
186 The address of this routine is specified when creating a CacheMap for
187 a virtual file. It is subsequently called by the Lazy Writer to release
188 a resource acquired above.
192 Fcb - The pointer supplied as context to the cache initialization
204 NT_ASSERT(IoGetTopLevelIrp() == (PIRP
)FSRTL_CACHE_TOP_LEVEL_IRP
);
205 IoSetTopLevelIrp( NULL
);
207 ExReleaseResourceLite( Fcb
->Resource
);
212 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
222 This routine does nothing.
226 Fcb - The Fcb/Vcb which was specified as a context parameter for this
229 Wait - TRUE if the caller is willing to block.
240 UNREFERENCED_PARAMETER( Fcb
);
241 UNREFERENCED_PARAMETER( Wait
);
248 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
257 This routine does nothing.
261 Fcb - The Fcb/Vcb which was specified as a context parameter for this
273 UNREFERENCED_PARAMETER( Fcb
);
277 _Requires_lock_held_(_Global_critical_region_
)
279 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
280 CdFilterCallbackAcquireForCreateSection (
281 _In_ PFS_FILTER_CALLBACK_DATA CallbackData
,
282 _Unreferenced_parameter_ PVOID
*CompletionContext
289 This is the callback routine for MM to use to acquire the file exclusively.
293 FS_FILTER_CALLBACK_DATA - Filter based callback data that provides the file object we
296 CompletionContext - Ignored.
300 On success we return STATUS_FSFILTER_OP_COMPLETED_SUCCESSFULLY.
302 If SyncType is SyncTypeCreateSection, we return a status that indicates there are no
303 writers to this file.
308 PFILE_OBJECT FileObject
;
313 NT_ASSERT( CallbackData
->Operation
== FS_FILTER_ACQUIRE_FOR_SECTION_SYNCHRONIZATION
);
314 NT_ASSERT( CallbackData
->SizeOfFsFilterCallbackData
== sizeof(FS_FILTER_CALLBACK_DATA
) );
317 // Get the file object from the callback data.
320 FileObject
= CallbackData
->FileObject
;
323 // Get the Fcb resource exclusively.
326 ExAcquireResourceExclusiveLite( &((PFCB
) FileObject
->FsContext
)->FcbNonpaged
->FcbResource
,
330 // Take the File resource shared. We need this later on when MM calls
331 // QueryStandardInfo to get the file size.
333 // If we don't use StarveExclusive, then we can get wedged behind an
334 // exclusive waiter who is waiting on someone else holding it shared in the
335 // read->initializecachemap path (which calls createsection) who is in turn
336 // waiting on us to finish the create section.
339 ExAcquireSharedStarveExclusive( ((PFCB
) FileObject
->FsContext
)->Resource
,
343 // CDFS is a read-only file system, so we can always indicate no writers.
344 // We only do this for create section synchronization. For others we
345 // return the generic success STATUS_FSFILTER_OP_COMPLETED_SUCCESSFULLY.
348 if (CallbackData
->Parameters
.AcquireForSectionSynchronization
.SyncType
== SyncTypeCreateSection
) {
350 return STATUS_FILE_LOCKED_WITH_ONLY_READERS
;
354 return STATUS_FSFILTER_OP_COMPLETED_SUCCESSFULLY
;
357 UNREFERENCED_PARAMETER( CompletionContext
);
361 _Function_class_(FAST_IO_RELEASE_FILE
)
362 _Requires_lock_held_(_Global_critical_region_
)
364 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
365 CdReleaseForCreateSection (
366 _In_ PFILE_OBJECT FileObject
373 This is the callback routine for MM to use to release a file acquired with
374 the AcquireForCreateSection call above.
378 FileObject - File object for a Cdfs stream.
390 // Release the resources.
393 ExReleaseResourceLite( &((PFCB
) FileObject
->FsContext
)->FcbNonpaged
->FcbResource
);
394 ExReleaseResourceLite( ((PFCB
) FileObject
->FsContext
)->Resource
);