瀏覽代碼

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

aozima 12 年之前
父節點
當前提交
f71555ec55
共有 1 個文件被更改,包括 35 次插入1 次删除
  1. 35 1
      components/dfs/filesystems/elmfat/dfs_elm.c

+ 35 - 1
components/dfs/filesystems/elmfat/dfs_elm.c

@@ -14,8 +14,12 @@
  * 2011-11-23     Bernard      fixed the rename issue.
  * 2011-11-23     Bernard      fixed the rename issue.
  * 2012-07-26     aozima       implement ff_memalloc and ff_memfree.
  * 2012-07-26     aozima       implement ff_memalloc and ff_memfree.
  * 2012-12-19     Bernard      fixed the O_APPEND and lseek issue.
  * 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 <rtthread.h>
 #include "ffconf.h"
 #include "ffconf.h"
 #include "ff.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_mode &= ~(DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH);
 
 
         st->st_size  = file_info.fsize;
         st->st_size  = file_info.fsize;
-        st->st_mtime = file_info.ftime;
         st->st_blksize = 512;
         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
 #if _USE_LFN