Hello everyone,
I can’t find a flush function in FreeRTOS FAT.
After calling ff_fwrite() function, i have to call ff_fclose() to flush data to disk. Then open the file again next writting time, it’s really unconveniant. Is there a way to synchronize the data to disk without calling ff_fclose?
You can call this to flush the data:
FF_SDDiskFlush(pxFile->pxIOManager->xBlkDevice.pxDisk);
where pxFile
is your FF_FILE *pxFile
.
But, it won’t update the file size. For that, if you like to live dangerously, you could try this:
// Make Filesize equal to the FilePointer
FF_Error_t FF_UpdateDirEnt( FF_FILE *pxFile )
{
FF_DirEnt_t xOriginalEntry;
FF_Error_t xError;
/* Get the directory entry and update it to show the new file size */
xError = FF_GetEntry( pxFile->pxIOManager, pxFile->usDirEntry, pxFile->ulDirCluster, &xOriginalEntry );
/* Now update the directory entry */
if( ( FF_isERR( xError ) == pdFALSE ) &&
( ( pxFile->ulFileSize != xOriginalEntry.ulFileSize ) || ( pxFile->ulFileSize == 0UL ) ) )
{
if( pxFile->ulFileSize == 0UL )
{
xOriginalEntry.ulObjectCluster = 0;
}
xOriginalEntry.ulFileSize = pxFile->ulFileSize;
xError = FF_PutEntry( pxFile->pxIOManager, pxFile->usDirEntry, pxFile->ulDirCluster, &xOriginalEntry, NULL );
}
return xError;
}