IStorage.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using LibHac;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
  4. {
  5. class IStorage : DisposableIpcService
  6. {
  7. private LibHac.Fs.IStorage _baseStorage;
  8. public IStorage(LibHac.Fs.IStorage baseStorage)
  9. {
  10. _baseStorage = baseStorage;
  11. }
  12. [CommandHipc(0)]
  13. // Read(u64 offset, u64 length) -> buffer<u8, 0x46, 0> buffer
  14. public ResultCode Read(ServiceCtx context)
  15. {
  16. ulong offset = context.RequestData.ReadUInt64();
  17. ulong size = context.RequestData.ReadUInt64();
  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((long)offset, data);
  28. context.Memory.Write(buffDesc.Position, data);
  29. return (ResultCode)result.Value;
  30. }
  31. return ResultCode.Success;
  32. }
  33. [CommandHipc(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. protected override void Dispose(bool isDisposing)
  42. {
  43. if (isDisposing)
  44. {
  45. _baseStorage?.Dispose();
  46. }
  47. }
  48. }
  49. }