Skip to content

Commit

Permalink
efi/file: fixup dir/file name
Browse files Browse the repository at this point in the history
Fat filename can be 12, that is filename with length of 8 and extension
name with length of 3 and a separator like '.'. But directory name
length limits to 11. That's say some name can't be shown correctly. For
that case, we can do a fixup to give a correct name to userspace.

Fixes: #261
Signed-off-by: Jianyong Wu <[email protected]>
  • Loading branch information
jongwu committed Jul 6, 2023
1 parent 3e29535 commit 7d71120
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/efi/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub extern "efiapi" fn read(file: *mut FileProtocol, size: *mut usize, buf: *mut
Err(_) => return Status::DEVICE_ERROR,
};

let (node, name) = match d.next_node() {
let (node, mut name) = match d.next_node() {
Ok(node) => node,
Err(crate::fat::Error::EndOfFile) => {
unsafe { *size = 0 };
Expand All @@ -115,6 +115,17 @@ pub extern "efiapi" fn read(file: *mut FileProtocol, size: *mut usize, buf: *mut
Err(_) => return Status::DEVICE_ERROR,
};

// Fixup for Director or file name, when the length of its name and extend name equals 11. There maybe no
// separation between them. If so, add it.
if name[10] >= b'a' && name[10] <= b'z'
|| name[10] >= b'A' && name[10] <= b'Z' && name[7] != b' ' && name[7] != b'.'
{
name[11] = name[10];
name[10] = name[9];
name[9] = name[8];
name[8] = b'.';
}

let attribute = match &node {
crate::fat::Node::Directory(_) => r_efi::protocols::file::DIRECTORY,
crate::fat::Node::File(_) => r_efi::protocols::file::ARCHIVE,
Expand Down
4 changes: 2 additions & 2 deletions src/fat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ impl<'a> Directory<'a> {
}
}

pub fn next_node(&mut self) -> Result<(Node, [u8; 11]), Error> {
pub fn next_node(&mut self) -> Result<(Node, [u8; 12]), Error> {
let de = self.next_entry()?;
let mut name = [0_u8; 11];
let mut name = [0_u8; 12];
name_to_str(core::str::from_utf8(&de.name).unwrap(), &mut name);

match de.file_type {
Expand Down

0 comments on commit 7d71120

Please sign in to comment.