Improved remounting of images

This commit is contained in:
d0k3 2016-04-05 15:20:48 +02:00
parent 5a9110b3d4
commit e15259f9ba
3 changed files with 31 additions and 17 deletions

View File

@ -28,7 +28,7 @@ bool InitSDCardFS() {
return fs_mounted[0]; return fs_mounted[0];
} }
bool InitNandFS() { bool InitExtFS() {
if (!fs_mounted[0]) if (!fs_mounted[0])
return false; return false;
for (u32 i = 1; i < NORM_FS; i++) { for (u32 i = 1; i < NORM_FS; i++) {
@ -40,7 +40,7 @@ bool InitNandFS() {
return true; return true;
} }
void DeinitNandFS() { void DeinitExtFS() {
for (u32 i = NORM_FS; i > 0; i--) { for (u32 i = NORM_FS; i > 0; i--) {
if (fs_mounted[i]) { if (fs_mounted[i]) {
char fsname[8]; char fsname[8];
@ -67,6 +67,11 @@ int PathToNumFS(const char* path) {
return fsnum; return fsnum;
} }
bool IsMountedFS(const char* path) {
int fsnum = PathToNumFS(path);
return ((fsnum >= 0) && (fsnum < NORM_FS)) ? fs_mounted[fsnum] : false;
}
bool CheckWritePermissions(const char* path) { bool CheckWritePermissions(const char* path) {
int pdrv = PathToNumFS(path); int pdrv = PathToNumFS(path);
if (pdrv < 0) { if (pdrv < 0) {
@ -198,7 +203,7 @@ bool PathCopyVirtual(const char* destdir, const char* orig) {
if ((dvfile.keyslot == ovfile.keyslot) && (dvfile.offset == ovfile.offset)) // this improves copy times if ((dvfile.keyslot == ovfile.keyslot) && (dvfile.offset == ovfile.offset)) // this improves copy times
dvfile.keyslot = ovfile.keyslot = 0xFF; dvfile.keyslot = ovfile.keyslot = 0xFF;
DeinitNandFS(); DeinitExtFS();
if (!ShowProgress(0, 0, orig)) ret = false; if (!ShowProgress(0, 0, orig)) ret = false;
for (size_t pos = 0; (pos < osize) && ret; pos += MAIN_BUFFER_SIZE) { for (size_t pos = 0; (pos < osize) && ret; pos += MAIN_BUFFER_SIZE) {
UINT read_bytes = min(MAIN_BUFFER_SIZE, osize - pos); UINT read_bytes = min(MAIN_BUFFER_SIZE, osize - pos);
@ -210,7 +215,7 @@ bool PathCopyVirtual(const char* destdir, const char* orig) {
ret = false; ret = false;
} }
ShowProgress(1, 1, orig); ShowProgress(1, 1, orig);
InitNandFS(); InitExtFS();
} else if (IsVirtualPath(dest)) { // SD card to virtual (other FAT not allowed!) } else if (IsVirtualPath(dest)) { // SD card to virtual (other FAT not allowed!)
VirtualFile dvfile; VirtualFile dvfile;
FIL ofile; FIL ofile;
@ -250,7 +255,7 @@ bool PathCopyVirtual(const char* destdir, const char* orig) {
} }
} }
DeinitNandFS(); DeinitExtFS();
if (!ShowProgress(0, 0, orig)) ret = false; if (!ShowProgress(0, 0, orig)) ret = false;
for (size_t pos = 0; (pos < osize) && ret; pos += MAIN_BUFFER_SIZE) { for (size_t pos = 0; (pos < osize) && ret; pos += MAIN_BUFFER_SIZE) {
UINT bytes_read = 0; UINT bytes_read = 0;
@ -263,8 +268,8 @@ bool PathCopyVirtual(const char* destdir, const char* orig) {
} }
ShowProgress(1, 1, orig); ShowProgress(1, 1, orig);
f_close(&ofile); f_close(&ofile);
InitNandFS(); InitExtFS();
} else if (IsVirtualPath(orig)) { // virtual to SD card (other FAT not allowed) } else if (IsVirtualPath(orig)) { // virtual to any file system
VirtualFile ovfile; VirtualFile ovfile;
FIL dfile; FIL dfile;
u32 osize; u32 osize;

View File

@ -25,8 +25,8 @@ typedef struct {
} DirStruct; } DirStruct;
bool InitSDCardFS(); bool InitSDCardFS();
bool InitNandFS(); bool InitExtFS();
void DeinitNandFS(); void DeinitExtFS();
void DeinitSDCardFS(); void DeinitSDCardFS();
/** Check if writing to this path is allowed **/ /** Check if writing to this path is allowed **/
@ -74,5 +74,8 @@ uint64_t GetPartitionOffsetSector(const char* path);
/** Helper function to get drive number from path */ /** Helper function to get drive number from path */
int PathToNumFS(const char* path); int PathToNumFS(const char* path);
/** Check if drive is mounted */
bool IsMountedFS(const char* path);
/** Helper function for copying DirEntry structs */ /** Helper function for copying DirEntry structs */
void DirEntryCpy(DirEntry* dest, const DirEntry* orig); void DirEntryCpy(DirEntry* dest, const DirEntry* orig);

View File

@ -150,11 +150,11 @@ u32 GodMode() {
} }
InitEmuNandBase(); InitEmuNandBase();
InitNandCrypto(); InitNandCrypto();
InitNandFS(); InitExtFS();
if ((GetUnitPlatform() == PLATFORM_N3DS) && !CheckSlot0x05Crypto()) { if ((GetUnitPlatform() == PLATFORM_N3DS) && !CheckSlot0x05Crypto()) {
if (!ShowPrompt(true, "Warning: slot0x05 crypto fail\nslot0x05keyY.bin is either corrupt\nor does not exist. Continue?")) { if (!ShowPrompt(true, "Warning: slot0x05 crypto fail\nslot0x05keyY.bin is either corrupt\nor does not exist. Continue?")) {
DeinitNandFS(); DeinitExtFS();
DeinitSDCardFS(); DeinitSDCardFS();
return exit_mode; return exit_mode;
} }
@ -189,15 +189,21 @@ u32 GodMode() {
(PathToNumFS(current_dir->entry[cursor].path) == 0)) { // try to mount image (PathToNumFS(current_dir->entry[cursor].path) == 0)) { // try to mount image
u32 file_type = IdentifyImage(current_dir->entry[cursor].path); u32 file_type = IdentifyImage(current_dir->entry[cursor].path);
if (file_type && ShowPrompt(true, "This looks like a %s image\nTry to mount it?", (file_type == IMG_NAND) ? "NAND" : "FAT")) { if (file_type && ShowPrompt(true, "This looks like a %s image\nTry to mount it?", (file_type == IMG_NAND) ? "NAND" : "FAT")) {
if (!MountImage(current_dir->entry[cursor].path)) { DeinitExtFS();
u32 mount_state = MountImage(current_dir->entry[cursor].path);
InitExtFS();
if (!mount_state || !(IsMountedFS("7:")|IsMountedFS("8:")|IsMountedFS("9:"))) {
ShowPrompt(false, "Mounting image: failed"); ShowPrompt(false, "Mounting image: failed");
DeinitExtFS();
MountImage(NULL);
InitExtFS();
} else { } else {
DeinitNandFS();
InitNandFS();
*current_path = '\0'; *current_path = '\0';
GetDirContents(current_dir, current_path); GetDirContents(current_dir, current_path);
cursor = 0; cursor = 0;
} }
if (clipboard->n_entries && (strcspn(clipboard->entry[0].path, "789I") == 0))
clipboard->n_entries = 0; // remove invalid clipboard stuff
} }
} else if ((pad_state & BUTTON_B) && *current_path) { // one level down } else if ((pad_state & BUTTON_B) && *current_path) { // one level down
char old_path[256]; char old_path[256];
@ -212,7 +218,7 @@ u32 GodMode() {
scroll = 0; scroll = 0;
} }
} else if ((pad_state & BUTTON_B) && (pad_state & BUTTON_R1)) { // unmount SD card } else if ((pad_state & BUTTON_B) && (pad_state & BUTTON_R1)) { // unmount SD card
DeinitNandFS(); DeinitExtFS();
DeinitSDCardFS(); DeinitSDCardFS();
clipboard->n_entries = 0; clipboard->n_entries = 0;
ShowPrompt(false, "SD card unmounted, you can eject now.\nPut it back in before you press <A>."); ShowPrompt(false, "SD card unmounted, you can eject now.\nPut it back in before you press <A>.");
@ -221,7 +227,7 @@ u32 GodMode() {
return exit_mode; return exit_mode;
} }
InitEmuNandBase(); InitEmuNandBase();
InitNandFS(); InitExtFS();
GetDirContents(current_dir, current_path); GetDirContents(current_dir, current_path);
if (cursor >= current_dir->n_entries) cursor = 0; if (cursor >= current_dir->n_entries) cursor = 0;
} else if ((pad_state & BUTTON_DOWN) && (cursor + 1 < current_dir->n_entries)) { // cursor up } else if ((pad_state & BUTTON_DOWN) && (cursor + 1 < current_dir->n_entries)) { // cursor up
@ -361,7 +367,7 @@ u32 GodMode() {
} }
} }
DeinitNandFS(); DeinitExtFS();
DeinitSDCardFS(); DeinitSDCardFS();
return exit_mode; return exit_mode;