IStorage.cs 1.8 KB

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