From b725d1fdf7641661161815466a14ed7e8e26ce67 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 15 Nov 2018 23:27:29 -0500 Subject: [PATCH 1/3] file_sys/errors: Extract FS-related error codes to file_sys/errors.h Keeps filesystem-related error codes in one spot. --- src/core/file_sys/errors.h | 9 ++++++++- src/core/hle/result.h | 2 -- src/core/hle/service/filesystem/filesystem.cpp | 6 +++--- src/core/hle/service/filesystem/fsp_srv.cpp | 16 ++++++++-------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/core/file_sys/errors.h b/src/core/file_sys/errors.h index fea0593c7..043fccf42 100644 --- a/src/core/file_sys/errors.h +++ b/src/core/file_sys/errors.h @@ -11,9 +11,11 @@ namespace FileSys { namespace ErrCodes { enum { NotFound = 1, - TitleNotFound = 1002, + EntityNotFound = 1002, SdCardNotFound = 2001, RomFSNotFound = 2520, + InvalidOffset = 6061, + InvalidSize = 6062, }; } @@ -29,4 +31,9 @@ constexpr ResultCode ERROR_DIRECTORY_ALREADY_EXISTS(-1); constexpr ResultCode ERROR_FILE_ALREADY_EXISTS(-1); constexpr ResultCode ERROR_DIRECTORY_NOT_EMPTY(-1); +constexpr ResultCode ERROR_ENTITY_NOT_FOUND{ErrorModule::FS, ErrCodes::EntityNotFound}; +constexpr ResultCode ERROR_SD_CARD_NOT_FOUND{ErrorModule::FS, ErrCodes::SdCardNotFound}; +constexpr ResultCode ERROR_INVALID_OFFSET{ErrorModule::FS, ErrCodes::InvalidOffset}; +constexpr ResultCode ERROR_INVALID_SIZE{ErrorModule::FS, ErrCodes::InvalidSize}; + } // namespace FileSys diff --git a/src/core/hle/result.h b/src/core/hle/result.h index c6b18cfba..bfb77cc31 100644 --- a/src/core/hle/result.h +++ b/src/core/hle/result.h @@ -19,8 +19,6 @@ enum class ErrorDescription : u32 { Success = 0, RemoteProcessDead = 301, - InvalidOffset = 6061, - InvalidLength = 6062, }; /** diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index a92cf7815..554474cf6 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -303,7 +303,7 @@ ResultVal OpenSaveData(FileSys::SaveDataSpaceId space, static_cast(space), save_struct.DebugInfo()); if (save_data_factory == nullptr) { - return ResultCode(ErrorModule::FS, FileSys::ErrCodes::TitleNotFound); + return FileSys::ERROR_ENTITY_NOT_FOUND; } return save_data_factory->Open(space, save_struct); @@ -313,7 +313,7 @@ ResultVal OpenSaveDataSpace(FileSys::SaveDataSpaceId space) LOG_TRACE(Service_FS, "Opening Save Data Space for space_id={:01X}", static_cast(space)); if (save_data_factory == nullptr) { - return ResultCode(ErrorModule::FS, FileSys::ErrCodes::TitleNotFound); + return FileSys::ERROR_ENTITY_NOT_FOUND; } return MakeResult(save_data_factory->GetSaveDataSpaceDirectory(space)); @@ -323,7 +323,7 @@ ResultVal OpenSDMC() { LOG_TRACE(Service_FS, "Opening SDMC"); if (sdmc_factory == nullptr) { - return ResultCode(ErrorModule::FS, FileSys::ErrCodes::SdCardNotFound); + return FileSys::ERROR_SD_CARD_NOT_FOUND; } return sdmc_factory->Open(); diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index b9a1d5105..038dc80b1 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -63,12 +63,12 @@ private: // Error checking if (length < 0) { IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidLength)); + rb.Push(FileSys::ERROR_INVALID_SIZE); return; } if (offset < 0) { IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidOffset)); + rb.Push(FileSys::ERROR_INVALID_OFFSET); return; } @@ -108,12 +108,12 @@ private: // Error checking if (length < 0) { IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidLength)); + rb.Push(FileSys::ERROR_INVALID_SIZE); return; } if (offset < 0) { IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidOffset)); + rb.Push(FileSys::ERROR_INVALID_OFFSET); return; } @@ -139,12 +139,12 @@ private: // Error checking if (length < 0) { IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidLength)); + rb.Push(FileSys::ERROR_INVALID_SIZE); return; } if (offset < 0) { IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidOffset)); + rb.Push(FileSys::ERROR_INVALID_OFFSET); return; } @@ -744,7 +744,7 @@ void FSP_SRV::MountSaveData(Kernel::HLERequestContext& ctx) { if (dir.Failed()) { IPC::ResponseBuilder rb{ctx, 2, 0, 0}; - rb.Push(ResultCode(ErrorModule::FS, FileSys::ErrCodes::TitleNotFound)); + rb.Push(FileSys::ERROR_ENTITY_NOT_FOUND); return; } @@ -836,7 +836,7 @@ void FSP_SRV::OpenRomStorage(Kernel::HLERequestContext& ctx) { static_cast(storage_id), title_id); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultCode(ErrorModule::FS, FileSys::ErrCodes::TitleNotFound)); + rb.Push(FileSys::ERROR_ENTITY_NOT_FOUND); } } // namespace Service::FileSystem From edd5b6f12f4959588dbeb02d43180af3b3f7f226 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 16 Nov 2018 00:08:41 -0500 Subject: [PATCH 2/3] file_sys/errors: Get rid of the ErrCodes namespace There's no real point to keeping the separate enum around, especially given the name of the error code itself is supposed to document what the value actually represents. --- src/core/file_sys/errors.h | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/core/file_sys/errors.h b/src/core/file_sys/errors.h index 043fccf42..40e2b41b0 100644 --- a/src/core/file_sys/errors.h +++ b/src/core/file_sys/errors.h @@ -8,19 +8,6 @@ namespace FileSys { -namespace ErrCodes { -enum { - NotFound = 1, - EntityNotFound = 1002, - SdCardNotFound = 2001, - RomFSNotFound = 2520, - InvalidOffset = 6061, - InvalidSize = 6062, -}; -} - -constexpr ResultCode ERROR_PATH_NOT_FOUND(ErrorModule::FS, ErrCodes::NotFound); - // TODO(bunnei): Replace these with correct errors for Switch OS constexpr ResultCode ERROR_INVALID_PATH(-1); constexpr ResultCode ERROR_UNSUPPORTED_OPEN_FLAGS(-1); @@ -31,9 +18,10 @@ constexpr ResultCode ERROR_DIRECTORY_ALREADY_EXISTS(-1); constexpr ResultCode ERROR_FILE_ALREADY_EXISTS(-1); constexpr ResultCode ERROR_DIRECTORY_NOT_EMPTY(-1); -constexpr ResultCode ERROR_ENTITY_NOT_FOUND{ErrorModule::FS, ErrCodes::EntityNotFound}; -constexpr ResultCode ERROR_SD_CARD_NOT_FOUND{ErrorModule::FS, ErrCodes::SdCardNotFound}; -constexpr ResultCode ERROR_INVALID_OFFSET{ErrorModule::FS, ErrCodes::InvalidOffset}; -constexpr ResultCode ERROR_INVALID_SIZE{ErrorModule::FS, ErrCodes::InvalidSize}; +constexpr ResultCode ERROR_PATH_NOT_FOUND{ErrorModule::FS, 1}; +constexpr ResultCode ERROR_ENTITY_NOT_FOUND{ErrorModule::FS, 1002}; +constexpr ResultCode ERROR_SD_CARD_NOT_FOUND{ErrorModule::FS, 2001}; +constexpr ResultCode ERROR_INVALID_OFFSET{ErrorModule::FS, 6061}; +constexpr ResultCode ERROR_INVALID_SIZE{ErrorModule::FS, 6062}; } // namespace FileSys From 5c9c33e8ad764cea4151a6f262c383876905518d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 16 Nov 2018 00:18:19 -0500 Subject: [PATCH 3/3] file_sys/errors: Remove currently unused filesystem error codes Rather than keeping around unused values, we can just introduce them as needed. --- src/core/file_sys/errors.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/core/file_sys/errors.h b/src/core/file_sys/errors.h index 40e2b41b0..e4a4ee4ab 100644 --- a/src/core/file_sys/errors.h +++ b/src/core/file_sys/errors.h @@ -8,16 +8,6 @@ namespace FileSys { -// TODO(bunnei): Replace these with correct errors for Switch OS -constexpr ResultCode ERROR_INVALID_PATH(-1); -constexpr ResultCode ERROR_UNSUPPORTED_OPEN_FLAGS(-1); -constexpr ResultCode ERROR_INVALID_OPEN_FLAGS(-1); -constexpr ResultCode ERROR_FILE_NOT_FOUND(-1); -constexpr ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY(-1); -constexpr ResultCode ERROR_DIRECTORY_ALREADY_EXISTS(-1); -constexpr ResultCode ERROR_FILE_ALREADY_EXISTS(-1); -constexpr ResultCode ERROR_DIRECTORY_NOT_EMPTY(-1); - constexpr ResultCode ERROR_PATH_NOT_FOUND{ErrorModule::FS, 1}; constexpr ResultCode ERROR_ENTITY_NOT_FOUND{ErrorModule::FS, 1002}; constexpr ResultCode ERROR_SD_CARD_NOT_FOUND{ErrorModule::FS, 2001};