Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

260 lines
5.6 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1998 **/
  4. /**********************************************************************/
  5. /*
  6. filecach.hxx
  7. This module declares the private interface to the file cache
  8. FILE HISTORY:
  9. MCourage 11-Dec-1997 Created
  10. */
  11. #ifndef _FILECACH_H_
  12. #define _FILECACH_H_
  13. extern HANDLE g_hFileCacheShutdownEvent;
  14. extern BOOL g_fFileCacheShutdown;
  15. /*
  16. * Symbolic Constants
  17. */
  18. #define FCF_UNINITIALIZED 0x00000001
  19. #define FCF_FOR_IO 0x00000002
  20. #define FCF_NO_DEREF 0x00000004
  21. #define TS_ERROR_SUCCESS 0
  22. #define TS_ERROR_OUT_OF_MEMORY 1
  23. #define TS_ERROR_ALREADY_CACHED 2
  24. const DWORD c_dwSleepmax = 1000; // on file opens don't sleep longer than 1s
  25. const DWORD c_SleepTimeout = 100; // Don't sleep more than 100 times
  26. /*
  27. * File Cache functions
  28. */
  29. BOOL
  30. FileCache_Initialize(
  31. IN DWORD dwMaxFiles
  32. );
  33. VOID
  34. FileCache_Terminate(
  35. VOID
  36. );
  37. DWORD
  38. CacheFile(
  39. IN TS_OPEN_FILE_INFO * pOpenFile,
  40. IN DWORD dwFlags
  41. );
  42. VOID
  43. NotifyInitializedFile(
  44. IN TS_OPEN_FILE_INFO * pOpenFile
  45. );
  46. VOID
  47. DecacheFile(
  48. IN TS_OPEN_FILE_INFO * pOpenFile,
  49. IN DWORD dwFlags
  50. );
  51. VOID
  52. FlushFileCache(
  53. VOID
  54. );
  55. typedef BOOL (*PFCFILTERRTN)(TS_OPEN_FILE_INFO *pOpenFile, PVOID pv);
  56. VOID
  57. FilteredFlushFileCache(
  58. IN PFCFILTERRTN pFilterRoutine,
  59. IN PVOID pv
  60. );
  61. BOOL
  62. CheckoutFile(
  63. IN LPCSTR pstrPath,
  64. IN DWORD dwFlags,
  65. OUT TS_OPEN_FILE_INFO ** ppOpenFile
  66. );
  67. BOOL
  68. CheckoutFileEntry(
  69. IN TS_OPEN_FILE_INFO * pOpenFile,
  70. IN DWORD dwFlags
  71. );
  72. VOID
  73. CheckinFile(
  74. IN TS_OPEN_FILE_INFO * pOpenFile,
  75. IN DWORD dwFlags
  76. );
  77. /*
  78. * Statistics stuff
  79. */
  80. class CFileCacheStats
  81. {
  82. private:
  83. DWORD FilesCached; // # of files currently in the cache
  84. DWORD TotalFilesCached; // # of files added to the cache ever
  85. DWORD Hits; // cache hits
  86. DWORD Misses; // cache misses
  87. DWORD Flushes; // flushes due to dir change or other
  88. DWORD OplockBreaks; // decache operations due to oplock breaks
  89. DWORD OplockBreaksToNone; // decache operations due to oplock Break To None
  90. DWORD FlushedEntries; // # of flushed entries still kicking around
  91. DWORD TotalFlushed; // # of entries ever flushed from the cache
  92. DWORD Decached4Space; // # of entries decached to make room
  93. public:
  94. CFileCacheStats()
  95. : FilesCached(0),
  96. TotalFilesCached(0),
  97. Hits(0),
  98. Misses(0),
  99. Flushes(0),
  100. OplockBreaks(0),
  101. OplockBreaksToNone(0),
  102. FlushedEntries(0),
  103. TotalFlushed(0),
  104. Decached4Space(0)
  105. {}
  106. BOOL DumpToHtml(CHAR * pchBuffer, LPDWORD lpcbBuffer) const;
  107. BOOL QueryStats(INETA_CACHE_STATISTICS * pCacheCtrs) const;
  108. DWORD GetFilesCached() const
  109. {
  110. return FilesCached;
  111. }
  112. DWORD GetTotalFilesCached() const
  113. {
  114. return TotalFilesCached;
  115. }
  116. DWORD GetHits() const
  117. {
  118. return Hits;
  119. }
  120. DWORD GetMisses() const
  121. {
  122. return Misses;
  123. }
  124. DWORD GetFlushes() const
  125. {
  126. return Flushes;
  127. }
  128. DWORD GetOplockBreaks() const
  129. {
  130. return OplockBreaks;
  131. }
  132. DWORD GetOplockBreaksToNone() const
  133. {
  134. return OplockBreaksToNone;
  135. }
  136. DWORD GetFlushedEntries() const
  137. {
  138. return FlushedEntries;
  139. }
  140. DWORD GetTotalFlushed() const
  141. {
  142. return TotalFlushed;
  143. }
  144. DWORD GetDecached4Space() const
  145. {
  146. return Decached4Space;
  147. }
  148. VOID IncFilesCached(VOID)
  149. {
  150. InterlockedIncrement((LONG *)&FilesCached);
  151. InterlockedIncrement((LONG *)&TotalFilesCached);
  152. }
  153. VOID DecFilesCached(VOID)
  154. {
  155. InterlockedDecrement((LONG *)&FilesCached);
  156. }
  157. VOID IncHits(VOID)
  158. {
  159. InterlockedIncrement((LONG *)&Hits);
  160. }
  161. VOID IncMisses(VOID)
  162. {
  163. InterlockedIncrement((LONG *)&Misses);
  164. }
  165. VOID IncFlushes(VOID)
  166. {
  167. InterlockedIncrement((LONG *)&Flushes);
  168. }
  169. VOID IncOplockBreaks(VOID)
  170. {
  171. InterlockedIncrement((LONG *)&OplockBreaks);
  172. }
  173. VOID IncOplockBreaksToNone(VOID)
  174. {
  175. InterlockedIncrement((LONG *)&OplockBreaksToNone);
  176. }
  177. VOID IncFlushedEntries(VOID)
  178. {
  179. InterlockedIncrement((LONG *)&FlushedEntries);
  180. InterlockedIncrement((LONG *)&TotalFlushed);
  181. }
  182. VOID IncDecached4Space(VOID)
  183. {
  184. InterlockedIncrement((LONG *)&Decached4Space);
  185. }
  186. VOID DecFlushedEntries(VOID)
  187. {
  188. InterlockedDecrement((LONG *)&FlushedEntries);
  189. //
  190. // If we're shutting down, and all the entries are
  191. // gone, it's safe to clean up.
  192. //
  193. if ((FlushedEntries == 0)
  194. && g_fFileCacheShutdown
  195. && (FilesCached == 0)) {
  196. SetEvent(g_hFileCacheShutdownEvent);
  197. }
  198. }
  199. };
  200. class TS_FILE_FLUSH_STATE
  201. {
  202. public:
  203. LIST_ENTRY ListHead;
  204. PFCFILTERRTN pfnFilter;
  205. PVOID pvParm;
  206. };
  207. #if DBG
  208. BOOL CheckFileState(TS_OPEN_FILE_INFO *pOpenFile);
  209. #endif
  210. #define CHECK_FILE_STATE( x ) DBG_ASSERT( CheckFileState((x)) )
  211. #endif