Skip to content

Commit

Permalink
Code cleanup as per review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
huming2207 committed Jan 10, 2024
1 parent 3e5830b commit 536651b
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions src/esp_littlefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,12 @@ esp_err_t format_from_efs(esp_littlefs_t *efs)
ESP_LOGV(ESP_LITTLEFS_TAG, "Formatting filesystem");

/* Need to write explicit block_count to cfg; but skip if it's the SD card */
#ifndef CONFIG_LITTLEFS_SDMMC_SUPPORT
efs->cfg.block_count = efs->partition->size / efs->cfg.block_size;
res = lfs_format(efs->fs, &efs->cfg);
efs->cfg.block_count = 0;
#else
#ifdef CONFIG_LITTLEFS_SDMMC_SUPPORT
if (efs->sdcard) {
res = lfs_format(efs->fs, &efs->cfg);
} else {
} else
#else
{
efs->cfg.block_count = efs->partition->size / efs->cfg.block_size;
res = lfs_format(efs->fs, &efs->cfg);
efs->cfg.block_count = 0;
Expand Down Expand Up @@ -380,21 +378,21 @@ esp_err_t esp_vfs_littlefs_register(const esp_vfs_littlefs_conf_t * conf)

int index;

if(conf->partition_label) {
if (esp_littlefs_by_label(conf->partition_label, &index) != ESP_OK) {
ESP_LOGE(ESP_LITTLEFS_TAG, "Unable to find partition \"%s\"", conf->partition_label);
return ESP_ERR_NOT_FOUND;
}
}
#ifdef CONFIG_LITTLEFS_SDMMC_SUPPORT
if (conf->sdcard) {
else if (conf->sdcard) {
if (esp_littlefs_by_sdmmc_handle(conf->sdcard, &index) != ESP_OK) {
ESP_LOGE(ESP_LITTLEFS_TAG, "Unable to find SD card \"%p\"", conf->sdcard);
return ESP_ERR_NOT_FOUND;
}
} else if(conf->partition_label) {
#else
if(conf->partition_label) {
}
#endif
if (esp_littlefs_by_label(conf->partition_label, &index) != ESP_OK) {
ESP_LOGE(ESP_LITTLEFS_TAG, "Unable to find partition \"%s\"", conf->partition_label);
return ESP_ERR_NOT_FOUND;
}
} else {
else {
if (esp_littlefs_by_partition(conf->partition, &index) != ESP_OK) {
ESP_LOGE(ESP_LITTLEFS_TAG, "Unable to find partition \"0x%08"PRIX32"\"", conf->partition->address);
return ESP_ERR_NOT_FOUND;
Expand Down Expand Up @@ -878,7 +876,7 @@ static esp_err_t esp_littlefs_init_sdcard(esp_littlefs_t** efs, sdmmc_card_t* sd
(*efs)->cfg.read_size = sdcard->csd.sector_size;
(*efs)->cfg.prog_size = sdcard->csd.sector_size;
(*efs)->cfg.block_size = sdcard->csd.sector_size;
(*efs)->cfg.block_count = sdcard->csd.capacity;
(*efs)->cfg.block_count = max_allowed_blk_cnt;
(*efs)->cfg.cache_size = MAX(CONFIG_LITTLEFS_CACHE_SIZE, sdcard->csd.sector_size); // Must not be smaller than SD sector size
(*efs)->cfg.lookahead_size = CONFIG_LITTLEFS_LOOKAHEAD_SIZE;
(*efs)->cfg.block_cycles = CONFIG_LITTLEFS_BLOCK_CYCLES;
Expand Down Expand Up @@ -1032,8 +1030,9 @@ static esp_err_t esp_littlefs_init(const esp_vfs_littlefs_conf_t* conf)
if(err != ESP_OK) {
goto exit;
}
} else {
} else
#endif
{
uint32_t flash_page_size = g_rom_flashchip.page_size;
uint32_t log_page_size = CONFIG_LITTLEFS_PAGE_SIZE;
if (log_page_size % flash_page_size != 0) {
Expand All @@ -1048,10 +1047,7 @@ static esp_err_t esp_littlefs_init(const esp_vfs_littlefs_conf_t* conf)
if(err != ESP_OK) {
goto exit;
}

#ifdef CONFIG_LITTLEFS_SDMMC_SUPPORT
}
#endif

// Mount and Error Check
_efs[index] = efs;
Expand All @@ -1062,12 +1058,12 @@ static esp_err_t esp_littlefs_init(const esp_vfs_littlefs_conf_t* conf)

if (conf->format_if_mount_failed && res != LFS_ERR_OK) {
ESP_LOGW(ESP_LITTLEFS_TAG, "mount failed, %s (%i). formatting...", esp_littlefs_errno(res), res);
#ifndef CONFIG_LITTLEFS_SDMMC_SUPPORT
err = esp_littlefs_format_partition(efs->partition);
#else
#ifdef CONFIG_LITTLEFS_SDMMC_SUPPORT
if (conf->sdcard) {
err = esp_littlefs_format_sdmmc(conf->sdcard);
} else {
} else
#else
{
err = esp_littlefs_format_partition(efs->partition);
}
#endif
Expand Down

0 comments on commit 536651b

Please sign in to comment.