From 69370a2f5347daeaafcd6b60cdc650658df847c3 Mon Sep 17 00:00:00 2001 From: Jan De Landtsheer Date: Mon, 13 Oct 2025 10:35:31 +0200 Subject: [PATCH] config: reuse reserved label and GPT name constants --- src/config/loader.rs | 63 ++++++++++++++++++++++++-------------------- src/types.rs | 10 +++++++ 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/src/config/loader.rs b/src/config/loader.rs index 005e8e5..c4cc8f3 100644 --- a/src/config/loader.rs +++ b/src/config/loader.rs @@ -128,43 +128,50 @@ pub fn validate(cfg: &Config) -> Result<()> { } // Reserved GPT names - if cfg.partitioning.esp.gpt_name != "zosboot" { - return Err(Error::Validation( - "partitioning.esp.gpt_name must be 'zosboot'".into(), - )); + if cfg.partitioning.esp.gpt_name != GPT_NAME_ZOSBOOT { + return Err(Error::Validation(format!( + "partitioning.esp.gpt_name must be '{}'", + GPT_NAME_ZOSBOOT + ))); } - if cfg.partitioning.data.gpt_name != "zosdata" { - return Err(Error::Validation( - "partitioning.data.gpt_name must be 'zosdata'".into(), - )); + if cfg.partitioning.data.gpt_name != GPT_NAME_ZOSDATA { + return Err(Error::Validation(format!( + "partitioning.data.gpt_name must be '{}'", + GPT_NAME_ZOSDATA + ))); } - if cfg.partitioning.cache.gpt_name != "zoscache" { - return Err(Error::Validation( - "partitioning.cache.gpt_name must be 'zoscache'".into(), - )); + if cfg.partitioning.cache.gpt_name != GPT_NAME_ZOSCACHE { + return Err(Error::Validation(format!( + "partitioning.cache.gpt_name must be '{}'", + GPT_NAME_ZOSCACHE + ))); } // BIOS boot name is also 'zosboot' per current assumption - if cfg.partitioning.bios_boot.gpt_name != "zosboot" { - return Err(Error::Validation( - "partitioning.bios_boot.gpt_name must be 'zosboot'".into(), - )); + if cfg.partitioning.bios_boot.gpt_name != GPT_NAME_ZOSBOOT { + return Err(Error::Validation(format!( + "partitioning.bios_boot.gpt_name must be '{}'", + GPT_NAME_ZOSBOOT + ))); } // Reserved filesystem labels - if cfg.filesystem.vfat.label != "ZOSBOOT" { - return Err(Error::Validation( - "filesystem.vfat.label must be 'ZOSBOOT'".into(), - )); + if cfg.filesystem.vfat.label != LABEL_ZOSBOOT { + return Err(Error::Validation(format!( + "filesystem.vfat.label must be '{}'", + LABEL_ZOSBOOT + ))); } - if cfg.filesystem.btrfs.label != "ZOSDATA" { - return Err(Error::Validation( - "filesystem.btrfs.label must be 'ZOSDATA'".into(), - )); + if cfg.filesystem.btrfs.label != LABEL_ZOSDATA { + return Err(Error::Validation(format!( + "filesystem.btrfs.label must be '{}'", + LABEL_ZOSDATA + ))); } - if cfg.filesystem.bcachefs.label != "ZOSDATA" { - return Err(Error::Validation( - "filesystem.bcachefs.label must be 'ZOSDATA'".into(), - )); + if cfg.filesystem.bcachefs.label != LABEL_ZOSDATA { + return Err(Error::Validation(format!( + "filesystem.bcachefs.label must be '{}'", + LABEL_ZOSDATA + ))); } // Mount scheme diff --git a/src/types.rs b/src/types.rs index d01632e..34beeed 100644 --- a/src/types.rs +++ b/src/types.rs @@ -18,6 +18,16 @@ use clap::ValueEnum; use serde::{Deserialize, Serialize}; +/// Reserved filesystem labels. +pub const LABEL_ZOSBOOT: &str = "ZOSBOOT"; +pub const LABEL_ZOSDATA: &str = "ZOSDATA"; +pub const LABEL_ZOSCACHE: &str = "ZOSCACHE"; + +/// Reserved GPT partition names. +pub const GPT_NAME_ZOSBOOT: &str = "zosboot"; +pub const GPT_NAME_ZOSDATA: &str = "zosdata"; +pub const GPT_NAME_ZOSCACHE: &str = "zoscache"; + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct LoggingConfig { /// Log level: "error" | "warn" | "info" | "debug"