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>
|
|
|
|
|
|
|
|
namespace ams::fssystem {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
constexpr size_t IdealWorkBufferSize = 1_MB;
|
|
|
|
constexpr size_t MinimumWorkBufferSize = 1_KB;
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
constexpr const fs::Path CommittedDirectoryPath = fs::MakeConstantPath("/0");
|
|
|
|
constexpr const fs::Path WorkingDirectoryPath = fs::MakeConstantPath("/1");
|
|
|
|
constexpr const fs::Path SynchronizingDirectoryPath = fs::MakeConstantPath("/_");
|
|
|
|
constexpr const fs::Path LockFilePath = fs::MakeConstantPath("/.lock");
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
class DirectorySaveDataFile : public fs::fsa::IFile, public fs::impl::Newable {
|
2019-12-09 11:57:37 +00:00
|
|
|
private:
|
2021-10-10 07:14:06 +00:00
|
|
|
std::unique_ptr<fs::fsa::IFile> m_base_file;
|
|
|
|
DirectorySaveDataFileSystem *m_parent_fs;
|
|
|
|
fs::OpenMode m_open_mode;
|
2019-12-09 11:57:37 +00:00
|
|
|
public:
|
2021-10-10 07:14:06 +00:00
|
|
|
DirectorySaveDataFile(std::unique_ptr<fs::fsa::IFile> f, DirectorySaveDataFileSystem *p, fs::OpenMode m) : m_base_file(std::move(f)), m_parent_fs(p), m_open_mode(m) {
|
2019-12-09 11:57:37 +00:00
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~DirectorySaveDataFile() {
|
|
|
|
/* Observe closing of writable file. */
|
2021-10-10 07:14:06 +00:00
|
|
|
if (m_open_mode & fs::OpenMode_Write) {
|
2022-03-06 20:08:20 +00:00
|
|
|
m_parent_fs->DecrementWriteOpenFileCount();
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
public:
|
2020-12-05 11:05:06 +00:00
|
|
|
virtual Result DoRead(size_t *out, s64 offset, void *buffer, size_t size, const fs::ReadOption &option) override {
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(m_base_file->Read(out, offset, buffer, size, option));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-05 11:05:06 +00:00
|
|
|
virtual Result DoGetSize(s64 *out) override {
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(m_base_file->GetSize(out));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-05 11:05:06 +00:00
|
|
|
virtual Result DoFlush() override {
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(m_base_file->Flush());
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-05 11:05:06 +00:00
|
|
|
virtual Result DoWrite(s64 offset, const void *buffer, size_t size, const fs::WriteOption &option) override {
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(m_base_file->Write(offset, buffer, size, option));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-05 11:05:06 +00:00
|
|
|
virtual Result DoSetSize(s64 size) override {
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(m_base_file->SetSize(size));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-05 11:05:06 +00:00
|
|
|
virtual Result DoOperateRange(void *dst, size_t dst_size, fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override {
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(m_base_file->OperateRange(dst, dst_size, op_id, offset, size, src, src_size));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
public:
|
|
|
|
virtual sf::cmif::DomainObjectId GetDomainObjectId() const override {
|
2021-10-10 07:14:06 +00:00
|
|
|
return m_base_file->GetDomainObjectId();
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result DirectorySaveDataFileSystem::Initialize(bool journaling_supported, bool multi_commit_supported, bool journaling_enabled) {
|
|
|
|
/* Configure ourselves. */
|
|
|
|
m_is_journaling_supported = journaling_supported;
|
|
|
|
m_is_multi_commit_supported = multi_commit_supported;
|
|
|
|
m_is_journaling_enabled = journaling_enabled;
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Ensure that we can initialize further by acquiring a lock on the filesystem. */
|
|
|
|
R_TRY(this->AcquireLockFile());
|
2019-12-09 11:57:37 +00:00
|
|
|
|
|
|
|
fs::DirectoryEntryType type;
|
|
|
|
|
|
|
|
/* Check that the working directory exists. */
|
2021-10-10 07:14:06 +00:00
|
|
|
R_TRY_CATCH(m_base_fs->GetEntryType(std::addressof(type), WorkingDirectoryPath)) {
|
2019-12-09 11:57:37 +00:00
|
|
|
/* If path isn't found, create working directory and committed directory. */
|
|
|
|
R_CATCH(fs::ResultPathNotFound) {
|
2021-10-10 07:14:06 +00:00
|
|
|
R_TRY(m_base_fs->CreateDirectory(WorkingDirectoryPath));
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
if (m_is_journaling_supported) {
|
|
|
|
R_TRY(m_base_fs->CreateDirectory(CommittedDirectoryPath));
|
|
|
|
}
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
} R_END_TRY_CATCH;
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* If we support journaling, we need to set up the committed directory. */
|
|
|
|
if (m_is_journaling_supported) {
|
|
|
|
/* Now check for the committed directory. */
|
|
|
|
R_TRY_CATCH(m_base_fs->GetEntryType(std::addressof(type), CommittedDirectoryPath)) {
|
|
|
|
/* Committed doesn't exist, so synchronize and rename. */
|
|
|
|
R_CATCH(fs::ResultPathNotFound) {
|
|
|
|
R_TRY(this->SynchronizeDirectory(SynchronizingDirectoryPath, WorkingDirectoryPath));
|
|
|
|
R_TRY(m_base_fs->RenameDirectory(SynchronizingDirectoryPath, CommittedDirectoryPath));
|
|
|
|
R_SUCCEED();
|
|
|
|
}
|
|
|
|
} R_END_TRY_CATCH;
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* The committed directory exists, so if we should, synchronize it to the working directory. */
|
|
|
|
if (m_is_journaling_enabled) {
|
|
|
|
R_TRY(this->SynchronizeDirectory(WorkingDirectoryPath, CommittedDirectoryPath));
|
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
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result DirectorySaveDataFileSystem::SynchronizeDirectory(const fs::Path &dst, const fs::Path &src) {
|
2019-12-09 11:57:37 +00:00
|
|
|
/* Delete destination dir and recreate it. */
|
2021-10-10 07:14:06 +00:00
|
|
|
R_TRY_CATCH(m_base_fs->DeleteDirectoryRecursively(dst)) {
|
2019-12-09 11:57:37 +00:00
|
|
|
R_CATCH(fs::ResultPathNotFound) { /* Nintendo returns error unconditionally, but I think that's a bug in their code. */}
|
|
|
|
} R_END_TRY_CATCH;
|
|
|
|
|
2021-10-10 07:14:06 +00:00
|
|
|
R_TRY(m_base_fs->CreateDirectory(dst));
|
2019-12-09 11:57:37 +00:00
|
|
|
|
|
|
|
/* Get a work buffer to work with. */
|
2022-03-06 20:08:20 +00:00
|
|
|
fssystem::PooledBuffer buffer;
|
|
|
|
buffer.AllocateParticularlyLarge(IdealWorkBufferSize, MinimumWorkBufferSize);
|
2019-12-09 11:57:37 +00:00
|
|
|
|
|
|
|
/* Copy the directory recursively. */
|
2022-03-06 20:08:20 +00:00
|
|
|
fs::DirectoryEntry dir_entry_buffer = {};
|
|
|
|
R_RETURN(fssystem::CopyDirectoryRecursively(m_base_fs, dst, src, std::addressof(dir_entry_buffer), buffer.GetBuffer(), buffer.GetSize()));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result DirectorySaveDataFileSystem::ResolvePath(fs::Path *out, const fs::Path &path) {
|
|
|
|
const fs::Path &directory = (m_is_journaling_supported && !m_is_journaling_enabled) ? CommittedDirectoryPath : WorkingDirectoryPath;
|
|
|
|
R_RETURN(out->Combine(directory, path));
|
|
|
|
}
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result DirectorySaveDataFileSystem::AcquireLockFile() {
|
|
|
|
/* If we already have a lock file, we don't need to lock again. */
|
|
|
|
R_SUCCEED_IF(m_lock_file != nullptr);
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Open the lock file. */
|
|
|
|
std::unique_ptr<fs::fsa::IFile> file;
|
|
|
|
R_TRY_CATCH(m_base_fs->OpenFile(std::addressof(file), LockFilePath, fs::OpenMode_ReadWrite)) {
|
|
|
|
/* If the lock file doesn't yet exist, we may need to create it. */
|
|
|
|
R_CATCH(fs::ResultPathNotFound) {
|
|
|
|
R_TRY(m_base_fs->CreateFile(LockFilePath, 0));
|
|
|
|
R_TRY(m_base_fs->OpenFile(std::addressof(file), LockFilePath, fs::OpenMode_ReadWrite));
|
|
|
|
}
|
|
|
|
} R_END_TRY_CATCH;
|
|
|
|
|
|
|
|
/* Set our lock file. */
|
|
|
|
m_lock_file = std::move(file);
|
|
|
|
R_SUCCEED();
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
void DirectorySaveDataFileSystem::DecrementWriteOpenFileCount() {
|
2021-10-10 07:14:06 +00:00
|
|
|
std::scoped_lock lk(m_accessor_mutex);
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
--m_open_writable_files;
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result DirectorySaveDataFileSystem::DoCreateFile(const fs::Path &path, s64 size, int option) {
|
|
|
|
/* Resolve the final path. */
|
|
|
|
fs::Path resolved;
|
|
|
|
R_TRY(this->ResolvePath(std::addressof(resolved), path));
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Lock ourselves. */
|
|
|
|
std::scoped_lock lk(m_accessor_mutex);
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
R_RETURN(m_base_fs->CreateFile(resolved, size, option));
|
|
|
|
}
|
|
|
|
Result DirectorySaveDataFileSystem::DoDeleteFile(const fs::Path &path) {
|
|
|
|
/* Resolve the final path. */
|
|
|
|
fs::Path resolved;
|
|
|
|
R_TRY(this->ResolvePath(std::addressof(resolved), path));
|
|
|
|
|
|
|
|
/* Lock ourselves. */
|
|
|
|
std::scoped_lock lk(m_accessor_mutex);
|
|
|
|
|
|
|
|
R_RETURN(m_base_fs->DeleteFile(resolved));
|
|
|
|
}
|
|
|
|
|
|
|
|
Result DirectorySaveDataFileSystem::DoCreateDirectory(const fs::Path &path) {
|
|
|
|
/* Resolve the final path. */
|
|
|
|
fs::Path resolved;
|
|
|
|
R_TRY(this->ResolvePath(std::addressof(resolved), path));
|
|
|
|
|
|
|
|
/* Lock ourselves. */
|
|
|
|
std::scoped_lock lk(m_accessor_mutex);
|
|
|
|
|
|
|
|
R_RETURN(m_base_fs->CreateDirectory(resolved));
|
|
|
|
}
|
|
|
|
|
|
|
|
Result DirectorySaveDataFileSystem::DoDeleteDirectory(const fs::Path &path) {
|
|
|
|
/* Resolve the final path. */
|
|
|
|
fs::Path resolved;
|
|
|
|
R_TRY(this->ResolvePath(std::addressof(resolved), path));
|
|
|
|
|
|
|
|
/* Lock ourselves. */
|
|
|
|
std::scoped_lock lk(m_accessor_mutex);
|
|
|
|
|
|
|
|
R_RETURN(m_base_fs->DeleteDirectory(resolved));
|
|
|
|
}
|
|
|
|
|
|
|
|
Result DirectorySaveDataFileSystem::DoDeleteDirectoryRecursively(const fs::Path &path) {
|
|
|
|
/* Resolve the final path. */
|
|
|
|
fs::Path resolved;
|
|
|
|
R_TRY(this->ResolvePath(std::addressof(resolved), path));
|
|
|
|
|
|
|
|
/* Lock ourselves. */
|
|
|
|
std::scoped_lock lk(m_accessor_mutex);
|
|
|
|
|
|
|
|
R_RETURN(m_base_fs->DeleteDirectoryRecursively(resolved));
|
|
|
|
}
|
|
|
|
|
|
|
|
Result DirectorySaveDataFileSystem::DoRenameFile(const fs::Path &old_path, const fs::Path &new_path) {
|
|
|
|
/* Resolve the final paths. */
|
|
|
|
fs::Path old_resolved;
|
|
|
|
fs::Path new_resolved;
|
|
|
|
R_TRY(this->ResolvePath(std::addressof(old_resolved), old_path));
|
|
|
|
R_TRY(this->ResolvePath(std::addressof(new_resolved), new_path));
|
|
|
|
|
|
|
|
/* Lock ourselves. */
|
|
|
|
std::scoped_lock lk(m_accessor_mutex);
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
R_RETURN(m_base_fs->RenameFile(old_resolved, new_resolved));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result DirectorySaveDataFileSystem::DoRenameDirectory(const fs::Path &old_path, const fs::Path &new_path) {
|
|
|
|
/* Resolve the final paths. */
|
|
|
|
fs::Path old_resolved;
|
|
|
|
fs::Path new_resolved;
|
|
|
|
R_TRY(this->ResolvePath(std::addressof(old_resolved), old_path));
|
|
|
|
R_TRY(this->ResolvePath(std::addressof(new_resolved), new_path));
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Lock ourselves. */
|
2021-10-10 07:14:06 +00:00
|
|
|
std::scoped_lock lk(m_accessor_mutex);
|
2022-03-06 20:08:20 +00:00
|
|
|
|
|
|
|
R_RETURN(m_base_fs->RenameDirectory(old_resolved, new_resolved));
|
|
|
|
}
|
|
|
|
|
|
|
|
Result DirectorySaveDataFileSystem::DoGetEntryType(fs::DirectoryEntryType *out, const fs::Path &path) {
|
|
|
|
/* Resolve the final path. */
|
|
|
|
fs::Path resolved;
|
|
|
|
R_TRY(this->ResolvePath(std::addressof(resolved), path));
|
|
|
|
|
|
|
|
/* Lock ourselves. */
|
|
|
|
std::scoped_lock lk(m_accessor_mutex);
|
|
|
|
|
|
|
|
R_RETURN(m_base_fs->GetEntryType(out, resolved));
|
|
|
|
}
|
|
|
|
|
|
|
|
Result DirectorySaveDataFileSystem::DoOpenFile(std::unique_ptr<fs::fsa::IFile> *out_file, const fs::Path &path, fs::OpenMode mode) {
|
|
|
|
/* Resolve the final path. */
|
|
|
|
fs::Path resolved;
|
|
|
|
R_TRY(this->ResolvePath(std::addressof(resolved), path));
|
|
|
|
|
|
|
|
/* Lock ourselves. */
|
|
|
|
std::scoped_lock lk(m_accessor_mutex);
|
|
|
|
|
|
|
|
/* Open base file. */
|
2019-12-09 11:57:37 +00:00
|
|
|
std::unique_ptr<fs::fsa::IFile> base_file;
|
2022-03-06 20:08:20 +00:00
|
|
|
R_TRY(m_base_fs->OpenFile(std::addressof(base_file), resolved, mode));
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Make DirectorySaveDataFile. */
|
|
|
|
std::unique_ptr<fs::fsa::IFile> file = std::make_unique<DirectorySaveDataFile>(std::move(base_file), this, mode);
|
2022-03-13 09:51:42 +00:00
|
|
|
R_UNLESS(file != nullptr, fs::ResultAllocationMemoryFailedInDirectorySaveDataFileSystemA());
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Increment our open writable files, if the file is writable. */
|
2019-12-09 11:57:37 +00:00
|
|
|
if (mode & fs::OpenMode_Write) {
|
2022-03-06 20:08:20 +00:00
|
|
|
++m_open_writable_files;
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Set the output. */
|
2019-12-09 11:57:37 +00:00
|
|
|
*out_file = std::move(file);
|
2022-03-06 20:08:20 +00:00
|
|
|
R_SUCCEED();
|
|
|
|
}
|
|
|
|
|
|
|
|
Result DirectorySaveDataFileSystem::DoOpenDirectory(std::unique_ptr<fs::fsa::IDirectory> *out_dir, const fs::Path &path, fs::OpenDirectoryMode mode) {
|
|
|
|
/* Resolve the final path. */
|
|
|
|
fs::Path resolved;
|
|
|
|
R_TRY(this->ResolvePath(std::addressof(resolved), path));
|
|
|
|
|
|
|
|
/* Lock ourselves. */
|
|
|
|
std::scoped_lock lk(m_accessor_mutex);
|
|
|
|
|
|
|
|
R_RETURN(m_base_fs->OpenDirectory(out_dir, resolved, mode));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-05 11:05:06 +00:00
|
|
|
Result DirectorySaveDataFileSystem::DoCommit() {
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Lock ourselves. */
|
2021-10-10 07:14:06 +00:00
|
|
|
std::scoped_lock lk(m_accessor_mutex);
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* If we aren't journaling, we don't need to do anything. */
|
|
|
|
R_SUCCEED_IF(!m_is_journaling_enabled);
|
|
|
|
R_SUCCEED_IF(!m_is_journaling_supported);
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Check that there are no open files blocking the commit. */
|
|
|
|
R_UNLESS(m_open_writable_files == 0, fs::ResultWriteModeFileNotClosed());
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Remove the previous commit by renaming the folder. */
|
|
|
|
R_TRY(fssystem::RetryFinitelyForTargetLocked([&] () ALWAYS_INLINE_LAMBDA { R_RETURN(m_base_fs->RenameDirectory(CommittedDirectoryPath, SynchronizingDirectoryPath)); }));
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Synchronize the working directory to the synchronizing directory. */
|
|
|
|
R_TRY(fssystem::RetryFinitelyForTargetLocked([&] () ALWAYS_INLINE_LAMBDA { R_RETURN(this->SynchronizeDirectory(SynchronizingDirectoryPath, WorkingDirectoryPath)); }));
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Rename the synchronized directory to commit it. */
|
|
|
|
R_TRY(fssystem::RetryFinitelyForTargetLocked([&] () ALWAYS_INLINE_LAMBDA { R_RETURN(m_base_fs->RenameDirectory(SynchronizingDirectoryPath, CommittedDirectoryPath)); }));
|
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
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result DirectorySaveDataFileSystem::DoGetFreeSpaceSize(s64 *out, const fs::Path &path) {
|
|
|
|
/* Lock ourselves. */
|
|
|
|
std::scoped_lock lk(m_accessor_mutex);
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Get the free space size in our working directory. */
|
|
|
|
AMS_UNUSED(path);
|
|
|
|
R_RETURN(m_base_fs->GetFreeSpaceSize(out, WorkingDirectoryPath));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result DirectorySaveDataFileSystem::DoGetTotalSpaceSize(s64 *out, const fs::Path &path) {
|
|
|
|
/* Lock ourselves. */
|
|
|
|
std::scoped_lock lk(m_accessor_mutex);
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
/* Get the free space size in our working directory. */
|
|
|
|
AMS_UNUSED(path);
|
|
|
|
R_RETURN(m_base_fs->GetTotalSpaceSize(out, WorkingDirectoryPath));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result DirectorySaveDataFileSystem::DoCleanDirectoryRecursively(const fs::Path &path) {
|
|
|
|
/* Resolve the final path. */
|
|
|
|
fs::Path resolved;
|
|
|
|
R_TRY(this->ResolvePath(std::addressof(resolved), path));
|
|
|
|
|
|
|
|
/* Lock ourselves. */
|
|
|
|
std::scoped_lock lk(m_accessor_mutex);
|
|
|
|
|
|
|
|
R_RETURN(m_base_fs->CleanDirectoryRecursively(resolved));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result DirectorySaveDataFileSystem::DoCommitProvisionally(s64 counter) {
|
|
|
|
/* Check that we support multi-commit. */
|
2022-03-13 09:32:34 +00:00
|
|
|
R_UNLESS(m_is_multi_commit_supported, fs::ResultUnsupportedCommitProvisionallyForDirectorySaveDataFileSystem());
|
2022-03-06 20:08:20 +00:00
|
|
|
|
|
|
|
/* Do nothing. */
|
|
|
|
AMS_UNUSED(counter);
|
|
|
|
R_SUCCEED();
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
Result DirectorySaveDataFileSystem::DoRollback() {
|
|
|
|
/* On non-journaled savedata, there's nothing to roll back to. */
|
|
|
|
R_SUCCEED_IF(!m_is_journaling_supported);
|
|
|
|
|
|
|
|
/* Perform a re-initialize. */
|
|
|
|
R_RETURN(this->Initialize(m_is_journaling_supported, m_is_multi_commit_supported, m_is_journaling_enabled));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|