Skip to content

Commit dfe5084

Browse files
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.
1 parent 0462b02 commit dfe5084

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

common/src/fx_fault_tolerant_cleanup_FAT_chain.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ ULONG last_FAT_sector;
207207

208208
/* At this point, the head_cluster points to the cluster chain that is to be removed. */
209209

210-
/* Tail cluster points to the back of the origianal FAT chain where the new chain is attached to.
210+
/* Tail cluster points to the back of the original FAT chain where the new chain is attached to.
211211
The remove process terminates once this cluster is encountered. */
212212
tail_cluster = _fx_utility_32_unsigned_read((UCHAR *)&FAT_chain -> fx_fault_tolerant_FAT_chain_insertion_back);
213213

@@ -262,7 +262,11 @@ ULONG last_FAT_sector;
262262
{
263263
if (head_cluster == next_session || next_session == FX_FREE_CLUSTER)
264264
{
265-
next_session = next_cluster;
265+
/* Do not start another session if this is the end of the chain. */
266+
if (next_cluster != tail_cluster)
267+
{
268+
next_session = next_cluster;
269+
}
266270
}
267271
break;
268272
}
@@ -277,7 +281,11 @@ ULONG last_FAT_sector;
277281
/* Get next session. */
278282
if (cache_count == cache_max)
279283
{
280-
next_session = next_cluster;
284+
/* Do not start another session if this is the end of the chain. */
285+
if (next_cluster != tail_cluster)
286+
{
287+
next_session = next_cluster;
288+
}
281289
}
282290

283291
/* Update head cluster and next session into log file. */

0 commit comments

Comments
 (0)