filesystem.h 5.4 KB

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