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.

196 lines
6.0 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
  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 FHT_PRIMARY 0x0001 // System hives
  33. #define FHT_SECONDARY 0x0080 // User/application hives
  34. typedef struct _KEYNODE_HEADER {
  35. DWORD Signature; // KH_SIGNATURE
  36. DWORD FileKnSize; // of entire keynode table inc header
  37. DWORD RootIndex;
  38. DWORD FirstFreeIndex;
  39. DWORD Flags; // KHF_* bits
  40. DWORD Checksum; // of entire keynode table
  41. BYTE Reserved[8];
  42. } KEYNODE_HEADER, UNALIGNED FAR* LPKEYNODE_HEADER;
  43. #define KH_SIGNATURE 0x4E4B4752 // "RGKN"
  44. #define KHF_DIRTY 0x00000001 // Win95: Must rewrite to disk
  45. #define KHF_EXTENDED 0x00000002 // Win95: Table has grown
  46. #define KHF_HASCHECKSUM 0x00000004 // Win95: Checksum is valid
  47. #define KHF_NEWHASH 0x00000008 // Alway expect
  48. typedef struct _VERSION20_HEADER_PAGE {
  49. union {
  50. struct {
  51. FILE_HEADER FileHeader;
  52. KEYNODE_HEADER KeynodeHeader;
  53. };
  54. struct {
  55. BYTE Page[4096];
  56. };
  57. };
  58. } VERSION20_HEADER_PAGE, UNALIGNED FAR* LPVERSION20_HEADER_PAGE;
  59. typedef struct _W95KEYNODE {
  60. DWORD W95State; // KNS_* constant
  61. union {
  62. // State == KNS_USED
  63. struct {
  64. DWORD W95Hash;
  65. DWORD W95Reserved1;
  66. DWORD W95ParentOffset;
  67. DWORD W95ChildOffset;
  68. DWORD W95NextOffset;
  69. DWORD W95DatablockAddress;
  70. };
  71. // State == KNS_FREE or KNS_ALLFREE
  72. struct {
  73. DWORD W95FreeRecordSize;
  74. DWORD W95NextFreeOffset;
  75. DWORD W95Reserved2[4];
  76. };
  77. };
  78. } W95KEYNODE, UNALIGNED FAR* LPW95KEYNODE;
  79. #define KNS_USED 0x00000000 // Keynode
  80. #define KNS_FREE 0x80000000
  81. #define KNS_ALLFREE 0xFFFFFFFF
  82. typedef struct _KEYNODE {
  83. DWORD NextIndex:24,
  84. Flags:8;
  85. union {
  86. // Flags & KNF_INUSE
  87. struct {
  88. DWORD ChildIndex:24,
  89. BinNumber:8;
  90. DWORD ParentIndex:24,
  91. KeyRecordIndex:8;
  92. WORD BlockIndex;
  93. WORD Hash;
  94. };
  95. // !(Flags & KNF_INUSE)
  96. struct {
  97. DWORD Reserved;
  98. DWORD FreeRecordSize;
  99. };
  100. };
  101. } KEYNODE, FAR* LPKEYNODE;
  102. #define KNF_INUSE 0x01 // Block is in use
  103. #define IsNullKeynodeIndex(kni) ((kni) >= 0x00FFFFFF)
  104. typedef struct _DATABLOCK_HEADER {
  105. DWORD Signature; // DH_SIGNATURE
  106. DWORD BlockSize;
  107. DWORD FreeBytes;
  108. WORD Flags; // DHF_* bits
  109. WORD BlockIndex;
  110. DWORD FirstFreeOffset;
  111. WORD MaxAllocatedIndex;
  112. WORD FirstFreeIndex;
  113. DWORD Reserved;
  114. DWORD Checksum; // of entire datablock
  115. } DATABLOCK_HEADER, UNALIGNED FAR* LPDATABLOCK_HEADER;
  116. #define DH_SIGNATURE 0x42444752 // "RGDB"
  117. #define DHF_DIRTY 0x0001 // Must rewrite to disk
  118. #define DHF_EXTENDED 0x0002 // Datablock size has grown
  119. #define DHF_HASCHECKSUM 0x0004 // Checksum member is valid
  120. #define DHF_HASBLOCKNUMBERS 0x0008 // Keys contain block numbers
  121. #define DATABLOCKS_PER_FILE 0xFFFE // 0xFFFF is 'null' block index
  122. // Arbitrary size pulled from the old registry code. Oh well, makes it
  123. // convenient when we do 16-bit math to extend a datablock by 4K.
  124. #define MAXIMUM_DATABLOCK_SIZE ((DWORD)(60L*1024L))
  125. // Win95 registry files may not always have a key record for the root key of
  126. // a file.
  127. #define NULL_BLOCK_INDEX 0xFFFF
  128. #define IsNullBlockIndex(bi) ((bi) == NULL_BLOCK_INDEX)
  129. typedef struct _KEY_RECORD {
  130. DWORD AllocatedSize;
  131. union {
  132. DWORD DatablockAddress;
  133. struct {
  134. WORD KeyRecordIndex;
  135. WORD BlockIndex;
  136. };
  137. };
  138. DWORD RecordSize;
  139. WORD NameLength;
  140. WORD ValueCount;
  141. WORD ClassLength;
  142. WORD Reserved;
  143. char Name[ANYSIZE_ARRAY];
  144. } KEY_RECORD, UNALIGNED FAR* LPKEY_RECORD;
  145. typedef struct _FREEKEY_RECORD {
  146. DWORD AllocatedSize;
  147. DWORD DatablockAddress; // REG_NULL for free records
  148. DWORD NextFreeOffset;
  149. } FREEKEY_RECORD, UNALIGNED FAR* LPFREEKEY_RECORD;
  150. typedef struct _VALUE_RECORD {
  151. DWORD DataType;
  152. DWORD Reserved;
  153. WORD NameLength;
  154. WORD DataLength;
  155. char Name[ANYSIZE_ARRAY];
  156. } VALUE_RECORD, UNALIGNED FAR* LPVALUE_RECORD;
  157. #define KEY_RECORDS_PER_DATABLOCK 255
  158. // Arbitrary size pulled from the old registry code. Oh well, makes it
  159. // convenient when we do 16-bit math to extend a datablock by 4K.
  160. #define MAXIMUM_KEY_RECORD_SIZE \
  161. ((DWORD)(MAXIMUM_DATABLOCK_SIZE-sizeof(DATABLOCK_HEADER)))
  162. #ifdef WIN32
  163. #include <poppack.h>
  164. #else
  165. #pragma pack()
  166. #endif
  167. #endif // _REGFFMT_