IFileSystem.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. using LibHac;
  2. using LibHac.Fs;
  3. using static Ryujinx.HLE.Utilities.StringUtils;
  4. namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
  5. {
  6. class IFileSystem : IpcService
  7. {
  8. private LibHac.Fs.IFileSystem _fileSystem;
  9. public IFileSystem(LibHac.Fs.IFileSystem provider)
  10. {
  11. _fileSystem = provider;
  12. }
  13. [Command(0)]
  14. // CreateFile(u32 createOption, u64 size, buffer<bytes<0x301>, 0x19, 0x301> path)
  15. public ResultCode CreateFile(ServiceCtx context)
  16. {
  17. string name = ReadUtf8String(context);
  18. CreateFileOptions createOption = (CreateFileOptions)context.RequestData.ReadInt32();
  19. context.RequestData.BaseStream.Position += 4;
  20. long size = context.RequestData.ReadInt64();
  21. return (ResultCode)_fileSystem.CreateFile(name, size, createOption).Value;
  22. }
  23. [Command(1)]
  24. // DeleteFile(buffer<bytes<0x301>, 0x19, 0x301> path)
  25. public ResultCode DeleteFile(ServiceCtx context)
  26. {
  27. string name = ReadUtf8String(context);
  28. return (ResultCode)_fileSystem.DeleteFile(name).Value;
  29. }
  30. [Command(2)]
  31. // CreateDirectory(buffer<bytes<0x301>, 0x19, 0x301> path)
  32. public ResultCode CreateDirectory(ServiceCtx context)
  33. {
  34. string name = ReadUtf8String(context);
  35. return (ResultCode)_fileSystem.CreateDirectory(name).Value;
  36. }
  37. [Command(3)]
  38. // DeleteDirectory(buffer<bytes<0x301>, 0x19, 0x301> path)
  39. public ResultCode DeleteDirectory(ServiceCtx context)
  40. {
  41. string name = ReadUtf8String(context);
  42. return (ResultCode)_fileSystem.DeleteDirectory(name).Value;
  43. }
  44. [Command(4)]
  45. // DeleteDirectoryRecursively(buffer<bytes<0x301>, 0x19, 0x301> path)
  46. public ResultCode DeleteDirectoryRecursively(ServiceCtx context)
  47. {
  48. string name = ReadUtf8String(context);
  49. return (ResultCode)_fileSystem.DeleteDirectoryRecursively(name).Value;
  50. }
  51. [Command(5)]
  52. // RenameFile(buffer<bytes<0x301>, 0x19, 0x301> oldPath, buffer<bytes<0x301>, 0x19, 0x301> newPath)
  53. public ResultCode RenameFile(ServiceCtx context)
  54. {
  55. string oldName = ReadUtf8String(context, 0);
  56. string newName = ReadUtf8String(context, 1);
  57. return (ResultCode)_fileSystem.RenameFile(oldName, newName).Value;
  58. }
  59. [Command(6)]
  60. // RenameDirectory(buffer<bytes<0x301>, 0x19, 0x301> oldPath, buffer<bytes<0x301>, 0x19, 0x301> newPath)
  61. public ResultCode RenameDirectory(ServiceCtx context)
  62. {
  63. string oldName = ReadUtf8String(context, 0);
  64. string newName = ReadUtf8String(context, 1);
  65. return (ResultCode)_fileSystem.RenameDirectory(oldName, newName).Value;
  66. }
  67. [Command(7)]
  68. // GetEntryType(buffer<bytes<0x301>, 0x19, 0x301> path) -> nn::fssrv::sf::DirectoryEntryType
  69. public ResultCode GetEntryType(ServiceCtx context)
  70. {
  71. string name = ReadUtf8String(context);
  72. Result result = _fileSystem.GetEntryType(out DirectoryEntryType entryType, name);
  73. context.ResponseData.Write((int)entryType);
  74. return (ResultCode)result.Value;
  75. }
  76. [Command(8)]
  77. // OpenFile(u32 mode, buffer<bytes<0x301>, 0x19, 0x301> path) -> object<nn::fssrv::sf::IFile> file
  78. public ResultCode OpenFile(ServiceCtx context)
  79. {
  80. OpenMode mode = (OpenMode)context.RequestData.ReadInt32();
  81. string name = ReadUtf8String(context);
  82. Result result = _fileSystem.OpenFile(out LibHac.Fs.IFile file, name, mode);
  83. if (result.IsSuccess())
  84. {
  85. IFile fileInterface = new IFile(file);
  86. MakeObject(context, fileInterface);
  87. }
  88. return (ResultCode)result.Value;
  89. }
  90. [Command(9)]
  91. // OpenDirectory(u32 filter_flags, buffer<bytes<0x301>, 0x19, 0x301> path) -> object<nn::fssrv::sf::IDirectory> directory
  92. public ResultCode OpenDirectory(ServiceCtx context)
  93. {
  94. OpenDirectoryMode mode = (OpenDirectoryMode)context.RequestData.ReadInt32();
  95. string name = ReadUtf8String(context);
  96. Result result = _fileSystem.OpenDirectory(out LibHac.Fs.IDirectory dir, name, mode);
  97. if (result.IsSuccess())
  98. {
  99. IDirectory dirInterface = new IDirectory(dir);
  100. MakeObject(context, dirInterface);
  101. }
  102. return (ResultCode)result.Value;
  103. }
  104. [Command(10)]
  105. // Commit()
  106. public ResultCode Commit(ServiceCtx context)
  107. {
  108. return (ResultCode)_fileSystem.Commit().Value;
  109. }
  110. [Command(11)]
  111. // GetFreeSpaceSize(buffer<bytes<0x301>, 0x19, 0x301> path) -> u64 totalFreeSpace
  112. public ResultCode GetFreeSpaceSize(ServiceCtx context)
  113. {
  114. string name = ReadUtf8String(context);
  115. Result result = _fileSystem.GetFreeSpaceSize(out long size, name);
  116. context.ResponseData.Write(size);
  117. return (ResultCode)result.Value;
  118. }
  119. [Command(12)]
  120. // GetTotalSpaceSize(buffer<bytes<0x301>, 0x19, 0x301> path) -> u64 totalSize
  121. public ResultCode GetTotalSpaceSize(ServiceCtx context)
  122. {
  123. string name = ReadUtf8String(context);
  124. Result result = _fileSystem.GetTotalSpaceSize(out long size, name);
  125. context.ResponseData.Write(size);
  126. return (ResultCode)result.Value;
  127. }
  128. [Command(13)]
  129. // CleanDirectoryRecursively(buffer<bytes<0x301>, 0x19, 0x301> path)
  130. public ResultCode CleanDirectoryRecursively(ServiceCtx context)
  131. {
  132. string name = ReadUtf8String(context);
  133. return (ResultCode)_fileSystem.CleanDirectoryRecursively(name).Value;
  134. }
  135. [Command(14)]
  136. // GetFileTimeStampRaw(buffer<bytes<0x301>, 0x19, 0x301> path) -> bytes<0x20> timestamp
  137. public ResultCode GetFileTimeStampRaw(ServiceCtx context)
  138. {
  139. string name = ReadUtf8String(context);
  140. Result result = _fileSystem.GetFileTimeStampRaw(out FileTimeStampRaw timestamp, name);
  141. context.ResponseData.Write(timestamp.Created);
  142. context.ResponseData.Write(timestamp.Modified);
  143. context.ResponseData.Write(timestamp.Accessed);
  144. byte[] data = new byte[8];
  145. // is valid?
  146. data[0] = 1;
  147. context.ResponseData.Write(data);
  148. return (ResultCode)result.Value;
  149. }
  150. }
  151. }