IStorage.cs 1.6 KB

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