From f9ca0f95ce1cb9cf5400416a9a4d9a497b698b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Harabie=C5=84?= Date: Mon, 25 Jun 2018 00:16:14 +0200 Subject: [PATCH] Fix decoding 0xE5 character in first byte of short name --- src/dir_entry.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/dir_entry.rs b/src/dir_entry.rs index ccb0ada..0f67ca8 100644 --- a/src/dir_entry.rs +++ b/src/dir_entry.rs @@ -38,6 +38,7 @@ pub(crate) const LFN_PART_LEN: usize = 13; pub(crate) const DIR_ENTRY_SIZE: u64 = 32; pub(crate) const DIR_ENTRY_FREE_FLAG: u8 = 0xE5; pub(crate) const LFN_ENTRY_LAST_FLAG: u8 = 0x40; +pub(crate) const LFN_ENTRY_REALLY_E5_FLAG: u8 = 0x05; /// Decoded file short name #[derive(Clone, Debug, Default)] @@ -64,6 +65,10 @@ impl ShortName { // No extension - return length of name part name_len }; + // FAT encodes character 0xE5 as 0x05 because 0xE5 marks deleted files + if name[0] == LFN_ENTRY_REALLY_E5_FLAG { + name[0] = 0xE5; + } // Short names in FAT filesystem are encoded in OEM code-page ShortName { name, @@ -798,6 +803,12 @@ mod tests { assert_eq!(ShortName::new(&raw_short_name).to_string(), "LOOK AT"); } + #[test] + fn short_name_05_changed_to_e5() { + let raw_short_name = [0x05;11]; + assert_eq!(ShortName::new(&raw_short_name).as_bytes(), [0xE5, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, '.' as u8, 0x05, 0x05, 0x05]); + } + #[test] fn lowercase_short_name() { let mut raw_short_name = [0u8;11];