Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7cfaf19

Browse files
Return a SimpleFileSystem from BootServices::get_image_file_system
This reverts a small change from: #472 If using the library without the `alloc` feature enabled, `FileSystem` isn't available, but you might still want access to the image's file system via the underlying protocol. The high-level API is still easily accessible via `FileSystem::new`.
1 parent 0fa5207 commit 7cfaf19

File tree

3 files changed

+43
-38
lines changed

3 files changed

+43
-38
lines changed

‎CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
### Changed
66
- `Input::wait_for_key_event` now returns an `Option<Event>`, and is no longer `const`.
77
- `LoadedImage::device` now returns an `Option<Handle>` and is no longer `const`.
8+
- `BootServices::get_image_file_system` now returns
9+
`ScopedProtocol<SimpleFileSystem>` instead of `fs::FileSystem`.
810

911
## uefi-macros - [Unreleased]
1012

‎uefi-test-runner/src/boot/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloc::string::ToString;
2+
use uefi::fs::FileSystem;
23
use uefi::proto::console::text::Output;
34
use uefi::proto::device_path::media::FilePath;
45
use uefi::proto::device_path::{DevicePath, LoadedImageDevicePath};
@@ -76,11 +77,13 @@ fn test_load_image(bt: &BootServices) {
7677

7778
// Variant A: FromBuffer
7879
{
79-
let mutfs = bt
80+
let fs = bt
8081
.get_image_file_system(bt.image_handle())
8182
.expect("should open file system");
8283
let path = CString16::try_from(image_device_path_file_path.as_str()).unwrap();
83-
let image_data = fs.read(&*path).expect("should read file content");
84+
let image_data = FileSystem::new(fs)
85+
.read(&*path)
86+
.expect("should read file content");
8487
let load_source = LoadImageSource::FromBuffer {
8588
buffer: image_data.as_slice(),
8689
file_path: None,

‎uefi/src/table/boot.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
use super::Revision;
44
use crate::data_types::{Align, PhysicalAddress};
55
use crate::proto::device_path::DevicePath;
6+
use crate::proto::loaded_image::LoadedImage;
7+
use crate::proto::media::fs::SimpleFileSystem;
68
use crate::proto::{Protocol, ProtocolPointer};
79
use crate::{Char16, Error, Event, Guid, Handle, Result, Status, StatusExt};
810
use core::cell::UnsafeCell;
@@ -12,12 +14,9 @@ use core::mem::{self, MaybeUninit};
1214
use core::ops::{Deref, DerefMut};
1315
use core::ptr::NonNull;
1416
use core::{ptr, slice};
17+
1518
#[cfg(feature = "alloc")]
16-
use {
17-
crate::fs::FileSystem,
18-
crate::proto::{loaded_image::LoadedImage, media::fs::SimpleFileSystem},
19-
::alloc::vec::Vec,
20-
};
19+
use alloc::vec::Vec;
2120

2221
pub use uefi_raw::table::boot::{
2322
EventType, InterfaceType, MemoryAttribute, MemoryDescriptor, MemoryType, Tpl,
@@ -1344,6 +1343,38 @@ impl BootServices {
13441343
pub unsafe fn set_mem(&self, buffer: *mut u8, size: usize, value: u8) {
13451344
(self.0.set_mem)(buffer, size, value);
13461345
}
1346+
1347+
/// Retrieves a [`SimpleFileSystem`] protocol associated with the device the given
1348+
/// image was loaded from.
1349+
///
1350+
/// # Errors
1351+
///
1352+
/// This function can return errors from [`open_protocol_exclusive`] and
1353+
/// [`locate_device_path`]. See those functions for more details.
1354+
///
1355+
/// [`open_protocol_exclusive`]: Self::open_protocol_exclusive
1356+
/// [`locate_device_path`]: Self::locate_device_path
1357+
///
1358+
/// * [`uefi::Status::INVALID_PARAMETER`]
1359+
/// * [`uefi::Status::UNSUPPORTED`]
1360+
/// * [`uefi::Status::ACCESS_DENIED`]
1361+
/// * [`uefi::Status::ALREADY_STARTED`]
1362+
/// * [`uefi::Status::NOT_FOUND`]
1363+
pub fn get_image_file_system(
1364+
&self,
1365+
image_handle: Handle,
1366+
) -> Result<ScopedProtocol<SimpleFileSystem>> {
1367+
let loaded_image = self.open_protocol_exclusive::<LoadedImage>(image_handle)?;
1368+
1369+
let device_handle = loaded_image
1370+
.device()
1371+
.ok_or(Error::new(Status::UNSUPPORTED, ()))?;
1372+
let device_path = self.open_protocol_exclusive::<DevicePath>(device_handle)?;
1373+
1374+
let device_handle = self.locate_device_path::<SimpleFileSystem>(&mut &*device_path)?;
1375+
1376+
self.open_protocol_exclusive(device_handle)
1377+
}
13471378
}
13481379

13491380
#[cfg(feature = "alloc")]
@@ -1377,37 +1408,6 @@ impl BootServices {
13771408
// Emit output, with warnings
13781409
Ok(handles)
13791410
}
1380-
1381-
/// Retrieves a [`FileSystem`] protocol associated with the device the given
1382-
/// image was loaded from.
1383-
///
1384-
/// # Errors
1385-
///
1386-
/// This function can return errors from [`open_protocol_exclusive`] and
1387-
/// [`locate_device_path`]. See those functions for more details.
1388-
///
1389-
/// [`open_protocol_exclusive`]: Self::open_protocol_exclusive
1390-
/// [`locate_device_path`]: Self::locate_device_path
1391-
/// [`FileSystem`]: uefi::fs::FileSystem
1392-
///
1393-
/// * [`uefi::Status::INVALID_PARAMETER`]
1394-
/// * [`uefi::Status::UNSUPPORTED`]
1395-
/// * [`uefi::Status::ACCESS_DENIED`]
1396-
/// * [`uefi::Status::ALREADY_STARTED`]
1397-
/// * [`uefi::Status::NOT_FOUND`]
1398-
pub fn get_image_file_system(&self, image_handle: Handle) -> Result<FileSystem> {
1399-
let loaded_image = self.open_protocol_exclusive::<LoadedImage>(image_handle)?;
1400-
1401-
let device_handle = loaded_image
1402-
.device()
1403-
.ok_or(Error::new(Status::UNSUPPORTED, ()))?;
1404-
let device_path = self.open_protocol_exclusive::<DevicePath>(device_handle)?;
1405-
1406-
let device_handle = self.locate_device_path::<SimpleFileSystem>(&mut &*device_path)?;
1407-
1408-
let protocol = self.open_protocol_exclusive(device_handle)?;
1409-
Ok(FileSystem::new(protocol))
1410-
}
14111411
}
14121412

14131413
impl super::Table for BootServices {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /