diff --git a/src/LITTLEFS.cpp b/src/LITTLEFS.cpp index d14f1ee..6b4ab0b 100644 --- a/src/LITTLEFS.cpp +++ b/src/LITTLEFS.cpp @@ -41,7 +41,11 @@ LITTLEFSImpl::LITTLEFSImpl() bool LITTLEFSImpl::exists(const char* path) { +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0) + File f = open(path, "r", false); +#else File f = open(path, "r"); +#endif return (f == true); } diff --git a/src/esp_littlefs.c b/src/esp_littlefs.c index 2b0c2e4..9bdff1e 100644 --- a/src/esp_littlefs.c +++ b/src/esp_littlefs.c @@ -182,11 +182,18 @@ esp_err_t esp_littlefs_info(const char* partition_label, size_t *total_bytes, si esp_littlefs_t *efs = NULL; err = esp_littlefs_by_label(partition_label, &index); - if(err != ESP_OK) return false; + if(err != ESP_OK) return err; efs = _efs[index]; - if(total_bytes) *total_bytes = efs->cfg.block_size * efs->cfg.block_count; - if(used_bytes) *used_bytes = efs->cfg.block_size * lfs_fs_size(efs->fs); + sem_take(efs); + size_t total_bytes_local = efs->cfg.block_size * efs->cfg.block_count; + if(total_bytes) *total_bytes = total_bytes_local; + + /* lfs_fs_size may return a size larger than the actual filesystem size. + * https://github.com/littlefs-project/littlefs/blob/9c7e232086f865cff0bb96fe753deb66431d91fd/lfs.h#L658 + */ + if(used_bytes) *used_bytes = MIN(total_bytes_local, efs->cfg.block_size * lfs_fs_size(efs->fs)); + sem_give(efs); return ESP_OK; }