file_backend.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. * Read data from the file
  17. * @param offset Offset in bytes to start reading data from
  18. * @param length Length in bytes of data to read from file
  19. * @param buffer Buffer to read data into
  20. * @return Number of bytes read, or error code
  21. */
  22. virtual ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const = 0;
  23. /**
  24. * Write data to the file
  25. * @param offset Offset in bytes to start writing data to
  26. * @param length Length in bytes of data to write to file
  27. * @param flush The flush parameters (0 == do not flush)
  28. * @param buffer Buffer to read data from
  29. * @return Number of bytes written, or error code
  30. */
  31. virtual ResultVal<size_t> Write(u64 offset, size_t length, bool flush,
  32. const u8* buffer) const = 0;
  33. /**
  34. * Get the size of the file in bytes
  35. * @return Size of the file in bytes
  36. */
  37. virtual u64 GetSize() const = 0;
  38. /**
  39. * Set the size of the file in bytes
  40. * @param size New size of the file
  41. * @return true if successful
  42. */
  43. virtual bool SetSize(u64 size) const = 0;
  44. /**
  45. * Close the file
  46. * @return true if the file closed correctly
  47. */
  48. virtual bool Close() const = 0;
  49. /**
  50. * Flushes the file
  51. */
  52. virtual void Flush() const = 0;
  53. };
  54. } // namespace FileSys