Skip to content

Commit

Permalink
Limit SD card size
Browse files Browse the repository at this point in the history
  • Loading branch information
huming2207 committed Jan 10, 2024
1 parent 536651b commit 74cb038
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/esp_littlefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,16 @@ static esp_err_t esp_littlefs_init_sdcard(esp_littlefs_t** efs, sdmmc_card_t* sd
(*efs)->cfg.erase = littlefs_sdmmc_erase;
(*efs)->cfg.sync = littlefs_sdmmc_sync;

size_t max_allowed_blk_cnt = 0;
if (((uint64_t)sdcard->csd.capacity * (uint64_t)sdcard->csd.sector_size) > SIZE_MAX) {
max_allowed_blk_cnt = SIZE_MAX / sdcard->csd.sector_size;
ESP_LOGW(ESP_LITTLEFS_TAG, "SD card is too big (sector=%d, count=%d; total=%llu bytes), throttling to maximum possible %u blocks",
sdcard->csd.sector_size, sdcard->csd.capacity,
(((uint64_t)sdcard->csd.capacity * (uint64_t)sdcard->csd.sector_size)), max_allowed_blk_cnt);
} else {
max_allowed_blk_cnt = sdcard->csd.capacity;
}

// block device configuration
(*efs)->cfg.read_size = sdcard->csd.sector_size;
(*efs)->cfg.prog_size = sdcard->csd.sector_size;
Expand Down

0 comments on commit 74cb038

Please sign in to comment.