IStorage.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Ryujinx.HLE.OsHle.Ipc;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. namespace Ryujinx.HLE.OsHle.Services.FspSrv
  5. {
  6. class IStorage : IpcService
  7. {
  8. private Dictionary<int, ServiceProcessRequest> m_Commands;
  9. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  10. private Stream BaseStream;
  11. public IStorage(Stream BaseStream)
  12. {
  13. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  14. {
  15. { 0, Read }
  16. };
  17. this.BaseStream = BaseStream;
  18. }
  19. public long Read(ServiceCtx Context)
  20. {
  21. long Offset = Context.RequestData.ReadInt64();
  22. long Size = Context.RequestData.ReadInt64();
  23. if (Context.Request.ReceiveBuff.Count > 0)
  24. {
  25. IpcBuffDesc BuffDesc = Context.Request.ReceiveBuff[0];
  26. //Use smaller length to avoid overflows.
  27. if (Size > BuffDesc.Size)
  28. {
  29. Size = BuffDesc.Size;
  30. }
  31. byte[] Data = new byte[Size];
  32. BaseStream.Seek(Offset, SeekOrigin.Begin);
  33. BaseStream.Read(Data, 0, Data.Length);
  34. Context.Memory.WriteBytes(BuffDesc.Position, Data);
  35. }
  36. return 0;
  37. }
  38. }
  39. }