Skip to main content

efivar_fix/boot/
reader.rs

1//! This module contains functions to read boot entries. Actual boot entry parsing is done in [`crate::boot::parse`]
2
3use byteorder::{LittleEndian, ReadBytesExt};
4
5use crate::{boot::BootVarFormat, efi::Variable, Error, VarReader};
6
7use super::boot_entry_iter::BootEntriesIterator;
8
9pub trait BootVarReader {
10    fn get_boot_order(&self) -> crate::Result<Vec<u16>>;
11    fn get_boot_entries<'a>(&'a self) -> crate::Result<BootEntriesIterator<'a>>;
12}
13
14impl<T: VarReader> BootVarReader for T {
15    fn get_boot_order(&self) -> crate::Result<Vec<u16>> {
16        let (data, _) = self.read(&Variable::new("BootOrder"))?;
17
18        assert!(data.len() % 2 == 0); // ids are u16 values, so it must be an even number of u8
19
20        let mut ids = vec![0u16; data.len() / 2];
21        data.as_slice()
22            .read_u16_into::<LittleEndian>(&mut ids)
23            .map_err(Error::UnknownIoError)?;
24
25        let ids_formatted: Vec<String> = ids.iter().map(|id| id.boot_id_format()).collect();
26        log::debug!("Queried BootOrder: [{}]", ids_formatted.join(", "));
27        Ok(ids)
28    }
29
30    fn get_boot_entries<'a>(&'a self) -> crate::Result<BootEntriesIterator<'a>> {
31        BootEntriesIterator::new(self)
32    }
33}