romfs_archive.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <cstring>
  5. #include <memory>
  6. #include "common/common_types.h"
  7. #include "common/logging/log.h"
  8. #include "core/file_sys/romfs_archive.h"
  9. namespace FileSys {
  10. std::string ROMFSArchive::GetName() const {
  11. return "RomFS";
  12. }
  13. ResultVal<std::unique_ptr<FileBackend>> ROMFSArchive::OpenFile(const Path& path,
  14. const Mode& mode) const {
  15. return MakeResult<std::unique_ptr<FileBackend>>(
  16. std::make_unique<ROMFSFile>(romfs_file, data_offset, data_size));
  17. }
  18. ResultCode ROMFSArchive::DeleteFile(const Path& path) const {
  19. LOG_CRITICAL(Service_FS, "Attempted to delete a file from an ROMFS archive (%s).",
  20. GetName().c_str());
  21. // TODO(bunnei): Use correct error code
  22. return ResultCode(-1);
  23. }
  24. ResultCode ROMFSArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
  25. LOG_CRITICAL(Service_FS, "Attempted to rename a file within an ROMFS archive (%s).",
  26. GetName().c_str());
  27. // TODO(wwylele): Use correct error code
  28. return ResultCode(-1);
  29. }
  30. ResultCode ROMFSArchive::DeleteDirectory(const Path& path) const {
  31. LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an ROMFS archive (%s).",
  32. GetName().c_str());
  33. // TODO(wwylele): Use correct error code
  34. return ResultCode(-1);
  35. }
  36. ResultCode ROMFSArchive::DeleteDirectoryRecursively(const Path& path) const {
  37. LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an ROMFS archive (%s).",
  38. GetName().c_str());
  39. // TODO(wwylele): Use correct error code
  40. return ResultCode(-1);
  41. }
  42. ResultCode ROMFSArchive::CreateFile(const Path& path, u64 size) const {
  43. LOG_CRITICAL(Service_FS, "Attempted to create a file in an ROMFS archive (%s).",
  44. GetName().c_str());
  45. // TODO(bunnei): Use correct error code
  46. return ResultCode(-1);
  47. }
  48. ResultCode ROMFSArchive::CreateDirectory(const Path& path) const {
  49. LOG_CRITICAL(Service_FS, "Attempted to create a directory in an ROMFS archive (%s).",
  50. GetName().c_str());
  51. // TODO(wwylele): Use correct error code
  52. return ResultCode(-1);
  53. }
  54. ResultCode ROMFSArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
  55. LOG_CRITICAL(Service_FS, "Attempted to rename a file within an ROMFS archive (%s).",
  56. GetName().c_str());
  57. // TODO(wwylele): Use correct error code
  58. return ResultCode(-1);
  59. }
  60. ResultVal<std::unique_ptr<DirectoryBackend>> ROMFSArchive::OpenDirectory(const Path& path) const {
  61. return MakeResult<std::unique_ptr<DirectoryBackend>>(std::make_unique<ROMFSDirectory>());
  62. }
  63. u64 ROMFSArchive::GetFreeSpaceSize() const {
  64. LOG_WARNING(Service_FS, "Attempted to get the free space in an ROMFS archive");
  65. return 0;
  66. }
  67. ResultVal<size_t> ROMFSFile::Read(const u64 offset, const size_t length, u8* buffer) const {
  68. LOG_TRACE(Service_FS, "called offset=%llu, length=%zu", offset, length);
  69. romfs_file->Seek(data_offset + offset, SEEK_SET);
  70. size_t read_length = (size_t)std::min((u64)length, data_size - offset);
  71. return MakeResult<size_t>(romfs_file->ReadBytes(buffer, read_length));
  72. }
  73. ResultVal<size_t> ROMFSFile::Write(const u64 offset, const size_t length, const bool flush,
  74. const u8* buffer) const {
  75. LOG_ERROR(Service_FS, "Attempted to write to ROMFS file");
  76. // TODO(Subv): Find error code
  77. return MakeResult<size_t>(0);
  78. }
  79. u64 ROMFSFile::GetSize() const {
  80. return data_size;
  81. }
  82. bool ROMFSFile::SetSize(const u64 size) const {
  83. LOG_ERROR(Service_FS, "Attempted to set the size of an ROMFS file");
  84. return false;
  85. }
  86. } // namespace FileSys