Refactor embedded config extraction

This commit is contained in:
Julian Stecklina 2022-11-23 17:57:43 +01:00
parent fa331d8b98
commit dcca50d14f
1 changed files with 7 additions and 11 deletions

View File

@ -13,11 +13,11 @@ use pe_section::pe_section_as_string;
use uefi::{ use uefi::{
prelude::*, prelude::*,
proto::{ proto::{
console::text::Output, console::text::{self, Output},
loaded_image::LoadedImage, loaded_image::LoadedImage,
media::file::{File, FileAttribute, FileMode, RegularFile}, media::file::{File, FileAttribute, FileMode, RegularFile},
}, },
CString16, CString16, Error,
}; };
use crate::{ use crate::{
@ -48,10 +48,8 @@ struct EmbeddedConfiguration {
initrd_filename: CString16, initrd_filename: CString16,
} }
impl TryFrom<&mut RegularFile> for EmbeddedConfiguration { impl EmbeddedConfiguration {
type Error = uefi::Error; fn new(file: &mut RegularFile) -> Result<Self, Error> {
fn try_from(file: &mut RegularFile) -> Result<Self, Self::Error> {
file.set_position(0)?; file.set_position(0)?;
let file_data = read_all(file)?; let file_data = read_all(file)?;
@ -73,11 +71,9 @@ fn main(handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
print_logo(system_table.stdout()); print_logo(system_table.stdout());
let config: EmbeddedConfiguration = { let config: EmbeddedConfiguration =
let mut booted_image = booted_image_file(system_table.boot_services()).unwrap(); EmbeddedConfiguration::new(&mut booted_image_file(system_table.boot_services()).unwrap())
.unwrap();
(&mut booted_image).try_into().unwrap()
};
let mut file_system = system_table let mut file_system = system_table
.boot_services() .boot_services()