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.

743 lines
26 KiB

  1. //depot/main/Base/ntos/inc/hivedata.h#9 - integrate change 19035 (text)
  2. /*++
  3. Copyright (c) 1999 Microsoft Corporation
  4. Module Name:
  5. hivedata.h
  6. Abstract:
  7. This module contains data structures used by the
  8. direct memory loaded hive manager.
  9. Author:
  10. Dragos C. Sambotin (dragoss) 13-Jan-99
  11. Revision History:
  12. --*/
  13. #ifndef __HIVE_DATA__
  14. #define __HIVE_DATA__
  15. //
  16. // ===== Arbitrary Limits Imposed For Sanity =====
  17. //
  18. #define HSANE_CELL_MAX (1024*1024) // 1 megabyte max size for
  19. // a single cell
  20. //
  21. // ===== Tuning =====
  22. #define HBIN_THRESHOLD (HBLOCK_SIZE-512) // If less than threshold
  23. // bytes would be left in
  24. // bin, add another page
  25. #define HLOG_GROW HBLOCK_SIZE // Minimum size to grow log
  26. // by. Can set this up
  27. // if we think it thrashes.
  28. #define HCELL_BIG_ROUND (HBLOCK_SIZE*3) //
  29. // If someone tries to
  30. // allocate a very large
  31. // cell, round it up to
  32. // HBLOCK_SIZE. This is
  33. // the rather arbitrary
  34. // define for "very large"
  35. //
  36. //
  37. // Never shrink the log files smaller than this, this prevents people
  38. // from taking up all the disk space and then being unable to do
  39. // critical registry operations (like logging on to delete some files)
  40. //
  41. #define HLOG_MINSIZE(Hive) \
  42. ((Hive)->Cluster * HSECTOR_SIZE * 2)
  43. //
  44. // ===== Basic Structures and Definitions =====
  45. //
  46. // These are same whether on disk or in memory.
  47. //
  48. //
  49. // NOTE: Volatile == storage goes away at reboot
  50. // Stable == Persistent == Not Volatile
  51. //
  52. typedef enum {
  53. Stable = 0,
  54. Volatile = 1
  55. } HSTORAGE_TYPE;
  56. #define HTYPE_COUNT 2
  57. //
  58. // --- HCELL_INDEX ---
  59. //
  60. //
  61. // Handle to a cell -> effectively the "virtual" address of the cell,
  62. // HvMapCell converts this to a "real" address, that is, a memory
  63. // address. Mapping scheme is very much like that standard two level
  64. // page table. No mappings stored in file, they are built up when
  65. // the file is read in. (The INDEX in HCELL_INDEX is historical)
  66. //
  67. // Bit 31 30-21 20-12 11-0
  68. // +----------------------------+
  69. // | T | Table | Block | Offset |
  70. // +----------------------------+
  71. //
  72. // T = Type(1)= 0 for stable ("normal") storage
  73. // 1 for volatile storage
  74. //
  75. // Table(10) = Index into directory of mapping tables, selects a table.
  76. // Each mapping table is an array of HMAP_ENTRY structures.
  77. //
  78. // Block(9) = Index into Table, selects an HMAP_ENTRY. HMAP_ENTRY
  79. // contains address of area in memory that this HCELL_INDEX
  80. // maps to. (Base of memory copy of Block)
  81. //
  82. // Offset(12) = Offset within page, of the Cell header for the cell
  83. // of interest.
  84. //
  85. typedef ULONG HCELL_INDEX;
  86. typedef HCELL_INDEX *PHCELL_INDEX;
  87. #ifdef DRAGOSS_PRIVATE_DEBUG
  88. //#undef PAGE_SIZE
  89. //#define PAGE_SIZE 0x2000
  90. #endif //DRAGOSS_PRIVATE_DEBUG
  91. #define HCELL_NIL ((HCELL_INDEX)(-1))
  92. #define HCELL_TYPE_MASK 0x80000000
  93. #define HCELL_TYPE_SHIFT 31
  94. #define HCELL_TABLE_MASK 0x7fe00000
  95. #define HCELL_TABLE_SHIFT 21
  96. #define HCELL_BLOCK_MASK 0x001ff000
  97. #define HCELL_BLOCK_SHIFT 12
  98. #define HCELL_OFFSET_MASK 0x00000fff
  99. #define HBLOCK_SIZE 0x1000 // LOGICAL block size
  100. // This is the size of one of
  101. // the registry's logical/virtual
  102. // pages. It has no particular
  103. // relationship to page size
  104. // of the machine.
  105. #define HSECTOR_SIZE 0x200 // LOGICAL sector size
  106. #define HSECTOR_COUNT 8 // LOGICAL sectors / LOGICAL Block
  107. #define HSECTOR_PER_PAGE_COUNT (PAGE_SIZE / HSECTOR_SIZE) // LOGICAL sectors / Physical page
  108. #define HTABLE_SLOTS 512 // 9 bits of address
  109. #define HDIRECTORY_SLOTS 1024 // 10 bits of address
  110. #define HvGetCellType(Cell) ((ULONG)((Cell & HCELL_TYPE_MASK) >> HCELL_TYPE_SHIFT))
  111. //
  112. // --- HCELL --- an object within the hive (A bin is filled with HCELLs)
  113. //
  114. // Any given item of user data must fit within a single HCELL.
  115. // HCELLs cannot span Bins.
  116. //
  117. #define HCELL_PAD(Hive) ((Hive->Version>=2) ? 8 : 16)
  118. // All cells must be at least this large,
  119. // All allocations on this boundary
  120. #define HCELL_ALLOCATE_FILL 0xb2 // bz -> buzz buzz (yeah, it's a stretch)
  121. // must fill all newly allocated
  122. // cells for security reasons
  123. #define HCELL_FREE_FILL 0xfc // fc = HvFreeCell...
  124. //
  125. // Currently we support two cell formats, one with a Last backpointer (old version),
  126. // and one without (new version)
  127. //
  128. // All cells in a hive must be of the same type. Version 1 hives use the old version,
  129. // Version 2 or greater use the new version.
  130. //
  131. #define USE_OLD_CELL(Hive) (Hive->Version==1)
  132. typedef struct _HCELL {
  133. LONG Size;
  134. union {
  135. struct {
  136. ULONG Last;
  137. union {
  138. ULONG UserData;
  139. HCELL_INDEX Next; // offset of next element in freelist (not a FLink)
  140. } u;
  141. } OldCell;
  142. struct {
  143. union {
  144. ULONG UserData;
  145. HCELL_INDEX Next; // offset of next element in freelist (not a FLink)
  146. } u;
  147. } NewCell;
  148. } u;
  149. } HCELL, *PHCELL;
  150. //
  151. // --- HBIN --- is a contiguous set of HBLOCKs, filled with HCELLs.
  152. //
  153. #define HBIN_SIGNATURE 0x6e696268 // "hbin"
  154. #define HBIN_NIL (-1)
  155. #pragma pack(4)
  156. typedef struct _HBIN {
  157. ULONG Signature;
  158. ULONG FileOffset; // Own file offset (used in checking)
  159. ULONG Size; // Size of bin in bytes, all inclusive
  160. ULONG Reserved1[2]; // Old FreeSpace and FreeList (from 1.0)
  161. LARGE_INTEGER TimeStamp; // Old Link (from 1.0). Usually trash, but
  162. // first bin has valid value used for .log
  163. // correspondence testing, only meaningful
  164. // on disk.
  165. ULONG Spare; // this used to be MemAlloc. We don't use it anymore as we
  166. // can't afford to touch the bin (it's not residing in paged-pool
  167. // anymore, so touching it means modifying mnw pages).
  168. // Spare is used for the ShiftFreeBins Stuff - in memory only!
  169. //
  170. // Cell data goes here
  171. //
  172. } HBIN, *PHBIN;
  173. #pragma pack()
  174. //
  175. // ===== On Disk Structures =====
  176. //
  177. //
  178. // NOTE: Hive storage is always allocated in units of 4K. This size
  179. // must be used on all systems, regardless of page size, since
  180. // the file format needs to be transportable amoung systems.
  181. //
  182. // NOTE: The integrity code depends on certain blocks (e.g., the
  183. // BASE block) being at least as large as the size of a physical
  184. // sector. (Otherwise data that should be left alone will
  185. // be written because the FS has to block/deblock.) This means
  186. // that the current code will not work with sectors > 4K.
  187. //
  188. // NOTE: A hive on disk always contains at least two blocks of storage.
  189. // 1 block for the base block, and 1 for the minimum 1 bin.
  190. //
  191. // NOTE: Only modified parts of the hive get written to disk.
  192. // This is not just for efficiency, but also to avoid risk
  193. // of destruction of unlogged data. Dirty bits keep track
  194. // of what has been modified, they reside in a simple
  195. // bit map attached to the hive. One bit for each logical
  196. // sector of 512 bytes.
  197. //
  198. // If the physical sector size of the machine is less than 512,
  199. // no matter, we'll always write in clumps of 512. If the
  200. // physical sector size is greater than 512, we'll always clump
  201. // data together so that we log and write data
  202. // in chunks of that size. Physical sector sizes > 4K will
  203. // not work correctly (logging will not work right, so system
  204. // crashes may lose data that would not otherwise be lost.)
  205. //
  206. //
  207. // An on disk image of a hive looks like this:
  208. //
  209. // +---------------------------------------+
  210. // | HBASE_BLOCK | 1 Hive Block == 4K
  211. // | |
  212. // +---------------------------------------+ <- HBLOCK_SIZE boundary
  213. // | Bin - 1 to N 4K blocks |
  214. // | Each contains a signature, size, and |
  215. // | a boundary tag heap internal to |
  216. // | itself. Once allocated lives forever |
  217. // | and always at same file offset. |
  218. // +---------------------------------------+ <- HBLOCK_SIZE boundary
  219. // | Bin ... |
  220. // +---------------------------------------+ <- HBLOCK_SIZE boundary
  221. // ...
  222. // +---------------------------------------+ <- HBLOCK_SIZE boundary
  223. // | Last allocated Bin, new bins are put |
  224. // | immediately after this one. |
  225. // +---------------------------------------+ <- HBLOCK_SIZE boundary
  226. //
  227. // Hive files must allocate on HBLOCK_SIZE boundaries because they
  228. // might be written on many different systems, and must therefore be
  229. // set up for the largest cluster size we will support.
  230. //
  231. //
  232. // The log file format is:
  233. //
  234. // +-------------------------------+
  235. // | HBASE_BLOCK copy |
  236. // +-------------------------------+ <- cluster (usually 512) bound
  237. // | DirtyVector |
  238. // | (length computed from length |
  239. // | in the base block |
  240. // | (with "DIRT" on front as a |
  241. // | signature) |
  242. // +-------------------------------+ <- cluster (usually 512) bound
  243. // | Dirty Data |
  244. // +-------------------------------+ <- cluster (usually 512) bound
  245. // | Dirty Data |
  246. // +-------------------------------+ <- cluster (usually 512) bound
  247. // | ... |
  248. // +-------------------------------+
  249. //
  250. // Recovery consists of reading the file in, computing which clusters
  251. // of data are present from the dirtyvector, and where they belong in
  252. // the hive address space. Position in file is by sequential count.
  253. //
  254. // Logs can allocate on cluster boundaries (physical sector size of
  255. // host machine) because they will never be written on any machine other
  256. // than the one that created them.
  257. //
  258. // For log to be valid:
  259. //
  260. // Signature, format, major.minor must match expected values.
  261. // Sequence1 and Sequence2 must match.
  262. // CheckSum must be correct.
  263. // Signture on DirtyVector must be correct
  264. //
  265. // For log to be applicable:
  266. //
  267. // Sequence in log must match sequence in hive.
  268. // TimeStamp in log must match TimeStamp in hive.
  269. // Hive must be in mid-update state, or have bogus header.
  270. //
  271. //
  272. // --- HBASE_BLOCK --- on disk description of the hive
  273. //
  274. //
  275. // NOTE: HBASE_BLOCK must be >= the size of physical sector,
  276. // or integrity assumptions will be violated, and crash
  277. // recovery may not work.
  278. //
  279. #define HBASE_BLOCK_SIGNATURE 0x66676572 // "regf"
  280. #define HSYS_MAJOR 1 // Must match to read at all
  281. #define HSYS_MINOR 3
  282. #define HSYS_WHISTLER_BETA1 4 // Whistler Beta1 hives
  283. #define HSYS_WHISTLER 5 // normal Whistler hives
  284. #define HSYS_MINOR_SUPPORTED HSYS_WHISTLER // Must be <= to write, always
  285. // set up to writer's version.
  286. #define HBASE_FORMAT_MEMORY 1 // Direct memory load case
  287. #define HBASE_NAME_ALLOC 64 // 32 unicode chars
  288. //
  289. // Boot Type Loader <-> Kernel communication
  290. //
  291. #define HBOOT_NORMAL 0
  292. #define HBOOT_REPAIR 1
  293. #define HBOOT_BACKUP 2
  294. #define HBOOT_SELFHEAL 4
  295. #pragma pack(4)
  296. typedef struct _HBASE_BLOCK {
  297. ULONG Signature;
  298. ULONG Sequence1;
  299. ULONG Sequence2;
  300. LARGE_INTEGER TimeStamp;
  301. ULONG Major;
  302. ULONG Minor;
  303. ULONG Type; // HFILE_TYPE_[PRIMARY|LOG]
  304. ULONG Format;
  305. HCELL_INDEX RootCell;
  306. ULONG Length; // Includes all but header
  307. ULONG Cluster; // for logs only
  308. UCHAR FileName[HBASE_NAME_ALLOC]; // filename tail
  309. ULONG Reserved1[99];
  310. ULONG CheckSum;
  311. ULONG Reserved2[128*7-2]; // subtract 2 for the volatile info
  312. ULONG BootType; // set by bootloader
  313. ULONG BootRecover; // set to 1 by bootloader if it did hive recovery
  314. // nobody else is using this
  315. } HBASE_BLOCK, *PHBASE_BLOCK;
  316. #pragma pack()
  317. #define HLOG_HEADER_SIZE (FIELD_OFFSET(HBASE_BLOCK, Reserved2))
  318. #define HLOG_DV_SIGNATURE 0x54524944 // "DIRT"
  319. //
  320. // ===== In Memory Structures =====
  321. //
  322. //
  323. // In memory image of a Hive looks just like the on-disk image,
  324. // EXCEPT that the HBIN structures can be spread throughout memory
  325. // rather than packed together.
  326. //
  327. // To find an HCELL in memory, a mechanism that takes an HCELL_INDEX and
  328. // derives a memory address from it is used. That mechanism is very
  329. // similar to a two level hardware paging table.
  330. //
  331. // A bit map is used to remember which parts of the hive are dirty.
  332. //
  333. // An HBLOCK can be in three different states
  334. // 1. Present in memory. BlockAddress and BinAddress are valid pointers.
  335. // This is the normal state of an HBLOCK.
  336. //
  337. // 2. Discardable. The HBIN containing this HBLOCK is completely free, but
  338. // the bin is dirty and needs to be written to the hive file before it
  339. // can be free. This is the state we will be in if somebody frees a
  340. // cell, causing the entire HBIN to become free. HvpEnlistFreeCell will
  341. // transition all the HBLOCKs in the free HBIN to this state, but will
  342. // not free their memory. After the dirty HBLOCKs are flushed to the
  343. // file, the memory will be freed.
  344. //
  345. // Note that if we need to allocate more storage from an HBIN in this
  346. // state, HvAllocateCell will simply change its state back to State 1
  347. // and it will be usable.
  348. //
  349. // An HBLOCK in this state has a valid BlockAddress and BinAddress, but
  350. // the HMAP_DISCARDABLE bit will be set.
  351. //
  352. // 3. Discarded. The HBIN containing this HBLOCK is completely free, and
  353. // is not dirty (i.e. it is marked as free in the hive file as well).
  354. // There is no memory allocated to contain this HBIN. After HvSyncHive
  355. // writes out an HBIN that is in State 2, it frees its pool and the
  356. // HBIN moves into this state.
  357. //
  358. // In order to use this HBIN, memory must be allocated to back it, and
  359. // the HBIN and initial HCELL must be recreated. (we could re-read it
  360. // from the hive file, but there's not much point in that since we know
  361. // that it is entirely free, so we might as well just recreate it and
  362. // save the disk i/o)
  363. //
  364. // An HBLOCK in this state has a NULL BlockAddress in the map.
  365. // The BinAddress will contain the next HCELL in the free list, so
  366. // we can reconstruct this when we need it.
  367. // The HMAP_NEWALLOC bit will be set for the first HBLOCK in the HBIN.
  368. //
  369. //
  370. // --- HMAP_ENTRY --- Holds memory location of HCELL
  371. //
  372. #define HMAP_FLAGS (0xf)
  373. #define HMAP_BASE (~(HMAP_FLAGS))
  374. #define HBIN_BASE(BinAddress) (BinAddress & HMAP_BASE)
  375. #define HBIN_FLAGS(BinAddress) (BinAddress & HMAP_FLAGS)
  376. #define HMAP_NEWALLOC 1 // the bin is the beginning of a new
  377. // allocation. When bin is in view this
  378. // doesn't really matter
  379. #define HMAP_DISCARDABLE 2 // bin is discardable (i.e. is all free)
  380. // first time when we get the chance we'll
  381. // free it (if it is in paged pool)
  382. #define HMAP_INVIEW 4 // bin is mapped in system cache
  383. #define HMAP_INPAGEDPOOL 8 // bin is allocated from paged pool
  384. #define BIN_MAP_ALLOCATION_TYPE(Me) (((Me)->BinAddress)&(HMAP_INPAGEDPOOL|HMAP_INVIEW))
  385. #define ASSERT_BIN_INVIEW(Me) ASSERT( ((Me)->BinAddress & HMAP_INVIEW) != 0 )
  386. #define ASSERT_BIN_INPAGEDPOOL(Me) ASSERT( ((Me)->BinAddress & HMAP_INPAGEDPOOL) != 0 )
  387. #define ASSERT_BIN_INVALID(Me) ASSERT( ((Me)->BinAddress & (HMAP_INPAGEDPOOL|HMAP_INVIEW)) == 0 )
  388. #define ASSERT_BIN_VALID(Me) ASSERT( ((Me)->BinAddress & (HMAP_INPAGEDPOOL|HMAP_INVIEW)) != 0 )
  389. struct _CM_VIEW_OF_FILE; //forward
  390. typedef struct _HMAP_ENTRY {
  391. ULONG_PTR BlockAddress; // Low 2 bits always 0. High bits
  392. // are memory address of HBLOCK that
  393. // HCELL starts in, add Offset to this.
  394. // (An HCELL can span several HBLOCKs)
  395. //
  396. ULONG_PTR BinAddress; // Low bit set TRUE to mark beginning
  397. // of a new allocation.
  398. // High bits are memory address of
  399. // first HBLOCK in same bin.
  400. // (A given HCELL is always contained
  401. // in a single bin.)
  402. // Dragos: From here start the changes!!!
  403. struct _CM_VIEW_OF_FILE *CmView; // pointer to the view; NULL when bin is not mapped
  404. ULONG MemAlloc; // we needed to move this from the bin header to the map, in
  405. // order to prevent the bin from being touched
  406. /*
  407. We don't really need this. Left just as a comment
  408. ULONG Flags; // tells if a bin is mapped through
  409. // a view, is allocated from paged pool
  410. // or is unmapped/unallocated
  411. ULONG_PTR MappedAddress; // temporary address inside the mapped view.
  412. */
  413. } HMAP_ENTRY, *PHMAP_ENTRY;
  414. //
  415. // --- HMAP_TABLE --- Array of MAP_ENTRYs that point to memory HBLOCKs
  416. //
  417. // Each HBLOCK worth of space in the Hive image has an entry in
  418. // an HMAP_TABLE.
  419. //
  420. typedef struct _HMAP_TABLE {
  421. HMAP_ENTRY Table[ HTABLE_SLOTS ];
  422. } HMAP_TABLE, *PHMAP_TABLE;
  423. //
  424. // --- HMAP_DIRECTORY --- Array of pointers to HMAP_TABLEs
  425. //
  426. typedef struct _HMAP_DIRECTORY {
  427. PHMAP_TABLE Directory[ HDIRECTORY_SLOTS ];
  428. } HMAP_DIRECTORY, *PHMAP_DIRECTORY;
  429. //
  430. // ===== Hive Routines typedefs =====
  431. //
  432. struct _HHIVE; // forward
  433. typedef
  434. PVOID
  435. (*PALLOCATE_ROUTINE) (
  436. ULONG Length, // Size of new block wanted
  437. BOOLEAN UseForIo, // TRUE if yes, FALSE if no
  438. ULONG Tag
  439. );
  440. typedef
  441. VOID
  442. (*PFREE_ROUTINE) (
  443. PVOID MemoryBlock,
  444. ULONG GlobalQuotaSize
  445. );
  446. typedef
  447. BOOLEAN
  448. (*PFILE_SET_SIZE_ROUTINE) (
  449. struct _HHIVE *Hive,
  450. ULONG FileType,
  451. ULONG FileSize,
  452. ULONG OldFileSize
  453. );
  454. typedef struct {
  455. ULONG FileOffset;
  456. PVOID DataBuffer;
  457. ULONG DataLength;
  458. } CMP_OFFSET_ARRAY, * PCMP_OFFSET_ARRAY;
  459. typedef
  460. BOOLEAN
  461. (*PFILE_WRITE_ROUTINE) (
  462. struct _HHIVE *Hive,
  463. ULONG FileType,
  464. PCMP_OFFSET_ARRAY offsetArray,
  465. ULONG offsetArrayCount,
  466. PULONG FileOffset
  467. );
  468. typedef
  469. BOOLEAN
  470. (*PFILE_READ_ROUTINE) (
  471. struct _HHIVE *Hive,
  472. ULONG FileType,
  473. PULONG FileOffset,
  474. PVOID DataBuffer,
  475. ULONG DataLength
  476. );
  477. typedef
  478. BOOLEAN
  479. (*PFILE_FLUSH_ROUTINE) (
  480. struct _HHIVE *Hive,
  481. ULONG FileType,
  482. PLARGE_INTEGER FileOffset,
  483. ULONG Length
  484. );
  485. typedef
  486. struct _CELL_DATA *
  487. (*PGET_CELL_ROUTINE)(
  488. struct _HHIVE *Hive,
  489. HCELL_INDEX Cell
  490. );
  491. typedef
  492. VOID
  493. (*PRELEASE_CELL_ROUTINE)(
  494. struct _HHIVE *Hive,
  495. HCELL_INDEX Cell
  496. );
  497. //
  498. // --- HHIVE --- In memory descriptor for a hive.
  499. //
  500. //
  501. // HHIVE contains pointers to service procedures, and pointers to
  502. // map structure.
  503. //
  504. // NOTE: Optimization - If the size of a hive is less than what can
  505. // be mapped with a single HMAP_TABLE (HTABLE_SLOTS * HBLOCK_SIZE,
  506. // or 2 megabytes) there is no real HMAP_DIRECTORY. Instead,
  507. // a single DWORD in the HHIVE acts as the 0th entry of the
  508. // directory.
  509. //
  510. // NOTE: Free Storage Management - When a hive is loaded, we build up
  511. // a display (vector) of lists of free cells. The first part
  512. // of this vector contains lists that only hold one size cell.
  513. // The size of cell on the list is HCELL_PAD * (ListIndex+1)
  514. // There are 15 of these lists, so all free cells between 8 and
  515. // 120 bytes are on these lists.
  516. //
  517. // The second part of this vector contains lists that hold more
  518. // than one size cell. Each size bucket is twice the previous
  519. // size. There are 8 of these lists, so all free cells between 136 and
  520. // 32768 bytes are on these lists.
  521. //
  522. // The last list in this vector contains all cells too large to
  523. // fit in any previous list.
  524. //
  525. // Example: All free cells of size 1 HCELL_PAD (8 bytes)
  526. // are on the list at offset 0 in FreeDisplay.
  527. //
  528. // All free cells of size 15 HCELL_PAD (120 bytes)
  529. // are on the list at offset 0xe.
  530. //
  531. // All free cells of size 16-31 HCELL_PAD (128-248 bytes)
  532. // are on the list at offset 0xf
  533. //
  534. // All free cells of size 32-63 HCELL_PAD (256-506 bytes)
  535. // are on the list at offset 0x10.
  536. //
  537. // All free cells of size 2048 HCELL_PAD (16384 bytes)
  538. // OR greater, are on the list at offset 0x17.
  539. //
  540. // FreeSummary is a bit vector, with a bit set to true for each
  541. // entry in FreeDisplay that is not empty.
  542. //
  543. #define HHIVE_SIGNATURE 0xBEE0BEE0
  544. #define HFILE_TYPE_PRIMARY 0 // Base hive file
  545. #define HFILE_TYPE_LOG 1 // Log (security.log)
  546. #define HFILE_TYPE_EXTERNAL 2 // Target of savekey, etc.
  547. #define HFILE_TYPE_MAX 3
  548. #define HHIVE_LINEAR_INDEX 16 // All computed linear indices < HHIVE_LINEAR_INDEX are valid
  549. #define HHIVE_EXPONENTIAL_INDEX 23 // All computed exponential indices < HHIVE_EXPONENTIAL_INDEX
  550. // and >= HHIVE_LINEAR_INDEX are valid.
  551. #define HHIVE_FREE_DISPLAY_SIZE 24
  552. #define HHIVE_FREE_DISPLAY_SHIFT 3 // This must be log2 of HCELL_PAD!
  553. #define HHIVE_FREE_DISPLAY_BIAS 7 // Add to first set bit left of cell size to get exponential index
  554. #define FREE_HBIN_DISCARDABLE 1 // the BlockAddress in HBIN points to the real bin
  555. typedef struct _FREE_HBIN {
  556. LIST_ENTRY ListEntry;
  557. ULONG Size;
  558. ULONG FileOffset;
  559. ULONG Flags;
  560. } FREE_HBIN, *PFREE_HBIN;
  561. typedef struct _HHIVE {
  562. ULONG Signature;
  563. PGET_CELL_ROUTINE GetCellRoutine;
  564. PRELEASE_CELL_ROUTINE ReleaseCellRoutine;
  565. PALLOCATE_ROUTINE Allocate;
  566. PFREE_ROUTINE Free;
  567. PFILE_SET_SIZE_ROUTINE FileSetSize;
  568. PFILE_WRITE_ROUTINE FileWrite;
  569. PFILE_READ_ROUTINE FileRead;
  570. PFILE_FLUSH_ROUTINE FileFlush;
  571. struct _HBASE_BLOCK *BaseBlock;
  572. RTL_BITMAP DirtyVector; // only for Stable bins
  573. ULONG DirtyCount;
  574. ULONG DirtyAlloc; // allocated bytges for dirty vect
  575. ULONG Cluster; // Usually 1 512 byte sector.
  576. // Set up force writes to be
  577. // done in larger units on
  578. // machines with larger sectors.
  579. // Is number of logical 512 sectors.
  580. BOOLEAN Flat; // TRUE if FLAT
  581. BOOLEAN ReadOnly; // TRUE if READONLY
  582. BOOLEAN Log;
  583. ULONG HiveFlags;
  584. ULONG LogSize;
  585. ULONG RefreshCount; // debugging aid
  586. ULONG StorageTypeCount; // 1 > Number of largest valid
  587. // type. (1 for Stable only,
  588. // 2 for stable & volatile)
  589. ULONG Version; // hive version, to allow supporting multiple
  590. // formats simultaneously.
  591. struct _DUAL {
  592. ULONG Length;
  593. #ifdef HV_TRACK_FREE_SPACE
  594. ULONG FreeStorage; // how many free space.
  595. #endif
  596. PHMAP_DIRECTORY Map;
  597. PHMAP_TABLE SmallDir;
  598. ULONG Guard; // Always == -1
  599. RTL_BITMAP FreeDisplay[HHIVE_FREE_DISPLAY_SIZE]; // bitmap of freecells of the corresponding size
  600. // for every HBLOCK_SIZE - bin in the hive, a bit
  601. // is set here if a free cell of the desired size
  602. // lies in this block
  603. ULONG FreeSummary;
  604. LIST_ENTRY FreeBins; // list of freed HBINs (FREE_HBIN)
  605. } Storage[ HTYPE_COUNT ];
  606. //
  607. // Caller defined data goes here
  608. //
  609. } HHIVE, *PHHIVE;
  610. #endif // __HIVE_DATA__