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