summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.cpp39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp
index 1b003bd84..e7ffb6bd1 100644
--- a/src/core/hle/service/filesystem/fsp_srv.cpp
+++ b/src/core/hle/service/filesystem/fsp_srv.cpp
@@ -3,6 +3,14 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <cinttypes> 5#include <cinttypes>
6#include <cstring>
7#include <iterator>
8#include <string>
9#include <utility>
10#include <vector>
11
12#include "common/assert.h"
13#include "common/common_types.h"
6#include "common/logging/log.h" 14#include "common/logging/log.h"
7#include "common/string_util.h" 15#include "common/string_util.h"
8#include "core/core.h" 16#include "core/core.h"
@@ -26,7 +34,7 @@ enum class StorageId : u8 {
26 34
27class IStorage final : public ServiceFramework<IStorage> { 35class IStorage final : public ServiceFramework<IStorage> {
28public: 36public:
29 IStorage(FileSys::VirtualFile backend_) 37 explicit IStorage(FileSys::VirtualFile backend_)
30 : ServiceFramework("IStorage"), backend(std::move(backend_)) { 38 : ServiceFramework("IStorage"), backend(std::move(backend_)) {
31 static const FunctionInfo functions[] = { 39 static const FunctionInfo functions[] = {
32 {0, &IStorage::Read, "Read"}, {1, nullptr, "Write"}, {2, nullptr, "Flush"}, 40 {0, &IStorage::Read, "Read"}, {1, nullptr, "Write"}, {2, nullptr, "Flush"},
@@ -133,19 +141,19 @@ private:
133 return; 141 return;
134 } 142 }
135 143
136 std::vector<u8> data = ctx.ReadBuffer(); 144 const std::vector<u8> data = ctx.ReadBuffer();
137 std::vector<u8> actual_data(length);
138 145
139 ASSERT_MSG( 146 ASSERT_MSG(
140 data.size() <= length, 147 static_cast<s64>(data.size()) <= length,
141 "Attempting to write more data than requested (requested={:016X}, actual={:016X}).", 148 "Attempting to write more data than requested (requested={:016X}, actual={:016X}).",
142 length, data.size()); 149 length, data.size());
143 150
144 std::copy(data.begin(), data.end(), actual_data.begin());
145 // Write the data to the Storage backend 151 // Write the data to the Storage backend
146 auto written = backend->WriteBytes(data, offset); 152 const auto write_size =
153 static_cast<std::size_t>(std::distance(data.begin(), data.begin() + length));
154 const std::size_t written = backend->Write(data.data(), write_size, offset);
147 155
148 ASSERT_MSG(written == length, 156 ASSERT_MSG(static_cast<s64>(written) == length,
149 "Could not write all bytes to file (requested={:016X}, actual={:016X}).", length, 157 "Could not write all bytes to file (requested={:016X}, actual={:016X}).", length,
150 written); 158 written);
151 159
@@ -223,23 +231,20 @@ private:
223 LOG_DEBUG(Service_FS, "called, unk=0x{:X}", unk); 231 LOG_DEBUG(Service_FS, "called, unk=0x{:X}", unk);
224 232
225 // Calculate how many entries we can fit in the output buffer 233 // Calculate how many entries we can fit in the output buffer
226 u64 count_entries = ctx.GetWriteBufferSize() / sizeof(FileSys::Entry); 234 const u64 count_entries = ctx.GetWriteBufferSize() / sizeof(FileSys::Entry);
227 235
228 // Cap at total number of entries. 236 // Cap at total number of entries.
229 u64 actual_entries = std::min(count_entries, entries.size() - next_entry_index); 237 const u64 actual_entries = std::min(count_entries, entries.size() - next_entry_index);
230 238
231 // Read the data from the Directory backend 239 // Determine data start and end
232 std::vector<FileSys::Entry> entry_data(entries.begin() + next_entry_index, 240 const auto* begin = reinterpret_cast<u8*>(entries.data() + next_entry_index);
233 entries.begin() + next_entry_index + actual_entries); 241 const auto* end = reinterpret_cast<u8*>(entries.data() + next_entry_index + actual_entries);
242 const auto range_size = static_cast<std::size_t>(std::distance(begin, end));
234 243
235 next_entry_index += actual_entries; 244 next_entry_index += actual_entries;
236 245
237 // Convert the data into a byte array
238 std::vector<u8> output(entry_data.size() * sizeof(FileSys::Entry));
239 std::memcpy(output.data(), entry_data.data(), output.size());
240
241 // Write the data to memory 246 // Write the data to memory
242 ctx.WriteBuffer(output); 247 ctx.WriteBuffer(begin, range_size);
243 248
244 IPC::ResponseBuilder rb{ctx, 4}; 249 IPC::ResponseBuilder rb{ctx, 4};
245 rb.Push(RESULT_SUCCESS); 250 rb.Push(RESULT_SUCCESS);