Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix .. cluster number for first-level dirs #99

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't create LFNs for . and ..
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.
badicsalex committed Oct 28, 2024
commit 34c83e30e3c34dcf7eb1e4c8c5cbd83638e9804e
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ Bug fixes:
* Fix formatting volumes with size in range 4096-4199 KB
* Always respect `fat_type` from `FormatVolumeOptions`
* Fill FAT32 root directory clusters with zeros after allocation to avoid interpreting old data as directory entries
* Put '.' and '..' in the first two directory entries. (fixes "Expected a valid '.' entry in this slot." fsck error)

0.3.4 (2020-07-20)
------------------
15 changes: 13 additions & 2 deletions src/dir.rs
Original file line number Diff line number Diff line change
@@ -529,6 +529,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,
@@ -539,8 +545,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