1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-09-19 21:43:29 +01:00

fs: fixup all OperateRange implementations

This commit is contained in:
Michael Scire 2022-03-28 00:54:10 -07:00
parent 4ad8dad416
commit 0fbf007bcf
11 changed files with 60 additions and 41 deletions

View file

@ -65,4 +65,5 @@
#include <stratosphere/fs/fs_program_index_map_info.hpp>
#include <stratosphere/fs/impl/fs_access_log_impl.hpp>
#include <stratosphere/fs/impl/fs_hash_generator_factory_selector.hpp>
#include <stratosphere/fs/impl/fs_storage_service_object_adapter.hpp>
#include <stratosphere/fs/fs_api.hpp>

View file

@ -156,18 +156,17 @@ namespace ams::fs {
}
virtual Result DoGetFreeSpaceSize(s64 *out, const fs::Path &path) override final {
AMS_UNUSED(out, path);
R_THROW(fs::ResultUnsupportedCommitProvisionallyForReadOnlyFileSystem());
R_RETURN(m_base_fs->GetFreeSpaceSize(out, path));
}
virtual Result DoGetTotalSpaceSize(s64 *out, const fs::Path &path) override final {
AMS_UNUSED(out, path);
R_THROW(fs::ResultUnsupportedCommitProvisionallyForReadOnlyFileSystem());
R_THROW(fs::ResultUnsupportedGetTotalSpaceSizeForReadOnlyFileSystem());
}
virtual Result DoCommitProvisionally(s64 counter) override final {
AMS_UNUSED(counter);
R_THROW(fs::ResultUnsupportedGetTotalSpaceSizeForReadOnlyFileSystem());
R_THROW(fs::ResultUnsupportedCommitProvisionallyForReadOnlyFileSystem());
}
};

View file

@ -14,17 +14,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere.hpp>
#include <stratosphere/fs/fs_common.hpp>
#include <stratosphere/fs/fs_istorage.hpp>
#include <stratosphere/fs/impl/fs_newable.hpp>
namespace ams::fs::impl {
template<typename StorageInterface>
class StorageServiceObjectAdapter : public ::ams::fs::impl::Newable, public ::ams::fs::IStorage {
NON_COPYABLE(StorageServiceObjectAdapter);
NON_MOVEABLE(StorageServiceObjectAdapter);
private:
sf::SharedPointer<fssrv::sf::IStorage> m_x;
sf::SharedPointer<StorageInterface> m_x;
public:
explicit StorageServiceObjectAdapter(sf::SharedPointer<fssrv::sf::IStorage> &&o) : m_x(o) { /* ... */}
explicit StorageServiceObjectAdapter(sf::SharedPointer<StorageInterface> &&o) : m_x(o) { /* ... */}
virtual ~StorageServiceObjectAdapter() { /* ... */ }
public:
virtual Result Read(s64 offset, void *buffer, size_t size) override final {

View file

@ -16,7 +16,6 @@
#include <stratosphere.hpp>
#include "fsa/fs_mount_utils.hpp"
#include "impl/fs_file_system_service_object_adapter.hpp"
#include "impl/fs_storage_service_object_adapter.hpp"
#include "impl/fs_file_system_proxy_service_object.hpp"
namespace ams::fs {
@ -121,7 +120,7 @@ namespace ams::fs {
AMS_FS_R_TRY(fsp->OpenBisStorage(std::addressof(s), static_cast<u32>(id)));
/* Allocate a new storage wrapper. */
auto storage = std::make_unique<impl::StorageServiceObjectAdapter>(std::move(s));
auto storage = std::make_unique<impl::StorageServiceObjectAdapter<fssrv::sf::IStorage>>(std::move(s));
AMS_FS_R_UNLESS(storage != nullptr, fs::ResultAllocationMemoryFailedInBisC());
*out = std::move(storage);

View file

@ -16,7 +16,6 @@
#include <stratosphere.hpp>
#include "fsa/fs_mount_utils.hpp"
#include "impl/fs_file_system_proxy_service_object.hpp"
#include "impl/fs_storage_service_object_adapter.hpp"
namespace ams::fs::impl {
@ -35,7 +34,7 @@ namespace ams::fs::impl {
sf::SharedPointer<fssrv::sf::IStorage> s;
AMS_FS_R_TRY(OpenDataStorageByDataIdImpl(std::addressof(s), data_id, storage_id));
auto storage = std::make_unique<impl::StorageServiceObjectAdapter>(std::move(s));
auto storage = std::make_unique<impl::StorageServiceObjectAdapter<fssrv::sf::IStorage>>(std::move(s));
R_UNLESS(storage != nullptr, fs::ResultAllocationMemoryFailedInDataA());
*out = std::move(storage);

View file

@ -232,10 +232,11 @@ namespace ams::fs {
virtual Result DoOperateRange(void *dst, size_t dst_size, fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override {
switch (op_id) {
case OperationId::Invalidate:
R_RETURN(this->GetStorage()->OperateRange(fs::OperationId::Invalidate, 0, std::numeric_limits<s64>::max()));
case OperationId::QueryRange:
{
R_UNLESS(offset >= 0, fs::ResultOutOfRange());
R_UNLESS(this->GetSize() >= 0, fs::ResultOutOfRange());
R_UNLESS(offset >= 0, fs::ResultInvalidOffset());
R_UNLESS(this->GetSize() >= offset, fs::ResultOutOfRange());
auto operate_size = size;
if (offset + operate_size > this->GetSize() || offset + operate_size < offset) {

View file

@ -145,22 +145,25 @@ namespace ams::fssystem {
template<typename BasePointer>
Result AesCtrStorage<BasePointer>::OperateRange(void *dst, size_t dst_size, fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) {
/* Handle the zero size case. */
if (size == 0) {
if (op_id == fs::OperationId::QueryRange) {
R_UNLESS(dst != nullptr, fs::ResultNullptrArgument());
R_UNLESS(dst_size == sizeof(fs::QueryRangeInfo), fs::ResultInvalidSize());
/* If operation isn't invalidate, special case. */
if (op_id != fs::OperationId::Invalidate) {
/* Handle the zero-size case. */
if (size == 0) {
if (op_id == fs::OperationId::QueryRange) {
R_UNLESS(dst != nullptr, fs::ResultNullptrArgument());
R_UNLESS(dst_size == sizeof(fs::QueryRangeInfo), fs::ResultInvalidSize());
reinterpret_cast<fs::QueryRangeInfo *>(dst)->Clear();
reinterpret_cast<fs::QueryRangeInfo *>(dst)->Clear();
}
R_SUCCEED();
}
R_SUCCEED();
/* Ensure alignment. */
R_UNLESS(util::IsAligned(offset, BlockSize), fs::ResultInvalidArgument());
R_UNLESS(util::IsAligned(size, BlockSize), fs::ResultInvalidArgument());
}
/* Ensure alignment. */
R_UNLESS(util::IsAligned(offset, BlockSize), fs::ResultInvalidArgument());
R_UNLESS(util::IsAligned(size, BlockSize), fs::ResultInvalidArgument());
switch (op_id) {
case fs::OperationId::QueryRange:
{

View file

@ -722,10 +722,7 @@ namespace ams::fssystem {
/* Invalidate caches, if we should. */
if (op_id == fs::OperationId::Invalidate) {
SharedCache cache(this);
while (cache.AcquireNextOverlappedCache(offset, size)) {
cache.Invalidate();
}
this->InvalidateCaches();
}
R_RETURN(m_base_storage.OperateRange(dst, dst_size, op_id, offset, size, src, src_size));

View file

@ -122,6 +122,11 @@ namespace ams::fssystem {
}
Result IndirectStorage::OperateRange(void *dst, size_t dst_size, fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) {
/* Validate pre-conditions. */
AMS_ASSERT(offset >= 0);
AMS_ASSERT(size >= 0);
AMS_ASSERT(this->IsInitialized());
switch (op_id) {
case fs::OperationId::Invalidate:
{

View file

@ -90,24 +90,33 @@ namespace ams::fssystem {
virtual Result DoOperateRange(void *dst, size_t dst_size, fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override final {
/* Validate preconditions for operation. */
s64 operate_offset;
s64 operate_size;
switch (op_id) {
case fs::OperationId::Invalidate:
R_UNLESS((m_mode & fs::OpenMode_Read) != 0, fs::ResultReadNotPermitted());
R_UNLESS((m_mode & fs::OpenMode_Write) == 0, fs::ResultUnsupportedOperateRangeForPartitionFile());
/* Set offset/size. */
operate_offset = 0;
operate_size = std::numeric_limits<s64>::max();
break;
case fs::OperationId::QueryRange:
/* Validate offset and size. */
R_UNLESS(offset >= 0, fs::ResultOutOfRange());
R_UNLESS(offset <= static_cast<s64>(m_partition_entry->size), fs::ResultOutOfRange());
R_UNLESS(static_cast<s64>(offset + size) <= static_cast<s64>(m_partition_entry->size), fs::ResultInvalidSize());
R_UNLESS(static_cast<s64>(offset + size) >= offset, fs::ResultInvalidSize());
/* Set offset/size. */
operate_offset = m_parent->m_meta_data_size + m_partition_entry->offset + offset;
operate_size = size;
break;
default:
R_THROW(fs::ResultUnsupportedOperateRangeForPartitionFile());
}
/* Validate offset and size. */
R_UNLESS(offset >= 0, fs::ResultOutOfRange());
R_UNLESS(offset <= static_cast<s64>(m_partition_entry->size), fs::ResultOutOfRange());
R_UNLESS(static_cast<s64>(offset + size) <= static_cast<s64>(m_partition_entry->size), fs::ResultInvalidSize());
R_UNLESS(static_cast<s64>(offset + size) >= offset, fs::ResultInvalidSize());
R_RETURN(m_parent->m_base_storage->OperateRange(dst, dst_size, op_id, m_parent->m_meta_data_size + m_partition_entry->offset + offset, size, src, src_size));
R_RETURN(m_parent->m_base_storage->OperateRange(dst, dst_size, op_id, operate_offset, operate_size, src, src_size));
}
public:
virtual sf::cmif::DomainObjectId GetDomainObjectId() const override {

View file

@ -77,21 +77,24 @@ namespace ams::fssystem {
virtual Result DoOperateRange(void *dst, size_t dst_size, fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override {
switch (op_id) {
case fs::OperationId::Invalidate:
{
R_RETURN(buffers::DoContinuouslyUntilBufferIsAllocated([&]() -> Result {
R_RETURN(m_parent->GetBaseStorage()->OperateRange(fs::OperationId::Invalidate, 0, std::numeric_limits<s64>::max()));
}, AMS_CURRENT_FUNCTION_NAME));
}
case fs::OperationId::QueryRange:
{
R_UNLESS(offset >= 0, fs::ResultOutOfRange());
R_UNLESS(this->GetSize() >= 0, fs::ResultOutOfRange());
R_UNLESS(offset >= 0, fs::ResultInvalidOffset());
R_UNLESS(this->GetSize() >= offset, fs::ResultOutOfRange());
auto operate_size = size;
if (offset + operate_size > this->GetSize() || offset + operate_size < offset) {
operate_size = this->GetSize() - offset;
}
R_TRY(buffers::DoContinuouslyUntilBufferIsAllocated([&]() -> Result {
R_TRY(m_parent->GetBaseStorage()->OperateRange(dst, dst_size, op_id, m_start + offset, operate_size, src, src_size));
R_SUCCEED();
R_RETURN(buffers::DoContinuouslyUntilBufferIsAllocated([&]() -> Result {
R_RETURN(m_parent->GetBaseStorage()->OperateRange(dst, dst_size, op_id, m_start + offset, operate_size, src, src_size));
}, AMS_CURRENT_FUNCTION_NAME));
R_SUCCEED();
}
default:
R_THROW(fs::ResultUnsupportedOperateRangeForRomFsFile());