filesystem.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <memory>
  6. #include "common/common_types.h"
  7. #include "core/file_sys/directory.h"
  8. #include "core/file_sys/vfs.h"
  9. #include "core/hle/result.h"
  10. namespace FileSys {
  11. class BISFactory;
  12. class RegisteredCache;
  13. class RegisteredCacheUnion;
  14. class RomFSFactory;
  15. class SaveDataFactory;
  16. class SDMCFactory;
  17. enum class ContentRecordType : u8;
  18. enum class Mode : u32;
  19. enum class SaveDataSpaceId : u8;
  20. enum class SaveDataType : u8;
  21. enum class StorageId : u8;
  22. struct SaveDataDescriptor;
  23. struct SaveDataSize;
  24. } // namespace FileSys
  25. namespace Service {
  26. namespace SM {
  27. class ServiceManager;
  28. } // namespace SM
  29. namespace FileSystem {
  30. ResultCode RegisterRomFS(std::unique_ptr<FileSys::RomFSFactory>&& factory);
  31. ResultCode RegisterSaveData(std::unique_ptr<FileSys::SaveDataFactory>&& factory);
  32. ResultCode RegisterSDMC(std::unique_ptr<FileSys::SDMCFactory>&& factory);
  33. ResultCode RegisterBIS(std::unique_ptr<FileSys::BISFactory>&& factory);
  34. void SetPackedUpdate(FileSys::VirtualFile update_raw);
  35. ResultVal<FileSys::VirtualFile> OpenRomFSCurrentProcess();
  36. ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id, FileSys::StorageId storage_id,
  37. FileSys::ContentRecordType type);
  38. ResultVal<FileSys::VirtualDir> OpenSaveData(FileSys::SaveDataSpaceId space,
  39. const FileSys::SaveDataDescriptor& descriptor);
  40. ResultVal<FileSys::VirtualDir> OpenSaveDataSpace(FileSys::SaveDataSpaceId space);
  41. ResultVal<FileSys::VirtualDir> OpenSDMC();
  42. FileSys::SaveDataSize ReadSaveDataSize(FileSys::SaveDataType type, u64 title_id, u128 user_id);
  43. void WriteSaveDataSize(FileSys::SaveDataType type, u64 title_id, u128 user_id,
  44. FileSys::SaveDataSize new_value);
  45. FileSys::RegisteredCache* GetSystemNANDContents();
  46. FileSys::RegisteredCache* GetUserNANDContents();
  47. FileSys::RegisteredCache* GetSDMCContents();
  48. FileSys::VirtualDir GetModificationLoadRoot(u64 title_id);
  49. FileSys::VirtualDir GetModificationDumpRoot(u64 title_id);
  50. // Creates the SaveData, SDMC, and BIS Factories. Should be called once and before any function
  51. // above is called.
  52. void CreateFactories(FileSys::VfsFilesystem& vfs, bool overwrite = true);
  53. void InstallInterfaces(Core::System& system);
  54. // A class that wraps a VfsDirectory with methods that return ResultVal and ResultCode instead of
  55. // pointers and booleans. This makes using a VfsDirectory with switch services much easier and
  56. // avoids repetitive code.
  57. class VfsDirectoryServiceWrapper {
  58. public:
  59. explicit VfsDirectoryServiceWrapper(FileSys::VirtualDir backing);
  60. ~VfsDirectoryServiceWrapper();
  61. /**
  62. * Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.)
  63. */
  64. std::string GetName() const;
  65. /**
  66. * Create a file specified by its path
  67. * @param path Path relative to the Archive
  68. * @param size The size of the new file, filled with zeroes
  69. * @return Result of the operation
  70. */
  71. ResultCode CreateFile(const std::string& path, u64 size) const;
  72. /**
  73. * Delete a file specified by its path
  74. * @param path Path relative to the archive
  75. * @return Result of the operation
  76. */
  77. ResultCode DeleteFile(const std::string& path) const;
  78. /**
  79. * Create a directory specified by its path
  80. * @param path Path relative to the archive
  81. * @return Result of the operation
  82. */
  83. ResultCode CreateDirectory(const std::string& path) const;
  84. /**
  85. * Delete a directory specified by its path
  86. * @param path Path relative to the archive
  87. * @return Result of the operation
  88. */
  89. ResultCode DeleteDirectory(const std::string& path) const;
  90. /**
  91. * Delete a directory specified by its path and anything under it
  92. * @param path Path relative to the archive
  93. * @return Result of the operation
  94. */
  95. ResultCode DeleteDirectoryRecursively(const std::string& path) const;
  96. /**
  97. * Cleans the specified directory. This is similar to DeleteDirectoryRecursively,
  98. * in that it deletes all the contents of the specified directory, however, this
  99. * function does *not* delete the directory itself. It only deletes everything
  100. * within it.
  101. *
  102. * @param path Path relative to the archive.
  103. *
  104. * @return Result of the operation.
  105. */
  106. ResultCode CleanDirectoryRecursively(const std::string& path) const;
  107. /**
  108. * Rename a File specified by its path
  109. * @param src_path Source path relative to the archive
  110. * @param dest_path Destination path relative to the archive
  111. * @return Result of the operation
  112. */
  113. ResultCode RenameFile(const std::string& src_path, const std::string& dest_path) const;
  114. /**
  115. * Rename a Directory specified by its path
  116. * @param src_path Source path relative to the archive
  117. * @param dest_path Destination path relative to the archive
  118. * @return Result of the operation
  119. */
  120. ResultCode RenameDirectory(const std::string& src_path, const std::string& dest_path) const;
  121. /**
  122. * Open a file specified by its path, using the specified mode
  123. * @param path Path relative to the archive
  124. * @param mode Mode to open the file with
  125. * @return Opened file, or error code
  126. */
  127. ResultVal<FileSys::VirtualFile> OpenFile(const std::string& path, FileSys::Mode mode) const;
  128. /**
  129. * Open a directory specified by its path
  130. * @param path Path relative to the archive
  131. * @return Opened directory, or error code
  132. */
  133. ResultVal<FileSys::VirtualDir> OpenDirectory(const std::string& path);
  134. /**
  135. * Get the free space
  136. * @return The number of free bytes in the archive
  137. */
  138. u64 GetFreeSpaceSize() const;
  139. /**
  140. * Get the type of the specified path
  141. * @return The type of the specified path or error code
  142. */
  143. ResultVal<FileSys::EntryType> GetEntryType(const std::string& path) const;
  144. private:
  145. FileSys::VirtualDir backing;
  146. };
  147. } // namespace FileSystem
  148. } // namespace Service