Introduces the SequentialSink / RandomAccessSink trait pair under io::sink and an open_for_mkv dispatch helper that picks WritebackFile on Linux+NFS and LocalFileSink everywhere else. LocalFileSink wraps BufWriter<File> with a 4 MiB buffer and exposes a per-OS preallocate path (fallocate on Linux, F_PREALLOCATE on macOS, no-op fallback). Adds platform::fs_type::detect with a per-OS split (statfs on Linux / macOS, UNC heuristic on Windows, Unknown elsewhere) so construction- site dispatch has a single primitive to call. Blanket impls cover the common shapes: any Write+Send is a SequentialSink, and any SequentialSink+Seek is a RandomAccessSink. WritebackFile satisfies the random-access trait via the blanket impl without needing an explicit per-type impl. No callers wired yet — the mux::resolve construction sites stay on WritebackFile pending Phase 3. Tests: 5 new sink/preallocate tests + 3 fs_type tests (1 ignored, needs a real NFS mount). cargo +1.86 fmt + clippy + tests all green.
28 lines
897 B
Rust
28 lines
897 B
Rust
//! Per-OS extent preallocation. Best-effort; failures are logged at
|
|
//! debug and otherwise swallowed because the file is still usable
|
|
//! without the size reservation — only large-file fragmentation gets
|
|
//! marginally worse.
|
|
|
|
use std::fs::File;
|
|
|
|
#[cfg(target_os = "linux")]
|
|
mod linux;
|
|
#[cfg(target_os = "macos")]
|
|
mod macos;
|
|
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
|
mod other;
|
|
|
|
#[cfg(target_os = "linux")]
|
|
use linux::preallocate_impl;
|
|
#[cfg(target_os = "macos")]
|
|
use macos::preallocate_impl;
|
|
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
|
use other::preallocate_impl;
|
|
|
|
/// Reserve `size_bytes` of disk space for `file`'s on-disk extents.
|
|
/// Reported file size is unchanged — writes still grow the file
|
|
/// naturally; only the allocator's extent map is primed.
|
|
pub(super) fn preallocate(file: &File, size_bytes: u64) {
|
|
preallocate_impl(file, size_bytes);
|
|
}
|