2
2
3
3
//! EFI Shell Protocol v2.2
4
4
5
- use uefi_macros :: unsafe_protocol;
6
-
5
+ use crate :: proto :: unsafe_protocol;
6
+ use crate :: { CStr16 , Char16 , Error , Result , Status , StatusExt } ;
7
7
use core:: ptr;
8
-
9
8
use uefi_raw:: protocol:: shell:: ShellProtocol ;
10
9
11
- use crate :: { CStr16 , Char16 , Result , StatusExt } ;
12
-
13
10
/// Shell Protocol
14
11
#[ derive( Debug ) ]
15
12
#[ repr( transparent) ]
16
13
#[ unsafe_protocol( ShellProtocol :: GUID ) ]
17
14
pub struct Shell ( ShellProtocol ) ;
15
+
18
16
impl Shell {
19
- /// Returns the current directory on the specified device
17
+ /// Returns the current directory on the specified device.
20
18
///
21
19
/// # Arguments
22
20
///
@@ -25,34 +23,32 @@ impl Shell {
25
23
///
26
24
/// # Returns
27
25
///
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
+ /// * `Ok(cwd)` - CStr16 containing the current working directory
27
+ ///
28
+ /// # Errors
29
+ ///
30
+ /// * [`Status::NOT_FOUND`] - Could not retrieve current directory
31
+ pub fn current_dir ( & self , file_system_mapping : Option < & CStr16 > ) -> Result < & CStr16 > {
32
32
let mapping_ptr: * const Char16 = file_system_mapping. map_or ( ptr:: null ( ) , CStr16 :: as_ptr) ;
33
33
let cur_dir = unsafe { ( self . 0 . get_cur_dir ) ( mapping_ptr. cast ( ) ) } ;
34
34
if cur_dir. is_null ( ) {
35
- None
35
+ Err ( Error :: new ( Status :: NOT_FOUND , ( ) ) )
36
36
} else {
37
- unsafe { Some ( CStr16 :: from_ptr ( cur_dir. cast ( ) ) ) }
37
+ unsafe { Ok ( CStr16 :: from_ptr ( cur_dir. cast ( ) ) ) }
38
38
}
39
39
}
40
40
41
41
/// Changes the current directory on the specified device
42
42
///
43
43
/// # Arguments
44
44
///
45
- /// * `file_system` - Pointer to the file system's mapped name.
46
- /// * `directory` - Points to the directory on the device specified by
45
+ /// * `file_system` - File system's mapped name.
46
+ /// * `directory` - Directory on the device specified by
47
47
/// `file_system`.
48
48
///
49
- /// # Returns
50
- ///
51
- /// * `Status::SUCCESS` - The directory was successfully set
52
- ///
53
49
/// # Errors
54
50
///
55
- /// * `Status::EFI_NOT_FOUND` - The directory does not exist
51
+ /// * [ `Status::NOT_FOUND`] - The directory does not exist
56
52
pub fn set_current_dir (
57
53
& self ,
58
54
file_system : Option < & CStr16 > ,
0 commit comments