2019-12-09 11:57:37 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2019-12-09 11:57:37 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
#include <stratosphere.hpp>
|
|
|
|
#include <stratosphere/fssrv/fssrv_interface_adapters.hpp>
|
2022-03-06 20:08:20 +00:00
|
|
|
#include "fssrv_retry_utility.hpp"
|
2019-12-09 11:57:37 +00:00
|
|
|
|
|
|
|
namespace ams::fssrv::impl {
|
|
|
|
|
|
|
|
Result StorageInterfaceAdapter::Read(s64 offset, const ams::sf::OutNonSecureBuffer &buffer, s64 size) {
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Check pre-conditions. */
|
|
|
|
R_UNLESS(0 <= offset, fs::ResultInvalidOffset());
|
|
|
|
R_UNLESS(0 <= size, fs::ResultInvalidSize());
|
|
|
|
R_UNLESS(size <= static_cast<s64>(buffer.GetSize()), fs::ResultInvalidSize());
|
|
|
|
|
|
|
|
R_RETURN(RetryFinitelyForDataCorrupted([&] () ALWAYS_INLINE_LAMBDA {
|
|
|
|
R_RETURN(m_base_storage->Read(offset, buffer.GetPointer(), size));
|
|
|
|
}));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result StorageInterfaceAdapter::Write(s64 offset, const ams::sf::InNonSecureBuffer &buffer, s64 size) {
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Check pre-conditions. */
|
|
|
|
R_UNLESS(0 <= offset, fs::ResultInvalidOffset());
|
|
|
|
R_UNLESS(0 <= size, fs::ResultInvalidSize());
|
|
|
|
R_UNLESS(size <= static_cast<s64>(buffer.GetSize()), fs::ResultInvalidSize());
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Temporarily increase our thread's priority. */
|
|
|
|
fssystem::ScopedThreadPriorityChangerByAccessPriority cp(fssystem::ScopedThreadPriorityChangerByAccessPriority::AccessMode::Write);
|
|
|
|
|
|
|
|
R_RETURN(m_base_storage->Write(offset, buffer.GetPointer(), size));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result StorageInterfaceAdapter::Flush() {
|
2022-03-06 20:08:20 +00:00
|
|
|
R_RETURN(m_base_storage->Flush());
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result StorageInterfaceAdapter::SetSize(s64 size) {
|
|
|
|
R_UNLESS(size >= 0, fs::ResultInvalidSize());
|
2022-03-06 20:08:20 +00:00
|
|
|
R_RETURN(m_base_storage->SetSize(size));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result StorageInterfaceAdapter::GetSize(ams::sf::Out<s64> out) {
|
2022-03-06 20:08:20 +00:00
|
|
|
R_RETURN(m_base_storage->GetSize(out.GetPointer()));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result StorageInterfaceAdapter::OperateRange(ams::sf::Out<fs::StorageQueryRangeInfo> out, s32 op_id, s64 offset, s64 size) {
|
|
|
|
/* N includes this redundant check, so we will too. */
|
|
|
|
R_UNLESS(out.GetPointer() != nullptr, fs::ResultNullptrArgument());
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Clear the range info. */
|
2019-12-09 11:57:37 +00:00
|
|
|
out->Clear();
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
if (op_id == static_cast<s32>(fs::OperationId::QueryRange)) {
|
|
|
|
fs::FileQueryRangeInfo info;
|
2021-10-10 07:14:06 +00:00
|
|
|
R_TRY(m_base_storage->OperateRange(std::addressof(info), sizeof(info), fs::OperationId::QueryRange, offset, size, nullptr, 0));
|
2019-12-09 11:57:37 +00:00
|
|
|
out->Merge(info);
|
2022-03-06 20:08:20 +00:00
|
|
|
} else if (op_id == static_cast<s32>(fs::OperationId::Invalidate)) {
|
|
|
|
R_TRY(m_base_storage->OperateRange(nullptr, 0, fs::OperationId::Invalidate, offset, size, nullptr, 0));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
R_SUCCEED();
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|