Convert FatFS date/time to Unix timestamp in SFTP#977
Open
ejohnstown wants to merge 1 commit into
Open
Conversation
Contributor
Author
|
This should hopefully fix issue #975. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the SFTP FatFS backend to report file timestamps as Unix epoch seconds instead of returning raw FatFS fdate values, aligning the returned attributes with SFTP’s expected time representation.
Changes:
- Add a FatFS
fdate/ftimedecoder (TimeTo32_FatFS()) that builds astruct tmand converts it viamktime(). - Populate
atr->atime/atr->mtimeusing the converted Unix timestamp (rather than rawinfo.fdate).
Comments suppressed due to low confidence (2)
src/wolfsftp.c:4893
struct tm.tm_yearis defined as “years since 1900”, butWS_GETYEAR(d)returns a FatFS year offset from 1980 (0..127). As written this will convert 1980->1900, 2024->1944, etc. Adjust the year by +80 (same as the existing Nucleus TimeTo32() implementation above) before callingmktime().
tmp.tm_mday = WS_GETDAY(d);
tmp.tm_mon = WS_GETMON(d);
tmp.tm_year = WS_GETYEAR(d);
tmp.tm_hour = WS_GETHOUR(t);
src/wolfsftp.c:4897
- This adds a new platform-specific date/time conversion that’s easy to get subtly wrong (year base, month base, seconds/2). There is an internal regression test for the analogous Nucleus month conversion (
TestNucleusMonthConversion); consider adding a smallWOLFSSH_TEST_INTERNALhelper + regress test for FatFS conversion (at least year base + month conversion) so future refactors don’t break timestamps again.
static word32 TimeTo32_FatFS(word16 d, word16 t)
{
struct tm tmp = {0};
tmp.tm_mday = WS_GETDAY(d);
tmp.tm_mon = WS_GETMON(d);
tmp.tm_year = WS_GETYEAR(d);
tmp.tm_hour = WS_GETHOUR(t);
tmp.tm_min = WS_GETMIN(t);
tmp.tm_sec = WS_GETSEC(t);
return mktime(&tmp);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
J-Goldacker
reviewed
May 13, 2026
- Add SetAttrTime() helper to decode fdate/ftime into a Unix timestamp via mktime() and assigns it to atr->atime/mtime. - Use it from both SFTP_GetAttributes() (was using raw fdate) and SFTP_GetAttributes_Handle() (was using raw ftime, losing the date).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.