Skip to content

Commit

Permalink
Don't create LFNs for . and ..
Browse files Browse the repository at this point in the history
The current code makes invalid dir entries, because the first two slots
should be . and .., but with LFNs, it's

    LFN for .
    .
    LFN for ..
    ..

We should probably not create LFN's when not needed anyway, but that's not
implemented in this patch.
  • Loading branch information
badicsalex committed Oct 23, 2024
1 parent 85f06e0 commit ec6066a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,12 @@ impl<'a, IO: ReadWriteSeek, TP: TimeProvider, OCC: OemCpConverter> Dir<'a, IO, T
Ok((stream, start_pos))
}

fn alloc_sfn_entry(&self) -> Result<(DirRawStream<'a, IO, TP, OCC>, u64), Error<IO::Error>> {
let mut stream = self.find_free_entries(1)?;
let start_pos = stream.seek(io::SeekFrom::Current(0))?;
Ok((stream, start_pos))
}

fn write_entry(
&self,
name: &str,
Expand All @@ -540,8 +546,13 @@ impl<'a, IO: ReadWriteSeek, TP: TimeProvider, OCC: OemCpConverter> Dir<'a, IO, T
validate_long_name(name)?;
// convert long name to UTF-16
let lfn_utf16 = Self::encode_lfn_utf16(name);
// write LFN entries
let (mut stream, start_pos) = self.alloc_and_write_lfn_entries(&lfn_utf16, raw_entry.name())?;
// write LFN entries, except for . and .., which need to be at
// the first two slots and don't need LFNs anyway
let (mut stream, start_pos) = if name == "." || name == ".." {
self.alloc_sfn_entry()?
} else {
self.alloc_and_write_lfn_entries(&lfn_utf16, raw_entry.name())?
};
// write short name entry
raw_entry.serialize(&mut stream)?;
// Get position directory stream after entries were written
Expand Down

0 comments on commit ec6066a

Please sign in to comment.