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.

204 lines
7.9 KiB

  1. //
  2. // REGFFMT.H
  3. //
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. // Defines the physical format of a Windows VMM registry file.
  7. //
  8. #ifndef _REGFFMT_
  9. #define _REGFFMT_
  10. #ifdef WIN32
  11. #include <pshpack1.h>
  12. #else
  13. #pragma pack(1)
  14. #endif
  15. #define REG_NULL 0xFFFFFFFF
  16. typedef struct _FILE_HEADER {
  17. DWORD Signature; // FH_SIGNATURE
  18. DWORD Version; // FH_VERSION_*
  19. DWORD Size; // of file header, all keynodes
  20. DWORD Checksum; // of file header
  21. WORD BlockCount;
  22. DWORD Flags; // FHF_* bits
  23. WORD Type; // FHT_* constant
  24. BYTE Reserved[8];
  25. } FILE_HEADER, UNALIGNED FAR* LPFILE_HEADER;
  26. #define FH_SIGNATURE 0x47455243 // "CREG"
  27. #define FH_VERSION10 0x00010000 // Win95 compatible
  28. #define FH_VERSION20 0x00020000 // Supports compact keynodes (never used)
  29. #define FHF_DIRTY 0x00000001 // Must rewrite to disk
  30. #define FHF_RESERVED1 0x00000002 // Dead bit from VERY old files
  31. #define FHF_HASCHECKSUM 0x00000004 // Checksum member is valid
  32. #define FHF_FILEDIRTY 0x00000008 // File is in the process of being updated (checked by win.com)
  33. #define FHF_CORRUPT 0x00000010 // File is corrupt (detected by scanregw.exe)
  34. #define FHF_SUPPORTSDIRTY 0x00000020 // The registry supports FHF_CORRUPT and FHF_FILEDIRTY
  35. #define FHF_BOOTFAILED 0x00000040 // Failed to boot and verify the integrity of the registry
  36. #define FHT_PRIMARY 0x0001 // System hives
  37. #define FHT_SECONDARY 0x0080 // User/application hives
  38. typedef struct _KEYNODE_HEADER {
  39. DWORD Signature; // KH_SIGNATURE
  40. DWORD FileKnSize; // of entire keynode table inc header
  41. DWORD RootIndex; // Index into keynode array of the root key node
  42. DWORD FirstFreeIndex; // Index into keynode array of the root of the key node free list
  43. DWORD Flags; // KHF_* bits
  44. DWORD Checksum; // of entire keynode table
  45. BYTE Reserved[8];
  46. } KEYNODE_HEADER, UNALIGNED FAR* LPKEYNODE_HEADER;
  47. #define KH_SIGNATURE 0x4E4B4752 // "RGKN"
  48. #define KHF_DIRTY 0x00000001 // Win95: Must rewrite to disk
  49. #define KHF_EXTENDED 0x00000002 // Win95: Table has grown
  50. #define KHF_HASCHECKSUM 0x00000004 // Win95: Checksum is valid
  51. #define KHF_NEWHASH 0x00000008 // Always expect
  52. typedef struct _VERSION20_HEADER_PAGE {
  53. union {
  54. struct {
  55. FILE_HEADER FileHeader;
  56. KEYNODE_HEADER KeynodeHeader;
  57. };
  58. struct {
  59. BYTE Page[4096];
  60. };
  61. };
  62. } VERSION20_HEADER_PAGE, UNALIGNED FAR* LPVERSION20_HEADER_PAGE;
  63. typedef struct _W95KEYNODE {
  64. DWORD W95State; // KNS_* constant
  65. union {
  66. // State == KNS_USED or KNS_BIGUSED
  67. struct {
  68. DWORD W95Hash;
  69. DWORD W95Reserved1;
  70. DWORD W95ParentOffset; // offset from start of keynode header
  71. DWORD W95ChildOffset; // offset from start of keynode header
  72. DWORD W95NextOffset; // offset from start of keynode header
  73. DWORD W95DatablockAddress; // HIWORD: block #, LOWORD: Index in block
  74. };
  75. // State == KNS_FREE or KNS_ALLFREE
  76. struct {
  77. DWORD W95FreeRecordSize;
  78. DWORD W95NextFreeOffset;
  79. DWORD W95Reserved2[4];
  80. };
  81. };
  82. } W95KEYNODE, UNALIGNED FAR* LPW95KEYNODE;
  83. #define KNS_USED 0x00000000UL // Normal Keynode
  84. #define KNS_BIGUSED 0x00000001UL // Big key node root
  85. #define KNS_BIGUSEDEXT 0x00000002UL // Big key node extension
  86. #define KNS_FREE 0x80000000UL
  87. #define KNS_ALLFREE 0xFFFFFFFFUL
  88. typedef struct _KEYNODE {
  89. DWORD NextIndex:24,
  90. Flags:8;
  91. union {
  92. // Flags & KNF_INUSE
  93. struct {
  94. DWORD ChildIndex:24,
  95. BinNumber:8;
  96. DWORD ParentIndex:24,
  97. KeyRecordIndex:8;
  98. WORD BlockIndex;
  99. WORD Hash;
  100. };
  101. // !(Flags & KNF_INUSE)
  102. struct {
  103. DWORD Reserved;
  104. DWORD FreeRecordSize;
  105. };
  106. };
  107. } KEYNODE, FAR* LPKEYNODE;
  108. #define KNF_INUSE 0x01 // Block is in use
  109. #define KNF_BIGKEYROOT 0x02 // Keynode represents a big key root
  110. #define KNF_BIGKEYEXT 0x04 // Keynode represents a big key extension
  111. #define IsNullKeynodeIndex(kni) ((kni) >= 0x00FFFFFF)
  112. typedef struct _DATABLOCK_HEADER {
  113. DWORD Signature; // DH_SIGNATURE
  114. DWORD BlockSize; // size of block including header
  115. DWORD FreeBytes; // total of free bytes in block
  116. WORD Flags; // DHF_* bits
  117. WORD BlockIndex;
  118. DWORD FirstFreeOffset; // offset of first free record from start of data block header
  119. WORD MaxAllocatedIndex; // maximum index already allocated in the block
  120. WORD FirstFreeIndex; // first available index in the block
  121. DWORD Reserved;
  122. DWORD Checksum; // of entire datablock
  123. } DATABLOCK_HEADER, UNALIGNED FAR* LPDATABLOCK_HEADER;
  124. #define DH_SIGNATURE 0x42444752 // "RGDB"
  125. #define DHF_DIRTY 0x0001 // Must rewrite to disk
  126. #define DHF_EXTENDED 0x0002 // Datablock size has grown
  127. #define DHF_HASCHECKSUM 0x0004 // Checksum member is valid
  128. #define DHF_HASBLOCKNUMBERS 0x0008 // Keys contain block numbers
  129. #define DATABLOCKS_PER_FILE 0xFFFE // 0xFFFF is 'null' block index
  130. // Arbitrary size pulled from the old registry code. Oh well, makes it
  131. // convenient when we do 16-bit math to extend a datablock by 4K.
  132. #define MAXIMUM_DATABLOCK_SIZE ((DWORD)(60L*1024L))
  133. // Win95 registry files may not always have a key record for the root key of
  134. // a file.
  135. #define NULL_BLOCK_INDEX 0xFFFF
  136. #define IsNullBlockIndex(bi) ((bi) == NULL_BLOCK_INDEX)
  137. typedef struct _KEY_RECORD {
  138. DWORD AllocatedSize; // bytes allocated for the record
  139. union {
  140. DWORD DatablockAddress; // corresponds to W95KEYNODE.W95DatablockAddress
  141. struct {
  142. WORD KeyRecordIndex; // index into the data block for this key
  143. WORD BlockIndex; // data block index that this key resides in
  144. };
  145. };
  146. DWORD RecordSize; // bytes used in the record
  147. WORD NameLength;
  148. WORD ValueCount; // Count of value name records
  149. WORD ClassLength;
  150. WORD Reserved;
  151. char Name[ANYSIZE_ARRAY];
  152. } KEY_RECORD, UNALIGNED FAR* LPKEY_RECORD;
  153. typedef struct _FREEKEY_RECORD {
  154. DWORD AllocatedSize;
  155. DWORD DatablockAddress; // REG_NULL for free records
  156. DWORD NextFreeOffset;
  157. } FREEKEY_RECORD, UNALIGNED FAR* LPFREEKEY_RECORD;
  158. typedef struct _VALUE_RECORD {
  159. DWORD DataType;
  160. DWORD Reserved;
  161. WORD NameLength;
  162. WORD DataLength;
  163. char Name[ANYSIZE_ARRAY];
  164. } VALUE_RECORD, UNALIGNED FAR* LPVALUE_RECORD;
  165. #define KEY_RECORDS_PER_DATABLOCK 255
  166. // Arbitrary size pulled from the old registry code. Oh well, makes it
  167. // convenient when we do 16-bit math to extend a datablock by 4K.
  168. #define MAXIMUM_KEY_RECORD_SIZE \
  169. ((DWORD)(MAXIMUM_DATABLOCK_SIZE-sizeof(DATABLOCK_HEADER)))
  170. #ifdef WIN32
  171. #include <poppack.h>
  172. #else
  173. #pragma pack()
  174. #endif
  175. #endif // _REGFFMT_