|
17 | 17 | #include "esp_log.h" |
18 | 18 | #include "esp_vfs.h" |
19 | 19 | #include "esp_vfs_fat.h" |
| 20 | +#include "vfs_fat_internal.h" |
20 | 21 | #include "driver/sdmmc_host.h" |
21 | 22 | #include "driver/sdspi_host.h" |
22 | 23 | #include "sdmmc_cmd.h" |
@@ -112,16 +113,23 @@ esp_err_t esp_vfs_fat_sdmmc_mount(const char* base_path, |
112 | 113 | goto fail; |
113 | 114 | } |
114 | 115 | ESP_LOGW(TAG, "partitioning card"); |
115 | | - DWORD plist[] = {100, 0, 0, 0}; |
116 | 116 | workbuf = malloc(workbuf_size); |
| 117 | + if (workbuf == NULL) { |
| 118 | + err = ESP_ERR_NO_MEM; |
| 119 | + goto fail; |
| 120 | + } |
| 121 | + DWORD plist[] = {100, 0, 0, 0}; |
117 | 122 | res = f_fdisk(s_pdrv, plist, workbuf); |
118 | 123 | if (res != FR_OK) { |
119 | 124 | err = ESP_FAIL; |
120 | 125 | ESP_LOGD(TAG, "f_fdisk failed (%d)", res); |
121 | 126 | goto fail; |
122 | 127 | } |
123 | | - ESP_LOGW(TAG, "formatting card"); |
124 | | - res = f_mkfs(drv, FM_ANY, s_card->csd.sector_size, workbuf, workbuf_size); |
| 128 | + size_t alloc_unit_size = esp_vfs_fat_get_allocation_unit_size( |
| 129 | + s_card->csd.sector_size, |
| 130 | + mount_config->allocation_unit_size); |
| 131 | + ESP_LOGW(TAG, "formatting card, allocation unit size=%d", alloc_unit_size); |
| 132 | + res = f_mkfs(drv, FM_ANY, alloc_unit_size, workbuf, workbuf_size); |
125 | 133 | if (res != FR_OK) { |
126 | 134 | err = ESP_FAIL; |
127 | 135 | ESP_LOGD(TAG, "f_mkfs failed (%d)", res); |
|
0 commit comments