forked from M-Labs/rust-fatfs
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.
This commit is contained in:
parent
b4be13823c
commit
0e96b05054
@ -105,6 +105,21 @@ impl DirFileEntryData {
|
|||||||
&self.name
|
&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<u32> {
|
pub(crate) fn first_cluster(&self, fat_type: FatType) -> Option<u32> {
|
||||||
let first_cluster_hi = if fat_type == FatType::Fat32 { self.first_cluster_hi } else { 0 };
|
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;
|
let n = ((first_cluster_hi as u32) << 16) | self.first_cluster_lo as u32;
|
||||||
@ -139,6 +154,14 @@ impl DirFileEntryData {
|
|||||||
!self.is_dir()
|
!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 {
|
fn created(&self) -> DateTime {
|
||||||
DateTime::from_u16(self.create_date, self.create_time_1)
|
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 {
|
if self.lfn.len() > 0 {
|
||||||
String::from_utf16_lossy(&self.lfn)
|
String::from_utf16_lossy(&self.lfn)
|
||||||
} else {
|
} else {
|
||||||
self.short_file_name()
|
self.data.lowercase_name()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "alloc"))]
|
#[cfg(not(feature = "alloc"))]
|
||||||
|
Loading…
Reference in New Issue
Block a user