Simplify code that finds the root directory

This commit is contained in:
Julian Stecklina 2022-11-22 01:00:36 +01:00
parent ed8509ce9d
commit 172b341a4c
1 changed files with 5 additions and 6 deletions

View File

@ -38,6 +38,8 @@ fn print_logo(output: &mut Output) {
.unwrap(); .unwrap();
} }
// Find the root directory of the given image.
//
// # Safety // # Safety
// //
// TODO Need to find out whether we can open the protocols in safe code. // TODO Need to find out whether we can open the protocols in safe code.
@ -65,7 +67,7 @@ unsafe fn root_directory(image: Handle, boot_services: &BootServices) -> Result<
let mut device_path: &DevicePath = device_path.deref(); let mut device_path: &DevicePath = device_path.deref();
let fs_handle = boot_services.locate_device_path::<SimpleFileSystem>(&mut device_path)?; let fs_handle = boot_services.locate_device_path::<SimpleFileSystem>(&mut device_path)?;
let mut file_system_raw = boot_services.open_protocol::<SimpleFileSystem>( let mut file_system = boot_services.open_protocol::<SimpleFileSystem>(
OpenProtocolParams { OpenProtocolParams {
handle: fs_handle, handle: fs_handle,
agent: image, agent: image,
@ -74,10 +76,7 @@ unsafe fn root_directory(image: Handle, boot_services: &BootServices) -> Result<
OpenProtocolAttributes::Exclusive, OpenProtocolAttributes::Exclusive,
)?; )?;
let file_system: &mut SimpleFileSystem = &mut file_system_raw; file_system.open_volume()
let root = file_system.open_volume()?;
Ok(root)
} }
#[entry] #[entry]
@ -104,7 +103,7 @@ fn main(handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
let bytes_read = file.read(&mut buf).unwrap(); let bytes_read = file.read(&mut buf).unwrap();
let data = &buf[0..bytes_read]; let data = &buf[0..bytes_read];
debug!("Data: {}", alloc::str::from_utf8(&data).unwrap()); debug!("Data: {}", alloc::str::from_utf8(data).unwrap());
Status::SUCCESS Status::SUCCESS
} }