fs: move bitmap classes out of save::

This commit is contained in:
Michael Scire 2022-03-12 14:08:39 -08:00 committed by SciresM
parent 7a69723021
commit be9338eb33
14 changed files with 52 additions and 85 deletions

View file

@ -13,10 +13,10 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* 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 <stratosphere/fssystem/fssystem_allocator_utility.hpp> #include <stratosphere/fssystem/fssystem_allocator_utility.hpp>
#include <stratosphere/fssystem/fssystem_utility.hpp> #include <stratosphere/fssystem/fssystem_utility.hpp>
#include <stratosphere/fssystem/fssystem_bitmap_utils.hpp>
#include <stratosphere/fssystem/fssystem_speed_emulation_configuration.hpp> #include <stratosphere/fssystem/fssystem_speed_emulation_configuration.hpp>
#include <stratosphere/fssystem/fssystem_external_code.hpp> #include <stratosphere/fssystem/fssystem_external_code.hpp>
#include <stratosphere/fssystem/fssystem_forwarding_file_system.hpp> #include <stratosphere/fssystem/fssystem_forwarding_file_system.hpp>
@ -46,8 +46,8 @@
#include <stratosphere/fssystem/fssystem_alignment_matching_storage_impl.hpp> #include <stratosphere/fssystem/fssystem_alignment_matching_storage_impl.hpp>
#include <stratosphere/fssystem/fssystem_alignment_matching_storage.hpp> #include <stratosphere/fssystem/fssystem_alignment_matching_storage.hpp>
#include <stratosphere/fssystem/fssystem_compressed_storage.hpp> #include <stratosphere/fssystem/fssystem_compressed_storage.hpp>
#include <stratosphere/fssystem/save/fssystem_buffered_storage.hpp> #include <stratosphere/fssystem/fssystem_buffered_storage.hpp>
#include <stratosphere/fssystem/save/fssystem_hierarchical_integrity_verification_storage.hpp> #include <stratosphere/fssystem/fssystem_hierarchical_integrity_verification_storage.hpp>
#include <stratosphere/fssystem/fssystem_integrity_romfs_storage.hpp> #include <stratosphere/fssystem/fssystem_integrity_romfs_storage.hpp>
#include <stratosphere/fssystem/fssystem_sha256_hash_generator.hpp> #include <stratosphere/fssystem/fssystem_sha256_hash_generator.hpp>
#include <stratosphere/fssystem/fssystem_local_file_system.hpp> #include <stratosphere/fssystem/fssystem_local_file_system.hpp>

View file

@ -1,43 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::fssystem::dbm {
namespace {
constexpr inline s32 CountLeadingZeros(u32 val) {
return util::CountLeadingZeros(val);
}
constexpr inline s32 CountLeadingOnes(u32 val) {
return CountLeadingZeros(~val);
}
inline u32 ReadU32(const u8 *buf, size_t index) {
u32 val;
std::memcpy(std::addressof(val), buf + index, sizeof(u32));
return val;
}
inline void WriteU32(u8 *buf, size_t index, u32 val) {
std::memcpy(buf + index, std::addressof(val), sizeof(u32));
}
}
}

View file

@ -15,12 +15,26 @@
*/ */
#pragma once #pragma once
#include <vapours.hpp> #include <vapours.hpp>
#include <stratosphere/lmem.hpp>
#include <stratosphere/fs/fs_directory.hpp>
#include <stratosphere/fs/fs_filesystem.hpp>
#include <stratosphere/fssystem/dbm/fssystem_dbm_utils.hpp>
namespace ams::fssystem::save { namespace ams::fssystem {
constexpr inline s32 CountLeadingZeros(u32 val) {
return util::CountLeadingZeros(val);
}
constexpr inline s32 CountLeadingOnes(u32 val) {
return CountLeadingZeros(~val);
}
inline u32 ReadU32(const u8 *buf, size_t index) {
u32 val;
std::memcpy(std::addressof(val), buf + index, sizeof(u32));
return val;
}
inline void WriteU32(u8 *buf, size_t index, u32 val) {
std::memcpy(buf + index, std::addressof(val), sizeof(u32));
}
constexpr inline bool IsPowerOfTwo(s32 val) { constexpr inline bool IsPowerOfTwo(s32 val) {
return util::IsPowerOfTwo(val); return util::IsPowerOfTwo(val);
@ -28,14 +42,15 @@ namespace ams::fssystem::save {
constexpr inline u32 ILog2(u32 val) { constexpr inline u32 ILog2(u32 val) {
AMS_ASSERT(val > 0); AMS_ASSERT(val > 0);
return (BITSIZEOF(u32) - 1 - dbm::CountLeadingZeros(val)); return (BITSIZEOF(u32) - 1 - util::CountLeadingZeros<u32>(val));
} }
constexpr inline u32 CeilPowerOfTwo(u32 val) { constexpr inline u32 CeilingPowerOfTwo(u32 val) {
if (val == 0) { if (val == 0) {
return 1; return 1;
} }
return ((1u << (BITSIZEOF(u32) - 1)) >> (dbm::CountLeadingZeros(val - 1) - 1));
return util::CeilingPowerOfTwo<u32>(val);
} }
} }

View file

@ -19,11 +19,10 @@
#include <stratosphere/fs/fs_storage_type.hpp> #include <stratosphere/fs/fs_storage_type.hpp>
#include <stratosphere/fs/fs_istorage.hpp> #include <stratosphere/fs/fs_istorage.hpp>
#include <stratosphere/fs/fs_memory_management.hpp> #include <stratosphere/fs/fs_memory_management.hpp>
#include <stratosphere/fssystem/save/fssystem_i_save_file_system_driver.hpp>
#include <stratosphere/fssystem/buffers/fssystem_file_system_buffer_manager.hpp> #include <stratosphere/fssystem/buffers/fssystem_file_system_buffer_manager.hpp>
#include <stratosphere/fssystem/impl/fssystem_block_cache_manager.hpp> #include <stratosphere/fssystem/impl/fssystem_block_cache_manager.hpp>
namespace ams::fssystem::save { namespace ams::fssystem {
constexpr inline size_t IntegrityMinLayerCount = 2; constexpr inline size_t IntegrityMinLayerCount = 2;
constexpr inline size_t IntegrityMaxLayerCount = 7; constexpr inline size_t IntegrityMaxLayerCount = 7;

View file

@ -20,7 +20,7 @@
#include <stratosphere/fs/fs_substorage.hpp> #include <stratosphere/fs/fs_substorage.hpp>
#include <stratosphere/fs/fs_i_buffer_manager.hpp> #include <stratosphere/fs/fs_i_buffer_manager.hpp>
namespace ams::fssystem::save { namespace ams::fssystem {
class BufferedStorage : public ::ams::fs::IStorage { class BufferedStorage : public ::ams::fs::IStorage {
NON_COPYABLE(BufferedStorage); NON_COPYABLE(BufferedStorage);

View file

@ -19,11 +19,10 @@
#include <stratosphere/fs/fs_istorage.hpp> #include <stratosphere/fs/fs_istorage.hpp>
#include <stratosphere/fs/fs_substorage.hpp> #include <stratosphere/fs/fs_substorage.hpp>
#include <stratosphere/fs/fs_storage_type.hpp> #include <stratosphere/fs/fs_storage_type.hpp>
#include <stratosphere/fssystem/save/fssystem_i_save_file.hpp> #include <stratosphere/fssystem/fssystem_integrity_verification_storage.hpp>
#include <stratosphere/fssystem/save/fssystem_integrity_verification_storage.hpp> #include <stratosphere/fssystem/fssystem_block_cache_buffered_storage.hpp>
#include <stratosphere/fssystem/save/fssystem_block_cache_buffered_storage.hpp>
namespace ams::fssystem::save { namespace ams::fssystem {
struct HierarchicalIntegrityVerificationLevelInformation { struct HierarchicalIntegrityVerificationLevelInformation {
fs::Int64 offset; fs::Int64 offset;

View file

@ -19,7 +19,7 @@
#include <stratosphere/fs/fs_memory_storage.hpp> #include <stratosphere/fs/fs_memory_storage.hpp>
#include <stratosphere/fs/impl/fs_newable.hpp> #include <stratosphere/fs/impl/fs_newable.hpp>
#include <stratosphere/fssystem/fssystem_nca_header.hpp> #include <stratosphere/fssystem/fssystem_nca_header.hpp>
#include <stratosphere/fssystem/save/fssystem_hierarchical_integrity_verification_storage.hpp> #include <stratosphere/fssystem/fssystem_hierarchical_integrity_verification_storage.hpp>
namespace ams::fssystem { namespace ams::fssystem {
@ -28,8 +28,8 @@ namespace ams::fssystem {
class IntegrityRomFsStorage : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable { class IntegrityRomFsStorage : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable {
private: private:
save::HierarchicalIntegrityVerificationStorage m_integrity_storage; HierarchicalIntegrityVerificationStorage m_integrity_storage;
save::FileSystemBufferManagerSet m_buffers; FileSystemBufferManagerSet m_buffers;
os::SdkRecursiveMutex m_mutex; os::SdkRecursiveMutex m_mutex;
Hash m_master_hash; Hash m_master_hash;
std::unique_ptr<fs::MemoryStorage> m_master_hash_storage; std::unique_ptr<fs::MemoryStorage> m_master_hash_storage;
@ -37,7 +37,7 @@ namespace ams::fssystem {
IntegrityRomFsStorage() : m_mutex() { /* ... */ } IntegrityRomFsStorage() : m_mutex() { /* ... */ }
virtual ~IntegrityRomFsStorage() override { this->Finalize(); } virtual ~IntegrityRomFsStorage() override { this->Finalize(); }
Result Initialize(save::HierarchicalIntegrityVerificationInformation level_hash_info, Hash master_hash, save::HierarchicalIntegrityVerificationStorage::HierarchicalStorageInformation storage_info, fs::IBufferManager *bm, IHash256GeneratorFactory *hgf); Result Initialize(HierarchicalIntegrityVerificationInformation level_hash_info, Hash master_hash, HierarchicalIntegrityVerificationStorage::HierarchicalStorageInformation storage_info, fs::IBufferManager *bm, IHash256GeneratorFactory *hgf);
void Finalize(); void Finalize();
virtual Result Read(s64 offset, void *buffer, size_t size) override { virtual Result Read(s64 offset, void *buffer, size_t size) override {
@ -66,7 +66,7 @@ namespace ams::fssystem {
return m_integrity_storage.Commit(); return m_integrity_storage.Commit();
} }
save::FileSystemBufferManagerSet *GetBuffers() { FileSystemBufferManagerSet *GetBuffers() {
return m_integrity_storage.GetBuffers(); return m_integrity_storage.GetBuffers();
} }
}; };

View file

@ -19,12 +19,9 @@
#include <stratosphere/fs/fs_istorage.hpp> #include <stratosphere/fs/fs_istorage.hpp>
#include <stratosphere/fs/fs_substorage.hpp> #include <stratosphere/fs/fs_substorage.hpp>
#include <stratosphere/fs/fs_storage_type.hpp> #include <stratosphere/fs/fs_storage_type.hpp>
#include <stratosphere/fs/fs_save_data_types.hpp> #include <stratosphere/fssystem/fssystem_block_cache_buffered_storage.hpp>
#include <stratosphere/fssystem/save/fssystem_save_types.hpp>
#include <stratosphere/fssystem/save/fssystem_i_save_file_system_driver.hpp>
#include <stratosphere/fssystem/save/fssystem_block_cache_buffered_storage.hpp>
namespace ams::fssystem::save { namespace ams::fssystem {
class IntegrityVerificationStorage : public ::ams::fs::IStorage { class IntegrityVerificationStorage : public ::ams::fs::IStorage {
NON_COPYABLE(IntegrityVerificationStorage); NON_COPYABLE(IntegrityVerificationStorage);

View file

@ -15,7 +15,7 @@
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
namespace ams::fssystem::save { namespace ams::fssystem {
BlockCacheBufferedStorage::BlockCacheBufferedStorage() : m_mutex(), m_data_storage(), m_last_result(ResultSuccess()), m_data_size(), m_verification_block_size(), m_verification_block_shift(), m_flags(), m_buffer_level(-1), m_block_cache_manager() BlockCacheBufferedStorage::BlockCacheBufferedStorage() : m_mutex(), m_data_storage(), m_last_result(ResultSuccess()), m_data_size(), m_verification_block_size(), m_verification_block_shift(), m_flags(), m_buffer_level(-1), m_block_cache_manager()
{ {

View file

@ -15,7 +15,7 @@
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
namespace ams::fssystem::save { namespace ams::fssystem {
namespace { namespace {

View file

@ -15,7 +15,7 @@
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
namespace ams::fssystem::save { namespace ams::fssystem {
namespace { namespace {

View file

@ -17,7 +17,7 @@
namespace ams::fssystem { namespace ams::fssystem {
Result IntegrityRomFsStorage::Initialize(save::HierarchicalIntegrityVerificationInformation level_hash_info, Hash master_hash, save::HierarchicalIntegrityVerificationStorage::HierarchicalStorageInformation storage_info, fs::IBufferManager *bm, IHash256GeneratorFactory *hgf) { Result IntegrityRomFsStorage::Initialize(HierarchicalIntegrityVerificationInformation level_hash_info, Hash master_hash, HierarchicalIntegrityVerificationStorage::HierarchicalStorageInformation storage_info, fs::IBufferManager *bm, IHash256GeneratorFactory *hgf) {
/* Validate preconditions. */ /* Validate preconditions. */
AMS_ASSERT(bm != nullptr); AMS_ASSERT(bm != nullptr);

View file

@ -15,7 +15,7 @@
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
namespace ams::fssystem::save { namespace ams::fssystem {
Result IntegrityVerificationStorage::Initialize(fs::SubStorage hs, fs::SubStorage ds, s64 verif_block_size, s64 upper_layer_verif_block_size, fs::IBufferManager *bm, fssystem::IHash256GeneratorFactory *hgf, const fs::HashSalt &salt, bool is_real_data, fs::StorageType storage_type) { Result IntegrityVerificationStorage::Initialize(fs::SubStorage hs, fs::SubStorage ds, s64 verif_block_size, s64 upper_layer_verif_block_size, fs::IBufferManager *bm, fssystem::IHash256GeneratorFactory *hgf, const fs::HashSalt &salt, bool is_real_data, fs::StorageType storage_type) {
/* Validate preconditions. */ /* Validate preconditions. */

View file

@ -549,7 +549,7 @@ namespace ams::fssystem {
R_TRY(base_storage->GetSize(std::addressof(base_size))); R_TRY(base_storage->GetSize(std::addressof(base_size)));
/* Create buffered storage. */ /* Create buffered storage. */
auto buffered_storage = fssystem::AllocateShared<save::BufferedStorage>(); auto buffered_storage = fssystem::AllocateShared<BufferedStorage>();
R_UNLESS(buffered_storage != nullptr, fs::ResultAllocationFailureInAllocateShared()); R_UNLESS(buffered_storage != nullptr, fs::ResultAllocationFailureInAllocateShared());
/* Initialize the buffered storage. */ /* Initialize the buffered storage. */
@ -655,7 +655,7 @@ namespace ams::fssystem {
R_TRY(this->CreateAesCtrStorage(std::addressof(decrypted_storage), std::move(enc_storage), offset + meta_offset, sparse_info.MakeAesCtrUpperIv(upper_iv), AlignmentStorageRequirement_None)); R_TRY(this->CreateAesCtrStorage(std::addressof(decrypted_storage), std::move(enc_storage), offset + meta_offset, sparse_info.MakeAesCtrUpperIv(upper_iv), AlignmentStorageRequirement_None));
/* Create meta storage. */ /* Create meta storage. */
auto meta_storage = fssystem::AllocateShared<save::BufferedStorage>(); auto meta_storage = fssystem::AllocateShared<BufferedStorage>();
R_UNLESS(meta_storage != nullptr, fs::ResultAllocationFailureInAllocateShared()); R_UNLESS(meta_storage != nullptr, fs::ResultAllocationFailureInAllocateShared());
/* Initialize the meta storage. */ /* Initialize the meta storage. */
@ -789,7 +789,7 @@ namespace ams::fssystem {
R_TRY(this->CreateAesCtrStorage(std::addressof(decrypted_storage), std::move(enc_storage), offset + meta_offset, upper_iv, AlignmentStorageRequirement_None)); R_TRY(this->CreateAesCtrStorage(std::addressof(decrypted_storage), std::move(enc_storage), offset + meta_offset, upper_iv, AlignmentStorageRequirement_None));
/* Create meta storage. */ /* Create meta storage. */
auto meta_storage = fssystem::AllocateShared<save::BufferedStorage>(); auto meta_storage = fssystem::AllocateShared<BufferedStorage>();
R_UNLESS(meta_storage != nullptr, fs::ResultAllocationFailureInAllocateShared()); R_UNLESS(meta_storage != nullptr, fs::ResultAllocationFailureInAllocateShared());
/* Initialize the meta storage. */ /* Initialize the meta storage. */
@ -921,7 +921,7 @@ namespace ams::fssystem {
R_UNLESS(patch_info.indirect_offset + patch_info.indirect_size <= base_size, fs::ResultNcaBaseStorageOutOfRangeE()); R_UNLESS(patch_info.indirect_offset + patch_info.indirect_size <= base_size, fs::ResultNcaBaseStorageOutOfRangeE());
/* Allocate the meta storage. */ /* Allocate the meta storage. */
auto meta_storage = fssystem::AllocateShared<save::BufferedStorage>(); auto meta_storage = fssystem::AllocateShared<BufferedStorage>();
R_UNLESS(meta_storage != nullptr, fs::ResultAllocationFailureInAllocateShared()); R_UNLESS(meta_storage != nullptr, fs::ResultAllocationFailureInAllocateShared());
/* Initialize the meta storage. */ /* Initialize the meta storage. */
@ -954,7 +954,7 @@ namespace ams::fssystem {
AMS_ASSERT(util::IsAligned(indirect_data_size, NcaHeader::XtsBlockSize)); AMS_ASSERT(util::IsAligned(indirect_data_size, NcaHeader::XtsBlockSize));
/* Create the indirect data storage. */ /* Create the indirect data storage. */
auto indirect_data_storage = fssystem::AllocateShared<save::BufferedStorage>(); auto indirect_data_storage = fssystem::AllocateShared<BufferedStorage>();
R_UNLESS(indirect_data_storage != nullptr, fs::ResultAllocationFailureInAllocateShared()); R_UNLESS(indirect_data_storage != nullptr, fs::ResultAllocationFailureInAllocateShared());
/* Initialize the indirect data storage. */ /* Initialize the indirect data storage. */
@ -1061,15 +1061,15 @@ namespace ams::fssystem {
AMS_ASSERT(base_storage != nullptr); AMS_ASSERT(base_storage != nullptr);
/* Define storage types. */ /* Define storage types. */
using VerificationStorage = save::HierarchicalIntegrityVerificationStorage; using VerificationStorage = HierarchicalIntegrityVerificationStorage;
using StorageInfo = VerificationStorage::HierarchicalStorageInformation; using StorageInfo = VerificationStorage::HierarchicalStorageInformation;
/* Validate the meta info. */ /* Validate the meta info. */
save::HierarchicalIntegrityVerificationInformation level_hash_info; HierarchicalIntegrityVerificationInformation level_hash_info;
std::memcpy(std::addressof(level_hash_info), std::addressof(meta_info.level_hash_info), sizeof(level_hash_info)); std::memcpy(std::addressof(level_hash_info), std::addressof(meta_info.level_hash_info), sizeof(level_hash_info));
R_UNLESS(save::IntegrityMinLayerCount <= level_hash_info.max_layers, fs::ResultInvalidHierarchicalIntegrityVerificationLayerCount()); R_UNLESS(IntegrityMinLayerCount <= level_hash_info.max_layers, fs::ResultInvalidHierarchicalIntegrityVerificationLayerCount());
R_UNLESS(level_hash_info.max_layers <= save::IntegrityMaxLayerCount, fs::ResultInvalidHierarchicalIntegrityVerificationLayerCount()); R_UNLESS(level_hash_info.max_layers <= IntegrityMaxLayerCount, fs::ResultInvalidHierarchicalIntegrityVerificationLayerCount());
/* Get the base storage size. */ /* Get the base storage size. */
s64 base_storage_size; s64 base_storage_size;