diff options
| author | 2024-02-11 22:27:20 +0100 | |
|---|---|---|
| committer | 2024-02-19 19:20:46 +0100 | |
| commit | ba70dc4c13ff84b51d2937f5c8ba873b061cb4c1 (patch) | |
| tree | 82751935ffc1d9b1ab8a9f3fa0999762b1e6e9b2 /src/core/file_sys/fsa | |
| 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/core/file_sys/fsa')
| -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 |
3 files changed, 18 insertions, 15 deletions
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 | ||