ivfc_archive.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright 2014 Citra Emulator Project
  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/ivfc_archive.h"
  9. ////////////////////////////////////////////////////////////////////////////////////////////////////
  10. // FileSys namespace
  11. namespace FileSys {
  12. std::string IVFCArchive::GetName() const {
  13. return "IVFC";
  14. }
  15. ResultVal<std::unique_ptr<FileBackend>> IVFCArchive::OpenFile(const Path& path,
  16. const Mode& mode) const {
  17. return MakeResult<std::unique_ptr<FileBackend>>(
  18. std::make_unique<IVFCFile>(romfs_file, data_offset, data_size));
  19. }
  20. ResultCode IVFCArchive::DeleteFile(const Path& path) const {
  21. LOG_CRITICAL(Service_FS, "Attempted to delete a file from an IVFC archive (%s).",
  22. GetName().c_str());
  23. // TODO(Subv): Verify error code
  24. return ResultCode(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled,
  25. ErrorLevel::Status);
  26. }
  27. ResultCode IVFCArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
  28. LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive (%s).",
  29. GetName().c_str());
  30. // TODO(wwylele): Use correct error code
  31. return ResultCode(-1);
  32. }
  33. ResultCode IVFCArchive::DeleteDirectory(const Path& path) const {
  34. LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive (%s).",
  35. GetName().c_str());
  36. // TODO(wwylele): Use correct error code
  37. return ResultCode(-1);
  38. }
  39. ResultCode IVFCArchive::DeleteDirectoryRecursively(const Path& path) const {
  40. LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive (%s).",
  41. GetName().c_str());
  42. // TODO(wwylele): Use correct error code
  43. return ResultCode(-1);
  44. }
  45. ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const {
  46. LOG_CRITICAL(Service_FS, "Attempted to create a file in an IVFC archive (%s).",
  47. GetName().c_str());
  48. // TODO: Verify error code
  49. return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported,
  50. ErrorLevel::Permanent);
  51. }
  52. ResultCode IVFCArchive::CreateDirectory(const Path& path) const {
  53. LOG_CRITICAL(Service_FS, "Attempted to create a directory in an IVFC archive (%s).",
  54. GetName().c_str());
  55. // TODO(wwylele): Use correct error code
  56. return ResultCode(-1);
  57. }
  58. ResultCode IVFCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
  59. LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive (%s).",
  60. GetName().c_str());
  61. // TODO(wwylele): Use correct error code
  62. return ResultCode(-1);
  63. }
  64. ResultVal<std::unique_ptr<DirectoryBackend>> IVFCArchive::OpenDirectory(const Path& path) const {
  65. return MakeResult<std::unique_ptr<DirectoryBackend>>(std::make_unique<IVFCDirectory>());
  66. }
  67. u64 IVFCArchive::GetFreeBytes() const {
  68. LOG_WARNING(Service_FS, "Attempted to get the free space in an IVFC archive");
  69. return 0;
  70. }
  71. ////////////////////////////////////////////////////////////////////////////////////////////////////
  72. ResultVal<size_t> IVFCFile::Read(const u64 offset, const size_t length, u8* buffer) const {
  73. LOG_TRACE(Service_FS, "called offset=%llu, length=%zu", offset, length);
  74. romfs_file->Seek(data_offset + offset, SEEK_SET);
  75. size_t read_length = (size_t)std::min((u64)length, data_size - offset);
  76. return MakeResult<size_t>(romfs_file->ReadBytes(buffer, read_length));
  77. }
  78. ResultVal<size_t> IVFCFile::Write(const u64 offset, const size_t length, const bool flush,
  79. const u8* buffer) const {
  80. LOG_ERROR(Service_FS, "Attempted to write to IVFC file");
  81. // TODO(Subv): Find error code
  82. return MakeResult<size_t>(0);
  83. }
  84. u64 IVFCFile::GetSize() const {
  85. return data_size;
  86. }
  87. bool IVFCFile::SetSize(const u64 size) const {
  88. LOG_ERROR(Service_FS, "Attempted to set the size of an IVFC file");
  89. return false;
  90. }
  91. } // namespace FileSys