Revert "hoc-clk: add live vdd2, live boost clock and basic pwm dimming"
This reverts commit 15b7df8ef1.
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "fs_directory_accessor.hpp"
|
||||
#include "fs_filesystem_accessor.hpp"
|
||||
|
||||
namespace ams::fs::impl {
|
||||
|
||||
DirectoryAccessor::DirectoryAccessor(std::unique_ptr<fsa::IDirectory>&& d, FileSystemAccessor &p) : m_impl(std::move(d)), m_parent(p) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
DirectoryAccessor::~DirectoryAccessor() {
|
||||
m_impl.reset();
|
||||
m_parent.NotifyCloseDirectory(this);
|
||||
}
|
||||
|
||||
Result DirectoryAccessor::Read(s64 *out_count, DirectoryEntry *out_entries, s64 max_entries) {
|
||||
R_RETURN(m_impl->Read(out_count, out_entries, max_entries));
|
||||
}
|
||||
|
||||
Result DirectoryAccessor::GetEntryCount(s64 *out) {
|
||||
R_RETURN(m_impl->GetEntryCount(out));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.hpp>
|
||||
|
||||
namespace ams::fs::impl {
|
||||
|
||||
class FileSystemAccessor;
|
||||
|
||||
class DirectoryAccessor : public util::IntrusiveListBaseNode<DirectoryAccessor>, public Newable {
|
||||
NON_COPYABLE(DirectoryAccessor);
|
||||
private:
|
||||
std::unique_ptr<fsa::IDirectory> m_impl;
|
||||
FileSystemAccessor &m_parent;
|
||||
public:
|
||||
DirectoryAccessor(std::unique_ptr<fsa::IDirectory>&& d, FileSystemAccessor &p);
|
||||
~DirectoryAccessor();
|
||||
|
||||
Result Read(s64 *out_count, DirectoryEntry *out_entries, s64 max_entries);
|
||||
Result GetEntryCount(s64 *out);
|
||||
|
||||
FileSystemAccessor *GetParent() const { return std::addressof(m_parent); }
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "../fs_scoped_setter.hpp"
|
||||
#include "../fs_file_path_hash.hpp"
|
||||
#include "fs_file_accessor.hpp"
|
||||
#include "fs_filesystem_accessor.hpp"
|
||||
|
||||
namespace ams::fs::impl {
|
||||
|
||||
FileAccessor::FileAccessor(std::unique_ptr<fsa::IFile>&& f, FileSystemAccessor *p, OpenMode mode)
|
||||
: m_impl(std::move(f)), m_parent(p), m_write_state(WriteState::None), m_write_result(ResultSuccess()), m_open_mode(mode)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
FileAccessor::~FileAccessor() {
|
||||
/* Ensure that all files are flushed. */
|
||||
if (R_SUCCEEDED(m_write_result)) {
|
||||
AMS_FS_ABORT_UNLESS_WITH_RESULT(m_write_state != WriteState::NeedsFlush, fs::ResultNeedFlush());
|
||||
}
|
||||
m_impl.reset();
|
||||
|
||||
if (m_parent != nullptr) {
|
||||
m_parent->NotifyCloseFile(this);
|
||||
}
|
||||
}
|
||||
|
||||
Result FileAccessor::ReadWithCacheAccessLog(size_t *out, s64 offset, void *buf, size_t size, const ReadOption &option, bool use_path_cache, bool use_data_cache) {
|
||||
/* TODO */
|
||||
AMS_UNUSED(out, offset, buf, size, option, use_path_cache, use_data_cache);
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result FileAccessor::ReadWithoutCacheAccessLog(size_t *out, s64 offset, void *buf, size_t size, const ReadOption &option) {
|
||||
R_RETURN(m_impl->Read(out, offset, buf, size, option));
|
||||
}
|
||||
|
||||
Result FileAccessor::Read(size_t *out, s64 offset, void *buf, size_t size, const ReadOption &option) {
|
||||
/* Get a handle to this file for use in logging. */
|
||||
FileHandle handle = { this };
|
||||
|
||||
/* Fail after a write fails. */
|
||||
R_UNLESS(R_SUCCEEDED(m_write_result), AMS_FS_IMPL_ACCESS_LOG_WITH_NAME(m_write_result, handle, "ReadFile", AMS_FS_IMPL_ACCESS_LOG_FORMAT_READ_FILE(out, offset, size)));
|
||||
|
||||
/* TODO: Support cache. */
|
||||
const bool use_path_cache = m_parent != nullptr && m_file_path_hash != nullptr;
|
||||
const bool use_data_cache = /* TODO */false && m_parent != nullptr && m_parent->IsFileDataCacheAttachable();
|
||||
|
||||
if (use_path_cache && use_data_cache && false) {
|
||||
/* TODO */
|
||||
R_RETURN(this->ReadWithCacheAccessLog(out, offset, buf, size, option, use_path_cache, use_data_cache));
|
||||
} else {
|
||||
R_RETURN(AMS_FS_IMPL_ACCESS_LOG_WITH_NAME(this->ReadWithoutCacheAccessLog(out, offset, buf, size, option), handle, "ReadFile", AMS_FS_IMPL_ACCESS_LOG_FORMAT_READ_FILE(out, offset, size)));
|
||||
}
|
||||
}
|
||||
|
||||
Result FileAccessor::Write(s64 offset, const void *buf, size_t size, const WriteOption &option) {
|
||||
/* Fail after a write fails. */
|
||||
R_TRY(m_write_result);
|
||||
|
||||
auto setter = MakeScopedSetter(m_write_state, WriteState::Failed);
|
||||
if (m_file_path_hash != nullptr && /* TODO */ false) {
|
||||
/* TODO */
|
||||
AMS_ABORT();
|
||||
} else {
|
||||
R_TRY(this->UpdateLastResult(m_impl->Write(offset, buf, size, option)));
|
||||
}
|
||||
|
||||
setter.Set(option.HasFlushFlag() ? WriteState::None : WriteState::NeedsFlush);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result FileAccessor::Flush() {
|
||||
/* Fail after a write fails. */
|
||||
R_TRY(m_write_result);
|
||||
|
||||
auto setter = MakeScopedSetter(m_write_state, WriteState::Failed);
|
||||
R_TRY(this->UpdateLastResult(m_impl->Flush()));
|
||||
setter.Set(WriteState::None);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result FileAccessor::SetSize(s64 size) {
|
||||
/* Fail after a write fails. */
|
||||
R_TRY(m_write_result);
|
||||
|
||||
const WriteState old_write_state = m_write_state;
|
||||
auto setter = MakeScopedSetter(m_write_state, WriteState::Failed);
|
||||
|
||||
R_TRY(this->UpdateLastResult(m_impl->SetSize(size)));
|
||||
|
||||
if (m_file_path_hash != nullptr) {
|
||||
/* TODO: invalidate path cache */
|
||||
}
|
||||
|
||||
setter.Set(old_write_state);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result FileAccessor::GetSize(s64 *out) {
|
||||
/* Fail after a write fails. */
|
||||
R_TRY(m_write_result);
|
||||
|
||||
R_RETURN(m_impl->GetSize(out));
|
||||
}
|
||||
|
||||
Result FileAccessor::OperateRange(void *dst, size_t dst_size, OperationId operation, s64 offset, s64 size, const void *src, size_t src_size) {
|
||||
R_RETURN(m_impl->OperateRange(dst, dst_size, operation, offset, size, src, src_size));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.hpp>
|
||||
|
||||
namespace ams::fs::impl {
|
||||
|
||||
struct FilePathHash;
|
||||
class FileSystemAccessor;
|
||||
|
||||
enum class WriteState {
|
||||
None,
|
||||
NeedsFlush,
|
||||
Failed,
|
||||
};
|
||||
|
||||
class FileAccessor : public util::IntrusiveListBaseNode<FileAccessor>, public Newable {
|
||||
NON_COPYABLE(FileAccessor);
|
||||
private:
|
||||
std::unique_ptr<fsa::IFile> m_impl;
|
||||
FileSystemAccessor * const m_parent;
|
||||
WriteState m_write_state;
|
||||
Result m_write_result;
|
||||
const OpenMode m_open_mode;
|
||||
std::unique_ptr<FilePathHash> m_file_path_hash;
|
||||
s32 m_path_hash_index;
|
||||
public:
|
||||
FileAccessor(std::unique_ptr<fsa::IFile>&& f, FileSystemAccessor *p, OpenMode mode);
|
||||
~FileAccessor();
|
||||
|
||||
Result Read(size_t *out, s64 offset, void *buf, size_t size, const ReadOption &option);
|
||||
Result Write(s64 offset, const void *buf, size_t size, const WriteOption &option);
|
||||
Result Flush();
|
||||
Result SetSize(s64 size);
|
||||
Result GetSize(s64 *out);
|
||||
Result OperateRange(void *dst, size_t dst_size, OperationId operation, s64 offset, s64 size, const void *src, size_t src_size);
|
||||
|
||||
OpenMode GetOpenMode() const { return m_open_mode; }
|
||||
WriteState GetWriteState() const { return m_write_state; }
|
||||
FileSystemAccessor *GetParent() const { return m_parent; }
|
||||
|
||||
void SetFilePathHash(std::unique_ptr<FilePathHash>&& file_path_hash, s32 index);
|
||||
Result ReadWithoutCacheAccessLog(size_t *out, s64 offset, void *buf, size_t size, const ReadOption &option);
|
||||
private:
|
||||
Result ReadWithCacheAccessLog(size_t *out, s64 offset, void *buf, size_t size, const ReadOption &option, bool use_path_cache, bool use_data_cache);
|
||||
|
||||
ALWAYS_INLINE Result UpdateLastResult(Result r) {
|
||||
if (!fs::ResultNotEnoughFreeSpace::Includes(r)) {
|
||||
m_write_result = r;
|
||||
}
|
||||
R_RETURN(r);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,314 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "fs_file_accessor.hpp"
|
||||
#include "fs_directory_accessor.hpp"
|
||||
#include "fs_filesystem_accessor.hpp"
|
||||
|
||||
namespace ams::fs::impl {
|
||||
|
||||
namespace {
|
||||
|
||||
template<typename List, typename Iter>
|
||||
void Remove(List &list, Iter *desired) {
|
||||
for (auto it = list.cbegin(); it != list.cend(); ++it) {
|
||||
if (it.operator->() == desired) {
|
||||
list.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* This should never happen. */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result SetMountName(char *dst, const char *name) {
|
||||
R_UNLESS(name[0] != 0, fs::ResultInvalidMountName());
|
||||
|
||||
const size_t n_len = util::Strlcpy<char>(dst, name, MountNameLengthMax + 1);
|
||||
R_UNLESS(n_len <= MountNameLengthMax, fs::ResultInvalidMountName());
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
template<typename List>
|
||||
Result ValidateNoOpenWriteModeFiles(List &list) {
|
||||
for (auto it = list.cbegin(); it != list.cend(); it++) {
|
||||
R_UNLESS((it->GetOpenMode() & OpenMode_Write) == 0, fs::ResultWriteModeFileNotClosed());
|
||||
}
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FileSystemAccessor::FileSystemAccessor(const char *n, std::unique_ptr<fsa::IFileSystem> &&fs, std::unique_ptr<fsa::ICommonMountNameGenerator> &&generator)
|
||||
: m_impl(std::move(fs)), m_open_list_lock(), m_mount_name_generator(std::move(generator)),
|
||||
m_access_log_enabled(false), m_data_cache_attachable(false), m_path_cache_attachable(false), m_path_cache_attached(false), m_multi_commit_supported(false),
|
||||
m_path_flags()
|
||||
{
|
||||
R_ABORT_UNLESS(SetMountName(m_name.str, n));
|
||||
|
||||
if (std::strcmp(m_name.str, AMS_FS_IMPL_HOST_ROOT_FILE_SYSTEM_MOUNT_NAME) == 0) {
|
||||
m_path_flags.AllowWindowsPath();
|
||||
}
|
||||
}
|
||||
|
||||
FileSystemAccessor::~FileSystemAccessor() {
|
||||
std::scoped_lock lk(m_open_list_lock);
|
||||
|
||||
/* TODO: Iterate over list entries. */
|
||||
|
||||
if (!m_open_file_list.empty()) { R_ABORT_UNLESS(fs::ResultFileNotClosed()); }
|
||||
if (!m_open_dir_list.empty()) { R_ABORT_UNLESS(fs::ResultDirectoryNotClosed()); }
|
||||
|
||||
if (m_path_cache_attached) {
|
||||
/* TODO: Invalidate path cache */
|
||||
}
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::GetCommonMountName(char *dst, size_t dst_size) const {
|
||||
R_UNLESS(m_mount_name_generator != nullptr, fs::ResultPreconditionViolation());
|
||||
R_RETURN(m_mount_name_generator->GenerateCommonMountName(dst, dst_size));
|
||||
}
|
||||
|
||||
std::shared_ptr<fssrv::impl::FileSystemInterfaceAdapter> FileSystemAccessor::GetMultiCommitTarget() {
|
||||
if (m_multi_commit_supported) {
|
||||
AMS_ABORT("TODO: Support multi commit");
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void FileSystemAccessor::NotifyCloseFile(FileAccessor *f) {
|
||||
std::scoped_lock lk(m_open_list_lock);
|
||||
Remove(m_open_file_list, f);
|
||||
}
|
||||
|
||||
void FileSystemAccessor::NotifyCloseDirectory(DirectoryAccessor *d) {
|
||||
std::scoped_lock lk(m_open_list_lock);
|
||||
Remove(m_open_dir_list, d);
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::SetUpPath(fs::Path *out, const char *p) {
|
||||
/* Initialize the path appropriately. */
|
||||
bool normalized;
|
||||
size_t len;
|
||||
if (R_SUCCEEDED(PathFormatter::IsNormalized(std::addressof(normalized), std::addressof(len), p, m_path_flags)) && normalized) {
|
||||
/* We can use the input buffer directly. */
|
||||
out->SetShallowBuffer(p);
|
||||
} else {
|
||||
/* Initialize with appropriate slash replacement. */
|
||||
if (m_path_flags.IsWindowsPathAllowed()) {
|
||||
R_TRY(out->InitializeWithReplaceForwardSlashes(p));
|
||||
} else {
|
||||
R_TRY(out->InitializeWithReplaceBackslash(p));
|
||||
}
|
||||
|
||||
/* Ensure we're normalized. */
|
||||
R_TRY(out->Normalize(m_path_flags));
|
||||
}
|
||||
|
||||
/* Check the path isn't too long. */
|
||||
R_UNLESS(out->GetLength() <= fs::EntryNameLengthMax, fs::ResultTooLongPath());
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::CreateFile(const char *path, s64 size, int option) {
|
||||
/* Create path. */
|
||||
fs::Path normalized_path;
|
||||
R_TRY(this->SetUpPath(std::addressof(normalized_path), path));
|
||||
|
||||
if (m_path_cache_attached) {
|
||||
/* TODO: Path cache */
|
||||
R_TRY(m_impl->CreateFile(normalized_path, size, option));
|
||||
} else {
|
||||
R_TRY(m_impl->CreateFile(normalized_path, size, option));
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::DeleteFile(const char *path) {
|
||||
/* Create path. */
|
||||
fs::Path normalized_path;
|
||||
R_TRY(this->SetUpPath(std::addressof(normalized_path), path));
|
||||
|
||||
R_RETURN(m_impl->DeleteFile(normalized_path));
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::CreateDirectory(const char *path) {
|
||||
/* Create path. */
|
||||
fs::Path normalized_path;
|
||||
R_TRY(this->SetUpPath(std::addressof(normalized_path), path));
|
||||
|
||||
R_RETURN(m_impl->CreateDirectory(normalized_path));
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::DeleteDirectory(const char *path) {
|
||||
/* Create path. */
|
||||
fs::Path normalized_path;
|
||||
R_TRY(this->SetUpPath(std::addressof(normalized_path), path));
|
||||
|
||||
R_RETURN(m_impl->DeleteDirectory(normalized_path));
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::DeleteDirectoryRecursively(const char *path) {
|
||||
/* Create path. */
|
||||
fs::Path normalized_path;
|
||||
R_TRY(this->SetUpPath(std::addressof(normalized_path), path));
|
||||
|
||||
R_RETURN(m_impl->DeleteDirectoryRecursively(normalized_path));
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::RenameFile(const char *old_path, const char *new_path) {
|
||||
/* Create path. */
|
||||
fs::Path normalized_old_path;
|
||||
fs::Path normalized_new_path;
|
||||
R_TRY(this->SetUpPath(std::addressof(normalized_old_path), old_path));
|
||||
R_TRY(this->SetUpPath(std::addressof(normalized_new_path), new_path));
|
||||
|
||||
if (m_path_cache_attached) {
|
||||
/* TODO: Path cache */
|
||||
R_TRY(m_impl->RenameFile(normalized_old_path, normalized_new_path));
|
||||
} else {
|
||||
R_TRY(m_impl->RenameFile(normalized_old_path, normalized_new_path));
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::RenameDirectory(const char *old_path, const char *new_path) {
|
||||
/* Create path. */
|
||||
fs::Path normalized_old_path;
|
||||
fs::Path normalized_new_path;
|
||||
R_TRY(this->SetUpPath(std::addressof(normalized_old_path), old_path));
|
||||
R_TRY(this->SetUpPath(std::addressof(normalized_new_path), new_path));
|
||||
|
||||
if (m_path_cache_attached) {
|
||||
/* TODO: Path cache */
|
||||
R_TRY(m_impl->RenameDirectory(normalized_old_path, normalized_new_path));
|
||||
} else {
|
||||
R_TRY(m_impl->RenameDirectory(normalized_old_path, normalized_new_path));
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::GetEntryType(DirectoryEntryType *out, const char *path) {
|
||||
/* Create path. */
|
||||
fs::Path normalized_path;
|
||||
R_TRY(this->SetUpPath(std::addressof(normalized_path), path));
|
||||
|
||||
R_RETURN(m_impl->GetEntryType(out, normalized_path));
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::OpenFile(std::unique_ptr<FileAccessor> *out_file, const char *path, OpenMode mode) {
|
||||
/* Create path. */
|
||||
fs::Path normalized_path;
|
||||
R_TRY(this->SetUpPath(std::addressof(normalized_path), path));
|
||||
|
||||
std::unique_ptr<fsa::IFile> file;
|
||||
R_TRY(m_impl->OpenFile(std::addressof(file), normalized_path, mode));
|
||||
|
||||
auto accessor = new FileAccessor(std::move(file), this, mode);
|
||||
R_UNLESS(accessor != nullptr, fs::ResultAllocationMemoryFailedInFileSystemAccessorA());
|
||||
|
||||
{
|
||||
std::scoped_lock lk(m_open_list_lock);
|
||||
m_open_file_list.push_back(*accessor);
|
||||
}
|
||||
|
||||
if (m_path_cache_attached) {
|
||||
if (mode & OpenMode_AllowAppend) {
|
||||
/* TODO: Append Path cache */
|
||||
} else {
|
||||
/* TODO: Non-append path cache */
|
||||
}
|
||||
}
|
||||
|
||||
out_file->reset(accessor);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::OpenDirectory(std::unique_ptr<DirectoryAccessor> *out_dir, const char *path, OpenDirectoryMode mode) {
|
||||
/* Create path. */
|
||||
fs::Path normalized_path;
|
||||
R_TRY(this->SetUpPath(std::addressof(normalized_path), path));
|
||||
|
||||
std::unique_ptr<fsa::IDirectory> dir;
|
||||
R_TRY(m_impl->OpenDirectory(std::addressof(dir), normalized_path, mode));
|
||||
|
||||
auto accessor = new DirectoryAccessor(std::move(dir), *this);
|
||||
R_UNLESS(accessor != nullptr, fs::ResultAllocationMemoryFailedInFileSystemAccessorB());
|
||||
|
||||
{
|
||||
std::scoped_lock lk(m_open_list_lock);
|
||||
m_open_dir_list.push_back(*accessor);
|
||||
}
|
||||
|
||||
out_dir->reset(accessor);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::Commit() {
|
||||
{
|
||||
std::scoped_lock lk(m_open_list_lock);
|
||||
R_ABORT_UNLESS(ValidateNoOpenWriteModeFiles(m_open_file_list));
|
||||
}
|
||||
R_RETURN(m_impl->Commit());
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::GetFreeSpaceSize(s64 *out, const char *path) {
|
||||
/* Create path. */
|
||||
fs::Path normalized_path;
|
||||
R_TRY(this->SetUpPath(std::addressof(normalized_path), path));
|
||||
|
||||
R_RETURN(m_impl->GetFreeSpaceSize(out, normalized_path));
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::GetTotalSpaceSize(s64 *out, const char *path) {
|
||||
/* Create path. */
|
||||
fs::Path normalized_path;
|
||||
R_TRY(this->SetUpPath(std::addressof(normalized_path), path));
|
||||
|
||||
R_RETURN(m_impl->GetTotalSpaceSize(out, normalized_path));
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::CleanDirectoryRecursively(const char *path) {
|
||||
/* Create path. */
|
||||
fs::Path normalized_path;
|
||||
R_TRY(this->SetUpPath(std::addressof(normalized_path), path));
|
||||
|
||||
R_RETURN(m_impl->CleanDirectoryRecursively(normalized_path));
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::GetFileTimeStampRaw(FileTimeStampRaw *out, const char *path) {
|
||||
/* Create path. */
|
||||
fs::Path normalized_path;
|
||||
R_TRY(this->SetUpPath(std::addressof(normalized_path), path));
|
||||
|
||||
R_RETURN(m_impl->GetFileTimeStampRaw(out, normalized_path));
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::QueryEntry(char *dst, size_t dst_size, const char *src, size_t src_size, fsa::QueryId query, const char *path) {
|
||||
/* Create path. */
|
||||
fs::Path normalized_path;
|
||||
R_TRY(this->SetUpPath(std::addressof(normalized_path), path));
|
||||
|
||||
R_RETURN(m_impl->QueryEntry(dst, dst_size, src, src_size, query, normalized_path));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.hpp>
|
||||
#include <stratosphere/fssrv/fssrv_interface_adapters.hpp>
|
||||
#include "fs_mount_name.hpp"
|
||||
|
||||
namespace ams::fs::impl {
|
||||
|
||||
class FileAccessor;
|
||||
class DirectoryAccessor;
|
||||
|
||||
class FileSystemAccessor : public util::IntrusiveListBaseNode<FileSystemAccessor>, public Newable {
|
||||
NON_COPYABLE(FileSystemAccessor);
|
||||
friend class FileAccessor;
|
||||
friend class DirectoryAccessor;
|
||||
private:
|
||||
using FileList = util::IntrusiveListBaseTraits<FileAccessor>::ListType;
|
||||
using DirList = util::IntrusiveListBaseTraits<DirectoryAccessor>::ListType;
|
||||
private:
|
||||
MountName m_name;
|
||||
std::unique_ptr<fsa::IFileSystem> m_impl;
|
||||
FileList m_open_file_list;
|
||||
DirList m_open_dir_list;
|
||||
os::SdkMutex m_open_list_lock;
|
||||
std::unique_ptr<fsa::ICommonMountNameGenerator> m_mount_name_generator;
|
||||
bool m_access_log_enabled;
|
||||
bool m_data_cache_attachable;
|
||||
bool m_path_cache_attachable;
|
||||
bool m_path_cache_attached;
|
||||
bool m_multi_commit_supported;
|
||||
PathFlags m_path_flags;
|
||||
public:
|
||||
FileSystemAccessor(const char *name, std::unique_ptr<fsa::IFileSystem> &&fs, std::unique_ptr<fsa::ICommonMountNameGenerator> &&generator = nullptr);
|
||||
virtual ~FileSystemAccessor();
|
||||
|
||||
Result CreateFile(const char *path, s64 size, int option);
|
||||
Result DeleteFile(const char *path);
|
||||
Result CreateDirectory(const char *path);
|
||||
Result DeleteDirectory(const char *path);
|
||||
Result DeleteDirectoryRecursively(const char *path);
|
||||
Result RenameFile(const char *old_path, const char *new_path);
|
||||
Result RenameDirectory(const char *old_path, const char *new_path);
|
||||
Result GetEntryType(DirectoryEntryType *out, const char *path);
|
||||
Result OpenFile(std::unique_ptr<FileAccessor> *out_file, const char *path, OpenMode mode);
|
||||
Result OpenDirectory(std::unique_ptr<DirectoryAccessor> *out_dir, const char *path, OpenDirectoryMode mode);
|
||||
Result Commit();
|
||||
Result GetFreeSpaceSize(s64 *out, const char *path);
|
||||
Result GetTotalSpaceSize(s64 *out, const char *path);
|
||||
Result CleanDirectoryRecursively(const char *path);
|
||||
Result GetFileTimeStampRaw(FileTimeStampRaw *out, const char *path);
|
||||
Result QueryEntry(char *dst, size_t dst_size, const char *src, size_t src_size, fsa::QueryId query, const char *path);
|
||||
|
||||
const char *GetName() const { return m_name.str; }
|
||||
Result GetCommonMountName(char *dst, size_t dst_size) const;
|
||||
|
||||
void SetAccessLogEnabled(bool en) { m_access_log_enabled = en; }
|
||||
void SetFileDataCacheAttachable(bool en) { m_data_cache_attachable = en; }
|
||||
void SetPathBasedFileDataCacheAttachable(bool en) { m_path_cache_attachable = en; }
|
||||
void SetMultiCommitSupported(bool en) { m_multi_commit_supported = en; }
|
||||
|
||||
bool IsEnabledAccessLog() const { return m_access_log_enabled; }
|
||||
bool IsFileDataCacheAttachable() const { return m_data_cache_attachable; }
|
||||
bool IsPathBasedFileDataCacheAttachable() const { return m_path_cache_attachable; }
|
||||
|
||||
void AttachPathBasedFileDataCache() {
|
||||
if (this->IsPathBasedFileDataCacheAttachable()) {
|
||||
m_path_cache_attached = true;
|
||||
}
|
||||
}
|
||||
|
||||
void DetachPathBasedFileDataCache() {
|
||||
m_path_cache_attached = false;
|
||||
}
|
||||
|
||||
std::shared_ptr<fssrv::impl::FileSystemInterfaceAdapter> GetMultiCommitTarget();
|
||||
|
||||
fsa::IFileSystem *GetRawFileSystemUnsafe() {
|
||||
return m_impl.get();
|
||||
}
|
||||
private:
|
||||
void NotifyCloseFile(FileAccessor *f);
|
||||
void NotifyCloseDirectory(DirectoryAccessor *d);
|
||||
public:
|
||||
Result SetUpPath(fs::Path *out, const char *p);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.hpp>
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
struct MountName {
|
||||
char str[MountNameLengthMax + 1];
|
||||
};
|
||||
static_assert(util::is_pod<MountName>::value);
|
||||
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "fs_mount_table.hpp"
|
||||
|
||||
namespace ams::fs::impl {
|
||||
|
||||
namespace {
|
||||
|
||||
bool MatchesName(const FileSystemAccessor &accessor, const char *name) {
|
||||
return std::strncmp(accessor.GetName(), name, sizeof(MountName)) == 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool MountTable::CanAcceptMountName(const char *name) {
|
||||
for (const auto &fs : m_fs_list) {
|
||||
if (MatchesName(fs, name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Result MountTable::Mount(std::unique_ptr<FileSystemAccessor> &&fs) {
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
R_UNLESS(this->CanAcceptMountName(fs->GetName()), fs::ResultMountNameAlreadyExists());
|
||||
|
||||
m_fs_list.push_back(*fs.release());
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result MountTable::Find(FileSystemAccessor **out, const char *name) {
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
for (auto &fs : m_fs_list) {
|
||||
if (MatchesName(fs, name)) {
|
||||
*out = std::addressof(fs);
|
||||
R_SUCCEED();
|
||||
}
|
||||
}
|
||||
|
||||
R_THROW(fs::ResultNotMounted());
|
||||
}
|
||||
|
||||
void MountTable::Unmount(const char *name) {
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
for (auto it = m_fs_list.cbegin(); it != m_fs_list.cend(); it++) {
|
||||
if (MatchesName(*it, name)) {
|
||||
auto p = std::addressof(*it);
|
||||
m_fs_list.erase(it);
|
||||
delete p;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
R_ABORT_UNLESS(fs::ResultNotMounted());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.hpp>
|
||||
#include "fs_filesystem_accessor.hpp"
|
||||
|
||||
namespace ams::fs::impl {
|
||||
|
||||
class MountTable : public Newable {
|
||||
NON_COPYABLE(MountTable);
|
||||
NON_MOVEABLE(MountTable);
|
||||
private:
|
||||
using FileSystemList = util::IntrusiveListBaseTraits<FileSystemAccessor>::ListType;
|
||||
private:
|
||||
FileSystemList m_fs_list;
|
||||
os::SdkMutex m_mutex;
|
||||
public:
|
||||
constexpr MountTable() : m_fs_list(), m_mutex() { /* ... */ }
|
||||
private:
|
||||
bool CanAcceptMountName(const char *name);
|
||||
public:
|
||||
Result Mount(std::unique_ptr<FileSystemAccessor> &&fs);
|
||||
Result Find(FileSystemAccessor **out, const char *name);
|
||||
void Unmount(const char *name);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "fs_filesystem_accessor.hpp"
|
||||
#include "fs_mount_utils.hpp"
|
||||
#include "fs_user_mount_table.hpp"
|
||||
|
||||
namespace ams::fs::impl {
|
||||
|
||||
namespace {
|
||||
|
||||
const char *FindMountNameDriveSeparator(const char *path) {
|
||||
for (const char *cur = path; cur < path + MountNameLengthMax + 1 && *cur != StringTraits::NullTerminator; ++cur) {
|
||||
if (*cur == StringTraits::DriveSeparator) {
|
||||
return cur;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
constexpr bool IsHostRootPath(const char *path) {
|
||||
#if defined(ATMOSPHERE_OS_HORIZON) || defined(ATMOSPHERE_OS_WINDOWS)
|
||||
return fs::IsWindowsDrive(path) || fs::IsUncPath(path);
|
||||
#elif defined(ATMOSPHERE_OS_LINUX) || defined(ATMOSPHERE_OS_MACOS)
|
||||
return fs::IsPathAbsolute(path);
|
||||
#else
|
||||
#error "Unknown OS for host path identification"
|
||||
#endif
|
||||
}
|
||||
|
||||
Result GetMountNameAndSubPath(MountName *out_mount_name, const char **out_sub_path, const char *path) {
|
||||
/* Handle the Host-path case. */
|
||||
if (IsHostRootPath(path)) {
|
||||
std::strncpy(out_mount_name->str, HostRootFileSystemMountName, MountNameLengthMax);
|
||||
out_mount_name->str[MountNameLengthMax] = '\x00';
|
||||
|
||||
*out_sub_path = path;
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
/* Locate the drive separator. */
|
||||
const char *drive_separator = FindMountNameDriveSeparator(path);
|
||||
R_UNLESS(drive_separator != nullptr, fs::ResultInvalidMountName());
|
||||
|
||||
/* Ensure the mount name isn't too long. */
|
||||
const size_t len = drive_separator - path;
|
||||
R_UNLESS(0 < len, fs::ResultInvalidMountName());
|
||||
R_UNLESS(len <= MountNameLengthMax, fs::ResultInvalidMountName());
|
||||
|
||||
/* Ensure the result sub-path is valid. */
|
||||
const char *sub_path = drive_separator + 1;
|
||||
|
||||
const auto starts_with_dir = (sub_path[0] == StringTraits::DirectorySeparator) || (sub_path[0] == StringTraits::AlternateDirectorySeparator);
|
||||
R_UNLESS(starts_with_dir, fs::ResultInvalidPathFormat());
|
||||
|
||||
/* Set output. */
|
||||
std::memcpy(out_mount_name->str, path, len);
|
||||
out_mount_name->str[len] = StringTraits::NullTerminator;
|
||||
|
||||
*out_sub_path = sub_path;
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool IsValidMountName(const char *name) {
|
||||
if (name[0] == StringTraits::NullTerminator) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((('a' <= name[0] && name[0] <= 'z') || ('A' <= name[0] && name[0] <= 'Z')) && name[1] == StringTraits::NullTerminator) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t len = 0;
|
||||
for (const char *cur = name; *cur != StringTraits::NullTerminator; ++cur) {
|
||||
if (*cur == StringTraits::DriveSeparator || *cur == StringTraits::DirectorySeparator) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((++len) > MountNameLengthMax) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return util::VerifyUtf8String(name, len);
|
||||
}
|
||||
|
||||
bool IsReservedMountName(const char *name) {
|
||||
return name[0] == ReservedMountNamePrefixCharacter;
|
||||
}
|
||||
|
||||
Result CheckMountName(const char *name) {
|
||||
R_TRY(CheckMountNameAllowingReserved(name));
|
||||
R_UNLESS(!impl::IsReservedMountName(name), fs::ResultInvalidMountName());
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result CheckMountNameAllowingReserved(const char *name) {
|
||||
R_UNLESS(name != nullptr, fs::ResultInvalidMountName());
|
||||
R_UNLESS(impl::IsValidMountName(name), fs::ResultInvalidMountName());
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result FindFileSystem(FileSystemAccessor **out_accessor, const char **out_sub_path, const char *path) {
|
||||
R_UNLESS(out_accessor != nullptr, fs::ResultUnexpectedInFindFileSystemA());
|
||||
R_UNLESS(out_sub_path != nullptr, fs::ResultUnexpectedInFindFileSystemA());
|
||||
R_UNLESS(path != nullptr, fs::ResultNullptrArgument());
|
||||
|
||||
R_UNLESS(strncmp(path, HostRootFileSystemMountName, util::Strnlen(HostRootFileSystemMountName, sizeof(MountName))) != 0, fs::ResultNotMounted());
|
||||
|
||||
MountName mount_name;
|
||||
R_TRY(GetMountNameAndSubPath(std::addressof(mount_name), out_sub_path, path));
|
||||
|
||||
R_RETURN(impl::Find(out_accessor, mount_name.str));
|
||||
}
|
||||
|
||||
Result Unmount(const char *name) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
R_TRY(impl::Find(std::addressof(accessor), name));
|
||||
|
||||
if (accessor->IsFileDataCacheAttachable()) {
|
||||
/* TODO: Data cache purge */
|
||||
}
|
||||
|
||||
impl::Unregister(name);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
Result ConvertToFsCommonPath(char *dst, size_t dst_size, const char *src) {
|
||||
/* Ensure neither argument is nullptr. */
|
||||
AMS_FS_R_UNLESS(dst != nullptr, fs::ResultNullptrArgument());
|
||||
AMS_FS_R_UNLESS(src != nullptr, fs::ResultNullptrArgument());
|
||||
|
||||
/* Get the mount name and sub path for the path. */
|
||||
MountName mount_name;
|
||||
const char *sub_path;
|
||||
AMS_FS_R_TRY(impl::GetMountNameAndSubPath(std::addressof(mount_name), std::addressof(sub_path), src));
|
||||
|
||||
impl::FileSystemAccessor *accessor;
|
||||
AMS_FS_R_TRY(impl::Find(std::addressof(accessor), mount_name.str));
|
||||
AMS_FS_R_TRY(accessor->GetCommonMountName(dst, dst_size));
|
||||
|
||||
const auto mount_name_len = util::Strnlen(dst, dst_size);
|
||||
const auto common_path_len = util::SNPrintf(dst + mount_name_len, dst_size - mount_name_len, "%s", sub_path);
|
||||
|
||||
AMS_FS_R_UNLESS(static_cast<size_t>(common_path_len) < dst_size - mount_name_len, fs::ResultTooLongPath());
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void Unmount(const char *mount_name) {
|
||||
AMS_FS_R_ABORT_UNLESS(AMS_FS_IMPL_ACCESS_LOG_UNMOUNT(impl::Unmount(mount_name), mount_name, AMS_FS_IMPL_ACCESS_LOG_FORMAT_MOUNT, mount_name));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.hpp>
|
||||
|
||||
namespace ams::fs::impl {
|
||||
|
||||
class FileSystemAccessor;
|
||||
|
||||
Result FindFileSystem(FileSystemAccessor **out_accessor, const char **out_sub_path, const char *path);
|
||||
|
||||
bool IsWindowsDrive(const char *name);
|
||||
bool IsReservedMountName(const char *name);
|
||||
bool IsValidMountName(const char *name);
|
||||
Result CheckMountName(const char *name);
|
||||
Result CheckMountNameAllowingReserved(const char *name);
|
||||
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "fs_filesystem_accessor.hpp"
|
||||
#include "fs_user_mount_table.hpp"
|
||||
|
||||
namespace ams::fs::fsa {
|
||||
|
||||
Result Register(const char *name, std::unique_ptr<IFileSystem> &&fs) {
|
||||
auto accessor = std::make_unique<impl::FileSystemAccessor>(name, std::move(fs));
|
||||
R_UNLESS(accessor != nullptr, fs::ResultAllocationMemoryFailedInRegisterA());
|
||||
|
||||
R_RETURN(impl::Register(std::move(accessor)));
|
||||
}
|
||||
|
||||
Result Register(const char *name, std::unique_ptr<IFileSystem> &&fs, std::unique_ptr<ICommonMountNameGenerator> &&generator) {
|
||||
auto accessor = std::make_unique<impl::FileSystemAccessor>(name, std::move(fs), std::move(generator));
|
||||
R_UNLESS(accessor != nullptr, fs::ResultAllocationMemoryFailedInRegisterB());
|
||||
|
||||
R_RETURN(impl::Register(std::move(accessor)));
|
||||
}
|
||||
|
||||
Result Register(const char *name, std::unique_ptr<IFileSystem> &&fs, std::unique_ptr<ICommonMountNameGenerator> &&generator, bool use_data_cache, bool use_path_cache, bool support_multi_commit) {
|
||||
auto accessor = std::make_unique<impl::FileSystemAccessor>(name, std::move(fs), std::move(generator));
|
||||
R_UNLESS(accessor != nullptr, fs::ResultAllocationMemoryFailedInRegisterB());
|
||||
|
||||
accessor->SetFileDataCacheAttachable(use_data_cache);
|
||||
accessor->SetPathBasedFileDataCacheAttachable(use_path_cache);
|
||||
accessor->SetMultiCommitSupported(support_multi_commit);
|
||||
|
||||
R_RETURN(impl::Register(std::move(accessor)));
|
||||
}
|
||||
|
||||
void Unregister(const char *name) {
|
||||
impl::Unregister(name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "fs_directory_accessor.hpp"
|
||||
#include "fs_filesystem_accessor.hpp"
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
namespace {
|
||||
|
||||
ALWAYS_INLINE impl::DirectoryAccessor *Get(DirectoryHandle handle) {
|
||||
return reinterpret_cast<impl::DirectoryAccessor *>(handle.handle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result ReadDirectory(s64 *out_count, DirectoryEntry *out_entries, DirectoryHandle handle, s64 max_entries) {
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG(Get(handle)->Read(out_count, out_entries, max_entries), handle, AMS_FS_IMPL_ACCESS_LOG_FORMAT_READ_DIRECTORY(out_count, max_entries)));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result GetDirectoryEntryCount(s64 *out, DirectoryHandle handle) {
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG(Get(handle)->GetEntryCount(out), handle, AMS_FS_IMPL_ACCESS_LOG_FORMAT_GET_DIRECTORY_ENTRY_COUNT(out)));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void CloseDirectory(DirectoryHandle handle) {
|
||||
AMS_FS_IMPL_ACCESS_LOG((delete Get(handle), ResultSuccess()), handle, AMS_FS_IMPL_ACCESS_LOG_FORMAT_NONE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "fs_file_accessor.hpp"
|
||||
#include "fs_filesystem_accessor.hpp"
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
namespace {
|
||||
|
||||
ALWAYS_INLINE impl::FileAccessor *Get(FileHandle handle) {
|
||||
return reinterpret_cast<impl::FileAccessor *>(handle.handle);
|
||||
}
|
||||
|
||||
Result ReadFileImpl(size_t *out, FileHandle handle, s64 offset, void *buffer, size_t size, const fs::ReadOption &option) {
|
||||
R_TRY(Get(handle)->Read(out, offset, buffer, size, option));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result ReadFile(FileHandle handle, s64 offset, void *buffer, size_t size, const fs::ReadOption &option) {
|
||||
size_t read_size;
|
||||
AMS_FS_R_TRY(ReadFileImpl(std::addressof(read_size), handle, offset, buffer, size, option));
|
||||
AMS_FS_R_UNLESS(read_size == size, fs::ResultOutOfRange());
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ReadFile(FileHandle handle, s64 offset, void *buffer, size_t size) {
|
||||
size_t read_size;
|
||||
AMS_FS_R_TRY(ReadFileImpl(std::addressof(read_size), handle, offset, buffer, size, ReadOption()));
|
||||
AMS_FS_R_UNLESS(read_size == size, fs::ResultOutOfRange());
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ReadFile(size_t *out, FileHandle handle, s64 offset, void *buffer, size_t size, const fs::ReadOption &option) {
|
||||
AMS_FS_R_TRY(ReadFileImpl(out, handle, offset, buffer, size, option));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ReadFile(size_t *out, FileHandle handle, s64 offset, void *buffer, size_t size) {
|
||||
AMS_FS_R_TRY(ReadFileImpl(out, handle, offset, buffer, size, ReadOption()));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result GetFileSize(s64 *out, FileHandle handle) {
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG(Get(handle)->GetSize(out), handle, AMS_FS_IMPL_ACCESS_LOG_FORMAT_GET_FILE_SIZE(out)));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result FlushFile(FileHandle handle) {
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG(Get(handle)->Flush(), handle, AMS_FS_IMPL_ACCESS_LOG_FORMAT_NONE));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result WriteFile(FileHandle handle, s64 offset, const void *buffer, size_t size, const fs::WriteOption &option) {
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG(Get(handle)->Write(offset, buffer, size, option), handle, AMS_FS_IMPL_ACCESS_LOG_FORMAT_WRITE_FILE(option), offset, size));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SetFileSize(FileHandle handle, s64 size) {
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG(Get(handle)->SetSize(size), handle, AMS_FS_IMPL_ACCESS_LOG_FORMAT_SIZE, size));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
int GetFileOpenMode(FileHandle handle) {
|
||||
const int mode = Get(handle)->GetOpenMode();
|
||||
AMS_FS_IMPL_ACCESS_LOG(ResultSuccess(), handle, AMS_FS_IMPL_ACCESS_LOG_FORMAT_OPEN_MODE, static_cast<u32>(mode));
|
||||
return mode;
|
||||
}
|
||||
|
||||
void CloseFile(FileHandle handle) {
|
||||
AMS_FS_IMPL_ACCESS_LOG((delete Get(handle), ResultSuccess()), handle, AMS_FS_IMPL_ACCESS_LOG_FORMAT_NONE);
|
||||
}
|
||||
|
||||
Result QueryRange(QueryRangeInfo *out, FileHandle handle, s64 offset, s64 size) {
|
||||
AMS_FS_R_TRY(Get(handle)->OperateRange(out, sizeof(*out), OperationId::QueryRange, offset, size, nullptr, 0));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,230 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "fs_filesystem_accessor.hpp"
|
||||
#include "fs_file_accessor.hpp"
|
||||
#include "fs_directory_accessor.hpp"
|
||||
#include "fs_mount_utils.hpp"
|
||||
#include "fs_user_mount_table.hpp"
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
Result CreateFile(const char *path, s64 size) {
|
||||
R_RETURN(CreateFile(path, size, 0));
|
||||
}
|
||||
|
||||
Result CreateFile(const char* path, s64 size, int option) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path), AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH, path));
|
||||
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM(accessor->CreateFile(sub_path, size, option), nullptr, accessor, AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH_AND_SIZE, path, size));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result DeleteFile(const char *path) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path), AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH, path));
|
||||
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM(accessor->DeleteFile(sub_path), nullptr, accessor, AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH, path));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result CreateDirectory(const char *path) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path), AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH, path));
|
||||
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM(accessor->CreateDirectory(sub_path), nullptr, accessor, AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH, path));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result DeleteDirectory(const char *path) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path), AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH, path));
|
||||
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM(accessor->DeleteDirectory(sub_path), nullptr, accessor, AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH, path));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result DeleteDirectoryRecursively(const char *path) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path), AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH, path));
|
||||
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM(accessor->DeleteDirectoryRecursively(sub_path), nullptr, accessor, AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH, path));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result RenameFile(const char *old_path, const char *new_path) {
|
||||
impl::FileSystemAccessor *old_accessor;
|
||||
impl::FileSystemAccessor *new_accessor;
|
||||
const char *old_sub_path;
|
||||
const char *new_sub_path;
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(impl::FindFileSystem(std::addressof(old_accessor), std::addressof(old_sub_path), old_path), AMS_FS_IMPL_ACCESS_LOG_FORMAT_RENAME, old_path, new_path));
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(impl::FindFileSystem(std::addressof(new_accessor), std::addressof(new_sub_path), new_path), AMS_FS_IMPL_ACCESS_LOG_FORMAT_RENAME, old_path, new_path));
|
||||
|
||||
auto rename_impl = [=]() -> Result {
|
||||
R_UNLESS(old_accessor == new_accessor, fs::ResultRenameToOtherFileSystem());
|
||||
R_TRY(old_accessor->RenameFile(old_sub_path, new_sub_path));
|
||||
R_SUCCEED();
|
||||
};
|
||||
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM(rename_impl(), nullptr, old_accessor, AMS_FS_IMPL_ACCESS_LOG_FORMAT_RENAME, old_path, new_path));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result RenameDirectory(const char *old_path, const char *new_path) {
|
||||
impl::FileSystemAccessor *old_accessor;
|
||||
impl::FileSystemAccessor *new_accessor;
|
||||
const char *old_sub_path;
|
||||
const char *new_sub_path;
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(impl::FindFileSystem(std::addressof(old_accessor), std::addressof(old_sub_path), old_path), AMS_FS_IMPL_ACCESS_LOG_FORMAT_RENAME, old_path, new_path));
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(impl::FindFileSystem(std::addressof(new_accessor), std::addressof(new_sub_path), new_path), AMS_FS_IMPL_ACCESS_LOG_FORMAT_RENAME, old_path, new_path));
|
||||
|
||||
auto rename_impl = [=]() -> Result {
|
||||
R_UNLESS(old_accessor == new_accessor, fs::ResultRenameToOtherFileSystem());
|
||||
R_TRY(old_accessor->RenameDirectory(old_sub_path, new_sub_path));
|
||||
R_SUCCEED();
|
||||
};
|
||||
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM(rename_impl(), nullptr, old_accessor, AMS_FS_IMPL_ACCESS_LOG_FORMAT_RENAME, old_path, new_path));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result GetEntryType(DirectoryEntryType *out, const char *path) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path), AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH, path));
|
||||
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM(accessor->GetEntryType(out, sub_path), nullptr, accessor, AMS_FS_IMPL_ACCESS_LOG_FORMAT_GET_ENTRY_TYPE(out, path)));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result OpenFile(FileHandle *out_file, const char *path, int mode) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path), AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH_AND_OPEN_MODE, path, static_cast<u32>(mode)));
|
||||
|
||||
std::unique_ptr<impl::FileAccessor> file_accessor;
|
||||
|
||||
auto open_impl = [&]() -> Result {
|
||||
R_UNLESS(out_file != nullptr, fs::ResultNullptrArgument());
|
||||
R_TRY(accessor->OpenFile(std::addressof(file_accessor), sub_path, static_cast<OpenMode>(mode)));
|
||||
R_SUCCEED();
|
||||
};
|
||||
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM(open_impl(), nullptr, accessor, AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH_AND_OPEN_MODE, path, static_cast<u32>(mode)));
|
||||
|
||||
out_file->handle = file_accessor.release();
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result OpenDirectory(DirectoryHandle *out_dir, const char *path, int mode) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path), AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH_AND_OPEN_MODE, path, static_cast<u32>(mode)));
|
||||
|
||||
std::unique_ptr<impl::DirectoryAccessor> dir_accessor;
|
||||
|
||||
auto open_impl = [&]() -> Result {
|
||||
R_UNLESS(out_dir != nullptr, fs::ResultNullptrArgument());
|
||||
R_TRY(accessor->OpenDirectory(std::addressof(dir_accessor), sub_path, static_cast<OpenDirectoryMode>(mode)));
|
||||
R_SUCCEED();
|
||||
};
|
||||
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM(open_impl(), nullptr, accessor, AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH_AND_OPEN_MODE, path, static_cast<u32>(mode)));
|
||||
|
||||
out_dir->handle = dir_accessor.release();
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result CleanDirectoryRecursively(const char *path) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path), AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH, path));
|
||||
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM(accessor->CleanDirectoryRecursively(sub_path), nullptr, accessor, AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH, path));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result GetFreeSpaceSize(s64 *out, const char *path) {
|
||||
/* Find the filesystem without access logging. */
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
AMS_FS_R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path));
|
||||
|
||||
/* Get the total space size. */
|
||||
AMS_FS_R_TRY(accessor->GetFreeSpaceSize(out, sub_path));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result GetTotalSpaceSize(s64 *out, const char *path) {
|
||||
/* Find the filesystem without access logging. */
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
AMS_FS_R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path));
|
||||
|
||||
/* Get the total space size. */
|
||||
AMS_FS_R_TRY(accessor->GetTotalSpaceSize(out, sub_path));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SetConcatenationFileAttribute(const char *path) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
AMS_FS_R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path));
|
||||
|
||||
AMS_FS_R_TRY(accessor->QueryEntry(nullptr, 0, nullptr, 0, fsa::QueryId::SetConcatenationFileAttribute, sub_path));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result OpenFile(FileHandle *out, std::unique_ptr<fsa::IFile> &&file, int mode) {
|
||||
AMS_FS_R_UNLESS(out != nullptr, fs::ResultNullptrArgument());
|
||||
|
||||
auto file_accessor = std::make_unique<impl::FileAccessor>(std::move(file), nullptr, static_cast<OpenMode>(mode));
|
||||
AMS_FS_R_UNLESS(file_accessor != nullptr, fs::ResultAllocationMemoryFailedNew());
|
||||
out->handle = file_accessor.release();
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
Result CommitImpl(const char *mount_name, const char *func_name) {
|
||||
impl::FileSystemAccessor *accessor{};
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(impl::Find(std::addressof(accessor), mount_name), AMS_FS_IMPL_ACCESS_LOG_FORMAT_MOUNT, mount_name));
|
||||
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM_WITH_NAME(accessor->Commit(), nullptr, accessor, func_name, AMS_FS_IMPL_ACCESS_LOG_FORMAT_MOUNT, mount_name));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result Commit(const char *mount_name) {
|
||||
R_RETURN(CommitImpl(mount_name, AMS_CURRENT_FUNCTION_NAME));
|
||||
}
|
||||
|
||||
Result CommitSaveData(const char *mount_name) {
|
||||
R_RETURN(CommitImpl(mount_name, AMS_CURRENT_FUNCTION_NAME));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "fs_filesystem_accessor.hpp"
|
||||
#include "fs_file_accessor.hpp"
|
||||
#include "fs_directory_accessor.hpp"
|
||||
#include "fs_mount_utils.hpp"
|
||||
#include "fs_user_mount_table.hpp"
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
namespace impl {
|
||||
|
||||
Result GetFileTimeStampRawForDebug(FileTimeStampRaw *out, const char *path) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path));
|
||||
|
||||
R_TRY(accessor->GetFileTimeStampRaw(out, sub_path));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result GetFileTimeStamp(FileTimeStamp *out, const char *path) {
|
||||
fs::FileTimeStampRaw raw;
|
||||
AMS_FS_R_TRY(impl::GetFileTimeStampRawForDebug(std::addressof(raw), path));
|
||||
|
||||
static_assert(sizeof(raw) == sizeof(*out));
|
||||
std::memcpy(out, std::addressof(raw), sizeof(raw));
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "fs_user_mount_table.hpp"
|
||||
#include "fs_mount_table.hpp"
|
||||
#include "fs_filesystem_accessor.hpp"
|
||||
|
||||
namespace ams::fs::impl {
|
||||
|
||||
namespace {
|
||||
|
||||
constinit MountTable g_mount_table;
|
||||
|
||||
}
|
||||
|
||||
Result Register(std::unique_ptr<FileSystemAccessor> &&fs) {
|
||||
R_RETURN(g_mount_table.Mount(std::move(fs)));
|
||||
}
|
||||
|
||||
Result Find(FileSystemAccessor **out, const char *name) {
|
||||
R_RETURN(g_mount_table.Find(out, name));
|
||||
}
|
||||
|
||||
void Unregister(const char *name) {
|
||||
g_mount_table.Unmount(name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.hpp>
|
||||
|
||||
namespace ams::fs::impl {
|
||||
|
||||
class FileSystemAccessor;
|
||||
|
||||
Result Register(std::unique_ptr<FileSystemAccessor> &&fs);
|
||||
Result Find(FileSystemAccessor **out, const char *name);
|
||||
void Unregister(const char *name);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user