Allow cluster size selection on SD format

This commit is contained in:
d0k3 2016-09-07 00:18:49 +02:00
parent d00eabe9e4
commit 26c677b785
3 changed files with 15 additions and 8 deletions

View File

@ -108,7 +108,7 @@ uint64_t GetSDCardSize() {
return (u64) getMMCDevice(1)->total_size * 512;
}
bool FormatSDCard(u64 hidden_mb) {
bool FormatSDCard(u64 hidden_mb, u32 cluster_size) {
u8 mbr[0x200] = { 0 };
u8 mbrdata[0x42] = {
0x80, 0x01, 0x01, 0x00, 0x0C, 0xFE, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -152,9 +152,8 @@ bool FormatSDCard(u64 hidden_mb) {
}
// format the SD card
// cluster size: auto (<= 4GB) / 32KiB (<= 8GB) / 64 KiB (> 8GB)
f_mount(fs, "0:", 1);
UINT c_size = (sd_size < 0x800000) ? 0 : (sd_size < 0x1000000) ? 32768 : 65536;
UINT c_size = cluster_size;
bool ret = (f_mkfs("0:", FM_FAT32, c_size, MAIN_BUFFER, MAIN_BUFFER_SIZE) == FR_OK) && (f_setlabel("0:GM9SD") == FR_OK);
f_mount(NULL, "0:", 1);

View File

@ -50,7 +50,7 @@ void SetFSSearch(const char* pattern, const char* path);
uint64_t GetSDCardSize();
/** Format the SD card **/
bool FormatSDCard(u64 hidden_mb);
bool FormatSDCard(u64 hidden_mb, u32 cluster_size);
/** Check if writing to this path is allowed **/
bool CheckWritePermissions(const char* path);

View File

@ -7,7 +7,7 @@
#include "virtual.h"
#include "image.h"
#define VERSION "0.6.6"
#define VERSION "0.6.7"
#define N_PANES 2
#define IMG_DRV "789I"
@ -185,9 +185,13 @@ void DrawDirContents(DirStruct* contents, u32 cursor, u32* scroll) {
u32 SdFormatMenu(void) {
const u32 emunand_size_table[6] = { 0x0, 0x0, 0x3AF, 0x4D8, 0x3FF, 0x7FF };
const char* optionstr[6] = { "No EmuNAND", "O3DS NAND size", "N3DS NAND size", "1GB (legacy size)", "2GB (legacy size)", "User input..." };
const u32 cluster_size_table[5] = { 0x0, 0x0, 0x4000, 0x8000, 0x10000 };
const char* option_emunand_size[6] = { "No EmuNAND", "O3DS NAND size", "N3DS NAND size", "1GB (legacy size)", "2GB (legacy size)", "User input..." };
const char* option_cluster_size[4] = { "Auto", "16KB Clusters", "32KB Clusters", "64KB Clusters" };
u32 cluster_size = 0;
u64 sdcard_size_mb = 0;
u64 emunand_size_mb = (u64) -1;
u32 user_select;
// check actual SD card size
sdcard_size_mb = GetSDCardSize() / 0x100000;
@ -196,7 +200,7 @@ u32 SdFormatMenu(void) {
return 1;
}
u32 user_select = ShowSelectPrompt(6, optionstr, "Format SD card (%lluMB)?\nChoose EmuNAND size:", sdcard_size_mb);
user_select = ShowSelectPrompt(6, option_emunand_size, "Format SD card (%lluMB)?\nChoose EmuNAND size:", sdcard_size_mb);
if (user_select && (user_select < 6)) {
emunand_size_mb = emunand_size_table[user_select];
} else if (user_select == 6) do {
@ -205,7 +209,11 @@ u32 SdFormatMenu(void) {
} while (emunand_size_mb > sdcard_size_mb);
if (emunand_size_mb == (u64) -1) return 1;
if (!FormatSDCard(emunand_size_mb)) {
user_select = ShowSelectPrompt(4, option_cluster_size, "Format SD card (%lluMB)?\nChoose cluster size:", sdcard_size_mb);
if (!user_select) return 1;
else cluster_size = cluster_size_table[user_select];
if (!FormatSDCard(emunand_size_mb, cluster_size)) {
ShowPrompt(false, "Format SD: failed!");
return 1;
}