Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

resrcsup.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1996 Microsoft Corporation 00004 00005 Module Name: 00006 00007 ResrcSup.c 00008 00009 Abstract: 00010 00011 This module implements the Udfs Resource acquisition routines 00012 00013 Author: 00014 00015 Dan Lovinger [DanLo] 10-Jul-1996 00016 00017 Revision History: 00018 00019 --*/ 00020 00021 #include "UdfProcs.h" 00022 00023 // 00024 // The Bug check file id for this module 00025 // 00026 00027 #define BugCheckFileId (UDFS_BUG_CHECK_RESRCSUP) 00028 00029 // 00030 // The local debug trace level 00031 // 00032 00033 #define Dbg (UDFS_DEBUG_LEVEL_RESRCSUP) 00034 00035 #ifdef ALLOC_PRAGMA 00036 #pragma alloc_text(PAGE, UdfAcquireForCache) 00037 #pragma alloc_text(PAGE, UdfAcquireForCreateSection) 00038 #pragma alloc_text(PAGE, UdfAcquireResource) 00039 #pragma alloc_text(PAGE, UdfNoopAcquire) 00040 #pragma alloc_text(PAGE, UdfNoopRelease) 00041 #pragma alloc_text(PAGE, UdfReleaseForCreateSection) 00042 #pragma alloc_text(PAGE, UdfReleaseFromCache) 00043 #endif 00044 00045 00046 BOOLEAN 00047 UdfAcquireResource ( 00048 IN PIRP_CONTEXT IrpContext, 00049 IN PERESOURCE Resource, 00050 IN BOOLEAN IgnoreWait, 00051 IN TYPE_OF_ACQUIRE Type 00052 ) 00053 00054 /*++ 00055 00056 Routine Description: 00057 00058 This is the single routine used to acquire file system resources. It 00059 looks at the IgnoreWait flag to determine whether to try to acquire the 00060 resource without waiting. Returning TRUE/FALSE to indicate success or 00061 failure. Otherwise it is driven by the WAIT flag in the IrpContext and 00062 will raise CANT_WAIT on a failure. 00063 00064 Arguments: 00065 00066 Resource - This is the resource to try and acquire. 00067 00068 IgnoreWait - If TRUE then this routine will not wait to acquire the 00069 resource and will return a boolean indicating whether the resource was 00070 acquired. Otherwise we use the flag in the IrpContext and raise 00071 if the resource is not acquired. 00072 00073 Type - Indicates how we should try to get the resource. 00074 00075 Return Value: 00076 00077 BOOLEAN - TRUE if the resource is acquired. FALSE if not acquired and 00078 IgnoreWait is specified. Otherwise we raise CANT_WAIT. 00079 00080 --*/ 00081 00082 { 00083 BOOLEAN Wait = FALSE; 00084 BOOLEAN Acquired; 00085 PAGED_CODE(); 00086 00087 // 00088 // We look first at the IgnoreWait flag, next at the flag in the Irp 00089 // Context to decide how to acquire this resource. 00090 // 00091 00092 if (!IgnoreWait && FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT )) { 00093 00094 Wait = TRUE; 00095 } 00096 00097 // 00098 // Attempt to acquire the resource either shared or exclusively. 00099 // 00100 00101 switch (Type) { 00102 case AcquireExclusive: 00103 00104 Acquired = ExAcquireResourceExclusive( Resource, Wait ); 00105 break; 00106 00107 case AcquireShared: 00108 00109 Acquired = ExAcquireResourceShared( Resource, Wait ); 00110 break; 00111 00112 case AcquireSharedStarveExclusive: 00113 00114 Acquired = ExAcquireSharedStarveExclusive( Resource, Wait ); 00115 break; 00116 00117 default: 00118 ASSERT( FALSE ); 00119 } 00120 00121 // 00122 // If not acquired and the user didn't specifiy IgnoreWait then 00123 // raise CANT_WAIT. 00124 // 00125 00126 if (!Acquired && !IgnoreWait) { 00127 00128 UdfRaiseStatus( IrpContext, STATUS_CANT_WAIT ); 00129 } 00130 00131 return Acquired; 00132 } 00133 00134 00135 BOOLEAN 00136 UdfAcquireForCache ( 00137 IN PFCB Fcb, 00138 IN BOOLEAN Wait 00139 ) 00140 00141 /*++ 00142 00143 Routine Description: 00144 00145 The address of this routine is specified when creating a CacheMap for 00146 a file. It is subsequently called by the Lazy Writer for synchronization. 00147 00148 Arguments: 00149 00150 Fcb - The pointer supplied as context to the cache initialization 00151 routine. 00152 00153 Wait - TRUE if the caller is willing to block. 00154 00155 Return Value: 00156 00157 None 00158 00159 --*/ 00160 00161 { 00162 PAGED_CODE(); 00163 00164 ASSERT(IoGetTopLevelIrp() == NULL); 00165 IoSetTopLevelIrp((PIRP)FSRTL_CACHE_TOP_LEVEL_IRP); 00166 00167 return ExAcquireResourceShared( Fcb->Resource, Wait ); 00168 } 00169 00170 00171 VOID 00172 UdfReleaseFromCache ( 00173 IN PFCB Fcb 00174 ) 00175 00176 /*++ 00177 00178 Routine Description: 00179 00180 The address of this routine is specified when creating a CacheMap for 00181 a virtual file. It is subsequently called by the Lazy Writer to release 00182 a resource acquired above. 00183 00184 Arguments: 00185 00186 Fcb - The pointer supplied as context to the cache initialization 00187 routine. 00188 00189 Return Value: 00190 00191 None 00192 00193 --*/ 00194 00195 { 00196 PAGED_CODE(); 00197 00198 ASSERT(IoGetTopLevelIrp() == (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP); 00199 IoSetTopLevelIrp( NULL ); 00200 00201 ExReleaseResource( Fcb->Resource ); 00202 00203 return; 00204 } 00205 00206 00207 BOOLEAN 00208 UdfNoopAcquire ( 00209 IN PVOID Fcb, 00210 IN BOOLEAN Wait 00211 ) 00212 00213 /*++ 00214 00215 Routine Description: 00216 00217 This routine does nothing. 00218 00219 Arguments: 00220 00221 Fcb - The Fcb/Vcb which was specified as a context parameter for this 00222 routine. 00223 00224 Wait - TRUE if the caller is willing to block. 00225 00226 Return Value: 00227 00228 TRUE 00229 00230 --*/ 00231 00232 { 00233 PAGED_CODE(); 00234 return TRUE; 00235 } 00236 00237 00238 VOID 00239 UdfNoopRelease ( 00240 IN PVOID Fcb 00241 ) 00242 00243 /*++ 00244 00245 Routine Description: 00246 00247 This routine does nothing. 00248 00249 Arguments: 00250 00251 Fcb - The Fcb/Vcb which was specified as a context parameter for this 00252 routine. 00253 00254 Return Value: 00255 00256 None 00257 00258 --*/ 00259 00260 { 00261 PAGED_CODE(); 00262 return; 00263 } 00264 00265 00266 VOID 00267 UdfAcquireForCreateSection ( 00268 IN PFILE_OBJECT FileObject 00269 ) 00270 00271 /*++ 00272 00273 Routine Description: 00274 00275 This is the callback routine for MM to use to acquire the file exclusively. 00276 00277 Arguments: 00278 00279 FileObject - File object for a Udffs stream. 00280 00281 Return Value: 00282 00283 None 00284 00285 --*/ 00286 00287 { 00288 PAGED_CODE(); 00289 00290 // 00291 // Get the file resource exclusively. 00292 // 00293 00294 ExAcquireResourceExclusive( &((PFCB) FileObject->FsContext)->FcbNonpaged->FcbResource, 00295 TRUE ); 00296 00297 return; 00298 } 00299 00300 00301 VOID 00302 UdfReleaseForCreateSection ( 00303 IN PFILE_OBJECT FileObject 00304 ) 00305 00306 /*++ 00307 00308 Routine Description: 00309 00310 This is the callback routine for MM to use to release a file acquired with 00311 the AcquireForCreateSection call above. 00312 00313 Arguments: 00314 00315 FileObject - File object for a Udffs stream. 00316 00317 Return Value: 00318 00319 None 00320 00321 --*/ 00322 00323 { 00324 PAGED_CODE(); 00325 00326 // 00327 // Release the resource in the Fcb. 00328 // 00329 00330 ExReleaseResource( &((PFCB) FileObject->FsContext)->FcbNonpaged->FcbResource ); 00331 00332 return; 00333 }

Generated on Sat May 15 19:41:39 2004 for test by doxygen 1.3.7