2020-05-11 22:04:51 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2020-05-11 22:04:51 +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/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <vapours.hpp>
|
|
|
|
#include <stratosphere/fssystem/fssystem_indirect_storage.hpp>
|
|
|
|
|
|
|
|
namespace ams::fssystem {
|
|
|
|
|
2022-03-24 15:43:40 +00:00
|
|
|
/* ACCURATE_TO_VERSION: Unknown */
|
|
|
|
|
2020-05-11 22:04:51 +00:00
|
|
|
class SparseStorage : public IndirectStorage {
|
|
|
|
NON_COPYABLE(SparseStorage);
|
|
|
|
NON_MOVEABLE(SparseStorage);
|
|
|
|
private:
|
|
|
|
class ZeroStorage : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable {
|
|
|
|
public:
|
|
|
|
ZeroStorage() { /* ... */ }
|
|
|
|
virtual ~ZeroStorage() { /* ... */ }
|
|
|
|
|
|
|
|
virtual Result Read(s64 offset, void *buffer, size_t size) override {
|
|
|
|
AMS_ASSERT(offset >= 0);
|
|
|
|
AMS_ASSERT(buffer != nullptr || size == 0);
|
2021-10-07 00:58:42 +00:00
|
|
|
AMS_UNUSED(offset);
|
|
|
|
|
2020-05-11 22:04:51 +00:00
|
|
|
if (size > 0) {
|
|
|
|
std::memset(buffer, 0, size);
|
|
|
|
}
|
2022-03-12 21:03:17 +00:00
|
|
|
R_SUCCEED();
|
2020-05-11 22:04:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2021-10-07 00:58:42 +00:00
|
|
|
AMS_UNUSED(dst, dst_size, op_id, offset, size, src, src_size);
|
2022-03-12 21:03:17 +00:00
|
|
|
R_SUCCEED();
|
2020-05-11 22:04:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual Result GetSize(s64 *out) override {
|
|
|
|
AMS_ASSERT(out != nullptr);
|
|
|
|
*out = std::numeric_limits<s64>::max();
|
2022-03-12 21:03:17 +00:00
|
|
|
R_SUCCEED();
|
2020-05-11 22:04:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual Result Flush() override {
|
2022-03-12 21:03:17 +00:00
|
|
|
R_SUCCEED();
|
2020-05-11 22:04:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual Result Write(s64 offset, const void *buffer, size_t size) override {
|
2021-10-07 00:58:42 +00:00
|
|
|
AMS_UNUSED(offset, buffer, size);
|
2022-03-13 09:32:34 +00:00
|
|
|
R_THROW(fs::ResultUnsupportedWriteForZeroStorage());
|
2020-05-11 22:04:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual Result SetSize(s64 size) override {
|
2021-10-07 00:58:42 +00:00
|
|
|
AMS_UNUSED(size);
|
2022-03-13 09:32:34 +00:00
|
|
|
R_THROW(fs::ResultUnsupportedSetSizeForZeroStorage());
|
2020-05-11 22:04:51 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
private:
|
2021-10-10 07:14:06 +00:00
|
|
|
ZeroStorage m_zero_storage;
|
2020-05-11 22:04:51 +00:00
|
|
|
public:
|
2021-10-10 07:14:06 +00:00
|
|
|
SparseStorage() : IndirectStorage(), m_zero_storage() { /* ... */ }
|
2020-05-11 22:04:51 +00:00
|
|
|
virtual ~SparseStorage() { /* ... */ }
|
|
|
|
|
|
|
|
using IndirectStorage::Initialize;
|
|
|
|
|
|
|
|
void Initialize(s64 end_offset) {
|
|
|
|
this->GetEntryTable().Initialize(NodeSize, end_offset);
|
|
|
|
this->SetZeroStorage();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDataStorage(fs::SubStorage storage) {
|
|
|
|
AMS_ASSERT(this->IsInitialized());
|
|
|
|
|
|
|
|
this->SetStorage(0, storage);
|
|
|
|
this->SetZeroStorage();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void SetDataStorage(T storage, s64 offset, s64 size) {
|
|
|
|
AMS_ASSERT(this->IsInitialized());
|
|
|
|
|
|
|
|
this->SetStorage(0, storage, offset, size);
|
|
|
|
this->SetZeroStorage();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Result Read(s64 offset, void *buffer, size_t size) override;
|
|
|
|
private:
|
|
|
|
void SetZeroStorage() {
|
2021-10-10 07:14:06 +00:00
|
|
|
return this->SetStorage(1, std::addressof(m_zero_storage), 0, std::numeric_limits<s64>::max());
|
2020-05-11 22:04:51 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|