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
// Copyright 2026 James Gober. Licensed under Apache-2.0 OR MIT.
//! Cross-platform durability primitives for the file-backed store.
//!
//! Every supported platform ends up calling the strictest available
//! sync primitive at this layer:
//!
//! | OS | Primitive | Rust call site |
//! |-----------|--------------------------------------------|----------------------------|
//! | Linux | `fsync(2)` (drains the page cache + WAL) | [`std::fs::File::sync_all`] |
//! | macOS | `fcntl(fd, F_FULLFSYNC, 0)` | direct `libc::fcntl` |
//! | Windows | `FlushFileBuffers` | [`std::fs::File::sync_all`] |
//! | other Unix| `fsync(2)` | [`std::fs::File::sync_all`] |
//!
//! macOS is the only platform where the standard library's
//! [`File::sync_all`] is not enough: on Apple silicon and Intel macs
//! both, `fsync` returns once the data has reached the drive's
//! write-back cache, not the platter / flash. The drive controller's
//! cache can be lost on a power cut. `F_FULLFSYNC` is the documented
//! escape hatch — it asks the drive to flush its cache to durable
//! storage before returning. SQLite, Apple's own Core Data, and most
//! embedded databases use it for the same reason.
//!
//! The trade-off is throughput: `F_FULLFSYNC` is materially slower
//! than `fsync` on rotating media, and somewhat slower on SSDs.
//! Callers that prioritise throughput over durability can still get
//! the faster `fsync` semantics by calling `File::sync_all` directly
//! — but the public [`Iqdb::flush`](crate::Iqdb::flush) and
//! [`Iqdb::close`](crate::Iqdb::close) entry points always take the
//! strongest available primitive.
//!
//! [`File::sync_all`]: std::fs::File::sync_all
use File;
use io;
/// Flush the file's user-space buffers to durable storage.
///
/// See the module-level documentation for the per-platform primitive
/// this resolves to. The call is synchronous — it does not return
/// until the OS reports the flush has completed (or has failed).
///
/// # Errors
///
/// Propagates the OS-level error verbatim as `std::io::Error`. Common
/// failures: `ENOSPC` (disk full), `EIO` (hardware error), `EBADF`
/// (file already closed).
pub
// Fallback for cfg combinations the matrix above does not cover.
// All Tier-1 targets (linux / macos / windows on x86_64 + aarch64)
// hit one of the three branches above; this exists only so that
// `cargo check --target some-unknown-os` does not stop the build.