Skip to content

Convert FatFS date/time to Unix timestamp in SFTP#977

Draft
ejohnstown wants to merge 1 commit into
wolfSSL:masterfrom
ejohnstown:fatfs-times
Draft

Convert FatFS date/time to Unix timestamp in SFTP#977
ejohnstown wants to merge 1 commit into
wolfSSL:masterfrom
ejohnstown:fatfs-times

Conversation

@ejohnstown
Copy link
Copy Markdown
Contributor

  • Add TimeTo32_FatFS() to decode FatFS fdate/ftime fields via mktime()
  • Use converted timestamp for atime/mtime instead of raw fdate

- Add TimeTo32_FatFS() to decode FatFS fdate/ftime fields via mktime()
- Use converted timestamp for atime/mtime instead of raw fdate
Copilot AI review requested due to automatic review settings May 12, 2026 22:58
@ejohnstown ejohnstown marked this pull request as draft May 12, 2026 22:59
@ejohnstown
Copy link
Copy Markdown
Contributor Author

This should hopefully fix issue #975.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/ftime decoder (TimeTo32_FatFS()) that builds a struct tm and converts it via mktime().
  • Populate atr->atime / atr->mtime using the converted Unix timestamp (rather than raw info.fdate).
Comments suppressed due to low confidence (2)

src/wolfsftp.c:4893

  • struct tm.tm_year is defined as “years since 1900”, but WS_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 calling mktime().
    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 small WOLFSSH_TEST_INTERNAL helper + 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.

Comment thread src/wolfsftp.c
Comment on lines +4883 to +4887
#ifndef NO_WOLFSSH_MKTIME
/* convert nucleus date and time shorts to word32
* returns results in Unix time stamp */
static word32 TimeTo32_FatFS(word16 d, word16 t)
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants