diff options
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 { class IDirectory { public: - IDirectory(VirtualDir backend_, OpenDirectoryMode mode) : backend(std::move(backend_)) { + explicit IDirectory(VirtualDir backend_, OpenDirectoryMode mode) + : backend(std::move(backend_)) { // TODO(DarkLordZach): Verify that this is the correct behavior. // Build entry index now to save time later. if (True(mode & OpenDirectoryMode::Directory)) { - BuildEntryIndex(entries, backend->GetSubdirectories(), DirectoryEntryType::Directory); + BuildEntryIndex(backend->GetSubdirectories(), DirectoryEntryType::Directory); } if (True(mode & OpenDirectoryMode::File)) { - BuildEntryIndex(entries, backend->GetFiles(), DirectoryEntryType::File); + BuildEntryIndex(backend->GetFiles(), DirectoryEntryType::File); } } virtual ~IDirectory() {} @@ -45,28 +46,29 @@ public: } private: - virtual Result DoRead(s64* out_count, DirectoryEntry* out_entries, s64 max_entries) { + Result DoRead(s64* out_count, DirectoryEntry* out_entries, s64 max_entries) { const u64 actual_entries = std::min(static_cast<u64>(max_entries), entries.size() - next_entry_index); - auto* begin = reinterpret_cast<u8*>(entries.data() + next_entry_index); + const auto* begin = reinterpret_cast<u8*>(entries.data() + next_entry_index); + const auto* end = reinterpret_cast<u8*>(entries.data() + next_entry_index + actual_entries); + const auto range_size = static_cast<std::size_t>(std::distance(begin, end)); next_entry_index += actual_entries; *out_count = actual_entries; - out_entries = reinterpret_cast<DirectoryEntry*>(begin); + std::memcpy(out_entries, entries.data(), range_size); R_SUCCEED(); } - virtual Result DoGetEntryCount(s64* out) { + Result DoGetEntryCount(s64* out) { *out = entries.size() - next_entry_index; R_SUCCEED(); } // TODO: Remove this when VFS is gone template <typename T> - void BuildEntryIndex(std::vector<DirectoryEntry>& entries, const std::vector<T>& new_data, - DirectoryEntryType type) { + void BuildEntryIndex(const std::vector<T>& new_data, DirectoryEntryType type) { entries.reserve(entries.size() + new_data.size()); 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 { class IFile { public: - IFile(VirtualFile backend_) : backend(std::move(backend_)) {} + explicit IFile(VirtualFile backend_) : backend(std::move(backend_)) {} virtual ~IFile() {} Result Read(size_t* out, s64 offset, void* buffer, size_t size, const ReadOption& option) { @@ -126,8 +126,10 @@ protected: private: Result DoRead(size_t* out, s64 offset, void* buffer, size_t size, const ReadOption& option) { std::vector<u8> output = backend->ReadBytes(size, offset); + *out = output.size(); - buffer = output.data(); + std::memcpy(buffer, output.data(), size); + R_SUCCEED(); } 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 { class IFile; class IDirectory; -enum class QueryId { +enum class QueryId : u32 { SetConcatenationFileAttribute = 0, UpdateMac = 1, IsSignedSystemPartitionOnSdCardValid = 2, @@ -24,7 +24,7 @@ enum class QueryId { class IFileSystem { public: - IFileSystem(VirtualDir backend_) : backend{std::move(backend_)} {} + explicit IFileSystem(VirtualDir backend_) : backend{std::move(backend_)} {} virtual ~IFileSystem() {} Result CreateFile(const Path& path, s64 size, CreateOption option) { @@ -158,8 +158,7 @@ private: R_RETURN(backend.OpenFile(out_file, path.GetString(), mode)); } - Result DoOpenDirectory(VirtualDir* out_directory, const Path& path, - OpenDirectoryMode mode) { + Result DoOpenDirectory(VirtualDir* out_directory, const Path& path, OpenDirectoryMode mode) { R_RETURN(backend.OpenDirectory(out_directory, path.GetString())); } |