usn_journal_rs/lib.rs
1//! # usn-journal-rs
2//!
3//! A Rust library for manipulating the NTFS/ReFS USN change journal and enumerating the NTFS Master File Table (MFT).
4//!
5//! This crate provides safe, ergonomic abstractions for accessing the USN change journal and MFT records on NTFS volumes.
6//! It enables applications to efficiently monitor, enumerate file system changes on Windows.
7//!
8//! ## Features
9//! - Enumerate USN journal records or MFT entries as Rust iterators
10//! - Resolve file IDs to full paths
11//! - Safe wrappers over Windows API calls
12//!
13//! ## Example: Enumerate USN Journal
14//! ```no_run
15//! use usn_journal_rs::{volume::Volume, journal::UsnJournal};
16//!
17//! let drive_letter = 'C';
18//! let volume = Volume::from_drive_letter(drive_letter).unwrap();
19//! let journal = UsnJournal::new(&volume);
20//! for result in journal.iter().unwrap().take(10) {
21//! match result {
22//! Ok(entry) => println!("USN entry: {entry:?}"),
23//! Err(e) => eprintln!("Error reading entry: {e}"),
24//! }
25//! }
26//! ```
27//!
28//! # Example: Enumerating MFT Entries
29//! ```no_run
30//! use usn_journal_rs::{volume::Volume, mft::Mft};
31//!
32//! let drive_letter = 'C';
33//! let volume = Volume::from_drive_letter(drive_letter).unwrap();
34//! let mft = Mft::new(&volume);
35//! for result in mft.iter().take(10) {
36//! match result {
37//! Ok(entry) => println!("MFT entry: {entry:?}"),
38//! Err(e) => eprintln!("Error reading MFT entry: {e}"),
39//! }
40//! }
41//! ```
42//!
43//! ## Platform
44//! - Windows NTFS/ReFS volumes
45//! - Requires appropriate privileges to access the USN journal
46//!
47//! ## License
48//! MIT License. See [LICENSE](https://github.com/wangfu91/usn-journal-rs/blob/main/LICENSE).
49
50pub mod errors;
51pub mod journal;
52pub mod mft;
53pub mod path;
54mod privilege;
55
56// Re-export commonly used types
57pub use errors::UsnError;
58
59/// A convenient type alias for Results with UsnError.
60pub type UsnResult<T> = std::result::Result<T, UsnError>;
61
62mod time;
63pub mod volume;
64
65pub type Usn = i64;
66
67pub(crate) const DEFAULT_BUFFER_SIZE: usize = 64 * 1024; // 64KB
68
69pub const DEFAULT_JOURNAL_MAX_SIZE: u64 = 32 * 1024 * 1024; // 32MB
70pub const DEFAULT_JOURNAL_ALLOCATION_DELTA: u64 = 8 * 1024 * 1024; // 4MB
71pub const USN_REASON_MASK_ALL: u32 = 0xFFFFFFFF;