use std::path::Path;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BootMode {
Efi,
Bios,
}
impl BootMode {
pub fn detect() -> Self {
if is_efi_boot() {
BootMode::Efi
} else {
BootMode::Bios
}
}
pub fn is_efi(&self) -> bool {
matches!(self, BootMode::Efi)
}
pub fn is_bios(&self) -> bool {
matches!(self, BootMode::Bios)
}
}
fn is_efi_boot() -> bool {
Path::new("/sys/firmware/efi").exists()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_boot_mode_detection() {
let mode = BootMode::detect();
assert!(mode.is_efi() || mode.is_bios());
}
}