diff --git a/libraries/libstratosphere/include/stratosphere/fs.hpp b/libraries/libstratosphere/include/stratosphere/fs.hpp index 7ecf5abae..98800f5a4 100644 --- a/libraries/libstratosphere/include/stratosphere/fs.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs.hpp @@ -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" diff --git a/libraries/libstratosphere/include/stratosphere/fs/fs_system_data.hpp b/libraries/libstratosphere/include/stratosphere/fs/fs_system_data.hpp index 43cba17ee..e89ef8824 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/fs_system_data.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/fs_system_data.hpp @@ -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); } diff --git a/libraries/libstratosphere/include/stratosphere/fs/fs_data.hpp b/libraries/libstratosphere/include/stratosphere/fs/impl/fs_data.hpp similarity index 56% rename from libraries/libstratosphere/include/stratosphere/fs/fs_data.hpp rename to libraries/libstratosphere/include/stratosphere/fs/impl/fs_data.hpp index 0fb4d4068..4db782114 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/fs_data.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/impl/fs_data.hpp @@ -14,14 +14,14 @@ * along with this program. If not, see . */ #pragma once -#include "fs_common.hpp" +#include 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); } diff --git a/libraries/libstratosphere/source/fs/fs_data.cpp b/libraries/libstratosphere/source/fs/fs_data.cpp index b1d78d58f..4d7135b34 100644 --- a/libraries/libstratosphere/source/fs/fs_data.cpp +++ b/libraries/libstratosphere/source/fs/fs_data.cpp @@ -20,10 +20,10 @@ namespace ams::fs::impl { namespace { - Result OpenDataStorageByDataId(std::unique_ptr *out, ncm::ProgramId data_id, ncm::StorageId storage_id) { + Result OpenDataStorageByDataId(std::unique_ptr *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(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 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 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)); diff --git a/libraries/libstratosphere/source/fs/fs_system_data.cpp b/libraries/libstratosphere/source/fs/fs_system_data.cpp index 6f7db7b71..3231e330c 100644 --- a/libraries/libstratosphere/source/fs/fs_system_data.cpp +++ b/libraries/libstratosphere/source/fs/fs_system_data.cpp @@ -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); } diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp index 9bbf89df1..dc2cf1b35 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp @@ -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; }