From b0bcdeafac793ba87cec18abaf80d86e233eb159 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Sun, 14 Jun 2020 13:07:42 +0300 Subject: [PATCH] nyx: Find best cluster size automatically --- .../frontend/gui_tools_partition_manager.c | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/nyx/nyx_gui/frontend/gui_tools_partition_manager.c b/nyx/nyx_gui/frontend/gui_tools_partition_manager.c index 9c46241..2cb4935 100644 --- a/nyx/nyx_gui/frontend/gui_tools_partition_manager.c +++ b/nyx/nyx_gui/frontend/gui_tools_partition_manager.c @@ -1331,16 +1331,26 @@ static lv_res_t _create_mbox_start_partitioning(lv_obj_t *btn) disk_set_info(DRIVE_SD, SET_SECTOR_COUNT, &part_rsvd_size); u8 *buf = malloc(0x400000); - u32 cluster_size = part_info.hos_size < 2560 ? 4096 : 65536; - if (f_mkfs("sd:", FM_FAT32, cluster_size, buf, 0x400000)) + u32 cluster_size = 65536; + u32 mkfs_error = f_mkfs("sd:", FM_FAT32, cluster_size, buf, 0x400000); + if (mkfs_error) { - // Retry. - u32 error = f_mkfs("sd:", FM_FAT32, cluster_size, buf, 0x400000); - if (error) + // Retry by halving cluster size. + while (cluster_size > 4096) + { + cluster_size /= 2; + mkfs_error = f_mkfs("sd:", FM_FAT32, cluster_size, buf, 0x400000); + + if (!mkfs_error) + break; + } + + if (mkfs_error) { // Failed to format. s_printf((char *)buf, "#FFDD00 Error:# Failed to format disk (%d)!\n\n" - "Remove the SD card and check that is OK.\nIf not, format it, reinsert it and\npress #FF8000 POWER#!", error); + "Remove the SD card and check that is OK.\nIf not, format it, reinsert it and\npress #FF8000 POWER#!", mkfs_error); + lv_label_set_text(lbl_status, (char *)buf); lv_label_set_text(lbl_paths[0], " "); manual_system_maintenance(true);