2019-12-09 11:57:37 +00:00
|
|
|
/*
|
2021-10-04 20:59:10 +01: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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2021-10-01 03:21:08 +01:00
|
|
|
#include <stratosphere/fs/fs_common.hpp>
|
|
|
|
#include <stratosphere/fs/fs_filesystem.hpp>
|
|
|
|
#include <stratosphere/fs/fs_filesystem_for_debug.hpp>
|
2022-03-06 20:08:20 +00:00
|
|
|
#include <stratosphere/fs/fs_path.hpp>
|
2019-12-09 11:57:37 +00:00
|
|
|
|
|
|
|
namespace ams::fs::fsa {
|
|
|
|
|
2022-03-24 15:43:40 +00:00
|
|
|
/* ACCURATE_TO_VERSION: Unknown */
|
2019-12-09 11:57:37 +00:00
|
|
|
class IFile;
|
|
|
|
class IDirectory;
|
|
|
|
|
|
|
|
enum class QueryId {
|
2020-03-08 08:06:23 +00:00
|
|
|
SetConcatenationFileAttribute = 0,
|
2022-03-06 20:08:20 +00:00
|
|
|
UpdateMac = 1,
|
2020-03-08 08:06:23 +00:00
|
|
|
IsSignedSystemPartitionOnSdCardValid = 2,
|
2022-03-06 20:08:20 +00:00
|
|
|
QueryUnpreparedFileInformation = 3,
|
2019-12-09 11:57:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class IFileSystem {
|
|
|
|
public:
|
|
|
|
virtual ~IFileSystem() { /* ... */ }
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result CreateFile(const fs::Path &path, s64 size, int option) {
|
|
|
|
R_UNLESS(size >= 0, fs::ResultOutOfRange());
|
|
|
|
R_RETURN(this->DoCreateFile(path, size, option));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result CreateFile(const fs::Path &path, s64 size) {
|
|
|
|
R_RETURN(this->CreateFile(path, size, fs::CreateOption_None));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result DeleteFile(const fs::Path &path) {
|
|
|
|
R_RETURN(this->DoDeleteFile(path));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result CreateDirectory(const fs::Path &path) {
|
|
|
|
R_RETURN(this->DoCreateDirectory(path));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result DeleteDirectory(const fs::Path &path) {
|
|
|
|
R_RETURN(this->DoDeleteDirectory(path));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result DeleteDirectoryRecursively(const fs::Path &path) {
|
|
|
|
R_RETURN(this->DoDeleteDirectoryRecursively(path));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result RenameFile(const fs::Path &old_path, const fs::Path &new_path) {
|
|
|
|
R_RETURN(this->DoRenameFile(old_path, new_path));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result RenameDirectory(const fs::Path &old_path, const fs::Path &new_path) {
|
|
|
|
R_RETURN(this->DoRenameDirectory(old_path, new_path));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result GetEntryType(DirectoryEntryType *out, const fs::Path &path) {
|
|
|
|
R_RETURN(this->DoGetEntryType(out, path));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result OpenFile(std::unique_ptr<IFile> *out_file, const fs::Path &path, OpenMode mode) {
|
2019-12-09 11:57:37 +00:00
|
|
|
R_UNLESS(out_file != nullptr, fs::ResultNullptrArgument());
|
2020-04-04 10:37:21 +01:00
|
|
|
R_UNLESS((mode & OpenMode_ReadWrite) != 0, fs::ResultInvalidOpenMode());
|
|
|
|
R_UNLESS((mode & ~OpenMode_All) == 0, fs::ResultInvalidOpenMode());
|
2022-03-06 20:08:20 +00:00
|
|
|
R_RETURN(this->DoOpenFile(out_file, path, mode));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result OpenDirectory(std::unique_ptr<IDirectory> *out_dir, const fs::Path &path, OpenDirectoryMode mode) {
|
2020-03-08 08:06:23 +00:00
|
|
|
R_UNLESS(out_dir != nullptr, fs::ResultNullptrArgument());
|
2020-04-04 10:37:21 +01:00
|
|
|
R_UNLESS((mode & OpenDirectoryMode_All) != 0, fs::ResultInvalidOpenMode());
|
|
|
|
R_UNLESS((mode & ~(OpenDirectoryMode_All | OpenDirectoryMode_NotRequireFileSize)) == 0, fs::ResultInvalidOpenMode());
|
2022-03-06 20:08:20 +00:00
|
|
|
R_RETURN(this->DoOpenDirectory(out_dir, path, mode));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result Commit() {
|
2022-03-06 20:08:20 +00:00
|
|
|
R_RETURN(this->DoCommit());
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result GetFreeSpaceSize(s64 *out, const fs::Path &path) {
|
2019-12-09 11:57:37 +00:00
|
|
|
R_UNLESS(out != nullptr, fs::ResultNullptrArgument());
|
2022-03-06 20:08:20 +00:00
|
|
|
R_RETURN(this->DoGetFreeSpaceSize(out, path));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result GetTotalSpaceSize(s64 *out, const fs::Path &path) {
|
2019-12-09 11:57:37 +00:00
|
|
|
R_UNLESS(out != nullptr, fs::ResultNullptrArgument());
|
2022-03-06 20:08:20 +00:00
|
|
|
R_RETURN(this->DoGetTotalSpaceSize(out, path));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result CleanDirectoryRecursively(const fs::Path &path) {
|
|
|
|
R_RETURN(this->DoCleanDirectoryRecursively(path));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result GetFileTimeStampRaw(FileTimeStampRaw *out, const fs::Path &path) {
|
2019-12-09 11:57:37 +00:00
|
|
|
R_UNLESS(out != nullptr, fs::ResultNullptrArgument());
|
2022-03-06 20:08:20 +00:00
|
|
|
R_RETURN(this->DoGetFileTimeStampRaw(out, path));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result QueryEntry(char *dst, size_t dst_size, const char *src, size_t src_size, QueryId query, const fs::Path &path) {
|
|
|
|
R_RETURN(this->DoQueryEntry(dst, dst_size, src, src_size, query, path));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* These aren't accessible as commands. */
|
|
|
|
|
|
|
|
Result CommitProvisionally(s64 counter) {
|
2022-03-06 20:08:20 +00:00
|
|
|
R_RETURN(this->DoCommitProvisionally(counter));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result Rollback() {
|
2022-03-06 20:08:20 +00:00
|
|
|
R_RETURN(this->DoRollback());
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result Flush() {
|
2022-03-06 20:08:20 +00:00
|
|
|
R_RETURN(this->DoFlush());
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/* ...? */
|
|
|
|
private:
|
2022-03-06 20:08:20 +00:00
|
|
|
virtual Result DoCreateFile(const fs::Path &path, s64 size, int flags) = 0;
|
|
|
|
virtual Result DoDeleteFile(const fs::Path &path) = 0;
|
|
|
|
virtual Result DoCreateDirectory(const fs::Path &path) = 0;
|
|
|
|
virtual Result DoDeleteDirectory(const fs::Path &path) = 0;
|
|
|
|
virtual Result DoDeleteDirectoryRecursively(const fs::Path &path) = 0;
|
|
|
|
virtual Result DoRenameFile(const fs::Path &old_path, const fs::Path &new_path) = 0;
|
|
|
|
virtual Result DoRenameDirectory(const fs::Path &old_path, const fs::Path &new_path) = 0;
|
|
|
|
virtual Result DoGetEntryType(fs::DirectoryEntryType *out, const fs::Path &path) = 0;
|
|
|
|
virtual Result DoOpenFile(std::unique_ptr<fs::fsa::IFile> *out_file, const fs::Path &path, fs::OpenMode mode) = 0;
|
|
|
|
virtual Result DoOpenDirectory(std::unique_ptr<fs::fsa::IDirectory> *out_dir, const fs::Path &path, fs::OpenDirectoryMode mode) = 0;
|
2020-12-05 11:05:06 +00:00
|
|
|
virtual Result DoCommit() = 0;
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
virtual Result DoGetFreeSpaceSize(s64 *out, const fs::Path &path) {
|
2021-10-07 01:58:42 +01:00
|
|
|
AMS_UNUSED(out, path);
|
2022-03-06 20:08:20 +00:00
|
|
|
R_THROW(fs::ResultNotImplemented());
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
virtual Result DoGetTotalSpaceSize(s64 *out, const fs::Path &path) {
|
2021-10-07 01:58:42 +01:00
|
|
|
AMS_UNUSED(out, path);
|
2022-03-06 20:08:20 +00:00
|
|
|
R_THROW(fs::ResultNotImplemented());
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
virtual Result DoCleanDirectoryRecursively(const fs::Path &path) = 0;
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
virtual Result DoGetFileTimeStampRaw(fs::FileTimeStampRaw *out, const fs::Path &path) {
|
2021-10-07 01:58:42 +01:00
|
|
|
AMS_UNUSED(out, path);
|
2022-03-06 20:08:20 +00:00
|
|
|
R_THROW(fs::ResultNotImplemented());
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
virtual Result DoQueryEntry(char *dst, size_t dst_size, const char *src, size_t src_size, fs::fsa::QueryId query, const fs::Path &path) {
|
2021-10-07 01:58:42 +01:00
|
|
|
AMS_UNUSED(dst, dst_size, src, src_size, query, path);
|
2022-03-06 20:08:20 +00:00
|
|
|
R_THROW(fs::ResultNotImplemented());
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* These aren't accessible as commands. */
|
2020-12-05 11:05:06 +00:00
|
|
|
virtual Result DoCommitProvisionally(s64 counter) {
|
2021-10-07 01:58:42 +01:00
|
|
|
AMS_UNUSED(counter);
|
2022-03-06 20:08:20 +00:00
|
|
|
R_THROW(fs::ResultNotImplemented());
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-05 11:05:06 +00:00
|
|
|
virtual Result DoRollback() {
|
2022-03-06 20:08:20 +00:00
|
|
|
R_THROW(fs::ResultNotImplemented());
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-05 11:05:06 +00:00
|
|
|
virtual Result DoFlush() {
|
2022-03-06 20:08:20 +00:00
|
|
|
R_THROW(fs::ResultNotImplemented());
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-24 23:21:03 +00:00
|
|
|
template<typename T>
|
|
|
|
concept PointerToFileSystem = ::ams::util::RawOrSmartPointerTo<T, ::ams::fs::fsa::IFileSystem>;
|
|
|
|
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|