summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/filesystem/fsp/fs_i_storage.cpp
diff options
context:
space:
mode:
authorliamwhite <liamwhite@users.noreply.github.com>2024-01-26 15:55:25 +0100
committerGitHub <noreply@github.com>2024-01-26 15:55:25 +0100
commit55482ab5dce463d5014498b006c18a90d0d004e6 (patch)
treeb343faa9cadc692265efb4b6b88e157c97ef76d2 /src/core/hle/service/filesystem/fsp/fs_i_storage.cpp
parentMerge pull request #12796 from t895/controller-optimizations (diff)
parentAddress review comments and fix compilation problems (diff)
downloadyuzu-55482ab5dce463d5014498b006c18a90d0d004e6.tar
yuzu-55482ab5dce463d5014498b006c18a90d0d004e6.tar.gz
yuzu-55482ab5dce463d5014498b006c18a90d0d004e6.tar.bz2
yuzu-55482ab5dce463d5014498b006c18a90d0d004e6.tar.lz
yuzu-55482ab5dce463d5014498b006c18a90d0d004e6.tar.xz
yuzu-55482ab5dce463d5014498b006c18a90d0d004e6.tar.zst
yuzu-55482ab5dce463d5014498b006c18a90d0d004e6.zip
Diffstat (limited to 'src/core/hle/service/filesystem/fsp/fs_i_storage.cpp')
-rw-r--r--src/core/hle/service/filesystem/fsp/fs_i_storage.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/core/hle/service/filesystem/fsp/fs_i_storage.cpp b/src/core/hle/service/filesystem/fsp/fs_i_storage.cpp
new file mode 100644
index 000000000..98223c1f9
--- /dev/null
+++ b/src/core/hle/service/filesystem/fsp/fs_i_storage.cpp
@@ -0,0 +1,62 @@
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "core/file_sys/errors.h"
+#include "core/hle/service/filesystem/fsp/fs_i_storage.h"
+#include "core/hle/service/ipc_helpers.h"
+
+namespace Service::FileSystem {
+
+IStorage::IStorage(Core::System& system_, FileSys::VirtualFile backend_)
+ : ServiceFramework{system_, "IStorage"}, backend(std::move(backend_)) {
+ static const FunctionInfo functions[] = {
+ {0, &IStorage::Read, "Read"},
+ {1, nullptr, "Write"},
+ {2, nullptr, "Flush"},
+ {3, nullptr, "SetSize"},
+ {4, &IStorage::GetSize, "GetSize"},
+ {5, nullptr, "OperateRange"},
+ };
+ RegisterHandlers(functions);
+}
+
+void IStorage::Read(HLERequestContext& ctx) {
+ IPC::RequestParser rp{ctx};
+ const s64 offset = rp.Pop<s64>();
+ const s64 length = rp.Pop<s64>();
+
+ LOG_DEBUG(Service_FS, "called, offset=0x{:X}, length={}", offset, length);
+
+ // Error checking
+ if (length < 0) {
+ LOG_ERROR(Service_FS, "Length is less than 0, length={}", length);
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(FileSys::ResultInvalidSize);
+ return;
+ }
+ if (offset < 0) {
+ LOG_ERROR(Service_FS, "Offset is less than 0, offset={}", offset);
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(FileSys::ResultInvalidOffset);
+ return;
+ }
+
+ // Read the data from the Storage backend
+ std::vector<u8> output = backend->ReadBytes(length, offset);
+ // Write the data to memory
+ ctx.WriteBuffer(output);
+
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(ResultSuccess);
+}
+
+void IStorage::GetSize(HLERequestContext& ctx) {
+ const u64 size = backend->GetSize();
+ LOG_DEBUG(Service_FS, "called, size={}", size);
+
+ IPC::ResponseBuilder rb{ctx, 4};
+ rb.Push(ResultSuccess);
+ rb.Push<u64>(size);
+}
+
+} // namespace Service::FileSystem