strat: use m_ for member variables

This commit is contained in:
Michael Scire
2021-10-10 00:14:06 -07:00
parent ce28591ab2
commit a595c232b9
425 changed files with 8531 additions and 8484 deletions

View File

@@ -18,7 +18,7 @@
namespace ams::fssystem::save {
BlockCacheBufferedStorage::BlockCacheBufferedStorage()
: buffer_manager(), mutex(), entries(), data_storage(), last_result(ResultSuccess()), data_size(), verification_block_size(), verification_block_shift(), invalidate_index(), max_cache_entry_count(), flags(), buffer_level(-1)
: m_buffer_manager(), m_mutex(), m_entries(), m_data_storage(), m_last_result(ResultSuccess()), m_data_size(), m_verification_block_size(), m_verification_block_shift(), m_invalidate_index(), m_max_cache_entry_count(), m_flags(), m_buffer_level(-1)
{
/* ... */
}
@@ -32,35 +32,35 @@ namespace ams::fssystem::save {
AMS_ASSERT(data != nullptr);
AMS_ASSERT(bm != nullptr);
AMS_ASSERT(mtx != nullptr);
AMS_ASSERT(this->buffer_manager == nullptr);
AMS_ASSERT(this->mutex == nullptr);
AMS_ASSERT(this->data_storage == nullptr);
AMS_ASSERT(this->entries == nullptr);
AMS_ASSERT(m_buffer_manager == nullptr);
AMS_ASSERT(m_mutex == nullptr);
AMS_ASSERT(m_data_storage == nullptr);
AMS_ASSERT(m_entries == nullptr);
AMS_ASSERT(max_cache_entries > 0);
/* Create the entry. */
this->entries = fs::impl::MakeUnique<CacheEntry[]>(static_cast<size_t>(max_cache_entries));
R_UNLESS(this->entries != nullptr, fs::ResultAllocationFailureInBlockCacheBufferedStorageA());
m_entries = fs::impl::MakeUnique<CacheEntry[]>(static_cast<size_t>(max_cache_entries));
R_UNLESS(m_entries != nullptr, fs::ResultAllocationFailureInBlockCacheBufferedStorageA());
/* Set members. */
this->buffer_manager = bm;
this->mutex = mtx;
this->data_storage = data;
this->data_size = data_size;
this->verification_block_size = verif_block_size;
this->last_result = ResultSuccess();
this->invalidate_index = 0;
this->max_cache_entry_count = max_cache_entries;
this->flags = 0;
this->buffer_level = buffer_level;
this->storage_type = storage_type;
m_buffer_manager = bm;
m_mutex = mtx;
m_data_storage = data;
m_data_size = data_size;
m_verification_block_size = verif_block_size;
m_last_result = ResultSuccess();
m_invalidate_index = 0;
m_max_cache_entry_count = max_cache_entries;
m_flags = 0;
m_buffer_level = buffer_level;
m_storage_type = storage_type;
/* Calculate block shift. */
this->verification_block_shift = ILog2(static_cast<u32>(verif_block_size));
AMS_ASSERT(static_cast<size_t>(1ull << this->verification_block_size) == this->verification_block_size);
m_verification_block_shift = ILog2(static_cast<u32>(verif_block_size));
AMS_ASSERT(static_cast<size_t>(1ull << m_verification_block_size) == m_verification_block_size);
/* Clear the entry. */
std::memset(this->entries.get(), 0, sizeof(CacheEntry) * this->max_cache_entry_count);
std::memset(m_entries.get(), 0, sizeof(CacheEntry) * m_max_cache_entry_count);
/* Set burst mode. */
this->SetKeepBurstMode(is_keep_burst_mode);
@@ -72,31 +72,31 @@ namespace ams::fssystem::save {
}
void BlockCacheBufferedStorage::Finalize() {
if (this->entries != nullptr) {
if (m_entries != nullptr) {
/* Invalidate all cache entries. */
this->InvalidateAllCacheEntries();
/* Clear members. */
this->buffer_manager = nullptr;
this->mutex = nullptr;
this->data_storage = nullptr;
this->data_size = 0;
this->verification_block_size = 0;
this->verification_block_shift = 0;
this->invalidate_index = 0;
this->max_cache_entry_count = 0;
m_buffer_manager = nullptr;
m_mutex = nullptr;
m_data_storage = nullptr;
m_data_size = 0;
m_verification_block_size = 0;
m_verification_block_shift = 0;
m_invalidate_index = 0;
m_max_cache_entry_count = 0;
this->entries.reset();
m_entries.reset();
}
}
Result BlockCacheBufferedStorage::Read(s64 offset, void *buffer, size_t size) {
/* Validate pre-conditions. */
AMS_ASSERT(this->data_storage != nullptr);
AMS_ASSERT(this->buffer_manager != nullptr);
AMS_ASSERT(m_data_storage != nullptr);
AMS_ASSERT(m_buffer_manager != nullptr);
/* Ensure we aren't already in a failed state. */
R_TRY(this->last_result);
R_TRY(m_last_result);
/* Succeed if zero-size. */
R_SUCCEED_IF(size == 0);
@@ -108,18 +108,18 @@ namespace ams::fssystem::save {
s64 read_offset = offset;
size_t read_size = size;
R_UNLESS(read_offset < this->data_size, fs::ResultInvalidOffset());
R_UNLESS(read_offset < m_data_size, fs::ResultInvalidOffset());
if (static_cast<s64>(read_offset + read_size) > this->data_size) {
read_size = static_cast<size_t>(this->data_size - read_offset);
if (static_cast<s64>(read_offset + read_size) > m_data_size) {
read_size = static_cast<size_t>(m_data_size - read_offset);
}
/* Determine the aligned range to read. */
const size_t block_alignment = this->verification_block_size;
const size_t block_alignment = m_verification_block_size;
s64 aligned_offset = util::AlignDown(read_offset, block_alignment);
s64 aligned_offset_end = util::AlignUp(read_offset + read_size, block_alignment);
AMS_ASSERT(0 <= aligned_offset && aligned_offset_end <= static_cast<s64>(util::AlignUp(this->data_size, block_alignment)));
AMS_ASSERT(0 <= aligned_offset && aligned_offset_end <= static_cast<s64>(util::AlignUp(m_data_size, block_alignment)));
/* Try to read using cache. */
char *dst = static_cast<char *>(buffer);
@@ -183,7 +183,7 @@ namespace ams::fssystem::save {
R_TRY(this->UpdateLastResult(this->FlushRangeCacheEntries(read_offset, aligned_size, false)));
/* Read the data. */
R_TRY(this->UpdateLastResult(this->data_storage->Read(read_offset, dst, aligned_size)));
R_TRY(this->UpdateLastResult(m_data_storage->Read(read_offset, dst, aligned_size)));
/* Advance. */
dst += aligned_size;
@@ -202,7 +202,7 @@ namespace ams::fssystem::save {
/* If the entry isn't cached, read the data. */
if (!entry.is_cached) {
if (Result result = this->data_storage->Read(entry.offset, src, entry.size); R_FAILED(result)) {
if (Result result = m_data_storage->Read(entry.offset, src, entry.size); R_FAILED(result)) {
this->DestroyBuffer(std::addressof(entry), range);
return this->UpdateLastResult(result);
}
@@ -243,11 +243,11 @@ namespace ams::fssystem::save {
Result BlockCacheBufferedStorage::Write(s64 offset, const void *buffer, size_t size) {
/* Validate pre-conditions. */
AMS_ASSERT(this->data_storage != nullptr);
AMS_ASSERT(this->buffer_manager != nullptr);
AMS_ASSERT(m_data_storage != nullptr);
AMS_ASSERT(m_buffer_manager != nullptr);
/* Ensure we aren't already in a failed state. */
R_TRY(this->last_result);
R_TRY(m_last_result);
/* Succeed if zero-size. */
R_SUCCEED_IF(size == 0);
@@ -256,21 +256,21 @@ namespace ams::fssystem::save {
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
/* Determine the extents to read. */
R_UNLESS(offset < this->data_size, fs::ResultInvalidOffset());
R_UNLESS(offset < m_data_size, fs::ResultInvalidOffset());
if (static_cast<s64>(offset + size) > this->data_size) {
size = static_cast<size_t>(this->data_size - offset);
if (static_cast<s64>(offset + size) > m_data_size) {
size = static_cast<size_t>(m_data_size - offset);
}
/* The actual extents may be zero-size, so succeed if that's the case. */
R_SUCCEED_IF(size == 0);
/* Determine the aligned range to read. */
const size_t block_alignment = this->verification_block_size;
const size_t block_alignment = m_verification_block_size;
s64 aligned_offset = util::AlignDown(offset, block_alignment);
const s64 aligned_offset_end = util::AlignUp(offset + size, block_alignment);
AMS_ASSERT(0 <= aligned_offset && aligned_offset_end <= static_cast<s64>(util::AlignUp(this->data_size, block_alignment)));
AMS_ASSERT(0 <= aligned_offset && aligned_offset_end <= static_cast<s64>(util::AlignUp(m_data_size, block_alignment)));
/* Write the data. */
const u8 *src = static_cast<const u8 *>(buffer);
@@ -283,7 +283,7 @@ namespace ams::fssystem::save {
R_TRY(this->UpdateLastResult(this->FlushRangeCacheEntries(offset, aligned_size, true)));
/* Read the data. */
R_TRY(this->UpdateLastResult(this->data_storage->Write(offset, src, aligned_size)));
R_TRY(this->UpdateLastResult(m_data_storage->Write(offset, src, aligned_size)));
/* Set blocking buffer manager allocations. */
buffers::EnableBlockingBufferManagerAllocation();
@@ -304,7 +304,7 @@ namespace ams::fssystem::save {
/* If the entry isn't cached and we're writing a partial entry, read in the entry. */
if (!entry.is_cached && ((offset != entry.offset) || (offset + size < entry.offset + entry.size))) {
if (Result result = this->data_storage->Read(entry.offset, dst, entry.size); R_FAILED(result)) {
if (Result result = m_data_storage->Read(entry.offset, dst, entry.size); R_FAILED(result)) {
this->DestroyBuffer(std::addressof(entry), range);
return this->UpdateLastResult(result);
}
@@ -349,7 +349,7 @@ namespace ams::fssystem::save {
}
/* Ensure that didn't end up in a failure state. */
R_TRY(this->last_result);
R_TRY(m_last_result);
return ResultSuccess();
}
@@ -357,26 +357,26 @@ namespace ams::fssystem::save {
Result BlockCacheBufferedStorage::GetSize(s64 *out) {
/* Validate pre-conditions. */
AMS_ASSERT(out != nullptr);
AMS_ASSERT(this->data_storage != nullptr);
AMS_ASSERT(m_data_storage != nullptr);
/* Set the size. */
*out = this->data_size;
*out = m_data_size;
return ResultSuccess();
}
Result BlockCacheBufferedStorage::Flush() {
/* Validate pre-conditions. */
AMS_ASSERT(this->data_storage != nullptr);
AMS_ASSERT(this->buffer_manager != nullptr);
AMS_ASSERT(m_data_storage != nullptr);
AMS_ASSERT(m_buffer_manager != nullptr);
/* Ensure we aren't already in a failed state. */
R_TRY(this->last_result);
R_TRY(m_last_result);
/* Flush all cache entries. */
R_TRY(this->UpdateLastResult(this->FlushAllCacheEntries()));
/* Flush the data storage. */
R_TRY(this->UpdateLastResult(this->data_storage->Flush()));
R_TRY(this->UpdateLastResult(m_data_storage->Flush()));
/* Set blocking buffer manager allocations. */
buffers::EnableBlockingBufferManagerAllocation();
@@ -388,7 +388,7 @@ namespace ams::fssystem::save {
AMS_UNUSED(src, src_size);
/* Validate pre-conditions. */
AMS_ASSERT(this->data_storage != nullptr);
AMS_ASSERT(m_data_storage != nullptr);
switch (op_id) {
case fs::OperationId::FillZero:
@@ -403,7 +403,7 @@ namespace ams::fssystem::save {
}
case fs::OperationId::Invalidate:
{
R_UNLESS(this->storage_type != fs::StorageType_SaveData, fs::ResultUnsupportedOperationInBlockCacheBufferedStorageB());
R_UNLESS(m_storage_type != fs::StorageType_SaveData, fs::ResultUnsupportedOperationInBlockCacheBufferedStorageB());
R_TRY(this->InvalidateCacheImpl(offset, size));
return ResultSuccess();
}
@@ -419,11 +419,11 @@ namespace ams::fssystem::save {
Result BlockCacheBufferedStorage::Commit() {
/* Validate pre-conditions. */
AMS_ASSERT(this->data_storage != nullptr);
AMS_ASSERT(this->buffer_manager != nullptr);
AMS_ASSERT(m_data_storage != nullptr);
AMS_ASSERT(m_buffer_manager != nullptr);
/* Ensure we aren't already in a failed state. */
R_TRY(this->last_result);
R_TRY(m_last_result);
/* Flush all cache entries. */
R_TRY(this->UpdateLastResult(this->FlushAllCacheEntries()));
@@ -433,38 +433,38 @@ namespace ams::fssystem::save {
Result BlockCacheBufferedStorage::OnRollback() {
/* Validate pre-conditions. */
AMS_ASSERT(this->buffer_manager != nullptr);
AMS_ASSERT(m_buffer_manager != nullptr);
/* Ensure we aren't already in a failed state. */
R_TRY(this->last_result);
R_TRY(m_last_result);
/* Release all valid entries back to the buffer manager. */
const auto max_cache_entry_count = this->GetMaxCacheEntryCount();
for (s32 i = 0; i < max_cache_entry_count; i++) {
const auto &entry = this->entries[i];
const auto &entry = m_entries[i];
if (entry.is_valid) {
if (entry.is_write_back) {
AMS_ASSERT(entry.memory_address != 0 && entry.handle == 0);
this->buffer_manager->DeallocateBuffer(entry.memory_address, entry.memory_size);
m_buffer_manager->DeallocateBuffer(entry.memory_address, entry.memory_size);
} else {
AMS_ASSERT(entry.memory_address == 0 && entry.handle != 0);
const auto memory_range = this->buffer_manager->AcquireCache(entry.handle);
const auto memory_range = m_buffer_manager->AcquireCache(entry.handle);
if (memory_range.first != 0) {
this->buffer_manager->DeallocateBuffer(memory_range.first, memory_range.second);
m_buffer_manager->DeallocateBuffer(memory_range.first, memory_range.second);
}
}
}
}
/* Clear all entries. */
std::memset(this->entries.get(), 0, sizeof(CacheEntry) * max_cache_entry_count);
std::memset(m_entries.get(), 0, sizeof(CacheEntry) * max_cache_entry_count);
return ResultSuccess();
}
Result BlockCacheBufferedStorage::ClearImpl(s64 offset, s64 size) {
/* Ensure we aren't already in a failed state. */
R_TRY(this->last_result);
R_TRY(m_last_result);
/* Get our storage size. */
s64 storage_size = 0;
@@ -474,8 +474,8 @@ namespace ams::fssystem::save {
R_UNLESS(0 <= offset && offset < storage_size, fs::ResultInvalidOffset());
/* Determine the extents to data signature for. */
auto start_offset = util::AlignDown(offset, this->verification_block_size);
auto end_offset = util::AlignUp(std::min(offset + size, storage_size), this->verification_block_size);
auto start_offset = util::AlignDown(offset, m_verification_block_size);
auto end_offset = util::AlignUp(std::min(offset + size, storage_size), m_verification_block_size);
/* Flush the entries. */
R_TRY(this->UpdateLastResult(this->FlushRangeCacheEntries(offset, size, true)));
@@ -483,26 +483,26 @@ namespace ams::fssystem::save {
/* Handle any data before or after the aligned range. */
if (start_offset < offset || offset + size < end_offset) {
/* Allocate a work buffer. */
std::unique_ptr<char[], fs::impl::Deleter> work = fs::impl::MakeUnique<char[]>(this->verification_block_size);
std::unique_ptr<char[], fs::impl::Deleter> work = fs::impl::MakeUnique<char[]>(m_verification_block_size);
R_UNLESS(work != nullptr, fs::ResultAllocationFailureInBlockCacheBufferedStorageB());
/* Handle data before the aligned range. */
if (start_offset < offset) {
/* Read the block. */
R_TRY(this->UpdateLastResult(this->data_storage->Read(start_offset, work.get(), this->verification_block_size)));
R_TRY(this->UpdateLastResult(m_data_storage->Read(start_offset, work.get(), m_verification_block_size)));
/* Determine the partial extents to clear. */
const auto clear_offset = static_cast<size_t>(offset - start_offset);
const auto clear_size = static_cast<size_t>(std::min(static_cast<s64>(this->verification_block_size - clear_offset), size));
const auto clear_size = static_cast<size_t>(std::min(static_cast<s64>(m_verification_block_size - clear_offset), size));
/* Clear the partial block. */
std::memset(work.get() + clear_offset, 0, clear_size);
/* Write the partially cleared block. */
R_TRY(this->UpdateLastResult(this->data_storage->Write(start_offset, work.get(), this->verification_block_size)));
R_TRY(this->UpdateLastResult(m_data_storage->Write(start_offset, work.get(), m_verification_block_size)));
/* Update the start offset. */
start_offset += this->verification_block_size;
start_offset += m_verification_block_size;
/* Set blocking buffer manager allocations. */
buffers::EnableBlockingBufferManagerAllocation();
@@ -511,18 +511,18 @@ namespace ams::fssystem::save {
/* Handle data after the aligned range. */
if (start_offset < offset + size && offset + size < end_offset) {
/* Read the block. */
const auto last_offset = end_offset - this->verification_block_size;
R_TRY(this->UpdateLastResult(this->data_storage->Read(last_offset, work.get(), this->verification_block_size)));
const auto last_offset = end_offset - m_verification_block_size;
R_TRY(this->UpdateLastResult(m_data_storage->Read(last_offset, work.get(), m_verification_block_size)));
/* Clear the partial block. */
const auto clear_size = static_cast<size_t>((offset + size) - last_offset);
std::memset(work.get(), 0, clear_size);
/* Write the partially cleared block. */
R_TRY(this->UpdateLastResult(this->data_storage->Write(last_offset, work.get(), this->verification_block_size)));
R_TRY(this->UpdateLastResult(m_data_storage->Write(last_offset, work.get(), m_verification_block_size)));
/* Update the end offset. */
end_offset -= this->verification_block_size;
end_offset -= m_verification_block_size;
/* Set blocking buffer manager allocations. */
buffers::EnableBlockingBufferManagerAllocation();
@@ -533,7 +533,7 @@ namespace ams::fssystem::save {
R_SUCCEED_IF(start_offset == end_offset);
/* Clear the signature for the aligned range. */
R_TRY(this->UpdateLastResult(this->data_storage->OperateRange(fs::OperationId::FillZero, start_offset, end_offset - start_offset)));
R_TRY(this->UpdateLastResult(m_data_storage->OperateRange(fs::OperationId::FillZero, start_offset, end_offset - start_offset)));
/* Set blocking buffer manager allocations. */
buffers::EnableBlockingBufferManagerAllocation();
@@ -543,7 +543,7 @@ namespace ams::fssystem::save {
Result BlockCacheBufferedStorage::ClearSignatureImpl(s64 offset, s64 size) {
/* Ensure we aren't already in a failed state. */
R_TRY(this->last_result);
R_TRY(m_last_result);
/* Get our storage size. */
s64 storage_size = 0;
@@ -553,14 +553,14 @@ namespace ams::fssystem::save {
R_UNLESS(0 <= offset && offset < storage_size, fs::ResultInvalidOffset());
/* Determine the extents to clear signature for. */
const auto start_offset = util::AlignUp(offset, this->verification_block_size);
const auto end_offset = util::AlignDown(std::min(offset + size, storage_size), this->verification_block_size);
const auto start_offset = util::AlignUp(offset, m_verification_block_size);
const auto end_offset = util::AlignDown(std::min(offset + size, storage_size), m_verification_block_size);
/* Flush the entries. */
R_TRY(this->UpdateLastResult(this->FlushRangeCacheEntries(offset, size, true)));
/* Clear the signature for the aligned range. */
R_TRY(this->UpdateLastResult(this->data_storage->OperateRange(fs::OperationId::DestroySignature, start_offset, end_offset - start_offset)));
R_TRY(this->UpdateLastResult(m_data_storage->OperateRange(fs::OperationId::DestroySignature, start_offset, end_offset - start_offset)));
/* Set blocking buffer manager allocations. */
buffers::EnableBlockingBufferManagerAllocation();
@@ -579,20 +579,20 @@ namespace ams::fssystem::save {
/* Determine the extents we can actually query. */
const auto actual_size = std::min(size, storage_size - offset);
const auto aligned_offset = util::AlignDown(offset, this->verification_block_size);
const auto aligned_offset_end = util::AlignUp(offset + actual_size, this->verification_block_size);
const auto aligned_offset = util::AlignDown(offset, m_verification_block_size);
const auto aligned_offset_end = util::AlignUp(offset + actual_size, m_verification_block_size);
const auto aligned_size = aligned_offset_end - aligned_offset;
/* Invalidate the aligned range. */
{
Result result = this->data_storage->OperateRange(fs::OperationId::Invalidate, aligned_offset, aligned_size);
Result result = m_data_storage->OperateRange(fs::OperationId::Invalidate, aligned_offset, aligned_size);
AMS_ASSERT(!fs::ResultBufferAllocationFailed::Includes(result));
R_TRY(result);
}
/* Clear our last result if we should. */
if (fs::ResultIntegrityVerificationStorageCorrupted::Includes(this->last_result)) {
this->last_result = ResultSuccess();
if (fs::ResultIntegrityVerificationStorageCorrupted::Includes(m_last_result)) {
m_last_result = ResultSuccess();
}
return ResultSuccess();
@@ -605,12 +605,12 @@ namespace ams::fssystem::save {
/* Determine the extents we can actually query. */
const auto actual_size = std::min(size, storage_size - offset);
const auto aligned_offset = util::AlignDown(offset, this->verification_block_size);
const auto aligned_offset_end = util::AlignUp(offset + actual_size, this->verification_block_size);
const auto aligned_offset = util::AlignDown(offset, m_verification_block_size);
const auto aligned_offset_end = util::AlignUp(offset + actual_size, m_verification_block_size);
const auto aligned_size = aligned_offset_end - aligned_offset;
/* Query the aligned range. */
R_TRY(this->UpdateLastResult(this->data_storage->OperateRange(dst, dst_size, fs::OperationId::QueryRange, aligned_offset, aligned_size, nullptr, 0)));
R_TRY(this->UpdateLastResult(m_data_storage->OperateRange(dst, dst_size, fs::OperationId::QueryRange, aligned_offset, aligned_size, nullptr, 0)));
return ResultSuccess();
}
@@ -621,12 +621,12 @@ namespace ams::fssystem::save {
const size_t size = entry.size;
/* Lock our mutex. */
std::scoped_lock lk(*this->mutex);
std::scoped_lock lk(*m_mutex);
/* Iterate over all entries, checking if any overlap our extents. */
const auto max_cache_entry_count = this->GetMaxCacheEntryCount();
for (auto i = 0; i < max_cache_entry_count; ++i) {
const auto &entry = this->entries[i];
const auto &entry = m_entries[i];
if (entry.is_valid && (entry.is_write_back ? entry.memory_address != 0 : entry.handle != 0)) {
if (entry.offset < static_cast<s64>(offset + size) && offset < static_cast<s64>(entry.offset + entry.size)) {
return true;
@@ -641,13 +641,13 @@ namespace ams::fssystem::save {
AMS_UNUSED(is_allocate_for_write);
/* Validate pre-conditions. */
AMS_ASSERT(this->data_storage != nullptr);
AMS_ASSERT(this->buffer_manager != nullptr);
AMS_ASSERT(m_data_storage != nullptr);
AMS_ASSERT(m_buffer_manager != nullptr);
AMS_ASSERT(out_range != nullptr);
AMS_ASSERT(out_entry != nullptr);
/* Lock our mutex. */
std::scoped_lock lk(*this->mutex);
std::scoped_lock lk(*m_mutex);
/* Get the maximum cache entry count. */
const CacheIndex max_cache_entry_count = static_cast<CacheIndex>(this->GetMaxCacheEntryCount());
@@ -656,7 +656,7 @@ namespace ams::fssystem::save {
CacheIndex index;
size_t actual_size = ideal_size;
for (index = 0; index < max_cache_entry_count; ++index) {
const auto &entry = this->entries[index];
const auto &entry = m_entries[index];
if (entry.is_valid && (entry.is_write_back ? entry.memory_address != 0 : entry.handle != 0)) {
const s64 entry_offset = entry.offset;
if (entry_offset <= offset && offset < static_cast<s64>(entry_offset + entry.size)) {
@@ -675,13 +675,13 @@ namespace ams::fssystem::save {
/* If we located an entry, use it. */
if (index != max_cache_entry_count) {
auto &entry = this->entries[index];
auto &entry = m_entries[index];
/* Get the range of the found entry. */
if (entry.is_write_back) {
*out_range = std::make_pair(entry.memory_address, entry.memory_size);
} else {
*out_range = this->buffer_manager->AcquireCache(entry.handle);
*out_range = m_buffer_manager->AcquireCache(entry.handle);
}
/* Get the found entry. */
@@ -705,13 +705,13 @@ namespace ams::fssystem::save {
/* If we don't have an out entry, allocate one. */
if (out_range->first == 0) {
/* Ensure that the allocatable size is above a threshold. */
const auto size_threshold = this->buffer_manager->GetTotalSize() / 8;
if (this->buffer_manager->GetTotalAllocatableSize() < size_threshold) {
const auto size_threshold = m_buffer_manager->GetTotalSize() / 8;
if (m_buffer_manager->GetTotalAllocatableSize() < size_threshold) {
R_TRY(this->FlushAllCacheEntries());
}
/* Decide in advance on a block alignment. */
const size_t block_alignment = this->verification_block_size;
const size_t block_alignment = m_verification_block_size;
/* Ensure that the size we request is valid. */
{
@@ -721,7 +721,7 @@ namespace ams::fssystem::save {
AMS_ASSERT(actual_size >= block_alignment);
/* Allocate a buffer. */
R_TRY(buffers::AllocateBufferUsingBufferManagerContext(out_range, this->buffer_manager, actual_size, IBufferManager::BufferAttribute(this->buffer_level), [=](const MemoryRange &buffer) {
R_TRY(buffers::AllocateBufferUsingBufferManagerContext(out_range, m_buffer_manager, actual_size, IBufferManager::BufferAttribute(m_buffer_level), [=](const MemoryRange &buffer) {
return buffer.first != 0 && block_alignment <= buffer.second;
}, AMS_CURRENT_FUNCTION_NAME));
@@ -748,7 +748,7 @@ namespace ams::fssystem::save {
void BlockCacheBufferedStorage::DestroyBuffer(CacheEntry *entry, const MemoryRange &range) {
/* Validate pre-conditions. */
AMS_ASSERT(this->buffer_manager != nullptr);
AMS_ASSERT(m_buffer_manager != nullptr);
AMS_ASSERT(entry != nullptr);
/* Set the entry as invalid and not cached. */
@@ -756,7 +756,7 @@ namespace ams::fssystem::save {
entry->is_valid = false;
/* Release the entry. */
this->buffer_manager->DeallocateBuffer(range.first, range.second);
m_buffer_manager->DeallocateBuffer(range.first, range.second);
}
Result BlockCacheBufferedStorage::StoreAssociateBuffer(CacheIndex *out, const MemoryRange &range, const CacheEntry &entry) {
@@ -764,7 +764,7 @@ namespace ams::fssystem::save {
AMS_ASSERT(out != nullptr);
/* Lock our mutex. */
std::scoped_lock lk(*this->mutex);
std::scoped_lock lk(*m_mutex);
/* If the entry is write-back, ensure we don't exceed certain dirtiness thresholds. */
if (entry.is_write_back) {
@@ -778,7 +778,7 @@ namespace ams::fssystem::save {
/* Locate the index of an unused cache entry. */
CacheIndex index;
for (index = 0; index < max_cache_entry_count; ++index) {
if (!this->entries[index].is_valid) {
if (!m_entries[index].is_valid) {
break;
}
}
@@ -786,10 +786,10 @@ namespace ams::fssystem::save {
/* If all entries are valid, we need to invalidate one. */
if (index == max_cache_entry_count) {
/* Increment the index to invalidate. */
this->invalidate_index = (this->invalidate_index + 1) % max_cache_entry_count;
m_invalidate_index = (m_invalidate_index + 1) % max_cache_entry_count;
/* Get the entry to invalidate. */
const CacheEntry *entry_to_invalidate = std::addressof(this->entries[this->invalidate_index]);
const CacheEntry *entry_to_invalidate = std::addressof(m_entries[m_invalidate_index]);
AMS_UNUSED(entry_to_invalidate);
/* Ensure that the entry can be invalidated. */
@@ -797,17 +797,17 @@ namespace ams::fssystem::save {
AMS_ASSERT(!entry_to_invalidate->is_flushing);
/* Invalidate the entry. */
R_TRY(this->FlushCacheEntry(this->invalidate_index, true));
R_TRY(this->FlushCacheEntry(m_invalidate_index, true));
/* Check that the entry was invalidated successfully. */
AMS_ASSERT(!entry_to_invalidate->is_valid);
AMS_ASSERT(!entry_to_invalidate->is_flushing);
index = this->invalidate_index;
index = m_invalidate_index;
}
/* Store the entry. */
CacheEntry *entry_ptr = std::addressof(this->entries[index]);
CacheEntry *entry_ptr = std::addressof(m_entries[index]);
*entry_ptr = entry;
/* Assert that the entry is valid to store. */
@@ -824,7 +824,7 @@ namespace ams::fssystem::save {
entry_ptr->memory_address = range.first;
entry_ptr->memory_size = range.second;
} else {
entry_ptr->handle = this->buffer_manager->RegisterCache(range.first, range.second, IBufferManager::BufferAttribute(this->buffer_level));
entry_ptr->handle = m_buffer_manager->RegisterCache(range.first, range.second, IBufferManager::BufferAttribute(m_buffer_level));
entry_ptr->memory_address = 0;
entry_ptr->memory_size = 0;
}
@@ -832,10 +832,10 @@ namespace ams::fssystem::save {
/* Set the out index. */
AMS_ASSERT(entry_ptr->is_valid);
*out = index;
this->invalidate_index = index;
m_invalidate_index = index;
} else {
/* If a redundant entry exists, we don't need the newly stored entry. */
this->buffer_manager->DeallocateBuffer(range.first, range.second);
m_buffer_manager->DeallocateBuffer(range.first, range.second);
entry_ptr->is_valid = false;
*out = -1;
}
@@ -845,10 +845,10 @@ namespace ams::fssystem::save {
Result BlockCacheBufferedStorage::FlushCacheEntry(CacheIndex index, bool invalidate) {
/* Lock our mutex. */
std::scoped_lock lk(*this->mutex);
std::scoped_lock lk(*m_mutex);
/* Get the entry. */
CacheEntry *entry = std::addressof(this->entries[index]);
CacheEntry *entry = std::addressof(m_entries[index]);
MemoryRange memory_range;
/* Check that the entry's state allows for flush. */
@@ -860,9 +860,9 @@ namespace ams::fssystem::save {
AMS_ASSERT(invalidate);
/* Get and release the buffer. */
memory_range = this->buffer_manager->AcquireCache(entry->handle);
memory_range = m_buffer_manager->AcquireCache(entry->handle);
if (memory_range.first != 0) {
this->buffer_manager->DeallocateBuffer(memory_range.first, memory_range.second);
m_buffer_manager->DeallocateBuffer(memory_range.first, memory_range.second);
}
/* The entry is no longer valid. */
@@ -881,20 +881,20 @@ namespace ams::fssystem::save {
/* Validate the entry's offset. */
AMS_ASSERT(entry->offset >= 0);
AMS_ASSERT(entry->offset < this->data_size);
AMS_ASSERT(util::IsAligned(entry->offset, this->verification_block_size));
AMS_ASSERT(entry->offset < m_data_size);
AMS_ASSERT(util::IsAligned(entry->offset, m_verification_block_size));
/* Write back the data. */
Result result = ResultSuccess();
size_t write_size = entry->size;
if (R_SUCCEEDED(this->last_result)) {
if (R_SUCCEEDED(m_last_result)) {
/* Set blocking buffer manager allocations. */
result = this->data_storage->Write(entry->offset, reinterpret_cast<const void *>(memory_range.first), write_size);
result = m_data_storage->Write(entry->offset, reinterpret_cast<const void *>(memory_range.first), write_size);
/* Check the result. */
AMS_ASSERT(!fs::ResultBufferAllocationFailed::Includes(result));
} else {
result = this->last_result;
result = m_last_result;
}
/* Set that we're not write-back. */
@@ -902,13 +902,13 @@ namespace ams::fssystem::save {
/* If we're invalidating, release the buffer. Otherwise, register the flushed data. */
if (invalidate) {
this->buffer_manager->DeallocateBuffer(memory_range.first, memory_range.second);
m_buffer_manager->DeallocateBuffer(memory_range.first, memory_range.second);
entry->is_valid = false;
entry->is_flushing = false;
} else {
AMS_ASSERT(entry->is_valid);
entry->handle = this->buffer_manager->RegisterCache(memory_range.first, memory_range.second, IBufferManager::BufferAttribute(this->buffer_level));
entry->handle = m_buffer_manager->RegisterCache(memory_range.first, memory_range.second, IBufferManager::BufferAttribute(m_buffer_level));
entry->memory_address = 0;
entry->memory_size = 0;
@@ -924,14 +924,14 @@ namespace ams::fssystem::save {
Result BlockCacheBufferedStorage::FlushRangeCacheEntries(s64 offset, s64 size, bool invalidate) {
/* Validate pre-conditions. */
AMS_ASSERT(this->data_storage != nullptr);
AMS_ASSERT(this->buffer_manager != nullptr);
AMS_ASSERT(m_data_storage != nullptr);
AMS_ASSERT(m_buffer_manager != nullptr);
/* Iterate over all entries that fall within the range. */
Result result = ResultSuccess();
const auto max_cache_entry_count = this->GetMaxCacheEntryCount();
for (auto i = 0; i < max_cache_entry_count; ++i) {
auto &entry = this->entries[i];
auto &entry = m_entries[i];
if (entry.is_valid && (entry.is_write_back || invalidate) && (entry.offset < (offset + size)) && (offset < static_cast<s64>(entry.offset + entry.size))) {
const auto cur_result = this->FlushCacheEntry(i, invalidate);
if (R_FAILED(cur_result) && R_SUCCEEDED(result)) {
@@ -949,22 +949,22 @@ namespace ams::fssystem::save {
void BlockCacheBufferedStorage::InvalidateRangeCacheEntries(s64 offset, s64 size) {
/* Validate pre-conditions. */
AMS_ASSERT(this->data_storage != nullptr);
AMS_ASSERT(this->buffer_manager != nullptr);
AMS_ASSERT(m_data_storage != nullptr);
AMS_ASSERT(m_buffer_manager != nullptr);
/* Iterate over all entries that fall within the range. */
const auto max_cache_entry_count = this->GetMaxCacheEntryCount();
for (auto i = 0; i < max_cache_entry_count; ++i) {
auto &entry = this->entries[i];
auto &entry = m_entries[i];
if (entry.is_valid && (entry.offset < (offset + size)) && (offset < static_cast<s64>(entry.offset + entry.size))) {
if (entry.is_write_back) {
AMS_ASSERT(entry.memory_address != 0 && entry.handle == 0);
this->buffer_manager->DeallocateBuffer(entry.memory_address, entry.memory_size);
m_buffer_manager->DeallocateBuffer(entry.memory_address, entry.memory_size);
} else {
AMS_ASSERT(entry.memory_address == 0 && entry.handle != 0);
const auto memory_range = this->buffer_manager->AcquireCache(entry.handle);
const auto memory_range = m_buffer_manager->AcquireCache(entry.handle);
if (memory_range.first != 0) {
this->buffer_manager->DeallocateBuffer(memory_range.first, memory_range.second);
m_buffer_manager->DeallocateBuffer(memory_range.first, memory_range.second);
}
}
@@ -992,8 +992,8 @@ namespace ams::fssystem::save {
AMS_ASSERT(max_cache_entry_count > 0);
/* Get size metrics from the buffer manager. */
const auto total_size = this->buffer_manager->GetTotalSize();
const auto allocatable_size = this->buffer_manager->GetTotalAllocatableSize();
const auto total_size = m_buffer_manager->GetTotalSize();
const auto allocatable_size = m_buffer_manager->GetTotalAllocatableSize();
/* If we have enough allocatable space, we don't need to do anything. */
R_SUCCEED_IF(allocatable_size >= total_size / 4);
@@ -1001,12 +1001,12 @@ namespace ams::fssystem::save {
/* Setup for flushing dirty entries. */
auto threshold = 2;
auto dirty_count = 0;
auto flushed_index = this->invalidate_index;
auto flushed_index = m_invalidate_index;
/* Iterate over all entries (starting with the invalidate index), and flush dirty entries once threshold is met. */
for (auto i = 0; i < max_cache_entry_count; ++i) {
auto index = (this->invalidate_index + 1 + i) % max_cache_entry_count;
if (this->entries[index].is_valid && this->entries[index].is_write_back) {
auto index = (m_invalidate_index + 1 + i) % max_cache_entry_count;
if (m_entries[index].is_valid && m_entries[index].is_write_back) {
++dirty_count;
if (threshold <= dirty_count) {
R_TRY(this->FlushCacheEntry(index, false));
@@ -1016,15 +1016,15 @@ namespace ams::fssystem::save {
}
/* Update the invalidate index. */
this->invalidate_index = flushed_index;
m_invalidate_index = flushed_index;
return ResultSuccess();
}
Result BlockCacheBufferedStorage::UpdateLastResult(Result result) {
/* Update the last result. */
if (R_FAILED(result) && !fs::ResultBufferAllocationFailed::Includes(result) && R_SUCCEEDED(this->last_result)) {
this->last_result = result;
if (R_FAILED(result) && !fs::ResultBufferAllocationFailed::Includes(result) && R_SUCCEEDED(m_last_result)) {
m_last_result = result;
}
/* Try to succeed with the result. */
@@ -1054,7 +1054,7 @@ namespace ams::fssystem::save {
while (*aligned_offset < aligned_offset_end) {
/* Get the associated buffer for the offset. */
R_TRY(this->UpdateLastResult(this->GetAssociateBuffer(std::addressof(memory_range), std::addressof(entry), *aligned_offset, this->verification_block_size, true)));
R_TRY(this->UpdateLastResult(this->GetAssociateBuffer(std::addressof(memory_range), std::addressof(entry), *aligned_offset, m_verification_block_size, true)));
/* If the entry isn't cached, we're done. */
if (!entry.is_cached) {
@@ -1106,7 +1106,7 @@ namespace ams::fssystem::save {
while (aligned_offset < *aligned_offset_end) {
/* Get the associated buffer for the offset. */
R_TRY(this->UpdateLastResult(this->GetAssociateBuffer(std::addressof(memory_range), std::addressof(entry), *aligned_offset_end - this->verification_block_size, this->verification_block_size, true)));
R_TRY(this->UpdateLastResult(this->GetAssociateBuffer(std::addressof(memory_range), std::addressof(entry), *aligned_offset_end - m_verification_block_size, m_verification_block_size, true)));
/* If the entry isn't cached, we're done. */
if (!entry.is_cached) {
@@ -1149,8 +1149,8 @@ namespace ams::fssystem::save {
/* Determine bulk read offsets. */
const s64 read_offset = offset;
const size_t read_size = size;
const s64 aligned_offset = util::AlignDown(read_offset, this->verification_block_size);
const s64 aligned_offset_end = util::AlignUp(read_offset + read_size, this->verification_block_size);
const s64 aligned_offset = util::AlignDown(read_offset, m_verification_block_size);
const s64 aligned_offset_end = util::AlignUp(read_offset + read_size, m_verification_block_size);
char *dst = static_cast<char *>(buffer);
/* Prepare to do our reads. */
@@ -1177,7 +1177,7 @@ namespace ams::fssystem::save {
}
/* Read the data. */
R_TRY(this->data_storage->Read(aligned_offset, read_buffer, buffer_size));
R_TRY(m_data_storage->Read(aligned_offset, read_buffer, buffer_size));
/* Copy the data out. */
if (dst != read_buffer) {

View File

@@ -56,7 +56,7 @@ namespace ams::fssystem::save {
}
/* Instantiate the global random generation function. */
HierarchicalIntegrityVerificationStorage::GenerateRandomFunction HierarchicalIntegrityVerificationStorage::s_generate_random = nullptr;
constinit HierarchicalIntegrityVerificationStorage::GenerateRandomFunction HierarchicalIntegrityVerificationStorage::s_generate_random = nullptr;
Result HierarchicalIntegrityVerificationStorageControlArea::QuerySize(HierarchicalIntegrityVerificationSizeSet *out, const InputParam &input_param, s32 layer_count, s64 data_size) {
/* Validate preconditions. */
@@ -130,24 +130,24 @@ namespace ams::fssystem::save {
{
s64 meta_size = 0;
R_TRY(meta_storage.GetSize(std::addressof(meta_size)));
R_UNLESS(meta_size >= static_cast<s64>(sizeof(this->meta)), fs::ResultInvalidSize());
R_UNLESS(meta_size >= static_cast<s64>(sizeof(m_meta)), fs::ResultInvalidSize());
}
/* Set the storage and read the meta. */
this->storage = meta_storage;
R_TRY(this->storage.Read(0, std::addressof(this->meta), sizeof(this->meta)));
m_storage = meta_storage;
R_TRY(m_storage.Read(0, std::addressof(m_meta), sizeof(m_meta)));
/* Validate the meta magic. */
R_UNLESS(this->meta.magic == IntegrityVerificationStorageMagic, fs::ResultIncorrectIntegrityVerificationMagic());
R_UNLESS(m_meta.magic == IntegrityVerificationStorageMagic, fs::ResultIncorrectIntegrityVerificationMagic());
/* Validate the meta version. */
R_UNLESS((this->meta.version & IntegrityVerificationStorageVersionMask) == (IntegrityVerificationStorageVersion & IntegrityVerificationStorageVersionMask), fs::ResultUnsupportedVersion());
R_UNLESS((m_meta.version & IntegrityVerificationStorageVersionMask) == (IntegrityVerificationStorageVersion & IntegrityVerificationStorageVersionMask), fs::ResultUnsupportedVersion());
return ResultSuccess();
}
void HierarchicalIntegrityVerificationStorageControlArea::Finalize() {
this->storage = fs::SubStorage();
m_storage = fs::SubStorage();
}
Result HierarchicalIntegrityVerificationStorage::Initialize(const HierarchicalIntegrityVerificationInformation &info, HierarchicalStorageInformation storage, FileSystemBufferManagerSet *bufs, os::SdkRecursiveMutex *mtx, fs::StorageType storage_type) {
@@ -156,9 +156,9 @@ namespace ams::fssystem::save {
AMS_ASSERT(IntegrityMinLayerCount <= info.max_layers && info.max_layers <= IntegrityMaxLayerCount);
/* Set member variables. */
this->max_layers = info.max_layers;
this->buffers = bufs;
this->mutex = mtx;
m_max_layers = info.max_layers;
m_buffers = bufs;
m_mutex = mtx;
/* Determine our cache counts. */
const auto max_data_cache_entry_count = (storage_type == fs::StorageType_SaveData) ? MaxSaveDataFsDataCacheEntryCount : MaxRomFsDataCacheEntryCount;
@@ -168,64 +168,64 @@ namespace ams::fssystem::save {
{
fs::HashSalt mac;
crypto::GenerateHmacSha256Mac(mac.value, sizeof(mac), info.seed.value, sizeof(info.seed), KeyArray[0].key, KeyArray[0].size);
this->verify_storages[0].Initialize(storage[HierarchicalStorageInformation::MasterStorage], storage[HierarchicalStorageInformation::Layer1Storage], static_cast<s64>(1) << info.info[0].block_order, HashSize, this->buffers->buffers[this->max_layers - 2], mac, false, storage_type);
m_verify_storages[0].Initialize(storage[HierarchicalStorageInformation::MasterStorage], storage[HierarchicalStorageInformation::Layer1Storage], static_cast<s64>(1) << info.info[0].block_order, HashSize, m_buffers->buffers[m_max_layers - 2], mac, false, storage_type);
}
/* Ensure we don't leak state if further initialization goes wrong. */
auto top_verif_guard = SCOPE_GUARD {
this->verify_storages[0].Finalize();
m_verify_storages[0].Finalize();
this->data_size = -1;
this->buffers = nullptr;
this->mutex = nullptr;
m_data_size = -1;
m_buffers = nullptr;
m_mutex = nullptr;
};
/* Initialize the top level buffer storage. */
R_TRY(this->buffer_storages[0].Initialize(this->buffers->buffers[0], this->mutex, std::addressof(this->verify_storages[0]), info.info[0].size, static_cast<s64>(1) << info.info[0].block_order, max_hash_cache_entry_count, false, 0x10, false, storage_type));
auto top_buffer_guard = SCOPE_GUARD { this->buffer_storages[0].Finalize(); };
R_TRY(m_buffer_storages[0].Initialize(m_buffers->buffers[0], m_mutex, std::addressof(m_verify_storages[0]), info.info[0].size, static_cast<s64>(1) << info.info[0].block_order, max_hash_cache_entry_count, false, 0x10, false, storage_type));
auto top_buffer_guard = SCOPE_GUARD { m_buffer_storages[0].Finalize(); };
/* Prepare to initialize the level storages. */
s32 level = 0;
/* Ensure we don't leak state if further initialization goes wrong. */
auto level_guard = SCOPE_GUARD {
this->verify_storages[level + 1].Finalize();
m_verify_storages[level + 1].Finalize();
for (/* ... */; level > 0; --level) {
this->buffer_storages[level].Finalize();
this->verify_storages[level].Finalize();
m_buffer_storages[level].Finalize();
m_verify_storages[level].Finalize();
}
};
/* Initialize the level storages. */
for (/* ... */; level < this->max_layers - 3; ++level) {
for (/* ... */; level < m_max_layers - 3; ++level) {
/* Initialize the verification storage. */
{
fs::SubStorage buffer_storage(std::addressof(this->buffer_storages[level]), 0, info.info[level].size);
fs::SubStorage buffer_storage(std::addressof(m_buffer_storages[level]), 0, info.info[level].size);
fs::HashSalt mac;
crypto::GenerateHmacSha256Mac(mac.value, sizeof(mac), info.seed.value, sizeof(info.seed), KeyArray[level + 1].key, KeyArray[level + 1].size);
this->verify_storages[level + 1].Initialize(buffer_storage, storage[level + 2], static_cast<s64>(1) << info.info[level + 1].block_order, static_cast<s64>(1) << info.info[level].block_order, this->buffers->buffers[this->max_layers - 2], mac, false, storage_type);
m_verify_storages[level + 1].Initialize(buffer_storage, storage[level + 2], static_cast<s64>(1) << info.info[level + 1].block_order, static_cast<s64>(1) << info.info[level].block_order, m_buffers->buffers[m_max_layers - 2], mac, false, storage_type);
}
/* Initialize the buffer storage. */
R_TRY(this->buffer_storages[level + 1].Initialize(this->buffers->buffers[level + 1], this->mutex, std::addressof(this->verify_storages[level + 1]), info.info[level + 1].size, static_cast<s64>(1) << info.info[level + 1].block_order, max_hash_cache_entry_count, false, 0x11 + static_cast<s8>(level), false, storage_type));
R_TRY(m_buffer_storages[level + 1].Initialize(m_buffers->buffers[level + 1], m_mutex, std::addressof(m_verify_storages[level + 1]), info.info[level + 1].size, static_cast<s64>(1) << info.info[level + 1].block_order, max_hash_cache_entry_count, false, 0x11 + static_cast<s8>(level), false, storage_type));
}
/* Initialize the final level storage. */
{
/* Initialize the verification storage. */
{
fs::SubStorage buffer_storage(std::addressof(this->buffer_storages[level]), 0, info.info[level].size);
fs::SubStorage buffer_storage(std::addressof(m_buffer_storages[level]), 0, info.info[level].size);
fs::HashSalt mac;
crypto::GenerateHmacSha256Mac(mac.value, sizeof(mac), info.seed.value, sizeof(info.seed), KeyArray[level + 1].key, KeyArray[level + 1].size);
this->verify_storages[level + 1].Initialize(buffer_storage, storage[level + 2], static_cast<s64>(1) << info.info[level + 1].block_order, static_cast<s64>(1) << info.info[level].block_order, this->buffers->buffers[this->max_layers - 2], mac, true, storage_type);
m_verify_storages[level + 1].Initialize(buffer_storage, storage[level + 2], static_cast<s64>(1) << info.info[level + 1].block_order, static_cast<s64>(1) << info.info[level].block_order, m_buffers->buffers[m_max_layers - 2], mac, true, storage_type);
}
/* Initialize the buffer storage. */
R_TRY(this->buffer_storages[level + 1].Initialize(this->buffers->buffers[level + 1], this->mutex, std::addressof(this->verify_storages[level + 1]), info.info[level + 1].size, static_cast<s64>(1) << info.info[level + 1].block_order, max_data_cache_entry_count, true, 0x11 + static_cast<s8>(level), true, storage_type));
R_TRY(m_buffer_storages[level + 1].Initialize(m_buffers->buffers[level + 1], m_mutex, std::addressof(m_verify_storages[level + 1]), info.info[level + 1].size, static_cast<s64>(1) << info.info[level + 1].block_order, max_data_cache_entry_count, true, 0x11 + static_cast<s8>(level), true, storage_type));
}
/* Set the data size. */
this->data_size = info.info[level + 1].size;
m_data_size = info.info[level + 1].size;
/* We succeeded. */
level_guard.Cancel();
@@ -235,24 +235,24 @@ namespace ams::fssystem::save {
}
void HierarchicalIntegrityVerificationStorage::Finalize() {
if (this->data_size >= 0) {
this->data_size = 0;
if (m_data_size >= 0) {
m_data_size = 0;
this->buffers = nullptr;
this->mutex = nullptr;
m_buffers = nullptr;
m_mutex = nullptr;
for (s32 level = this->max_layers - 2; level >= 0; --level) {
this->buffer_storages[level].Finalize();
this->verify_storages[level].Finalize();
for (s32 level = m_max_layers - 2; level >= 0; --level) {
m_buffer_storages[level].Finalize();
m_verify_storages[level].Finalize();
}
this->data_size = -1;
m_data_size = -1;
}
}
Result HierarchicalIntegrityVerificationStorage::Read(s64 offset, void *buffer, size_t size) {
/* Validate preconditions. */
AMS_ASSERT(this->data_size >= 0);
AMS_ASSERT(m_data_size >= 0);
/* Succeed if zero-size. */
R_SUCCEED_IF(size == 0);
@@ -262,8 +262,8 @@ namespace ams::fssystem::save {
/* Acquire access to the read semaphore. */
if (!g_read_semaphore.TimedAcquire(AccessTimeout)) {
for (auto level = this->max_layers - 2; level >= 0; --level) {
R_TRY(this->buffer_storages[level].Flush());
for (auto level = m_max_layers - 2; level >= 0; --level) {
R_TRY(m_buffer_storages[level].Flush());
}
g_read_semaphore.Acquire();
}
@@ -272,13 +272,13 @@ namespace ams::fssystem::save {
ON_SCOPE_EXIT { g_read_semaphore.Release(); };
/* Read the data. */
R_TRY(this->buffer_storages[this->max_layers - 2].Read(offset, buffer, size));
R_TRY(m_buffer_storages[m_max_layers - 2].Read(offset, buffer, size));
return ResultSuccess();
}
Result HierarchicalIntegrityVerificationStorage::Write(s64 offset, const void *buffer, size_t size) {
/* Validate preconditions. */
AMS_ASSERT(this->data_size >= 0);
AMS_ASSERT(m_data_size >= 0);
/* Succeed if zero-size. */
R_SUCCEED_IF(size == 0);
@@ -288,8 +288,8 @@ namespace ams::fssystem::save {
/* Acquire access to the write semaphore. */
if (!g_write_semaphore.TimedAcquire(AccessTimeout)) {
for (auto level = this->max_layers - 2; level >= 0; --level) {
R_TRY(this->buffer_storages[level].Flush());
for (auto level = m_max_layers - 2; level >= 0; --level) {
R_TRY(m_buffer_storages[level].Flush());
}
g_write_semaphore.Acquire();
}
@@ -298,15 +298,15 @@ namespace ams::fssystem::save {
ON_SCOPE_EXIT { g_write_semaphore.Release(); };
/* Write the data. */
R_TRY(this->buffer_storages[this->max_layers - 2].Write(offset, buffer, size));
this->is_written_for_rollback = true;
R_TRY(m_buffer_storages[m_max_layers - 2].Write(offset, buffer, size));
m_is_written_for_rollback = true;
return ResultSuccess();
}
Result HierarchicalIntegrityVerificationStorage::GetSize(s64 *out) {
AMS_ASSERT(out != nullptr);
AMS_ASSERT(this->data_size >= 0);
*out = this->data_size;
AMS_ASSERT(m_data_size >= 0);
*out = m_data_size;
return ResultSuccess();
}
@@ -319,14 +319,14 @@ namespace ams::fssystem::save {
case fs::OperationId::FillZero:
case fs::OperationId::DestroySignature:
{
R_TRY(this->buffer_storages[this->max_layers - 2].OperateRange(dst, dst_size, op_id, offset, size, src, src_size));
this->is_written_for_rollback = true;
R_TRY(m_buffer_storages[m_max_layers - 2].OperateRange(dst, dst_size, op_id, offset, size, src, src_size));
m_is_written_for_rollback = true;
return ResultSuccess();
}
case fs::OperationId::Invalidate:
case fs::OperationId::QueryRange:
{
R_TRY(this->buffer_storages[this->max_layers - 2].OperateRange(dst, dst_size, op_id, offset, size, src, src_size));
R_TRY(m_buffer_storages[m_max_layers - 2].OperateRange(dst, dst_size, op_id, offset, size, src, src_size));
return ResultSuccess();
}
default:
@@ -335,17 +335,17 @@ namespace ams::fssystem::save {
}
Result HierarchicalIntegrityVerificationStorage::Commit() {
for (s32 level = this->max_layers - 2; level >= 0; --level) {
R_TRY(this->buffer_storages[level].Commit());
for (s32 level = m_max_layers - 2; level >= 0; --level) {
R_TRY(m_buffer_storages[level].Commit());
}
return ResultSuccess();
}
Result HierarchicalIntegrityVerificationStorage::OnRollback() {
for (s32 level = this->max_layers - 2; level >= 0; --level) {
R_TRY(this->buffer_storages[level].OnRollback());
for (s32 level = m_max_layers - 2; level >= 0; --level) {
R_TRY(m_buffer_storages[level].OnRollback());
}
this->is_written_for_rollback = false;
m_is_written_for_rollback = false;
return ResultSuccess();
}

View File

@@ -23,47 +23,47 @@ namespace ams::fssystem::save {
AMS_ASSERT(bm != nullptr);
/* Set storages. */
this->hash_storage = hs;
this->data_storage = ds;
m_hash_storage = hs;
m_data_storage = ds;
/* Set verification block sizes. */
this->verification_block_size = verif_block_size;
this->verification_block_order = ILog2(static_cast<u32>(verif_block_size));
AMS_ASSERT(this->verification_block_size == (1l << this->verification_block_order));
m_verification_block_size = verif_block_size;
m_verification_block_order = ILog2(static_cast<u32>(verif_block_size));
AMS_ASSERT(m_verification_block_size == (1l << m_verification_block_order));
/* Set buffer manager. */
this->buffer_manager = bm;
m_buffer_manager = bm;
/* Set upper layer block sizes. */
upper_layer_verif_block_size = std::max(upper_layer_verif_block_size, HashSize);
this->upper_layer_verification_block_size = upper_layer_verif_block_size;
this->upper_layer_verification_block_order = ILog2(static_cast<u32>(upper_layer_verif_block_size));
AMS_ASSERT(this->upper_layer_verification_block_size == (1l << this->upper_layer_verification_block_order));
m_upper_layer_verification_block_size = upper_layer_verif_block_size;
m_upper_layer_verification_block_order = ILog2(static_cast<u32>(upper_layer_verif_block_size));
AMS_ASSERT(m_upper_layer_verification_block_size == (1l << m_upper_layer_verification_block_order));
/* Validate sizes. */
{
s64 hash_size = 0;
s64 data_size = 0;
R_ASSERT(hash_storage.GetSize(std::addressof(hash_size)));
R_ASSERT(data_storage.GetSize(std::addressof(hash_size)));
AMS_ASSERT(((hash_size / HashSize) * this->verification_block_size) >= data_size);
AMS_ASSERT(R_SUCCEEDED(m_hash_storage.GetSize(std::addressof(hash_size))));
AMS_ASSERT(R_SUCCEEDED(m_data_storage.GetSize(std::addressof(hash_size))));
AMS_ASSERT(((hash_size / HashSize) * m_verification_block_size) >= data_size);
AMS_UNUSED(hash_size, data_size);
}
/* Set salt. */
std::memcpy(this->salt.value, salt.value, fs::HashSalt::Size);
std::memcpy(m_salt.value, salt.value, fs::HashSalt::Size);
/* Set data and storage type. */
this->is_real_data = is_real_data;
this->storage_type = storage_type;
m_is_real_data = is_real_data;
m_storage_type = storage_type;
return ResultSuccess();
}
void IntegrityVerificationStorage::Finalize() {
if (this->buffer_manager != nullptr) {
this->hash_storage = fs::SubStorage();
this->data_storage = fs::SubStorage();
this->buffer_manager = nullptr;
if (m_buffer_manager != nullptr) {
m_hash_storage = fs::SubStorage();
m_data_storage = fs::SubStorage();
m_buffer_manager = nullptr;
}
}
@@ -72,8 +72,8 @@ namespace ams::fssystem::save {
AMS_ASSERT(size != 0);
/* Validate other preconditions. */
AMS_ASSERT(util::IsAligned(offset, static_cast<size_t>(this->verification_block_size)));
AMS_ASSERT(util::IsAligned(size, static_cast<size_t>(this->verification_block_size)));
AMS_ASSERT(util::IsAligned(offset, static_cast<size_t>(m_verification_block_size)));
AMS_ASSERT(util::IsAligned(size, static_cast<size_t>(m_verification_block_size)));
/* Succeed if zero size. */
R_SUCCEED_IF(size == 0);
@@ -83,19 +83,19 @@ namespace ams::fssystem::save {
/* Validate the offset. */
s64 data_size;
R_TRY(this->data_storage.GetSize(std::addressof(data_size)));
R_TRY(m_data_storage.GetSize(std::addressof(data_size)));
R_UNLESS(offset <= data_size, fs::ResultInvalidOffset());
/* Validate the access range. */
R_UNLESS(IStorage::CheckAccessRange(offset, size, util::AlignUp(data_size, static_cast<size_t>(this->verification_block_size))), fs::ResultOutOfRange());
R_UNLESS(IStorage::CheckAccessRange(offset, size, util::AlignUp(data_size, static_cast<size_t>(m_verification_block_size))), fs::ResultOutOfRange());
/* Determine the read extents. */
size_t read_size = size;
if (static_cast<s64>(offset + read_size) > data_size) {
/* Determine the padding sizes. */
s64 padding_offset = data_size - offset;
size_t padding_size = static_cast<size_t>(this->verification_block_size - (padding_offset & (this->verification_block_size - 1)));
AMS_ASSERT(static_cast<s64>(padding_size) < this->verification_block_size);
size_t padding_size = static_cast<size_t>(m_verification_block_size - (padding_offset & (m_verification_block_size - 1)));
AMS_ASSERT(static_cast<s64>(padding_size) < m_verification_block_size);
/* Clear the padding. */
std::memset(static_cast<u8 *>(buffer) + padding_offset, 0, padding_size);
@@ -107,12 +107,12 @@ namespace ams::fssystem::save {
/* Perform the read. */
{
auto clear_guard = SCOPE_GUARD { std::memset(buffer, 0, size); };
R_TRY(this->data_storage.Read(offset, buffer, read_size));
R_TRY(m_data_storage.Read(offset, buffer, read_size));
clear_guard.Cancel();
}
/* Prepare to validate the signatures. */
const auto signature_count = size >> this->verification_block_order;
const auto signature_count = size >> m_verification_block_order;
PooledBuffer signature_buffer(signature_count * sizeof(BlockHash), sizeof(BlockHash));
const auto buffer_count = std::min(signature_count, signature_buffer.GetSize() / sizeof(BlockHash));
@@ -123,23 +123,23 @@ namespace ams::fssystem::save {
while (verified_count < signature_count) {
/* Read the current signatures. */
const auto cur_count = std::min(buffer_count, signature_count - verified_count);
auto cur_result = this->ReadBlockSignature(signature_buffer.GetBuffer(), signature_buffer.GetSize(), offset + (verified_count << this->verification_block_order), cur_count << this->verification_block_order);
auto cur_result = this->ReadBlockSignature(signature_buffer.GetBuffer(), signature_buffer.GetSize(), offset + (verified_count << m_verification_block_order), cur_count << m_verification_block_order);
/* Temporarily increase our priority. */
ScopedThreadPriorityChanger cp(+1, ScopedThreadPriorityChanger::Mode::Relative);
/* Loop over each signature we read. */
for (size_t i = 0; i < cur_count && R_SUCCEEDED(cur_result); ++i) {
const auto verified_size = (verified_count + i) << this->verification_block_order;
const auto verified_size = (verified_count + i) << m_verification_block_order;
u8 *cur_buf = static_cast<u8 *>(buffer) + verified_size;
cur_result = this->VerifyHash(cur_buf, reinterpret_cast<BlockHash *>(signature_buffer.GetBuffer()) + i);
/* If the data is corrupted, clear the corrupted parts. */
if (fs::ResultIntegrityVerificationStorageCorrupted::Includes(cur_result)) {
std::memset(cur_buf, 0, this->verification_block_size);
std::memset(cur_buf, 0, m_verification_block_size);
/* Set the result if we should. */
if (!fs::ResultClearedRealDataVerificationFailed::Includes(cur_result) && this->storage_type != fs::StorageType_Authoring) {
if (!fs::ResultClearedRealDataVerificationFailed::Includes(cur_result) && m_storage_type != fs::StorageType_Authoring) {
verify_hash_result = cur_result;
}
@@ -170,17 +170,17 @@ namespace ams::fssystem::save {
/* Validate the offset. */
s64 data_size;
R_TRY(this->data_storage.GetSize(std::addressof(data_size)));
R_TRY(m_data_storage.GetSize(std::addressof(data_size)));
R_UNLESS(offset < data_size, fs::ResultInvalidOffset());
/* Validate the access range. */
R_UNLESS(IStorage::CheckAccessRange(offset, size, util::AlignUp(data_size, static_cast<size_t>(this->verification_block_size))), fs::ResultOutOfRange());
R_UNLESS(IStorage::CheckAccessRange(offset, size, util::AlignUp(data_size, static_cast<size_t>(m_verification_block_size))), fs::ResultOutOfRange());
/* Validate preconditions. */
AMS_ASSERT(util::IsAligned(offset, this->verification_block_size));
AMS_ASSERT(util::IsAligned(size, this->verification_block_size));
AMS_ASSERT(util::IsAligned(offset, m_verification_block_size));
AMS_ASSERT(util::IsAligned(size, m_verification_block_size));
AMS_ASSERT(offset <= data_size);
AMS_ASSERT(static_cast<s64>(offset + size) < data_size + this->verification_block_size);
AMS_ASSERT(static_cast<s64>(offset + size) < data_size + m_verification_block_size);
/* Validate that if writing past the end, all extra data is zero padding. */
if (static_cast<s64>(offset + size) > data_size) {
@@ -201,13 +201,13 @@ namespace ams::fssystem::save {
}
/* Determine the size we're writing in blocks. */
const auto aligned_write_size = util::AlignUp(write_size, this->verification_block_size);
const auto aligned_write_size = util::AlignUp(write_size, m_verification_block_size);
/* Write the updated block signatures. */
Result update_result = ResultSuccess();
size_t updated_count = 0;
{
const auto signature_count = aligned_write_size >> this->verification_block_order;
const auto signature_count = aligned_write_size >> m_verification_block_order;
PooledBuffer signature_buffer(signature_count * sizeof(BlockHash), sizeof(BlockHash));
const auto buffer_count = std::min(signature_count, signature_buffer.GetSize() / sizeof(BlockHash));
@@ -219,13 +219,13 @@ namespace ams::fssystem::save {
ScopedThreadPriorityChanger cp(+1, ScopedThreadPriorityChanger::Mode::Relative);
for (size_t i = 0; i < cur_count; ++i) {
const auto updated_size = (updated_count + i) << this->verification_block_order;
const auto updated_size = (updated_count + i) << m_verification_block_order;
this->CalcBlockHash(reinterpret_cast<BlockHash *>(signature_buffer.GetBuffer()) + i, reinterpret_cast<const u8 *>(buffer) + updated_size);
}
}
/* Write the new block signatures. */
if (R_FAILED((update_result = this->WriteBlockSignature(signature_buffer.GetBuffer(), signature_buffer.GetSize(), offset + (updated_count << this->verification_block_order), cur_count << this->verification_block_order)))) {
if (R_FAILED((update_result = this->WriteBlockSignature(signature_buffer.GetBuffer(), signature_buffer.GetSize(), offset + (updated_count << m_verification_block_order), cur_count << m_verification_block_order)))) {
break;
}
@@ -235,44 +235,44 @@ namespace ams::fssystem::save {
}
/* Write the data. */
R_TRY(this->data_storage.Write(offset, buffer, std::min(write_size, updated_count << this->verification_block_order)));
R_TRY(m_data_storage.Write(offset, buffer, std::min(write_size, updated_count << m_verification_block_order)));
return update_result;
}
Result IntegrityVerificationStorage::GetSize(s64 *out) {
return this->data_storage.GetSize(out);
return m_data_storage.GetSize(out);
}
Result IntegrityVerificationStorage::Flush() {
/* Flush both storages. */
R_TRY(this->hash_storage.Flush());
R_TRY(this->data_storage.Flush());
R_TRY(m_hash_storage.Flush());
R_TRY(m_data_storage.Flush());
return ResultSuccess();
}
Result IntegrityVerificationStorage::OperateRange(void *dst, size_t dst_size, fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) {
/* Validate preconditions. */
AMS_ASSERT(util::IsAligned(offset, static_cast<size_t>(this->verification_block_size)));
AMS_ASSERT(util::IsAligned(size, static_cast<size_t>(this->verification_block_size)));
AMS_ASSERT(util::IsAligned(offset, static_cast<size_t>(m_verification_block_size)));
AMS_ASSERT(util::IsAligned(size, static_cast<size_t>(m_verification_block_size)));
switch (op_id) {
case fs::OperationId::FillZero:
{
/* Clear should only be called for save data. */
AMS_ASSERT(this->storage_type == fs::StorageType_SaveData);
AMS_ASSERT(m_storage_type == fs::StorageType_SaveData);
/* Validate the range. */
s64 data_size = 0;
R_TRY(this->data_storage.GetSize(std::addressof(data_size)));
R_TRY(m_data_storage.GetSize(std::addressof(data_size)));
R_UNLESS(0 <= offset && offset <= data_size, fs::ResultInvalidOffset());
/* Determine the extents to clear. */
const auto sign_offset = (offset >> this->verification_block_order) * HashSize;
const auto sign_size = (std::min(size, data_size - offset) >> this->verification_block_order) * HashSize;
const auto sign_offset = (offset >> m_verification_block_order) * HashSize;
const auto sign_size = (std::min(size, data_size - offset) >> m_verification_block_order) * HashSize;
/* Allocate a work buffer. */
const auto buf_size = static_cast<size_t>(std::min(sign_size, static_cast<s64>(1) << (this->upper_layer_verification_block_order + 2)));
const auto buf_size = static_cast<size_t>(std::min(sign_size, static_cast<s64>(1) << (m_upper_layer_verification_block_order + 2)));
std::unique_ptr<char[], fs::impl::Deleter> buf = fs::impl::MakeUnique<char[]>(buf_size);
R_UNLESS(buf != nullptr, fs::ResultAllocationFailureInIntegrityVerificationStorageA());
@@ -284,7 +284,7 @@ namespace ams::fssystem::save {
while (remaining_size > 0) {
const auto cur_size = static_cast<size_t>(std::min(remaining_size, static_cast<s64>(buf_size)));
R_TRY(this->hash_storage.Write(sign_offset + sign_size - remaining_size, buf.get(), cur_size));
R_TRY(m_hash_storage.Write(sign_offset + sign_size - remaining_size, buf.get(), cur_size));
remaining_size -= cur_size;
}
@@ -293,23 +293,23 @@ namespace ams::fssystem::save {
case fs::OperationId::DestroySignature:
{
/* Clear Signature should only be called for save data. */
AMS_ASSERT(this->storage_type == fs::StorageType_SaveData);
AMS_ASSERT(m_storage_type == fs::StorageType_SaveData);
/* Validate the range. */
s64 data_size = 0;
R_TRY(this->data_storage.GetSize(std::addressof(data_size)));
R_TRY(m_data_storage.GetSize(std::addressof(data_size)));
R_UNLESS(0 <= offset && offset <= data_size, fs::ResultInvalidOffset());
/* Determine the extents to clear the signature for. */
const auto sign_offset = (offset >> this->verification_block_order) * HashSize;
const auto sign_size = (std::min(size, data_size - offset) >> this->verification_block_order) * HashSize;
const auto sign_offset = (offset >> m_verification_block_order) * HashSize;
const auto sign_size = (std::min(size, data_size - offset) >> m_verification_block_order) * HashSize;
/* Allocate a work buffer. */
std::unique_ptr<char[], fs::impl::Deleter> buf = fs::impl::MakeUnique<char[]>(sign_size);
R_UNLESS(buf != nullptr, fs::ResultAllocationFailureInIntegrityVerificationStorageB());
/* Read the existing signature. */
R_TRY(this->hash_storage.Read(sign_offset, buf.get(), sign_size));
R_TRY(m_hash_storage.Read(sign_offset, buf.get(), sign_size));
/* Clear the signature. */
/* This sets all bytes to FF, with the verification bit cleared. */
@@ -318,25 +318,25 @@ namespace ams::fssystem::save {
}
/* Write the cleared signature. */
return this->hash_storage.Write(sign_offset, buf.get(), sign_size);
return m_hash_storage.Write(sign_offset, buf.get(), sign_size);
}
case fs::OperationId::Invalidate:
{
/* Only allow cache invalidation for RomFs. */
R_UNLESS(this->storage_type != fs::StorageType_SaveData, fs::ResultUnsupportedOperationInIntegrityVerificationStorageB());
R_UNLESS(m_storage_type != fs::StorageType_SaveData, fs::ResultUnsupportedOperationInIntegrityVerificationStorageB());
/* Validate the range. */
s64 data_size = 0;
R_TRY(this->data_storage.GetSize(std::addressof(data_size)));
R_TRY(m_data_storage.GetSize(std::addressof(data_size)));
R_UNLESS(0 <= offset && offset <= data_size, fs::ResultInvalidOffset());
/* Determine the extents to invalidate. */
const auto sign_offset = (offset >> this->verification_block_order) * HashSize;
const auto sign_size = (std::min(size, data_size - offset) >> this->verification_block_order) * HashSize;
const auto sign_offset = (offset >> m_verification_block_order) * HashSize;
const auto sign_size = (std::min(size, data_size - offset) >> m_verification_block_order) * HashSize;
/* Operate on our storages. */
R_TRY(this->hash_storage.OperateRange(dst, dst_size, op_id, sign_offset, sign_size, src, src_size));
R_TRY(this->data_storage.OperateRange(dst, dst_size, op_id, sign_offset, sign_size, src, src_size));
R_TRY(m_hash_storage.OperateRange(dst, dst_size, op_id, sign_offset, sign_size, src, src_size));
R_TRY(m_data_storage.OperateRange(dst, dst_size, op_id, sign_offset, sign_size, src, src_size));
return ResultSuccess();
}
@@ -344,14 +344,14 @@ namespace ams::fssystem::save {
{
/* Validate the range. */
s64 data_size = 0;
R_TRY(this->data_storage.GetSize(std::addressof(data_size)));
R_TRY(m_data_storage.GetSize(std::addressof(data_size)));
R_UNLESS(0 <= offset && offset <= data_size, fs::ResultInvalidOffset());
/* Determine the real size to query. */
const auto actual_size = std::min(size, data_size - offset);
/* Query the data storage. */
R_TRY(this->data_storage.OperateRange(dst, dst_size, op_id, offset, actual_size, src, src_size));
R_TRY(m_data_storage.OperateRange(dst, dst_size, op_id, offset, actual_size, src, src_size));
return ResultSuccess();
}
@@ -366,8 +366,8 @@ namespace ams::fssystem::save {
sha.Initialize();
/* If calculating for save data, hash the salt. */
if (this->storage_type == fs::StorageType_SaveData) {
sha.Update(this->salt.value, sizeof(this->salt));
if (m_storage_type == fs::StorageType_SaveData) {
sha.Update(m_salt.value, sizeof(m_salt));
}
/* Update with the buffer and get the hash. */
@@ -375,7 +375,7 @@ namespace ams::fssystem::save {
sha.GetHash(out, sizeof(*out));
/* Set the validation bit, if the hash is for save data. */
if (this->storage_type == fs::StorageType_SaveData) {
if (m_storage_type == fs::StorageType_SaveData) {
SetValidationBit(out);
}
}
@@ -383,12 +383,12 @@ namespace ams::fssystem::save {
Result IntegrityVerificationStorage::ReadBlockSignature(void *dst, size_t dst_size, s64 offset, size_t size) {
/* Validate preconditions. */
AMS_ASSERT(dst != nullptr);
AMS_ASSERT(util::IsAligned(offset, static_cast<size_t>(this->verification_block_size)));
AMS_ASSERT(util::IsAligned(size, static_cast<size_t>(this->verification_block_size)));
AMS_ASSERT(util::IsAligned(offset, static_cast<size_t>(m_verification_block_size)));
AMS_ASSERT(util::IsAligned(size, static_cast<size_t>(m_verification_block_size)));
/* Determine where to read the signature. */
const s64 sign_offset = (offset >> this->verification_block_order) * HashSize;
const auto sign_size = static_cast<size_t>((size >> this->verification_block_order) * HashSize);
const s64 sign_offset = (offset >> m_verification_block_order) * HashSize;
const auto sign_size = static_cast<size_t>((size >> m_verification_block_order) * HashSize);
AMS_ASSERT(dst_size >= sign_size);
AMS_UNUSED(dst_size);
@@ -397,13 +397,13 @@ namespace ams::fssystem::save {
/* Validate that we can read the signature. */
s64 hash_size;
R_TRY(this->hash_storage.GetSize(std::addressof(hash_size)));
R_TRY(m_hash_storage.GetSize(std::addressof(hash_size)));
const bool range_valid = static_cast<s64>(sign_offset + sign_size) <= hash_size;
AMS_ASSERT(range_valid);
R_UNLESS(range_valid, fs::ResultOutOfRange());
/* Read the signature. */
R_TRY(this->hash_storage.Read(sign_offset, dst, sign_size));
R_TRY(m_hash_storage.Read(sign_offset, dst, sign_size));
/* We succeeded. */
clear_guard.Cancel();
@@ -413,16 +413,16 @@ namespace ams::fssystem::save {
Result IntegrityVerificationStorage::WriteBlockSignature(const void *src, size_t src_size, s64 offset, size_t size) {
/* Validate preconditions. */
AMS_ASSERT(src != nullptr);
AMS_ASSERT(util::IsAligned(offset, static_cast<size_t>(this->verification_block_size)));
AMS_ASSERT(util::IsAligned(offset, static_cast<size_t>(m_verification_block_size)));
/* Determine where to write the signature. */
const s64 sign_offset = (offset >> this->verification_block_order) * HashSize;
const auto sign_size = static_cast<size_t>((size >> this->verification_block_order) * HashSize);
const s64 sign_offset = (offset >> m_verification_block_order) * HashSize;
const auto sign_size = static_cast<size_t>((size >> m_verification_block_order) * HashSize);
AMS_ASSERT(src_size >= sign_size);
AMS_UNUSED(src_size);
/* Write the signature. */
R_TRY(this->hash_storage.Write(sign_offset, src, sign_size));
R_TRY(m_hash_storage.Write(sign_offset, src, sign_size));
/* We succeeded. */
return ResultSuccess();
@@ -437,7 +437,7 @@ namespace ams::fssystem::save {
auto &cmp_hash = *hash;
/* If save data, check if the data is uninitialized. */
if (this->storage_type == fs::StorageType_SaveData) {
if (m_storage_type == fs::StorageType_SaveData) {
bool is_cleared = false;
R_TRY(this->IsCleared(std::addressof(is_cleared), cmp_hash));
R_UNLESS(!is_cleared, fs::ResultClearedRealDataVerificationFailed());
@@ -453,7 +453,7 @@ namespace ams::fssystem::save {
std::memset(std::addressof(cmp_hash), 0, sizeof(cmp_hash));
/* Return the appropriate result. */
if (this->is_real_data) {
if (m_is_real_data) {
return fs::ResultUnclearedRealDataVerificationFailed();
} else {
return fs::ResultNonRealDataVerificationFailed();
@@ -466,7 +466,7 @@ namespace ams::fssystem::save {
Result IntegrityVerificationStorage::IsCleared(bool *is_cleared, const BlockHash &hash) {
/* Validate preconditions. */
AMS_ASSERT(is_cleared != nullptr);
AMS_ASSERT(this->storage_type == fs::StorageType_SaveData);
AMS_ASSERT(m_storage_type == fs::StorageType_SaveData);
/* Default to uncleared. */
*is_cleared = false;