You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] FF_Close() does not update xModifiedTime with current system time when file is modified (ffconfigTIME_SUPPORT=1) #81
FF_GetSystemTime() implemented and verified to return correct system time
Summary
When appending or modifying a file, FF_Close() does not update xOriginalEntry.xModifiedTime (or xDirEntry.xModifiedTime) with the current system time, even though ffconfigTIME_SUPPORT = 1 and FF_GetSystemTime() is correctly implemented.
As a result, the FAT directory entry's “last modified timestamp” does not change on file close unless the modified time was manually updated earlier in the write path.
This behavior seems unintended, because FF_PutEntry() simply writes the existingxModifiedTime value into the directory entry without refreshing it.
Reproduction steps
Open a file in append or write mode:
FF_FILE*fp=ff_fopen("/file.txt", "a");
Proposed Fix
The root cause is that neither FF_Close() nor FF_PutEntry() updates xOriginalEntry.xModifiedTime (or pxDirEntry->xModifiedTime) to the current system time before storing the directory entry.
To ensure correct FAT "last modified timestamp" behavior, the modified time must be refreshed immediately before the directory entry is written back.
The FreeRTOS+FAT library is being used for a long time now. We could change FF_Close() and add a call to FF_SetFileTime(), But some users might complain that calling FF_Close() has become slower than it used to be.
We didn't update the timestamps automatically in order to save time. Also, in some cases you want to set the time stamp "manually", for instance when FTP creates a file.
So let add a new config parameters and change FF_Close() a bit.
@htibosch
Thank you for your comment.
Now, I got your situation.
However, I wonder whether I should use FF_GetSystemTime() or FF_SetFileTime(), and where its location should be. I'd like to ask you that point.
Using FF_GetSystemTime() instead of FF_SetFileTime()
My thought:FF_Close() already calls FF_GetEntry() and FF_PutEntry() when updating the file size. Using FF_SetFileTime() would cause these operations to execute twice, resulting in redundant disk I/O.
Proposed implementation: Insert FF_GetSystemTime() directly between the existing FF_GetEntry() and FF_PutEntry() calls:
No additional FF_GetEntry() call (already fetched)
No additional FF_PutEntry() call (single write)
No additional FF_FlushCache() call
Minimal performance impact
Placement: Only when file size changes
The timestamp update should be placed inside the condition that checks for file size changes:
This ensures the modified timestamp is updated only when actual file content changes, which aligns with standard filesystem behavior and avoids unnecessary updates.
Implementation location
After xOriginalEntry.ulFileSize = pxFile->ulFileSize; and before FF_PutEntry().
This approach reuses the existing directory entry fetch/write cycle, keeping FF_Close() efficient while correctly updating timestamps when files are modified.
I opened PR #86 following the config-gated approach discussed here: ffconfigUPDATE_FILE_MODIFIED_TIME_ON_CLOSE defaults to 0, and when enabled the timestamp update reuses the existing FF_Close() directory-entry write for files that were actually modified.
Activity
htibosch commentedon Feb 20, 2026
The FreeRTOS+FAT library is being used for a long time now. We could change
FF_Close()and add a call toFF_SetFileTime(), But some users might complain that callingFF_Close()has become slower than it used to be.We didn't update the timestamps automatically in order to save time. Also, in some cases you want to set the time stamp "manually", for instance when FTP creates a file.
So let add a new config parameters and change
FF_Close()a bit.Before closing the file, test for write access:
It would be good if the timestamp is only written in case it has changed.
Let's give it some thoughts.
35001215 commentedon Feb 24, 2026
@htibosch
Thank you for your comment.
Now, I got your situation.
However, I wonder whether I should use
FF_GetSystemTime()orFF_SetFileTime(), and where its location should be. I'd like to ask you that point.Using
FF_GetSystemTime()instead ofFF_SetFileTime()My thought:
FF_Close()already callsFF_GetEntry()andFF_PutEntry()when updating the file size. UsingFF_SetFileTime()would cause these operations to execute twice, resulting in redundant disk I/O.Proposed implementation: Insert
FF_GetSystemTime()directly between the existingFF_GetEntry()andFF_PutEntry()calls:FF_GetEntry()call (already fetched)FF_PutEntry()call (single write)FF_FlushCache()callPlacement: Only when file size changes
The timestamp update should be placed inside the condition that checks for file size changes:
if( ( pxFile->ulFileSize != xOriginalEntry.ulFileSize ) || ( pxFile->ulFileSize == 0UL ) )This ensures the modified timestamp is updated only when actual file content changes, which aligns with standard filesystem behavior and avoids unnecessary updates.
Implementation location
After
xOriginalEntry.ulFileSize = pxFile->ulFileSize;and beforeFF_PutEntry().This approach reuses the existing directory entry fetch/write cycle, keeping
FF_Close()efficient while correctly updating timestamps when files are modified.Is my understanding correct?
Old-Ding commentedon Jul 4, 2026
I opened PR #86 following the config-gated approach discussed here:
ffconfigUPDATE_FILE_MODIFIED_TIME_ON_CLOSEdefaults to0, and when enabled the timestamp update reuses the existingFF_Close()directory-entry write for files that were actually modified.