Skip to content

Commit fd3b5b7

Browse files
authored
coreinit: Fix FSGetMountSource and FSAppendFile implementation (#863)
Fixes SD access in SSBU
1 parent 950e956 commit fd3b5b7

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

src/Cafe/IOSU/fsa/iosu_fsa.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,14 +611,13 @@ namespace iosu
611611

612612
FSA_RESULT FSAProcessCmd_appendFile(FSAClient* client, FSAShimBuffer* shimBuffer)
613613
{
614-
uint32 fileHandle = shimBuffer->request.cmdAppendFile.fileHandle;
615-
FSCVirtualFile* fscFile = sFileHandleTable.GetByHandle(fileHandle);
614+
FSCVirtualFile* fscFile = sFileHandleTable.GetByHandle(shimBuffer->request.cmdAppendFile.fileHandle);
616615
if (!fscFile)
617616
return FSA_RESULT::INVALID_FILE_HANDLE;
618617
#ifdef CEMU_DEBUG_ASSERT
619618
cemuLog_log(LogType::Force, "FSAProcessCmd_appendFile(): size 0x{:08x} count 0x{:08x} (todo)\n", shimBuffer->request.cmdAppendFile.size, shimBuffer->request.cmdAppendFile.count);
620619
#endif
621-
return (FSA_RESULT)(shimBuffer->request.cmdAppendFile.size * shimBuffer->request.cmdAppendFile.count);
620+
return (FSA_RESULT)(shimBuffer->request.cmdAppendFile.count.value());
622621
}
623622

624623
FSA_RESULT FSAProcessCmd_truncateFile(FSAClient* client, FSAShimBuffer* shimBuffer)

src/Cafe/OS/libs/coreinit/coreinit_FS.cpp

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,32 +74,39 @@ namespace coreinit
7474

7575
FS_RESULT FSGetMountSourceNext(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, MOUNT_TYPE mountSourceType, FS_MOUNT_SOURCE* mountSourceInfo, FS_ERROR_MASK errMask)
7676
{
77-
// hacky
78-
static FS_MOUNT_SOURCE* s_last_source = nullptr;
79-
if (s_last_source != mountSourceInfo)
77+
if (mountSourceType == MOUNT_TYPE::SD)
8078
{
81-
s_last_source = mountSourceInfo;
82-
fsCmdBlock->data.mount_it = 0;
79+
// This function is supposed to be called after an initial FSGetMountSource call => always returns FS_RESULT::END_ITERATION because we only have one SD Card
80+
// It *might* causes issues if this function is called for getting the first MountSource (instead of "FSGetMountSource")
81+
cemu_assert_suspicious();
82+
return FS_RESULT::END_ITERATION;
83+
}
84+
else
85+
{
86+
cemu_assert_unimplemented();
8387
}
8488

85-
fsCmdBlock->data.mount_it++;
89+
return FS_RESULT::END_ITERATION;
90+
}
8691

87-
// SD
88-
if (mountSourceType == MOUNT_TYPE::SD && fsCmdBlock->data.mount_it == 1)
92+
FS_RESULT FSGetMountSource(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, MOUNT_TYPE mountSourceType, FS_MOUNT_SOURCE* mountSourceInfo, FS_ERROR_MASK errMask)
93+
{
94+
// This implementation is simplified A LOT compared to what the Wii U is actually doing. On Cemu we expect to only have one mountable source (SD Card) anyway,
95+
// so we can just hard code it. Other mount types are not (yet) supported.
96+
if (mountSourceType == MOUNT_TYPE::SD)
8997
{
9098
mountSourceInfo->sourceType = 0;
9199
strcpy(mountSourceInfo->path, "/sd");
92100
return FS_RESULT::SUCCESS;
93101
}
102+
else
103+
{
104+
cemu_assert_unimplemented();
105+
}
94106

95107
return FS_RESULT::END_ITERATION;
96108
}
97109

98-
FS_RESULT FSGetMountSource(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, MOUNT_TYPE mountSourceType, FS_MOUNT_SOURCE* mountSourceInfo, FS_ERROR_MASK errMask)
99-
{
100-
return FSGetMountSourceNext(fsClient, fsCmdBlock, mountSourceType, mountSourceInfo, errMask);
101-
}
102-
103110
bool _sdCard01Mounted = false;
104111
bool _mlc01Mounted = false;
105112

@@ -1399,7 +1406,7 @@ namespace coreinit
13991406
return __FSProcessAsyncResult(fsClient, fsCmdBlock, fsAsyncRet, errorMask);
14001407
}
14011408

1402-
FSA_RESULT __FSPrepareCmd_AppendFile(iosu::fsa::FSAShimBuffer* fsaShimBuffer, IOSDevHandle fsaHandle, uint32 fileHandle, uint32 size, uint32 count, uint32 uknParam)
1409+
FSA_RESULT __FSPrepareCmd_AppendFile(iosu::fsa::FSAShimBuffer* fsaShimBuffer, IOSDevHandle fsaHandle, uint32 size, uint32 count, uint32 fileHandle, uint32 uknParam)
14031410
{
14041411
if (fsaShimBuffer == nullptr)
14051412
return FSA_RESULT::INVALID_BUFFER;
@@ -1408,29 +1415,29 @@ namespace coreinit
14081415
fsaShimBuffer->operationType = (uint32)FSA_CMD_OPERATION_TYPE::APPENDFILE;
14091416

14101417
fsaShimBuffer->request.cmdAppendFile.fileHandle = fileHandle;
1411-
fsaShimBuffer->request.cmdAppendFile.count = size;
1412-
fsaShimBuffer->request.cmdAppendFile.size = count;
1418+
fsaShimBuffer->request.cmdAppendFile.count = count;
1419+
fsaShimBuffer->request.cmdAppendFile.size = size;
14131420
fsaShimBuffer->request.cmdAppendFile.uknParam = uknParam;
14141421

14151422
return FSA_RESULT::OK;
14161423
}
14171424

1418-
sint32 FSAppendFileAsync(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, uint32 fileHandle, uint32 size, uint32 count, uint32 errorMask, FSAsyncParamsNew_t* fsAsyncParams)
1425+
sint32 FSAppendFileAsync(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, uint32 size, uint32 count, uint32 fileHandle, uint32 errorMask, FSAsyncParamsNew_t* fsAsyncParams)
14191426
{
14201427
_FSCmdIntro();
1421-
FSA_RESULT prepareResult = __FSPrepareCmd_AppendFile(&fsCmdBlockBody->fsaShimBuffer, fsClientBody->iosuFSAHandle, fileHandle, size, count, 0);
1428+
FSA_RESULT prepareResult = __FSPrepareCmd_AppendFile(&fsCmdBlockBody->fsaShimBuffer, fsClientBody->iosuFSAHandle, size, count, fileHandle, 0);
14221429
if (prepareResult != FSA_RESULT::OK)
14231430
return (FSStatus)_FSAStatusToFSStatus(prepareResult);
14241431

14251432
__FSQueueCmd(&fsClientBody->fsCmdQueue, fsCmdBlockBody, RPLLoader_MakePPCCallable(export___FSQueueDefaultFinishFunc));
14261433
return (FSStatus)FS_RESULT::SUCCESS;
14271434
}
14281435

1429-
sint32 FSAppendFile(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, uint32 fileHandle, uint32 size, uint32 count, uint32 errorMask)
1436+
sint32 FSAppendFile(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, uint32 size, uint32 count, uint32 fileHandle, uint32 errorMask)
14301437
{
14311438
StackAllocator<FSAsyncParamsNew_t> asyncParams;
14321439
__FSAsyncToSyncInit(fsClient, fsCmdBlock, asyncParams);
1433-
sint32 fsAsyncRet = FSAppendFileAsync(fsClient, fsCmdBlock, fileHandle, size, count, errorMask, asyncParams.GetPointer());
1440+
sint32 fsAsyncRet = FSAppendFileAsync(fsClient, fsCmdBlock, size, count, fileHandle, errorMask, asyncParams.GetPointer());
14341441
return __FSProcessAsyncResult(fsClient, fsCmdBlock, fsAsyncRet, errorMask);
14351442
}
14361443

0 commit comments

Comments
 (0)