mirror of
https://github.com/eclipse-threadx/filex.git
synced 2026-09-14 04:05:59 +08:00
Fixed potential file system corruption when truncating or overwriting file data with fault tolerant mode enabled (#78)
* _fx_fault_tolerant_cleanup_FAT_chain(): Add checks to prevent starting a new cluster deletion session in some corner cases where the end of the chain is reached. * Fixed formatting of previous commit.
This commit is contained in:
@@ -207,7 +207,7 @@ ULONG last_FAT_sector;
|
||||
|
||||
/* At this point, the head_cluster points to the cluster chain that is to be removed. */
|
||||
|
||||
/* Tail cluster points to the back of the origianal FAT chain where the new chain is attached to.
|
||||
/* Tail cluster points to the back of the original FAT chain where the new chain is attached to.
|
||||
The remove process terminates once this cluster is encountered. */
|
||||
tail_cluster = _fx_utility_32_unsigned_read((UCHAR *)&FAT_chain -> fx_fault_tolerant_FAT_chain_insertion_back);
|
||||
|
||||
@@ -261,9 +261,13 @@ ULONG last_FAT_sector;
|
||||
if (_fx_utility_FAT_entry_multiple_sectors_check(media_ptr, current_cluster))
|
||||
{
|
||||
if (head_cluster == next_session || next_session == FX_FREE_CLUSTER)
|
||||
{
|
||||
/* Do not start another session if this is the end of the chain. */
|
||||
if (next_cluster != tail_cluster)
|
||||
{
|
||||
next_session = next_cluster;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -276,9 +280,13 @@ ULONG last_FAT_sector;
|
||||
|
||||
/* Get next session. */
|
||||
if (cache_count == cache_max)
|
||||
{
|
||||
/* Do not start another session if this is the end of the chain. */
|
||||
if (next_cluster != tail_cluster)
|
||||
{
|
||||
next_session = next_cluster;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update head cluster and next session into log file. */
|
||||
_fx_utility_32_unsigned_write((UCHAR *)&FAT_chain -> fx_fault_tolerant_FAT_chain_next_deletion, next_session);
|
||||
|
||||
Reference in New Issue
Block a user