Skip to content

Commit 18953be

Browse files
uefi: Revising style for EFI Shell CurDir functions
Co-authored-by: Nicholas Bishop <[email protected]>
1 parent 873e382 commit 18953be

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

uefi-test-runner/src/proto/shell.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use uefi::boot::ScopedProtocol;
44
use uefi::proto::shell::Shell;
5-
use uefi::{boot, cstr16};
5+
use uefi::{Error, Status, boot, cstr16};
66

77
/// Test `current_dir()` and `set_current_dir()`
88
pub fn test_current_dir(shell: &ScopedProtocol<Shell>) {
@@ -48,7 +48,11 @@ pub fn test_current_dir(shell: &ScopedProtocol<Shell>) {
4848

4949
// At this point, the current working file system has not been set
5050
// So we expect a NULL output
51-
assert!(shell.current_dir(None).is_none());
51+
assert!(shell.current_dir(None).is_err());
52+
assert_eq!(
53+
shell.current_dir(None).err().unwrap(),
54+
Error::new(Status::NOT_FOUND, ())
55+
);
5256

5357
// Setting the current working file system and current working directory
5458
let dir_var = cstr16!("fs0:/");

uefi/src/proto/shell/mod.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,49 @@
22

33
//! EFI Shell Protocol v2.2
44
5-
use uefi_macros::unsafe_protocol;
6-
5+
use crate::proto::unsafe_protocol;
6+
use crate::{CStr16, Char16, Error, Result, Status, StatusExt};
77
use core::ptr;
8-
98
use uefi_raw::protocol::shell::ShellProtocol;
109

11-
use crate::{CStr16, Char16, Result, StatusExt};
12-
1310
/// Shell Protocol
1411
#[derive(Debug)]
1512
#[repr(transparent)]
1613
#[unsafe_protocol(ShellProtocol::GUID)]
1714
pub struct Shell(ShellProtocol);
15+
1816
impl Shell {
19-
/// Returns the current directory on the specified device
17+
/// Returns the current directory on the specified device.
2018
///
2119
/// # Arguments
2220
///
2321
/// * `file_system_mapping` - The file system mapping for which to get
2422
/// the current directory
2523
///
26-
/// # Returns
24+
/// # Errors
2725
///
28-
/// * `Some(cwd)` - CStr16 containing the current working directory
29-
/// * `None` - Could not retrieve current directory
30-
#[must_use]
31-
pub fn current_dir(&self, file_system_mapping: Option<&CStr16>) -> Option<&CStr16> {
26+
/// * [`Status::NOT_FOUND`] - Could not retrieve current directory
27+
pub fn current_dir(&self, file_system_mapping: Option<&CStr16>) -> Result<&CStr16> {
3228
let mapping_ptr: *const Char16 = file_system_mapping.map_or(ptr::null(), CStr16::as_ptr);
3329
let cur_dir = unsafe { (self.0.get_cur_dir)(mapping_ptr.cast()) };
3430
if cur_dir.is_null() {
35-
None
31+
Err(Error::new(Status::NOT_FOUND, ()))
3632
} else {
37-
unsafe { Some(CStr16::from_ptr(cur_dir.cast())) }
33+
unsafe { Ok(CStr16::from_ptr(cur_dir.cast())) }
3834
}
3935
}
4036

4137
/// Changes the current directory on the specified device
4238
///
4339
/// # Arguments
4440
///
45-
/// * `file_system` - Pointer to the file system's mapped name.
46-
/// * `directory` - Points to the directory on the device specified by
41+
/// * `file_system` - File system's mapped name.
42+
/// * `directory` - Directory on the device specified by
4743
/// `file_system`.
4844
///
49-
/// # Returns
50-
///
51-
/// * `Status::SUCCESS` - The directory was successfully set
52-
///
5345
/// # Errors
5446
///
55-
/// * `Status::EFI_NOT_FOUND` - The directory does not exist
47+
/// * [`Status::NOT_FOUND`] - The directory does not exist
5648
pub fn set_current_dir(
5749
&self,
5850
file_system: Option<&CStr16>,

0 commit comments

Comments
 (0)