From 0e96b050546b6f00dc569157fc8bd9b5bea22887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Harabie=C5=84?= Date: Wed, 30 May 2018 01:17:24 +0200 Subject: [PATCH] Add support for LFN encoding in SFN entries on WinNT New Windows does not create LFN entries if name fits in 8.3 format and letters in both basename and ext parts are all uppercase or all lowercase. This commit fixes handling of lowercase letters. --- src/dir_entry.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/dir_entry.rs b/src/dir_entry.rs index 6ae0e14..d27852a 100644 --- a/src/dir_entry.rs +++ b/src/dir_entry.rs @@ -105,6 +105,21 @@ impl DirFileEntryData { &self.name } + pub(crate) fn lowercase_name(&self) -> String { + let mut name_copy: [u8; 11] = self.name; + if self.lowercase_basename() { + for c in &mut name_copy[..8] { + *c = (*c as char).to_ascii_lowercase() as u8; + } + } + if self.lowercase_ext() { + for c in &mut name_copy[8..] { + *c = (*c as char).to_ascii_lowercase() as u8; + } + } + ShortName::new(&name_copy).to_str().to_string() + } + pub(crate) fn first_cluster(&self, fat_type: FatType) -> Option { let first_cluster_hi = if fat_type == FatType::Fat32 { self.first_cluster_hi } else { 0 }; let n = ((first_cluster_hi as u32) << 16) | self.first_cluster_lo as u32; @@ -139,6 +154,14 @@ impl DirFileEntryData { !self.is_dir() } + pub(crate) fn lowercase_basename(&self) -> bool { + self.reserved_0 & (1 << 3) != 0 + } + + pub(crate) fn lowercase_ext(&self) -> bool { + self.reserved_0 & (1 << 4) != 0 + } + fn created(&self) -> DateTime { DateTime::from_u16(self.create_date, self.create_time_1) } @@ -605,7 +628,7 @@ impl <'a, 'b> DirEntry<'a, 'b> { if self.lfn.len() > 0 { String::from_utf16_lossy(&self.lfn) } else { - self.short_file_name() + self.data.lowercase_name() } } #[cfg(not(feature = "alloc"))]