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, 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)
37 IN PIRP_CONTEXT IrpContext
,
38 IN PERESOURCE Resource
,
39 IN BOOLEAN IgnoreWait
,
40 IN TYPE_OF_ACQUIRE Type
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.
55 Resource - This is the resource to try and acquire.
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.
62 Type - Indicates how we should try to get the resource.
66 BOOLEAN - TRUE if the resource is acquired. FALSE if not acquired and
67 IgnoreWait is specified. Otherwise we raise CANT_WAIT.
77 // We look first at the IgnoreWait flag, next at the flag in the Irp
78 // Context to decide how to acquire this resource.
81 if (!IgnoreWait
&& FlagOn( IrpContext
->Flags
, IRP_CONTEXT_FLAG_WAIT
)) {
87 // Attempt to acquire the resource either shared or exclusively.
91 case AcquireExclusive
:
93 Acquired
= ExAcquireResourceExclusiveLite( Resource
, Wait
);
98 Acquired
= ExAcquireResourceSharedLite( Resource
, Wait
);
101 case AcquireSharedStarveExclusive
:
103 Acquired
= ExAcquireSharedStarveExclusive( Resource
, Wait
);
112 // If not acquired and the user didn't specify IgnoreWait then
116 if (!Acquired
&& !IgnoreWait
) {
118 CdRaiseStatus( IrpContext
, STATUS_CANT_WAIT
);
126 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
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.
141 Fcb - The pointer supplied as context to the cache initialization
144 Wait - TRUE if the caller is willing to block.
155 ASSERT(IoGetTopLevelIrp() == NULL
);
156 IoSetTopLevelIrp((PIRP
)FSRTL_CACHE_TOP_LEVEL_IRP
);
158 return ExAcquireResourceSharedLite( Fcb
->Resource
, Wait
);
163 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
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.
178 Fcb - The pointer supplied as context to the cache initialization
190 ASSERT(IoGetTopLevelIrp() == (PIRP
)FSRTL_CACHE_TOP_LEVEL_IRP
);
191 IoSetTopLevelIrp( NULL
);
193 ExReleaseResourceLite( Fcb
->Resource
);
198 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
208 This routine does nothing.
212 Fcb - The Fcb/Vcb which was specified as a context parameter for this
215 Wait - TRUE if the caller is willing to block.
230 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
239 This routine does nothing.
243 Fcb - The Fcb/Vcb which was specified as a context parameter for this
258 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
259 CdAcquireForCreateSection (
260 IN PFILE_OBJECT FileObject
267 This is the callback routine for MM to use to acquire the file exclusively.
271 FileObject - File object for a Cdfs stream.
284 // Get the Fcb resource exclusively.
287 ExAcquireResourceExclusiveLite( &((PFCB
) FileObject
->FsContext
)->FcbNonpaged
->FcbResource
,
291 // Take the File resource shared. We need this later on when MM calls
292 // QueryStandardInfo to get the file size.
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.
300 ExAcquireSharedStarveExclusive( ((PFCB
) FileObject
->FsContext
)->Resource
,
306 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
307 CdReleaseForCreateSection (
308 IN PFILE_OBJECT FileObject
315 This is the callback routine for MM to use to release a file acquired with
316 the AcquireForCreateSection call above.
320 FileObject - File object for a Cdfs stream.
332 // Release the resources.
335 ExReleaseResourceLite( &((PFCB
) FileObject
->FsContext
)->FcbNonpaged
->FcbResource
);
336 ExReleaseResourceLite( ((PFCB
) FileObject
->FsContext
)->Resource
);