|
4 | 4 | #include "core/file_sys/errors.h" |
5 | 5 | #include "core/hle/service/cmif_serialization.h" |
6 | 6 | #include "core/hle/service/filesystem/fsp/fs_i_storage.h" |
| 7 | +#include <nxemu-module-spec/system_loader.h> |
7 | 8 |
|
8 | 9 | namespace Service::FileSystem { |
9 | 10 |
|
| 11 | +IStorage::IStorage(Core::System& system_, IVirtualFilePtr && backend_) |
| 12 | + : ServiceFramework{system_, "IStorage"}, backend(std::move(backend_)) { |
| 13 | + static const FunctionInfo functions[] = { |
| 14 | + {0, D<&IStorage::Read>, "Read"}, |
| 15 | + {1, nullptr, "Write"}, |
| 16 | + {2, nullptr, "Flush"}, |
| 17 | + {3, nullptr, "SetSize"}, |
| 18 | + {4, D<&IStorage::GetSize>, "GetSize"}, |
| 19 | + {5, nullptr, "OperateRange"}, |
| 20 | + }; |
| 21 | + RegisterHandlers(functions); |
| 22 | +} |
| 23 | + |
| 24 | +Result IStorage::Read( |
| 25 | + OutBuffer<BufferAttr_HipcMapAlias | BufferAttr_HipcMapTransferAllowsNonSecure> out_bytes, |
| 26 | + s64 offset, s64 length) { |
| 27 | + LOG_DEBUG(Service_FS, "called, offset=0x{:X}, length={}", offset, length); |
| 28 | + |
| 29 | + R_UNLESS(length >= 0, FileSys::ResultInvalidSize); |
| 30 | + R_UNLESS(offset >= 0, FileSys::ResultInvalidOffset); |
| 31 | + |
| 32 | + // Read the data from the Storage backend |
| 33 | + backend->ReadBytes(out_bytes.data(), length, offset); |
| 34 | + |
| 35 | + R_SUCCEED(); |
| 36 | +} |
| 37 | + |
| 38 | +Result IStorage::GetSize(Out<u64> out_size) { |
| 39 | + *out_size = backend->GetSize(); |
| 40 | + |
| 41 | + LOG_DEBUG(Service_FS, "called, size={}", *out_size); |
| 42 | + |
| 43 | + R_SUCCEED(); |
| 44 | +} |
| 45 | + |
10 | 46 | } // namespace Service::FileSystem |
0 commit comments