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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
//! # fsys
//!
//! Adaptive file and directory IO for Rust — fast, hardware-aware,
//! multi-strategy.
//!
//! `fsys` is a low-level filesystem abstraction designed for storage
//! engines, databases, and any application that needs predictable,
//! high-performance file IO with explicit control over durability
//! strategy.
//!
//! ## Three tiers of API
//!
//! ### Tier 1 — one-shot helpers
//!
//! The simplest path. Uses a lazily-initialised default [`Handle`]
//! configured with [`Method::Auto`].
//!
//! ```no_run
//! # fn example() -> fsys::Result<()> {
//! fsys::quick::write("/tmp/greeting.txt", b"hello")?;
//! let data = fsys::quick::read("/tmp/greeting.txt")?;
//! assert_eq!(data, b"hello");
//! # Ok(())
//! # }
//! ```
//!
//! ### Tier 2 — handle-based
//!
//! The primary API for everything beyond one-shot use. Construct a
//! [`Handle`] with [`new()`] (default `Method::Auto`) or
//! [`with(method)`](with).
//!
//! ```no_run
//! # fn example() -> fsys::Result<()> {
//! let fs = fsys::new()?; // Method::Auto
//! let fs = fsys::with(fsys::Method::Data)?; // explicit method
//! fs.write("/tmp/world.txt", b"world")?;
//! let read = fs.read("/tmp/world.txt")?;
//! # Ok(())
//! # }
//! ```
//!
//! ### Tier 3 — full builder
//!
//! For advanced configuration: custom root, dev/prod mode,
//! per-handle batch knobs, io_uring queue depth, buffer pool size.
//!
//! ```no_run
//! # fn example() -> fsys::Result<()> {
//! let fs = fsys::builder()
//! .method(fsys::Method::Direct)
//! .root("/var/lib/myapp")
//! .mode(fsys::Mode::Prod)
//! .build()?;
//! # Ok(())
//! # }
//! ```
//!
//! ## What's in 0.9.0 (release candidate for 1.0)
//!
//! 0.9.0 is the **release candidate for 1.0**. Real-world testing
//! begins from this tag. The public API documented in
//! [`docs/API.md`](https://github.com/jamesgober/fsys-rs/blob/main/docs/API.md)
//! is the 1.0 target shape.
//!
//! - **Journal substrate** — open-once append-only log for WAL-style
//! workloads. [`JournalHandle::append`](crate::JournalHandle::append)
//! is the high-throughput durable-write primitive that databases /
//! queues / ledgers should use; [`Handle::write`] is the
//! atomic-replace primitive for individual files. Three throughput
//! tiers ship: cross-platform sync, lock-free concurrent append,
//! and native io_uring async on Linux.
//! - **Direct-IO journal opt-in** —
//! [`JournalOptions::direct(true)`](crate::JournalOptions::direct)
//! routes appends through a sector-aligned in-memory log buffer
//! (the InnoDB / WiredTiger pattern), bypassing the kernel page
//! cache for zero-copy DMA on NVMe.
//! - **Production-grade frame format** — every record wrapped in
//! a 12-byte frame with CRC-32C (Castagnoli, RFC 3720 KAT-verified).
//! Tail-truncation detection via [`JournalTailState`].
//! - **Crash-safety integration tests** — process-kill harness
//! validates durability claims under real crashes.
//! - **Optional `tracing` feature** for production observability.
//!
//! ## What shipped in 0.6.0–0.7.0
//!
//! 0.6.0 finished the public API and 0.7.0 (the optimization
//! phase) tuned it. Every method that will ship at 1.0 is
//! present from 0.7.0 onward.
//!
//! - **Async layer** (gated behind the `async` Cargo feature). Every
//! sync method gets an `_async` sibling backed by
//! `tokio::task::spawn_blocking`; async batch ops route through the
//! per-handle dispatcher via `tokio::sync::oneshot`.
//! - **NVMe passthrough flush** on Linux (`NVME_IOCTL_IO_CMD`) and
//! Windows (`IOCTL_STORAGE_PROTOCOL_COMMAND`). Capability detection
//! at first Direct op; transparent fallback to `fdatasync` /
//! `WRITE_THROUGH` on incapable hardware. macOS uses
//! `F_NOCACHE + F_FULLFSYNC` (Apple does not expose NVMe
//! passthrough).
//! - **Completion CRUD:** [`Handle::write_copy`] (atomic-swap with
//! metadata preservation), [`Handle::scan`], [`Handle::find`]
//! (glob), [`Handle::count`], [`Handle::truncate`],
//! [`Handle::rename`].
//! - **`Handle::active_durability_primitive()`** + [`mod@primitive`]
//! constants — the canonical name of the durability primitive
//! currently in effect.
//!
//! ## What shipped earlier
//!
//! - **0.5.x:** real hardware probe, `Method::Mmap`, `Method::Direct`
//! with io_uring on Linux, per-method crash tests, per-handle
//! aligned buffer pool. 0.5.1 unstubbed the real io_uring path.
//! - **0.4.0:** dual-pipeline model. Solo lane (single writes via
//! the calling thread) + group lane (batch ops via a per-handle
//! dispatcher).
//! - **0.3.0:** [`Handle`], [`Builder`], full file/dir CRUD,
//! cross-platform Direct IO with observable fallback.
//! - **0.2.0:** [`Error`] / [`Result`], hardware probe stubs, OS
//! detection, path resolution.
//!
//! ## Choosing a method
//!
//! | If you... | Pick |
//! |---|---|
//! | Don't know what you need | [`Method::Auto`] |
//! | Need universal correctness floor | [`Method::Sync`] |
//! | Want Linux's `fdatasync` speedup | [`Method::Data`] |
//! | Have read-heavy random-access workloads | [`Method::Mmap`] |
//! | Need < 100 µs single-write latency on NVMe | [`Method::Direct`] |
//!
//! See [`docs/METHODS.md`](https://github.com/jamesgober/fsys-rs/blob/main/docs/METHODS.md)
//! for the full per-platform matrix and the `Auto` decision ladder.
//!
//! ## Crash safety
//!
//! Every write API (`write`, `write_copy`, `write_batch`,
//! `Batch::commit`) uses an atomic temp-file + rename pattern. The
//! target file is either entirely the old payload (kill before
//! rename) or entirely the new payload (kill after rename). Never
//! torn. See [`docs/CRASH-SAFETY.md`](https://github.com/jamesgober/fsys-rs/blob/main/docs/CRASH-SAFETY.md)
//! for the full per-method contract.
//!
//! ## Async (feature `async`)
//!
//! ```no_run
//! # async fn example() -> fsys::Result<()> {
//! # #[cfg(feature = "async")] {
//! let fs = std::sync::Arc::new(fsys::builder().build()?);
//! fs.clone().write_async("/tmp/async.dat", b"payload".to_vec()).await?;
//! let data = fs.clone().read_async("/tmp/async.dat").await?;
//! # }
//! # Ok(())
//! # }
//! ```
//!
//! Calling sync `fs.write()` from inside a tokio runtime is supported
//! (it just blocks the calling thread). Calling async
//! `fs.write_async()` outside a tokio runtime returns
//! [`Error::AsyncRuntimeRequired`] rather than panicking.
pub
pub
pub
/// Internal fuzz-test surface. Wraps `pub(crate)` helpers under
/// `cfg(feature = "fuzz")` so the cargo-fuzz workspace can reach
/// them without making them part of the public 1.0 API surface.
/// Subject to change without semver guarantees; do not use from
/// non-fuzz code.
pub use crateAdvice;
pub use crateBatch;
pub use crate;
pub use crate;
pub use crateHandle;
pub use crate;
pub use crate;
pub use crateMethod;
pub use crateMode;
pub use crateAsyncSubstrate;
/// Creates a default [`Handle`] using [`Method::Auto`] and no root scope.
///
/// Equivalent to `Builder::new().build()`.
///
/// # Errors
///
/// Returns an error if method validation fails (this will not happen for
/// the default [`Method::Auto`] setting).
/// Creates a [`Handle`] using the specified [`Method`].
///
/// # Errors
///
/// Returns [`Error::UnsupportedMethod`] if a reserved method variant is
/// supplied.
/// Returns a new [`Builder`] with default settings.
///
/// # Example
///
/// ```
/// # fn example() -> fsys::Result<()> {
/// let handle = fsys::builder().method(fsys::Method::Sync).build()?;
/// # Ok(())
/// # }
/// ```
/// Library version, matching the crate version declared in `Cargo.toml`.
pub const VERSION: &str = env!;