1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//! ReFS v3 metadata-block (page) header and its checksum descriptor.
//!
//! Every ReFS metadata block is a self-describing 16 KiB page (four 4096-byte
//! clusters). The page begins with a **format-version-3 metadata block header**
//! (80 bytes), byte-verified against a real ReFS v3.14 volume and consistent
//! with libyal `libfsrefs`:
//!
//! ```text
//! off size field
//! 0 4 block signature ("SUPB"/"CHKP"/"MSB+")
//! 4 4 unknown (observed 2)
//! c 4 volume signature
//! 10 8 virtual allocator clock
//! 18 8 tree update clock
//! 20 8 first block number (== the block's SELF number)
//! 28 8 second block number (redundancy copy)
//! 30 8 third block number
//! 38 8 fourth block number
//! 40 16 128-bit table identifier
//! ```
//!
//! # Checksums (CRC-32C and CRC-64/ECMA-182)
//!
//! ReFS protects each metadata block with a checksum recorded in the *metadata
//! block reference* that points to it (a 48-byte structure whose checksum
//! descriptor gives `type` — `1` = CRC-32C, `2` = CRC64-ECMA-182 — plus the
//! stored checksum bytes). This module exposes the two checksum **algorithms**
//! (validated against their published check values) and a range-explicit
//! [`MetaBlock::verify_crc32c`] verifier.
//!
//! **Honest limitation (Tier-2 reverse-engineering).** The exact byte *range*
//! ReFS runs the block checksum over is **not documented** in the
//! reverse-engineered references, and an empirical search over the real v3.14
//! volume did not reproduce the stored value from any obvious contiguous range
//! (starts `{0, 80, 208}` × every end, checksum-field zeroed or not, both CRC
//! init conventions). Rather than guess a range and fabricate a
//! `Some(false)` "corruption" verdict on every clean block (the LZNT1 trap),
//! this crate exposes the checksum *descriptor* and the checksum *algorithms*,
//! and verifies only over a **caller-supplied explicit range** — so a future
//! phase that pins the range (against `libfsrefs`/Prade or a larger corpus) can
//! call [`MetaBlock::verify_crc32c`] with the correct bounds. Automatic
//! whole-block verification stays deliberately absent until the range is
//! confirmed.
use ;
use crate;
use crateRefsError;
/// The ReFS v3 metadata page (block) size in bytes: 16 KiB (four 4096-byte
/// clusters), verified on the real v3.14 volume.
pub const REFS_METADATA_PAGE_SIZE: usize = 16384;
/// Length of the format-version-3 metadata block header.
const V3_HEADER_LEN: usize = 80;
/// Offset of the first (self) block number within the v3 header.
const SELF_BLOCK_NUMBER_OFFSET: usize = 0x20;
/// CRC-32C engine (iSCSI / Castagnoli, polynomial `0x1edc6f41`), the ReFS
/// checksum type `1`.
const CRC32C: = new;
/// CRC-64/ECMA-182 engine, the ReFS checksum type `2`.
const CRC64: = new;
/// ReFS metadata-block checksum type `1`: CRC-32C (Castagnoli).
/// ReFS metadata-block checksum type `2`: CRC-64/ECMA-182.
/// A ReFS v3 self-describing metadata-block header.
///
/// Carries the four-byte block signature and the block's own (self) block
/// number. `#[non_exhaustive]` so later phases add the redundancy block numbers,
/// table identifier, and clocks without a breaking change.