romfs_filesystem.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 Path& 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 Path& path) const override;
  34. ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override;
  35. ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override;
  36. u64 GetFreeSpaceSize() const override;
  37. ResultVal<EntryType> GetEntryType(const std::string& path) const override;
  38. protected:
  39. std::shared_ptr<FileUtil::IOFile> romfs_file;
  40. u64 data_offset;
  41. u64 data_size;
  42. };
  43. class RomFS_Storage : public StorageBackend {
  44. public:
  45. RomFS_Storage(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size)
  46. : romfs_file(file), data_offset(offset), data_size(size) {}
  47. ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override;
  48. ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) const override;
  49. u64 GetSize() const override;
  50. bool SetSize(u64 size) const override;
  51. bool Close() const override {
  52. return false;
  53. }
  54. void Flush() const override {}
  55. private:
  56. std::shared_ptr<FileUtil::IOFile> romfs_file;
  57. u64 data_offset;
  58. u64 data_size;
  59. };
  60. class ROMFSDirectory : public DirectoryBackend {
  61. public:
  62. u32 Read(const u32 count, Entry* entries) override {
  63. return 0;
  64. }
  65. bool Close() const override {
  66. return false;
  67. }
  68. };
  69. } // namespace FileSys