From 5dbf6cd0c98be721dbabe204a02ae0a481b44e59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 6 May 2018 17:21:05 +0200 Subject: [PATCH] IOS/FS: Make ConvertResult usable from ES ES makes extensive use of FS and most of the time returns its error codes directly. --- Source/Core/Core/IOS/FS/FileSystem.cpp | 10 ++++++++++ Source/Core/Core/IOS/FS/FileSystem.h | 12 ++++++++++-- Source/Core/Core/IOS/FS/FileSystemProxy.cpp | 7 ------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/IOS/FS/FileSystem.cpp b/Source/Core/Core/IOS/FS/FileSystem.cpp index c6db165002..e62c6bcc6b 100644 --- a/Source/Core/Core/IOS/FS/FileSystem.cpp +++ b/Source/Core/Core/IOS/FS/FileSystem.cpp @@ -6,6 +6,7 @@ #include "Common/Assert.h" #include "Common/FileUtil.h" +#include "Core/IOS/Device.h" #include "Core/IOS/FS/HostBackend/FS.h" namespace IOS::HLE::FS @@ -17,6 +18,15 @@ std::unique_ptr MakeFileSystem(Location location) return std::make_unique(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(-(static_cast(code) + 100)); +} + FileHandle::FileHandle(FileSystem* fs, Fd fd) : m_fs{fs}, m_fd{fd} { } diff --git a/Source/Core/Core/IOS/FS/FileSystem.h b/Source/Core/Core/IOS/FS/FileSystem.h index 42edb14cdf..a53cd36ac9 100644 --- a/Source/Core/Core/IOS/FS/FileSystem.h +++ b/Source/Core/Core/IOS/FS/FileSystem.h @@ -14,7 +14,11 @@ class PointerWrap; -namespace IOS::HLE::FS +namespace IOS::HLE +{ +enum ReturnCode : s32; + +namespace FS { enum class ResultCode { @@ -218,4 +222,8 @@ enum class Location std::unique_ptr 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 diff --git a/Source/Core/Core/IOS/FS/FileSystemProxy.cpp b/Source/Core/Core/IOS/FS/FileSystemProxy.cpp index 587577d497..2fbcee6794 100644 --- a/Source/Core/Core/IOS/FS/FileSystemProxy.cpp +++ b/Source/Core/Core/IOS/FS/FileSystemProxy.cpp @@ -23,13 +23,6 @@ namespace Device { using namespace IOS::HLE::FS; -static s32 ConvertResult(ResultCode code) -{ - if (code == ResultCode::Success) - return IPC_SUCCESS; - return -(static_cast(code) + 100); -} - 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.