irontide_core/preallocate_mode.rs
1use serde::{Deserialize, Serialize};
2
3/// Pre-allocation strategy for torrent files.
4///
5/// Sibling of [`StorageMode`](crate::StorageMode); both live in
6/// `irontide-core` so configuration crates can reference them without
7/// depending on `irontide-storage`.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
9pub enum PreallocateMode {
10 /// No pre-allocation — files created sparse via `set_len`.
11 #[default]
12 None,
13 /// Reserve extents without write amplification (`FALLOC_FL_KEEP_SIZE` on Linux).
14 /// Falls back to `None` on unsupported filesystems.
15 Sparse,
16 /// Full allocation — `fallocate(0)` on Linux, falls back to writing zeros.
17 Full,
18}
19
20impl From<bool> for PreallocateMode {
21 fn from(preallocate: bool) -> Self {
22 if preallocate { Self::Full } else { Self::None }
23 }
24}