filesystem.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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/mode.h"
  9. #include "core/file_sys/romfs_factory.h"
  10. #include "core/file_sys/savedata_factory.h"
  11. #include "core/file_sys/sdmc_factory.h"
  12. #include "core/hle/result.h"
  13. namespace Service {
  14. namespace SM {
  15. class ServiceManager;
  16. } // namespace SM
  17. namespace FileSystem {
  18. ResultCode RegisterRomFS(std::unique_ptr<FileSys::RomFSFactory>&& factory);
  19. ResultCode RegisterSaveData(std::unique_ptr<FileSys::SaveDataFactory>&& factory);
  20. ResultCode RegisterSDMC(std::unique_ptr<FileSys::SDMCFactory>&& factory);
  21. // TODO(DarkLordZach): BIS Filesystem
  22. // ResultCode RegisterBIS(std::unique_ptr<FileSys::BISFactory>&& factory);
  23. ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id);
  24. ResultVal<FileSys::VirtualDir> OpenSaveData(FileSys::SaveDataSpaceId space,
  25. FileSys::SaveDataDescriptor save_struct);
  26. ResultVal<FileSys::VirtualDir> OpenSDMC();
  27. // TODO(DarkLordZach): BIS Filesystem
  28. // ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenBIS();
  29. /// Registers all Filesystem services with the specified service manager.
  30. void InstallInterfaces(SM::ServiceManager& service_manager);
  31. // A class that wraps a VfsDirectory with methods that return ResultVal and ResultCode instead of
  32. // pointers and booleans. This makes using a VfsDirectory with switch services much easier and
  33. // avoids repetitive code.
  34. class VfsDirectoryServiceWrapper {
  35. public:
  36. explicit VfsDirectoryServiceWrapper(FileSys::VirtualDir backing);
  37. /**
  38. * Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.)
  39. */
  40. std::string GetName() const;
  41. /**
  42. * Create a file specified by its path
  43. * @param path Path relative to the Archive
  44. * @param size The size of the new file, filled with zeroes
  45. * @return Result of the operation
  46. */
  47. ResultCode CreateFile(const std::string& path, u64 size) const;
  48. /**
  49. * Delete a file specified by its path
  50. * @param path Path relative to the archive
  51. * @return Result of the operation
  52. */
  53. ResultCode DeleteFile(const std::string& path) const;
  54. /**
  55. * Create a directory specified by its path
  56. * @param path Path relative to the archive
  57. * @return Result of the operation
  58. */
  59. ResultCode CreateDirectory(const std::string& path) const;
  60. /**
  61. * Delete a directory specified by its path
  62. * @param path Path relative to the archive
  63. * @return Result of the operation
  64. */
  65. ResultCode DeleteDirectory(const std::string& path) const;
  66. /**
  67. * Delete a directory specified by its path and anything under it
  68. * @param path Path relative to the archive
  69. * @return Result of the operation
  70. */
  71. ResultCode DeleteDirectoryRecursively(const std::string& path) const;
  72. /**
  73. * Rename a File specified by its path
  74. * @param src_path Source path relative to the archive
  75. * @param dest_path Destination path relative to the archive
  76. * @return Result of the operation
  77. */
  78. ResultCode RenameFile(const std::string& src_path, const std::string& dest_path) const;
  79. /**
  80. * Rename a Directory specified by its path
  81. * @param src_path Source path relative to the archive
  82. * @param dest_path Destination path relative to the archive
  83. * @return Result of the operation
  84. */
  85. ResultCode RenameDirectory(const std::string& src_path, const std::string& dest_path) const;
  86. /**
  87. * Open a file specified by its path, using the specified mode
  88. * @param path Path relative to the archive
  89. * @param mode Mode to open the file with
  90. * @return Opened file, or error code
  91. */
  92. ResultVal<FileSys::VirtualFile> OpenFile(const std::string& path, FileSys::Mode mode) const;
  93. /**
  94. * Open a directory specified by its path
  95. * @param path Path relative to the archive
  96. * @return Opened directory, or error code
  97. */
  98. ResultVal<FileSys::VirtualDir> OpenDirectory(const std::string& path);
  99. /**
  100. * Get the free space
  101. * @return The number of free bytes in the archive
  102. */
  103. u64 GetFreeSpaceSize() const;
  104. /**
  105. * Get the type of the specified path
  106. * @return The type of the specified path or error code
  107. */
  108. ResultVal<FileSys::EntryType> GetEntryType(const std::string& path) const;
  109. private:
  110. FileSys::VirtualDir backing;
  111. };
  112. } // namespace FileSystem
  113. } // namespace Service