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.

169 lines
4.5 KiB

  1. /******************************************************************************
  2. *
  3. * Copyright (c) 1999 Microsoft Corporation
  4. *
  5. * Module Name:
  6. * hashlist.h
  7. *
  8. * Abstract:
  9. * This file contains the implementation for hashlist.
  10. *
  11. * Revision History:
  12. * Kanwaljit S Marok ( kmarok ) 05/17/99
  13. * created
  14. *
  15. *****************************************************************************/
  16. #ifndef _HASHED_LIST_H_
  17. #define _HASHED_LIST_H_
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #include "common.h"
  22. #ifdef RING3
  23. #include <nt.h>
  24. #include <ntrtl.h>
  25. #include <nturtl.h>
  26. #include <windows.h>
  27. #include <stdio.h>
  28. #endif
  29. //
  30. // Ordered List Structures
  31. //
  32. #define MAX_BUCKETS 1000
  33. #define MAX_EXT_LEN 256 // Length of extension PathElem
  34. #define SR_MAX_EXTENSION_CHARS 20
  35. #define SR_MAX_EXTENSION_LENGTH sizeof(UNICODE_STRING) + \
  36. ((SR_MAX_EXTENSION_CHARS + 1) * sizeof(WCHAR))
  37. typedef struct LIST_HEADER
  38. {
  39. DEFINE_BLOB_HEADER(); // Define common header for blob.
  40. DWORD m_dwDataOff ; // Offset for next available entry.
  41. DWORD m_iFreeNode ; // Next free node.
  42. DWORD m_iHashBuckets; // Number of hash buckets.
  43. } ListHeader;
  44. //
  45. // Hash list entry node.
  46. //
  47. typedef struct
  48. {
  49. INT m_iNext ; // Index to next sibling
  50. DWORD m_dwData ; // Offset for node data
  51. DWORD m_dwDataLen ; // Length of node data
  52. DWORD m_dwType ; // Node Type
  53. } ListEntry;
  54. //
  55. // Ordered List related macros
  56. //
  57. #define LIST_HEADER(pList) ( (ListHeader*) pList )
  58. #define LIST_CURRDATAOFF(pList) ( LIST_HEADER(pList)->m_dwDataOff )
  59. #define LIST_NODES(pList) ( (ListEntry*) ( \
  60. (BYTE*)pList + \
  61. sizeof(ListHeader)+ \
  62. LIST_HEADER(pList)->m_iHashBuckets * sizeof(DWORD))\
  63. )
  64. #define LIST_NODEPTR(pList, iNode) ( LIST_NODES(pList) + iNode)
  65. #define LIST_HASHARR(pList) ( (DWORD *) \
  66. ((BYTE*)pList + \
  67. sizeof(ListHeader)) \
  68. )
  69. #define STR_BYTES( pEntry ) (INT)(pEntry->m_dwDataLen - sizeof(USHORT))
  70. //
  71. // Hashing related inline functions / macros
  72. //
  73. #define HASH_BUCKET(pList, iHash) \
  74. ( LIST_HASHARR(pList)[ iHash ] )
  75. static __inline INT
  76. CALC_LIST_SIZE(
  77. DWORD dwMaxBuckets,
  78. DWORD dwMaxNodes ,
  79. DWORD dwDataSize )
  80. {
  81. INT iSize = sizeof(ListHeader) +
  82. (dwMaxNodes + 1) * sizeof(ListEntry) +
  83. dwDataSize;
  84. if ( dwMaxBuckets > MAX_BUCKETS )
  85. iSize += (MAX_BUCKETS*sizeof(DWORD));
  86. else
  87. iSize += (dwMaxBuckets*sizeof(DWORD));
  88. return iSize;
  89. }
  90. static __inline INT HASH(BYTE * pList, PathElement * pe)
  91. {
  92. unsigned long g, h = 0;
  93. INT i;
  94. INT cbChars = (pe->pe_length / sizeof(USHORT)) - 1;
  95. USHORT * pStr = pe->pe_unichars;
  96. for( i = 0; i < cbChars; i++ )
  97. {
  98. h = ( h << 4 ) + *pStr++;
  99. if ( g = h & 0xF0000000 ) h ^= g >> 24;
  100. h &= ~g;
  101. }
  102. return (h % LIST_HEADER(pList)->m_iHashBuckets);
  103. }
  104. static __inline INT HASHSTR(PBYTE pList, LPWSTR pStr, USHORT Size)
  105. {
  106. INT i;
  107. unsigned long g, h = 0;
  108. USHORT NumChars = Size/sizeof(WCHAR);
  109. for( i = 0; i < NumChars; i++ )
  110. {
  111. h = ( h << 4 ) + *pStr++;
  112. if ( g = h & 0xF0000000 ) h ^= g >> 24;
  113. h &= ~g;
  114. }
  115. return (h % LIST_HEADER(pList)->m_iHashBuckets);
  116. }
  117. //
  118. // Function Prototypes.
  119. //
  120. BOOL
  121. MatchEntry(
  122. IN PBYTE pList, // Pointer to hash list
  123. IN LPWSTR pStr, // Pointer to unicode path string
  124. IN INT NumChars, // Number of unichars in path string
  125. OUT PINT pType ); // Pointer to variable returning ext type
  126. BOOL
  127. MatchExtension(
  128. IN PBYTE pList, // Pointer to hash list
  129. IN PUNICODE_STRING pPath, // Pointer to unicode path
  130. OUT PINT pType, // Pointer to node type
  131. OUT PBOOL pfHasExt ); // Pointer to BOOL var returning ext result
  132. #ifdef __cplusplus
  133. }
  134. #endif
  135. #endif _HASHED_LIST_H_