diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/core/file_sys/fs_filesystem.h | 2 | ||||
| -rw-r--r-- | src/core/file_sys/fs_memory_management.h | 8 | ||||
| -rw-r--r-- | src/core/file_sys/fs_path.h | 2 | ||||
| -rw-r--r-- | src/core/file_sys/fs_string_util.h | 15 | ||||
| -rw-r--r-- | src/core/file_sys/fsa/fs_i_directory.h | 89 | ||||
| -rw-r--r-- | src/core/file_sys/fsa/fs_i_file.h | 167 | ||||
| -rw-r--r-- | src/core/file_sys/fsa/fs_i_filesystem.h | 207 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/fsp/fs_i_directory.cpp | 58 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/fsp/fs_i_directory.h | 7 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/fsp/fs_i_file.cpp | 74 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/fsp/fs_i_file.h | 5 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp | 41 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/fsp/fs_i_filesystem.h | 5 |
14 files changed, 554 insertions, 130 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 23f717472..24dcc405f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -59,8 +59,12 @@ add_library(core STATIC | |||
| 59 | file_sys/fs_path.h | 59 | file_sys/fs_path.h |
| 60 | file_sys/fs_path_utility.h | 60 | file_sys/fs_path_utility.h |
| 61 | file_sys/fs_string_util.h | 61 | file_sys/fs_string_util.h |
| 62 | file_sys/fsa/fs_i_directory.h | ||
| 63 | file_sys/fsa/fs_i_file.h | ||
| 64 | file_sys/fsa/fs_i_filesystem.h | ||
| 62 | file_sys/fsmitm_romfsbuild.cpp | 65 | file_sys/fsmitm_romfsbuild.cpp |
| 63 | file_sys/fsmitm_romfsbuild.h | 66 | file_sys/fsmitm_romfsbuild.h |
| 67 | file_sys/fssrv/fssrv_sf_path.h | ||
| 64 | file_sys/fssystem/fs_i_storage.h | 68 | file_sys/fssystem/fs_i_storage.h |
| 65 | file_sys/fssystem/fs_types.h | 69 | file_sys/fssystem/fs_types.h |
| 66 | file_sys/fssystem/fssystem_aes_ctr_counter_extended_storage.cpp | 70 | file_sys/fssystem/fssystem_aes_ctr_counter_extended_storage.cpp |
diff --git a/src/core/file_sys/fs_filesystem.h b/src/core/file_sys/fs_filesystem.h index 7f237b7fa..7065ef6a6 100644 --- a/src/core/file_sys/fs_filesystem.h +++ b/src/core/file_sys/fs_filesystem.h | |||
| @@ -23,6 +23,8 @@ enum class OpenDirectoryMode : u64 { | |||
| 23 | File = (1 << 1), | 23 | File = (1 << 1), |
| 24 | 24 | ||
| 25 | All = (Directory | File), | 25 | All = (Directory | File), |
| 26 | |||
| 27 | NotRequireFileSize = (1 << 31), | ||
| 26 | }; | 28 | }; |
| 27 | DECLARE_ENUM_FLAG_OPERATORS(OpenDirectoryMode) | 29 | DECLARE_ENUM_FLAG_OPERATORS(OpenDirectoryMode) |
| 28 | 30 | ||
diff --git a/src/core/file_sys/fs_memory_management.h b/src/core/file_sys/fs_memory_management.h index f03c6354b..080017c5d 100644 --- a/src/core/file_sys/fs_memory_management.h +++ b/src/core/file_sys/fs_memory_management.h | |||
| @@ -10,7 +10,7 @@ namespace FileSys { | |||
| 10 | 10 | ||
| 11 | constexpr size_t RequiredAlignment = alignof(u64); | 11 | constexpr size_t RequiredAlignment = alignof(u64); |
| 12 | 12 | ||
| 13 | void* AllocateUnsafe(size_t size) { | 13 | inline void* AllocateUnsafe(size_t size) { |
| 14 | // Allocate | 14 | // Allocate |
| 15 | void* const ptr = ::operator new(size, std::align_val_t{RequiredAlignment}); | 15 | void* const ptr = ::operator new(size, std::align_val_t{RequiredAlignment}); |
| 16 | 16 | ||
| @@ -21,16 +21,16 @@ void* AllocateUnsafe(size_t size) { | |||
| 21 | return ptr; | 21 | return ptr; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | void DeallocateUnsafe(void* ptr, size_t size) { | 24 | inline void DeallocateUnsafe(void* ptr, size_t size) { |
| 25 | // Deallocate the pointer | 25 | // Deallocate the pointer |
| 26 | ::operator delete(ptr, std::align_val_t{RequiredAlignment}); | 26 | ::operator delete(ptr, std::align_val_t{RequiredAlignment}); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | void* Allocate(size_t size) { | 29 | inline void* Allocate(size_t size) { |
| 30 | return AllocateUnsafe(size); | 30 | return AllocateUnsafe(size); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | void Deallocate(void* ptr, size_t size) { | 33 | inline void Deallocate(void* ptr, size_t size) { |
| 34 | // If the pointer is non-null, deallocate it | 34 | // If the pointer is non-null, deallocate it |
| 35 | if (ptr != nullptr) { | 35 | if (ptr != nullptr) { |
| 36 | DeallocateUnsafe(ptr, size); | 36 | DeallocateUnsafe(ptr, size); |
diff --git a/src/core/file_sys/fs_path.h b/src/core/file_sys/fs_path.h index 56ba08a6a..1566e82b9 100644 --- a/src/core/file_sys/fs_path.h +++ b/src/core/file_sys/fs_path.h | |||
| @@ -381,7 +381,7 @@ public: | |||
| 381 | 381 | ||
| 382 | // Check that it's possible for us to remove a child | 382 | // Check that it's possible for us to remove a child |
| 383 | auto* p = m_write_buffer.Get(); | 383 | auto* p = m_write_buffer.Get(); |
| 384 | s32 len = std::strlen(p); | 384 | s32 len = static_cast<s32>(std::strlen(p)); |
| 385 | R_UNLESS(len != 1 || (p[0] != '/' && p[0] != '.'), ResultNotImplemented); | 385 | R_UNLESS(len != 1 || (p[0] != '/' && p[0] != '.'), ResultNotImplemented); |
| 386 | 386 | ||
| 387 | // Handle a trailing separator | 387 | // Handle a trailing separator |
diff --git a/src/core/file_sys/fs_string_util.h b/src/core/file_sys/fs_string_util.h index 874e09054..c751a8f1a 100644 --- a/src/core/file_sys/fs_string_util.h +++ b/src/core/file_sys/fs_string_util.h | |||
| @@ -20,6 +20,11 @@ constexpr int Strlen(const T* str) { | |||
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | template <typename T> | 22 | template <typename T> |
| 23 | constexpr int Strnlen(const T* str, std::size_t count) { | ||
| 24 | return Strnlen(str, static_cast<int>(count)); | ||
| 25 | } | ||
| 26 | |||
| 27 | template <typename T> | ||
| 23 | constexpr int Strnlen(const T* str, int count) { | 28 | constexpr int Strnlen(const T* str, int count) { |
| 24 | ASSERT(str != nullptr); | 29 | ASSERT(str != nullptr); |
| 25 | ASSERT(count >= 0); | 30 | ASSERT(count >= 0); |
| @@ -33,6 +38,11 @@ constexpr int Strnlen(const T* str, int count) { | |||
| 33 | } | 38 | } |
| 34 | 39 | ||
| 35 | template <typename T> | 40 | template <typename T> |
| 41 | constexpr int Strncmp(const T* lhs, const T* rhs, std::size_t count) { | ||
| 42 | return Strncmp(lhs, rhs, static_cast<int>(count)); | ||
| 43 | } | ||
| 44 | |||
| 45 | template <typename T> | ||
| 36 | constexpr int Strncmp(const T* lhs, const T* rhs, int count) { | 46 | constexpr int Strncmp(const T* lhs, const T* rhs, int count) { |
| 37 | ASSERT(lhs != nullptr); | 47 | ASSERT(lhs != nullptr); |
| 38 | ASSERT(rhs != nullptr); | 48 | ASSERT(rhs != nullptr); |
| @@ -52,6 +62,11 @@ constexpr int Strncmp(const T* lhs, const T* rhs, int count) { | |||
| 52 | } | 62 | } |
| 53 | 63 | ||
| 54 | template <typename T> | 64 | template <typename T> |
| 65 | static constexpr int Strlcpy(T* dst, const T* src, std::size_t count) { | ||
| 66 | return Strlcpy<T>(dst, src, static_cast<int>(count)); | ||
| 67 | } | ||
| 68 | |||
| 69 | template <typename T> | ||
| 55 | static constexpr int Strlcpy(T* dst, const T* src, int count) { | 70 | static constexpr int Strlcpy(T* dst, const T* src, int count) { |
| 56 | ASSERT(dst != nullptr); | 71 | ASSERT(dst != nullptr); |
| 57 | ASSERT(src != nullptr); | 72 | ASSERT(src != nullptr); |
diff --git a/src/core/file_sys/fsa/fs_i_directory.h b/src/core/file_sys/fsa/fs_i_directory.h new file mode 100644 index 000000000..a4135efec --- /dev/null +++ b/src/core/file_sys/fsa/fs_i_directory.h | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "common/common_types.h" | ||
| 7 | #include "core/file_sys/errors.h" | ||
| 8 | #include "core/file_sys/fs_directory.h" | ||
| 9 | #include "core/file_sys/fs_file.h" | ||
| 10 | #include "core/file_sys/fs_filesystem.h" | ||
| 11 | #include "core/file_sys/savedata_factory.h" | ||
| 12 | #include "core/file_sys/vfs/vfs.h" | ||
| 13 | #include "core/hle/result.h" | ||
| 14 | |||
| 15 | namespace FileSys::Fsa { | ||
| 16 | |||
| 17 | class IDirectory { | ||
| 18 | public: | ||
| 19 | IDirectory(VirtualDir backend_, OpenDirectoryMode mode) : backend(std::move(backend_)) { | ||
| 20 | // TODO(DarkLordZach): Verify that this is the correct behavior. | ||
| 21 | // Build entry index now to save time later. | ||
| 22 | if (True(mode & OpenDirectoryMode::Directory)) { | ||
| 23 | BuildEntryIndex(entries, backend->GetSubdirectories(), DirectoryEntryType::Directory); | ||
| 24 | } | ||
| 25 | if (True(mode & OpenDirectoryMode::File)) { | ||
| 26 | BuildEntryIndex(entries, backend->GetFiles(), DirectoryEntryType::File); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | virtual ~IDirectory() {} | ||
| 30 | |||
| 31 | Result Read(s64* out_count, DirectoryEntry* out_entries, s64 max_entries) { | ||
| 32 | R_UNLESS(out_count != nullptr, ResultNullptrArgument); | ||
| 33 | if (max_entries == 0) { | ||
| 34 | *out_count = 0; | ||
| 35 | R_SUCCEED(); | ||
| 36 | } | ||
| 37 | R_UNLESS(out_entries != nullptr, ResultNullptrArgument); | ||
| 38 | R_UNLESS(max_entries > 0, ResultInvalidArgument); | ||
| 39 | R_RETURN(this->DoRead(out_count, out_entries, max_entries)); | ||
| 40 | } | ||
| 41 | |||
| 42 | Result GetEntryCount(s64* out) { | ||
| 43 | R_UNLESS(out != nullptr, ResultNullptrArgument); | ||
| 44 | R_RETURN(this->DoGetEntryCount(out)); | ||
| 45 | } | ||
| 46 | |||
| 47 | private: | ||
| 48 | virtual Result DoRead(s64* out_count, DirectoryEntry* out_entries, s64 max_entries) { | ||
| 49 | const u64 actual_entries = | ||
| 50 | std::min(static_cast<u64>(max_entries), entries.size() - next_entry_index); | ||
| 51 | auto* begin = reinterpret_cast<u8*>(entries.data() + next_entry_index); | ||
| 52 | |||
| 53 | next_entry_index += actual_entries; | ||
| 54 | *out_count = actual_entries; | ||
| 55 | |||
| 56 | out_entries = reinterpret_cast<DirectoryEntry*>(begin); | ||
| 57 | |||
| 58 | R_SUCCEED(); | ||
| 59 | } | ||
| 60 | |||
| 61 | virtual Result DoGetEntryCount(s64* out) { | ||
| 62 | *out = entries.size() - next_entry_index; | ||
| 63 | R_SUCCEED(); | ||
| 64 | } | ||
| 65 | |||
| 66 | // TODO: Remove this when VFS is gone | ||
| 67 | template <typename T> | ||
| 68 | void BuildEntryIndex(std::vector<DirectoryEntry>& entries, const std::vector<T>& new_data, | ||
| 69 | DirectoryEntryType type) { | ||
| 70 | entries.reserve(entries.size() + new_data.size()); | ||
| 71 | |||
| 72 | for (const auto& new_entry : new_data) { | ||
| 73 | auto name = new_entry->GetName(); | ||
| 74 | |||
| 75 | if (type == DirectoryEntryType::File && name == GetSaveDataSizeFileName()) { | ||
| 76 | continue; | ||
| 77 | } | ||
| 78 | |||
| 79 | entries.emplace_back(name, static_cast<s8>(type), | ||
| 80 | type == DirectoryEntryType::Directory ? 0 : new_entry->GetSize()); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | VirtualDir backend; | ||
| 85 | std::vector<DirectoryEntry> entries; | ||
| 86 | u64 next_entry_index = 0; | ||
| 87 | }; | ||
| 88 | |||
| 89 | } // namespace FileSys::Fsa | ||
diff --git a/src/core/file_sys/fsa/fs_i_file.h b/src/core/file_sys/fsa/fs_i_file.h new file mode 100644 index 000000000..6dd0f6439 --- /dev/null +++ b/src/core/file_sys/fsa/fs_i_file.h | |||
| @@ -0,0 +1,167 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "common/overflow.h" | ||
| 7 | #include "core/file_sys/errors.h" | ||
| 8 | #include "core/file_sys/fs_file.h" | ||
| 9 | #include "core/file_sys/fs_filesystem.h" | ||
| 10 | #include "core/file_sys/fs_operate_range.h" | ||
| 11 | #include "core/file_sys/vfs/vfs.h" | ||
| 12 | #include "core/file_sys/vfs/vfs_types.h" | ||
| 13 | #include "core/hle/result.h" | ||
| 14 | |||
| 15 | namespace FileSys::Fsa { | ||
| 16 | |||
| 17 | class IFile { | ||
| 18 | public: | ||
| 19 | IFile(VirtualFile backend_) : backend(std::move(backend_)) {} | ||
| 20 | virtual ~IFile() {} | ||
| 21 | |||
| 22 | Result Read(size_t* out, s64 offset, void* buffer, size_t size, const ReadOption& option) { | ||
| 23 | // Check that we have an output pointer | ||
| 24 | R_UNLESS(out != nullptr, ResultNullptrArgument); | ||
| 25 | |||
| 26 | // If we have nothing to read, just succeed | ||
| 27 | if (size == 0) { | ||
| 28 | *out = 0; | ||
| 29 | R_SUCCEED(); | ||
| 30 | } | ||
| 31 | |||
| 32 | // Check that the read is valid | ||
| 33 | R_UNLESS(buffer != nullptr, ResultNullptrArgument); | ||
| 34 | R_UNLESS(offset >= 0, ResultOutOfRange); | ||
| 35 | R_UNLESS(Common::CanAddWithoutOverflow<s64>(offset, size), ResultOutOfRange); | ||
| 36 | |||
| 37 | // Do the read | ||
| 38 | R_RETURN(this->DoRead(out, offset, buffer, size, option)); | ||
| 39 | } | ||
| 40 | |||
| 41 | Result Read(size_t* out, s64 offset, void* buffer, size_t size) { | ||
| 42 | R_RETURN(this->Read(out, offset, buffer, size, ReadOption::None)); | ||
| 43 | } | ||
| 44 | |||
| 45 | Result GetSize(s64* out) { | ||
| 46 | R_UNLESS(out != nullptr, ResultNullptrArgument); | ||
| 47 | R_RETURN(this->DoGetSize(out)); | ||
| 48 | } | ||
| 49 | |||
| 50 | Result Flush() { | ||
| 51 | R_RETURN(this->DoFlush()); | ||
| 52 | } | ||
| 53 | |||
| 54 | Result Write(s64 offset, const void* buffer, size_t size, const WriteOption& option) { | ||
| 55 | // Handle the zero-size case | ||
| 56 | if (size == 0) { | ||
| 57 | if (option.HasFlushFlag()) { | ||
| 58 | R_TRY(this->Flush()); | ||
| 59 | } | ||
| 60 | R_SUCCEED(); | ||
| 61 | } | ||
| 62 | |||
| 63 | // Check the write is valid | ||
| 64 | R_UNLESS(buffer != nullptr, ResultNullptrArgument); | ||
| 65 | R_UNLESS(offset >= 0, ResultOutOfRange); | ||
| 66 | R_UNLESS(Common::CanAddWithoutOverflow<s64>(offset, size), ResultOutOfRange); | ||
| 67 | |||
| 68 | R_RETURN(this->DoWrite(offset, buffer, size, option)); | ||
| 69 | } | ||
| 70 | |||
| 71 | Result SetSize(s64 size) { | ||
| 72 | R_UNLESS(size >= 0, ResultOutOfRange); | ||
| 73 | R_RETURN(this->DoSetSize(size)); | ||
| 74 | } | ||
| 75 | |||
| 76 | Result OperateRange(void* dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, | ||
| 77 | const void* src, size_t src_size) { | ||
| 78 | R_RETURN(this->DoOperateRange(dst, dst_size, op_id, offset, size, src, src_size)); | ||
| 79 | } | ||
| 80 | |||
| 81 | Result OperateRange(OperationId op_id, s64 offset, s64 size) { | ||
| 82 | R_RETURN(this->DoOperateRange(nullptr, 0, op_id, offset, size, nullptr, 0)); | ||
| 83 | } | ||
| 84 | |||
| 85 | protected: | ||
| 86 | Result DryRead(size_t* out, s64 offset, size_t size, const ReadOption& option, | ||
| 87 | OpenMode open_mode) { | ||
| 88 | // Check that we can read | ||
| 89 | R_UNLESS(static_cast<u32>(open_mode & OpenMode::Read) != 0, ResultReadNotPermitted); | ||
| 90 | |||
| 91 | // Get the file size, and validate our offset | ||
| 92 | s64 file_size = 0; | ||
| 93 | R_TRY(this->DoGetSize(std::addressof(file_size))); | ||
| 94 | R_UNLESS(offset <= file_size, ResultOutOfRange); | ||
| 95 | |||
| 96 | *out = static_cast<size_t>(std::min(file_size - offset, static_cast<s64>(size))); | ||
| 97 | R_SUCCEED(); | ||
| 98 | } | ||
| 99 | |||
| 100 | Result DrySetSize(s64 size, OpenMode open_mode) { | ||
| 101 | // Check that we can write | ||
| 102 | R_UNLESS(static_cast<u32>(open_mode & OpenMode::Write) != 0, ResultWriteNotPermitted); | ||
| 103 | R_SUCCEED(); | ||
| 104 | } | ||
| 105 | |||
| 106 | Result DryWrite(bool* out_append, s64 offset, size_t size, const WriteOption& option, | ||
| 107 | OpenMode open_mode) { | ||
| 108 | // Check that we can write | ||
| 109 | R_UNLESS(static_cast<u32>(open_mode & OpenMode::Write) != 0, ResultWriteNotPermitted); | ||
| 110 | |||
| 111 | // Get the file size | ||
| 112 | s64 file_size = 0; | ||
| 113 | R_TRY(this->DoGetSize(&file_size)); | ||
| 114 | |||
| 115 | // Determine if we need to append | ||
| 116 | *out_append = false; | ||
| 117 | if (file_size < offset + static_cast<s64>(size)) { | ||
| 118 | R_UNLESS(static_cast<u32>(open_mode & OpenMode::AllowAppend) != 0, | ||
| 119 | ResultFileExtensionWithoutOpenModeAllowAppend); | ||
| 120 | *out_append = true; | ||
| 121 | } | ||
| 122 | |||
| 123 | R_SUCCEED(); | ||
| 124 | } | ||
| 125 | |||
| 126 | private: | ||
| 127 | Result DoRead(size_t* out, s64 offset, void* buffer, size_t size, const ReadOption& option) { | ||
| 128 | std::vector<u8> output = backend->ReadBytes(size, offset); | ||
| 129 | *out = output.size(); | ||
| 130 | buffer = output.data(); | ||
| 131 | R_SUCCEED(); | ||
| 132 | } | ||
| 133 | |||
| 134 | Result DoGetSize(s64* out) { | ||
| 135 | *out = backend->GetSize(); | ||
| 136 | R_SUCCEED(); | ||
| 137 | } | ||
| 138 | |||
| 139 | Result DoFlush() { | ||
| 140 | // Exists for SDK compatibiltity -- No need to flush file. | ||
| 141 | R_SUCCEED(); | ||
| 142 | } | ||
| 143 | |||
| 144 | Result DoWrite(s64 offset, const void* buffer, size_t size, const WriteOption& option) { | ||
| 145 | const std::size_t written = backend->Write(static_cast<const u8*>(buffer), size, offset); | ||
| 146 | |||
| 147 | ASSERT_MSG(written == size, | ||
| 148 | "Could not write all bytes to file (requested={:016X}, actual={:016X}).", size, | ||
| 149 | written); | ||
| 150 | |||
| 151 | R_SUCCEED(); | ||
| 152 | } | ||
| 153 | |||
| 154 | Result DoSetSize(s64 size) { | ||
| 155 | backend->Resize(size); | ||
| 156 | R_SUCCEED(); | ||
| 157 | } | ||
| 158 | |||
| 159 | Result DoOperateRange(void* dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, | ||
| 160 | const void* src, size_t src_size) { | ||
| 161 | R_THROW(ResultNotImplemented); | ||
| 162 | } | ||
| 163 | |||
| 164 | VirtualFile backend; | ||
| 165 | }; | ||
| 166 | |||
| 167 | } // namespace FileSys::Fsa | ||
diff --git a/src/core/file_sys/fsa/fs_i_filesystem.h b/src/core/file_sys/fsa/fs_i_filesystem.h new file mode 100644 index 000000000..e92284459 --- /dev/null +++ b/src/core/file_sys/fsa/fs_i_filesystem.h | |||
| @@ -0,0 +1,207 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "core/file_sys/errors.h" | ||
| 7 | #include "core/file_sys/fs_filesystem.h" | ||
| 8 | #include "core/file_sys/fs_path.h" | ||
| 9 | #include "core/file_sys/vfs/vfs_types.h" | ||
| 10 | #include "core/hle/result.h" | ||
| 11 | #include "core/hle/service/filesystem/filesystem.h" | ||
| 12 | |||
| 13 | namespace FileSys::Fsa { | ||
| 14 | |||
| 15 | class IFile; | ||
| 16 | class IDirectory; | ||
| 17 | |||
| 18 | enum class QueryId { | ||
| 19 | SetConcatenationFileAttribute = 0, | ||
| 20 | UpdateMac = 1, | ||
| 21 | IsSignedSystemPartitionOnSdCardValid = 2, | ||
| 22 | QueryUnpreparedFileInformation = 3, | ||
| 23 | }; | ||
| 24 | |||
| 25 | class IFileSystem { | ||
| 26 | public: | ||
| 27 | IFileSystem(VirtualDir backend_) : backend{std::move(backend_)} {} | ||
| 28 | virtual ~IFileSystem() {} | ||
| 29 | |||
| 30 | Result CreateFile(const Path& path, s64 size, CreateOption option) { | ||
| 31 | R_UNLESS(size >= 0, ResultOutOfRange); | ||
| 32 | R_RETURN(this->DoCreateFile(path, size, static_cast<int>(option))); | ||
| 33 | } | ||
| 34 | |||
| 35 | Result CreateFile(const Path& path, s64 size) { | ||
| 36 | R_RETURN(this->CreateFile(path, size, CreateOption::None)); | ||
| 37 | } | ||
| 38 | |||
| 39 | Result DeleteFile(const Path& path) { | ||
| 40 | R_RETURN(this->DoDeleteFile(path)); | ||
| 41 | } | ||
| 42 | |||
| 43 | Result CreateDirectory(const Path& path) { | ||
| 44 | R_RETURN(this->DoCreateDirectory(path)); | ||
| 45 | } | ||
| 46 | |||
| 47 | Result DeleteDirectory(const Path& path) { | ||
| 48 | R_RETURN(this->DoDeleteDirectory(path)); | ||
| 49 | } | ||
| 50 | |||
| 51 | Result DeleteDirectoryRecursively(const Path& path) { | ||
| 52 | R_RETURN(this->DoDeleteDirectoryRecursively(path)); | ||
| 53 | } | ||
| 54 | |||
| 55 | Result RenameFile(const Path& old_path, const Path& new_path) { | ||
| 56 | R_RETURN(this->DoRenameFile(old_path, new_path)); | ||
| 57 | } | ||
| 58 | |||
| 59 | Result RenameDirectory(const Path& old_path, const Path& new_path) { | ||
| 60 | R_RETURN(this->DoRenameDirectory(old_path, new_path)); | ||
| 61 | } | ||
| 62 | |||
| 63 | Result GetEntryType(DirectoryEntryType* out, const Path& path) { | ||
| 64 | R_RETURN(this->DoGetEntryType(out, path)); | ||
| 65 | } | ||
| 66 | |||
| 67 | Result OpenFile(VirtualFile* out_file, const Path& path, OpenMode mode) { | ||
| 68 | R_UNLESS(out_file != nullptr, ResultNullptrArgument); | ||
| 69 | R_UNLESS(static_cast<u32>(mode & OpenMode::ReadWrite) != 0, ResultInvalidOpenMode); | ||
| 70 | R_UNLESS(static_cast<u32>(mode & ~OpenMode::All) == 0, ResultInvalidOpenMode); | ||
| 71 | R_RETURN(this->DoOpenFile(out_file, path, mode)); | ||
| 72 | } | ||
| 73 | |||
| 74 | Result OpenDirectory(VirtualDir* out_dir, const Path& path, OpenDirectoryMode mode) { | ||
| 75 | R_UNLESS(out_dir != nullptr, ResultNullptrArgument); | ||
| 76 | R_UNLESS(static_cast<u64>(mode & OpenDirectoryMode::All) != 0, ResultInvalidOpenMode); | ||
| 77 | R_UNLESS(static_cast<u64>( | ||
| 78 | mode & ~(OpenDirectoryMode::All | OpenDirectoryMode::NotRequireFileSize)) == 0, | ||
| 79 | ResultInvalidOpenMode); | ||
| 80 | R_RETURN(this->DoOpenDirectory(out_dir, path, mode)); | ||
| 81 | } | ||
| 82 | |||
| 83 | Result Commit() { | ||
| 84 | R_RETURN(this->DoCommit()); | ||
| 85 | } | ||
| 86 | |||
| 87 | Result GetFreeSpaceSize(s64* out, const Path& path) { | ||
| 88 | R_UNLESS(out != nullptr, ResultNullptrArgument); | ||
| 89 | R_RETURN(this->DoGetFreeSpaceSize(out, path)); | ||
| 90 | } | ||
| 91 | |||
| 92 | Result GetTotalSpaceSize(s64* out, const Path& path) { | ||
| 93 | R_UNLESS(out != nullptr, ResultNullptrArgument); | ||
| 94 | R_RETURN(this->DoGetTotalSpaceSize(out, path)); | ||
| 95 | } | ||
| 96 | |||
| 97 | Result CleanDirectoryRecursively(const Path& path) { | ||
| 98 | R_RETURN(this->DoCleanDirectoryRecursively(path)); | ||
| 99 | } | ||
| 100 | |||
| 101 | Result GetFileTimeStampRaw(FileTimeStampRaw* out, const Path& path) { | ||
| 102 | R_UNLESS(out != nullptr, ResultNullptrArgument); | ||
| 103 | R_RETURN(this->DoGetFileTimeStampRaw(out, path)); | ||
| 104 | } | ||
| 105 | |||
| 106 | Result QueryEntry(char* dst, size_t dst_size, const char* src, size_t src_size, QueryId query, | ||
| 107 | const Path& path) { | ||
| 108 | R_RETURN(this->DoQueryEntry(dst, dst_size, src, src_size, query, path)); | ||
| 109 | } | ||
| 110 | |||
| 111 | // These aren't accessible as commands | ||
| 112 | Result CommitProvisionally(s64 counter) { | ||
| 113 | R_RETURN(this->DoCommitProvisionally(counter)); | ||
| 114 | } | ||
| 115 | |||
| 116 | Result Rollback() { | ||
| 117 | R_RETURN(this->DoRollback()); | ||
| 118 | } | ||
| 119 | |||
| 120 | Result Flush() { | ||
| 121 | R_RETURN(this->DoFlush()); | ||
| 122 | } | ||
| 123 | |||
| 124 | private: | ||
| 125 | Result DoCreateFile(const Path& path, s64 size, int flags) { | ||
| 126 | R_RETURN(backend.CreateFile(path.GetString(), size)); | ||
| 127 | } | ||
| 128 | |||
| 129 | Result DoDeleteFile(const Path& path) { | ||
| 130 | R_RETURN(backend.DeleteFile(path.GetString())); | ||
| 131 | } | ||
| 132 | |||
| 133 | Result DoCreateDirectory(const Path& path) { | ||
| 134 | R_RETURN(backend.CreateDirectory(path.GetString())); | ||
| 135 | } | ||
| 136 | |||
| 137 | Result DoDeleteDirectory(const Path& path) { | ||
| 138 | R_RETURN(backend.DeleteDirectory(path.GetString())); | ||
| 139 | } | ||
| 140 | |||
| 141 | Result DoDeleteDirectoryRecursively(const Path& path) { | ||
| 142 | R_RETURN(backend.DeleteDirectoryRecursively(path.GetString())); | ||
| 143 | } | ||
| 144 | |||
| 145 | Result DoRenameFile(const Path& old_path, const Path& new_path) { | ||
| 146 | R_RETURN(backend.RenameFile(old_path.GetString(), new_path.GetString())); | ||
| 147 | } | ||
| 148 | |||
| 149 | Result DoRenameDirectory(const Path& old_path, const Path& new_path) { | ||
| 150 | R_RETURN(backend.RenameDirectory(old_path.GetString(), new_path.GetString())); | ||
| 151 | } | ||
| 152 | |||
| 153 | Result DoGetEntryType(DirectoryEntryType* out, const Path& path) { | ||
| 154 | R_RETURN(backend.GetEntryType(out, path.GetString())); | ||
| 155 | } | ||
| 156 | |||
| 157 | Result DoOpenFile(VirtualFile* out_file, const Path& path, OpenMode mode) { | ||
| 158 | R_RETURN(backend.OpenFile(out_file, path.GetString(), mode)); | ||
| 159 | } | ||
| 160 | |||
| 161 | Result DoOpenDirectory(VirtualDir* out_directory, const Path& path, | ||
| 162 | OpenDirectoryMode mode) { | ||
| 163 | R_RETURN(backend.OpenDirectory(out_directory, path.GetString())); | ||
| 164 | } | ||
| 165 | |||
| 166 | Result DoCommit() { | ||
| 167 | R_THROW(ResultNotImplemented); | ||
| 168 | } | ||
| 169 | |||
| 170 | Result DoGetFreeSpaceSize(s64* out, const Path& path) { | ||
| 171 | R_THROW(ResultNotImplemented); | ||
| 172 | } | ||
| 173 | |||
| 174 | Result DoGetTotalSpaceSize(s64* out, const Path& path) { | ||
| 175 | R_THROW(ResultNotImplemented); | ||
| 176 | } | ||
| 177 | |||
| 178 | Result DoCleanDirectoryRecursively(const Path& path) { | ||
| 179 | R_RETURN(backend.CleanDirectoryRecursively(path.GetString())); | ||
| 180 | } | ||
| 181 | |||
| 182 | Result DoGetFileTimeStampRaw(FileTimeStampRaw* out, const Path& path) { | ||
| 183 | R_RETURN(backend.GetFileTimeStampRaw(out, path.GetString())); | ||
| 184 | } | ||
| 185 | |||
| 186 | Result DoQueryEntry(char* dst, size_t dst_size, const char* src, size_t src_size, QueryId query, | ||
| 187 | const Path& path) { | ||
| 188 | R_THROW(ResultNotImplemented); | ||
| 189 | } | ||
| 190 | |||
| 191 | // These aren't accessible as commands | ||
| 192 | Result DoCommitProvisionally(s64 counter) { | ||
| 193 | R_THROW(ResultNotImplemented); | ||
| 194 | } | ||
| 195 | |||
| 196 | Result DoRollback() { | ||
| 197 | R_THROW(ResultNotImplemented); | ||
| 198 | } | ||
| 199 | |||
| 200 | Result DoFlush() { | ||
| 201 | R_THROW(ResultNotImplemented); | ||
| 202 | } | ||
| 203 | |||
| 204 | Service::FileSystem::VfsDirectoryServiceWrapper backend; | ||
| 205 | }; | ||
| 206 | |||
| 207 | } // namespace FileSys::Fsa | ||
diff --git a/src/core/hle/service/filesystem/fsp/fs_i_directory.cpp b/src/core/hle/service/filesystem/fsp/fs_i_directory.cpp index 39690018b..661da5326 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_directory.cpp +++ b/src/core/hle/service/filesystem/fsp/fs_i_directory.cpp | |||
| @@ -8,43 +8,15 @@ | |||
| 8 | 8 | ||
| 9 | namespace Service::FileSystem { | 9 | namespace Service::FileSystem { |
| 10 | 10 | ||
| 11 | template <typename T> | 11 | IDirectory::IDirectory(Core::System& system_, FileSys::VirtualDir directory_, |
| 12 | static void BuildEntryIndex(std::vector<FileSys::DirectoryEntry>& entries, | ||
| 13 | const std::vector<T>& new_data, FileSys::DirectoryEntryType type) { | ||
| 14 | entries.reserve(entries.size() + new_data.size()); | ||
| 15 | |||
| 16 | for (const auto& new_entry : new_data) { | ||
| 17 | auto name = new_entry->GetName(); | ||
| 18 | |||
| 19 | if (type == FileSys::DirectoryEntryType::File && | ||
| 20 | name == FileSys::GetSaveDataSizeFileName()) { | ||
| 21 | continue; | ||
| 22 | } | ||
| 23 | |||
| 24 | entries.emplace_back(name, static_cast<s8>(type), | ||
| 25 | type == FileSys::DirectoryEntryType::Directory ? 0 | ||
| 26 | : new_entry->GetSize()); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | IDirectory::IDirectory(Core::System& system_, FileSys::VirtualDir backend_, | ||
| 31 | FileSys::OpenDirectoryMode mode) | 12 | FileSys::OpenDirectoryMode mode) |
| 32 | : ServiceFramework{system_, "IDirectory"}, backend(std::move(backend_)) { | 13 | : ServiceFramework{system_, "IDirectory"}, |
| 14 | backend(std::make_unique<FileSys::Fsa::IDirectory>(directory_, mode)) { | ||
| 33 | static const FunctionInfo functions[] = { | 15 | static const FunctionInfo functions[] = { |
| 34 | {0, &IDirectory::Read, "Read"}, | 16 | {0, &IDirectory::Read, "Read"}, |
| 35 | {1, &IDirectory::GetEntryCount, "GetEntryCount"}, | 17 | {1, &IDirectory::GetEntryCount, "GetEntryCount"}, |
| 36 | }; | 18 | }; |
| 37 | RegisterHandlers(functions); | 19 | RegisterHandlers(functions); |
| 38 | |||
| 39 | // TODO(DarkLordZach): Verify that this is the correct behavior. | ||
| 40 | // Build entry index now to save time later. | ||
| 41 | if (True(mode & FileSys::OpenDirectoryMode::Directory)) { | ||
| 42 | BuildEntryIndex(entries, backend->GetSubdirectories(), | ||
| 43 | FileSys::DirectoryEntryType::Directory); | ||
| 44 | } | ||
| 45 | if (True(mode & FileSys::OpenDirectoryMode::File)) { | ||
| 46 | BuildEntryIndex(entries, backend->GetFiles(), FileSys::DirectoryEntryType::File); | ||
| 47 | } | ||
| 48 | } | 20 | } |
| 49 | 21 | ||
| 50 | void IDirectory::Read(HLERequestContext& ctx) { | 22 | void IDirectory::Read(HLERequestContext& ctx) { |
| @@ -53,32 +25,26 @@ void IDirectory::Read(HLERequestContext& ctx) { | |||
| 53 | // Calculate how many entries we can fit in the output buffer | 25 | // Calculate how many entries we can fit in the output buffer |
| 54 | const u64 count_entries = ctx.GetWriteBufferNumElements<FileSys::DirectoryEntry>(); | 26 | const u64 count_entries = ctx.GetWriteBufferNumElements<FileSys::DirectoryEntry>(); |
| 55 | 27 | ||
| 56 | // Cap at total number of entries. | 28 | s64 out_count{}; |
| 57 | const u64 actual_entries = std::min(count_entries, entries.size() - next_entry_index); | 29 | FileSys::DirectoryEntry* out_entries = nullptr; |
| 58 | 30 | const auto result = backend->Read(&out_count, out_entries, count_entries); | |
| 59 | // Determine data start and end | ||
| 60 | const auto* begin = reinterpret_cast<u8*>(entries.data() + next_entry_index); | ||
| 61 | const auto* end = reinterpret_cast<u8*>(entries.data() + next_entry_index + actual_entries); | ||
| 62 | const auto range_size = static_cast<std::size_t>(std::distance(begin, end)); | ||
| 63 | |||
| 64 | next_entry_index += actual_entries; | ||
| 65 | 31 | ||
| 66 | // Write the data to memory | 32 | // Write the data to memory |
| 67 | ctx.WriteBuffer(begin, range_size); | 33 | ctx.WriteBuffer(out_entries, out_count); |
| 68 | 34 | ||
| 69 | IPC::ResponseBuilder rb{ctx, 4}; | 35 | IPC::ResponseBuilder rb{ctx, 4}; |
| 70 | rb.Push(ResultSuccess); | 36 | rb.Push(result); |
| 71 | rb.Push(actual_entries); | 37 | rb.Push(out_count); |
| 72 | } | 38 | } |
| 73 | 39 | ||
| 74 | void IDirectory::GetEntryCount(HLERequestContext& ctx) { | 40 | void IDirectory::GetEntryCount(HLERequestContext& ctx) { |
| 75 | LOG_DEBUG(Service_FS, "called"); | 41 | LOG_DEBUG(Service_FS, "called"); |
| 76 | 42 | ||
| 77 | u64 count = entries.size() - next_entry_index; | 43 | s64 out_count{}; |
| 78 | 44 | ||
| 79 | IPC::ResponseBuilder rb{ctx, 4}; | 45 | IPC::ResponseBuilder rb{ctx, 4}; |
| 80 | rb.Push(ResultSuccess); | 46 | rb.Push(backend->GetEntryCount(&out_count)); |
| 81 | rb.Push(count); | 47 | rb.Push(out_count); |
| 82 | } | 48 | } |
| 83 | 49 | ||
| 84 | } // namespace Service::FileSystem | 50 | } // namespace Service::FileSystem |
diff --git a/src/core/hle/service/filesystem/fsp/fs_i_directory.h b/src/core/hle/service/filesystem/fsp/fs_i_directory.h index 793ecfcd7..0dec4367b 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_directory.h +++ b/src/core/hle/service/filesystem/fsp/fs_i_directory.h | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include "core/file_sys/fsa/fs_i_directory.h" | ||
| 6 | #include "core/file_sys/vfs/vfs.h" | 7 | #include "core/file_sys/vfs/vfs.h" |
| 7 | #include "core/hle/service/filesystem/filesystem.h" | 8 | #include "core/hle/service/filesystem/filesystem.h" |
| 8 | #include "core/hle/service/service.h" | 9 | #include "core/hle/service/service.h" |
| @@ -15,13 +16,11 @@ namespace Service::FileSystem { | |||
| 15 | 16 | ||
| 16 | class IDirectory final : public ServiceFramework<IDirectory> { | 17 | class IDirectory final : public ServiceFramework<IDirectory> { |
| 17 | public: | 18 | public: |
| 18 | explicit IDirectory(Core::System& system_, FileSys::VirtualDir backend_, | 19 | explicit IDirectory(Core::System& system_, FileSys::VirtualDir directory_, |
| 19 | FileSys::OpenDirectoryMode mode); | 20 | FileSys::OpenDirectoryMode mode); |
| 20 | 21 | ||
| 21 | private: | 22 | private: |
| 22 | FileSys::VirtualDir backend; | 23 | std::unique_ptr<FileSys::Fsa::IDirectory> backend; |
| 23 | std::vector<FileSys::DirectoryEntry> entries; | ||
| 24 | u64 next_entry_index = 0; | ||
| 25 | 24 | ||
| 26 | void Read(HLERequestContext& ctx); | 25 | void Read(HLERequestContext& ctx); |
| 27 | void GetEntryCount(HLERequestContext& ctx); | 26 | void GetEntryCount(HLERequestContext& ctx); |
diff --git a/src/core/hle/service/filesystem/fsp/fs_i_file.cpp b/src/core/hle/service/filesystem/fsp/fs_i_file.cpp index 9a18f6ec5..8fb8620de 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_file.cpp +++ b/src/core/hle/service/filesystem/fsp/fs_i_file.cpp | |||
| @@ -7,8 +7,8 @@ | |||
| 7 | 7 | ||
| 8 | namespace Service::FileSystem { | 8 | namespace Service::FileSystem { |
| 9 | 9 | ||
| 10 | IFile::IFile(Core::System& system_, FileSys::VirtualFile backend_) | 10 | IFile::IFile(Core::System& system_, FileSys::VirtualFile file_) |
| 11 | : ServiceFramework{system_, "IFile"}, backend(std::move(backend_)) { | 11 | : ServiceFramework{system_, "IFile"}, backend{std::make_unique<FileSys::Fsa::IFile>(file_)} { |
| 12 | static const FunctionInfo functions[] = { | 12 | static const FunctionInfo functions[] = { |
| 13 | {0, &IFile::Read, "Read"}, | 13 | {0, &IFile::Read, "Read"}, |
| 14 | {1, &IFile::Write, "Write"}, | 14 | {1, &IFile::Write, "Write"}, |
| @@ -29,79 +29,40 @@ void IFile::Read(HLERequestContext& ctx) { | |||
| 29 | 29 | ||
| 30 | LOG_DEBUG(Service_FS, "called, option={}, offset=0x{:X}, length={}", option, offset, length); | 30 | LOG_DEBUG(Service_FS, "called, option={}, offset=0x{:X}, length={}", option, offset, length); |
| 31 | 31 | ||
| 32 | // Error checking | ||
| 33 | if (length < 0) { | ||
| 34 | LOG_ERROR(Service_FS, "Length is less than 0, length={}", length); | ||
| 35 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 36 | rb.Push(FileSys::ResultInvalidSize); | ||
| 37 | return; | ||
| 38 | } | ||
| 39 | if (offset < 0) { | ||
| 40 | LOG_ERROR(Service_FS, "Offset is less than 0, offset={}", offset); | ||
| 41 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 42 | rb.Push(FileSys::ResultInvalidOffset); | ||
| 43 | return; | ||
| 44 | } | ||
| 45 | |||
| 46 | // Read the data from the Storage backend | 32 | // Read the data from the Storage backend |
| 47 | std::vector<u8> output = backend->ReadBytes(length, offset); | 33 | std::vector<u8> output(length); |
| 34 | std::size_t bytes_read; | ||
| 35 | const auto result = backend->Read(&bytes_read, offset, output.data(), length); | ||
| 48 | 36 | ||
| 49 | // Write the data to memory | 37 | // Write the data to memory |
| 50 | ctx.WriteBuffer(output); | 38 | ctx.WriteBuffer(output); |
| 51 | 39 | ||
| 52 | IPC::ResponseBuilder rb{ctx, 4}; | 40 | IPC::ResponseBuilder rb{ctx, 4}; |
| 53 | rb.Push(ResultSuccess); | 41 | rb.Push(result); |
| 54 | rb.Push(static_cast<u64>(output.size())); | 42 | rb.Push(static_cast<u64>(bytes_read)); |
| 55 | } | 43 | } |
| 56 | 44 | ||
| 57 | void IFile::Write(HLERequestContext& ctx) { | 45 | void IFile::Write(HLERequestContext& ctx) { |
| 58 | IPC::RequestParser rp{ctx}; | 46 | IPC::RequestParser rp{ctx}; |
| 59 | const u64 option = rp.Pop<u64>(); | 47 | const auto option = rp.PopRaw<FileSys::WriteOption>(); |
| 48 | [[maybe_unused]] const u32 unused = rp.Pop<u32>(); | ||
| 60 | const s64 offset = rp.Pop<s64>(); | 49 | const s64 offset = rp.Pop<s64>(); |
| 61 | const s64 length = rp.Pop<s64>(); | 50 | const s64 length = rp.Pop<s64>(); |
| 62 | 51 | ||
| 63 | LOG_DEBUG(Service_FS, "called, option={}, offset=0x{:X}, length={}", option, offset, length); | 52 | LOG_DEBUG(Service_FS, "called, option={}, offset=0x{:X}, length={}", option.value, offset, |
| 64 | 53 | length); | |
| 65 | // Error checking | ||
| 66 | if (length < 0) { | ||
| 67 | LOG_ERROR(Service_FS, "Length is less than 0, length={}", length); | ||
| 68 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 69 | rb.Push(FileSys::ResultInvalidSize); | ||
| 70 | return; | ||
| 71 | } | ||
| 72 | if (offset < 0) { | ||
| 73 | LOG_ERROR(Service_FS, "Offset is less than 0, offset={}", offset); | ||
| 74 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 75 | rb.Push(FileSys::ResultInvalidOffset); | ||
| 76 | return; | ||
| 77 | } | ||
| 78 | 54 | ||
| 79 | const auto data = ctx.ReadBuffer(); | 55 | const auto data = ctx.ReadBuffer(); |
| 80 | 56 | ||
| 81 | ASSERT_MSG(static_cast<s64>(data.size()) <= length, | ||
| 82 | "Attempting to write more data than requested (requested={:016X}, actual={:016X}).", | ||
| 83 | length, data.size()); | ||
| 84 | |||
| 85 | // Write the data to the Storage backend | ||
| 86 | const auto write_size = | ||
| 87 | static_cast<std::size_t>(std::distance(data.begin(), data.begin() + length)); | ||
| 88 | const std::size_t written = backend->Write(data.data(), write_size, offset); | ||
| 89 | |||
| 90 | ASSERT_MSG(static_cast<s64>(written) == length, | ||
| 91 | "Could not write all bytes to file (requested={:016X}, actual={:016X}).", length, | ||
| 92 | written); | ||
| 93 | |||
| 94 | IPC::ResponseBuilder rb{ctx, 2}; | 57 | IPC::ResponseBuilder rb{ctx, 2}; |
| 95 | rb.Push(ResultSuccess); | 58 | rb.Push(backend->Write(offset, data.data(), length, option)); |
| 96 | } | 59 | } |
| 97 | 60 | ||
| 98 | void IFile::Flush(HLERequestContext& ctx) { | 61 | void IFile::Flush(HLERequestContext& ctx) { |
| 99 | LOG_DEBUG(Service_FS, "called"); | 62 | LOG_DEBUG(Service_FS, "called"); |
| 100 | 63 | ||
| 101 | // Exists for SDK compatibiltity -- No need to flush file. | ||
| 102 | |||
| 103 | IPC::ResponseBuilder rb{ctx, 2}; | 64 | IPC::ResponseBuilder rb{ctx, 2}; |
| 104 | rb.Push(ResultSuccess); | 65 | rb.Push(backend->Flush()); |
| 105 | } | 66 | } |
| 106 | 67 | ||
| 107 | void IFile::SetSize(HLERequestContext& ctx) { | 68 | void IFile::SetSize(HLERequestContext& ctx) { |
| @@ -109,18 +70,17 @@ void IFile::SetSize(HLERequestContext& ctx) { | |||
| 109 | const u64 size = rp.Pop<u64>(); | 70 | const u64 size = rp.Pop<u64>(); |
| 110 | LOG_DEBUG(Service_FS, "called, size={}", size); | 71 | LOG_DEBUG(Service_FS, "called, size={}", size); |
| 111 | 72 | ||
| 112 | backend->Resize(size); | ||
| 113 | |||
| 114 | IPC::ResponseBuilder rb{ctx, 2}; | 73 | IPC::ResponseBuilder rb{ctx, 2}; |
| 115 | rb.Push(ResultSuccess); | 74 | rb.Push(backend->SetSize(size)); |
| 116 | } | 75 | } |
| 117 | 76 | ||
| 118 | void IFile::GetSize(HLERequestContext& ctx) { | 77 | void IFile::GetSize(HLERequestContext& ctx) { |
| 119 | const u64 size = backend->GetSize(); | 78 | s64 size; |
| 79 | const auto result = backend->GetSize(&size); | ||
| 120 | LOG_DEBUG(Service_FS, "called, size={}", size); | 80 | LOG_DEBUG(Service_FS, "called, size={}", size); |
| 121 | 81 | ||
| 122 | IPC::ResponseBuilder rb{ctx, 4}; | 82 | IPC::ResponseBuilder rb{ctx, 4}; |
| 123 | rb.Push(ResultSuccess); | 83 | rb.Push(result); |
| 124 | rb.Push<u64>(size); | 84 | rb.Push<u64>(size); |
| 125 | } | 85 | } |
| 126 | 86 | ||
diff --git a/src/core/hle/service/filesystem/fsp/fs_i_file.h b/src/core/hle/service/filesystem/fsp/fs_i_file.h index 5e5430c67..887fd3ba2 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_file.h +++ b/src/core/hle/service/filesystem/fsp/fs_i_file.h | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include "core/file_sys/fsa/fs_i_file.h" | ||
| 6 | #include "core/hle/service/filesystem/filesystem.h" | 7 | #include "core/hle/service/filesystem/filesystem.h" |
| 7 | #include "core/hle/service/service.h" | 8 | #include "core/hle/service/service.h" |
| 8 | 9 | ||
| @@ -10,10 +11,10 @@ namespace Service::FileSystem { | |||
| 10 | 11 | ||
| 11 | class IFile final : public ServiceFramework<IFile> { | 12 | class IFile final : public ServiceFramework<IFile> { |
| 12 | public: | 13 | public: |
| 13 | explicit IFile(Core::System& system_, FileSys::VirtualFile backend_); | 14 | explicit IFile(Core::System& system_, FileSys::VirtualFile file_); |
| 14 | 15 | ||
| 15 | private: | 16 | private: |
| 16 | FileSys::VirtualFile backend; | 17 | std::unique_ptr<FileSys::Fsa::IFile> backend; |
| 17 | 18 | ||
| 18 | void Read(HLERequestContext& ctx); | 19 | void Read(HLERequestContext& ctx); |
| 19 | void Write(HLERequestContext& ctx); | 20 | void Write(HLERequestContext& ctx); |
diff --git a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp index efa394dd1..1e69d22b8 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp +++ b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp | |||
| @@ -9,9 +9,9 @@ | |||
| 9 | 9 | ||
| 10 | namespace Service::FileSystem { | 10 | namespace Service::FileSystem { |
| 11 | 11 | ||
| 12 | IFileSystem::IFileSystem(Core::System& system_, FileSys::VirtualDir backend_, SizeGetter size_) | 12 | IFileSystem::IFileSystem(Core::System& system_, FileSys::VirtualDir dir_, SizeGetter size_) |
| 13 | : ServiceFramework{system_, "IFileSystem"}, backend{std::move(backend_)}, size{std::move( | 13 | : ServiceFramework{system_, "IFileSystem"}, |
| 14 | size_)} { | 14 | backend{std::make_unique<FileSys::Fsa::IFileSystem>(dir_)}, size{std::move(size_)} { |
| 15 | static const FunctionInfo functions[] = { | 15 | static const FunctionInfo functions[] = { |
| 16 | {0, &IFileSystem::CreateFile, "CreateFile"}, | 16 | {0, &IFileSystem::CreateFile, "CreateFile"}, |
| 17 | {1, &IFileSystem::DeleteFile, "DeleteFile"}, | 17 | {1, &IFileSystem::DeleteFile, "DeleteFile"}, |
| @@ -39,6 +39,7 @@ void IFileSystem::CreateFile(HLERequestContext& ctx) { | |||
| 39 | 39 | ||
| 40 | const auto file_buffer = ctx.ReadBuffer(); | 40 | const auto file_buffer = ctx.ReadBuffer(); |
| 41 | const std::string name = Common::StringFromBuffer(file_buffer); | 41 | const std::string name = Common::StringFromBuffer(file_buffer); |
| 42 | const auto path = FileSys::Path(name.c_str()); | ||
| 42 | 43 | ||
| 43 | const u64 file_mode = rp.Pop<u64>(); | 44 | const u64 file_mode = rp.Pop<u64>(); |
| 44 | const u32 file_size = rp.Pop<u32>(); | 45 | const u32 file_size = rp.Pop<u32>(); |
| @@ -47,67 +48,75 @@ void IFileSystem::CreateFile(HLERequestContext& ctx) { | |||
| 47 | file_size); | 48 | file_size); |
| 48 | 49 | ||
| 49 | IPC::ResponseBuilder rb{ctx, 2}; | 50 | IPC::ResponseBuilder rb{ctx, 2}; |
| 50 | rb.Push(backend.CreateFile(name, file_size)); | 51 | rb.Push(backend->CreateFile(path, file_size)); |
| 51 | } | 52 | } |
| 52 | 53 | ||
| 53 | void IFileSystem::DeleteFile(HLERequestContext& ctx) { | 54 | void IFileSystem::DeleteFile(HLERequestContext& ctx) { |
| 54 | const auto file_buffer = ctx.ReadBuffer(); | 55 | const auto file_buffer = ctx.ReadBuffer(); |
| 55 | const std::string name = Common::StringFromBuffer(file_buffer); | 56 | const std::string name = Common::StringFromBuffer(file_buffer); |
| 57 | const auto path = FileSys::Path(name.c_str()); | ||
| 56 | 58 | ||
| 57 | LOG_DEBUG(Service_FS, "called. file={}", name); | 59 | LOG_DEBUG(Service_FS, "called. file={}", name); |
| 58 | 60 | ||
| 59 | IPC::ResponseBuilder rb{ctx, 2}; | 61 | IPC::ResponseBuilder rb{ctx, 2}; |
| 60 | rb.Push(backend.DeleteFile(name)); | 62 | rb.Push(backend->DeleteFile(path)); |
| 61 | } | 63 | } |
| 62 | 64 | ||
| 63 | void IFileSystem::CreateDirectory(HLERequestContext& ctx) { | 65 | void IFileSystem::CreateDirectory(HLERequestContext& ctx) { |
| 64 | const auto file_buffer = ctx.ReadBuffer(); | 66 | const auto file_buffer = ctx.ReadBuffer(); |
| 65 | const std::string name = Common::StringFromBuffer(file_buffer); | 67 | const std::string name = Common::StringFromBuffer(file_buffer); |
| 68 | const auto path = FileSys::Path(name.c_str()); | ||
| 66 | 69 | ||
| 67 | LOG_DEBUG(Service_FS, "called. directory={}", name); | 70 | LOG_DEBUG(Service_FS, "called. directory={}", name); |
| 68 | 71 | ||
| 69 | IPC::ResponseBuilder rb{ctx, 2}; | 72 | IPC::ResponseBuilder rb{ctx, 2}; |
| 70 | rb.Push(backend.CreateDirectory(name)); | 73 | rb.Push(backend->CreateDirectory(path)); |
| 71 | } | 74 | } |
| 72 | 75 | ||
| 73 | void IFileSystem::DeleteDirectory(HLERequestContext& ctx) { | 76 | void IFileSystem::DeleteDirectory(HLERequestContext& ctx) { |
| 74 | const auto file_buffer = ctx.ReadBuffer(); | 77 | const auto file_buffer = ctx.ReadBuffer(); |
| 75 | const std::string name = Common::StringFromBuffer(file_buffer); | 78 | const std::string name = Common::StringFromBuffer(file_buffer); |
| 79 | const auto path = FileSys::Path(name.c_str()); | ||
| 76 | 80 | ||
| 77 | LOG_DEBUG(Service_FS, "called. directory={}", name); | 81 | LOG_DEBUG(Service_FS, "called. directory={}", name); |
| 78 | 82 | ||
| 79 | IPC::ResponseBuilder rb{ctx, 2}; | 83 | IPC::ResponseBuilder rb{ctx, 2}; |
| 80 | rb.Push(backend.DeleteDirectory(name)); | 84 | rb.Push(backend->DeleteDirectory(path)); |
| 81 | } | 85 | } |
| 82 | 86 | ||
| 83 | void IFileSystem::DeleteDirectoryRecursively(HLERequestContext& ctx) { | 87 | void IFileSystem::DeleteDirectoryRecursively(HLERequestContext& ctx) { |
| 84 | const auto file_buffer = ctx.ReadBuffer(); | 88 | const auto file_buffer = ctx.ReadBuffer(); |
| 85 | const std::string name = Common::StringFromBuffer(file_buffer); | 89 | const std::string name = Common::StringFromBuffer(file_buffer); |
| 90 | const auto path = FileSys::Path(name.c_str()); | ||
| 86 | 91 | ||
| 87 | LOG_DEBUG(Service_FS, "called. directory={}", name); | 92 | LOG_DEBUG(Service_FS, "called. directory={}", name); |
| 88 | 93 | ||
| 89 | IPC::ResponseBuilder rb{ctx, 2}; | 94 | IPC::ResponseBuilder rb{ctx, 2}; |
| 90 | rb.Push(backend.DeleteDirectoryRecursively(name)); | 95 | rb.Push(backend->DeleteDirectoryRecursively(path)); |
| 91 | } | 96 | } |
| 92 | 97 | ||
| 93 | void IFileSystem::CleanDirectoryRecursively(HLERequestContext& ctx) { | 98 | void IFileSystem::CleanDirectoryRecursively(HLERequestContext& ctx) { |
| 94 | const auto file_buffer = ctx.ReadBuffer(); | 99 | const auto file_buffer = ctx.ReadBuffer(); |
| 95 | const std::string name = Common::StringFromBuffer(file_buffer); | 100 | const std::string name = Common::StringFromBuffer(file_buffer); |
| 101 | const auto path = FileSys::Path(name.c_str()); | ||
| 96 | 102 | ||
| 97 | LOG_DEBUG(Service_FS, "called. Directory: {}", name); | 103 | LOG_DEBUG(Service_FS, "called. Directory: {}", name); |
| 98 | 104 | ||
| 99 | IPC::ResponseBuilder rb{ctx, 2}; | 105 | IPC::ResponseBuilder rb{ctx, 2}; |
| 100 | rb.Push(backend.CleanDirectoryRecursively(name)); | 106 | rb.Push(backend->CleanDirectoryRecursively(path)); |
| 101 | } | 107 | } |
| 102 | 108 | ||
| 103 | void IFileSystem::RenameFile(HLERequestContext& ctx) { | 109 | void IFileSystem::RenameFile(HLERequestContext& ctx) { |
| 104 | const std::string src_name = Common::StringFromBuffer(ctx.ReadBuffer(0)); | 110 | const std::string src_name = Common::StringFromBuffer(ctx.ReadBuffer(0)); |
| 105 | const std::string dst_name = Common::StringFromBuffer(ctx.ReadBuffer(1)); | 111 | const std::string dst_name = Common::StringFromBuffer(ctx.ReadBuffer(1)); |
| 106 | 112 | ||
| 113 | const auto src_path = FileSys::Path(src_name.c_str()); | ||
| 114 | const auto dst_path = FileSys::Path(dst_name.c_str()); | ||
| 115 | |||
| 107 | LOG_DEBUG(Service_FS, "called. file '{}' to file '{}'", src_name, dst_name); | 116 | LOG_DEBUG(Service_FS, "called. file '{}' to file '{}'", src_name, dst_name); |
| 108 | 117 | ||
| 109 | IPC::ResponseBuilder rb{ctx, 2}; | 118 | IPC::ResponseBuilder rb{ctx, 2}; |
| 110 | rb.Push(backend.RenameFile(src_name, dst_name)); | 119 | rb.Push(backend->RenameFile(src_path, dst_path)); |
| 111 | } | 120 | } |
| 112 | 121 | ||
| 113 | void IFileSystem::OpenFile(HLERequestContext& ctx) { | 122 | void IFileSystem::OpenFile(HLERequestContext& ctx) { |
| @@ -115,13 +124,14 @@ void IFileSystem::OpenFile(HLERequestContext& ctx) { | |||
| 115 | 124 | ||
| 116 | const auto file_buffer = ctx.ReadBuffer(); | 125 | const auto file_buffer = ctx.ReadBuffer(); |
| 117 | const std::string name = Common::StringFromBuffer(file_buffer); | 126 | const std::string name = Common::StringFromBuffer(file_buffer); |
| 127 | const auto path = FileSys::Path(name.c_str()); | ||
| 118 | 128 | ||
| 119 | const auto mode = static_cast<FileSys::OpenMode>(rp.Pop<u32>()); | 129 | const auto mode = static_cast<FileSys::OpenMode>(rp.Pop<u32>()); |
| 120 | 130 | ||
| 121 | LOG_DEBUG(Service_FS, "called. file={}, mode={}", name, mode); | 131 | LOG_DEBUG(Service_FS, "called. file={}, mode={}", name, mode); |
| 122 | 132 | ||
| 123 | FileSys::VirtualFile vfs_file{}; | 133 | FileSys::VirtualFile vfs_file{}; |
| 124 | auto result = backend.OpenFile(&vfs_file, name, mode); | 134 | auto result = backend->OpenFile(&vfs_file, path, mode); |
| 125 | if (result != ResultSuccess) { | 135 | if (result != ResultSuccess) { |
| 126 | IPC::ResponseBuilder rb{ctx, 2}; | 136 | IPC::ResponseBuilder rb{ctx, 2}; |
| 127 | rb.Push(result); | 137 | rb.Push(result); |
| @@ -140,12 +150,13 @@ void IFileSystem::OpenDirectory(HLERequestContext& ctx) { | |||
| 140 | 150 | ||
| 141 | const auto file_buffer = ctx.ReadBuffer(); | 151 | const auto file_buffer = ctx.ReadBuffer(); |
| 142 | const std::string name = Common::StringFromBuffer(file_buffer); | 152 | const std::string name = Common::StringFromBuffer(file_buffer); |
| 153 | const auto path = FileSys::Path(name.c_str()); | ||
| 143 | const auto mode = rp.PopRaw<FileSys::OpenDirectoryMode>(); | 154 | const auto mode = rp.PopRaw<FileSys::OpenDirectoryMode>(); |
| 144 | 155 | ||
| 145 | LOG_DEBUG(Service_FS, "called. directory={}, mode={}", name, mode); | 156 | LOG_DEBUG(Service_FS, "called. directory={}, mode={}", name, mode); |
| 146 | 157 | ||
| 147 | FileSys::VirtualDir vfs_dir{}; | 158 | FileSys::VirtualDir vfs_dir{}; |
| 148 | auto result = backend.OpenDirectory(&vfs_dir, name); | 159 | auto result = backend->OpenDirectory(&vfs_dir, path, mode); |
| 149 | if (result != ResultSuccess) { | 160 | if (result != ResultSuccess) { |
| 150 | IPC::ResponseBuilder rb{ctx, 2}; | 161 | IPC::ResponseBuilder rb{ctx, 2}; |
| 151 | rb.Push(result); | 162 | rb.Push(result); |
| @@ -162,11 +173,12 @@ void IFileSystem::OpenDirectory(HLERequestContext& ctx) { | |||
| 162 | void IFileSystem::GetEntryType(HLERequestContext& ctx) { | 173 | void IFileSystem::GetEntryType(HLERequestContext& ctx) { |
| 163 | const auto file_buffer = ctx.ReadBuffer(); | 174 | const auto file_buffer = ctx.ReadBuffer(); |
| 164 | const std::string name = Common::StringFromBuffer(file_buffer); | 175 | const std::string name = Common::StringFromBuffer(file_buffer); |
| 176 | const auto path = FileSys::Path(name.c_str()); | ||
| 165 | 177 | ||
| 166 | LOG_DEBUG(Service_FS, "called. file={}", name); | 178 | LOG_DEBUG(Service_FS, "called. file={}", name); |
| 167 | 179 | ||
| 168 | FileSys::DirectoryEntryType vfs_entry_type{}; | 180 | FileSys::DirectoryEntryType vfs_entry_type{}; |
| 169 | auto result = backend.GetEntryType(&vfs_entry_type, name); | 181 | auto result = backend->GetEntryType(&vfs_entry_type, path); |
| 170 | if (result != ResultSuccess) { | 182 | if (result != ResultSuccess) { |
| 171 | IPC::ResponseBuilder rb{ctx, 2}; | 183 | IPC::ResponseBuilder rb{ctx, 2}; |
| 172 | rb.Push(result); | 184 | rb.Push(result); |
| @@ -204,11 +216,12 @@ void IFileSystem::GetTotalSpaceSize(HLERequestContext& ctx) { | |||
| 204 | void IFileSystem::GetFileTimeStampRaw(HLERequestContext& ctx) { | 216 | void IFileSystem::GetFileTimeStampRaw(HLERequestContext& ctx) { |
| 205 | const auto file_buffer = ctx.ReadBuffer(); | 217 | const auto file_buffer = ctx.ReadBuffer(); |
| 206 | const std::string name = Common::StringFromBuffer(file_buffer); | 218 | const std::string name = Common::StringFromBuffer(file_buffer); |
| 219 | const auto path = FileSys::Path(name.c_str()); | ||
| 207 | 220 | ||
| 208 | LOG_WARNING(Service_FS, "(Partial Implementation) called. file={}", name); | 221 | LOG_WARNING(Service_FS, "(Partial Implementation) called. file={}", name); |
| 209 | 222 | ||
| 210 | FileSys::FileTimeStampRaw vfs_timestamp{}; | 223 | FileSys::FileTimeStampRaw vfs_timestamp{}; |
| 211 | auto result = backend.GetFileTimeStampRaw(&vfs_timestamp, name); | 224 | auto result = backend->GetFileTimeStampRaw(&vfs_timestamp, path); |
| 212 | if (result != ResultSuccess) { | 225 | if (result != ResultSuccess) { |
| 213 | IPC::ResponseBuilder rb{ctx, 2}; | 226 | IPC::ResponseBuilder rb{ctx, 2}; |
| 214 | rb.Push(result); | 227 | rb.Push(result); |
diff --git a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h index b06b3ef0e..d500be725 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h +++ b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include "core/file_sys/fsa/fs_i_filesystem.h" | ||
| 6 | #include "core/file_sys/vfs/vfs.h" | 7 | #include "core/file_sys/vfs/vfs.h" |
| 7 | #include "core/hle/service/filesystem/filesystem.h" | 8 | #include "core/hle/service/filesystem/filesystem.h" |
| 8 | #include "core/hle/service/filesystem/fsp/fsp_util.h" | 9 | #include "core/hle/service/filesystem/fsp/fsp_util.h" |
| @@ -12,7 +13,7 @@ namespace Service::FileSystem { | |||
| 12 | 13 | ||
| 13 | class IFileSystem final : public ServiceFramework<IFileSystem> { | 14 | class IFileSystem final : public ServiceFramework<IFileSystem> { |
| 14 | public: | 15 | public: |
| 15 | explicit IFileSystem(Core::System& system_, FileSys::VirtualDir backend_, SizeGetter size_); | 16 | explicit IFileSystem(Core::System& system_, FileSys::VirtualDir dir_, SizeGetter size_); |
| 16 | 17 | ||
| 17 | void CreateFile(HLERequestContext& ctx); | 18 | void CreateFile(HLERequestContext& ctx); |
| 18 | void DeleteFile(HLERequestContext& ctx); | 19 | void DeleteFile(HLERequestContext& ctx); |
| @@ -31,7 +32,7 @@ public: | |||
| 31 | void GetFileSystemAttribute(HLERequestContext& ctx); | 32 | void GetFileSystemAttribute(HLERequestContext& ctx); |
| 32 | 33 | ||
| 33 | private: | 34 | private: |
| 34 | VfsDirectoryServiceWrapper backend; | 35 | std::unique_ptr<FileSys::Fsa::IFileSystem> backend; |
| 35 | SizeGetter size; | 36 | SizeGetter size; |
| 36 | }; | 37 | }; |
| 37 | 38 | ||