Skip to content

Commit 4e0df01

Browse files
committed
fs/path: documentation and visibility adjustments
1 parent 82e4499 commit 4e0df01

File tree

4 files changed

+33
-41
lines changed

4 files changed

+33
-41
lines changed

uefi/src/fs/file_system.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Module for [`FileSystem`].
22
33
use super::*;
4-
use crate::fs::path::validation::{validate_path, PathError};
4+
use crate::fs::path::{validate_path, PathError};
55
use crate::proto::media::file::{FileAttribute, FileInfo, FileType};
66
use crate::table::boot::ScopedProtocol;
77
use alloc::boxed::Box;
@@ -21,7 +21,7 @@ pub enum FileSystemError {
2121
CantOpenVolume,
2222
/// The path is invalid because of the underlying [`PathError`].
2323
///
24-
/// [`PathError`]: path::validation::PathError
24+
/// [`PathError`]: path::PathError
2525
IllegalPath(PathError),
2626
/// The file or directory was not found in the underlying volume.
2727
FileNotFound(String),

uefi/src/fs/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
//! A high-level file system API for UEFI applications close to the `fs` module
2-
//! from Rust's standard library.
1+
//! 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
3+
//! [`FileSystem`].
34
//!
45
//! # Difference to typical File System Abstractions
56
//! Users perform actions on dedicated volumes: For example, the boot volume,
67
//! such as a CD-rom, USB-stick, or any other storage device.
78
//!
89
//! Unlike in the API of typical UNIX file system abstractions, there is
9-
//! no virtual file system.
10-
//!
11-
//! Unlike Windows, there is no way to access volumes by a dedicated name.
10+
//! no virtual file system. Unlike in Windows, there is no way to access volumes
11+
//! by a dedicated name.
1212
//!
1313
//! # Paths
1414
//! All paths are absolute and follow the FAT-like file system conventions for
@@ -17,7 +17,8 @@
1717
//! directory is always `/`, i.e., the root, of the opened volume.
1818
//!
1919
//! Symlinks or hard-links are not supported but only directories and regular
20-
//! files with plain linear paths to them.
20+
//! files with plain linear paths to them. For more information, see
21+
//! [`Path`] and [`PathBuf`].
2122
//!
2223
//! # API Hints
2324
//! There are no `File` and `Path` abstractions similar to those from `std` that

uefi/src/fs/path/mod.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
1616
mod path;
1717
mod pathbuf;
18-
pub mod validation;
18+
mod validation;
1919

2020
pub use path::Path;
2121
pub use pathbuf::PathBuf;
2222

2323
use uefi::{CStr16, Char16};
24+
pub(super) use validation::validate_path;
25+
pub use validation::PathError;
2426

2527
/// The default separator for paths.
2628
pub const SEPARATOR: char = '\\';
@@ -32,5 +34,20 @@ pub const SEPARATOR_STR: &str = "\\";
3234
/// [`SEPARATOR_STR`] but as useful UEFI type.
3335
pub const SEPARATOR_CSTR16: &CStr16 = uefi_macros::cstr16!("\\");
3436

35-
/// Denied characters in a path component.
36-
pub const CHARACTER_DENY_LIST: [char; 10] = ['\0', '"', '*', '/', ':', '<', '>', '?', '\\', '|'];
37+
/// Deny list of characters for path components. UEFI supports FAT-like file
38+
/// systems. According to <https://en.wikipedia.org/wiki/Comparison_of_file_systems>,
39+
/// paths should not contain the following symbols.
40+
pub const CHARACTER_DENY_LIST: [Char16; 10] = unsafe {
41+
[
42+
Char16::from_u16_unchecked('\0' as u16),
43+
Char16::from_u16_unchecked('"' as u16),
44+
Char16::from_u16_unchecked('*' as u16),
45+
Char16::from_u16_unchecked('/' as u16),
46+
Char16::from_u16_unchecked(':' as u16),
47+
Char16::from_u16_unchecked('<' as u16),
48+
Char16::from_u16_unchecked('>' as u16),
49+
Char16::from_u16_unchecked('?' as u16),
50+
Char16::from_u16_unchecked('\\' as u16),
51+
Char16::from_u16_unchecked('|' as u16),
52+
]
53+
};

uefi/src/fs/path/validation.rs

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,10 @@
66
//! [`fs`]: crate::fs
77
88
use super::Path;
9+
use crate::fs::CHARACTER_DENY_LIST;
910
use crate::Char16;
1011
use derive_more::Display;
1112

12-
/// Deny list of characters for path components. UEFI supports FAT-like file
13-
/// systems. According to <https://en.wikipedia.org/wiki/Comparison_of_file_systems>,
14-
/// paths should not contain the following symbols.
15-
pub const CHARACTER_DENY_LIST: [Char16; 10] = unsafe {
16-
[
17-
Char16::from_u16_unchecked('\0' as u16),
18-
Char16::from_u16_unchecked('"' as u16),
19-
Char16::from_u16_unchecked('*' as u16),
20-
Char16::from_u16_unchecked('/' as u16),
21-
Char16::from_u16_unchecked(':' as u16),
22-
Char16::from_u16_unchecked('<' as u16),
23-
Char16::from_u16_unchecked('>' as u16),
24-
Char16::from_u16_unchecked('?' as u16),
25-
Char16::from_u16_unchecked('\\' as u16),
26-
Char16::from_u16_unchecked('|' as u16),
27-
]
28-
};
29-
3013
/// Errors related to file paths.
3114
#[derive(Debug, Clone, Eq, PartialEq, Display)]
3215
pub enum PathError {
@@ -73,21 +56,12 @@ mod tests {
7356

7457
#[test]
7558
fn test_validate_path() {
76-
let source: &CStr16 = cstr16!("hello\\foo\\bar");
77-
let path: &Path = source.into();
78-
// TODO why can't I just pass in a &Path ?!
79-
validate_path(path.as_ref()).unwrap();
59+
validate_path(cstr16!("hello\\foo\\bar")).unwrap();
8060

81-
let source: &CStr16 = cstr16!("hello\\f>oo\\bar");
82-
let path: &Path = source.into();
83-
// TODO why can't I just pass in a &Path ?!
84-
let err = validate_path(path.as_ref()).unwrap_err();
61+
let err = validate_path(cstr16!("hello\\f>oo\\bar")).unwrap_err();
8562
assert_eq!(err, PathError::IllegalChar(CHARACTER_DENY_LIST[6]));
8663

87-
let source: &CStr16 = cstr16!("hello\\\\bar");
88-
let path: &Path = source.into();
89-
// TODO why can't I just pass in a &Path ?!
90-
let err = validate_path(path.as_ref()).unwrap_err();
64+
let err = validate_path(cstr16!("hello\\\\bar")).unwrap_err();
9165
assert_eq!(err, PathError::EmptyComponent);
9266

9367
let empty_cstring16 = CString16::try_from("").unwrap();

0 commit comments

Comments
 (0)