Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 55 additions & 4 deletions src/wolfsftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4850,6 +4850,54 @@ static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,

#elif defined(WOLFSSH_FATFS)

/*
* fdate
* The date when the file was modified or the directory was created.
* bit15:9
* Year origin from 1980 (0..127)
* bit8:5
* Month (1..12)
* bit4:0
* Day (1..31)
*
* ftime
* The time when the file was modified or the directory was created.
* bit15:11
* Hour (0..23)
* bit10:5
* Minute (0..59)
* bit4:0
* Second / 2 (0..29)
*
* mktime() expects month from 0 to 11. FatFS months
* are saved as 1 to 12. Hence 1 is being deducted to
* make it compatible with Unix time stamp.
*/
#define WS_GETDAY(d) ((d) & 0x001f)
#define WS_GETMON(d) ((((d) >> 5) & 0x000f) - 1)
#define WS_GETYEAR(d) (((d) >> 9) & 0x007f)
#define WS_GETHOUR(t) (((t) >> 11) & 0x001f)
#define WS_GETMIN(t) (((t) >> 5 ) & 0x003f)
#define WS_GETSEC(t) (((t) << 1 ) & 0x003f)

#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)
{
Comment on lines +4883 to +4887
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);
}
#endif /* NO_WOLFSSH_MKTIME */

/* FatFs has its own structure for file attributes */

static int SFTP_GetAttributes(void* fs, const char* fileName,
Expand Down Expand Up @@ -4907,10 +4955,13 @@ static int SFTP_GetAttributes(void* fs, const char* fileName,
}

#ifndef NO_WOLFSSH_MKTIME
/* get file times */
atr->flags |= WOLFSSH_FILEATRB_TIME;
atr->atime = info.fdate;
atr->mtime = info.fdate;
{
/* get file times */
word32 daytime = TimeTo32_FatFS(info.fdate, info.ftime);
atr->flags |= WOLFSSH_FILEATRB_TIME;
atr->atime = daytime;
atr->mtime = daytime;
}
#endif /* NO_WOLFSSH_MKTIME */
return WS_SUCCESS;
}
Expand Down
Loading