Skip to content

Commit 873e382

Browse files
committed
uefi: Revising function calls, names, and return types to better match standard convention
1 parent 6d6586e commit 873e382

File tree

2 files changed

+36
-35
lines changed

2 files changed

+36
-35
lines changed

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

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,29 @@
33
use uefi::boot::ScopedProtocol;
44
use uefi::proto::shell::Shell;
55
use uefi::{boot, cstr16};
6-
use uefi_raw::Status;
76

8-
/// Test `get_cur_dir()` and `set_cur_dir()`
9-
pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) {
7+
/// Test `current_dir()` and `set_current_dir()`
8+
pub fn test_current_dir(shell: &ScopedProtocol<Shell>) {
109
/* Test setting and getting current file system and current directory */
1110
let fs_var = cstr16!("fs0:");
1211
let dir_var = cstr16!("/");
13-
let status = shell.set_cur_dir(Some(fs_var), Some(dir_var));
14-
assert_eq!(status, Status::SUCCESS);
12+
let status = shell.set_current_dir(Some(fs_var), Some(dir_var));
13+
assert!(status.is_ok());
1514

1615
let cur_fs_str = shell
17-
.get_cur_dir(Some(fs_var))
16+
.current_dir(Some(fs_var))
1817
.expect("Could not get the current file system mapping");
1918
let expected_fs_str = cstr16!("FS0:\\");
2019
assert_eq!(cur_fs_str, expected_fs_str);
2120

2221
// Changing current file system
2322
let fs_var = cstr16!("fs1:");
2423
let dir_var = cstr16!("/");
25-
let status = shell.set_cur_dir(Some(fs_var), Some(dir_var));
26-
assert_eq!(status, Status::SUCCESS);
24+
let status = shell.set_current_dir(Some(fs_var), Some(dir_var));
25+
assert!(status.is_ok());
2726

2827
let cur_fs_str = shell
29-
.get_cur_dir(Some(fs_var))
28+
.current_dir(Some(fs_var))
3029
.expect("Could not get the current file system mapping");
3130
assert_ne!(cur_fs_str, expected_fs_str);
3231
let expected_fs_str = cstr16!("FS1:\\");
@@ -35,11 +34,11 @@ pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) {
3534
// Changing current file system and current directory
3635
let fs_var = cstr16!("fs0:");
3736
let dir_var = cstr16!("efi/");
38-
let status = shell.set_cur_dir(Some(fs_var), Some(dir_var));
39-
assert_eq!(status, Status::SUCCESS);
37+
let status = shell.set_current_dir(Some(fs_var), Some(dir_var));
38+
assert!(status.is_ok());
4039

4140
let cur_fs_str = shell
42-
.get_cur_dir(Some(fs_var))
41+
.current_dir(Some(fs_var))
4342
.expect("Could not get the current file system mapping");
4443
assert_ne!(cur_fs_str, expected_fs_str);
4544
let expected_fs_str = cstr16!("FS0:\\efi");
@@ -49,50 +48,50 @@ pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) {
4948

5049
// At this point, the current working file system has not been set
5150
// So we expect a NULL output
52-
assert!(shell.get_cur_dir(None).is_none());
51+
assert!(shell.current_dir(None).is_none());
5352

5453
// Setting the current working file system and current working directory
5554
let dir_var = cstr16!("fs0:/");
56-
let status = shell.set_cur_dir(None, Some(dir_var));
57-
assert_eq!(status, Status::SUCCESS);
55+
let status = shell.set_current_dir(None, Some(dir_var));
56+
assert!(status.is_ok());
5857
let cur_fs_str = shell
59-
.get_cur_dir(Some(fs_var))
58+
.current_dir(Some(fs_var))
6059
.expect("Could not get the current file system mapping");
6160
let expected_fs_str = cstr16!("FS0:");
6261
assert_eq!(cur_fs_str, expected_fs_str);
6362

6463
let cur_fs_str = shell
65-
.get_cur_dir(None)
64+
.current_dir(None)
6665
.expect("Could not get the current file system mapping");
6766
assert_eq!(cur_fs_str, expected_fs_str);
6867

6968
// Changing current working directory
7069
let dir_var = cstr16!("/efi");
71-
let status = shell.set_cur_dir(None, Some(dir_var));
72-
assert_eq!(status, Status::SUCCESS);
70+
let status = shell.set_current_dir(None, Some(dir_var));
71+
assert!(status.is_ok());
7372
let cur_fs_str = shell
74-
.get_cur_dir(Some(fs_var))
73+
.current_dir(Some(fs_var))
7574
.expect("Could not get the current file system mapping");
7675
let expected_fs_str = cstr16!("FS0:\\efi");
7776
assert_eq!(cur_fs_str, expected_fs_str);
7877
let cur_fs_str = shell
79-
.get_cur_dir(None)
78+
.current_dir(None)
8079
.expect("Could not get the current file system mapping");
8180
assert_eq!(cur_fs_str, expected_fs_str);
8281

8382
// Changing current directory in a non-current working file system
8483
let fs_var = cstr16!("fs0:");
8584
let dir_var = cstr16!("efi/tools");
86-
let status = shell.set_cur_dir(Some(fs_var), Some(dir_var));
87-
assert_eq!(status, Status::SUCCESS);
85+
let status = shell.set_current_dir(Some(fs_var), Some(dir_var));
86+
assert!(status.is_ok());
8887
let cur_fs_str = shell
89-
.get_cur_dir(None)
88+
.current_dir(None)
9089
.expect("Could not get the current file system mapping");
9190
assert_ne!(cur_fs_str, expected_fs_str);
9291

9392
let expected_fs_str = cstr16!("FS0:\\efi\\tools");
9493
let cur_fs_str = shell
95-
.get_cur_dir(Some(fs_var))
94+
.current_dir(Some(fs_var))
9695
.expect("Could not get the current file system mapping");
9796
assert_eq!(cur_fs_str, expected_fs_str);
9897
}
@@ -105,5 +104,5 @@ pub fn test() {
105104
let shell =
106105
boot::open_protocol_exclusive::<Shell>(handle).expect("Failed to open Shell protocol");
107106

108-
test_cur_dir(&shell);
107+
test_current_dir(&shell);
109108
}

uefi/src/proto/shell/mod.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33
//! EFI Shell Protocol v2.2
44
55
use uefi_macros::unsafe_protocol;
6-
use uefi_raw::Status;
76

87
use core::ptr;
98

109
use uefi_raw::protocol::shell::ShellProtocol;
1110

12-
use crate::{CStr16, Char16};
11+
use crate::{CStr16, Char16, Result, StatusExt};
1312

1413
/// Shell Protocol
1514
#[derive(Debug)]
1615
#[repr(transparent)]
1716
#[unsafe_protocol(ShellProtocol::GUID)]
1817
pub struct Shell(ShellProtocol);
19-
2018
impl Shell {
2119
/// Returns the current directory on the specified device
2220
///
@@ -30,8 +28,8 @@ impl Shell {
3028
/// * `Some(cwd)` - CStr16 containing the current working directory
3129
/// * `None` - Could not retrieve current directory
3230
#[must_use]
33-
pub fn get_cur_dir(&self, file_system_mapping: Option<&CStr16>) -> Option<&CStr16> {
34-
let mapping_ptr: *const Char16 = file_system_mapping.map_or(ptr::null(), |x| (x.as_ptr()));
31+
pub fn current_dir(&self, file_system_mapping: Option<&CStr16>) -> Option<&CStr16> {
32+
let mapping_ptr: *const Char16 = file_system_mapping.map_or(ptr::null(), CStr16::as_ptr);
3533
let cur_dir = unsafe { (self.0.get_cur_dir)(mapping_ptr.cast()) };
3634
if cur_dir.is_null() {
3735
None
@@ -55,9 +53,13 @@ impl Shell {
5553
/// # Errors
5654
///
5755
/// * `Status::EFI_NOT_FOUND` - The directory does not exist
58-
pub fn set_cur_dir(&self, file_system: Option<&CStr16>, directory: Option<&CStr16>) -> Status {
59-
let fs_ptr: *const Char16 = file_system.map_or(ptr::null(), |x| (x.as_ptr()));
60-
let dir_ptr: *const Char16 = directory.map_or(ptr::null(), |x| (x.as_ptr()));
61-
unsafe { (self.0.set_cur_dir)(fs_ptr.cast(), dir_ptr.cast()) }
56+
pub fn set_current_dir(
57+
&self,
58+
file_system: Option<&CStr16>,
59+
directory: Option<&CStr16>,
60+
) -> Result {
61+
let fs_ptr: *const Char16 = file_system.map_or(ptr::null(), |x| x.as_ptr());
62+
let dir_ptr: *const Char16 = directory.map_or(ptr::null(), |x| x.as_ptr());
63+
unsafe { (self.0.set_cur_dir)(fs_ptr.cast(), dir_ptr.cast()) }.to_result()
6264
}
6365
}

0 commit comments

Comments
 (0)