mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-02 15:49:48 -04:00
fs: fixup all OperateRange implementations
This commit is contained in:
parent
4ad8dad416
commit
0fbf007bcf
11 changed files with 60 additions and 41 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -1,73 +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 <stratosphere.hpp>
|
||||
|
||||
namespace ams::fs::impl {
|
||||
|
||||
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;
|
||||
public:
|
||||
explicit StorageServiceObjectAdapter(sf::SharedPointer<fssrv::sf::IStorage> &&o) : m_x(o) { /* ... */}
|
||||
virtual ~StorageServiceObjectAdapter() { /* ... */ }
|
||||
public:
|
||||
virtual Result Read(s64 offset, void *buffer, size_t size) override final {
|
||||
R_RETURN(m_x->Read(offset, sf::OutNonSecureBuffer(buffer, size), static_cast<s64>(size)));
|
||||
}
|
||||
|
||||
virtual Result GetSize(s64 *out) override final {
|
||||
R_RETURN(m_x->GetSize(out));
|
||||
}
|
||||
|
||||
virtual Result Flush() override final {
|
||||
R_RETURN(m_x->Flush());
|
||||
}
|
||||
|
||||
virtual Result Write(s64 offset, const void *buffer, size_t size) override final {
|
||||
R_RETURN(m_x->Write(offset, sf::InNonSecureBuffer(buffer, size), static_cast<s64>(size)));
|
||||
}
|
||||
|
||||
virtual Result SetSize(s64 size) override final {
|
||||
R_RETURN(m_x->SetSize(size));
|
||||
}
|
||||
|
||||
virtual Result OperateRange(void *dst, size_t dst_size, fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override final {
|
||||
AMS_UNUSED(src, src_size);
|
||||
switch (op_id) {
|
||||
case OperationId::Invalidate:
|
||||
{
|
||||
fs::QueryRangeInfo dummy_range_info;
|
||||
R_RETURN(m_x->OperateRange(std::addressof(dummy_range_info), static_cast<s32>(op_id), offset, size));
|
||||
}
|
||||
case OperationId::QueryRange:
|
||||
{
|
||||
R_UNLESS(dst != nullptr, fs::ResultNullptrArgument());
|
||||
R_UNLESS(dst_size == sizeof(fs::QueryRangeInfo), fs::ResultInvalidSize());
|
||||
|
||||
R_RETURN(m_x->OperateRange(reinterpret_cast<fs::QueryRangeInfo *>(dst), static_cast<s32>(op_id), offset, size));
|
||||
}
|
||||
default:
|
||||
{
|
||||
R_THROW(fs::ResultUnsupportedOperateRangeForStorageServiceObjectAdapter());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue