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,6 +15,8 @@
*/
#include <stratosphere.hpp>
#include "fsa/fs_mount_utils.hpp"
#include "impl/fs_file_system_service_object_adapter.hpp"
#include "impl/fs_file_system_proxy_service_object.hpp"
namespace ams::fs {
@@ -28,7 +30,7 @@ namespace ams::fs {
virtual Result GenerateCommonMountName(char *dst, size_t dst_size) override {
/* Determine how much space we need. */
const size_t needed_size = strnlen(GetContentStorageMountName(id), MountNameLengthMax) + 2;
const size_t needed_size = util::Strnlen(GetContentStorageMountName(id), MountNameLengthMax) + 2;
AMS_ABORT_UNLESS(dst_size >= needed_size);
/* Generate the name. */
@@ -56,43 +58,55 @@ namespace ams::fs {
}
Result MountContentStorage(const char *name, ContentStorageId id) {
/* Validate the mount name. */
R_TRY(impl::CheckMountNameAllowingReserved(name));
auto mount_impl = [=]() -> Result {
/* Validate the mount name. */
R_TRY(impl::CheckMountNameAllowingReserved(name));
/* It can take some time for the system partition to be ready (if it's on the SD card). */
/* Thus, we will retry up to 10 times, waiting one second each time. */
constexpr size_t MaxRetries = 10;
constexpr auto RetryInterval = TimeSpan::FromSeconds(1);
/* It can take some time for the system partition to be ready (if it's on the SD card). */
/* Thus, we will retry up to 10 times, waiting one second each time. */
constexpr size_t MaxRetries = 10;
constexpr auto RetryInterval = TimeSpan::FromSeconds(1);
/* Mount the content storage, use libnx bindings. */
::FsFileSystem fs;
for (size_t i = 0; i < MaxRetries; i++) {
/* Try to open the filesystem. */
R_TRY_CATCH(fsOpenContentStorageFileSystem(std::addressof(fs), static_cast<::FsContentStorageId>(id))) {
R_CATCH(fs::ResultSystemPartitionNotReady) {
if (i < MaxRetries - 1) {
os::SleepThread(RetryInterval);
continue;
} else {
return fs::ResultSystemPartitionNotReady();
/* Mount the content storage */
auto fsp = impl::GetFileSystemProxyServiceObject();
sf::SharedPointer<fssrv::sf::IFileSystem> fs;
for (size_t i = 0; i < MaxRetries; i++) {
/* Try to open the filesystem. */
R_TRY_CATCH(fsp->OpenContentStorageFileSystem(std::addressof(fs), static_cast<u32>(id))) {
R_CATCH(fs::ResultSystemPartitionNotReady) {
if (i < MaxRetries - 1) {
os::SleepThread(RetryInterval);
continue;
} else {
R_THROW(fs::ResultSystemPartitionNotReady());
}
}
}
} R_END_TRY_CATCH;
} R_END_TRY_CATCH;
/* The filesystem was opened successfully. */
break;
}
/* The filesystem was opened successfully. */
break;
}
/* Allocate a new filesystem wrapper. */
auto fsa = std::make_unique<RemoteFileSystem>(fs);
R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInContentStorageA());
/* Allocate a new filesystem wrapper. */
auto fsa = std::make_unique<impl::FileSystemServiceObjectAdapter>(std::move(fs));
R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInContentStorageA());
/* Allocate a new mountname generator. */
auto generator = std::make_unique<ContentStorageCommonMountNameGenerator>(id);
R_UNLESS(generator != nullptr, fs::ResultAllocationFailureInContentStorageB());
/* Allocate a new mountname generator. */
auto generator = std::make_unique<ContentStorageCommonMountNameGenerator>(id);
R_UNLESS(generator != nullptr, fs::ResultAllocationFailureInContentStorageB());
/* Register. */
return fsa::Register(name, std::move(fsa), std::move(generator));
/* Register. */
R_RETURN(fsa::Register(name, std::move(fsa), std::move(generator)));
};
/* Perform the mount. */
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_SYSTEM_MOUNT(mount_impl(), name, AMS_FS_IMPL_ACCESS_LOG_FORMAT_MOUNT_CONTENT_STORAGE(name, id)));
/* Enable access logging. */
AMS_FS_IMPL_ACCESS_LOG_SYSTEM_FS_ACCESSOR_ENABLE(name);
R_SUCCEED();
}
}