//! Typed configuration schema for zosstorage. //! //! Mirrors docs in [docs/SCHEMA.md](docs/SCHEMA.md) and is loaded/validated by //! [fn load_and_merge()](src/config/loader.rs:1) and [fn validate()](src/config/loader.rs:1). // // REGION: API // api: types::Topology { BtrfsSingle, BcachefsSingle, DualIndependent, Bcachefs2Copy, SsdHddBcachefs, BtrfsRaid1 } // api: types::Config { logging, device_selection, topology, partitioning, filesystem, mount, report } // api: types::Partitioning { alignment_mib, require_empty_disks, bios_boot, esp, data, cache } // api: types::FsOptions { btrfs, bcachefs, vfat } // REGION: API-END // // REGION: RESPONSIBILITIES // - Define serde-serializable configuration types and enums used across modules. // - Keep field names and enums stable; update docs/SCHEMA.md when public surface changes. // REGION: RESPONSIBILITIES-END use serde::{Deserialize, Serialize}; use clap::ValueEnum; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct LoggingConfig { /// Log level: "error" | "warn" | "info" | "debug" pub level: String, // default "info" /// When true, also log to /run/zosstorage/zosstorage.log pub to_file: bool, // default false } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct DeviceSelection { /// Regex patterns to include device paths (Rust regex). pub include_patterns: Vec, /// Regex patterns to exclude device paths. pub exclude_patterns: Vec, /// Whether to include removable devices (future). pub allow_removable: bool, /// Minimum device size (GiB) to consider eligible. pub min_size_gib: u64, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, ValueEnum)] #[serde(rename_all = "snake_case")] #[value(rename_all = "snake_case")] pub enum Topology { /// Single eligible disk; btrfs on remainder. #[value(alias = "btrfs-single")] BtrfsSingle, /// Single eligible disk; bcachefs on remainder. #[value(alias = "bcachefs-single")] BcachefsSingle, /// Independent btrfs filesystems on each data partition (any number of disks). #[value(alias = "dual-independent")] DualIndependent, /// SSD + HDD; bcachefs with SSD cache/promote and HDD backing. #[value(alias = "ssd-hdd-bcachefs")] SsdHddBcachefs, /// Multi-device bcachefs with two replicas (data+metadata). #[value(alias = "bcachefs2-copy", alias = "bcachefs-2copy", alias = "bcachefs-2-copy")] Bcachefs2Copy, /// Optional mirrored btrfs across two disks when explicitly requested. #[value(alias = "btrfs-raid1")] BtrfsRaid1, } impl std::fmt::Display for Topology { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let s = match self { Topology::BtrfsSingle => "btrfs_single", Topology::BcachefsSingle => "bcachefs_single", Topology::DualIndependent => "dual_independent", Topology::SsdHddBcachefs => "ssd_hdd_bcachefs", Topology::Bcachefs2Copy => "bcachefs2_copy", Topology::BtrfsRaid1 => "btrfs_raid1", }; f.write_str(s) } } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct BiosBootSpec { /// Whether to create a tiny BIOS boot partition. pub enabled: bool, /// Size in MiB (default 1). pub size_mib: u64, /// GPT partition name (e.g., "zosboot"). pub gpt_name: String, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct EspSpec { /// ESP size in MiB (default 512). pub size_mib: u64, /// Filesystem label for ESP (ZOSBOOT). pub label: String, /// GPT partition name (e.g., "zosboot"). pub gpt_name: String, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct DataSpec { /// GPT partition name for data (e.g., "zosdata"). pub gpt_name: String, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct CacheSpec { /// GPT partition name for cache partitions (e.g., "zoscache"). pub gpt_name: String, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Partitioning { /// Alignment in MiB (default 1 MiB). pub alignment_mib: u64, /// Abort if any target disk is not empty (default true). pub require_empty_disks: bool, /// BIOS boot partition spec. pub bios_boot: BiosBootSpec, /// ESP partition spec. pub esp: EspSpec, /// Data partition spec. pub data: DataSpec, /// Cache partition spec (only in ssd_hdd_bcachefs). pub cache: CacheSpec, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct BtrfsOptions { /// Filesystem label (ZOSDATA). pub label: String, /// Compression string (e.g., "zstd:3"). pub compression: String, /// "none" | "raid1" pub raid_profile: String, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct BcachefsOptions { /// Filesystem label (ZOSDATA). pub label: String, /// "promote" | "writeback" (if supported). pub cache_mode: String, /// Compression algorithm (e.g., "zstd"). pub compression: String, /// Checksum algorithm (e.g., "crc32c"). pub checksum: String, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct VfatOptions { /// Filesystem label (ZOSBOOT). pub label: String, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct FsOptions { /// btrfs tuning. pub btrfs: BtrfsOptions, /// bcachefs tuning. pub bcachefs: BcachefsOptions, /// vfat tuning for ESP. pub vfat: VfatOptions, } #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum MountSchemeKind { /// Mount under /var/cache/ PerUuid, /// Reserved for future custom mappings. Custom, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct MountScheme { /// Base directory (default: /var/cache). pub base_dir: String, /// Scheme kind (PerUuid | Custom (reserved)). pub scheme: MountSchemeKind, /// When true, write /etc/fstab entries (disabled by default). pub fstab_enabled: bool, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ReportOptions { /// Path for JSON state report (default: /run/zosstorage/state.json). pub path: String, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Config { /// Schema version (start at 1). pub version: u32, /// Logging configuration. pub logging: LoggingConfig, /// Device selection and filtering rules. pub device_selection: DeviceSelection, /// Desired topology mode. pub topology: Topology, /// Partitioning parameters. pub partitioning: Partitioning, /// Filesystem options and tuning. pub filesystem: FsOptions, /// Mount scheme and fstab policy. pub mount: MountScheme, /// Report output configuration. pub report: ReportOptions, }