filesystem.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 StorageId : u8;
  21. struct SaveDataDescriptor;
  22. } // namespace FileSys
  23. namespace Service {
  24. namespace SM {
  25. class ServiceManager;
  26. } // namespace SM
  27. namespace FileSystem {
  28. ResultCode RegisterRomFS(std::unique_ptr<FileSys::RomFSFactory>&& factory);
  29. ResultCode RegisterSaveData(std::unique_ptr<FileSys::SaveDataFactory>&& factory);
  30. ResultCode RegisterSDMC(std::unique_ptr<FileSys::SDMCFactory>&& factory);
  31. ResultCode RegisterBIS(std::unique_ptr<FileSys::BISFactory>&& factory);
  32. void SetPackedUpdate(FileSys::VirtualFile update_raw);
  33. ResultVal<FileSys::VirtualFile> OpenRomFSCurrentProcess();
  34. ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id, FileSys::StorageId storage_id,
  35. FileSys::ContentRecordType type);
  36. ResultVal<FileSys::VirtualDir> OpenSaveData(FileSys::SaveDataSpaceId space,
  37. FileSys::SaveDataDescriptor save_struct);
  38. ResultVal<FileSys::VirtualDir> OpenSaveDataSpace(FileSys::SaveDataSpaceId space);
  39. ResultVal<FileSys::VirtualDir> OpenSDMC();
  40. std::shared_ptr<FileSys::RegisteredCacheUnion> GetUnionContents();
  41. FileSys::RegisteredCache* GetSystemNANDContents();
  42. FileSys::RegisteredCache* GetUserNANDContents();
  43. FileSys::RegisteredCache* GetSDMCContents();
  44. FileSys::VirtualDir GetModificationLoadRoot(u64 title_id);
  45. FileSys::VirtualDir GetModificationDumpRoot(u64 title_id);
  46. // Creates the SaveData, SDMC, and BIS Factories. Should be called once and before any function
  47. // above is called.
  48. void CreateFactories(FileSys::VfsFilesystem& vfs, bool overwrite = true);
  49. void InstallInterfaces(SM::ServiceManager& service_manager, FileSys::VfsFilesystem& vfs);
  50. // A class that wraps a VfsDirectory with methods that return ResultVal and ResultCode instead of
  51. // pointers and booleans. This makes using a VfsDirectory with switch services much easier and
  52. // avoids repetitive code.
  53. class VfsDirectoryServiceWrapper {
  54. public:
  55. explicit VfsDirectoryServiceWrapper(FileSys::VirtualDir backing);
  56. ~VfsDirectoryServiceWrapper();
  57. /**
  58. * Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.)
  59. */
  60. std::string GetName() const;
  61. /**
  62. * Create a file specified by its path
  63. * @param path Path relative to the Archive
  64. * @param size The size of the new file, filled with zeroes
  65. * @return Result of the operation
  66. */
  67. ResultCode CreateFile(const std::string& path, u64 size) const;
  68. /**
  69. * Delete a file specified by its path
  70. * @param path Path relative to the archive
  71. * @return Result of the operation
  72. */
  73. ResultCode DeleteFile(const std::string& path) const;
  74. /**
  75. * Create a directory specified by its path
  76. * @param path Path relative to the archive
  77. * @return Result of the operation
  78. */
  79. ResultCode CreateDirectory(const std::string& path) const;
  80. /**
  81. * Delete a directory specified by its path
  82. * @param path Path relative to the archive
  83. * @return Result of the operation
  84. */
  85. ResultCode DeleteDirectory(const std::string& path) const;
  86. /**
  87. * Delete a directory specified by its path and anything under it
  88. * @param path Path relative to the archive
  89. * @return Result of the operation
  90. */
  91. ResultCode DeleteDirectoryRecursively(const std::string& path) const;
  92. /**
  93. * Rename a File specified by its path
  94. * @param src_path Source path relative to the archive
  95. * @param dest_path Destination path relative to the archive
  96. * @return Result of the operation
  97. */
  98. ResultCode RenameFile(const std::string& src_path, const std::string& dest_path) const;
  99. /**
  100. * Rename a Directory specified by its path
  101. * @param src_path Source path relative to the archive
  102. * @param dest_path Destination path relative to the archive
  103. * @return Result of the operation
  104. */
  105. ResultCode RenameDirectory(const std::string& src_path, const std::string& dest_path) const;
  106. /**
  107. * Open a file specified by its path, using the specified mode
  108. * @param path Path relative to the archive
  109. * @param mode Mode to open the file with
  110. * @return Opened file, or error code
  111. */
  112. ResultVal<FileSys::VirtualFile> OpenFile(const std::string& path, FileSys::Mode mode) const;
  113. /**
  114. * Open a directory specified by its path
  115. * @param path Path relative to the archive
  116. * @return Opened directory, or error code
  117. */
  118. ResultVal<FileSys::VirtualDir> OpenDirectory(const std::string& path);
  119. /**
  120. * Get the free space
  121. * @return The number of free bytes in the archive
  122. */
  123. u64 GetFreeSpaceSize() const;
  124. /**
  125. * Get the type of the specified path
  126. * @return The type of the specified path or error code
  127. */
  128. ResultVal<FileSys::EntryType> GetEntryType(const std::string& path) const;
  129. private:
  130. FileSys::VirtualDir backing;
  131. };
  132. } // namespace FileSystem
  133. } // namespace Service