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.

480 lines
10 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. // This is the maximum number of UNC file handles to cache. The SMB
  107. // protocol limits the server to 2048 open files per client. Currently,
  108. // this count includes *all* UNC connections regardles of the remote
  109. // server
  110. //
  111. #define MAX_CACHED_UNC_HANDLES 1200
  112. extern DWORD cCachedUNCHandles;
  113. extern DWORD g_dwFileCacheByteThreshold;
  114. extern DWORDLONG g_dwMemCacheSize;
  115. extern BOOL g_bEnableSequentialRead;
  116. //
  117. // Disables Tsunami Caching
  118. //
  119. extern BOOL DisableTsunamiCaching;
  120. //
  121. // Disables SPUD
  122. //
  123. extern BOOL DisableSPUD;
  124. //
  125. // Allows us to mask the invalid flags
  126. //
  127. extern DWORD TsValidCreateFileOptions;
  128. //
  129. // flags for create file
  130. //
  131. extern BOOL TsNoDirOpenSupport;
  132. extern DWORD TsCreateFileFlags;
  133. extern DWORD TsCreateFileShareMode;
  134. //
  135. // function prototypes
  136. //
  137. BOOL
  138. Cache_Initialize(
  139. IN DWORD MaxOpenFile
  140. );
  141. BOOL
  142. MetaCache_Initialize(
  143. VOID
  144. );
  145. BOOL
  146. MetaCache_Terminate(
  147. VOID
  148. );
  149. //
  150. // This function converts a service ID into an index for statistics
  151. // gathering
  152. //
  153. inline
  154. DWORD
  155. MaskIndex( DWORD dwService )
  156. {
  157. if ( dwService > 0 && dwService <= LAST_PERF_CTR_SVC )
  158. return dwService - 1;
  159. else
  160. return CACHE_STATS_UNUSED_INDEX;
  161. }
  162. #define INC_COUNTER( dwServiceId, CounterName ) \
  163. IP_INCREMENT_COUNTER( Configuration.Stats[MaskIndex(dwServiceId)].CounterName )
  164. #define DEC_COUNTER( dwServiceId, CounterName ) \
  165. IP_DECREMENT_COUNTER( Configuration.Stats[MaskIndex(dwServiceId)].CounterName )
  166. #define SET_COUNTER( dwServiceId, CounterName, Val ) \
  167. IP_SET_COUNTER( Configuration.Stats[MaskIndex(dwServiceId)].CounterName, Val )
  168. //
  169. // Virtual roots related data and structures.
  170. //
  171. extern LIST_ENTRY GlobalVRootList;
  172. extern HANDLE g_hNewItem;
  173. extern HANDLE g_hQuit;
  174. typedef struct {
  175. DWORD Signature;
  176. BOOLEAN fUNC;
  177. DWORD dwServiceID;
  178. DWORD dwInstanceID;
  179. DWORD dwFileSystem;
  180. DWORD dwAccessMask;
  181. HANDLE hImpersonationToken;
  182. DWORD cchRootA;
  183. DWORD cchDirectoryA;
  184. CHAR pszRootA[ MAX_LENGTH_VIRTUAL_ROOT + 1 ];
  185. CHAR pszDirectoryA[ MAX_PATH + 1 ];
  186. CHAR pszAccountName[ UNLEN + 1 ];
  187. CVRootDirMonitorEntry * pDME;
  188. } VIRTUAL_ROOT_MAPPING, *PVIRTUAL_ROOT_MAPPING;
  189. #define VIRT_ROOT_SIGNATURE 0x544F4F52 // 'ROOT'
  190. //
  191. // Number of times to try and get dir change notification
  192. //
  193. #define MAX_NOTIFICATION_FAILURES 3
  194. #if ENABLE_DIR_MONITOR
  195. class CVRootDirMonitorEntry : public CDirMonitorEntry
  196. {
  197. private:
  198. DWORD m_cNotificationFailures;
  199. // BOOL IORelease(VOID);
  200. BOOL ActOnNotification(DWORD dwStatus, DWORD dwBytesWritten);
  201. void FileChanged(const char *pszFileName, BOOL bDoFlush);
  202. public:
  203. CVRootDirMonitorEntry();
  204. ~CVRootDirMonitorEntry();
  205. // BOOL Release(VOID);
  206. BOOL Init();
  207. };
  208. #endif // ENABLE_DIR_MONITOR
  209. //
  210. // Directory Change Manager Functions
  211. //
  212. BOOL
  213. DcmInitialize(
  214. VOID
  215. );
  216. VOID
  217. DcmTerminate(
  218. VOID
  219. );
  220. BOOL
  221. DcmAddRoot(
  222. PVIRTUAL_ROOT_MAPPING pVrm
  223. );
  224. VOID
  225. DcmRemoveRoot(
  226. PVIRTUAL_ROOT_MAPPING pVrm
  227. );
  228. //
  229. // Directory Listing related objects and functions
  230. //
  231. # define MAX_DIR_ENTRIES_PER_BLOCK (25)
  232. typedef struct _TS_DIR_BUFFERS {
  233. LIST_ENTRY listEntry;
  234. int nEntries;
  235. WIN32_FIND_DATA rgFindData[MAX_DIR_ENTRIES_PER_BLOCK];
  236. } TS_DIR_BUFFERS, * PTS_DIR_BUFFERS;
  237. class TS_DIRECTORY_HEADER
  238. : public BLOB_HEADER
  239. {
  240. public:
  241. TS_DIRECTORY_HEADER( VOID)
  242. : m_hListingUser ( INVALID_HANDLE_VALUE),
  243. m_nEntries ( 0),
  244. m_ppFileInfo ( NULL)
  245. { InitializeListHead( & m_listDirectoryBuffers); }
  246. ~TS_DIRECTORY_HEADER( VOID) {}
  247. BOOL
  248. IsValid( VOID) const
  249. { return ( TRUE); }
  250. int
  251. QueryNumEntries( VOID) const
  252. { return ( m_nEntries); }
  253. HANDLE
  254. QueryListingUser( VOID) const
  255. { return ( m_hListingUser); }
  256. const PWIN32_FIND_DATA *
  257. QueryArrayOfFileInfoPointers(VOID) const
  258. { return ( m_ppFileInfo); }
  259. PLIST_ENTRY
  260. QueryDirBuffersListEntry( VOID)
  261. { return ( & m_listDirectoryBuffers); }
  262. VOID
  263. ReInitialize( VOID)
  264. {
  265. //
  266. // this function provided to initialize, when we allocate using
  267. // malloc or GlobalAlloc()
  268. m_hListingUser = INVALID_HANDLE_VALUE;
  269. m_nEntries = 0;
  270. m_ppFileInfo = NULL;
  271. InitializeListHead( &m_listDirectoryBuffers);
  272. }
  273. VOID
  274. SetListingUser( IN HANDLE hListingUser)
  275. { m_hListingUser = hListingUser; }
  276. VOID
  277. IncrementDirEntries( VOID)
  278. { m_nEntries++; }
  279. VOID
  280. InsertBufferInTail( IN PLIST_ENTRY pEntry)
  281. { InsertTailList( &m_listDirectoryBuffers, pEntry); }
  282. VOID
  283. CleanupThis( VOID);
  284. BOOL
  285. ReadWin32DirListing(IN LPCSTR pszDirectoryName,
  286. IN OUT DWORD * pcbMemUsed );
  287. BOOL
  288. BuildFileInfoPointers( IN OUT DWORD * pcbMemUsed );
  289. # if DBG
  290. VOID Print( VOID) const;
  291. #else
  292. VOID Print( VOID) const
  293. { ; }
  294. # endif // DBG
  295. private:
  296. HANDLE m_hListingUser;
  297. int m_nEntries;
  298. // contains array of pointers indirected into buffers in m_listDirBuffers
  299. PWIN32_FIND_DATA * m_ppFileInfo;
  300. LIST_ENTRY m_listDirectoryBuffers; // ptr to DIR_BUFFERS
  301. }; // class TS_DIRECTORY_HEADER
  302. typedef TS_DIRECTORY_HEADER * PTS_DIRECTORY_HEADER;
  303. //
  304. // Virtual roots and directories always have their trailing slashes
  305. // stripped. This macro is used disambiguate the "/root1/" from "/root/"
  306. // case where "/root/" is an existing root (i.e., matching prefix).
  307. //
  308. extern BOOL
  309. IsCharTermA(
  310. IN LPCSTR lpszString,
  311. IN INT cch
  312. );
  313. #define IS_CHAR_TERM_A( psz, cch ) IsCharTermA(psz,cch)
  314. extern
  315. dllexp
  316. BOOL
  317. TsGetDirectoryListing(
  318. IN const TSVC_CACHE &TSvcCache,
  319. IN PCSTR pszDirectoryName,
  320. IN HANDLE ListingUser,
  321. OUT PTS_DIRECTORY_HEADER* ppDirectoryHeader
  322. );
  323. extern
  324. dllexp
  325. BOOL
  326. TsFreeDirectoryListing
  327. (
  328. IN const TSVC_CACHE & TSvcCache,
  329. IN OUT PTS_DIRECTORY_HEADER pTsDirectoryHeader
  330. );
  331. extern
  332. BOOL
  333. SortInPlaceFileInfoPointers(
  334. IN OUT PWIN32_FIND_DATA * prgFileInfo,
  335. IN int nFiles,
  336. IN PFN_CMP_WIN32_FIND_DATA pfnCompare
  337. );
  338. extern
  339. BOOL
  340. RegExpressionMatch( IN LPCSTR pszName, IN LPCSTR pszRegExp);
  341. #pragma hdrstop
  342. #endif // _TSUNAMIP_HXX_