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

cache.h

Go to the documentation of this file.
00001 /*++ BUILD Version: 0003 // Increment this if a change has global effects 00002 00003 Copyright (c) 1989 Microsoft Corporation 00004 00005 Module Name: 00006 00007 Cache.h 00008 00009 Abstract: 00010 00011 This module contains the public data structures and procedure 00012 prototypes for the cache management system. 00013 00014 Author: 00015 00016 00017 Revision History: 00018 00019 --*/ 00020 00021 #ifndef _CACHE_ 00022 #define _CACHE_ 00023 00024 // begin_ntifs 00025 // 00026 // Define two constants describing the view size (and alignment) 00027 // that the Cache Manager uses to map files. 00028 // 00029 00030 #define VACB_MAPPING_GRANULARITY (0x40000) 00031 #define VACB_OFFSET_SHIFT (18) 00032 00033 // 00034 // Public portion of BCB 00035 // 00036 00037 typedef struct _PUBLIC_BCB { 00038 00039 // 00040 // Type and size of this record 00041 // 00042 // NOTE: The first four fields must be the same as the BCB in cc.h. 00043 // 00044 00045 CSHORT NodeTypeCode; 00046 CSHORT NodeByteSize; 00047 00048 // 00049 // Description of range of file which is currently mapped. 00050 // 00051 00052 ULONG MappedLength; 00053 LARGE_INTEGER MappedFileOffset; 00054 } PUBLIC_BCB, *PPUBLIC_BCB; 00055 00056 // 00057 // File Sizes structure. 00058 // 00059 00060 typedef struct _CC_FILE_SIZES { 00061 00062 LARGE_INTEGER AllocationSize; 00063 LARGE_INTEGER FileSize; 00064 LARGE_INTEGER ValidDataLength; 00065 00066 } CC_FILE_SIZES, *PCC_FILE_SIZES; 00067 00068 // 00069 // Define a Cache Manager callback structure. These routines are required 00070 // by the Lazy Writer, so that it can acquire resources in the right order 00071 // to avoid deadlocks. Note that otherwise you would have most FS requests 00072 // acquiring FS resources first and caching structures second, while the 00073 // Lazy Writer needs to acquire its own resources first, and then FS 00074 // structures later as it calls the file system. 00075 // 00076 00077 // 00078 // First define the procedure pointer typedefs 00079 // 00080 00081 // 00082 // This routine is called by the Lazy Writer prior to doing a write, 00083 // since this will require some file system resources associated with 00084 // this cached file. The context parameter supplied is whatever the FS 00085 // passed as the LazyWriteContext parameter when is called 00086 // CcInitializeCacheMap. 00087 // 00088 00089 typedef 00090 BOOLEAN (*PACQUIRE_FOR_LAZY_WRITE) ( 00091 IN PVOID Context, 00092 IN BOOLEAN Wait 00093 ); 00094 00095 // 00096 // This routine releases the Context acquired above. 00097 // 00098 00099 typedef 00100 VOID (*PRELEASE_FROM_LAZY_WRITE) ( 00101 IN PVOID Context 00102 ); 00103 00104 // 00105 // This routine is called by the Lazy Writer prior to doing a readahead. 00106 // 00107 00108 typedef 00109 BOOLEAN (*PACQUIRE_FOR_READ_AHEAD) ( 00110 IN PVOID Context, 00111 IN BOOLEAN Wait 00112 ); 00113 00114 // 00115 // This routine releases the Context acquired above. 00116 // 00117 00118 typedef 00119 VOID (*PRELEASE_FROM_READ_AHEAD) ( 00120 IN PVOID Context 00121 ); 00122 00123 typedef struct _CACHE_MANAGER_CALLBACKS { 00124 00125 PACQUIRE_FOR_LAZY_WRITE AcquireForLazyWrite; 00126 PRELEASE_FROM_LAZY_WRITE ReleaseFromLazyWrite; 00127 PACQUIRE_FOR_READ_AHEAD AcquireForReadAhead; 00128 PRELEASE_FROM_READ_AHEAD ReleaseFromReadAhead; 00129 00130 } CACHE_MANAGER_CALLBACKS, *PCACHE_MANAGER_CALLBACKS; 00131 00132 // 00133 // This structure is passed into CcUninitializeCacheMap 00134 // if the caller wants to know when the cache map is deleted. 00135 // 00136 00137 typedef struct _CACHE_UNINITIALIZE_EVENT { 00138 struct _CACHE_UNINITIALIZE_EVENT *Next; 00139 KEVENT Event; 00140 } CACHE_UNINITIALIZE_EVENT, *PCACHE_UNINITIALIZE_EVENT; 00141 00142 // end_ntifs 00143 // 00144 // Callback routine for retrieving dirty pages from Cache Manager. 00145 // 00146 00147 typedef 00148 VOID (*PDIRTY_PAGE_ROUTINE) ( 00149 IN PFILE_OBJECT FileObject, 00150 IN PLARGE_INTEGER FileOffset, 00151 IN ULONG Length, 00152 IN PLARGE_INTEGER OldestLsn, 00153 IN PLARGE_INTEGER NewestLsn, 00154 IN PVOID Context1, 00155 IN PVOID Context2 00156 ); 00157 00158 // 00159 // Callback routine for doing log file flushes to Lsn. 00160 // 00161 00162 typedef 00163 VOID (*PFLUSH_TO_LSN) ( 00164 IN PVOID LogHandle, 00165 IN LARGE_INTEGER Lsn 00166 ); 00167 00168 // begin_ntifs 00169 // 00170 // Macro to test whether a file is cached or not. 00171 // 00172 00173 #define CcIsFileCached(FO) ( \ 00174 ((FO)->SectionObjectPointer != NULL) && \ 00175 (((PSECTION_OBJECT_POINTERS)(FO)->SectionObjectPointer)->SharedCacheMap != NULL) \ 00176 ) 00177 00178 // end_ntifs 00179 // 00180 // Throw away miss counter 00181 // 00182 00183 extern ULONG CcThrowAway; 00184 00185 // 00186 // Performance Counters 00187 // 00188 00189 extern ULONG CcFastReadNoWait; 00190 extern ULONG CcFastReadWait; 00191 extern ULONG CcFastReadResourceMiss; 00192 extern ULONG CcFastReadNotPossible; 00193 00194 extern ULONG CcFastMdlReadNoWait; 00195 extern ULONG CcFastMdlReadWait; 00196 extern ULONG CcFastMdlReadResourceMiss; 00197 extern ULONG CcFastMdlReadNotPossible; 00198 00199 extern ULONG CcMapDataNoWait; 00200 extern ULONG CcMapDataWait; 00201 extern ULONG CcMapDataNoWaitMiss; 00202 extern ULONG CcMapDataWaitMiss; 00203 00204 extern ULONG CcPinMappedDataCount; 00205 00206 extern ULONG CcPinReadNoWait; 00207 extern ULONG CcPinReadWait; 00208 extern ULONG CcPinReadNoWaitMiss; 00209 extern ULONG CcPinReadWaitMiss; 00210 00211 extern ULONG CcCopyReadNoWait; 00212 extern ULONG CcCopyReadWait; 00213 extern ULONG CcCopyReadNoWaitMiss; 00214 extern ULONG CcCopyReadWaitMiss; 00215 00216 extern ULONG CcMdlReadNoWait; 00217 extern ULONG CcMdlReadWait; 00218 extern ULONG CcMdlReadNoWaitMiss; 00219 extern ULONG CcMdlReadWaitMiss; 00220 00221 extern ULONG CcReadAheadIos; 00222 00223 extern ULONG CcLazyWriteIos; 00224 extern ULONG CcLazyWritePages; 00225 extern ULONG CcDataFlushes; 00226 extern ULONG CcDataPages; 00227 00228 extern PULONG CcMissCounter; 00229 00230 // 00231 // Global Maintenance routines 00232 // 00233 00234 NTKERNELAPI 00235 BOOLEAN 00236 CcInitializeCacheManager ( 00237 ); 00238 00239 // begin_ntifs 00240 // 00241 // The following routines are intended for use by File Systems Only. 00242 // 00243 00244 NTKERNELAPI 00245 VOID 00246 CcInitializeCacheMap ( 00247 IN PFILE_OBJECT FileObject, 00248 IN PCC_FILE_SIZES FileSizes, 00249 IN BOOLEAN PinAccess, 00250 IN PCACHE_MANAGER_CALLBACKS Callbacks, 00251 IN PVOID LazyWriteContext 00252 ); 00253 00254 NTKERNELAPI 00255 BOOLEAN 00256 CcUninitializeCacheMap ( 00257 IN PFILE_OBJECT FileObject, 00258 IN PLARGE_INTEGER TruncateSize OPTIONAL, 00259 IN PCACHE_UNINITIALIZE_EVENT UninitializeCompleteEvent OPTIONAL 00260 ); 00261 00262 NTKERNELAPI 00263 VOID 00264 CcSetFileSizes ( 00265 IN PFILE_OBJECT FileObject, 00266 IN PCC_FILE_SIZES FileSizes 00267 ); 00268 00269 // 00270 // VOID 00271 // CcFastIoSetFileSizes ( 00272 // IN PFILE_OBJECT FileObject, 00273 // IN PCC_FILE_SIZES FileSizes 00274 // ); 00275 // 00276 00277 #define CcGetFileSizePointer(FO) ( \ 00278 ((PLARGE_INTEGER)((FO)->SectionObjectPointer->SharedCacheMap) + 1) \ 00279 ) 00280 00281 NTKERNELAPI 00282 BOOLEAN 00283 CcPurgeCacheSection ( 00284 IN PSECTION_OBJECT_POINTERS SectionObjectPointer, 00285 IN PLARGE_INTEGER FileOffset OPTIONAL, 00286 IN ULONG Length, 00287 IN BOOLEAN UninitializeCacheMaps 00288 ); 00289 00290 NTKERNELAPI 00291 VOID 00292 CcSetDirtyPageThreshold ( 00293 IN PFILE_OBJECT FileObject, 00294 IN ULONG DirtyPageThreshold 00295 ); 00296 00297 NTKERNELAPI 00298 VOID 00299 CcFlushCache ( 00300 IN PSECTION_OBJECT_POINTERS SectionObjectPointer, 00301 IN PLARGE_INTEGER FileOffset OPTIONAL, 00302 IN ULONG Length, 00303 OUT PIO_STATUS_BLOCK IoStatus OPTIONAL 00304 ); 00305 00306 NTKERNELAPI 00307 LARGE_INTEGER 00308 CcGetFlushedValidData ( 00309 IN PSECTION_OBJECT_POINTERS SectionObjectPointer, 00310 IN BOOLEAN BcbListHeld 00311 ); 00312 00313 // end_ntifs 00314 NTKERNELAPI 00315 VOID 00316 CcZeroEndOfLastPage ( 00317 IN PFILE_OBJECT FileObject 00318 ); 00319 00320 // begin_ntifs 00321 NTKERNELAPI 00322 BOOLEAN 00323 CcZeroData ( 00324 IN PFILE_OBJECT FileObject, 00325 IN PLARGE_INTEGER StartOffset, 00326 IN PLARGE_INTEGER EndOffset, 00327 IN BOOLEAN Wait 00328 ); 00329 00330 NTKERNELAPI 00331 PVOID 00332 CcRemapBcb ( 00333 IN PVOID Bcb 00334 ); 00335 00336 NTKERNELAPI 00337 VOID 00338 CcRepinBcb ( 00339 IN PVOID Bcb 00340 ); 00341 00342 NTKERNELAPI 00343 VOID 00344 CcUnpinRepinnedBcb ( 00345 IN PVOID Bcb, 00346 IN BOOLEAN WriteThrough, 00347 OUT PIO_STATUS_BLOCK IoStatus 00348 ); 00349 00350 NTKERNELAPI 00351 PFILE_OBJECT 00352 CcGetFileObjectFromSectionPtrs ( 00353 IN PSECTION_OBJECT_POINTERS SectionObjectPointer 00354 ); 00355 00356 NTKERNELAPI 00357 PFILE_OBJECT 00358 CcGetFileObjectFromBcb ( 00359 IN PVOID Bcb 00360 ); 00361 00362 // 00363 // These routines are implemented to support write throttling. 00364 // 00365 00366 // 00367 // BOOLEAN 00368 // CcCopyWriteWontFlush ( 00369 // IN PFILE_OBJECT FileObject, 00370 // IN PLARGE_INTEGER FileOffset, 00371 // IN ULONG Length 00372 // ); 00373 // 00374 00375 #define CcCopyWriteWontFlush(FO,FOFF,LEN) ((LEN) <= 0X10000) 00376 00377 NTKERNELAPI 00378 BOOLEAN 00379 CcCanIWrite ( 00380 IN PFILE_OBJECT FileObject, 00381 IN ULONG BytesToWrite, 00382 IN BOOLEAN Wait, 00383 IN BOOLEAN Retrying 00384 ); 00385 00386 typedef 00387 VOID (*PCC_POST_DEFERRED_WRITE) ( 00388 IN PVOID Context1, 00389 IN PVOID Context2 00390 ); 00391 00392 NTKERNELAPI 00393 VOID 00394 CcDeferWrite ( 00395 IN PFILE_OBJECT FileObject, 00396 IN PCC_POST_DEFERRED_WRITE PostRoutine, 00397 IN PVOID Context1, 00398 IN PVOID Context2, 00399 IN ULONG BytesToWrite, 00400 IN BOOLEAN Retrying 00401 ); 00402 00403 // 00404 // The following routines provide a data copy interface to the cache, and 00405 // are intended for use by File Servers and File Systems. 00406 // 00407 00408 NTKERNELAPI 00409 BOOLEAN 00410 CcCopyRead ( 00411 IN PFILE_OBJECT FileObject, 00412 IN PLARGE_INTEGER FileOffset, 00413 IN ULONG Length, 00414 IN BOOLEAN Wait, 00415 OUT PVOID Buffer, 00416 OUT PIO_STATUS_BLOCK IoStatus 00417 ); 00418 00419 NTKERNELAPI 00420 VOID 00421 CcFastCopyRead ( 00422 IN PFILE_OBJECT FileObject, 00423 IN ULONG FileOffset, 00424 IN ULONG Length, 00425 IN ULONG PageCount, 00426 OUT PVOID Buffer, 00427 OUT PIO_STATUS_BLOCK IoStatus 00428 ); 00429 00430 NTKERNELAPI 00431 BOOLEAN 00432 CcCopyWrite ( 00433 IN PFILE_OBJECT FileObject, 00434 IN PLARGE_INTEGER FileOffset, 00435 IN ULONG Length, 00436 IN BOOLEAN Wait, 00437 IN PVOID Buffer 00438 ); 00439 00440 NTKERNELAPI 00441 VOID 00442 CcFastCopyWrite ( 00443 IN PFILE_OBJECT FileObject, 00444 IN ULONG FileOffset, 00445 IN ULONG Length, 00446 IN PVOID Buffer 00447 ); 00448 00449 // 00450 // The following routines provide an Mdl interface for transfers to and 00451 // from the cache, and are primarily intended for File Servers. 00452 // 00453 // NOBODY SHOULD BE CALLING THESE MDL ROUTINES DIRECTLY, USE FSRTL AND 00454 // FASTIO INTERFACES. 00455 // 00456 00457 NTKERNELAPI 00458 VOID 00459 CcMdlRead ( 00460 IN PFILE_OBJECT FileObject, 00461 IN PLARGE_INTEGER FileOffset, 00462 IN ULONG Length, 00463 OUT PMDL *MdlChain, 00464 OUT PIO_STATUS_BLOCK IoStatus 00465 ); 00466 00467 // 00468 // This routine is now a wrapper for FastIo if present or CcMdlReadComplete2 00469 // 00470 00471 NTKERNELAPI 00472 VOID 00473 CcMdlReadComplete ( 00474 IN PFILE_OBJECT FileObject, 00475 IN PMDL MdlChain 00476 ); 00477 00478 // end_ntifs 00479 NTKERNELAPI 00480 VOID 00481 CcMdlReadComplete2 ( 00482 IN PFILE_OBJECT FileObject, 00483 IN PMDL MdlChain 00484 ); 00485 00486 // begin_ntifs 00487 00488 NTKERNELAPI 00489 VOID 00490 CcPrepareMdlWrite ( 00491 IN PFILE_OBJECT FileObject, 00492 IN PLARGE_INTEGER FileOffset, 00493 IN ULONG Length, 00494 OUT PMDL *MdlChain, 00495 OUT PIO_STATUS_BLOCK IoStatus 00496 ); 00497 00498 // 00499 // This routine is now a wrapper for FastIo if present or CcMdlWriteComplete2 00500 // 00501 00502 NTKERNELAPI 00503 VOID 00504 CcMdlWriteComplete ( 00505 IN PFILE_OBJECT FileObject, 00506 IN PLARGE_INTEGER FileOffset, 00507 IN PMDL MdlChain 00508 ); 00509 00510 // end_ntifs 00511 NTKERNELAPI 00512 VOID 00513 CcMdlWriteComplete2 ( 00514 IN PFILE_OBJECT FileObject, 00515 IN PLARGE_INTEGER FileOffset, 00516 IN PMDL MdlChain 00517 ); 00518 00519 // begin_ntifs 00520 // 00521 // Common ReadAhead call for Copy Read and Mdl Read. 00522 // 00523 // ReadAhead should always be invoked by calling the CcReadAhead macro, 00524 // which tests first to see if the read is large enough to warrant read 00525 // ahead. Measurements have shown that, calling the read ahead routine 00526 // actually decreases performance for small reads, such as issued by 00527 // many compilers and linkers. Compilers simply want all of the include 00528 // files to stay in memory after being read the first time. 00529 // 00530 00531 #define CcReadAhead(FO,FOFF,LEN) { \ 00532 if ((LEN) >= 256) { \ 00533 CcScheduleReadAhead((FO),(FOFF),(LEN)); \ 00534 } \ 00535 } 00536 00537 NTKERNELAPI 00538 VOID 00539 CcScheduleReadAhead ( 00540 IN PFILE_OBJECT FileObject, 00541 IN PLARGE_INTEGER FileOffset, 00542 IN ULONG Length 00543 ); 00544 00545 // 00546 // The following routine allows a caller to wait for the next batch 00547 // of lazy writer work to complete. In particular, this provides a 00548 // mechanism for a caller to be sure that all avaliable lazy closes 00549 // at the time of this call have issued. 00550 // 00551 00552 NTSTATUS 00553 CcWaitForCurrentLazyWriterActivity ( 00554 ); 00555 00556 // 00557 // This routine changes the read ahead granularity for a file, which is 00558 // PAGE_SIZE by default. 00559 // 00560 00561 NTKERNELAPI 00562 VOID 00563 CcSetReadAheadGranularity ( 00564 IN PFILE_OBJECT FileObject, 00565 IN ULONG Granularity 00566 ); 00567 00568 // 00569 // The following routines provide direct access data which is pinned in the 00570 // cache, and is primarily intended for use by File Systems. In particular, 00571 // this mode of access is ideal for dealing with volume structures. 00572 // 00573 00574 // 00575 // Flags for pinning 00576 // 00577 00578 // 00579 // Synchronous Wait - normally specified. This pattern may be specified as TRUE. 00580 // 00581 00582 #define PIN_WAIT (1) 00583 00584 // 00585 // Acquire metadata Bcb exclusive (default is shared, Lazy Writer uses exclusive). 00586 // 00587 // Must be set with PIN_WAIT. 00588 // 00589 00590 #define PIN_EXCLUSIVE (2) 00591 00592 // 00593 // Acquire metadata Bcb but do not fault data in. Default is to fault the data in. 00594 // This unusual flag is only used by Ntfs for cache coherency synchronization between 00595 // compressed and uncompressed streams for the same compressed file. 00596 // 00597 // Must be set with PIN_WAIT. 00598 // 00599 00600 #define PIN_NO_READ (4) 00601 00602 // 00603 // This option may be used to pin data only if the Bcb already exists. If the Bcb 00604 // does not already exist - the pin is unsuccessful and no Bcb is returned. This routine 00605 // provides a way to see if data is already pinned (and possibly dirty) in the cache, 00606 // without forcing a fault if the data is not there. 00607 // 00608 00609 #define PIN_IF_BCB (8) 00610 00611 NTKERNELAPI 00612 BOOLEAN 00613 CcPinRead ( 00614 IN PFILE_OBJECT FileObject, 00615 IN PLARGE_INTEGER FileOffset, 00616 IN ULONG Length, 00617 IN ULONG Flags, 00618 OUT PVOID *Bcb, 00619 OUT PVOID *Buffer 00620 ); 00621 00622 NTKERNELAPI 00623 BOOLEAN 00624 CcMapData ( 00625 IN PFILE_OBJECT FileObject, 00626 IN PLARGE_INTEGER FileOffset, 00627 IN ULONG Length, 00628 IN BOOLEAN Wait, 00629 OUT PVOID *Bcb, 00630 OUT PVOID *Buffer 00631 ); 00632 00633 NTKERNELAPI 00634 BOOLEAN 00635 CcPinMappedData ( 00636 IN PFILE_OBJECT FileObject, 00637 IN PLARGE_INTEGER FileOffset, 00638 IN ULONG Length, 00639 IN ULONG Flags, 00640 IN OUT PVOID *Bcb 00641 ); 00642 00643 NTKERNELAPI 00644 BOOLEAN 00645 CcPreparePinWrite ( 00646 IN PFILE_OBJECT FileObject, 00647 IN PLARGE_INTEGER FileOffset, 00648 IN ULONG Length, 00649 IN BOOLEAN Zero, 00650 IN ULONG Flags, 00651 OUT PVOID *Bcb, 00652 OUT PVOID *Buffer 00653 ); 00654 00655 NTKERNELAPI 00656 VOID 00657 CcSetDirtyPinnedData ( 00658 IN PVOID BcbVoid, 00659 IN PLARGE_INTEGER Lsn OPTIONAL 00660 ); 00661 00662 NTKERNELAPI 00663 VOID 00664 CcUnpinData ( 00665 IN PVOID Bcb 00666 ); 00667 00668 NTKERNELAPI 00669 VOID 00670 CcSetBcbOwnerPointer ( 00671 IN PVOID Bcb, 00672 IN PVOID OwnerPointer 00673 ); 00674 00675 NTKERNELAPI 00676 VOID 00677 CcUnpinDataForThread ( 00678 IN PVOID Bcb, 00679 IN ERESOURCE_THREAD ResourceThreadId 00680 ); 00681 00682 // end_ntifs 00683 // 00684 // The following routines are in logsup.c, and provide special Cache Manager 00685 // support for storting Lsns with dirty file pages, and peforming subsequent 00686 // operations based on them. 00687 // 00688 00689 // begin_ntifs 00690 00691 NTKERNELAPI 00692 VOID 00693 CcSetAdditionalCacheAttributes ( 00694 IN PFILE_OBJECT FileObject, 00695 IN BOOLEAN DisableReadAhead, 00696 IN BOOLEAN DisableWriteBehind 00697 ); 00698 00699 // end_ntifs 00700 00701 NTKERNELAPI 00702 VOID 00703 CcSetLogHandleForFile ( 00704 IN PFILE_OBJECT FileObject, 00705 IN PVOID LogHandle, 00706 IN PFLUSH_TO_LSN FlushToLsnRoutine 00707 ); 00708 00709 NTKERNELAPI 00710 LARGE_INTEGER 00711 CcGetDirtyPages ( 00712 IN PVOID LogHandle, 00713 IN PDIRTY_PAGE_ROUTINE DirtyPageRoutine, 00714 IN PVOID Context1, 00715 IN PVOID Context2 00716 ); 00717 00718 // begin_ntifs 00719 00720 NTKERNELAPI 00721 BOOLEAN 00722 CcIsThereDirtyData ( 00723 IN PVPB Vpb 00724 ); 00725 00726 // end_ntifs 00727 00728 NTKERNELAPI 00729 LARGE_INTEGER 00730 CcGetLsnForFileObject( 00731 IN PFILE_OBJECT FileObject, 00732 OUT PLARGE_INTEGER OldestLsn OPTIONAL 00733 ); 00734 00735 #endif // CACHE

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