diff options
| author | 2024-02-11 22:27:20 +0100 | |
|---|---|---|
| committer | 2024-02-19 19:20:46 +0100 | |
| commit | ba70dc4c13ff84b51d2937f5c8ba873b061cb4c1 (patch) | |
| tree | 82751935ffc1d9b1ab8a9f3fa0999762b1e6e9b2 /src | |
| parent | fs: Refactor to use cmif serialization (diff) | |
| download | yuzu-ba70dc4c13ff84b51d2937f5c8ba873b061cb4c1.tar.gz yuzu-ba70dc4c13ff84b51d2937f5c8ba873b061cb4c1.tar.xz yuzu-ba70dc4c13ff84b51d2937f5c8ba873b061cb4c1.zip | |
Address review comments
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/file_sys/fs_filesystem.h | 2 | ||||
| -rw-r--r-- | src/core/file_sys/fs_path_utility.h | 15 | ||||
| -rw-r--r-- | src/core/file_sys/fsa/fs_i_directory.h | 20 | ||||
| -rw-r--r-- | src/core/file_sys/fsa/fs_i_file.h | 6 | ||||
| -rw-r--r-- | src/core/file_sys/fsa/fs_i_filesystem.h | 7 | ||||
| -rw-r--r-- | src/core/file_sys/fssrv/fssrv_sf_path.h | 2 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/fsp/fs_i_filesystem.h | 5 |
8 files changed, 35 insertions, 26 deletions
diff --git a/src/core/file_sys/fs_filesystem.h b/src/core/file_sys/fs_filesystem.h index 7065ef6a6..598b59a74 100644 --- a/src/core/file_sys/fs_filesystem.h +++ b/src/core/file_sys/fs_filesystem.h | |||
| @@ -24,7 +24,7 @@ enum class OpenDirectoryMode : u64 { | |||
| 24 | 24 | ||
| 25 | All = (Directory | File), | 25 | All = (Directory | File), |
| 26 | 26 | ||
| 27 | NotRequireFileSize = (1 << 31), | 27 | NotRequireFileSize = (1ULL << 31), |
| 28 | }; | 28 | }; |
| 29 | DECLARE_ENUM_FLAG_OPERATORS(OpenDirectoryMode) | 29 | DECLARE_ENUM_FLAG_OPERATORS(OpenDirectoryMode) |
| 30 | 30 | ||
diff --git a/src/core/file_sys/fs_path_utility.h b/src/core/file_sys/fs_path_utility.h index 5643141f9..51418ee16 100644 --- a/src/core/file_sys/fs_path_utility.h +++ b/src/core/file_sys/fs_path_utility.h | |||
| @@ -91,8 +91,12 @@ public: | |||
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | #define DECLARE_PATH_FLAG_HANDLER(__WHICH__) \ | 93 | #define DECLARE_PATH_FLAG_HANDLER(__WHICH__) \ |
| 94 | constexpr bool Is##__WHICH__##Allowed() const { return (m_value & __WHICH__##Flag) != 0; } \ | 94 | constexpr bool Is##__WHICH__##Allowed() const { \ |
| 95 | constexpr void Allow##__WHICH__() { m_value |= __WHICH__##Flag; } | 95 | return (m_value & __WHICH__##Flag) != 0; \ |
| 96 | } \ | ||
| 97 | constexpr void Allow##__WHICH__() { \ | ||
| 98 | m_value |= __WHICH__##Flag; \ | ||
| 99 | } | ||
| 96 | 100 | ||
| 97 | DECLARE_PATH_FLAG_HANDLER(WindowsPath) | 101 | DECLARE_PATH_FLAG_HANDLER(WindowsPath) |
| 98 | DECLARE_PATH_FLAG_HANDLER(RelativePath) | 102 | DECLARE_PATH_FLAG_HANDLER(RelativePath) |
| @@ -426,9 +430,10 @@ public: | |||
| 426 | R_SUCCEED(); | 430 | R_SUCCEED(); |
| 427 | } | 431 | } |
| 428 | 432 | ||
| 429 | static Result Normalize(char* dst, size_t* out_len, const char* path, size_t max_out_size, | 433 | static constexpr Result Normalize(char* dst, size_t* out_len, const char* path, |
| 430 | bool is_windows_path, bool is_drive_relative_path, | 434 | size_t max_out_size, bool is_windows_path, |
| 431 | bool allow_all_characters = false) { | 435 | bool is_drive_relative_path, |
| 436 | bool allow_all_characters = false) { | ||
| 432 | // Use StringTraits names for remainder of scope | 437 | // Use StringTraits names for remainder of scope |
| 433 | using namespace StringTraits; | 438 | using namespace StringTraits; |
| 434 | 439 | ||
diff --git a/src/core/file_sys/fsa/fs_i_directory.h b/src/core/file_sys/fsa/fs_i_directory.h index a4135efec..fc0407d01 100644 --- a/src/core/file_sys/fsa/fs_i_directory.h +++ b/src/core/file_sys/fsa/fs_i_directory.h | |||
| @@ -16,14 +16,15 @@ namespace FileSys::Fsa { | |||
| 16 | 16 | ||
| 17 | class IDirectory { | 17 | class IDirectory { |
| 18 | public: | 18 | public: |
| 19 | IDirectory(VirtualDir backend_, OpenDirectoryMode mode) : backend(std::move(backend_)) { | 19 | explicit IDirectory(VirtualDir backend_, OpenDirectoryMode mode) |
| 20 | : backend(std::move(backend_)) { | ||
| 20 | // TODO(DarkLordZach): Verify that this is the correct behavior. | 21 | // TODO(DarkLordZach): Verify that this is the correct behavior. |
| 21 | // Build entry index now to save time later. | 22 | // Build entry index now to save time later. |
| 22 | if (True(mode & OpenDirectoryMode::Directory)) { | 23 | if (True(mode & OpenDirectoryMode::Directory)) { |
| 23 | BuildEntryIndex(entries, backend->GetSubdirectories(), DirectoryEntryType::Directory); | 24 | BuildEntryIndex(backend->GetSubdirectories(), DirectoryEntryType::Directory); |
| 24 | } | 25 | } |
| 25 | if (True(mode & OpenDirectoryMode::File)) { | 26 | if (True(mode & OpenDirectoryMode::File)) { |
| 26 | BuildEntryIndex(entries, backend->GetFiles(), DirectoryEntryType::File); | 27 | BuildEntryIndex(backend->GetFiles(), DirectoryEntryType::File); |
| 27 | } | 28 | } |
| 28 | } | 29 | } |
| 29 | virtual ~IDirectory() {} | 30 | virtual ~IDirectory() {} |
| @@ -45,28 +46,29 @@ public: | |||
| 45 | } | 46 | } |
| 46 | 47 | ||
| 47 | private: | 48 | private: |
| 48 | virtual Result DoRead(s64* out_count, DirectoryEntry* out_entries, s64 max_entries) { | 49 | Result DoRead(s64* out_count, DirectoryEntry* out_entries, s64 max_entries) { |
| 49 | const u64 actual_entries = | 50 | const u64 actual_entries = |
| 50 | std::min(static_cast<u64>(max_entries), entries.size() - next_entry_index); | 51 | std::min(static_cast<u64>(max_entries), entries.size() - next_entry_index); |
| 51 | auto* begin = reinterpret_cast<u8*>(entries.data() + next_entry_index); | 52 | const auto* begin = reinterpret_cast<u8*>(entries.data() + next_entry_index); |
| 53 | const auto* end = reinterpret_cast<u8*>(entries.data() + next_entry_index + actual_entries); | ||
| 54 | const auto range_size = static_cast<std::size_t>(std::distance(begin, end)); | ||
| 52 | 55 | ||
| 53 | next_entry_index += actual_entries; | 56 | next_entry_index += actual_entries; |
| 54 | *out_count = actual_entries; | 57 | *out_count = actual_entries; |
| 55 | 58 | ||
| 56 | out_entries = reinterpret_cast<DirectoryEntry*>(begin); | 59 | std::memcpy(out_entries, entries.data(), range_size); |
| 57 | 60 | ||
| 58 | R_SUCCEED(); | 61 | R_SUCCEED(); |
| 59 | } | 62 | } |
| 60 | 63 | ||
| 61 | virtual Result DoGetEntryCount(s64* out) { | 64 | Result DoGetEntryCount(s64* out) { |
| 62 | *out = entries.size() - next_entry_index; | 65 | *out = entries.size() - next_entry_index; |
| 63 | R_SUCCEED(); | 66 | R_SUCCEED(); |
| 64 | } | 67 | } |
| 65 | 68 | ||
| 66 | // TODO: Remove this when VFS is gone | 69 | // TODO: Remove this when VFS is gone |
| 67 | template <typename T> | 70 | template <typename T> |
| 68 | void BuildEntryIndex(std::vector<DirectoryEntry>& entries, const std::vector<T>& new_data, | 71 | void BuildEntryIndex(const std::vector<T>& new_data, DirectoryEntryType type) { |
| 69 | DirectoryEntryType type) { | ||
| 70 | entries.reserve(entries.size() + new_data.size()); | 72 | entries.reserve(entries.size() + new_data.size()); |
| 71 | 73 | ||
| 72 | for (const auto& new_entry : new_data) { | 74 | for (const auto& new_entry : new_data) { |
diff --git a/src/core/file_sys/fsa/fs_i_file.h b/src/core/file_sys/fsa/fs_i_file.h index 6dd0f6439..8fdd71c80 100644 --- a/src/core/file_sys/fsa/fs_i_file.h +++ b/src/core/file_sys/fsa/fs_i_file.h | |||
| @@ -16,7 +16,7 @@ namespace FileSys::Fsa { | |||
| 16 | 16 | ||
| 17 | class IFile { | 17 | class IFile { |
| 18 | public: | 18 | public: |
| 19 | IFile(VirtualFile backend_) : backend(std::move(backend_)) {} | 19 | explicit IFile(VirtualFile backend_) : backend(std::move(backend_)) {} |
| 20 | virtual ~IFile() {} | 20 | virtual ~IFile() {} |
| 21 | 21 | ||
| 22 | Result Read(size_t* out, s64 offset, void* buffer, size_t size, const ReadOption& option) { | 22 | Result Read(size_t* out, s64 offset, void* buffer, size_t size, const ReadOption& option) { |
| @@ -126,8 +126,10 @@ protected: | |||
| 126 | private: | 126 | private: |
| 127 | Result DoRead(size_t* out, s64 offset, void* buffer, size_t size, const ReadOption& option) { | 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); | 128 | std::vector<u8> output = backend->ReadBytes(size, offset); |
| 129 | |||
| 129 | *out = output.size(); | 130 | *out = output.size(); |
| 130 | buffer = output.data(); | 131 | std::memcpy(buffer, output.data(), size); |
| 132 | |||
| 131 | R_SUCCEED(); | 133 | R_SUCCEED(); |
| 132 | } | 134 | } |
| 133 | 135 | ||
diff --git a/src/core/file_sys/fsa/fs_i_filesystem.h b/src/core/file_sys/fsa/fs_i_filesystem.h index e92284459..8172190f4 100644 --- a/src/core/file_sys/fsa/fs_i_filesystem.h +++ b/src/core/file_sys/fsa/fs_i_filesystem.h | |||
| @@ -15,7 +15,7 @@ namespace FileSys::Fsa { | |||
| 15 | class IFile; | 15 | class IFile; |
| 16 | class IDirectory; | 16 | class IDirectory; |
| 17 | 17 | ||
| 18 | enum class QueryId { | 18 | enum class QueryId : u32 { |
| 19 | SetConcatenationFileAttribute = 0, | 19 | SetConcatenationFileAttribute = 0, |
| 20 | UpdateMac = 1, | 20 | UpdateMac = 1, |
| 21 | IsSignedSystemPartitionOnSdCardValid = 2, | 21 | IsSignedSystemPartitionOnSdCardValid = 2, |
| @@ -24,7 +24,7 @@ enum class QueryId { | |||
| 24 | 24 | ||
| 25 | class IFileSystem { | 25 | class IFileSystem { |
| 26 | public: | 26 | public: |
| 27 | IFileSystem(VirtualDir backend_) : backend{std::move(backend_)} {} | 27 | explicit IFileSystem(VirtualDir backend_) : backend{std::move(backend_)} {} |
| 28 | virtual ~IFileSystem() {} | 28 | virtual ~IFileSystem() {} |
| 29 | 29 | ||
| 30 | Result CreateFile(const Path& path, s64 size, CreateOption option) { | 30 | Result CreateFile(const Path& path, s64 size, CreateOption option) { |
| @@ -158,8 +158,7 @@ private: | |||
| 158 | R_RETURN(backend.OpenFile(out_file, path.GetString(), mode)); | 158 | R_RETURN(backend.OpenFile(out_file, path.GetString(), mode)); |
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | Result DoOpenDirectory(VirtualDir* out_directory, const Path& path, | 161 | Result DoOpenDirectory(VirtualDir* out_directory, const Path& path, OpenDirectoryMode mode) { |
| 162 | OpenDirectoryMode mode) { | ||
| 163 | R_RETURN(backend.OpenDirectory(out_directory, path.GetString())); | 162 | R_RETURN(backend.OpenDirectory(out_directory, path.GetString())); |
| 164 | } | 163 | } |
| 165 | 164 | ||
diff --git a/src/core/file_sys/fssrv/fssrv_sf_path.h b/src/core/file_sys/fssrv/fssrv_sf_path.h index 1752a413d..a0c0b2dac 100644 --- a/src/core/file_sys/fssrv/fssrv_sf_path.h +++ b/src/core/file_sys/fssrv/fssrv_sf_path.h | |||
| @@ -33,4 +33,4 @@ static_assert(std::is_trivially_copyable_v<Path>, "Path must be trivially copyab | |||
| 33 | 33 | ||
| 34 | using FspPath = Path; | 34 | using FspPath = Path; |
| 35 | 35 | ||
| 36 | } // namespace FileSys::Sf \ No newline at end of file | 36 | } // namespace FileSys::Sf |
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 7fc62cb3e..86dd5b7e9 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp +++ b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp | |||
| @@ -11,8 +11,8 @@ | |||
| 11 | namespace Service::FileSystem { | 11 | namespace Service::FileSystem { |
| 12 | 12 | ||
| 13 | IFileSystem::IFileSystem(Core::System& system_, FileSys::VirtualDir dir_, SizeGetter size_getter_) | 13 | IFileSystem::IFileSystem(Core::System& system_, FileSys::VirtualDir dir_, SizeGetter size_getter_) |
| 14 | : ServiceFramework{system_, "IFileSystem"}, | 14 | : ServiceFramework{system_, "IFileSystem"}, backend{std::make_unique<FileSys::Fsa::IFileSystem>( |
| 15 | backend{std::make_unique<FileSys::Fsa::IFileSystem>(dir_)}, | 15 | dir_)}, |
| 16 | size_getter{std::move(size_getter_)} { | 16 | size_getter{std::move(size_getter_)} { |
| 17 | static const FunctionInfo functions[] = { | 17 | static const FunctionInfo functions[] = { |
| 18 | {0, D<&IFileSystem::CreateFile>, "CreateFile"}, | 18 | {0, D<&IFileSystem::CreateFile>, "CreateFile"}, |
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 d07b74938..230ab8d71 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 "common/common_funcs.h" | ||
| 6 | #include "core/file_sys/fsa/fs_i_filesystem.h" | 7 | #include "core/file_sys/fsa/fs_i_filesystem.h" |
| 7 | #include "core/file_sys/vfs/vfs.h" | 8 | #include "core/file_sys/vfs/vfs.h" |
| 8 | #include "core/hle/service/cmif_types.h" | 9 | #include "core/hle/service/cmif_types.h" |
| @@ -48,8 +49,8 @@ public: | |||
| 48 | }; | 49 | }; |
| 49 | static_assert(sizeof(FileSystemAttribute) == 0xC0, "FileSystemAttribute has incorrect size"); | 50 | static_assert(sizeof(FileSystemAttribute) == 0xC0, "FileSystemAttribute has incorrect size"); |
| 50 | 51 | ||
| 51 | Result CreateFile(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path, | 52 | Result CreateFile(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path, s32 option, |
| 52 | s32 option, s64 size); | 53 | s64 size); |
| 53 | Result DeleteFile(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path); | 54 | Result DeleteFile(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path); |
| 54 | Result CreateDirectory(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path); | 55 | Result CreateDirectory(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path); |
| 55 | Result DeleteDirectory(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path); | 56 | Result DeleteDirectory(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path); |