-
-
Notifications
You must be signed in to change notification settings - Fork 180
EFI Shell Interface: CurDir Functions #1740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicholasbishop
merged 4 commits into
rust-osdev:main
from
RenTrieu:enhancement/efi_shell_interface_cur_dir
Aug 18, 2025
+149
−6
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f7965e9
uefi: Implementing wrappers for EFI Shell env and cur_dir functions
RenTrieu 6d6586e
uefi-test-runner: Added tests for EFI Shell cur_dir functions
RenTrieu 873e382
uefi: Revising function calls, names, and return types to better matc…
RenTrieu 18953be
uefi: Revising style for EFI Shell CurDir functions
RenTrieu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,112 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
use uefi::boot; | ||
use uefi::boot::ScopedProtocol; | ||
use uefi::proto::shell::Shell; | ||
use uefi::{Error, Status, boot, cstr16}; | ||
|
||
/// Test `current_dir()` and `set_current_dir()` | ||
pub fn test_current_dir(shell: &ScopedProtocol<Shell>) { | ||
/* Test setting and getting current file system and current directory */ | ||
let fs_var = cstr16!("fs0:"); | ||
let dir_var = cstr16!("/"); | ||
let status = shell.set_current_dir(Some(fs_var), Some(dir_var)); | ||
assert!(status.is_ok()); | ||
|
||
let cur_fs_str = shell | ||
.current_dir(Some(fs_var)) | ||
.expect("Could not get the current file system mapping"); | ||
let expected_fs_str = cstr16!("FS0:\\"); | ||
assert_eq!(cur_fs_str, expected_fs_str); | ||
|
||
// Changing current file system | ||
let fs_var = cstr16!("fs1:"); | ||
let dir_var = cstr16!("/"); | ||
let status = shell.set_current_dir(Some(fs_var), Some(dir_var)); | ||
assert!(status.is_ok()); | ||
|
||
let cur_fs_str = shell | ||
.current_dir(Some(fs_var)) | ||
.expect("Could not get the current file system mapping"); | ||
assert_ne!(cur_fs_str, expected_fs_str); | ||
let expected_fs_str = cstr16!("FS1:\\"); | ||
assert_eq!(cur_fs_str, expected_fs_str); | ||
|
||
// Changing current file system and current directory | ||
let fs_var = cstr16!("fs0:"); | ||
let dir_var = cstr16!("efi/"); | ||
let status = shell.set_current_dir(Some(fs_var), Some(dir_var)); | ||
assert!(status.is_ok()); | ||
|
||
let cur_fs_str = shell | ||
.current_dir(Some(fs_var)) | ||
.expect("Could not get the current file system mapping"); | ||
assert_ne!(cur_fs_str, expected_fs_str); | ||
let expected_fs_str = cstr16!("FS0:\\efi"); | ||
assert_eq!(cur_fs_str, expected_fs_str); | ||
|
||
/* Test current working directory cases */ | ||
|
||
// At this point, the current working file system has not been set | ||
// So we expect a NULL output | ||
assert!(shell.current_dir(None).is_err()); | ||
assert_eq!( | ||
shell.current_dir(None).err().unwrap(), | ||
Error::new(Status::NOT_FOUND, ()) | ||
); | ||
|
||
// Setting the current working file system and current working directory | ||
let dir_var = cstr16!("fs0:/"); | ||
let status = shell.set_current_dir(None, Some(dir_var)); | ||
assert!(status.is_ok()); | ||
let cur_fs_str = shell | ||
.current_dir(Some(fs_var)) | ||
.expect("Could not get the current file system mapping"); | ||
let expected_fs_str = cstr16!("FS0:"); | ||
assert_eq!(cur_fs_str, expected_fs_str); | ||
|
||
let cur_fs_str = shell | ||
.current_dir(None) | ||
.expect("Could not get the current file system mapping"); | ||
assert_eq!(cur_fs_str, expected_fs_str); | ||
|
||
// Changing current working directory | ||
let dir_var = cstr16!("/efi"); | ||
let status = shell.set_current_dir(None, Some(dir_var)); | ||
assert!(status.is_ok()); | ||
let cur_fs_str = shell | ||
.current_dir(Some(fs_var)) | ||
.expect("Could not get the current file system mapping"); | ||
let expected_fs_str = cstr16!("FS0:\\efi"); | ||
assert_eq!(cur_fs_str, expected_fs_str); | ||
let cur_fs_str = shell | ||
.current_dir(None) | ||
.expect("Could not get the current file system mapping"); | ||
assert_eq!(cur_fs_str, expected_fs_str); | ||
|
||
// Changing current directory in a non-current working file system | ||
let fs_var = cstr16!("fs0:"); | ||
let dir_var = cstr16!("efi/tools"); | ||
let status = shell.set_current_dir(Some(fs_var), Some(dir_var)); | ||
assert!(status.is_ok()); | ||
let cur_fs_str = shell | ||
.current_dir(None) | ||
.expect("Could not get the current file system mapping"); | ||
assert_ne!(cur_fs_str, expected_fs_str); | ||
|
||
let expected_fs_str = cstr16!("FS0:\\efi\\tools"); | ||
let cur_fs_str = shell | ||
.current_dir(Some(fs_var)) | ||
.expect("Could not get the current file system mapping"); | ||
assert_eq!(cur_fs_str, expected_fs_str); | ||
} | ||
|
||
pub fn test() { | ||
info!("Running shell protocol tests"); | ||
|
||
let handle = boot::get_handle_for_protocol::<Shell>().expect("No Shell handles"); | ||
|
||
let mut _shell = | ||
let shell = | ||
boot::open_protocol_exclusive::<Shell>(handle).expect("Failed to open Shell protocol"); | ||
|
||
test_current_dir(&shell); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.