filesystem.h 5.3 KB

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