ams.mitm: use fs bindings instead of stdio

This commit is contained in:
Michael Scire 2020-03-06 08:21:25 -08:00
parent c4bf3adb4f
commit 150efae91e
6 changed files with 25 additions and 25 deletions

View file

@ -32,7 +32,7 @@
#include "fs/fs_path_tool.hpp"
#include "fs/fs_path_utils.hpp"
#include "fs/fs_romfs_filesystem.hpp"
#include "fs/fs_data.hpp"
#include "fs/impl/fs_data.hpp"
#include "fs/fs_system_data.hpp"
#include "fs/fs_content_storage.hpp"
#include "fs/fs_game_card.hpp"

View file

@ -18,9 +18,9 @@
namespace ams::fs {
Result QueryMountSystemDataCacheSize(size_t *out, ncm::ProgramId data_id);
Result QueryMountSystemDataCacheSize(size_t *out, ncm::DataId data_id);
Result MountSystemData(const char *name, ncm::ProgramId data_id);
Result MountSystemData(const char *name, ncm::ProgramId data_id, void *cache_buffer, size_t cache_size);
Result MountSystemData(const char *name, ncm::DataId data_id);
Result MountSystemData(const char *name, ncm::DataId data_id, void *cache_buffer, size_t cache_size);
}

View file

@ -14,14 +14,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "fs_common.hpp"
#include <stratosphere/fs/fs_common.hpp>
namespace ams::fs::impl {
Result QueryMountDataCacheSize(size_t *out, ncm::ProgramId data_id, ncm::StorageId storage_id);
Result QueryMountDataCacheSize(size_t *out, ncm::DataId data_id, ncm::StorageId storage_id);
Result MountData(const char *name, ncm::ProgramId data_id, ncm::StorageId storage_id);
Result MountData(const char *name, ncm::ProgramId data_id, ncm::StorageId storage_id, void *cache_buffer, size_t cache_size);
Result MountData(const char *name, ncm::ProgramId data_id, ncm::StorageId storage_id, void *cache_buffer, size_t cache_size, bool use_data_cache, bool use_path_cache);
Result MountData(const char *name, ncm::DataId data_id, ncm::StorageId storage_id);
Result MountData(const char *name, ncm::DataId data_id, ncm::StorageId storage_id, void *cache_buffer, size_t cache_size);
Result MountData(const char *name, ncm::DataId data_id, ncm::StorageId storage_id, void *cache_buffer, size_t cache_size, bool use_data_cache, bool use_path_cache);
}

View file

@ -20,10 +20,10 @@ namespace ams::fs::impl {
namespace {
Result OpenDataStorageByDataId(std::unique_ptr<ams::fs::IStorage> *out, ncm::ProgramId data_id, ncm::StorageId storage_id) {
Result OpenDataStorageByDataId(std::unique_ptr<ams::fs::IStorage> *out, ncm::DataId data_id, ncm::StorageId storage_id) {
/* Open storage using libnx bindings. */
::FsStorage s;
R_TRY_CATCH(fsOpenDataStorageByDataId(std::addressof(s), static_cast<u64>(data_id), static_cast<::NcmStorageId>(storage_id))) {
R_TRY_CATCH(fsOpenDataStorageByDataId(std::addressof(s), data_id.value, static_cast<::NcmStorageId>(storage_id))) {
R_CONVERT(ncm::ResultContentMetaNotFound, fs::ResultTargetNotFound());
} R_END_TRY_CATCH;
@ -34,7 +34,7 @@ namespace ams::fs::impl {
return ResultSuccess();
}
Result MountDataImpl(const char *name, ncm::ProgramId data_id, ncm::StorageId storage_id, void *cache_buffer, size_t cache_size, bool use_cache, bool use_data_cache, bool use_path_cache) {
Result MountDataImpl(const char *name, ncm::DataId data_id, ncm::StorageId storage_id, void *cache_buffer, size_t cache_size, bool use_cache, bool use_data_cache, bool use_path_cache) {
std::unique_ptr<fs::IStorage> storage;
R_TRY(OpenDataStorageByDataId(std::addressof(storage), data_id, storage_id));
@ -47,7 +47,7 @@ namespace ams::fs::impl {
}
Result QueryMountDataCacheSize(size_t *out, ncm::ProgramId data_id, ncm::StorageId storage_id) {
Result QueryMountDataCacheSize(size_t *out, ncm::DataId data_id, ncm::StorageId storage_id) {
R_UNLESS(out != nullptr, fs::ResultNullptrArgument());
std::unique_ptr<fs::IStorage> storage;
@ -61,14 +61,14 @@ namespace ams::fs::impl {
return ResultSuccess();
}
Result MountData(const char *name, ncm::ProgramId data_id, ncm::StorageId storage_id) {
Result MountData(const char *name, ncm::DataId data_id, ncm::StorageId storage_id) {
/* Validate the mount name. */
R_TRY(impl::CheckMountName(name));
return MountDataImpl(name, data_id, storage_id, nullptr, 0, false, false, false);
}
Result MountData(const char *name, ncm::ProgramId data_id, ncm::StorageId storage_id, void *cache_buffer, size_t cache_size) {
Result MountData(const char *name, ncm::DataId data_id, ncm::StorageId storage_id, void *cache_buffer, size_t cache_size) {
/* Validate the mount name. */
R_TRY(impl::CheckMountName(name));
@ -77,7 +77,7 @@ namespace ams::fs::impl {
return MountDataImpl(name, data_id, storage_id, cache_buffer, cache_size, true, false, false);
}
Result MountData(const char *name, ncm::ProgramId data_id, ncm::StorageId storage_id, void *cache_buffer, size_t cache_size, bool use_data_cache, bool use_path_cache) {
Result MountData(const char *name, ncm::DataId data_id, ncm::StorageId storage_id, void *cache_buffer, size_t cache_size, bool use_data_cache, bool use_path_cache) {
/* Validate the mount name. */
R_TRY(impl::CheckMountName(name));

View file

@ -18,15 +18,15 @@
namespace ams::fs {
Result QueryMountSystemDataCacheSize(size_t *out, ncm::ProgramId data_id) {
Result QueryMountSystemDataCacheSize(size_t *out, ncm::DataId data_id) {
return impl::QueryMountDataCacheSize(out, data_id, ncm::StorageId::BuiltInSystem);
}
Result MountSystemData(const char *name, ncm::ProgramId data_id) {
Result MountSystemData(const char *name, ncm::DataId data_id) {
return impl::MountData(name, data_id, ncm::StorageId::BuiltInSystem);
}
Result MountSystemData(const char *name, ncm::ProgramId data_id, void *cache_buffer, size_t cache_size) {
Result MountSystemData(const char *name, ncm::DataId data_id, void *cache_buffer, size_t cache_size) {
return impl::MountData(name, data_id, ncm::StorageId::BuiltInSystem, cache_buffer, cache_size);
}

View file

@ -35,17 +35,17 @@ namespace ams::mitm::settings {
}
/* Mount firmware version data archive. */
R_ABORT_UNLESS(romfsMountFromDataArchive(ncm::SystemDataId::SystemVersion.value, NcmStorageId_BuiltInSystem, "sysver"));
{
ON_SCOPE_EXIT { romfsUnmount("sysver"); };
R_ABORT_UNLESS(ams::fs::MountSystemData("sysver", ncm::SystemDataId::SystemVersion));
ON_SCOPE_EXIT { ams::fs::Unmount("sysver"); };
/* Firmware version file must exist. */
FILE *fp = fopen("sysver:/file", "rb");
AMS_ABORT_UNLESS(fp != nullptr);
ON_SCOPE_EXIT { fclose(fp); };
ams::fs::FileHandle file;
R_ABORT_UNLESS(ams::fs::OpenFile(std::addressof(file), "sysver:/file", fs::OpenMode_Read));
ON_SCOPE_EXIT { ams::fs::CloseFile(file); };
/* Must be possible to read firmware version from file. */
AMS_ABORT_UNLESS(fread(&g_firmware_version, sizeof(g_firmware_version), 1, fp) == 1);
R_ABORT_UNLESS(ams::fs::ReadFile(file, 0, std::addressof(g_firmware_version), sizeof(g_firmware_version)));
g_ams_firmware_version = g_firmware_version;
}