Testing Corrections

This commit is contained in:
Zach Hilman
2018-07-15 14:25:01 -04:00
parent 86abdbd9e0
commit ee2fb8ae96
6 changed files with 59 additions and 21 deletions

View File

@@ -28,18 +28,17 @@ __declspec(noinline, noreturn)
}
#define ASSERT(_a_) \
do \
if (!(_a_)) { \
assert_noinline_call([] { LOG_CRITICAL(Debug, "Assertion Failed!"); }); \
} \
while (0)
if (!(_a_)) { \
}
#define ASSERT_MSG(_a_, ...) \
do \
if (!(_a_)) { \
assert_noinline_call([&] { LOG_CRITICAL(Debug, "Assertion Failed!\n" __VA_ARGS__); }); \
} \
while (0)
if (!(_a_)) { \
}
/*do \
if (!(_a_)) { \
assert_noinline_call([&] { LOG_CRITICAL(Debug, "Assertion Failed!\n" __VA_ARGS__); }); \
} \
while (0)*/
#define UNREACHABLE() ASSERT_MSG(false, "Unreachable code!")
#define UNREACHABLE_MSG(...) ASSERT_MSG(false, __VA_ARGS__)

View File

@@ -2,6 +2,8 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma optimize("", off)
#include <memory>
#include "common/common_types.h"
#include "common/logging/log.h"
@@ -22,8 +24,35 @@ SaveDataFactory::SaveDataFactory(std::string save_directory)
: save_directory(std::move(save_directory)) {}
ResultVal<std::unique_ptr<FileSystemBackend>> SaveDataFactory::Open(SaveDataSpaceId space,
SaveStruct meta) {
if ((meta.type == SaveDataType::SystemSaveData || meta.type == SaveDataType::SaveData)) {
if (meta.zero_1 != 0) {
LOG_WARNING(Service_FS,
"Possibly incorrect SaveStruct, type is "
"SystemSaveData||SaveData but offset 0x28 is non-zero ({:016X}).",
meta.zero_1);
}
if (meta.zero_2 != 0) {
LOG_WARNING(Service_FS,
"Possibly incorrect SaveStruct, type is "
"SystemSaveData||SaveData but offset 0x30 is non-zero ({:016X}).",
meta.zero_2);
}
if (meta.zero_3 != 0) {
LOG_WARNING(Service_FS,
"Possibly incorrect SaveStruct, type is "
"SystemSaveData||SaveData but offset 0x38 is non-zero ({:016X}).",
meta.zero_3);
}
}
if (meta.type == SaveDataType::SystemSaveData && meta.title_id != 0) {
LOG_WARNING(Service_FS,
"Possibly incorrect SaveStruct, type is SystemSaveData but title_id is "
"non-zero ({:016X}).",
meta.title_id);
}
std::string save_directory =
GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id);
@@ -35,6 +64,10 @@ ResultVal<std::unique_ptr<FileSystemBackend>> SaveDataFactory::Open(SaveDataSpac
FileUtil::CreateFullPath(save_directory);
}
if (!FileUtil::IsDirectory(save_directory)) {
FileUtil::CreateDir(save_directory);
}
// Return an error if the save data doesn't actually exist.
if (!FileUtil::IsDirectory(save_directory)) {
// TODO(Subv): Find out correct error code.

View File

@@ -24,11 +24,14 @@ enum class SaveDataType : u8 {
};
struct SaveStruct {
u64 title_id;
u64_le title_id;
u128 user_id;
u64 save_id;
u64_le save_id;
SaveDataType type;
INSERT_PADDING_BYTES(31);
INSERT_PADDING_BYTES(7);
u64_le zero_1;
u64_le zero_2;
u64_le zero_3;
};
static_assert(sizeof(SaveStruct) == 0x40, "SaveStruct has incorrect size.");

View File

@@ -624,10 +624,10 @@ void IApplicationFunctions::EnsureSaveData(Kernel::HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 4};
FileSys::Path unused;
auto savedata = FileSystem::OpenSaveData(space, save_struct);
if (savedata.Failed()) {
// auto savedata = FileSystem::OpenSaveData(space, save_struct);
if (true) {
// Create the save data and return an error indicating that the operation was performed.
FileSystem::FormatSaveData(space, save_struct);
// FileSystem::FormatSaveData(space, save_struct);
// TODO(Subv): Find out the correct error code for this.
rb.Push(ResultCode(ErrorModule::FS, 40));
} else {

View File

@@ -68,7 +68,7 @@ ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenSaveData(
ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenSDMC() {
LOG_TRACE(Service_FS, "Opening SDMC");
if (romfs == nullptr) {
if (sdmc == nullptr) {
// TODO(bunnei): Find a better error code for this
return ResultCode(-1);
}

View File

@@ -2,6 +2,8 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma optimize("", off)
#include <cinttypes>
#include "common/logging/log.h"
#include "common/string_util.h"
@@ -508,7 +510,7 @@ void FSP_SRV::MountSdCard(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_FS, "called");
FileSys::Path unused;
auto filesystem = OpenSDMC().Unwrap();
auto filesystem = IFileSystem(OpenSDMC().Unwrap());
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(RESULT_SUCCESS);
@@ -521,6 +523,7 @@ void FSP_SRV::CreateSaveData(Kernel::HLERequestContext& ctx) {
auto save_struct = rp.PopRaw<std::array<u8, 0x40>>();
auto save_create_struct = rp.PopRaw<std::array<u8, 0x40>>();
u128 uid = rp.PopRaw<u128>();
FileSys::SaveStruct structs = *reinterpret_cast<FileSys::SaveStruct*>(save_struct.data());
LOG_WARNING(Service_FS, "(STUBBED) called uid = {:016X}{:016X}", uid[1], uid[0]);
@@ -533,8 +536,8 @@ void FSP_SRV::MountSaveData(Kernel::HLERequestContext& ctx) {
auto space_id = rp.PopRaw<FileSys::SaveDataSpaceId>();
auto save_struct = rp.PopRaw<FileSys::SaveStruct>();
auto filesystem = OpenSaveData(space_id, save_struct);
save_struct.type = FileSys::SaveDataType::SaveData;
auto filesystem = OpenSaveData(static_cast<FileSys::SaveDataSpaceId>(space_id), save_struct);
if (filesystem.Failed()) {
IPC::ResponseBuilder rb{ctx, 2, 0, 0};