Skip to content

Commit 11595f3

Browse files
Merge pull request #1126 from phip1611/doc
doc: update fs documentation
2 parents 1379320 + cff6db2 commit 11595f3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

uefi/src/fs/file_system/fs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ pub type FileSystemResult<T> = Result<T, Error>;
1717
/// High-level file-system abstraction for UEFI volumes with an API that is
1818
/// close to `std::fs`. It acts as convenient accessor around the
1919
/// [`SimpleFileSystemProtocol`].
20+
///
21+
/// Please refer to the [module documentation] for more information.
22+
///
23+
/// [module documentation]: uefi::fs
2024
pub struct FileSystem<'a>(ScopedProtocol<'a, SimpleFileSystemProtocol>);
2125

2226
impl<'a> FileSystem<'a> {

uefi/src/fs/mod.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! A high-level file system API for UEFI applications close to the `std::fs`
2-
//! module from Rust's standard library. The main type by this module is
2+
//! module from Rust's standard library. The main export of this module is
33
//! [`FileSystem`].
44
//!
55
//! # Difference to typical File System Abstractions
@@ -20,13 +20,34 @@
2020
//! files with plain linear paths to them. For more information, see
2121
//! [`Path`] and [`PathBuf`].
2222
//!
23+
//! ## Use `&str` as Path
24+
//! A `&str` known at compile time can be converted to a [`Path`] using the
25+
//! [`cstr16!`] macro. During runtime, you can create a path like this:
26+
//!
27+
//! ```no_run
28+
//! use uefi::CString16;
29+
//! use uefi::fs::{FileSystem, FileSystemResult};
30+
//! use uefi::prelude::BootServices;
31+
//! use uefi::proto::media::fs::SimpleFileSystem;
32+
//! use uefi::table::boot::ScopedProtocol;
33+
//!
34+
//! fn read_file(bs: BootServices, path: &str) -> FileSystemResult<Vec<u8>> {
35+
//! let path: CString16 = CString16::try_from(path).unwrap();
36+
//! let fs: ScopedProtocol<SimpleFileSystem> = bs.get_image_file_system(bs.image_handle()).unwrap();
37+
//! let mut fs = FileSystem::new(fs);
38+
//! fs.read(path.as_ref())
39+
//! }
40+
//! ```
41+
//!
2342
//! # API Hints
2443
//! There is no `File` abstraction as in the Rust `std` library. Instead, it is
2544
//! intended to work with the file system via dedicated functions, similar to
2645
//! the public functions of the `std::fs` module.
2746
//!
2847
//! There is no automatic synchronization of the file system for concurrent
2948
//! accesses. This is in the responsibility of the user.
49+
//!
50+
//! [`cstr16!`]: uefi_macros::cstr16
3051
3152
mod dir_entry_iter;
3253
mod file_system;

0 commit comments

Comments
 (0)