Open joel-jetcharge opened 2 years ago
Hi, thank you for the workaround. It works for me.
Also, it seems that the issue is related to the SEARCH_CACHE feature. When the macro FX_MEDIA_DISABLE_SEARCH_CACHE is defined, there is no problem. But the reopening process will be more expensive.
When calling
fx_file_write
on a file thefx_file_dir_entry.fx_dir_entry_available_file_size
field is not being updated before saving the directory entry. This causes issues when a file is re-opened as thefx_file_current_available_size
field will be set to 0 even though disk space has been allocated.Example code to demonstrate issue:
Continuing to write to a file in this state causes unexpected behaviour. As
fx_file_current_file_offset
is non-zero we get an underflow onfx_file_write.c:292
:The driver will continue to think there is enough space allocated even when there is not. Clusters will be written to even though they were not properly allocated.
I tested with both Fault Tolerant module on and off, with same results for exFAT. I also tested with FAT16 which does not have the issue as
fx_file_current_available_size
is calculated differently.Workaround: As a temporary fix I've added the following code to
fx_file_write.c:1603
andfx_file_write.c:1698
(i.e. below wherefx_file_dir_entry.fx_dir_entry_file_size
is updated):