ams: support building unit test programs on windows/linux/macos

This commit is contained in:
Michael Scire 2022-03-06 12:08:20 -08:00 committed by SciresM
parent 9a38be201a
commit 64a97576d0
756 changed files with 33359 additions and 9372 deletions

View file

@ -15,33 +15,11 @@
*/
#include <stratosphere.hpp>
#include "fsa/fs_mount_utils.hpp"
#include "impl/fs_file_system_proxy_service_object.hpp"
#include "impl/fs_file_system_service_object_adapter.hpp"
namespace ams::fs {
namespace {
Result MountSystemSaveDataImpl(const char *name, SaveDataSpaceId space_id, SystemSaveDataId id, UserId user_id, SaveDataType type) {
/* Validate the mount name. */
R_TRY(impl::CheckMountName(name));
/* Create the attribute. */
const auto attribute = SaveDataAttribute::Make(ncm::InvalidProgramId, type, user_id, id);
static_assert(sizeof(attribute) == sizeof(::FsSaveDataAttribute));
/* Open the filesystem, use libnx bindings. */
::FsFileSystem fs;
R_TRY(fsOpenSaveDataFileSystemBySystemSaveDataId(std::addressof(fs), static_cast<::FsSaveDataSpaceId>(space_id), reinterpret_cast<const ::FsSaveDataAttribute *>(std::addressof(attribute))));
/* Allocate a new filesystem wrapper. */
auto fsa = std::make_unique<RemoteFileSystem>(fs);
R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInSystemSaveDataA());
/* Register. */
return fsa::Register(name, std::move(fsa));
}
}
Result MountSystemSaveData(const char *name, SystemSaveDataId id) {
return MountSystemSaveData(name, id, InvalidUserId);
}
@ -55,7 +33,29 @@ namespace ams::fs {
}
Result MountSystemSaveData(const char *name, SaveDataSpaceId space_id, SystemSaveDataId id, UserId user_id) {
return MountSystemSaveDataImpl(name, space_id, id, user_id, SaveDataType::System);
auto mount_impl = [=]() -> Result {
/* Validate the mount name. */
R_TRY(impl::CheckMountName(name));
/* Create the attribute. */
const auto attribute = SaveDataAttribute::Make(ncm::InvalidProgramId, SaveDataType::System, user_id, id);
/* Open the filesystem. */
auto fsp = impl::GetFileSystemProxyServiceObject();
sf::SharedPointer<fssrv::sf::IFileSystem> fs;
R_TRY(fsp->OpenSaveDataFileSystemBySystemSaveDataId(std::addressof(fs), static_cast<u8>(space_id), attribute));
/* Allocate a new filesystem wrapper. */
auto fsa = std::make_unique<impl::FileSystemServiceObjectAdapter>(std::move(fs));
R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInSystemSaveDataA());
/* Register. */
return fsa::Register(name, std::move(fsa));
};
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_SYSTEM_MOUNT(mount_impl(), name, AMS_FS_IMPL_ACCESS_LOG_FORMAT_MOUNT_SYSTEM_SAVE_DATA(name, space_id, id, user_id)));
AMS_FS_IMPL_ACCESS_LOG_SYSTEM_FS_ACCESSOR_ENABLE(name);
R_SUCCEED();
}
}