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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
//! # fsys
//!
//! Foundation-tier filesystem IO for Rust storage engines: journal
//! substrate, io_uring, NVMe passthrough, atomic writes, cross-platform
//! durability.
//!
//! `fsys` sits one layer below your data structures and one layer above
//! [`std::fs`]. It pairs an explicit durability model (you choose a
//! [`Method`], you get the platform's best matching primitive, you
//! observe any fallback via [`Handle::active_durability_primitive`])
//! with a journal substrate built for write-ahead-log workloads.
//!
//! ## Quickstart
//!
//! Append-only journal — the canonical WAL pattern:
//!
//! ```no_run
//! # fn example() -> fsys::Result<()> {
//! use std::sync::Arc;
//!
//! let fs = Arc::new(fsys::builder().build()?);
//! let log = fs.journal("/var/lib/myapp/log.wal")?;
//!
//! let _ = log.append(b"txn 1: insert")?;
//! let _ = log.append(b"txn 2: update")?;
//! let lsn = log.append(b"txn 3: commit")?;
//!
//! // One fsync covers every prior append — group-commit.
//! log.sync_through(lsn)?;
//! # Ok(())
//! # }
//! ```
//!
//! One-shot durable file write, no handle required:
//!
//! ```no_run
//! # fn example() -> fsys::Result<()> {
//! fsys::quick::write("/etc/myapp/config.toml", b"value = 42")?;
//! let data = fsys::quick::read("/etc/myapp/config.toml")?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Three tiers of API
//!
//! ### Tier 1 — one-shot helpers
//!
//! For programs that issue one IO op and don't need a long-lived handle.
//! Backed by a lazily-initialised default [`Handle`] 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. Build a [`Handle`]
//! with [`new()`] (default [`Method::Auto`]) or [`with(method)`](with);
//! share across threads via [`Arc`](std::sync::Arc).
//!
//! ```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, observer hook,
//! workload presets.
//!
//! ```no_run
//! # fn example() -> fsys::Result<()> {
//! let fs = fsys::builder()
//! .method(fsys::Method::Direct)
//! .root("/var/lib/myapp")
//! .mode(fsys::Mode::Prod)
//! .tune_for(fsys::Workload::Database)
//! .build()?;
//! # Ok(())
//! # }
//! ```
//!
//! ## 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 [`Method::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.
//! The [`journal`] substrate adds explicit durability via
//! [`JournalHandle::sync_through`]; group-commit amortises the fsync
//! cost across many appends. 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(())
//! # }
//! ```
//!
//! On Linux + [`Method::Direct`], async ops submit directly to the
//! per-handle io_uring ring — the *native substrate*, observable via
//! [`Handle::async_substrate`] returning [`AsyncSubstrate::NativeIoUring`].
//! Everywhere else, async ops route through `tokio::task::spawn_blocking`
//! ([`AsyncSubstrate::SpawnBlocking`]).
//!
//! 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.
//!
//! ## Cargo features
//!
//! | Feature | Default | Purpose |
//! |---|---|---|
//! | `async` | off | `_async` siblings for every sync method; pulls in `tokio` |
//! | `tracing` | off | Structured spans + events on the write / read / journal hot paths |
//! | `stress` | off | Run `tests/stress.rs` for the full 1-hour soak (CI-nightly only) |
//! | `fuzz` | off | Compile-only flag for fuzz-target wiring; targets live in `fuzz/` |
//!
//! ## Concept reference
//!
//! | Concept | Type / module | Reach for it when... |
//! |---|---|---|
//! | Handle to filesystem | [`Handle`] | Any non-one-shot IO. The primary type. |
//! | Configure handle | [`Builder`] | Custom root, method, tuning, observer. |
//! | Durability strategy | [`Method`] | Five variants: `Sync`, `Data`, `Mmap`, `Direct`, `Auto`. |
//! | Append-only WAL | [`JournalHandle`] | High-throughput durable writes (WAL / ledger / queue). |
//! | Multi-op transaction | [`Batch`] | Group N writes / deletes / copies under one durability barrier. |
//! | One-shot helpers | [`mod@quick`] | Single-call file IO without holding a handle. |
//! | Async layer | `fsys::async_io` (feature `async`) | Tokio integration; `_async` siblings for every sync method. |
//! | Telemetry hook | [`observer::FsysObserver`] | Per-op events (append / sync / write / read). |
//! | Hardware introspection | [`mod@hardware`] | Probe PLP status, atomic-write unit, sector size. |
//! | Errors | [`Error`] / [`Result`] | 21 variants with stable `FS-XXXXX` codes. |
//!
//! ## Version history
//!
//! Per-version deltas live in
//! [`CHANGELOG.md`](https://github.com/jamesgober/fsys-rs/blob/main/CHANGELOG.md).
//! `1.0.0` is the first stable release; the `1.x` line is API-stable
//! and on-disk-format-stable per the contract in
//! [`docs/STABILITY-1.0.md`](https://github.com/jamesgober/fsys-rs/blob/main/docs/STABILITY-1.0.md).
// 0.9.6 audit H-12 — `html_root_url` was previously pinned to a
// specific version string that drifted every release. docs.rs
// handles per-version routing automatically; pinning it here
// just creates a fix-at-version-bump chore that we'd inevitably
// forget. Removed entirely. If a future release needs to
// override docs.rs's default routing (rare), the attribute can
// be re-added at that point with a clear reason.
pub
pub
pub
/// 0.9.7 H-7 — internal OOM-injection allocator hooks.
///
/// **NEVER enable the `oom_inject` feature in production.** Every
/// allocation pays a thread-local lookup + comparison. The
/// feature exists solely to make `tests/oom_injection.rs`
/// compileable; the integration test is the regression guard for
/// `AlignedBuf::new` / `read_all_direct` / other fallible-alloc
/// paths.
///
/// When `oom_inject` is enabled, the global allocator is replaced
/// with `OomInjectingAllocator` from `test_support`. The
/// `OOM_THRESHOLD` thread-local controls injection: allocations
/// of `>= threshold` bytes return `null` (OOM). Tests use the
/// `OomThreshold` RAII guard to set + restore the threshold
/// safely across scope exit (including panics).
static FSYS_OOM_INJECTING_ALLOCATOR: OomInjectingAllocator =
OomInjectingAllocator;
/// 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 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!;