From 58f046715ef925b77af0180d1a61db1d6d12cac3 Mon Sep 17 00:00:00 2001 From: luc lebosse Date: Sat, 14 Oct 2017 14:52:40 +0200 Subject: [PATCH] Unify the time file creation for SPIFFS and SD --- components/fatfs/src/vfs_fat.c | 5 +++++ components/spiffs/esp_spiffs.c | 22 ++++++++++++++++++++++ components/spiffs/include/spiffs_config.h | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/components/fatfs/src/vfs_fat.c b/components/fatfs/src/vfs_fat.c index a5a12d5b65..b1192b602c 100644 --- a/components/fatfs/src/vfs_fat.c +++ b/components/fatfs/src/vfs_fat.c @@ -389,6 +389,9 @@ static int vfs_fat_fstat(void* ctx, int fd, struct stat * st) FIL* file = &fat_ctx->files[fd]; st->st_size = f_size(file); st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFREG; + st->st_mtime = 0; + st->st_atime = 0; + st->st_ctime = 0; return 0; } @@ -422,6 +425,8 @@ static int vfs_fat_stat(void* ctx, const char * path, struct stat * st) ftime >>= 6; tm.tm_hour = (ftime & 0x1f); st->st_mtime = mktime(&tm); + st->st_atime = 0; + st->st_ctime = 0; return 0; } diff --git a/components/spiffs/esp_spiffs.c b/components/spiffs/esp_spiffs.c index 3f81b151d5..4520c81fa6 100644 --- a/components/spiffs/esp_spiffs.c +++ b/components/spiffs/esp_spiffs.c @@ -513,6 +513,16 @@ static int vfs_spiffs_open(void* ctx, const char * path, int flags, int mode) SPIFFS_clearerr(efs->fs); return -1; } +#if SPIFFS_OBJ_META_LEN > 0 + if (!(spiffs_mode_conv(flags) & SPIFFS_O_RDONLY)) + { + time_t t = time(NULL); + struct tm tmr; + localtime_r(&t, &tmr); + time_t meta = mktime(&tmr); + SPIFFS_fupdate_meta(efs->fs, fd, &meta); + } +#endif return fd; } @@ -578,6 +588,9 @@ static int vfs_spiffs_fstat(void* ctx, int fd, struct stat * st) } st->st_size = s.size; st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFREG; + st->st_mtime = 0; + st->st_atime = 0; + st->st_ctime = 0; return res; } @@ -597,6 +610,15 @@ static int vfs_spiffs_stat(void* ctx, const char * path, struct stat * st) st->st_size = s.size; st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO; st->st_mode |= (s.type == SPIFFS_TYPE_DIR)?S_IFDIR:S_IFREG; +#if SPIFFS_OBJ_META_LEN > 0 + time_t t =0; + memcpy(&t, s.meta, sizeof(time_t)); + st->st_mtime = t; +#else + st->st_mtime = 0; +#endif + st->st_atime = 0; + st->st_ctime = 0; return res; } diff --git a/components/spiffs/include/spiffs_config.h b/components/spiffs/include/spiffs_config.h index e412bfd0cf..c96a3412d3 100755 --- a/components/spiffs/include/spiffs_config.h +++ b/components/spiffs/include/spiffs_config.h @@ -158,7 +158,7 @@ extern void spiffs_api_unlock(struct spiffs_t *fs); // This is derived from following: // logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) + // spiffs_object_ix_header fields + at least some LUT entries) -#define SPIFFS_OBJ_META_LEN (0) +#define SPIFFS_OBJ_META_LEN (4) // Size of buffer allocated on stack used when copying data. // Lower value generates more read/writes. No meaning having it bigger