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 f7965e9

Browse files
committed
uefi: Implementing wrappers for EFI Shell env and cur_dir functions
This commit implements wrappers for the following EFI Shell Protocol functions: set_cur_dir() and get_cur_dir().
1 parent a86c8d7 commit f7965e9

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

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

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,60 @@
22

33
//! EFI Shell Protocol v2.2
44
5-
use crate::proto::unsafe_protocol;
5+
use uefi_macros::unsafe_protocol;
6+
use uefi_raw::Status;
7+
8+
use core::ptr;
69

710
pub use uefi_raw::protocol::shell::ShellProtocol;
811

12+
use crate::{CStr16, Char16};
13+
914
/// Shell Protocol
1015
#[derive(Debug)]
1116
#[repr(transparent)]
1217
#[unsafe_protocol(uefi_raw::protocol::shell::ShellProtocol::GUID)]
1318
pub struct Shell(uefi_raw::protocol::shell::ShellProtocol);
19+
20+
impl Shell {
21+
/// Returns the current directory on the specified device
22+
///
23+
/// # Arguments
24+
///
25+
/// * `file_system_mapping` - The file system mapping for which to get
26+
/// the current directory
27+
/// # Returns
28+
///
29+
/// * `Some(cwd)` - CStr16 containing the current working directory
30+
/// * `None` - Could not retrieve current directory
31+
#[must_use]
32+
pub fn get_cur_dir<'a>(&'a self, file_system_mapping: Option<&CStr16>) -> Option<&'a CStr16> {
33+
let mapping_ptr: *const Char16 = file_system_mapping.map_or(ptr::null(), |x| (x.as_ptr()));
34+
let cur_dir = unsafe { (self.0.get_cur_dir)(mapping_ptr.cast()) };
35+
if cur_dir.is_null() {
36+
None
37+
} else {
38+
unsafe { Some(CStr16::from_ptr(cur_dir.cast())) }
39+
}
40+
}
41+
42+
/// Changes the current directory on the specified device
43+
///
44+
/// # Arguments
45+
///
46+
/// * `file_system` - Pointer to the file system's mapped name.
47+
/// * `directory` - Points to the directory on the device specified by
48+
/// `file_system`.
49+
/// # Returns
50+
///
51+
/// * `Status::SUCCESS` The directory was successfully set
52+
///
53+
/// # Errors
54+
///
55+
/// * `Status::EFI_NOT_FOUND` The directory does not exist
56+
pub fn set_cur_dir(&self, file_system: Option<&CStr16>, directory: Option<&CStr16>) -> Status {
57+
let fs_ptr: *const Char16 = file_system.map_or(ptr::null(), |x| (x.as_ptr()));
58+
let dir_ptr: *const Char16 = directory.map_or(ptr::null(), |x| (x.as_ptr()));
59+
unsafe { (self.0.set_cur_dir)(fs_ptr.cast(), dir_ptr.cast()) }
60+
}
61+
}

0 commit comments

Comments
(0)

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