|
2 | 2 |
|
3 | 3 | //! EFI Shell Protocol v2.2
|
4 | 4 |
|
5 |
| -use crate::proto::unsafe_protocol; |
| 5 | +use uefi_macros::unsafe_protocol; |
| 6 | +use uefi_raw::Status; |
| 7 | + |
| 8 | +use core::ptr; |
6 | 9 |
|
7 | 10 | pub use uefi_raw::protocol::shell::ShellProtocol;
|
8 | 11 |
|
| 12 | +use crate::{CStr16, Char16}; |
| 13 | + |
9 | 14 | /// Shell Protocol
|
10 | 15 | #[derive(Debug)]
|
11 | 16 | #[repr(transparent)]
|
12 | 17 | #[unsafe_protocol(uefi_raw::protocol::shell::ShellProtocol::GUID)]
|
13 | 18 | 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