summaryrefslogtreecommitdiff
path: root/firmware/common
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common')
-rw-r--r--firmware/common/dircache.c29
-rw-r--r--firmware/common/file.c1
2 files changed, 30 insertions, 0 deletions
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c
index 97c58842d5..ab33d1213d 100644
--- a/firmware/common/dircache.c
+++ b/firmware/common/dircache.c
@@ -37,6 +37,10 @@
#include "usb.h"
#include "file.h"
#include "buffer.h"
+#if CONFIG_RTC
+#include "time.h"
+#include "timefuncs.h"
+#endif
/* Queue commands. */
#define DIRCACHE_BUILD 1
@@ -956,6 +960,31 @@ void dircache_update_filesize(int fd, long newsize, long startcluster)
fd_bindings[fd]->size = newsize;
fd_bindings[fd]->startcluster = startcluster;
}
+void dircache_update_filetime(int fd)
+{
+#if CONFIG_RTC == 0
+ (void)fd;
+#else
+ short year;
+ struct tm *now = get_time();
+ if (!dircache_initialized || fd < 0)
+ return ;
+
+ if (fd_bindings[fd] == NULL)
+ {
+ logf("dircache fd access error");
+ dircache_initialized = false;
+ return ;
+ }
+ year = now->tm_year+1900-1980;
+ fd_bindings[fd]->wrtdate = (((year)&0x7f)<<9) |
+ (((now->tm_mon+1)&0xf)<<5) |
+ (((now->tm_mday)&0x1f));
+ fd_bindings[fd]->wrttime = (((now->tm_hour)&0x1f)<<11) |
+ (((now->tm_min)&0x3f)<<5) |
+ (((now->tm_sec/2)&0x1f));
+#endif
+}
void dircache_mkdir(const char *path)
{ /* Test ok. */
diff --git a/firmware/common/file.c b/firmware/common/file.c
index d526f28859..ea2471ae92 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -250,6 +250,7 @@ int close(int fd)
return rc * 10 - 3;
#ifdef HAVE_DIRCACHE
dircache_update_filesize(fd, file->size, file->fatfile.firstcluster);
+ dircache_update_filetime(fd);
#endif
}