mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-26 05:42:17 +00:00
ams_mitm: update to use new NcaFileSystemDriver intf
This commit is contained in:
parent
e08f754646
commit
2b6719ec25
7 changed files with 82 additions and 10 deletions
|
@ -28,7 +28,7 @@ namespace ams::fssystem {
|
|||
Result QueryNextOffset(s64 *out, s64 start_offset, s64 end_offset, s64 access_size, s64 alignment_size);
|
||||
public:
|
||||
virtual Result QueryAppropriateOffset(s64 *out, s64 offset, s64 access_size, s64 alignment_size) = 0;
|
||||
virtual Result QueryInvocationCount(s64 *out, s64 start_offset, s64 end_offset, s64 access_size, s64 alignment_size);
|
||||
virtual Result QueryInvocationCount(s64 *out, s64 start_offset, s64 end_offset, s64 access_size, s64 alignment_size) { AMS_UNUSED(out, start_offset, end_offset, access_size, alignment_size); AMS_ABORT("TODO"); }
|
||||
};
|
||||
|
||||
class DefaultAsynchronousAccessSplitter final : public IAsynchronousAccessSplitter {
|
||||
|
|
|
@ -56,7 +56,10 @@ namespace ams::fssystem {
|
|||
CompressedStorage() { /* ... */ }
|
||||
virtual ~CompressedStorage() { this->Finalize(); }
|
||||
|
||||
Result Initialize(MemoryResource *bktr_allocator, IBufferManager *cache_allocator, fs::SubStorage data_storage, fs::SubStorage node_storage, fs::SubStorage entry_storage, s32 bktr_entry_count, size_t block_size_max, size_t continuous_reading_size_max, GetDecompressorFunction get_decompressor, size_t cache_size_0, size_t cache_size_1, s32 max_cache_entries);
|
||||
Result Initialize(MemoryResource *bktr_allocator, IBufferManager *cache_allocator, fs::SubStorage data_storage, fs::SubStorage node_storage, fs::SubStorage entry_storage, s32 bktr_entry_count, size_t block_size_max, size_t continuous_reading_size_max, GetDecompressorFunction get_decompressor, size_t cache_size_0, size_t cache_size_1, s32 max_cache_entries) {
|
||||
AMS_UNUSED(bktr_allocator, cache_allocator, data_storage, node_storage, entry_storage, bktr_entry_count, block_size_max, continuous_reading_size_max, get_decompressor, cache_size_0, cache_size_1, max_cache_entries);
|
||||
AMS_ABORT("TODO");
|
||||
}
|
||||
|
||||
void Finalize() {
|
||||
AMS_ABORT("TODO");
|
||||
|
@ -70,8 +73,8 @@ namespace ams::fssystem {
|
|||
/* return m_core.QueryAppropriateOffsetForAsynchronousAccess(out, offset, access_size, alignment_size); */
|
||||
}
|
||||
public:
|
||||
virtual Result Read(s64 offset, void *buffer, size_t size) override;
|
||||
virtual Result OperateRange(void *dst, size_t dst_size, fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override;
|
||||
virtual Result Read(s64 offset, void *buffer, size_t size) override { AMS_UNUSED(offset, buffer, size); AMS_ABORT("TODO"); }
|
||||
virtual Result OperateRange(void *dst, size_t dst_size, fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override { AMS_UNUSED(dst, dst_size, op_id, offset, size, src, src_size); AMS_ABORT("TODO"); }
|
||||
|
||||
virtual Result GetSize(s64 *out) override {
|
||||
AMS_ABORT("TODO");
|
||||
|
|
|
@ -28,6 +28,8 @@ namespace ams::fssystem {
|
|||
/* This should be re-examined when FS is reimplemented. */
|
||||
void InitializeForFileSystemProxy();
|
||||
|
||||
void InitializeForAtmosphereMitm();
|
||||
|
||||
const ::ams::fssrv::fscreator::FileSystemCreatorInterfaces *GetFileSystemCreatorInterfaces();
|
||||
|
||||
}
|
||||
|
|
|
@ -185,6 +185,73 @@ namespace ams::fssystem {
|
|||
/* TODO FS-REIMPL: spl::Finalize(); */
|
||||
}
|
||||
|
||||
void InitializeForAtmosphereMitm() {
|
||||
/* Initialize spl library. */
|
||||
spl::InitializeForFs();
|
||||
|
||||
/* TODO FS-REIMPL: spl::SetIsAvailableAccessKeyHandler(fssrv::IsAvailableAccessKey) */
|
||||
|
||||
/* Determine whether we're prod or dev. */
|
||||
bool is_prod = !spl::IsDevelopment();
|
||||
bool is_development_function_enabled = spl::IsDevelopmentFunctionEnabled();
|
||||
|
||||
/* Set debug flags. */
|
||||
fssrv::SetDebugFlagEnabled(is_development_function_enabled);
|
||||
|
||||
/* Setup our crypto configuration. */
|
||||
SetUpKekAccessKeys(is_prod);
|
||||
|
||||
/* Setup our heap. */
|
||||
InitializeExpHeap();
|
||||
|
||||
/* Initialize buffer allocator. */
|
||||
util::ConstructAt(g_buffer_allocator, g_buffer_pool, BufferPoolSize);
|
||||
util::ConstructAt(g_allocator, GetPointer(g_buffer_allocator));
|
||||
|
||||
/* Set allocators. */
|
||||
/* TODO FS-REIMPL: sf::SetGlobalDefaultMemoryResource() */
|
||||
fs::SetAllocator(AllocateForFileSystemProxy, DeallocateForFileSystemProxy);
|
||||
fssystem::InitializeAllocator(AllocateForFileSystemProxy, DeallocateForFileSystemProxy);
|
||||
fssystem::InitializeAllocatorForSystem(AllocateForFileSystemProxy, DeallocateForFileSystemProxy);
|
||||
|
||||
/* Initialize the buffer manager. */
|
||||
/* TODO FS-REIMPL: os::AllocateMemoryBlock(...); */
|
||||
util::ConstructAt(g_buffer_manager);
|
||||
GetReference(g_buffer_manager).Initialize(MaxCacheCount, reinterpret_cast<uintptr_t>(g_buffer_manager_heap), BufferManagerHeapSize, BlockSize);
|
||||
|
||||
/* TODO FS-REIMPL: os::AllocateMemoryBlock(...); */
|
||||
/* TODO FS-REIMPL: fssrv::storage::CreateDeviceAddressSpace(...); */
|
||||
fssystem::InitializeBufferPool(reinterpret_cast<char *>(g_device_buffer), DeviceBufferSize);
|
||||
|
||||
/* TODO FS-REIMPL: Create Pooled Threads/Stack Usage Reporter, fssystem::RegisterThreadPool. */
|
||||
|
||||
/* TODO FS-REIMPL: fssrv::GetFileSystemProxyServices(), some service creation. */
|
||||
|
||||
/* Initialize fs creators. */
|
||||
/* TODO FS-REIMPL: Revise for accuracy. */
|
||||
util::ConstructAt(g_rom_fs_creator, GetPointer(g_allocator));
|
||||
util::ConstructAt(g_partition_fs_creator);
|
||||
util::ConstructAt(g_storage_on_nca_creator, GetPointer(g_allocator), *GetNcaCryptoConfiguration(is_prod), *GetNcaCompressionConfiguration(), GetPointer(g_buffer_manager), fs::impl::GetNcaHashGeneratorFactorySelector());
|
||||
|
||||
/* TODO FS-REIMPL: Initialize other creators. */
|
||||
g_fs_creator_interfaces = {
|
||||
.rom_fs_creator = GetPointer(g_rom_fs_creator),
|
||||
.partition_fs_creator = GetPointer(g_partition_fs_creator),
|
||||
.storage_on_nca_creator = GetPointer(g_storage_on_nca_creator),
|
||||
};
|
||||
|
||||
/* Initialize fssrv. TODO FS-REIMPL: More arguments, more actions taken. */
|
||||
fssrv::InitializeForFileSystemProxy(std::addressof(g_fs_creator_interfaces), GetPointer(g_buffer_manager), is_development_function_enabled);
|
||||
|
||||
/* Disable auto-abort in fs library code. */
|
||||
fs::SetEnabledAutoAbort(false);
|
||||
|
||||
/* Quick sanity check, before we leave. */
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
AMS_ABORT_UNLESS(os::GetCurrentProgramId() == ncm::AtmosphereProgramId::Mitm);
|
||||
#endif
|
||||
}
|
||||
|
||||
const ::ams::fssrv::fscreator::FileSystemCreatorInterfaces *GetFileSystemCreatorInterfaces() {
|
||||
return std::addressof(g_fs_creator_interfaces);
|
||||
}
|
||||
|
|
|
@ -1022,7 +1022,7 @@ namespace ams::fssystem {
|
|||
R_TRY(buffer_hold_storage->GetSize(std::addressof(base_size)));
|
||||
|
||||
/* Check that we're within range. */
|
||||
R_UNLESS(data_region.offset + data_region.size <= base_size, fs::ResultNcaBaseStorageOutOfRangeC());
|
||||
R_UNLESS(hash_region.offset + hash_region.size <= base_size, fs::ResultNcaBaseStorageOutOfRangeC());
|
||||
R_UNLESS(data_region.offset + data_region.size <= base_size, fs::ResultNcaBaseStorageOutOfRangeC());
|
||||
|
||||
/* Create the master hash storage. */
|
||||
|
|
|
@ -43,7 +43,6 @@ namespace ams {
|
|||
R_ABORT_UNLESS(pmdmntInitialize());
|
||||
R_ABORT_UNLESS(pminfoInitialize());
|
||||
ncm::Initialize();
|
||||
spl::InitializeForFs();
|
||||
|
||||
/* Verify that we can sanely execute. */
|
||||
ams::CheckApiVersion();
|
||||
|
@ -79,7 +78,7 @@ namespace ams {
|
|||
}
|
||||
|
||||
/* Initialize fssystem library. */
|
||||
fssystem::InitializeForFileSystemProxy();
|
||||
fssystem::InitializeForAtmosphereMitm();
|
||||
|
||||
/* Configure ncm to use fssystem library to mount content from the sd card. */
|
||||
ncm::SetMountContentMetaFunction(mitm::sysupdater::MountSdCardContentMeta);
|
||||
|
|
|
@ -151,7 +151,7 @@ namespace ams::mitm::sysupdater {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result OpenMetaStorage(std::shared_ptr<ams::fs::IStorage> *out, std::shared_ptr<fssystem::NcaReader> nca_reader, fssystem::NcaFsHeader::FsType *out_fs_type) {
|
||||
Result OpenMetaStorage(std::shared_ptr<ams::fs::IStorage> *out, std::shared_ptr<fssystem::IAsynchronousAccessSplitter> *out_splitter, std::shared_ptr<fssystem::NcaReader> nca_reader, fssystem::NcaFsHeader::FsType *out_fs_type) {
|
||||
/* Ensure the nca is a meta nca. */
|
||||
R_UNLESS(nca_reader->GetContentType() == fssystem::NcaHeader::ContentType::Meta, fs::ResultPreconditionViolation());
|
||||
|
||||
|
@ -163,7 +163,7 @@ namespace ams::mitm::sysupdater {
|
|||
|
||||
/* Open fs header reader. */
|
||||
fssystem::NcaFsHeaderReader fs_header_reader;
|
||||
R_TRY(fssystem::GetFileSystemCreatorInterfaces()->storage_on_nca_creator->Create(out, std::addressof(fs_header_reader), std::move(nca_reader), MetaPartitionIndex, false));
|
||||
R_TRY(fssystem::GetFileSystemCreatorInterfaces()->storage_on_nca_creator->Create(out, out_splitter, std::addressof(fs_header_reader), std::move(nca_reader), MetaPartitionIndex));
|
||||
|
||||
/* Set the output fs type. */
|
||||
*out_fs_type = fs_header_reader.GetFsType();
|
||||
|
@ -195,8 +195,9 @@ namespace ams::mitm::sysupdater {
|
|||
|
||||
/* Open meta storage. */
|
||||
std::shared_ptr<ams::fs::IStorage> storage;
|
||||
std::shared_ptr<fssystem::IAsynchronousAccessSplitter> splitter;
|
||||
fssystem::NcaFsHeader::FsType fs_type;
|
||||
R_TRY(OpenMetaStorage(std::addressof(storage), std::move(nca_reader), std::addressof(fs_type)));
|
||||
R_TRY(OpenMetaStorage(std::addressof(storage), std::addressof(splitter), std::move(nca_reader), std::addressof(fs_type)));
|
||||
|
||||
/* Open the appropriate interface. */
|
||||
const auto * const creator_intfs = fssystem::GetFileSystemCreatorInterfaces();
|
||||
|
|
Loading…
Reference in a new issue