file_backend.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <cstddef>
  6. #include "common/common_types.h"
  7. #include "core/hle/result.h"
  8. ////////////////////////////////////////////////////////////////////////////////////////////////////
  9. // FileSys namespace
  10. namespace FileSys {
  11. class FileBackend : NonCopyable {
  12. public:
  13. FileBackend() { }
  14. virtual ~FileBackend() { }
  15. /**
  16. * Open the file
  17. * @return true if the file opened correctly
  18. */
  19. virtual bool Open() = 0;
  20. /**
  21. * Read data from the file
  22. * @param offset Offset in bytes to start reading data from
  23. * @param length Length in bytes of data to read from file
  24. * @param buffer Buffer to read data into
  25. * @return Number of bytes read, or error code
  26. */
  27. virtual ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const = 0;
  28. /**
  29. * Write data to the file
  30. * @param offset Offset in bytes to start writing data to
  31. * @param length Length in bytes of data to write to file
  32. * @param flush The flush parameters (0 == do not flush)
  33. * @param buffer Buffer to read data from
  34. * @return Number of bytes written, or error code
  35. */
  36. virtual ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) const = 0;
  37. /**
  38. * Get the size of the file in bytes
  39. * @return Size of the file in bytes
  40. */
  41. virtual u64 GetSize() const = 0;
  42. /**
  43. * Set the size of the file in bytes
  44. * @param size New size of the file
  45. * @return true if successful
  46. */
  47. virtual bool SetSize(u64 size) const = 0;
  48. /**
  49. * Close the file
  50. * @return true if the file closed correctly
  51. */
  52. virtual bool Close() const = 0;
  53. /**
  54. * Flushes the file
  55. */
  56. virtual void Flush() const = 0;
  57. };
  58. } // namespace FileSys