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 *fsCmd;
static bool sdmcInitialised = false;
static bool fsInitialised = false;
/* Initialize SDMC device */
/* Initialize device */
FSStatus fsDevInit(void)
{
FSStatus rc = 0;
if(sdmcInitialised)
if(fsInitialised)
return rc;
fsClient = memalign(0x20, 0x1700);
@ -120,31 +120,37 @@ FSStatus fsDevInit(void)
FSInitCmdBlock(fsCmd);
if(rc >= 0)
{
int dev = AddDevice(&fs_devoptab);
if(dev != -1)
{
setDefaultDevice(dev);
fsInitialised = true;
// 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)
{
sdmcInitialised = true;
int dev = AddDevice(&fs_devoptab);
if(dev != -1)
{
setDefaultDevice(dev);
// 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;
}
@ -187,7 +193,7 @@ FSStatus fsDevExit(void)
{
FSStatus rc = 0;
if(!sdmcInitialised) return rc;
if(!fsInitialised) return rc;
FSDelClient(fsClient, -1);
free(fsClient);