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

Don't create LFNs for . and .. #100

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ New features:
Bug fixes:
* Fix formatting volumes with size in range 4096-4199 KB
* Always respect `fat_type` from `FormatVolumeOptions`
* Put '.' and '..' in the first two directory entries. (fixes "Expected a valid '.' entry in this slot." fsck error)

0.3.4 (2020-07-20)
------------------
Expand Down
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