Implement support for parsing/interacting with NCAs. (#942)
* fs: implement support for interacting with ncas. * spl: extend to use virtual keyslots
This commit is contained in:
@@ -17,11 +17,14 @@
|
||||
#include <stratosphere/fs/fs_common.hpp>
|
||||
#include <stratosphere/fs/fs_istorage.hpp>
|
||||
#include <stratosphere/fs/fsa/fs_ifile.hpp>
|
||||
#include <stratosphere/fs/fsa/fs_ifilesystem.hpp>
|
||||
#include <stratosphere/fs/impl/fs_newable.hpp>
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
class FileStorage : public IStorage, public impl::Newable {
|
||||
NON_COPYABLE(FileStorage);
|
||||
NON_MOVEABLE(FileStorage);
|
||||
private:
|
||||
static constexpr s64 InvalidSize = -1;
|
||||
private:
|
||||
@@ -43,8 +46,25 @@ namespace ams::fs {
|
||||
}
|
||||
|
||||
virtual ~FileStorage() { /* ... */ }
|
||||
protected:
|
||||
private:
|
||||
Result UpdateSize();
|
||||
protected:
|
||||
constexpr FileStorage() : unique_file(), shared_file(), base_file(nullptr), size(InvalidSize) { /* ... */ }
|
||||
|
||||
void SetFile(fs::fsa::IFile *file) {
|
||||
AMS_ASSERT(file != nullptr);
|
||||
AMS_ASSERT(this->base_file == nullptr);
|
||||
this->base_file = file;
|
||||
}
|
||||
|
||||
void SetFile(std::unique_ptr<fs::fsa::IFile> &&file) {
|
||||
AMS_ASSERT(file != nullptr);
|
||||
AMS_ASSERT(this->base_file == nullptr);
|
||||
AMS_ASSERT(this->unique_file == nullptr);
|
||||
|
||||
this->unique_file = std::move(file);
|
||||
this->base_file = this->unique_file.get();
|
||||
}
|
||||
public:
|
||||
virtual Result Read(s64 offset, void *buffer, size_t size) override;
|
||||
virtual Result Write(s64 offset, const void *buffer, size_t size) override;
|
||||
@@ -54,6 +74,17 @@ namespace ams::fs {
|
||||
virtual Result OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override;
|
||||
};
|
||||
|
||||
class FileStorageBasedFileSystem : public FileStorage {
|
||||
NON_COPYABLE(FileStorageBasedFileSystem);
|
||||
NON_MOVEABLE(FileStorageBasedFileSystem);
|
||||
private:
|
||||
std::shared_ptr<fs::fsa::IFileSystem> base_file_system;
|
||||
public:
|
||||
constexpr FileStorageBasedFileSystem() : FileStorage(), base_file_system(nullptr) { /* ... */ }
|
||||
|
||||
Result Initialize(std::shared_ptr<fs::fsa::IFileSystem> base_file_system, const char *path, fs::OpenMode mode);
|
||||
};
|
||||
|
||||
class FileHandleStorage : public IStorage, public impl::Newable {
|
||||
private:
|
||||
static constexpr s64 InvalidSize = -1;
|
||||
|
||||
@@ -46,6 +46,17 @@ namespace ams::fs {
|
||||
return std::unique_ptr<T, Deleter>(static_cast<T *>(::ams::fs::impl::Allocate(sizeof(T))), Deleter(sizeof(T)));
|
||||
}
|
||||
|
||||
template<typename ArrayT>
|
||||
std::unique_ptr<ArrayT, Deleter> MakeUnique(size_t size) {
|
||||
using T = typename std::remove_extent<ArrayT>::type;
|
||||
|
||||
static_assert(std::is_pod<ArrayT>::value);
|
||||
static_assert(std::is_array<ArrayT>::value);
|
||||
|
||||
const size_t alloc_size = sizeof(T) * size;
|
||||
return std::unique_ptr<ArrayT, Deleter>(static_cast<T *>(::ams::fs::impl::Allocate(alloc_size)), Deleter(alloc_size));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ namespace ams::fs {
|
||||
|
||||
enum class AesCtrKeyTypeFlag : s32 {
|
||||
InternalKeyForSoftwareAes = (1 << 0),
|
||||
InternalKeyForHardwareAes = (1 << 1),
|
||||
ExternalKeyForHardwareAes = (1 << 2),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -156,4 +156,14 @@ namespace ams::fs {
|
||||
static_assert(sizeof(SaveDataExtraData) == 0x200);
|
||||
static_assert(util::is_pod<SaveDataExtraData>::value);
|
||||
|
||||
struct HashSalt {
|
||||
static constexpr size_t Size = 32;
|
||||
|
||||
u8 value[Size];
|
||||
};
|
||||
static_assert(std::is_pod<HashSalt>::value);
|
||||
static_assert(sizeof(HashSalt) == HashSalt::Size);
|
||||
|
||||
using SaveDataHashSalt = std::optional<HashSalt>;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 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/fs/fs_common.hpp>
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
enum class SpeedEmulationMode {
|
||||
None = 0,
|
||||
Faster = 1,
|
||||
Slower = 2,
|
||||
Random = 3,
|
||||
};
|
||||
|
||||
/* TODO */
|
||||
/* Result SetSpeedEmulationMode(SpeedEmulationMode mode); */
|
||||
/* Result GetSpeedEmulationMode(SpeedEmulationMode *out); */
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 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 <vapours.hpp>
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
enum StorageType : s32 {
|
||||
StorageType_SaveData = 0,
|
||||
StorageType_RomFs = 1,
|
||||
StorageType_Authoring = 2,
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user