whb: Add SD card mounting support.

This commit is contained in:
James Benton 2017-06-02 11:46:31 +01:00
parent fb325ec894
commit b79a58dec2
2 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,27 @@
#pragma once
#include <wut.h>
/**
* \defgroup whb_sdcard SDCard Access
* \ingroup whb
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
BOOL
WHBMountSdCard();
char *
WHBGetSdCardMountPath();
BOOL
WHBUnmountSdCard();
#ifdef __cplusplus
}
#endif
/** @} */

78
src/libwhb/src/sdcard.c Normal file
View File

@ -0,0 +1,78 @@
#include <coreinit/filesystem.h>
#include <whb/sdcard.h>
#include <whb/log.h>
static BOOL
sMounted = FALSE;
static char
sMountPath[128] = { 0 };
static FSClient
sClient;
BOOL
WHBMountSdCard()
{
FSCmdBlock cmd;
FSMountSource mountSource;
FSStatus result;
if (sMounted) {
return TRUE;
}
FSInit();
result = FSAddClient(&sClient, -1);
if (result != FS_STATUS_OK) {
WHBLogPrintf("%s: FSAddClient error %d", __FUNCTION__, result);
return FALSE;
}
FSInitCmdBlock(&cmd);
result = FSGetMountSource(&sClient, &cmd, FS_MOUNT_SOURCE_SD, &mountSource, -1);
if (result < 0) {
WHBLogPrintf("%s: FSGetMountSource error %d", __FUNCTION__, result);
goto fail;
}
result = FSMount(&sClient, &cmd, &mountSource, sMountPath, sizeof(sMountPath), -1);
if (result < 0) {
WHBLogPrintf("%s: FSMount error %d", __FUNCTION__, result);
goto fail;
}
sMounted = TRUE;
return TRUE;
fail:
FSDelClient(&sClient, -1);
return FALSE;
}
char *
WHBGetSdCardMountPath()
{
return sMountPath;
}
BOOL
WHBUnmountSdCard()
{
FSCmdBlock cmd;
FSStatus result;
if (!sMounted) {
return TRUE;
}
result = FSUnmount(&sClient, &cmd, sMountPath, -1);
if (result < 0) {
WHBLogPrintf("%s: FSUnmount error %d", __FUNCTION__, result);
return FALSE;
}
sMounted = FALSE;
return TRUE;
}