Deinit client and cmd block if device cannot be added, allow device to be added in environments without SD access

This commit is contained in:
shinyquagsire23 2016-07-31 13:54:43 -07:00
parent 0aa7a3e021
commit 6f015ad41e

View File

@ -93,14 +93,14 @@ fs_devoptab =
void *fsClient; void *fsClient;
void *fsCmd; void *fsCmd;
static bool sdmcInitialised = false; static bool fsInitialised = false;
/* Initialize SDMC device */ /* Initialize device */
FSStatus fsDevInit(void) FSStatus fsDevInit(void)
{ {
FSStatus rc = 0; FSStatus rc = 0;
if(sdmcInitialised) if(fsInitialised)
return rc; return rc;
fsClient = memalign(0x20, 0x1700); fsClient = memalign(0x20, 0x1700);
@ -119,33 +119,39 @@ FSStatus fsDevInit(void)
} }
FSInitCmdBlock(fsCmd); FSInitCmdBlock(fsCmd);
// Mount the SD card
rc = FSGetMountSource(fsClient, fsCmd, FS_MOUNT_SOURCE_SD, (void*)mountSource, -1);
if(rc < 0)
return rc;
rc = FSMount(fsClient, fsCmd, (void*)mountSource, mountPath, 0x80, -1);
if(rc >= 0) if(rc >= 0)
{ {
sdmcInitialised = true;
int dev = AddDevice(&fs_devoptab); int dev = AddDevice(&fs_devoptab);
if(dev != -1) if(dev != -1)
{ {
setDefaultDevice(dev); setDefaultDevice(dev);
fsInitialised = true;
// chdir to SD root for general use // Mount the SD card
strcpy(workDir, "fs:"); rc = FSGetMountSource(fsClient, fsCmd, FS_MOUNT_SOURCE_SD, (void*)mountSource, -1);
strcat(workDir, mountPath); if(rc < 0)
chdir(workDir); return rc;
rc = FSMount(fsClient, fsCmd, (void*)mountSource, mountPath, 0x80, -1);
if(rc >= 0)
{
// chdir to SD root for general use
strcpy(workDir, "fs:");
strcat(workDir, mountPath);
chdir(workDir);
}
}
else
{
FSDelClient(fsClient, -1);
free(fsClient);
free(fsCmd);
return dev;
} }
} }
return rc; return rc;
} }
@ -187,7 +193,7 @@ FSStatus fsDevExit(void)
{ {
FSStatus rc = 0; FSStatus rc = 0;
if(!sdmcInitialised) return rc; if(!fsInitialised) return rc;
FSDelClient(fsClient, -1); FSDelClient(fsClient, -1);
free(fsClient); free(fsClient);