Corruption happens if:
* files are created in non-root directory
* directory size becomes greater or equal to cluster size
Creating last directory entry in the directory cluster corrupts the
cluster directly preceding the directory cluster.
For 512 bytes long cluster creating 8th directory entry (counted from 1)
will cause first corruption.
Directory entry that causes the corruption will not be updated correctly.
Fixes#42
This brings fatfs closer to working on stable Rust - only stable core-io
crate is needed now.
This change was merged previously to master in commit
64eec4b3ad3981ff1c3f5225897d26e5b427a4df
Issue is caused by core_io crate requiring very old rustc which is not
compatible with byteorder create since version 1.3.
In crates depending on fatfs byteorder version can be overriden in
their Cargo.toml file.
* FAT type should be properly selected even if custom cluster size is used.
* root_entries has been renamed to max_root_dir_entries in FormatVolumeOptions
* added option FormatVolumeOptions::fats
* moved bytes_per_sector and total_sectors from FormatVolumeOptions::new
to a dedicated methods (it is optional now)
* calculate total number of sectors using seek() to disk end if not provided
* added more doc comments
* added assertions about disk handle position being zero
Fail mounting if:
* root_entries is zero (only on FAT12/FAT16)
* backup_boot_sector is outside of the reserved region (only on FAT32)
* fs_info_sector is outside of the reserved region (only on FAT32)
New formula gives nearly perfect results (according to tests) and is
better than formula from specification.
Also all math transformations are provided in comments so it is no longer
a blindly copied formula from spec but a Math supported formula.
Old formula was not taking into account sector size (it resulted in too
big FATs for sector size different than 512) and had rounding issues for
FAT12 and FAT32.
Previous implementation did not zero allocated cluster so created directory
could have garbage contents.
Bug exists in code since version 0.2 and all code using create_dir is
affected.
This commit also improves tests of volume formatting so a dirty partition
is used allowing to detect bugs like this.