mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-07-14 13:12:13 +02:00
ams.mitm: use fs bindings instead of stdio
This commit is contained in:
parent
c4bf3adb4f
commit
150efae91e
@ -32,7 +32,7 @@
|
|||||||
#include "fs/fs_path_tool.hpp"
|
#include "fs/fs_path_tool.hpp"
|
||||||
#include "fs/fs_path_utils.hpp"
|
#include "fs/fs_path_utils.hpp"
|
||||||
#include "fs/fs_romfs_filesystem.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_system_data.hpp"
|
||||||
#include "fs/fs_content_storage.hpp"
|
#include "fs/fs_content_storage.hpp"
|
||||||
#include "fs/fs_game_card.hpp"
|
#include "fs/fs_game_card.hpp"
|
||||||
|
@ -18,9 +18,9 @@
|
|||||||
|
|
||||||
namespace ams::fs {
|
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::DataId 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, void *cache_buffer, size_t cache_size);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,14 +14,14 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "fs_common.hpp"
|
#include <stratosphere/fs/fs_common.hpp>
|
||||||
|
|
||||||
namespace ams::fs::impl {
|
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::DataId 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::DataId 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, void *cache_buffer, size_t cache_size, bool use_data_cache, bool use_path_cache);
|
||||||
|
|
||||||
}
|
}
|
@ -20,10 +20,10 @@ namespace ams::fs::impl {
|
|||||||
|
|
||||||
namespace {
|
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. */
|
/* Open storage using libnx bindings. */
|
||||||
::FsStorage s;
|
::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_CONVERT(ncm::ResultContentMetaNotFound, fs::ResultTargetNotFound());
|
||||||
} R_END_TRY_CATCH;
|
} R_END_TRY_CATCH;
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ namespace ams::fs::impl {
|
|||||||
return ResultSuccess();
|
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;
|
std::unique_ptr<fs::IStorage> storage;
|
||||||
R_TRY(OpenDataStorageByDataId(std::addressof(storage), data_id, storage_id));
|
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());
|
R_UNLESS(out != nullptr, fs::ResultNullptrArgument());
|
||||||
|
|
||||||
std::unique_ptr<fs::IStorage> storage;
|
std::unique_ptr<fs::IStorage> storage;
|
||||||
@ -61,14 +61,14 @@ namespace ams::fs::impl {
|
|||||||
return ResultSuccess();
|
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. */
|
/* Validate the mount name. */
|
||||||
R_TRY(impl::CheckMountName(name));
|
R_TRY(impl::CheckMountName(name));
|
||||||
|
|
||||||
return MountDataImpl(name, data_id, storage_id, nullptr, 0, false, false, false);
|
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. */
|
/* Validate the mount name. */
|
||||||
R_TRY(impl::CheckMountName(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);
|
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. */
|
/* Validate the mount name. */
|
||||||
R_TRY(impl::CheckMountName(name));
|
R_TRY(impl::CheckMountName(name));
|
||||||
|
|
||||||
|
@ -18,15 +18,15 @@
|
|||||||
|
|
||||||
namespace ams::fs {
|
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);
|
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);
|
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);
|
return impl::MountData(name, data_id, ncm::StorageId::BuiltInSystem, cache_buffer, cache_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,17 +35,17 @@ namespace ams::mitm::settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Mount firmware version data archive. */
|
/* 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. */
|
/* Firmware version file must exist. */
|
||||||
FILE *fp = fopen("sysver:/file", "rb");
|
ams::fs::FileHandle file;
|
||||||
AMS_ABORT_UNLESS(fp != nullptr);
|
R_ABORT_UNLESS(ams::fs::OpenFile(std::addressof(file), "sysver:/file", fs::OpenMode_Read));
|
||||||
ON_SCOPE_EXIT { fclose(fp); };
|
ON_SCOPE_EXIT { ams::fs::CloseFile(file); };
|
||||||
|
|
||||||
/* Must be possible to read firmware version from 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;
|
g_ams_firmware_version = g_firmware_version;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user