romfs_filesystem.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_filesystem.h"
  9. namespace FileSys {
  10. std::string RomFS_FileSystem::GetName() const {
  11. return "RomFS";
  12. }
  13. ResultVal<std::unique_ptr<StorageBackend>> RomFS_FileSystem::OpenFile(const std::string& path,
  14. Mode mode) const {
  15. return MakeResult<std::unique_ptr<StorageBackend>>(
  16. std::make_unique<RomFS_Storage>(romfs_file, data_offset, data_size));
  17. }
  18. ResultCode RomFS_FileSystem::DeleteFile(const std::string& 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 RomFS_FileSystem::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 RomFS_FileSystem::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 RomFS_FileSystem::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 RomFS_FileSystem::CreateFile(const std::string& 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 RomFS_FileSystem::CreateDirectory(const std::string& 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 RomFS_FileSystem::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>> RomFS_FileSystem::OpenDirectory(
  61. const std::string& path) const {
  62. LOG_WARNING(Service_FS, "Opening Directory in a ROMFS archive");
  63. return MakeResult<std::unique_ptr<DirectoryBackend>>(std::make_unique<ROMFSDirectory>());
  64. }
  65. u64 RomFS_FileSystem::GetFreeSpaceSize() const {
  66. LOG_WARNING(Service_FS, "Attempted to get the free space in an ROMFS archive");
  67. return 0;
  68. }
  69. ResultVal<FileSys::EntryType> RomFS_FileSystem::GetEntryType(const std::string& path) const {
  70. LOG_CRITICAL(Service_FS, "Called within an ROMFS archive (path %s).", path.c_str());
  71. // TODO(wwylele): Use correct error code
  72. return ResultCode(-1);
  73. }
  74. ResultVal<size_t> RomFS_Storage::Read(const u64 offset, const size_t length, u8* buffer) const {
  75. LOG_TRACE(Service_FS, "called offset=%llu, length=%zu", offset, length);
  76. romfs_file->Seek(data_offset + offset, SEEK_SET);
  77. size_t read_length = (size_t)std::min((u64)length, data_size - offset);
  78. return MakeResult<size_t>(romfs_file->ReadBytes(buffer, read_length));
  79. }
  80. ResultVal<size_t> RomFS_Storage::Write(const u64 offset, const size_t length, const bool flush,
  81. const u8* buffer) const {
  82. LOG_ERROR(Service_FS, "Attempted to write to ROMFS file");
  83. // TODO(Subv): Find error code
  84. return MakeResult<size_t>(0);
  85. }
  86. u64 RomFS_Storage::GetSize() const {
  87. return data_size;
  88. }
  89. bool RomFS_Storage::SetSize(const u64 size) const {
  90. LOG_ERROR(Service_FS, "Attempted to set the size of an ROMFS file");
  91. return false;
  92. }
  93. } // namespace FileSys