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 8e808c2

Browse files
committed
uefi: Modifying functions to return Result instead of Status
1 parent 6759278 commit 8e808c2

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

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

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

87
/// Test `var()`, `vars()`, and `set_var()`
98
pub fn test_env(shell: &ScopedProtocol<Shell>) {
@@ -21,7 +20,7 @@ pub fn test_env(shell: &ScopedProtocol<Shell>) {
2120
let test_val = cstr16!("test_val");
2221
assert!(shell.var(test_var).is_none());
2322
let status = shell.set_var(test_var, test_val, false);
24-
assert_eq!(status,Status::SUCCESS);
23+
assert!(status.is_ok());
2524
let cur_env_str = shell
2625
.var(test_var)
2726
.expect("Could not get environment variable");
@@ -49,7 +48,7 @@ pub fn test_env(shell: &ScopedProtocol<Shell>) {
4948
/* Test deleting environment variable */
5049
let test_val = cstr16!("");
5150
let status = shell.set_var(test_var, test_val, false);
52-
assert_eq!(status,Status::SUCCESS);
51+
assert!(status.is_ok());
5352
assert!(shell.var(test_var).is_none());
5453

5554
let cur_env_vec = shell.vars();
@@ -70,7 +69,7 @@ pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) {
7069
let fs_var = cstr16!("fs0:");
7170
let dir_var = cstr16!("/");
7271
let status = shell.set_current_dir(Some(fs_var), Some(dir_var));
73-
assert_eq!(status,Status::SUCCESS);
72+
assert!(status.is_ok());
7473

7574
let cur_fs_str = shell
7675
.current_dir(Some(fs_var))
@@ -82,7 +81,7 @@ pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) {
8281
let fs_var = cstr16!("fs1:");
8382
let dir_var = cstr16!("/");
8483
let status = shell.set_current_dir(Some(fs_var), Some(dir_var));
85-
assert_eq!(status,Status::SUCCESS);
84+
assert!(status.is_ok());
8685

8786
let cur_fs_str = shell
8887
.current_dir(Some(fs_var))
@@ -95,7 +94,7 @@ pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) {
9594
let fs_var = cstr16!("fs0:");
9695
let dir_var = cstr16!("efi/");
9796
let status = shell.set_current_dir(Some(fs_var), Some(dir_var));
98-
assert_eq!(status,Status::SUCCESS);
97+
assert!(status.is_ok());
9998

10099
let cur_fs_str = shell
101100
.current_dir(Some(fs_var))
@@ -113,7 +112,7 @@ pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) {
113112
// Setting the current working file system and current working directory
114113
let dir_var = cstr16!("fs0:/");
115114
let status = shell.set_current_dir(None, Some(dir_var));
116-
assert_eq!(status,Status::SUCCESS);
115+
assert!(status.is_ok());
117116
let cur_fs_str = shell
118117
.current_dir(Some(fs_var))
119118
.expect("Could not get the current file system mapping");
@@ -128,7 +127,7 @@ pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) {
128127
// Changing current working directory
129128
let dir_var = cstr16!("/efi");
130129
let status = shell.set_current_dir(None, Some(dir_var));
131-
assert_eq!(status,Status::SUCCESS);
130+
assert!(status.is_ok());
132131
let cur_fs_str = shell
133132
.current_dir(Some(fs_var))
134133
.expect("Could not get the current file system mapping");
@@ -143,7 +142,7 @@ pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) {
143142
let fs_var = cstr16!("fs0:");
144143
let dir_var = cstr16!("efi/tools");
145144
let status = shell.set_current_dir(Some(fs_var), Some(dir_var));
146-
assert_eq!(status,Status::SUCCESS);
145+
assert!(status.is_ok());
147146
let cur_fs_str = shell
148147
.current_dir(None)
149148
.expect("Could not get the current file system mapping");

‎uefi/src/proto/shell/mod.rs

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

87
use core::marker::PhantomData;
98
use core::ptr;
109

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

13-
use crate::{CStr16, Char16};
12+
use crate::{CStr16, Char16,Result,StatusExt};
1413

1514
/// Shell Protocol
1615
#[derive(Debug)]
@@ -88,10 +87,10 @@ impl Shell {
8887
/// # Returns
8988
///
9089
/// * `Status::SUCCESS` - The variable was successfully set
91-
pub fn set_var(&self, name: &CStr16, value: &CStr16, volatile: bool) -> Status {
90+
pub fn set_var(&self, name: &CStr16, value: &CStr16, volatile: bool) -> Result {
9291
let name_ptr: *const Char16 = name.as_ptr();
9392
let value_ptr: *const Char16 = value.as_ptr();
94-
unsafe { (self.0.set_env)(name_ptr.cast(), value_ptr.cast(), volatile) }
93+
unsafe { (self.0.set_env)(name_ptr.cast(), value_ptr.cast(), volatile) }.to_result()
9594
}
9695

9796
/// Returns the current directory on the specified device
@@ -131,10 +130,14 @@ impl Shell {
131130
/// # Errors
132131
///
133132
/// * `Status::EFI_NOT_FOUND` - The directory does not exist
134-
pub fn set_current_dir(&self, file_system: Option<&CStr16>, directory: Option<&CStr16>) -> Status {
133+
pub fn set_current_dir(
134+
&self,
135+
file_system: Option<&CStr16>,
136+
directory: Option<&CStr16>,
137+
) -> Result {
135138
let fs_ptr: *const Char16 = file_system.map_or(ptr::null(), |x| (x.as_ptr()));
136139
let dir_ptr: *const Char16 = directory.map_or(ptr::null(), |x| (x.as_ptr()));
137-
unsafe { (self.0.set_cur_dir)(fs_ptr.cast(), dir_ptr.cast()) }
140+
unsafe { (self.0.set_cur_dir)(fs_ptr.cast(), dir_ptr.cast()) }.to_result()
138141
}
139142
}
140143

0 commit comments

Comments
(0)

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