From 98423fa79daf3160946deec8afb597094e2f7876 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Sun, 16 Aug 2015 14:00:35 +0300 Subject: [PATCH 1/2] Fix FS size and add type size checks --- cores/esp8266/spiffs_api.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/cores/esp8266/spiffs_api.cpp b/cores/esp8266/spiffs_api.cpp index c482c8438..6f63c59cd 100644 --- a/cores/esp8266/spiffs_api.cpp +++ b/cores/esp8266/spiffs_api.cpp @@ -23,9 +23,12 @@ */ #include "FS.h" +#undef max +#undef min #include "FSImpl.h" #include "spiffs/spiffs.h" #include "debug.h" +#include extern "C" { #include "c_types.h" @@ -119,6 +122,27 @@ protected: config.log_block_size = _blockSize; config.log_page_size = _pageSize; + + if (((uint32_t) std::numeric_limits::max()) < (_size / _blockSize)) { + DEBUGV("spiffs_block_ix type too small"); + abort(); + } + + if (((uint32_t) std::numeric_limits::max()) < (_size / _pageSize)) { + DEBUGV("spiffs_page_ix type too small"); + abort(); + } + + if (((uint32_t) std::numeric_limits::max()) < (2 + (_size / (2*_pageSize))*2)) { + DEBUGV("spiffs_obj_id type too small"); + abort(); + } + + if (((uint32_t) std::numeric_limits::max()) < (_size / _pageSize - 1)) { + DEBUGV("spiffs_span_ix type too small"); + abort(); + } + // hack: even though fs is not initialized at this point, // SPIFFS_buffer_bytes_for_cache uses only fs->config.log_page_size // suggestion: change SPIFFS_buffer_bytes_for_cache to take @@ -381,8 +405,8 @@ extern "C" uint32_t _SPIFFS_page; extern "C" uint32_t _SPIFFS_block; static SPIFFSImpl s_defaultFs( - (uint32_t) &_SPIFFS_start - 0x40200000, - (uint32_t) (&_SPIFFS_end - &_SPIFFS_start), + (uint32_t) (&_SPIFFS_start) - 0x40200000, + (uint32_t) (&_SPIFFS_end) - (uint32_t) (&_SPIFFS_start), (uint32_t) &_SPIFFS_page, (uint32_t) &_SPIFFS_block, 5); From fac840b6a8740536212242dbf9ecf1d35df312a1 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Sun, 16 Aug 2015 14:39:16 +0300 Subject: [PATCH 2/2] Use optimistic_yield in FS read and write --- cores/esp8266/spiffs_hal.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cores/esp8266/spiffs_hal.cpp b/cores/esp8266/spiffs_hal.cpp index 2719eb6e0..6fab52266 100644 --- a/cores/esp8266/spiffs_hal.cpp +++ b/cores/esp8266/spiffs_hal.cpp @@ -31,18 +31,20 @@ extern "C" { } static int spi_flash_read_locked(uint32_t addr, uint32_t* dst, uint32_t size) { - InterruptLock lock; + optimistic_yield(10000); + AutoInterruptLock(5); return spi_flash_read(addr, dst, size); } static int spi_flash_write_locked(uint32_t addr, const uint32_t* src, uint32_t size) { - InterruptLock lock; + optimistic_yield(10000); + AutoInterruptLock(5); return spi_flash_write(addr, (uint32_t*) src, size); } static int spi_flash_erase_sector_locked(uint32_t sector) { optimistic_yield(10000); - InterruptLock lock; + AutoInterruptLock(5); return spi_flash_erase_sector(sector); }