1use alloc::vec::Vec;
2use anyhow::{Result, anyhow};
3use uefi::{
4 boot::{
5 ScopedProtocol, get_handle_for_protocol, get_image_file_system, image_handle,
6 open_protocol_exclusive,
7 },
8 fs::{FileSystem, Path},
9 proto::Protocol,
10};
11
12pub fn read_file(path: impl AsRef<Path>) -> Result<Vec<u8>> {
13 Ok(FileSystem::new(get_image_file_system(image_handle())?).read(path)?)
14}
15
16pub fn get_and_open_protocol<T: Protocol>() -> Result<ScopedProtocol<T>> {
17 let handle = get_handle_for_protocol::<T>()?;
18 open_protocol_exclusive::<T>(handle).map_err(|err| anyhow!("{err}"))
19}