fs: use access_log for other user fs/dir/file bindings

This commit is contained in:
Michael Scire 2020-07-01 01:27:23 -07:00 committed by SciresM
parent e2b17086d4
commit 70e67da1e1
14 changed files with 356 additions and 141 deletions

View file

@ -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));
}
}

View file

@ -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));
}
}

View file

@ -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);

View file

@ -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);
}
}

View file

@ -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) {

View file

@ -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);
}
}

View file

@ -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();
}
}

View file

@ -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;