romfs_filesystem.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <cstddef>
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "common/common_types.h"
  10. #include "common/file_util.h"
  11. #include "core/file_sys/directory.h"
  12. #include "core/file_sys/filesystem.h"
  13. #include "core/file_sys/storage.h"
  14. #include "core/hle/result.h"
  15. namespace FileSys {
  16. /**
  17. * Helper which implements an interface to deal with Switch .istorage ROMFS images used in some
  18. * archives This should be subclassed by concrete archive types, which will provide the input data
  19. * (load the raw ROMFS archive) and override any required methods
  20. */
  21. class RomFS_FileSystem : public FileSystemBackend {
  22. public:
  23. RomFS_FileSystem(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size)
  24. : romfs_file(file), data_offset(offset), data_size(size) {}
  25. std::string GetName() const override;
  26. ResultVal<std::unique_ptr<StorageBackend>> OpenFile(const std::string& path,
  27. Mode mode) const override;
  28. ResultCode DeleteFile(const std::string& path) const override;
  29. ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override;
  30. ResultCode DeleteDirectory(const Path& path) const override;
  31. ResultCode DeleteDirectoryRecursively(const Path& path) const override;
  32. ResultCode CreateFile(const std::string& path, u64 size) const override;
  33. ResultCode CreateDirectory(const std::string& path) const override;
  34. ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override;
  35. ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(
  36. const std::string& path) const override;
  37. u64 GetFreeSpaceSize() const override;
  38. ResultVal<EntryType> GetEntryType(const std::string& path) const override;
  39. protected:
  40. std::shared_ptr<FileUtil::IOFile> romfs_file;
  41. u64 data_offset;
  42. u64 data_size;
  43. };
  44. class RomFS_Storage : public StorageBackend {
  45. public:
  46. RomFS_Storage(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size)
  47. : romfs_file(file), data_offset(offset), data_size(size) {}
  48. ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override;
  49. ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) const override;
  50. u64 GetSize() const override;
  51. bool SetSize(u64 size) const override;
  52. bool Close() const override {
  53. return false;
  54. }
  55. void Flush() const override {}
  56. private:
  57. std::shared_ptr<FileUtil::IOFile> romfs_file;
  58. u64 data_offset;
  59. u64 data_size;
  60. };
  61. class ROMFSDirectory : public DirectoryBackend {
  62. public:
  63. u64 Read(const u64 count, Entry* entries) override {
  64. return 0;
  65. }
  66. u64 GetEntryCount() const override {
  67. return 0;
  68. }
  69. bool Close() const override {
  70. return false;
  71. }
  72. };
  73. } // namespace FileSys