IStorage.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using LibHac;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
  4. {
  5. class IStorage : IpcService
  6. {
  7. private LibHac.Fs.IStorage _baseStorage;
  8. public IStorage(LibHac.Fs.IStorage baseStorage)
  9. {
  10. _baseStorage = baseStorage;
  11. }
  12. [Command(0)]
  13. // Read(u64 offset, u64 length) -> buffer<u8, 0x46, 0> buffer
  14. public ResultCode Read(ServiceCtx context)
  15. {
  16. long offset = context.RequestData.ReadInt64();
  17. long size = context.RequestData.ReadInt64();
  18. if (context.Request.ReceiveBuff.Count > 0)
  19. {
  20. IpcBuffDesc buffDesc = context.Request.ReceiveBuff[0];
  21. // Use smaller length to avoid overflows.
  22. if (size > buffDesc.Size)
  23. {
  24. size = buffDesc.Size;
  25. }
  26. byte[] data = new byte[size];
  27. Result result = _baseStorage.Read(offset, data);
  28. context.Memory.WriteBytes(buffDesc.Position, data);
  29. return (ResultCode)result.Value;
  30. }
  31. return ResultCode.Success;
  32. }
  33. [Command(4)]
  34. // GetSize() -> u64 size
  35. public ResultCode GetSize(ServiceCtx context)
  36. {
  37. Result result = _baseStorage.GetSize(out long size);
  38. context.ResponseData.Write(size);
  39. return (ResultCode)result.Value;
  40. }
  41. }
  42. }