mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-09 22:56:35 +00:00
fs: use access_log for other user fs/dir/file bindings
This commit is contained in:
parent
e2b17086d4
commit
70e67da1e1
14 changed files with 356 additions and 141 deletions
|
@ -53,8 +53,6 @@ namespace ams::fs {
|
|||
CreateOption_BigFile = ::FsCreateOption_BigFile,
|
||||
};
|
||||
|
||||
using FileTimeStampRaw = ::FsTimeStampRaw;
|
||||
|
||||
struct FileHandle;
|
||||
struct DirectoryHandle;
|
||||
|
||||
|
@ -74,7 +72,6 @@ namespace ams::fs {
|
|||
Result GetTotalSpaceSize(s64 *out, const char *path);
|
||||
|
||||
Result SetConcatenationFileAttribute(const char *path);
|
||||
Result GetFileTimeStampRaw(FileTimeStampRaw *out, const char *path);
|
||||
|
||||
Result OpenFile(FileHandle *out, std::unique_ptr<fsa::IFile> &&file, int mode);
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere/fs/fs_common.hpp>
|
||||
#include <stratosphere/fs/fs_filesystem.hpp>
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
using FileTimeStampRaw = ::FsTimeStampRaw;
|
||||
|
||||
namespace impl {
|
||||
|
||||
Result GetFileTimeStampRawForDebug(FileTimeStampRaw *out, const char *path);
|
||||
|
||||
}
|
||||
|
||||
Result GetFileTimeStampRawForDebug(FileTimeStampRaw *out, const char *path);
|
||||
|
||||
}
|
|
@ -14,8 +14,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include "fs_common.hpp"
|
||||
#include "fs_filesystem.hpp"
|
||||
#include <stratosphere/fs/fs_common.hpp>
|
||||
#include <stratosphere/fs/fs_filesystem.hpp>
|
||||
#include <stratosphere/fs/fs_filesystem_for_debug.hpp>
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#pragma once
|
||||
#include "../fs_common.hpp"
|
||||
#include "../fs_filesystem.hpp"
|
||||
#include "../fs_filesystem_for_debug.hpp"
|
||||
|
||||
namespace ams::fs::fsa {
|
||||
|
||||
|
|
|
@ -74,68 +74,111 @@ namespace ams::fs::impl {
|
|||
const char *ToString(T id);
|
||||
};
|
||||
|
||||
template<typename T> requires (requires { T{}; })
|
||||
inline T DereferenceOutValue(T *out_value, Result result) {
|
||||
if (R_SUCCEEDED(result) && out_value != nullptr) {
|
||||
return *out_value;
|
||||
} else {
|
||||
return T{};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Access log result name. */
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_RESULT_NAME __tmp_ams_fs_access_log_result
|
||||
/* Access log utils. */
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_DEREFERENCE_OUT_VALUE(__VALUE__) ::ams::fs::impl::DereferenceOutValue(__VALUE__, AMS_FS_IMPL_ACCESS_LOG_RESULT_NAME)
|
||||
|
||||
/* Access log components. */
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_SIZE ", size: %" PRId64 ""
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_OFFSET_AND_SIZE ", offset: %" PRId64 ", size: %zu"
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_THREAD_ID ", thread_id: %" PRIu64 ""
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_SIZE ", size: %" PRId64 ""
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_READ_SIZE ", read_size: %zu"
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_OFFSET_AND_SIZE ", offset: %" PRId64 ", size: %zu"
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_THREAD_ID ", thread_id: %" PRIu64 ""
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_MOUNT ", name: \"%s\""
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_ENTRY_COUNT ", entry_count: %" PRId64 ""
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_ENTRY_BUFFER_COUNT ", entry_buffer_count: %" PRId64 ""
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_OPEN_MODE ", open_mode: 0x%" PRIX32 ""
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH ", path: \"%s\""
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH_AND_SIZE ", path: \"%s\", size: %" PRId64 ""
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH_AND_OPEN_MODE ", path: \"%s\", open_mode: 0x%" PRIX32 ""
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_RENAME ", path: \"%s\", new_path: \"%s\""
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_DIRECTORY_ENTRY_TYPE ", entry_type: %s"
|
||||
|
||||
/* Access log formats. */
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_NONE ""
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_NONE ""
|
||||
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_READ_FILE(__OUT_READ_SIZE__, __OFFSET__, __SIZE__) \
|
||||
AMS_FS_IMPL_ACCESS_LOG_FORMAT_OFFSET_AND_SIZE AMS_FS_IMPL_ACCESS_LOG_FORMAT_READ_SIZE, __OFFSET__, __SIZE__, AMS_FS_IMPL_ACCESS_LOG_DEREFERENCE_OUT_VALUE(__OUT_READ_SIZE__)
|
||||
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_WRITE_FILE_WITH_NO_OPTION AMS_FS_IMPL_ACCESS_LOG_FORMAT_OFFSET_AND_SIZE
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_WRITE_FILE_WITH_FLUSH_OPTION AMS_FS_IMPL_ACCESS_LOG_FORMAT_WRITE_FILE_WITH_NO_OPTION ", write_option: Flush"
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_WRITE_FILE(__OPTION__) ((__OPTION__).HasFlushFlag() ? AMS_FS_IMPL_ACCESS_LOG_FORMAT_WRITE_FILE_WITH_FLUSH_OPTION : AMS_FS_IMPL_ACCESS_LOG_FORMAT_WRITE_FILE_WITH_NO_OPTION)
|
||||
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_GET_FILE_SIZE(__OUT_SIZE__) \
|
||||
AMS_FS_IMPL_ACCESS_LOG_FORMAT_SIZE, AMS_FS_IMPL_ACCESS_LOG_DEREFERENCE_OUT_VALUE(__OUT_SIZE__)
|
||||
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_READ_DIRECTORY(__OUT_ENTRY_COUNT__, __ENTRY_BUFFER_COUNT__) \
|
||||
AMS_FS_IMPL_ACCESS_LOG_FORMAT_ENTRY_BUFFER_COUNT AMS_FS_IMPL_ACCESS_LOG_FORMAT_ENTRY_COUNT, __ENTRY_BUFFER_COUNT__, AMS_FS_IMPL_ACCESS_LOG_DEREFERENCE_OUT_VALUE(__OUT_ENTRY_COUNT__)
|
||||
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_GET_DIRECTORY_ENTRY_COUNT(__OUT_ENTRY_COUNT__) \
|
||||
AMS_FS_IMPL_ACCESS_LOG_FORMAT_ENTRY_COUNT, AMS_FS_IMPL_ACCESS_LOG_DEREFERENCE_OUT_VALUE(__OUT_ENTRY_COUNT__)
|
||||
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_GET_ENTRY_TYPE(__OUT_ENTRY_TYPE__, __PATH__) \
|
||||
AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH AMS_FS_IMPL_ACCESS_LOG_FORMAT_DIRECTORY_ENTRY_TYPE, __PATH__, ::ams::fs::impl::IdString().ToString(AMS_FS_IMPL_ACCESS_LOG_DEREFERENCE_OUT_VALUE(__OUT_ENTRY_TYPE__))
|
||||
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FORMAT_GET_SPACE_SIZE(__OUT_SIZE__, __NAME__) \
|
||||
AMS_FS_IMPL_ACCESS_LOG_FORMAT_MOUNT AMS_FS_IMPL_ACCESS_LOG_FORMAT_SIZE, __NAME__, AMS_FS_IMPL_ACCESS_LOG_DEREFERENCE_OUT_VALUE(__OUT_SIZE__)
|
||||
|
||||
/* Access log invocation lambdas. */
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_IMPL(__EXPR__, __HANDLE__, __ENABLED__, __NAME__, ...) \
|
||||
[&](const char *name) { \
|
||||
if (!(__ENABLED__)) { \
|
||||
return (__EXPR__); \
|
||||
} else { \
|
||||
const ::ams::os::Tick start = ::ams::os::GetSystemTick(); \
|
||||
const auto result = (__EXPR__); \
|
||||
const ::ams::os::Tick end = ::ams::os::GetSystemTick(); \
|
||||
::ams::fs::impl::OutputAccessLog(result, start, end, name, __HANDLE__, __VA_ARGS__); \
|
||||
return result; \
|
||||
} \
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_IMPL(__EXPR__, __HANDLE__, __ENABLED__, __NAME__, ...) \
|
||||
[&](const char *name) { \
|
||||
if (!(__ENABLED__)) { \
|
||||
return (__EXPR__); \
|
||||
} else { \
|
||||
const ::ams::os::Tick start = ::ams::os::GetSystemTick(); \
|
||||
const auto AMS_FS_IMPL_ACCESS_LOG_RESULT_NAME = (__EXPR__); \
|
||||
const ::ams::os::Tick end = ::ams::os::GetSystemTick(); \
|
||||
::ams::fs::impl::OutputAccessLog(AMS_FS_IMPL_ACCESS_LOG_RESULT_NAME, start, end, name, __HANDLE__, __VA_ARGS__); \
|
||||
return AMS_FS_IMPL_ACCESS_LOG_RESULT_NAME; \
|
||||
} \
|
||||
}(__NAME__)
|
||||
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_WITH_PRIORITY_IMPL(__EXPR__, __PRIORITY__, __HANDLE__, __ENABLED__, __NAME__, ...) \
|
||||
[&](const char *name) { \
|
||||
if (!(__ENABLED__)) { \
|
||||
return (__EXPR__); \
|
||||
} else { \
|
||||
const ::ams::os::Tick start = ::ams::os::GetSystemTick(); \
|
||||
const auto result = (__EXPR__); \
|
||||
const ::ams::os::Tick end = ::ams::os::GetSystemTick(); \
|
||||
::ams::fs::impl::OutputAccessLog(result, __PRIORITY__, start, end, name, __HANDLE__, __VA_ARGS__); \
|
||||
return result; \
|
||||
} \
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_WITH_PRIORITY_IMPL(__EXPR__, __PRIORITY__, __HANDLE__, __ENABLED__, __NAME__, ...) \
|
||||
[&](const char *name) { \
|
||||
if (!(__ENABLED__)) { \
|
||||
return (__EXPR__); \
|
||||
} else { \
|
||||
const ::ams::os::Tick start = ::ams::os::GetSystemTick(); \
|
||||
const auto AMS_FS_IMPL_ACCESS_LOG_RESULT_NAME = (__EXPR__); \
|
||||
const ::ams::os::Tick end = ::ams::os::GetSystemTick(); \
|
||||
::ams::fs::impl::OutputAccessLog(AMS_FS_IMPL_ACCESS_LOG_RESULT_NAME, __PRIORITY__, start, end, name, __HANDLE__, __VA_ARGS__); \
|
||||
return AMS_FS_IMPL_ACCESS_LOG_RESULT_NAME; \
|
||||
} \
|
||||
}(__NAME__)
|
||||
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_EXPLICIT_IMPL(__RESULT__, __START__, __END__, __HANDLE__, __ENABLED__, __NAME__, ...) \
|
||||
[&](const char *name) { \
|
||||
if (!(__ENABLED__)) { \
|
||||
return __RESULT__; \
|
||||
} else { \
|
||||
::ams::fs::impl::OutputAccessLog(__RESULT__, __START__, __END__, name, __HANDLE__, __VA_ARGS__); \
|
||||
return __RESULT__; \
|
||||
} \
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_EXPLICIT_IMPL(__RESULT__, __START__, __END__, __HANDLE__, __ENABLED__, __NAME__, ...) \
|
||||
[&](const char *name) { \
|
||||
if (!(__ENABLED__)) { \
|
||||
return __RESULT__; \
|
||||
} else { \
|
||||
const auto AMS_FS_IMPL_ACCESS_LOG_RESULT_NAME = (__RESULT__); \
|
||||
::ams::fs::impl::OutputAccessLog(AMS_FS_IMPL_ACCESS_LOG_RESULT_NAME, __START__, __END__, name, __HANDLE__, __VA_ARGS__); \
|
||||
return AMS_FS_IMPL_ACCESS_LOG_RESULT_NAME; \
|
||||
} \
|
||||
}(__NAME__)
|
||||
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED_IMPL(__EXPR__, __ENABLED__, __NAME__, ...) \
|
||||
[&](const char *name) { \
|
||||
if (!(__ENABLED__)) { \
|
||||
return (__EXPR__); \
|
||||
} else { \
|
||||
const ::ams::os::Tick start = ::ams::os::GetSystemTick(); \
|
||||
const auto result = (__EXPR__); \
|
||||
const ::ams::os::Tick end = ::ams::os::GetSystemTick(); \
|
||||
::ams::fs::impl::OutputAccessLogUnlessResultSuccess(result, start, end, name, nullptr, __VA_ARGS__); \
|
||||
return result; \
|
||||
} \
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED_IMPL(__EXPR__, __ENABLED__, __NAME__, ...) \
|
||||
[&](const char *name) { \
|
||||
if (!(__ENABLED__)) { \
|
||||
return (__EXPR__); \
|
||||
} else { \
|
||||
const ::ams::os::Tick start = ::ams::os::GetSystemTick(); \
|
||||
const auto AMS_FS_IMPL_ACCESS_LOG_RESULT_NAME = (__EXPR__); \
|
||||
const ::ams::os::Tick end = ::ams::os::GetSystemTick(); \
|
||||
::ams::fs::impl::OutputAccessLogUnlessResultSuccess(AMS_FS_IMPL_ACCESS_LOG_RESULT_NAME, start, end, name, nullptr, __VA_ARGS__); \
|
||||
return AMS_FS_IMPL_ACCESS_LOG_RESULT_NAME; \
|
||||
} \
|
||||
}(__NAME__)
|
||||
|
||||
|
||||
|
@ -151,3 +194,13 @@ namespace ams::fs::impl {
|
|||
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(__EXPR__, ...) \
|
||||
AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED_IMPL((__EXPR__), ::ams::fs::impl::IsEnabledAccessLog(), AMS_CURRENT_FUNCTION_NAME, __VA_ARGS__)
|
||||
|
||||
/* Specific utilities. */
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM(__EXPR__, __HANDLE__, __FILESYSTEM__, ...) \
|
||||
AMS_FS_IMPL_ACCESS_LOG_IMPL((__EXPR__), __HANDLE__, ::ams::fs::impl::IsEnabledAccessLog() && (__FILESYSTEM__)->IsEnabledAccessLog(), AMS_CURRENT_FUNCTION_NAME, __VA_ARGS__)
|
||||
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM_WITH_NAME(__EXPR__, __HANDLE__, __FILESYSTEM__, __NAME__, ...) \
|
||||
AMS_FS_IMPL_ACCESS_LOG_IMPL((__EXPR__), __HANDLE__, ::ams::fs::impl::IsEnabledAccessLog() && (__FILESYSTEM__)->IsEnabledAccessLog(), __NAME__, __VA_ARGS__)
|
||||
|
||||
#define AMS_FS_IMPL_ACCESS_LOG_UNMOUNT(__EXPR__, __MOUNT_NAME__, ...) \
|
||||
AMS_FS_IMPL_ACCESS_LOG_IMPL((__EXPR__), nullptr, ::ams::fs::impl::IsEnabledAccessLog() && ::ams::fs::impl::IsEnabledFileSystemAccessorAccessLog(__MOUNT_NAME__), AMS_CURRENT_FUNCTION_NAME, __VA_ARGS__)
|
||||
|
|
|
@ -44,6 +44,13 @@ namespace ams::fs::impl {
|
|||
AMS_FS_R_CHECK_ABORT_IMPL(__tmp_fs_result, true); \
|
||||
})
|
||||
|
||||
#define AMS_FS_ABORT_UNLESS_WITH_RESULT(__EXPR__, __RESULT__) \
|
||||
({ \
|
||||
if (!(__EXPR__)) { \
|
||||
AMS_FS_R_ABORT_UNLESS((__RESULT__)); \
|
||||
} \
|
||||
})
|
||||
|
||||
#define AMS_FS_R_THROW(__RESULT__) \
|
||||
({ \
|
||||
const ::ams::Result __tmp_fs_result = (__RESULT__); \
|
||||
|
|
|
@ -29,8 +29,8 @@ namespace ams::fs::impl {
|
|||
|
||||
FileAccessor::~FileAccessor() {
|
||||
/* Ensure that all files are flushed. */
|
||||
if (R_FAILED(this->write_result)) {
|
||||
AMS_ABORT_UNLESS(this->write_state != WriteState::NeedsFlush);
|
||||
if (R_SUCCEEDED(this->write_result)) {
|
||||
AMS_FS_ABORT_UNLESS_WITH_RESULT(this->write_state != WriteState::NeedsFlush, fs::ResultNeedFlush());
|
||||
}
|
||||
this->impl.reset();
|
||||
|
||||
|
@ -40,6 +40,7 @@ namespace ams::fs::impl {
|
|||
}
|
||||
|
||||
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_ABORT();
|
||||
}
|
||||
|
||||
|
@ -48,10 +49,12 @@ namespace ams::fs::impl {
|
|||
}
|
||||
|
||||
Result FileAccessor::Read(size_t *out, s64 offset, void *buf, size_t size, const ReadOption &option) {
|
||||
/* Fail after a write fails. */
|
||||
R_TRY(this->write_result);
|
||||
/* Get a handle to this file for use in logging. */
|
||||
FileHandle handle = { this };
|
||||
|
||||
/* Fail after a write fails. */
|
||||
R_UNLESS(R_SUCCEEDED(this->write_result), AMS_FS_IMPL_ACCESS_LOG_WITH_NAME(this->write_result, handle, "ReadFile", AMS_FS_IMPL_ACCESS_LOG_FORMAT_READ_FILE(out, offset, size)));
|
||||
|
||||
/* TODO: Logging. */
|
||||
/* TODO: Support cache. */
|
||||
const bool use_path_cache = this->parent != nullptr && this->file_path_hash != nullptr;
|
||||
const bool use_data_cache = /* TODO */false && this->parent != nullptr && this->parent->IsFileDataCacheAttachable();
|
||||
|
@ -60,7 +63,7 @@ namespace ams::fs::impl {
|
|||
/* TODO */
|
||||
return this->ReadWithCacheAccessLog(out, offset, buf, size, option, use_path_cache, use_data_cache);
|
||||
} else {
|
||||
return this->ReadWithoutCacheAccessLog(out, offset, buf, size, option);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -120,49 +120,49 @@ namespace ams::fs::impl {
|
|||
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);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
namespace {
|
||||
|
||||
Result UnmountImpl(const char *name) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
R_TRY(impl::Find(std::addressof(accessor), name));
|
||||
|
||||
if (accessor->IsFileDataCacheAttachable()) {
|
||||
/* TODO: Data cache purge */
|
||||
}
|
||||
|
||||
impl::Unregister(name);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result ConvertToFsCommonPath(char *dst, size_t dst_size, const char *src) {
|
||||
/* Ensure neither argument is nullptr. */
|
||||
R_UNLESS(dst != nullptr, fs::ResultNullptrArgument());
|
||||
R_UNLESS(src != nullptr, fs::ResultNullptrArgument());
|
||||
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;
|
||||
R_TRY(impl::GetMountNameAndSubPath(std::addressof(mount_name), std::addressof(sub_path), src));
|
||||
AMS_FS_R_TRY(impl::GetMountNameAndSubPath(std::addressof(mount_name), std::addressof(sub_path), src));
|
||||
|
||||
impl::FileSystemAccessor *accessor;
|
||||
R_TRY(impl::Find(std::addressof(accessor), mount_name.str));
|
||||
R_TRY(accessor->GetCommonMountName(dst, dst_size));
|
||||
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 = strnlen(dst, dst_size);
|
||||
const auto common_path_len = std::snprintf(dst + mount_name_len, dst_size - mount_name_len, "%s", sub_path);
|
||||
|
||||
R_UNLESS(static_cast<size_t>(common_path_len) < dst_size - mount_name_len, fs::ResultTooLongPath());
|
||||
AMS_FS_R_UNLESS(static_cast<size_t>(common_path_len) < dst_size - mount_name_len, fs::ResultTooLongPath());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void Unmount(const char *mount_name) {
|
||||
R_ABORT_UNLESS(UnmountImpl(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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace ams::fs::impl {
|
|||
|
||||
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);
|
||||
|
||||
|
|
|
@ -28,15 +28,17 @@ namespace ams::fs {
|
|||
}
|
||||
|
||||
Result ReadDirectory(s64 *out_count, DirectoryEntry *out_entries, DirectoryHandle handle, s64 max_entries) {
|
||||
return Get(handle)->Read(out_count, out_entries, 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)));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result GetDirectoryEntryCount(s64 *out, DirectoryHandle handle) {
|
||||
return Get(handle)->GetEntryCount(out);
|
||||
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)));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void CloseDirectory(DirectoryHandle handle) {
|
||||
delete Get(handle);
|
||||
AMS_FS_IMPL_ACCESS_LOG((delete Get(handle), ResultSuccess()), handle, AMS_FS_IMPL_ACCESS_LOG_FORMAT_NONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,30 +25,39 @@ namespace ams::fs {
|
|||
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));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result ReadFile(FileHandle handle, s64 offset, void *buffer, size_t size, const fs::ReadOption &option) {
|
||||
size_t read_size;
|
||||
AMS_FS_R_TRY(ReadFile(std::addressof(read_size), handle, offset, buffer, size, option));
|
||||
AMS_FS_R_TRY(ReadFileImpl(std::addressof(read_size), handle, offset, buffer, size, option));
|
||||
AMS_FS_R_UNLESS(read_size == size, fs::ResultOutOfRange());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ReadFile(FileHandle handle, s64 offset, void *buffer, size_t size) {
|
||||
return ReadFile(handle, offset, buffer, size, ReadOption());
|
||||
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());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ReadFile(size_t *out, FileHandle handle, s64 offset, void *buffer, size_t size, const fs::ReadOption &option) {
|
||||
AMS_FS_R_TRY(Get(handle)->Read(out, offset, buffer, size, option));
|
||||
AMS_FS_R_TRY(ReadFileImpl(out, handle, offset, buffer, size, option));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ReadFile(size_t *out, FileHandle handle, s64 offset, void *buffer, size_t size) {
|
||||
return ReadFile(out, handle, offset, buffer, size, ReadOption());
|
||||
AMS_FS_R_TRY(ReadFileImpl(out, handle, offset, buffer, size, ReadOption()));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result GetFileSize(s64 *out, FileHandle handle) {
|
||||
AMS_FS_R_TRY(Get(handle)->GetSize(out));
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG(Get(handle)->GetSize(out), handle, AMS_FS_IMPL_ACCESS_LOG_FORMAT_GET_FILE_SIZE(out)));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
|
@ -68,7 +77,9 @@ namespace ams::fs {
|
|||
}
|
||||
|
||||
int GetFileOpenMode(FileHandle handle) {
|
||||
return Get(handle)->GetOpenMode();
|
||||
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) {
|
||||
|
|
|
@ -29,41 +29,46 @@ namespace ams::fs {
|
|||
Result CreateFile(const char* path, s64 size, int option) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), 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));
|
||||
|
||||
return accessor->CreateFile(sub_path, size, option);
|
||||
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));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result DeleteFile(const char *path) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), 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));
|
||||
|
||||
return accessor->DeleteFile(sub_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));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result CreateDirectory(const char *path) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), 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));
|
||||
|
||||
return accessor->CreateDirectory(sub_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));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result DeleteDirectory(const char *path) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), 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));
|
||||
|
||||
return accessor->DeleteDirectory(sub_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));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result DeleteDirectoryRecursively(const char *path) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), 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));
|
||||
|
||||
return accessor->DeleteDirectoryRecursively(sub_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));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RenameFile(const char *old_path, const char *new_path) {
|
||||
|
@ -71,11 +76,17 @@ namespace ams::fs {
|
|||
impl::FileSystemAccessor *new_accessor;
|
||||
const char *old_sub_path;
|
||||
const char *new_sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(old_accessor), std::addressof(old_sub_path), old_path));
|
||||
R_TRY(impl::FindFileSystem(std::addressof(new_accessor), std::addressof(new_sub_path), new_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));
|
||||
|
||||
R_UNLESS(old_accessor == new_accessor, fs::ResultRenameToOtherFileSystem());
|
||||
return old_accessor->RenameFile(old_sub_path, new_sub_path);
|
||||
auto rename_impl = [=]() -> Result {
|
||||
R_UNLESS(old_accessor == new_accessor, fs::ResultRenameToOtherFileSystem());
|
||||
R_TRY(old_accessor->RenameFile(old_sub_path, new_sub_path));
|
||||
return ResultSuccess();
|
||||
};
|
||||
|
||||
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));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RenameDirectory(const char *old_path, const char *new_path) {
|
||||
|
@ -83,30 +94,42 @@ namespace ams::fs {
|
|||
impl::FileSystemAccessor *new_accessor;
|
||||
const char *old_sub_path;
|
||||
const char *new_sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(old_accessor), std::addressof(old_sub_path), old_path));
|
||||
R_TRY(impl::FindFileSystem(std::addressof(new_accessor), std::addressof(new_sub_path), new_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));
|
||||
|
||||
R_UNLESS(old_accessor == new_accessor, fs::ResultRenameToOtherFileSystem());
|
||||
return old_accessor->RenameDirectory(old_sub_path, new_sub_path);
|
||||
auto rename_impl = [=]() -> Result {
|
||||
R_UNLESS(old_accessor == new_accessor, fs::ResultRenameToOtherFileSystem());
|
||||
R_TRY(old_accessor->RenameDirectory(old_sub_path, new_sub_path));
|
||||
return ResultSuccess();
|
||||
};
|
||||
|
||||
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));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result GetEntryType(DirectoryEntryType *out, const char *path) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), 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));
|
||||
|
||||
return accessor->GetEntryType(out, sub_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)));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result OpenFile(FileHandle *out_file, const char *path, int mode) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path));
|
||||
|
||||
R_UNLESS(out_file != nullptr, fs::ResultNullptrArgument());
|
||||
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;
|
||||
R_TRY(accessor->OpenFile(std::addressof(file_accessor), sub_path, static_cast<OpenMode>(mode)));
|
||||
|
||||
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)));
|
||||
return ResultSuccess();
|
||||
};
|
||||
|
||||
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();
|
||||
return ResultSuccess();
|
||||
|
@ -115,12 +138,17 @@ namespace ams::fs {
|
|||
Result OpenDirectory(DirectoryHandle *out_dir, const char *path, int mode) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path));
|
||||
|
||||
R_UNLESS(out_dir != nullptr, fs::ResultNullptrArgument());
|
||||
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;
|
||||
R_TRY(accessor->OpenDirectory(std::addressof(dir_accessor), sub_path, static_cast<OpenDirectoryMode>(mode)));
|
||||
|
||||
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)));
|
||||
return ResultSuccess();
|
||||
};
|
||||
|
||||
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();
|
||||
return ResultSuccess();
|
||||
|
@ -129,48 +157,86 @@ namespace ams::fs {
|
|||
Result CleanDirectoryRecursively(const char *path) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), 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));
|
||||
|
||||
return accessor->CleanDirectoryRecursively(sub_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));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result GetFreeSpaceSize(s64 *out, const char *path) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path));
|
||||
const char *sub_path = nullptr;
|
||||
|
||||
return accessor->GetFreeSpaceSize(out, sub_path);
|
||||
/* Get the accessor. */
|
||||
auto find_impl = [&]() -> Result {
|
||||
R_UNLESS(out != nullptr, fs::ResultNullptrArgument());
|
||||
R_UNLESS(path != nullptr, fs::ResultNullptrArgument());
|
||||
if (impl::IsValidMountName(path)) {
|
||||
R_TRY(impl::Find(std::addressof(accessor), path));
|
||||
} else {
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path));
|
||||
}
|
||||
return ResultSuccess();
|
||||
};
|
||||
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(find_impl(), AMS_FS_IMPL_ACCESS_LOG_FORMAT_GET_SPACE_SIZE(out, path)));
|
||||
|
||||
/* Get the space size. */
|
||||
auto get_size_impl = [&]() -> Result {
|
||||
R_UNLESS(sub_path == nullptr || std::strcmp(sub_path, "/") == 0, fs::ResultInvalidMountName());
|
||||
R_TRY(accessor->GetFreeSpaceSize(out, path));
|
||||
return ResultSuccess();
|
||||
};
|
||||
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM(get_size_impl(), nullptr, accessor, AMS_FS_IMPL_ACCESS_LOG_FORMAT_GET_SPACE_SIZE(out, path)));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result GetTotalSpaceSize(s64 *out, const char *path) {
|
||||
/* NOTE: Nintendo does not do access logging here, and does not support mount-name instead of path. */
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path));
|
||||
const char *sub_path = nullptr;
|
||||
|
||||
return accessor->GetTotalSpaceSize(out, sub_path);
|
||||
/* Get the accessor. */
|
||||
auto find_impl = [&]() -> Result {
|
||||
R_UNLESS(out != nullptr, fs::ResultNullptrArgument());
|
||||
R_UNLESS(path != nullptr, fs::ResultNullptrArgument());
|
||||
if (impl::IsValidMountName(path)) {
|
||||
R_TRY(impl::Find(std::addressof(accessor), path));
|
||||
} else {
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path));
|
||||
}
|
||||
return ResultSuccess();
|
||||
};
|
||||
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(find_impl(), AMS_FS_IMPL_ACCESS_LOG_FORMAT_GET_SPACE_SIZE(out, path)));
|
||||
|
||||
/* Get the space size. */
|
||||
auto get_size_impl = [&]() -> Result {
|
||||
R_UNLESS(sub_path == nullptr || std::strcmp(sub_path, "/") == 0, fs::ResultInvalidMountName());
|
||||
R_TRY(accessor->GetTotalSpaceSize(out, path));
|
||||
return ResultSuccess();
|
||||
};
|
||||
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM(get_size_impl(), nullptr, accessor, AMS_FS_IMPL_ACCESS_LOG_FORMAT_GET_SPACE_SIZE(out, path)));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result SetConcatenationFileAttribute(const char *path) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path));
|
||||
AMS_FS_R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path));
|
||||
|
||||
return accessor->QueryEntry(nullptr, 0, nullptr, 0, fsa::QueryId::SetConcatenationFileAttribute, sub_path);
|
||||
}
|
||||
AMS_FS_R_TRY(accessor->QueryEntry(nullptr, 0, nullptr, 0, fsa::QueryId::SetConcatenationFileAttribute, sub_path));
|
||||
|
||||
Result GetFileTimeStampRaw(FileTimeStampRaw *out, const char *path) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path));
|
||||
|
||||
return accessor->GetFileTimeStampRaw(out, sub_path);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result OpenFile(FileHandle *out, std::unique_ptr<fsa::IFile> &&file, int mode) {
|
||||
R_UNLESS(out != nullptr, fs::ResultNullptrArgument());
|
||||
AMS_FS_R_UNLESS(out != nullptr, fs::ResultNullptrArgument());
|
||||
|
||||
auto file_accessor = std::make_unique<impl::FileAccessor>(std::move(file), nullptr, static_cast<OpenMode>(mode));
|
||||
R_UNLESS(file_accessor != nullptr, fs::ResultAllocationFailureInNew());
|
||||
AMS_FS_R_UNLESS(file_accessor != nullptr, fs::ResultAllocationFailureInNew());
|
||||
out->handle = file_accessor.release();
|
||||
|
||||
return ResultSuccess();
|
||||
|
@ -178,22 +244,22 @@ namespace ams::fs {
|
|||
|
||||
namespace {
|
||||
|
||||
Result CommitImpl(const char *path) {
|
||||
Result CommitImpl(const char *path, const char *func_name) {
|
||||
impl::FileSystemAccessor *accessor;
|
||||
R_TRY(impl::Find(std::addressof(accessor), path));
|
||||
AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(impl::Find(std::addressof(accessor), path), AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH, path));
|
||||
|
||||
return accessor->Commit();
|
||||
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, path));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result Commit(const char *path) {
|
||||
return CommitImpl(path);
|
||||
return CommitImpl(path, AMS_CURRENT_FUNCTION_NAME);
|
||||
}
|
||||
|
||||
Result CommitSaveData(const char *path) {
|
||||
return CommitImpl(path);
|
||||
return CommitImpl(path, AMS_CURRENT_FUNCTION_NAME);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#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));
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result GetFileTimeStampRawForDebug(FileTimeStampRaw *out, const char *path) {
|
||||
AMS_FS_R_TRY(GetFileTimeStampRawForDebug(out, path));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
|
@ -38,9 +38,6 @@ namespace ams::sf {
|
|||
}
|
||||
|
||||
InlineContext GetInlineContext() {
|
||||
/* Get current thread. */
|
||||
os::ThreadType * const cur_thread = os::GetCurrentThread();
|
||||
|
||||
/* Get the context. */
|
||||
uintptr_t thread_context = GetAtomicSfInlineContext()->load();
|
||||
|
||||
|
@ -62,7 +59,7 @@ namespace ams::sf {
|
|||
std::memcpy(std::addressof(new_context_value), std::addressof(ctx), sizeof(ctx));
|
||||
|
||||
/* Get the old context. */
|
||||
uintptr_t old_context_value = GetAtomicSfInlineContext()->exchange(new_context_value);
|
||||
uintptr_t old_context_value = GetAtomicSfInlineContext(cur_thread)->exchange(new_context_value);
|
||||
|
||||
/* Convert and copy it out. */
|
||||
InlineContext old_ctx;
|
||||
|
|
Loading…
Reference in a new issue