Hi
When data is written to a file the data content is copied first and stored in the file's cluster chain.
As long as there was no error doing this the FAT is updated accordingly.
The code to update the FAT looks something like this (in utWriteFile()):
if (ptr_utFile->usLastReadWriteLength != 0) { // updata the file entry if there was a change
DIR_ENTRY_STRUCTURE_FAT32 *ptrFileEntry = (DIR_ENTRY_STRUCTURE_FAT32 *)ptr_utDisk->ptrSectorData; // the directory entry in the sector buffer
ptrFileEntry += ptr_utFile->private_disk_location.ucDirectoryEntry; // move to the file entry
if (fnLoadSector(ptr_utDisk, ptr_utFile->private_disk_location.directory_location.ulSector) != UTFAT_SUCCESS) { // ensure that the directory sector is loaded
return UTFAT_DISK_READ_ERROR;
}
fnSetFileInformation(ptrFileEntry, ptr_utFile->ulFileSize);
while (utCommitSector(ptr_utDisk, ptr_utFile->private_disk_location.directory_location.ulSector) == CARD_BUSY_WAIT) {} // force writeback to finalise the operation
ptr_utDisk->usDiskFlags &= ~WRITEBACK_BUFFER_FLAG;
}
As long as there had been a change made the directory entry is read to a local buffer and then the content is changed - meaning that the file size is updated and its write data (if supported) and the buffer is written back.
If your file content changes but the FAT is not updated there must be a problem around here, such as the FAT write failing or there being a reset before it was written. Any failures can be detected by the caller since UTFAT_SUCCESS will not be returned, meaning that you should be able to detect if something like this is taking place.
Regards
Mark