From: Ivan Grokhotkov Date: Wed, 13 Dec 2017 03:10:27 +0000 (+0800) Subject: Merge branch 'bugfix/fatfs_stat' into 'master' X-Git-Tag: v3.1-beta1~545 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4839da4d98d03f645ee044b01261a9c595627c80;p=esp-idf Merge branch 'bugfix/fatfs_stat' into 'master' Fix stat behavior for FATFS mount point See merge request !1652 --- 4839da4d98d03f645ee044b01261a9c595627c80 diff --cc components/fatfs/src/vfs_fat.c index b1192b602c,6b0180cb4d..556492e3ed --- a/components/fatfs/src/vfs_fat.c +++ b/components/fatfs/src/vfs_fat.c @@@ -408,25 -439,21 +442,23 @@@ static int vfs_fat_stat(void* ctx, cons errno = fresult_to_errno(res); return -1; } + + memset(st, 0, sizeof(*st)); st->st_size = info.fsize; - st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO | - ((info.fattrib & AM_DIR) ? S_IFDIR : S_IFREG); - struct tm tm; - uint16_t fdate = info.fdate; - tm.tm_mday = fdate & 0x1f; - fdate >>= 5; - tm.tm_mon = (fdate & 0xf) - 1; - fdate >>=4; - tm.tm_year = fdate + 80; - uint16_t ftime = info.ftime; - tm.tm_sec = (ftime & 0x1f) * 2; - ftime >>= 5; - tm.tm_min = (ftime & 0x3f); - ftime >>= 6; - tm.tm_hour = (ftime & 0x1f); + st->st_mode = get_stat_mode((info.fattrib & AM_DIR) != 0); + fat_date_t fdate = { .as_int = info.fdate }; + fat_time_t ftime = { .as_int = info.ftime }; + struct tm tm = { + .tm_mday = fdate.mday, + .tm_mon = fdate.mon - 1, /* unlike tm_mday, tm_mon is zero-based */ + .tm_year = fdate.year + 80, + .tm_sec = ftime.sec * 2, + .tm_min = ftime.min, + .tm_hour = ftime.hour + }; st->st_mtime = mktime(&tm); + st->st_atime = 0; + st->st_ctime = 0; return 0; }