fixed dfs(elmfat) bug: fixed the stat(st_mtime) issue.

This commit is contained in:
aozima 2013-03-01 12:23:28 +08:00
parent a67af25428
commit f71555ec55
1 changed files with 35 additions and 1 deletions

View File

@ -14,8 +14,12 @@
* 2011-11-23 Bernard fixed the rename issue.
* 2012-07-26 aozima implement ff_memalloc and ff_memfree.
* 2012-12-19 Bernard fixed the O_APPEND and lseek issue.
* 2013-03-01 aozima fixed the stat(st_mtime) issue.
*/
#include <string.h>
#include <time.h>
#include <rtthread.h>
#include "ffconf.h"
#include "ff.h"
@ -710,8 +714,38 @@ int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
st->st_mode &= ~(DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH);
st->st_size = file_info.fsize;
st->st_mtime = file_info.ftime;
st->st_blksize = 512;
/* get st_mtime. */
{
struct tm tm_file;
int year, mon, day, hour, min, sec;
WORD tmp;
tmp = file_info.fdate;
day = tmp & 0x1F; /* bit[4:0] Day(1..31) */
tmp >>= 5;
mon = tmp & 0x0F; /* bit[8:5] Month(1..12) */
tmp >>= 4;
year = (tmp & 0x7F) + 1980; /* bit[15:9] Year origin from 1980(0..127) */
tmp = file_info.ftime;
sec = (tmp & 0x1F) * 2; /* bit[4:0] Second/2(0..29) */
tmp >>= 5;
min = tmp & 0x3F; /* bit[10:5] Minute(0..59) */
tmp >>= 6;
hour = tmp & 0x1F; /* bit[15:11] Hour(0..23) */
memset(&tm_file, 0, sizeof(tm_file));
tm_file.tm_year = year - 1900; /* Years since 1900 */
tm_file.tm_mon = mon - 1; /* Months *since* january: 0-11 */
tm_file.tm_mday = day; /* Day of the month: 1-31 */
tm_file.tm_hour = hour; /* Hours since midnight: 0-23 */
tm_file.tm_min = min; /* Minutes: 0-59 */
tm_file.tm_sec = sec; /* Seconds: 0-59 */
st->st_mtime = mktime(&tm_file);
} /* get st_mtime. */
}
#if _USE_LFN