@@ -348,6 +348,13 @@ PARTITION* _FAT_partition_getPartitionFromPath (const char* path) {
348348 return (PARTITION * )devops -> deviceData ;
349349}
350350
351+ static void _FAT_updateFS_INFO (PARTITION * partition , uint8_t * sectorBuffer ) {
352+ partition -> fat .numberFreeCluster = _FAT_fat_freeClusterCount (partition );
353+ u32_to_u8array (sectorBuffer , FSIB_numberOfFreeCluster , partition -> fat .numberFreeCluster );
354+ u32_to_u8array (sectorBuffer , FSIB_numberLastAllocCluster , partition -> fat .numberLastAllocCluster );
355+ _FAT_disc_writeSectors (partition -> disc , partition -> fsInfoSector , 1 , sectorBuffer );
356+ }
357+
351358void _FAT_partition_createFSinfo (PARTITION * partition )
352359{
353360 if (partition -> readOnly || partition -> filesysType != FS_FAT32 )
@@ -364,14 +371,10 @@ void _FAT_partition_createFSinfo(PARTITION * partition)
364371 sectorBuffer [FSIB_SIG2 + i ] = FS_INFO_SIG2 [i ];
365372 }
366373
367- partition -> fat .numberFreeCluster = _FAT_fat_freeClusterCount (partition );
368- u32_to_u8array (sectorBuffer , FSIB_numberOfFreeCluster , partition -> fat .numberFreeCluster );
369- u32_to_u8array (sectorBuffer , FSIB_numberLastAllocCluster , partition -> fat .numberLastAllocCluster );
370-
371374 sectorBuffer [FSIB_bootSig_55 ] = 0x55 ;
372375 sectorBuffer [FSIB_bootSig_AA ] = 0xAA ;
373376
374- _FAT_disc_writeSectors (partition -> disc , partition -> fsInfoSector , 1 , sectorBuffer );
377+ _FAT_updateFS_INFO (partition , sectorBuffer );
375378
376379 _FAT_mem_free (sectorBuffer );
377380}
@@ -398,6 +401,10 @@ void _FAT_partition_readFSinfo(PARTITION * partition)
398401 _FAT_partition_createFSinfo (partition );
399402 } else {
400403 partition -> fat .numberFreeCluster = u8array_to_u32 (sectorBuffer , FSIB_numberOfFreeCluster );
404+ if (partition -> fat .numberFreeCluster == 0xffffffff ) {
405+ _FAT_updateFS_INFO (partition ,sectorBuffer );
406+ partition -> fat .numberFreeCluster = u8array_to_u32 (sectorBuffer , FSIB_numberOfFreeCluster );
407+ }
401408 partition -> fat .numberLastAllocCluster = u8array_to_u32 (sectorBuffer , FSIB_numberLastAllocCluster );
402409 }
403410 _FAT_mem_free (sectorBuffer );
0 commit comments