IStorage.cs 1.7 KB

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