Skip to main content

fmf_core\scan/
walk_id.rs

1//! Synthetic record numbers for scope-mode (folder-walk) indexing (ADR-0024).
2//!
3//! The $MFT scanner gets a real NTFS FRN per record; a folder walk has none.
4//! But the index keys identity on [`crate::index::Frn::record`] — the low 48
5//! bits, resolved by liveness (`index/frn.rs`), never on the full reference —
6//! so any stable, collision-resistant 48-bit key per path serves. We hash the
7//! folded absolute path: absolute paths are globally unique, so the low 48
8//! bits stay unique across roots without a separate root id (a root id placed
9//! in the high bits would be discarded by `record()` anyway), and the Phase 2
10//! watcher recomputes the identical key from a changed path with no shared
11//! state. Folding the path makes the key case-insensitive, matching NTFS and
12//! making the walk's and the watcher's spellings agree.
13
14use xxhash_rust::xxh64::xxh64;
15
16/// The low-48-bit synthetic record number for a folded-WTF-8 absolute path.
17///
18/// [`crate::index::Frn::record`] masks to 48 bits, so only these bits steer
19/// identity; the high 16 bits are left zero. Birthday-bound collisions are
20/// ~`n²/2⁴⁹` (well under 0.1% at the scope-mode target of ≤a few hundred
21/// thousand entries); a collision merely shadows one path and self-heals on
22/// the next walk (ADR-0024).
23#[must_use]
24pub fn path_record(folded_abs_path: &[u8]) -> u64 {
25    xxh64(folded_abs_path, 0) & 0x0000_FFFF_FFFF_FFFF
26}