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.

514 lines
9.8 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. hive.h
  5. Abstract:
  6. This module contains the private (internal) header file for the
  7. direct memory loaded hive manager.
  8. Author:
  9. Bryan M. Willman (bryanwi) 28-May-91
  10. Environment:
  11. Revision History:
  12. 26-Mar-92 bryanwi - changed to type 1.0 hive format
  13. 13-Jan-99 Dragos C. Sambotin (dragoss) - factoring the data structure declarations
  14. in \nt\private\ntos\inc\hivedata.h :: to be available from outside.
  15. --*/
  16. #ifndef _HIVE_
  17. #define _HIVE_
  18. // Hive data structure declarations
  19. // file location: \nt\private\ntos\inc
  20. #include "hivedata.h"
  21. #if DBG
  22. extern ULONG HvHiveChecking;
  23. #define DHvCheckHive(a) if(HvHiveChecking) ASSERT(HvCheckHive(a,NULL) == 0)
  24. #define DHvCheckBin(h,a) if(HvHiveChecking) ASSERT(HvCheckBin(h,a,NULL) == 0)
  25. #else
  26. #define DHvCheckHive(a)
  27. #define DHvCheckBin(h,a)
  28. #endif
  29. #define ROUND_UP(a, b) \
  30. ( ((ULONG)(a) + (ULONG)(b) - 1) & ~((ULONG)(b) - 1) )
  31. //
  32. // tombstone for an HBIN that is not resident in memory. This list is searched
  33. // before any new HBIN is added.
  34. //
  35. #define ASSERT_LISTENTRY(ListEntry) \
  36. ASSERT((ListEntry)->Flink->Blink==ListEntry); \
  37. ASSERT((ListEntry)->Blink->Flink==ListEntry);
  38. //
  39. // ===== Hive Private Procedure Prototypes =====
  40. //
  41. PHBIN
  42. HvpAddBin(
  43. PHHIVE Hive,
  44. ULONG NewSize,
  45. HSTORAGE_TYPE Type
  46. );
  47. PHMAP_ENTRY
  48. HvpGetCellMap(
  49. PHHIVE Hive,
  50. HCELL_INDEX Cell
  51. );
  52. VOID
  53. HvpFreeMap(
  54. PHHIVE Hive,
  55. PHMAP_DIRECTORY Dir,
  56. ULONG Start,
  57. ULONG End
  58. );
  59. BOOLEAN
  60. HvpAllocateMap(
  61. PHHIVE Hive,
  62. PHMAP_DIRECTORY Dir,
  63. ULONG Start,
  64. ULONG End
  65. );
  66. BOOLEAN
  67. HvpGrowLog1(
  68. PHHIVE Hive,
  69. ULONG Count
  70. );
  71. BOOLEAN
  72. HvpGrowLog2(
  73. PHHIVE Hive,
  74. ULONG Size
  75. );
  76. ULONG
  77. HvpHeaderCheckSum(
  78. PHBASE_BLOCK BaseBlock
  79. );
  80. NTSTATUS
  81. HvpBuildMap(
  82. PHHIVE Hive,
  83. PVOID Image
  84. );
  85. NTSTATUS
  86. HvpBuildMapAndCopy(
  87. PHHIVE Hive,
  88. PVOID Image
  89. );
  90. NTSTATUS
  91. HvpInitMap(
  92. PHHIVE Hive
  93. );
  94. VOID
  95. HvpCleanMap(
  96. PHHIVE Hive
  97. );
  98. NTSTATUS
  99. HvpEnlistBinInMap(
  100. PHHIVE Hive,
  101. ULONG Length,
  102. PHBIN Bin,
  103. ULONG Offset,
  104. PVOID CmView OPTIONAL
  105. );
  106. VOID
  107. HvpFreeAllocatedBins(
  108. PHHIVE Hive
  109. );
  110. BOOLEAN
  111. HvpDoWriteHive(
  112. PHHIVE Hive,
  113. ULONG FileType
  114. );
  115. struct _CELL_DATA *
  116. HvpGetCellFlat(
  117. PHHIVE Hive,
  118. HCELL_INDEX Cell
  119. );
  120. struct _CELL_DATA *
  121. HvpGetCellPaged(
  122. PHHIVE Hive,
  123. HCELL_INDEX Cell
  124. );
  125. struct _CELL_DATA *
  126. HvpGetCellMapped(
  127. PHHIVE Hive,
  128. HCELL_INDEX Cell
  129. );
  130. VOID
  131. HvpReleaseCellMapped(
  132. PHHIVE Hive,
  133. HCELL_INDEX Cell
  134. );
  135. VOID
  136. HvpEnlistFreeCell(
  137. PHHIVE Hive,
  138. HCELL_INDEX Cell,
  139. ULONG Size,
  140. HSTORAGE_TYPE Type,
  141. BOOLEAN CoalesceForward
  142. );
  143. BOOLEAN
  144. HvpEnlistFreeCells(
  145. PHHIVE Hive,
  146. PHBIN Bin,
  147. ULONG BinOffset
  148. );
  149. VOID
  150. HvpDelistFreeCell(
  151. PHHIVE Hive,
  152. HCELL_INDEX Cell,
  153. HSTORAGE_TYPE Type
  154. );
  155. //
  156. // ===== Hive Public Procedure Prototypes =====
  157. //
  158. #define HINIT_CREATE 0
  159. #define HINIT_MEMORY 1
  160. #define HINIT_FILE 2
  161. #define HINIT_MEMORY_INPLACE 3
  162. #define HINIT_FLAT 4
  163. #define HINIT_MAPFILE 5
  164. #define HIVE_VOLATILE 1
  165. #define HIVE_NOLAZYFLUSH 2
  166. #define HIVE_HAS_BEEN_REPLACED 4
  167. NTSTATUS
  168. HvInitializeHive(
  169. PHHIVE Hive,
  170. ULONG OperationType,
  171. ULONG HiveFlags,
  172. ULONG FileTypes,
  173. PVOID HiveData OPTIONAL,
  174. PALLOCATE_ROUTINE AllocateRoutine,
  175. PFREE_ROUTINE FreeRoutine,
  176. PFILE_SET_SIZE_ROUTINE FileSetSizeRoutine,
  177. PFILE_WRITE_ROUTINE FileWriteRoutine,
  178. PFILE_READ_ROUTINE FileReadRoutine,
  179. PFILE_FLUSH_ROUTINE FileFlushRoutine,
  180. ULONG Cluster,
  181. PUNICODE_STRING FileName
  182. );
  183. BOOLEAN
  184. HvSyncHive(
  185. PHHIVE Hive
  186. );
  187. NTSTATUS
  188. HvWriteHive(
  189. PHHIVE Hive,
  190. BOOLEAN DontGrow,
  191. BOOLEAN WriteThroughCache,
  192. BOOLEAN CrashSafe
  193. );
  194. NTSTATUS
  195. HvLoadHive(
  196. PHHIVE Hive
  197. );
  198. NTSTATUS
  199. HvMapHive(
  200. PHHIVE Hive
  201. );
  202. VOID
  203. HvRefreshHive(
  204. PHHIVE Hive
  205. );
  206. NTSTATUS
  207. HvReadInMemoryHive(
  208. PHHIVE Hive,
  209. PVOID *HiveImage
  210. );
  211. ULONG
  212. HvCheckHive(
  213. PHHIVE Hive,
  214. PULONG Storage OPTIONAL
  215. );
  216. ULONG
  217. HvCheckBin(
  218. PHHIVE Hive,
  219. PHBIN Bin,
  220. PULONG Storage
  221. );
  222. ULONG
  223. HvpGetBinMemAlloc(
  224. IN PHHIVE Hive,
  225. PHBIN Bin,
  226. IN HSTORAGE_TYPE Type
  227. );
  228. BOOLEAN
  229. HvMarkCellDirty(
  230. PHHIVE Hive,
  231. HCELL_INDEX Cell
  232. );
  233. #if DBG
  234. BOOLEAN
  235. HvIsCellDirty(
  236. IN PHHIVE Hive,
  237. IN HCELL_INDEX Cell
  238. );
  239. #ifndef _CM_LDR_
  240. #define ASSERT_CELL_DIRTY(_Hive_,_Cell_) ASSERT(HvIsCellDirty(_Hive_,_Cell_) == TRUE)
  241. #else
  242. #define ASSERT_CELL_DIRTY(_Hive_,_Cell_) // nothing
  243. #endif //_CM_LDR_
  244. #else
  245. #define ASSERT_CELL_DIRTY(_Hive_,_Cell_) // nothing
  246. #endif //DBG
  247. BOOLEAN
  248. HvMarkDirty(
  249. PHHIVE Hive,
  250. HCELL_INDEX Start,
  251. ULONG Length,
  252. BOOLEAN DirtyAndPin
  253. );
  254. /*
  255. !!!not used anymore!!!
  256. BOOLEAN
  257. HvMarkClean(
  258. PHHIVE Hive,
  259. HCELL_INDEX Start,
  260. ULONG Length
  261. );
  262. */
  263. //
  264. // IMPORTANT:
  265. // Every call to HvGetCell should be matched with a call to HvReleaseCell;
  266. // HvReleaseCell is only valid for mapped hives.
  267. //
  268. #define HvGetCell(Hive, Cell) (((Hive)->GetCellRoutine)(Hive, Cell))
  269. #define HvReleaseCell(Hive, Cell) if((Hive)->ReleaseCellRoutine) ((Hive)->ReleaseCellRoutine)(Hive, Cell)
  270. PHCELL
  271. HvpGetHCell(PHHIVE Hive,
  272. HCELL_INDEX Cell
  273. );
  274. LONG
  275. HvGetCellSize(
  276. PHHIVE Hive,
  277. PVOID Address
  278. );
  279. HCELL_INDEX
  280. HvAllocateCell(
  281. PHHIVE Hive,
  282. ULONG NewSize,
  283. HSTORAGE_TYPE Type,
  284. HCELL_INDEX Vicinity
  285. );
  286. VOID
  287. HvFreeCell(
  288. PHHIVE Hive,
  289. HCELL_INDEX Cell
  290. );
  291. HCELL_INDEX
  292. HvReallocateCell(
  293. PHHIVE Hive,
  294. HCELL_INDEX Cell,
  295. ULONG NewSize
  296. );
  297. BOOLEAN
  298. HvIsCellAllocated(
  299. PHHIVE Hive,
  300. HCELL_INDEX Cell
  301. );
  302. VOID
  303. HvFreeHive(
  304. PHHIVE Hive
  305. );
  306. VOID
  307. HvFreeHivePartial(
  308. PHHIVE Hive,
  309. HCELL_INDEX Start,
  310. HSTORAGE_TYPE Type
  311. );
  312. // Dragos : From here start the changes.
  313. #define CmpFindFirstSetRight KiFindFirstSetRight
  314. extern const CCHAR KiFindFirstSetRight[256];
  315. #define CmpFindFirstSetLeft KiFindFirstSetLeft
  316. extern const CCHAR KiFindFirstSetLeft[256];
  317. #define HvpComputeIndex(Index, Size) \
  318. { \
  319. Index = (Size >> HHIVE_FREE_DISPLAY_SHIFT) - 1; \
  320. if (Index >= HHIVE_LINEAR_INDEX ) { \
  321. \
  322. /* \
  323. ** Too big for the linear lists, compute the exponential \
  324. ** list. Shitft the index to make sure we cover the whole \
  325. ** range. \
  326. */ \
  327. Index >>= 4; \
  328. \
  329. if (Index > 255) { \
  330. /* \
  331. ** Too big for all the lists, use the last index. \
  332. */ \
  333. Index = HHIVE_FREE_DISPLAY_SIZE-1; \
  334. } else { \
  335. Index = CmpFindFirstSetLeft[Index] + \
  336. HHIVE_LINEAR_INDEX; \
  337. } \
  338. } \
  339. }
  340. VOID
  341. HvpFreeHiveFreeDisplay(
  342. IN PHHIVE Hive
  343. );
  344. NTSTATUS
  345. HvpAdjustHiveFreeDisplay(
  346. IN PHHIVE Hive,
  347. IN ULONG HiveLength,
  348. IN HSTORAGE_TYPE Type
  349. );
  350. VOID
  351. HvpAddFreeCellHint(
  352. PHHIVE Hive,
  353. HCELL_INDEX Cell,
  354. ULONG Index,
  355. HSTORAGE_TYPE Type
  356. );
  357. VOID
  358. HvpRemoveFreeCellHint(
  359. PHHIVE Hive,
  360. HCELL_INDEX Cell,
  361. ULONG Index,
  362. HSTORAGE_TYPE Type
  363. );
  364. HCELL_INDEX
  365. HvpFindFreeCell(
  366. PHHIVE Hive,
  367. ULONG Index,
  368. ULONG NewSize,
  369. HSTORAGE_TYPE Type,
  370. HCELL_INDEX Vicinity
  371. );
  372. BOOLEAN
  373. HvpCheckViewBoundary(
  374. IN ULONG Start,
  375. IN ULONG End
  376. );
  377. VOID
  378. HvpDropPagedBins(
  379. PHHIVE Hive
  380. #if DBG
  381. ,
  382. IN BOOLEAN Check
  383. #endif
  384. );
  385. VOID
  386. HvpDropAllPagedBins(
  387. IN PHHIVE Hive
  388. );
  389. BOOLEAN
  390. HvpWriteLog(
  391. PHHIVE Hive
  392. );
  393. BOOLEAN
  394. HvHiveWillShrink(
  395. IN PHHIVE Hive
  396. );
  397. BOOLEAN HvAutoCompressCheck(PHHIVE Hive);
  398. NTSTATUS
  399. HvCloneHive(PHHIVE SourceHive,
  400. PHHIVE DestHive,
  401. PULONG NewLength
  402. );
  403. NTSTATUS
  404. HvShrinkHive(PHHIVE Hive,
  405. ULONG NewLength
  406. );
  407. HCELL_INDEX
  408. HvShiftCell(PHHIVE Hive,HCELL_INDEX Cell);
  409. #ifdef NT_RENAME_KEY
  410. HCELL_INDEX
  411. HvDuplicateCell(
  412. PHHIVE Hive,
  413. HCELL_INDEX Cell,
  414. HSTORAGE_TYPE Type,
  415. BOOLEAN CopyData
  416. );
  417. #endif
  418. #ifdef CM_ENABLE_WRITE_ONLY_BINS
  419. VOID HvpMarkAllBinsWriteOnly(IN PHHIVE Hive);
  420. #endif //CM_ENABLE_WRITE_ONLY_BINS
  421. #endif // _HIVE_