bootmgr_rs_core/config/parsers/
shell.rs

1//! An auto detector for the UEFI shell (located at /shellx64.efi)
2
3use alloc::{format, vec::Vec};
4use uefi::{CStr16, Handle, cstr16};
5
6use crate::{
7    config::{
8        Config,
9        builder::ConfigBuilder,
10        parsers::{ConfigParser, Parsers},
11    },
12    system::{fs::UefiFileSystem, helper::get_path_cstr},
13};
14
15/// The configuration prefix.
16const SHELL_PREFIX: &CStr16 = cstr16!(""); // the root of the partition
17
18/// The configuration suffix.
19const SHELL_SUFFIX: &str = ".efi";
20
21/// A "parser" for detecting shellx64.efi
22pub struct ShellConfig;
23
24impl ConfigParser for ShellConfig {
25    fn parse_configs(fs: &mut UefiFileSystem, handle: Handle, configs: &mut Vec<Config>) {
26        let Ok(path) = get_path_cstr(SHELL_PREFIX, cstr16!("shellx64.efi")) else {
27            return;
28        };
29        if fs.exists(&path) {
30            let efi_path = format!("{SHELL_PREFIX}\\shellx64.efi");
31            let config = ConfigBuilder::new("shellx64.efi", SHELL_SUFFIX)
32                .efi_path(efi_path)
33                .title("UEFI Shell")
34                .sort_key("shell")
35                .fs_handle(handle)
36                .origin(Parsers::Shell);
37
38            configs.push(config.build());
39        }
40    }
41}