Source code of Windows XP (NT5)
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.

486 lines
9.7 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name :
  4. tsunamip.hxx
  5. Abstract:
  6. This module defines private structures and functions for
  7. tsunami module
  8. Author:
  9. Murali R. Krishnan ( MuraliK ) 13-Jan-1995
  10. Project:
  11. Tsuanmi Library ( caching and logging module for InternetServices)
  12. Revision History:
  13. MuraliK 20-Feb-1995 Added File System Types.
  14. MuraliK 22-Jan-1996 Cache UNC Impersonation Token
  15. MCourage 11-Dec-1997 Moved to cache2 for cache rewrite
  16. --*/
  17. #ifndef _TSUNAMIP_HXX_
  18. #define _TSUNAMIP_HXX_
  19. /************************************************************
  20. * Include Headers
  21. ************************************************************/
  22. # if defined ( __cplusplus)
  23. extern "C" {
  24. # endif
  25. #include <nt.h>
  26. #include <ntrtl.h>
  27. #include <nturtl.h>
  28. #include <windows.h>
  29. #include <basetyps.h>
  30. #include <lmcons.h>
  31. # if defined ( __cplusplus)
  32. }
  33. # endif
  34. #include <iis64.h>
  35. #include <inetinfo.h>
  36. #include "iperfctr.hxx"
  37. #include <refb.hxx>
  38. #include "dbgutil.h"
  39. #include <iistypes.hxx>
  40. #include <tsvroot.hxx>
  41. #include <tsunami.hxx>
  42. #include <reftrace.h>
  43. #include "tsmemp.hxx"
  44. #include "globals.hxx"
  45. #include "dbgmacro.hxx"
  46. #define ENABLE_DIR_MONITOR 1
  47. #include <dirmon.h>
  48. //
  49. // Setting TSUNAMI_REF_DEBUG to a non-zero value will enable reference
  50. // count logging.
  51. //
  52. #if DBG
  53. #define TSUNAMI_REF_DEBUG 1
  54. #else // !DBG
  55. #define TSUNAMI_REF_DEBUG 0
  56. #endif // DBG
  57. //
  58. // Tracing support.
  59. //
  60. #if TSUNAMI_REF_DEBUG
  61. extern PTRACE_LOG RefTraceLog;
  62. #define TSUNAMI_TRACE( refcount, context ) \
  63. if( RefTraceLog != NULL ) { \
  64. WriteRefTraceLog( \
  65. RefTraceLog, \
  66. (refcount), \
  67. (context) \
  68. ); \
  69. } else
  70. #else // !TSUNAMI_REF_DEBUG
  71. #define TSUNAMI_TRACE( refcount, context )
  72. #endif // TSUNAMI_REF_DEBUG
  73. /************************************************************
  74. * Type Definitions
  75. ************************************************************/
  76. struct _CACHE_OBJECT;
  77. class CBlobKey;
  78. class CVRootDirMonitorEntry;
  79. class CFileHashTable;
  80. class CFileCacheStats;
  81. class CBlobCacheStats;
  82. //
  83. // Globals
  84. //
  85. extern DWORD TsCreateFileShareMode;
  86. extern DWORD TsValidCreateFileOptions;
  87. extern DWORD TsCreateFileFlags;
  88. extern CFileHashTable * g_pFileInfoTable;
  89. extern CFileCacheStats * g_pFileCacheStats;
  90. extern CBlobCacheStats * g_pURICacheStats;
  91. extern CBlobCacheStats * g_pBlobCacheStats;
  92. extern CRITICAL_SECTION g_csUriInfo;
  93. //
  94. // ETag allocation related structures
  95. //
  96. // 3.0 seconds
  97. #define STRONG_ETAG_DELTA 30000000
  98. INT
  99. FormatETag(
  100. PCHAR pszBuffer,
  101. const FILETIME& rft,
  102. DWORD mdchange);
  103. #define FORMAT_ETAG(buffer, time, mdchange) \
  104. FormatETag(buffer, time, mdchange)
  105. //
  106. // bogus win95 handle
  107. //
  108. #define BOGUS_WIN95_DIR_HANDLE ((HANDLE)0x88888888)
  109. //
  110. // This is the maximum number of UNC file handles to cache. The SMB
  111. // protocol limits the server to 2048 open files per client. Currently,
  112. // this count includes *all* UNC connections regardles of the remote
  113. // server
  114. //
  115. #define MAX_CACHED_UNC_HANDLES 1200
  116. extern DWORD cCachedUNCHandles;
  117. extern LARGE_INTEGER g_liFileCacheByteThreshold;
  118. extern DWORDLONG g_dwMemCacheSize;
  119. extern BOOL g_bEnableSequentialRead;
  120. //
  121. // Disables Tsunami Caching
  122. //
  123. extern BOOL DisableTsunamiCaching;
  124. //
  125. // Disables SPUD
  126. //
  127. extern BOOL DisableSPUD;
  128. //
  129. // Allows us to mask the invalid flags
  130. //
  131. extern DWORD TsValidCreateFileOptions;
  132. //
  133. // flags for create file
  134. //
  135. extern BOOL TsNoDirOpenSupport;
  136. extern DWORD TsCreateFileFlags;
  137. extern DWORD TsCreateFileShareMode;
  138. //
  139. // function prototypes
  140. //
  141. BOOL
  142. Cache_Initialize(
  143. IN DWORD MaxOpenFile
  144. );
  145. BOOL
  146. MetaCache_Initialize(
  147. VOID
  148. );
  149. BOOL
  150. MetaCache_Terminate(
  151. VOID
  152. );
  153. //
  154. // This function converts a service ID into an index for statistics
  155. // gathering
  156. //
  157. inline
  158. DWORD
  159. MaskIndex( DWORD dwService )
  160. {
  161. if ( dwService > 0 && dwService <= LAST_PERF_CTR_SVC )
  162. return dwService - 1;
  163. else
  164. return CACHE_STATS_UNUSED_INDEX;
  165. }
  166. #define INC_COUNTER( dwServiceId, CounterName ) \
  167. IP_INCREMENT_COUNTER( Configuration.Stats[MaskIndex(dwServiceId)].CounterName )
  168. #define DEC_COUNTER( dwServiceId, CounterName ) \
  169. IP_DECREMENT_COUNTER( Configuration.Stats[MaskIndex(dwServiceId)].CounterName )
  170. #define SET_COUNTER( dwServiceId, CounterName, Val ) \
  171. IP_SET_COUNTER( Configuration.Stats[MaskIndex(dwServiceId)].CounterName, Val )
  172. //
  173. // Virtual roots related data and structures.
  174. //
  175. extern LIST_ENTRY GlobalVRootList;
  176. extern HANDLE g_hNewItem;
  177. extern HANDLE g_hQuit;
  178. typedef struct {
  179. DWORD Signature;
  180. BOOLEAN fUNC;
  181. DWORD dwServiceID;
  182. DWORD dwInstanceID;
  183. DWORD dwFileSystem;
  184. DWORD dwAccessMask;
  185. HANDLE hImpersonationToken;
  186. DWORD cchRootA;
  187. DWORD cchDirectoryA;
  188. CHAR pszRootA[ MAX_LENGTH_VIRTUAL_ROOT + 1 ];
  189. CHAR pszDirectoryA[ MAX_PATH + 1 ];
  190. CHAR pszAccountName[ UNLEN + 1 ];
  191. CVRootDirMonitorEntry * pDME;
  192. } VIRTUAL_ROOT_MAPPING, *PVIRTUAL_ROOT_MAPPING;
  193. #define VIRT_ROOT_SIGNATURE 0x544F4F52 // 'ROOT'
  194. //
  195. // Number of times to try and get dir change notification
  196. //
  197. #define MAX_NOTIFICATION_FAILURES 3
  198. #if ENABLE_DIR_MONITOR
  199. class CVRootDirMonitorEntry : public CDirMonitorEntry
  200. {
  201. private:
  202. DWORD m_cNotificationFailures;
  203. // BOOL IORelease(VOID);
  204. BOOL ActOnNotification(DWORD dwStatus, DWORD dwBytesWritten);
  205. void FileChanged(const char *pszFileName, BOOL bDoFlush);
  206. public:
  207. CVRootDirMonitorEntry();
  208. ~CVRootDirMonitorEntry();
  209. // BOOL Release(VOID);
  210. BOOL Init();
  211. };
  212. #endif // ENABLE_DIR_MONITOR
  213. //
  214. // Directory Change Manager Functions
  215. //
  216. BOOL
  217. DcmInitialize(
  218. VOID
  219. );
  220. VOID
  221. DcmTerminate(
  222. VOID
  223. );
  224. BOOL
  225. DcmAddRoot(
  226. PVIRTUAL_ROOT_MAPPING pVrm
  227. );
  228. VOID
  229. DcmRemoveRoot(
  230. PVIRTUAL_ROOT_MAPPING pVrm
  231. );
  232. //
  233. // Directory Listing related objects and functions
  234. //
  235. # define MAX_DIR_ENTRIES_PER_BLOCK (25)
  236. typedef struct _TS_DIR_BUFFERS {
  237. LIST_ENTRY listEntry;
  238. int nEntries;
  239. WIN32_FIND_DATA rgFindData[MAX_DIR_ENTRIES_PER_BLOCK];
  240. } TS_DIR_BUFFERS, * PTS_DIR_BUFFERS;
  241. class TS_DIRECTORY_HEADER
  242. : public BLOB_HEADER
  243. {
  244. public:
  245. TS_DIRECTORY_HEADER( VOID)
  246. : m_hListingUser ( INVALID_HANDLE_VALUE),
  247. m_nEntries ( 0),
  248. m_ppFileInfo ( NULL)
  249. { InitializeListHead( & m_listDirectoryBuffers); }
  250. ~TS_DIRECTORY_HEADER( VOID) {}
  251. BOOL
  252. IsValid( VOID) const
  253. { return ( TRUE); }
  254. int
  255. QueryNumEntries( VOID) const
  256. { return ( m_nEntries); }
  257. HANDLE
  258. QueryListingUser( VOID) const
  259. { return ( m_hListingUser); }
  260. const PWIN32_FIND_DATA *
  261. QueryArrayOfFileInfoPointers(VOID) const
  262. { return ( m_ppFileInfo); }
  263. PLIST_ENTRY
  264. QueryDirBuffersListEntry( VOID)
  265. { return ( & m_listDirectoryBuffers); }
  266. VOID
  267. ReInitialize( VOID)
  268. {
  269. //
  270. // this function provided to initialize, when we allocate using
  271. // malloc or GlobalAlloc()
  272. m_hListingUser = INVALID_HANDLE_VALUE;
  273. m_nEntries = 0;
  274. m_ppFileInfo = NULL;
  275. InitializeListHead( &m_listDirectoryBuffers);
  276. }
  277. VOID
  278. SetListingUser( IN HANDLE hListingUser)
  279. { m_hListingUser = hListingUser; }
  280. VOID
  281. IncrementDirEntries( VOID)
  282. { m_nEntries++; }
  283. VOID
  284. InsertBufferInTail( IN PLIST_ENTRY pEntry)
  285. { InsertTailList( &m_listDirectoryBuffers, pEntry); }
  286. VOID
  287. CleanupThis( VOID);
  288. BOOL
  289. ReadWin32DirListing(IN LPCSTR pszDirectoryName,
  290. IN OUT DWORD * pcbMemUsed );
  291. BOOL
  292. BuildFileInfoPointers( IN OUT DWORD * pcbMemUsed );
  293. # if DBG
  294. VOID Print( VOID) const;
  295. #else
  296. VOID Print( VOID) const
  297. { ; }
  298. # endif // DBG
  299. private:
  300. HANDLE m_hListingUser;
  301. int m_nEntries;
  302. // contains array of pointers indirected into buffers in m_listDirBuffers
  303. PWIN32_FIND_DATA * m_ppFileInfo;
  304. LIST_ENTRY m_listDirectoryBuffers; // ptr to DIR_BUFFERS
  305. }; // class TS_DIRECTORY_HEADER
  306. typedef TS_DIRECTORY_HEADER * PTS_DIRECTORY_HEADER;
  307. //
  308. // Virtual roots and directories always have their trailing slashes
  309. // stripped. This macro is used disambiguate the "/root1/" from "/root/"
  310. // case where "/root/" is an existing root (i.e., matching prefix).
  311. //
  312. extern BOOL
  313. IsCharTermA(
  314. IN LPCSTR lpszString,
  315. IN INT cch
  316. );
  317. #define IS_CHAR_TERM_A( psz, cch ) IsCharTermA(psz,cch)
  318. extern
  319. dllexp
  320. BOOL
  321. TsGetDirectoryListing(
  322. IN const TSVC_CACHE &TSvcCache,
  323. IN PCSTR pszDirectoryName,
  324. IN HANDLE ListingUser,
  325. OUT PTS_DIRECTORY_HEADER* ppDirectoryHeader
  326. );
  327. extern
  328. dllexp
  329. BOOL
  330. TsFreeDirectoryListing
  331. (
  332. IN const TSVC_CACHE & TSvcCache,
  333. IN OUT PTS_DIRECTORY_HEADER pTsDirectoryHeader
  334. );
  335. extern
  336. BOOL
  337. SortInPlaceFileInfoPointers(
  338. IN OUT PWIN32_FIND_DATA * prgFileInfo,
  339. IN int nFiles,
  340. IN PFN_CMP_WIN32_FIND_DATA pfnCompare
  341. );
  342. extern
  343. BOOL
  344. RegExpressionMatch( IN LPCSTR pszName, IN LPCSTR pszRegExp);
  345. #pragma hdrstop
  346. #endif // _TSUNAMIP_HXX_