Skip to content

doc: update fs documentation #1126

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
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions uefi/src/fs/file_system/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ pub type FileSystemResult<T> = Result<T, Error>;
/// High-level file-system abstraction for UEFI volumes with an API that is
/// close to `std::fs`. It acts as convenient accessor around the
/// [`SimpleFileSystemProtocol`].
///
/// Please refer to the [module documentation] for more information.
///
/// [module documentation]: uefi::fs
pub struct FileSystem<'a>(ScopedProtocol<'a, SimpleFileSystemProtocol>);

impl<'a> FileSystem<'a> {
Expand Down
23 changes: 22 additions & 1 deletion uefi/src/fs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! A high-level file system API for UEFI applications close to the `std::fs`
//! module from Rust's standard library. The main type by this module is
//! module from Rust's standard library. The main export of this module is
//! [`FileSystem`].
//!
//! # Difference to typical File System Abstractions
Expand All @@ -20,13 +20,34 @@
//! files with plain linear paths to them. For more information, see
//! [`Path`] and [`PathBuf`].
//!
//! ## Use `&str` as Path
//! A `&str` known at compile time can be converted to a [`Path`] using the
//! [`cstr16!`] macro. During runtime, you can create a path like this:
//!
//! ```no_run
//! use uefi::CString16;
//! use uefi::fs::{FileSystem, FileSystemResult};
//! use uefi::prelude::BootServices;
//! use uefi::proto::media::fs::SimpleFileSystem;
//! use uefi::table::boot::ScopedProtocol;
//!
//! fn read_file(bs: BootServices, path: &str) -> FileSystemResult<Vec<u8>> {
//! let path: CString16 = CString16::try_from(path).unwrap();
//! let fs: ScopedProtocol<SimpleFileSystem> = bs.get_image_file_system(bs.image_handle()).unwrap();
//! let mut fs = FileSystem::new(fs);
//! fs.read(path.as_ref())
//! }
//! ```
//!
//! # API Hints
//! There is no `File` abstraction as in the Rust `std` library. Instead, it is
//! intended to work with the file system via dedicated functions, similar to
//! the public functions of the `std::fs` module.
//!
//! There is no automatic synchronization of the file system for concurrent
//! accesses. This is in the responsibility of the user.
//!
//! [`cstr16!`]: uefi_macros::cstr16

mod dir_entry_iter;
mod file_system;
Expand Down