From 1683b12dd7105f456530931709e69f12e2994d6e Mon Sep 17 00:00:00 2001 From: Ahmed El Sharnoby Date: Fri, 22 Sep 2017 10:49:41 +0200 Subject: [PATCH] SPIFFS: update to f5e26c4, fixes #3612 (#3623) --- cores/esp8266/spiffs/spiffs_hydrogen.c | 1 - cores/esp8266/spiffs/spiffs_nucleus.c | 8 +++++++- cores/esp8266/spiffs/spiffs_nucleus.h | 22 +++++++++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/cores/esp8266/spiffs/spiffs_hydrogen.c b/cores/esp8266/spiffs/spiffs_hydrogen.c index 5ca0e048e..235aaaa60 100644 --- a/cores/esp8266/spiffs/spiffs_hydrogen.c +++ b/cores/esp8266/spiffs/spiffs_hydrogen.c @@ -481,7 +481,6 @@ s32_t SPIFFS_write(spiffs *fs, spiffs_file fh, void *buf, s32_t len) { if ((fd->flags & SPIFFS_O_APPEND)) { fd->fdoffset = fd->size == SPIFFS_UNDEFINED_LEN ? 0 : fd->size; } - offset = fd->fdoffset; #if SPIFFS_CACHE_WR diff --git a/cores/esp8266/spiffs/spiffs_nucleus.c b/cores/esp8266/spiffs/spiffs_nucleus.c index f2eda254a..27ecdff2a 100644 --- a/cores/esp8266/spiffs/spiffs_nucleus.c +++ b/cores/esp8266/spiffs/spiffs_nucleus.c @@ -1061,12 +1061,18 @@ void spiffs_cb_object_event( #if SPIFFS_TEMPORAL_FD_CACHE if (cur_fd->score == 0) continue; // never used fd #endif - SPIFFS_DBG(" callback: setting fd "_SPIPRIfd":"_SPIPRIid"(fdoffs:"_SPIPRIi" offs:"_SPIPRIi") objix_hdr_pix to "_SPIPRIpg", size:"_SPIPRIi"\n", SPIFFS_FH_OFFS(fs, cur_fd->file_nbr), cur_fd->obj_id, cur_fd->fdoffset, cur_fd->offset, new_pix, new_size); + SPIFFS_DBG(" callback: setting fd "_SPIPRIfd":"_SPIPRIid"(fdoffs:"_SPIPRIi" offs:"_SPIPRIi") objix_hdr_pix to "_SPIPRIpg", size:"_SPIPRIi"\n", + SPIFFS_FH_OFFS(fs, cur_fd->file_nbr), cur_fd->obj_id, cur_fd->fdoffset, cur_fd->offset, new_pix, new_size); cur_fd->objix_hdr_pix = new_pix; if (new_size != 0) { // update size and offsets for fds to this file cur_fd->size = new_size; u32_t act_new_size = new_size == SPIFFS_UNDEFINED_LEN ? 0 : new_size; +#if SPIFFS_CACHE_WR + if (act_new_size > 0 && cur_fd->cache_page) { + act_new_size = MAX(act_new_size, cur_fd->cache_page->offset + cur_fd->cache_page->size); + } +#endif if (cur_fd->offset > act_new_size) { cur_fd->offset = act_new_size; } diff --git a/cores/esp8266/spiffs/spiffs_nucleus.h b/cores/esp8266/spiffs/spiffs_nucleus.h index 3d77d508a..dd1c414bc 100644 --- a/cores/esp8266/spiffs/spiffs_nucleus.h +++ b/cores/esp8266/spiffs/spiffs_nucleus.h @@ -141,6 +141,22 @@ #define SPIFFS_OBJ_ID_DELETED ((spiffs_obj_id)0) #define SPIFFS_OBJ_ID_FREE ((spiffs_obj_id)-1) + + +#if defined(__GNUC__) || defined(__clang__) + /* For GCC and clang */ +#define SPIFFS_PACKED __attribute__((packed)) +#elif defined(__ICCARM__) || defined(__CC_ARM) + /* For IAR ARM and Keil MDK-ARM compilers */ +#define SPIFFS_PACKED + +#else + /* Unknown compiler */ +#define SPIFFS_PACKED +#endif + + + #if SPIFFS_USE_MAGIC #if !SPIFFS_USE_MAGIC_LENGTH #define SPIFFS_MAGIC(fs, bix) \ @@ -464,7 +480,7 @@ typedef struct { // page header, part of each page except object lookup pages // NB: this is always aligned when the data page is an object index, // as in this case struct spiffs_page_object_ix is used -typedef struct __attribute(( packed )) { +typedef struct SPIFFS_PACKED { // object id spiffs_obj_id obj_id; // object span index @@ -474,7 +490,7 @@ typedef struct __attribute(( packed )) { } spiffs_page_header; // object index header page header -typedef struct __attribute(( packed )) +typedef struct SPIFFS_PACKED #if SPIFFS_ALIGNED_OBJECT_INDEX_TABLES __attribute(( aligned(sizeof(spiffs_page_ix)) )) #endif @@ -496,7 +512,7 @@ typedef struct __attribute(( packed )) } spiffs_page_object_ix_header; // object index page header -typedef struct __attribute(( packed )) { +typedef struct SPIFFS_PACKED { spiffs_page_header p_hdr; u8_t _align[4 - ((sizeof(spiffs_page_header)&3)==0 ? 4 : (sizeof(spiffs_page_header)&3))]; } spiffs_page_object_ix;