mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Don't crash when includeing LittleFS.h w/no FS (#8173)
* Don't crash when includeing LittleFS.h w/no FS The LittleFS constructor could cause a divide-by-zero error and crash the chip during pre-main startup (i.e. when the constructors were called). Avoid by only initializing the LittleFS control structure when there is a filesystem specified in the flash layout. * Be even more paranoid on begin() and format()
This commit is contained in:
parent
20de82588e
commit
d1c7c046d5
@ -59,6 +59,7 @@ public:
|
|||||||
_mounted(false) {
|
_mounted(false) {
|
||||||
memset(&_lfs, 0, sizeof(_lfs));
|
memset(&_lfs, 0, sizeof(_lfs));
|
||||||
memset(&_lfs_cfg, 0, sizeof(_lfs_cfg));
|
memset(&_lfs_cfg, 0, sizeof(_lfs_cfg));
|
||||||
|
if (_size && _blockSize) {
|
||||||
_lfs_cfg.context = (void*) this;
|
_lfs_cfg.context = (void*) this;
|
||||||
_lfs_cfg.read = lfs_flash_read;
|
_lfs_cfg.read = lfs_flash_read;
|
||||||
_lfs_cfg.prog = lfs_flash_prog;
|
_lfs_cfg.prog = lfs_flash_prog;
|
||||||
@ -67,7 +68,7 @@ public:
|
|||||||
_lfs_cfg.read_size = 64;
|
_lfs_cfg.read_size = 64;
|
||||||
_lfs_cfg.prog_size = 64;
|
_lfs_cfg.prog_size = 64;
|
||||||
_lfs_cfg.block_size = _blockSize;
|
_lfs_cfg.block_size = _blockSize;
|
||||||
_lfs_cfg.block_count =_blockSize? _size / _blockSize: 0;
|
_lfs_cfg.block_count = _size / _blockSize;
|
||||||
_lfs_cfg.block_cycles = 16; // TODO - need better explanation
|
_lfs_cfg.block_cycles = 16; // TODO - need better explanation
|
||||||
_lfs_cfg.cache_size = 64;
|
_lfs_cfg.cache_size = 64;
|
||||||
_lfs_cfg.lookahead_size = 64;
|
_lfs_cfg.lookahead_size = 64;
|
||||||
@ -78,6 +79,7 @@ public:
|
|||||||
_lfs_cfg.file_max = 0;
|
_lfs_cfg.file_max = 0;
|
||||||
_lfs_cfg.attr_max = 0;
|
_lfs_cfg.attr_max = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
~LittleFSImpl() {
|
~LittleFSImpl() {
|
||||||
if (_mounted) {
|
if (_mounted) {
|
||||||
@ -181,7 +183,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool begin() override {
|
bool begin() override {
|
||||||
if (_size <= 0) {
|
if ((_blockSize <= 0) || (_size <= 0)) {
|
||||||
DEBUGV("LittleFS size is <= zero");
|
DEBUGV("LittleFS size is <= zero");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -203,7 +205,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool format() override {
|
bool format() override {
|
||||||
if (_size == 0) {
|
if ((_blockSize <= 0) || (_size <= 0)) {
|
||||||
DEBUGV("lfs size is zero\n");
|
DEBUGV("lfs size is zero\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user