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.

202 lines
6.2 KiB

  1. //
  2. // REGFINFO.H
  3. //
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. #ifndef _REGFINFO_
  7. #define _REGFINFO_
  8. #define PAGESHIFT 12
  9. #define PAGESIZE (1 << PAGESHIFT)
  10. #define PAGEMASK (PAGESIZE - 1)
  11. #define KEYNODE_BLOCK_SHIFT 10
  12. #define KEYNODES_PER_BLOCK (1 << KEYNODE_BLOCK_SHIFT)
  13. #define KEYNODE_BLOCK_MASK (KEYNODES_PER_BLOCK-1)
  14. #define KEYNODES_PER_PAGE (PAGESIZE / sizeof(KEYNODE))
  15. #define KN_INDEX_IN_BLOCK(i) ((i) & KEYNODE_BLOCK_MASK)
  16. #define KN_BLOCK_NUMBER(i) ((UINT) ((i) >> KEYNODE_BLOCK_SHIFT))
  17. typedef struct _KEYNODE_BLOCK {
  18. KEYNODE aKN[KEYNODES_PER_BLOCK];
  19. } KEYNODE_BLOCK, FAR* LPKEYNODE_BLOCK;
  20. #define KEYNODES_PER_PAGE (PAGESIZE / sizeof(KEYNODE))
  21. typedef struct _W95KEYNODE_BLOCK {
  22. W95KEYNODE aW95KN[KEYNODES_PER_BLOCK];
  23. } W95KEYNODE_BLOCK, FAR* LPW95KEYNODE_BLOCK;
  24. typedef struct _KEYNODE_BLOCK_INFO {
  25. LPKEYNODE_BLOCK lpKeynodeBlock;
  26. BYTE Flags; // KBDF_* bits
  27. BYTE LockCount;
  28. } KEYNODE_BLOCK_INFO, FAR* LPKEYNODE_BLOCK_INFO;
  29. #define KBIF_ACCESSED 0x01 // Recently accessed
  30. #define KBIF_DIRTY 0x02 // Must rewrite to disk
  31. // Number of extra KEYNODE_BLOCK_INFO structures to alloc on top of the block
  32. // count already in the file. Reduces heap fragmentation in real-mode.
  33. #define KEYNODE_BLOCK_INFO_SLACK_ALLOC 4
  34. #ifdef WIN32
  35. typedef UINT KEY_RECORD_TABLE_ENTRY;
  36. #else
  37. typedef WORD KEY_RECORD_TABLE_ENTRY;
  38. #endif
  39. typedef KEY_RECORD_TABLE_ENTRY FAR* LPKEY_RECORD_TABLE_ENTRY;
  40. #define NULL_KEY_RECORD_TABLE_ENTRY ((KEY_RECORD_TABLE_ENTRY) 0)
  41. #define IsNullKeyRecordTableEntry(kri) ((kri) == NULL_KEY_RECORD_TABLE_ENTRY)
  42. typedef struct _DATABLOCK_INFO {
  43. LPDATABLOCK_HEADER lpDatablockHeader;
  44. LPKEY_RECORD_TABLE_ENTRY lpKeyRecordTable;
  45. UINT BlockSize; // cached from datablock header
  46. UINT FreeBytes; // cached from datablock header
  47. UINT FirstFreeIndex; // cached from datablock header
  48. LONG FileOffset;
  49. BYTE Flags; // DIF_* bits
  50. BYTE LockCount;
  51. } DATABLOCK_INFO, FAR* LPDATABLOCK_INFO;
  52. #define DIF_PRESENT 0x01 // In memory
  53. #define DIF_ACCESSED 0x02 // Recently accessed
  54. #define DIF_DIRTY 0x04 // Must rewrite to disk
  55. #define DIF_EXTENDED 0x08 // Has grown in size
  56. // Number of extra DATABLOCK_INFO structures to alloc on top of the block count
  57. // already in the file. Reduces heap fragmentation in real-mode.
  58. #define DATABLOCK_INFO_SLACK_ALLOC 4
  59. // When we create or extend a datablock, try to keep it on page boundaries.
  60. #define DATABLOCK_GRANULARITY 4096
  61. #define RgAlignBlockSize(size) \
  62. (((size) + (DATABLOCK_GRANULARITY - 1)) & ~(DATABLOCK_GRANULARITY - 1))
  63. typedef struct _FILE_INFO {
  64. struct _FILE_INFO FAR* lpNextFileInfo;
  65. #ifdef WANT_HIVE_SUPPORT
  66. struct _HIVE_INFO FAR* lpHiveInfoList;
  67. #endif
  68. #ifdef WANT_NOTIFY_CHANGE_SUPPORT
  69. #ifdef WANT_HIVE_SUPPORT
  70. struct _FILE_INFO FAR* lpParentFileInfo;
  71. #endif
  72. struct _NOTIFY_CHANGE FAR* lpNotifyChangeList;
  73. #endif
  74. LPKEYNODE_BLOCK_INFO lpKeynodeBlockInfo;
  75. UINT KeynodeBlockCount;
  76. UINT KeynodeBlockInfoAllocCount;
  77. DWORD CurTotalKnSize; // Normally = to FileKnSize unless grown
  78. LPDATABLOCK_INFO lpDatablockInfo;
  79. UINT DatablockInfoAllocCount;
  80. FILE_HEADER FileHeader;
  81. KEYNODE_HEADER KeynodeHeader;
  82. WORD Flags; // FI_* bits
  83. char FileName[ANYSIZE_ARRAY];
  84. } FILE_INFO, FAR* LPFILE_INFO;
  85. #define FI_DIRTY 0x0001 // Must rewrite to disk
  86. #define FI_KEYNODEDIRTY 0x0002 //
  87. #define FI_EXTENDED 0x0004 //
  88. #define FI_VERSION20 0x0008 //
  89. #define FI_FLUSHING 0x0010 // Currently flushing file
  90. #define FI_SWEEPING 0x0020 // Currently sweeping file
  91. #define FI_VOLATILE 0x0040 // File has no backing store
  92. #define FI_READONLY 0x0080 // File cannot be modified
  93. #define FI_REPLACEMENTEXISTS 0x0100 // RegReplaceKey called on file
  94. typedef struct _HIVE_INFO {
  95. struct _HIVE_INFO FAR* lpNextHiveInfo;
  96. LPFILE_INFO lpFileInfo;
  97. UINT NameLength;
  98. BYTE Hash;
  99. char Name[ANYSIZE_ARRAY];
  100. } HIVE_INFO, FAR* LPHIVE_INFO;
  101. #define CFIN_PRIMARY 0x0000 // FHT_PRIMARY header type
  102. #define CFIN_SECONDARY 0x0001 // FHT_SECONDARY header type
  103. #define CFIN_VOLATILE 0x0002 // File has no backing store
  104. #define CFIN_VERSION20 0x0004 // Use compact keynode form
  105. int
  106. INTERNAL
  107. RgCreateFileInfoNew(
  108. LPFILE_INFO FAR* lplpFileInfo,
  109. LPCSTR lpFileName,
  110. UINT Flags
  111. );
  112. int
  113. INTERNAL
  114. RgCreateFileInfoExisting(
  115. LPFILE_INFO FAR* lplpFileInfo,
  116. LPCSTR lpFileName
  117. );
  118. int
  119. INTERNAL
  120. RgInitRootKeyFromFileInfo(
  121. HKEY hKey
  122. );
  123. int
  124. INTERNAL
  125. RgDestroyFileInfo(
  126. LPFILE_INFO lpFileInfo
  127. );
  128. int
  129. INTERNAL
  130. RgFlushFileInfo(
  131. LPFILE_INFO lpFileInfo
  132. );
  133. int
  134. INTERNAL
  135. RgSweepFileInfo(
  136. LPFILE_INFO lpFileInfo
  137. );
  138. typedef int (INTERNAL* LPENUMFILEINFOPROC)(LPFILE_INFO);
  139. VOID
  140. INTERNAL
  141. RgEnumFileInfos(
  142. LPENUMFILEINFOPROC lpEnumFileInfoProc
  143. );
  144. #define RgIndexKeynodeBlockInfoPtr(lpfi, index) \
  145. ((LPKEYNODE_BLOCK_INFO) (&(lpfi)-> lpKeynodeBlockInfo[index]))
  146. #define RgIndexDatablockInfoPtr(lpfi, index) \
  147. ((LPDATABLOCK_INFO) (&(lpfi)-> lpDatablockInfo[index]))
  148. #define RgIndexKeyRecordPtr(lpdi, index) \
  149. ((LPKEY_RECORD) ((LPBYTE)(lpdi)-> lpDatablockHeader + (lpdi)-> lpKeyRecordTable[(index)]))
  150. BOOL
  151. INTERNAL
  152. RgIsValidFileHeader(
  153. LPFILE_HEADER lpFileHeader
  154. );
  155. BOOL
  156. INTERNAL
  157. RgIsValidKeynodeHeader(
  158. LPKEYNODE_HEADER lpKeynodeHeader
  159. );
  160. BOOL
  161. INTERNAL
  162. RgIsValidDatablockHeader(
  163. LPDATABLOCK_HEADER lpDatablockHeader
  164. );
  165. extern LPFILE_INFO g_RgFileInfoList;
  166. #endif // _REGFINFO_