IOS/FS: Make ConvertResult usable from ES

ES makes extensive use of FS and most of the time returns its error
codes directly.
This commit is contained in:
Léo Lam 2018-05-06 17:21:05 +02:00
parent ecb5c97b4d
commit 5dbf6cd0c9
3 changed files with 20 additions and 9 deletions

View File

@ -6,6 +6,7 @@
#include "Common/Assert.h" #include "Common/Assert.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Core/IOS/Device.h"
#include "Core/IOS/FS/HostBackend/FS.h" #include "Core/IOS/FS/HostBackend/FS.h"
namespace IOS::HLE::FS namespace IOS::HLE::FS
@ -17,6 +18,15 @@ std::unique_ptr<FileSystem> MakeFileSystem(Location location)
return std::make_unique<HostFileSystem>(nand_root); return std::make_unique<HostFileSystem>(nand_root);
} }
IOS::HLE::ReturnCode ConvertResult(ResultCode code)
{
if (code == ResultCode::Success)
return IPC_SUCCESS;
// FS error codes start at -100. Since result codes in the enum are listed in the same way
// as the IOS codes, we just need to return -100-code.
return static_cast<ReturnCode>(-(static_cast<s32>(code) + 100));
}
FileHandle::FileHandle(FileSystem* fs, Fd fd) : m_fs{fs}, m_fd{fd} FileHandle::FileHandle(FileSystem* fs, Fd fd) : m_fs{fs}, m_fd{fd}
{ {
} }

View File

@ -14,7 +14,11 @@
class PointerWrap; class PointerWrap;
namespace IOS::HLE::FS namespace IOS::HLE
{
enum ReturnCode : s32;
namespace FS
{ {
enum class ResultCode enum class ResultCode
{ {
@ -218,4 +222,8 @@ enum class Location
std::unique_ptr<FileSystem> MakeFileSystem(Location location = Location::Session); std::unique_ptr<FileSystem> MakeFileSystem(Location location = Location::Session);
} // namespace IOS::HLE::FS /// Convert a FS result code to an IOS error code.
IOS::HLE::ReturnCode ConvertResult(ResultCode code);
} // namespace FS
} // namespace IOS::HLE

View File

@ -23,13 +23,6 @@ namespace Device
{ {
using namespace IOS::HLE::FS; using namespace IOS::HLE::FS;
static s32 ConvertResult(ResultCode code)
{
if (code == ResultCode::Success)
return IPC_SUCCESS;
return -(static_cast<s32>(code) + 100);
}
static IPCCommandResult GetFSReply(s32 return_value, u64 extra_tb_ticks = 0) static IPCCommandResult GetFSReply(s32 return_value, u64 extra_tb_ticks = 0)
{ {
// According to hardware tests, FS takes at least 2700 TB ticks to reply to commands. // According to hardware tests, FS takes at least 2700 TB ticks to reply to commands.