Files
website/content/news/20261129-xthv1-registry-hive-format.md
T
harraiken d3b870619f
Builds / ExectOS WebSite (push) Successful in 22s
Add XTHV1 registry hive format article
2026-11-29 14:57:54 +01:00

36 KiB
Raw Blame History

+++ title = 'XTHV1: A New Registry Hive Format for ExectOS' author = 'Aiken Harris' date = '2026-11-29T12:17:03+01:00' +++ We would like to share some news about what we are working on right now: configuration management and the registry. Like everything else in the kernel, the registry follows the NT model. There is a hierarchical database of keys and values, security descriptors on keys, volatile keys that disappear on reboot, symbolic links, and the familiar native API on top. One part of it, however, takes a different road. ExectOS will not store its registry in the REGF hive files known from Windows. Instead, we are deploying our own on-disk format, called XTHV1.

This article explains why we made that decision, what it buys us, what it costs, and what it means for NT compatibility. The second half is the complete specification of the format as it stands today.

Why Not REGF?

REGF is the file format of Windows registry hives. It has served Windows well for three decades, but those three decades show. The format accumulated revisions, compatibility rules, and fields whose meaning changed over time. Its crash consistency depends on a header with sequence numbers and a simple checksum, combined with separate transaction log files that are replayed when the primary file turns out to be inconsistent. The registry data itself, the bins and cells that hold keys and values, carries no integrity protection at all. A torn write, a flipped bit or a page written to the wrong place is only noticed if it happens to break the structure badly enough, and a damaged hive is typically handled by repairing it in place: dropping whatever cannot be made consistent and carrying on.

There is also the question of documentation. REGF has never been specified by its author. Everything known about it comes from observation and reverse engineering, and every implementation outside Windows has to rediscover the same corner cases. Implementing it for ExectOS would mean committing to a format we cannot fully specify, cannot change, and whose most important guarantees live in a log replay protocol rather than in the file itself.

We wanted the opposite: a format we can describe completely in one document, whose consistency does not depend on side files, and in which every byte on disk is verified before it is trusted.

What XTHV1 Is

XTHV1 keeps the record model that registry implementations have relied on for decades. Keys, values, security records and subkey indexes are stored as records in cells, and cells are grouped into bins. The configuration manager above the file therefore works with familiar structures. What changes is everything around those records.

An XTHV1 file is a sequence of 4096-byte pages. Two of them hold superblocks, the roots of the two most recent committed images. Every other page is either a data page carrying a piece of the registry image or a node of a small three-level map tree that translates logical page numbers into physical ones. Every pointer in the file, from the superblock down to each data page, carries a SHA-1 hash of the page it points to. The whole committed image is thus covered by a hash tree whose root lives in the superblock, and the superblock is protected by its own hash.

Changes are never written in place. A commit writes modified data pages and the map nodes above them to free pages, then publishes a new superblock in the slot that does not hold the current image. Until the second superblock write is durable, the previous image is the committed one. Afterwards the new one is. There is no log to replay and no intermediate state to repair.

What We Gain

Atomic commits without logs. A crash at any point of a commit leaves the file with either the previous image or the new one, both complete. Recovery after a power failure is the same procedure as a normal mount: pick the newest valid superblock and follow it.

Every byte is verified. Torn pages, bit rot, misdirected writes and stale pages are detected by the hash tree before any record is parsed. A hive that mounts successfully has been checked end to end.

The previous image stays available. Pages of the previous generation are not reused while it is still one of the two live images. If the newest image fails verification, the reader can fall back to the previous one, which is complete and consistent, instead of guessing which parts of a damaged image are still trustworthy.

A canonical byte form. Free space is zeroed, reserved fields are zero and runtime-only state never reaches the disk. Two hives with the same content and history produce the same bytes. Images are reproducible and comparable, and test fixtures can be generated from the specification alone.

Strict structure. The format defines exactly which records may appear and who may reference them. Every allocated cell must be reachable from the root key, every cell except a security record has exactly one owner, names are unique within a key, and indexes must be ordered and carry correct hints. There is no room for hidden data, dangling references or ambiguous interpretations, which also makes crafted hives considerably less interesting as an attack vector.

64-bit physical addressing and a complete specification. Physical page numbers are 64-bit, and the logical image can be scattered across the file in any order. The format is fully specified below, including test vectors, so it can be implemented independently of the ExectOS kernel.

What We Give Up

Compatibility at the file level. Windows cannot read XTHV1 hives, and ExectOS will not read REGF hives. Existing registry tools that operate on hive files will not work with ours.

Write amplification. Changing a single byte rewrites the whole data page, one map node on each of the three levels and a superblock, separated by two durable flushes. REGF with its log can be cheaper for small, frequent updates. We accept this because registry writes are batched and comparatively rare, and because the cost buys atomicity.

Space. Two generations are live at the same time, so a file may temporarily hold close to twice the pages of the logical image, plus about 1.2% for map nodes. Physical pages are also not kept in logical order.

Verification cost. Mounting a hive hashes every page and walks the entire record graph. For registry-sized data this is a small price, but it is not free.

No automatic repair. A strict format rejects images that a lenient implementation would silently patch. XTHV1 1.0 can fall back to the previous generation, but it defines no procedure for rewriting damaged content. A dedicated repair mechanism is planned, but it is not part of this version.

SHA-1. The hash tree uses SHA-1, whose collision resistance is no longer considered strong. The purpose of the hashes is to detect accidental damage, not to authenticate the file. Anyone who can write the file can recompute any hash in it, so a stronger function without a key would not change that.

What This Means for NT Compatibility

Our compatibility target has always been the interface, not the files. Applications and drivers use the registry through the native API and never parse hive files themselves. The semantics they depend on, such as keys, values and value types, security descriptors, volatile keys and symbolic links, are preserved. From their point of view, nothing changes.

What does change is everything that handles hive files directly. Offline registry editors, forensic tools and anything that copies hives between systems will not understand XTHV1, and moving registry data between Windows and ExectOS requires conversion. Our boot loader reads XTHV1 directly, so no REGF parser is needed anywhere in the boot path.

The XTHV1 Specification

The rest of this article is the specification of XTHV1 version 1.0, cell format 1. It is written for implementers of readers, writers, validators and debugging tools, and it does not require any knowledge of the ExectOS sources. The keywords MUST, MUST NOT, SHOULD and MAY are to be interpreted as described in RFC 2119.

1. Conventions

  • All multi-byte numbers are little-endian. Offsets are decimal unless written as 0x….
  • u8, u16, u32 and u64 are unsigned integers of the given width. i32 is a signed 32-bit integer.
  • "Zero" means that every byte of the range is 0x00.
  • String literals are ASCII. \r, \n and \x1a denote the bytes 0x0D, 0x0A and 0x1A.
  • The tables define the exact byte layout. An implementation MAY map them to C structures as long as widths, offsets and buffer bounds match. A buffer's position in the file says nothing about its alignment in memory, so readers MUST NOT assume that a page buffer is aligned for typed access.

2. Container

An XTHV1 file is a sequence of 4096-byte pages addressed by a physical block number (PBN). The byte offset of a page is PBN × 4096.

PBN Content
0 Superblock, slot A
1 Superblock, slot B
≥ 2 Data pages and map nodes, in any order

The logical image is the registry content: a sequence of bins (§7) of LogicalBytes bytes. The logical image is divided into logical pages (LPN). Logical byte address L lies in LPN = L / 4096 at offset L % 4096. The map tree (§5) translates every LPN into the PBN that holds it, and consecutive logical pages need not be physically adjacent. All cell indexes and bin offsets refer to the logical image.

The pages reachable from a superblock form a committed image. Any other page in the file belongs to an older generation or to an interrupted commit and MUST be ignored by readers.

XTHV1 container layout

3. Superblock

A superblock is exactly 4096 bytes long. The first 176 bytes form the header, followed by reserved space and the superblock hash.

XTHV1 superblock layout

Offset Size Field Rule
0 8 Magic bytes 58 54 48 56 31 0D 0A 1A ("XTHV1\r\n\x1a")
8 2 Major u16, 1
10 2 Minor u16, 0
12 4 HeaderBytes u32, 176
16 4 PageBytes u32, 4096
20 4 SlotId u32, 0 for slot A, 1 for slot B. MUST match the page the superblock is stored in.
24 16 HiveId Opaque hive identity. MUST NOT be all zero. Both slots MUST agree.
40 8 Generation u64, non-zero. Grows by one with every commit and never wraps.
48 8 LogicalBytes u64, size of the logical image. 4096 ≤ LogicalBytes ≤ 0x7FFFF000, a multiple of 4096.
56 8 FilePageLimit u64, ≥ 2. Exclusive upper bound of every PBN used by the live generations (§12).
64 4 RootCell u32, cell index of the root key node.
68 4 CellFormat u32, 1 (the record catalog of §8).
72 48 MapRoot Descriptor (§5.2) of the level-2 map node.
120 8 CommitTime u64, 100 ns units since 1601-01-01. Diagnostic, not interpreted.
128 8 RequiredFeatures u64, 0 in version 1.0 (§13).
136 8 ReadOnlyFeatures u64, 0 in version 1.0 (§13).
144 8 CompatibleFeatures u64, 0 in version 1.0 (§13).
152 16 WriterId Opaque writer identity. Diagnostic, not interpreted.
168 4 HashAlgorithm u32, 1 (SHA-1, §4).
172 4 Reserved u32, zero.
176 3888 — Reserved, zero.
4064 32 SuperblockHash SHA-1 digest of the superblock (§4.2) in bytes 0–19. Bytes 20–31 are zero.

Validating a slot. Each slot is examined independently.

  1. A slot is absent if the file is too short to contain its page. It is torn if the magic does not match, if any of the last 12 bytes of SuperblockHash is non-zero, or if the digest does not match the computed superblock hash. Absent and torn slots are skipped. They are never repaired.
  2. A slot that passes these checks is authenticated. If an authenticated slot carries Major ≠ 1, Minor ≠ 0, HeaderBytes ≠ 176, PageBytes ≠ 4096, CellFormat ≠ 1, HashAlgorithm ≠ 1 or RequiredFeatures ≠ 0, the file is unsupported and MUST be refused. A reader MUST NOT fall back to the other slot in that case.
  3. An authenticated slot whose HiveId is all zero, whose SlotId does not match its page, whose Reserved field or any byte in 176–4063 is non-zero, whose Generation is zero, whose LogicalBytes is out of range or not a multiple of 4096, or whose FilePageLimit is below 2 makes the file corrupt.
  4. Otherwise the slot is valid.

Selecting the current image.

  • If both slots are valid, their HiveId values MUST be equal and their Generation values MUST differ. Otherwise the file is corrupt. The slot with the higher generation holds the current image, and the other holds the previous image.
  • If one slot is valid, it holds the current image and there is no previous image. A newly created hive has slot A at generation 1 and slot B filled with zeros.
  • If no slot is valid, the file is not an XTHV1 hive.

4. Hashes

HashAlgorithm = 1 selects SHA-1 (FIPS 180-1). Every hash field is 32 bytes long: the 20-byte digest followed by 12 zero bytes, which readers MUST verify. Digests cover the exact bytes stored in the file.

4.1 Page hash

Data pages and map nodes are hashed together with a 52-byte context that binds the page to its position:

preimage = Domain[8] ‖ HiveId[16] ‖ u64 PBN ‖ u64 BirthGeneration ‖ u64 BaseLpn ‖ u32 LevelTag ‖ Page[4096]
hash     = SHA-1(preimage)
Field Data page Map node
Domain "XTHVDAT1" "XTHVMAP1"
HiveId hive identity hive identity
PBN page's own PBN page's own PBN
BirthGeneration from the page's descriptor the node's BirthGeneration
BaseLpn the page's LPN the node's BaseLpn
LevelTag 0xFFFFFFFF the node's Level

The context is exactly 52 bytes long. There are no padding bytes between LevelTag and the page data, and the full preimage is 4148 bytes long. Because the PBN and the generation are part of the preimage, a valid page copied to another location, or a stale page from an older generation, does not verify.

A child's hash MUST equal the hash stored in its parent's descriptor. The root descriptor is stored in the superblock and protected by the superblock hash.

4.2 Superblock hash
preimage = "XTHVSUP1" ‖ Superblock[4096], with bytes 4064–4095 set to zero
hash     = SHA-1(preimage)

5. Map Tree

5.1 Shape

The map tree has exactly three levels. Each node holds up to 84 descriptors, so the tree can address 84³ = 592 704 pages. That is more than the 524 287 pages of the largest logical image, so the depth never depends on the image size. The level-2 root covers the whole image. Each level-1 node covers 84² = 7056 logical pages, each level-0 node covers 84 logical pages, and level-0 descriptors point at data pages.

XTHV1 map tree

The mapping is dense. With N = LogicalBytes / 4096, the LPNs 0 … N − 1 exist, and no others do. To resolve an LPN, take entry LPN / 7056 of the root, entry (LPN % 7056) / 84 of the level-1 node and entry LPN % 84 of the level-0 node.

5.2 Descriptor

A descriptor is 48 bytes long. It is used for the superblock's MapRoot and for every node entry.

Offset Size Field Rule
0 8 PBN u64. 2 ≤ PBN < FilePageLimit, and the page MUST lie entirely within the file.
8 8 BirthGeneration u64, the generation in which the child page was written. 1 ≤ BirthGeneration ≤ Generation of the superblock.
16 32 Hash Page hash of the child (§4.1), followed by 12 zero bytes.

An empty descriptor is 48 zero bytes. Within one committed image, no PBN may appear twice: not as the root, not as a node and not as a data page. Pages are shared across generations, never within one.

5.3 Map node
Offset Size Field Rule
0 8 Magic "XTHVMAP1"
8 16 HiveId Equals the superblock's HiveId.
24 8 BirthGeneration Equals the BirthGeneration of the descriptor that points to this node.
32 8 BaseLpn First LPN covered by the node (global, not relative to the parent).
40 4 Level 0, 1 or 2.
44 4 UsedEntries 1 … 84. Nodes are never empty.
48 16 — Reserved, zero.
64 4032 Entries 84 descriptors. Entries 0 … UsedEntries − 1 are present, and the rest are empty.

Every node field is fully determined by the node's position:

  • Root: Level = 2, BaseLpn = 0, UsedEntries = ⌈N / 7056⌉.
  • Level-1 node at root entry i: Level = 1, BaseLpn = i × 7056, UsedEntries = ⌈(min(N, BaseLpn + 7056) − BaseLpn) / 84⌉.
  • Level-0 node at entry j of a level-1 node with base B: Level = 0, BaseLpn = B + j × 84, UsedEntries = min(84, N − BaseLpn).

A reader MUST verify every node against these values and its descriptor, and MUST verify that the level-0 nodes together cover all N logical pages.

6. Limits

Quantity Limit
Logical image 4096 … 0x7FFFF000 bytes, a multiple of 4096
Physical file bounded by FilePageLimit × 4096. The format imposes no fixed cap.
Generation 1 … 2⁶⁴ − 1. Exhaustion stops commits, and the counter never wraps.
Bin at least 4096 bytes, a multiple of 4096
Cell 8 … 1 048 576 bytes, a multiple of 8
Big value data at most 65 535 chunks of 16 344 bytes (1 071 104 040 bytes)
Index record 1 … 65 535 entries, limited by its cell

Implementations MAY impose stricter resource limits, such as a maximum file size or a maximum nesting depth of the key and index graph, and MUST document them. Such limits belong to the implementation, not to the format. For reference, the ExectOS kernel accepts files of up to 2²⁰ pages (4 GiB) and key/index nesting up to 64 levels deep.

7. Bins and Cells

XTHV1 bins and cells

7.1 Bin

A bin is a contiguous range of the logical image consisting of a 32-byte header followed by cells.

Offset Size Field Rule
0 4 Signature u32 0x6E696268 (bytes "hbin")
4 4 FileOffset u32, logical offset of this bin. MUST equal its actual position.
8 4 Size u32, total size of the bin: ≥ 4096, a multiple of 4096, and within the image.
12 8 — Reserved, written as zero, not interpreted by readers.
20 8 TimeStamp Diagnostic, not interpreted.
28 4 Spare Written as zero, not interpreted by readers.

The first bin starts at logical offset 0. Each following bin starts where the previous one ends, and the last one ends exactly at LogicalBytes. A bin may span several logical pages, which may be stored anywhere in the file. Bins never move, because cell indexes stored inside them depend on their position.

7.2 Cell

A cell consists of an i32 Size header followed by |Size| − 4 bytes of payload.

  • Size < 0: an allocated cell. Its payload holds a record (§8) or raw data.
  • Size > 0: a free cell. Its payload MUST be zero.
  • Size = 0 and Size = 0x80000000 are invalid.
  • |Size| includes the header, is a multiple of 8, satisfies 8 ≤ |Size| ≤ 1 048 576, and MUST NOT extend past the end of the bin.
  • The first cell starts at bin offset 32. Cells follow each other without gaps, and the last one ends exactly at the end of the bin.

The usable payload of a cell is |Size| − 4 bytes. Cell format 1 has no backward pointer: the 4-byte header is the entire cell header.

A cell index is the 32-bit logical offset of a cell header. 0xFFFFFFFF (HCELL_NIL) means "no cell". Bit 31 marks a cell in volatile storage, which exists only in memory, so it never appears in a file. Every cell index stored in a record MUST be below LogicalBytes, MUST have bit 31 clear, and MUST point at the start of an allocated cell, never into the middle of a cell or at a free cell.

8. Record Catalog

Records live in the payload of allocated cells. Offsets below are relative to the payload start, which lies four bytes after the cell header. Records are byte-packed: a field's offset is exactly the one given, even if this leaves it unaligned in memory. The fixed parts of nk and vk are 76 and 20 bytes long. Each record type is identified by a u16 signature at offset 0:

Record u16 value Bytes on disk
Key node 0x6B6E "nk"
Value node 0x6B76 "vk"
Big data 0x6264 "db"
Security 0x6B73 "sk"
Index root 0x6972 "ri"
Index leaf 0x696C "li"
Fast leaf 0x666C "lf"
Hash leaf 0x686C "lh"

Value data, class data, value lists and chunk lists are raw cells without a signature. They are validated through the record that references them.

8.1 Key node (nk)
Offset Size Field Rule
0 2 Signature 0x6B6E
2 2 Flags See the flag table below.
4 8 LastWriteTime Diagnostic, not interpreted.
12 4 Spare Not interpreted.
16 4 Parent Cell of the parent key. The root key points to itself.
20 4 SubKeyCounts[0] Number of subkeys.
24 4 SubKeyCounts[1] Volatile subkey count. 0 on disk.
28 4 SubKeyLists[0] Subkey index (§8.5). HCELL_NIL if and only if SubKeyCounts[0] = 0.
32 4 SubKeyLists[1] Volatile subkey index. HCELL_NIL on disk.
36 4 ValueList.Count Number of values.
40 4 ValueList.List Value list (§8.6). HCELL_NIL if and only if Count = 0.
44 4 Security sk record, or HCELL_NIL.
48 4 Class Class data cell, or HCELL_NIL.
52 16 MaxNameLen, MaxClassLen, MaxValueNameLen, MaxValueDataLen Advisory u32 counters, not validated.
68 4 WorkVar Runtime scratch. Zero on disk.
72 2 NameLength Length of the name in bytes.
74 2 ClassLength Length of the class data in bytes. 0 if and only if Class = HCELL_NIL.
76 var Name NameLength bytes (§9).
Flag Name On disk
0x0001 KEY_VOLATILE Forbidden (runtime only).
0x0002 KEY_HIVE_EXIT Forbidden (runtime only).
0x0004 KEY_HIVE_ENTRY Forbidden (runtime only).
0x0008 KEY_NO_DELETE Allowed. The key cannot be deleted.
0x0010 KEY_SYM_LINK Allowed. The key is a symbolic link.
0x0020 KEY_COMP_NAME Allowed. The name is stored in compressed form (§9.1).
0x0040 KEY_PREDEF_HANDLE Allowed. See below.
0x0080–0x0800 — Undefined, forbidden.
0xF000 User flags Allowed. Four bits for the configuration manager, not interpreted by the format.

Rules:

  • A key node with any forbidden flag bit is invalid. New bits require a new format version or feature bit (§13).
  • The name MUST fit into the cell (76 + NameLength ≤ |Size| − 4) and MUST follow §9.1. Every key except the root MUST have a non-empty name.
  • Parent MUST name the key whose index lists this key. The root key's Parent is its own cell.
  • If ClassLength > 0, the class cell MUST hold at least ClassLength payload bytes.
  • If KEY_PREDEF_HANDLE is set, ValueList.List MUST be HCELL_NIL. ValueList.Count then holds a handle value that the format does not interpret, and the key has no values.
  • SubKeyCounts[0] MUST equal the number of keys reachable through SubKeyLists[0], counted through index roots.
  • SubKeyCounts[1] MUST be 0 and SubKeyLists[1] MUST be HCELL_NIL. Volatile subkeys exist only in memory.
8.2 Value node (vk)
Offset Size Field Rule
0 2 Signature 0x6B76
2 2 NameLength Length of the name in bytes. 0 denotes the default value of a key.
4 4 DataLength Encoded data size (below).
8 4 Data Inline data, data cell or db cell (below).
12 4 Type Registry value type, passed through without interpretation.
16 2 Flags 0x0001 = VALUE_COMP_NAME. All other bits MUST be zero.
18 2 Spare Not interpreted.
20 var Name NameLength bytes (§9). The name MUST fit into the cell.
DataLength (D) Storage
0x80000000 ≤ D ≤ 0x80000004 Inline. The data (D − 0x80000000 bytes) is stored in the Data field itself. Unused bytes SHOULD be zero.
0 ≤ D ≤ 0x3FD8 External. Data names a cell whose payload holds at least D bytes.
0x3FD8 < D < 0x80000000 Big data. Data names a db record (§8.3).
D > 0x80000004 Invalid.

The external form requires a data cell even when D = 0, so writers SHOULD store empty data inline as 0x80000000. Values are not ordered.

8.3 Big data (db)
Offset Size Field
0 2 Signature (0x6264)
2 2 Count: number of chunks, u16, ≥ 1
4 4 List: cell holding Count chunk cell indexes (u32)

The value data is split into chunks of 16 344 bytes (0x3FD8). Count MUST equal ⌈D / 0x3FD8⌉. The list cell MUST hold at least 4 × Count payload bytes. Every chunk except the last MUST hold at least 0x3FD8 payload bytes, and the last chunk at least the remainder. Bytes between the logical end of a chunk and the end of its payload MUST be zero. Chunk contents are opaque value data and are never interpreted as records.

8.4 Security record (sk)
Offset Size Field Rule
0 2 Signature 0x6B73
2 2 Reserved Zero.
4 4 Flink Next sk in the ring.
8 4 Blink Previous sk in the ring.
12 4 ReferenceCount u32, ≥ 1.
16 4 DescriptorLength u32, ≥ 20, and 20 + DescriptorLength MUST fit into the cell's payload.
20 var Descriptor Self-relative security descriptor of DescriptorLength bytes.

All sk records of an image form a circular, doubly linked ring. For every element, the Blink of its Flink successor MUST point back at it, and following Flink MUST return to the starting element. A single record points to itself in both directions. Security records are the only records that may be shared: ReferenceCount MUST equal the number of key nodes whose Security field names the record.

The descriptor is validated structurally only, with no security policy implied:

Offset Size Field Rule
0 1 Revision 1
1 1 Sbz1 0
2 2 Control MUST contain SE_SELF_RELATIVE (0x8000). Other bits are passed through.
4 4 Owner 0, or an offset ≥ 20 of a SID inside the descriptor.
8 4 Group 0, or an offset ≥ 20 of a SID inside the descriptor.
12 4 Sacl 0, or an offset ≥ 20 of an ACL inside the descriptor.
16 4 Dacl 0, or an offset ≥ 20 of an ACL inside the descriptor.

A SID MUST have revision 1 and 1–15 subauthorities, and all of them MUST lie inside the descriptor. An ACL MUST have revision 2, a zero Sbz1 byte, and an AclSize of at least 8 that fits inside the descriptor. Each of its AceCount ACEs MUST have a 4-byte header with an AceSize of at least 4, and MUST lie inside AclSize.

8.5 Subkey indexes

An index record starts with a u16 signature and a u16 Count, followed by Count entries. Count MUST be at least 1, and all entries MUST fit into the cell.

Record Entry Points to
ri (index root) u32 Cell further index records of any type
li (leaf) u32 Cell key nodes
lf (fast leaf) u32 Cell, u8 NameHint[4] key nodes
lh (hash leaf) u32 Cell, u32 HashKey key nodes
  • Within one li or lf leaf, keys MUST be sorted in strictly increasing order of name (§9.3).
  • Within one lh leaf, entries MUST be sorted in non-decreasing order of HashKey. Equal hashes are allowed.
  • No ordering is imposed across the leaves of an index root.
  • NameHint holds the low bytes of the first min(4, characters) upcased name characters (§9.2). The remaining bytes are zero.
  • HashKey MUST equal the hash of the key's name (§9.4).
  • Writers SHOULD keep li records at or below 1014 entries and lf, lh and ri records at or below 507 entries, splitting a full leaf under an index root. Readers accept any record that fits into its cell.
8.6 Value list

A raw cell holding ValueList.Count u32 cell indexes of vk records. The cell MUST hold at least 4 × Count payload bytes.

9. Names

9.1 Encodings
  • UTF-16LE. NameLength bytes form NameLength / 2 characters. NameLength MUST be even.
  • Compressed. Used when KEY_COMP_NAME or VALUE_COMP_NAME is set. Each byte is one character, zero-extended to 16 bits. NameLength may be odd.
  • Names are not terminated and MUST NOT contain the character U+0000.
  • Names are stored as written. Comparisons are case-insensitive.
9.2 Upcase table

XTHV1 pins its own fixed upcase mapping. It is not the full Unicode mapping:

  • U+0061–U+007A (a–z) map to U+0041–U+005A.
  • U+00E0–U+00FE, except U+00F7, map to the code point minus 0x20.
  • U+00FF (ÿ) maps to U+0178 (Ÿ).
  • Every other code point maps to itself.

Characters outside these ranges therefore compare case-sensitively. For example, ł and Ł are different characters to XTHV1. Writers and readers MUST use exactly this table.

9.3 Comparison

Two names are compared character by character as upcased 16-bit values. The first difference decides. If one name is a prefix of the other, the shorter one orders first. There is no locale and no collation.

9.4 Hash
hash = 0
for each character c of the name:
    hash = (37 × hash + upcase(c)) mod 2³²

10. Whole-Image Rules

A conforming image satisfies the following rules in addition to the per-record rules above. A full traversal from RootCell is required to check them.

  1. Reachability. Every allocated cell is reached by the traversal from the root key. An unreachable allocated cell makes the image invalid.
  2. Single ownership. Every value list, value node, value data cell, class cell, index record, db record, chunk list and chunk is referenced exactly once in the whole image. Security records are the only exception.
  3. A proper tree. Every key node is reached exactly once, and its Parent field names the key that reached it. There are no cycles through keys or indexes.
  4. Unique names. No two subkeys of one key, in any of its leaves, have equal names under §9.3. This also applies when their hashes collide. No two values of one key have equal names.
  5. Stable references only. No cell index stored in the image has bit 31 set.
  6. Zeroed free space. Every free cell has a zero payload.

11. Canonical Form

Hashes cover every byte, so writers MUST produce canonical bytes. The rules of §10 and the following ones apply:

  1. Free cell payloads are zero.
  2. Reserved fields are zero. This covers the superblock reserved areas, map node reserved bytes, unused map entries, the tails of hash fields, bin reserved fields, sk.Reserved and descriptor Sbz1 bytes.
  3. Stable key nodes store SubKeyCounts[1] = 0, SubKeyLists[1] = HCELL_NIL and WorkVar = 0, regardless of the in-memory values. If a key node spans two logical pages, each page receives the canonical bytes of the part it contains.
  4. Runtime-only flags (KEY_VOLATILE, KEY_HIVE_EXIT, KEY_HIVE_ENTRY) never appear on disk.
  5. The padding at the end of big data chunks is zero.
  6. Raw value data is opaque. It MUST NOT be rewritten, even if it happens to look like a record.
  7. HiveId is 16 opaque bytes, generated once per hive. It MUST NOT be all zero.

12. Generations, Commits and Recovery

XTHV1 copy-on-write commit

Writer obligations. A commit turns the current generation G into G + 1:

  • The new superblock carries Generation = G + 1 and is written to the slot that does not hold generation G. The first commit of a new hive writes slot A and fills slot B with zeros. A writer MUST stop committing rather than wrap the generation counter.

  • New data pages and map nodes MUST be written to pages that are not reachable from any live generation. Unchanged pages and subtrees are referenced by their existing descriptors, including their original BirthGeneration.

  • The order of durable effects is:

    1. any growth of the file,
    2. all data pages and map nodes,
    3. a durable flush of the data and the file size,
    4. the superblock,
    5. a second durable flush.

    The superblock MUST NOT become durable before the pages it references. Writers MUST NOT assume that a 4096-byte write is atomic: torn pages are caught by hashes, and torn superblocks by slot validation.

  • FilePageLimit MUST be greater than every PBN reachable from either live generation. It may be larger than necessary.

  • After a successful commit, G becomes the previous generation. Pages reachable only from G − 1 are free.

Recovery. Readers recover in three stages:

  1. Slot selection. Torn and absent superblocks are skipped automatically (§3).
  2. Rollback. If the current image fails any later check (map tree, page hashes, bins, records), a reader MAY roll back to the previous image, provided it passes the complete verification itself. Rollback never modifies content. The price is the loss of the last commit. A writer that continues from a rolled-back generation P, after a failed generation D, writes its next commit as Generation = D + 1 into the slot that holds D. Pages reachable only from D are free, and pages shared with P stay protected. Until that commit, every mount performs the same rollback.
  3. Repair. Version 1.0 defines no repair of damaged content. An image that fails both the current and the previous generation cannot be mounted.

13. Versioning and Features

  • Major ≠ 1, Minor ≠ 0 or CellFormat ≠ 1: the file MUST be refused.
  • RequiredFeatures ≠ 0: the file MUST be refused.
  • ReadOnlyFeatures ≠ 0: the file MAY be opened, but only read-only.
  • CompatibleFeatures: ignored by readers.
  • Version 1.0 defines no feature bits. Writers MUST store zero in all three masks.
  • A non-zero byte in a reserved range that readers check is a structural error. Reserved bytes have no forward-compatible meaning in version 1.0.

14. The Empty Hive

The smallest valid hive can be built from this specification alone. It is six pages (24 576 bytes) long:

PBN Content
0 Superblock, slot A: Generation = 1, LogicalBytes = 4096, FilePageLimit = 6, RootCell = 32, MapRoot → PBN 2
1 Slot B, all zero
2 Level-2 node: BaseLpn 0, UsedEntries 1, entry → PBN 3
3 Level-1 node: BaseLpn 0, UsedEntries 1, entry → PBN 4
4 Level-0 node: BaseLpn 0, UsedEntries 1, entry → PBN 5
5 Data page, LPN 0: a single bin

All BirthGeneration values are 1. The bin has FileOffset = 0, Size = 4096 and a zero timestamp. It contains two cells:

  • At offset 32: an allocated cell with Size = −80 holding the root key. The key has no flags, its Parent is 32, its counts and lengths are zero, all cell references are HCELL_NIL, and its name is empty.
  • At offset 112: a free cell with Size = 3984 and a zero payload.

Specification Status

The XTHV1 specification presented here is a draft. The format is implemented and in active use during development, but registry support in ExectOS is still in progress, and the specification may change before the first release that ships it. Any change to on-disk bytes, hash preimages or test vectors will be published together with an updated version of this document.