Skip to content
4 changes: 4 additions & 0 deletions src/LITTLEFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
13 changes: 10 additions & 3 deletions src/esp_littlefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down