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.

92 lines
2.3 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1994 **/
  4. /**********************************************************************/
  5. /*
  6. filehash.hxx
  7. This module defines the classes used for storing TS_OPEN_FILE_INFO
  8. objects in a hash table.
  9. FILE HISTORY:
  10. MCourage 09-Dec-1997 Created
  11. */
  12. #ifndef __FILEHASH_HXX__
  13. #define __FILEHASH_HXX__
  14. #include <lkrhash.h>
  15. #include <mbstring.h>
  16. #include <tsunami.hxx>
  17. #include <dbgutil.h>
  18. extern VOID I_DerefFileInfo(TS_OPEN_FILE_INFO *pOpenFile);
  19. // Moved to tsunami.hxx
  20. //
  21. // class CFileKey {
  22. // public:
  23. // CHAR * m_pszFileName; // The file name in upper-case
  24. // DWORD m_cbFileName; // The number of bytes in the file name
  25. // };
  26. class CFileHashTable
  27. : public CTypedHashTable<CFileHashTable, TS_OPEN_FILE_INFO, const CFileKey*>
  28. {
  29. public:
  30. CFileHashTable(
  31. LPCSTR pszName)
  32. : CTypedHashTable<CFileHashTable, TS_OPEN_FILE_INFO, const CFileKey*>(
  33. pszName)
  34. {}
  35. static const CFileKey *
  36. ExtractKey(const TS_OPEN_FILE_INFO *pOpenFile)
  37. {
  38. return pOpenFile->GetKey();
  39. }
  40. static DWORD
  41. CalcKeyHash(const CFileKey * fileKey)
  42. {
  43. DBG_ASSERT( NULL != fileKey );
  44. const CHAR * psz = fileKey->m_pszFileName;
  45. if (fileKey->m_cbFileName > 80)
  46. psz += fileKey->m_cbFileName - 80;
  47. return HashString(psz, fileKey->m_cbFileName);
  48. }
  49. static bool
  50. EqualKeys(const CFileKey * fileKey1, const CFileKey * fileKey2)
  51. {
  52. if ((fileKey1->m_cbFileName == fileKey2->m_cbFileName) &&
  53. (memcmp(fileKey1->m_pszFileName,
  54. fileKey2->m_pszFileName,
  55. fileKey2->m_cbFileName) == 0)) {
  56. return TRUE;
  57. } else {
  58. return FALSE;
  59. }
  60. }
  61. static void
  62. AddRefRecord(TS_OPEN_FILE_INFO * pOpenFile, int nIncr)
  63. {
  64. DBG_ASSERT( nIncr == +1 || nIncr == -1 );
  65. if (nIncr == +1) {
  66. pOpenFile->AddRef();
  67. } else {
  68. I_DerefFileInfo(pOpenFile);
  69. }
  70. }
  71. };
  72. #endif // __FILEHASH_HXX__