zinit 0.3.6

Process supervisor with dependency management
Documentation
//! Boot mode detection (EFI vs BIOS)

use std::path::Path;

/// Boot mode of the system
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BootMode {
    /// UEFI boot mode
    Efi,
    /// Legacy BIOS boot mode
    Bios,
}

impl BootMode {
    /// Detect the current boot mode
    pub fn detect() -> Self {
        if is_efi_boot() {
            BootMode::Efi
        } else {
            BootMode::Bios
        }
    }

    /// Check if running in EFI mode
    pub fn is_efi(&self) -> bool {
        matches!(self, BootMode::Efi)
    }

    /// Check if running in BIOS mode
    pub fn is_bios(&self) -> bool {
        matches!(self, BootMode::Bios)
    }
}

/// Check if the system booted in EFI mode
///
/// Simply checks for the existence of /sys/firmware/efi
fn is_efi_boot() -> bool {
    Path::new("/sys/firmware/efi").exists()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_boot_mode_detection() {
        // This test just ensures the detection doesn't panic
        let mode = BootMode::detect();
        assert!(mode.is_efi() || mode.is_bios());
    }
}