file_backend.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "common/common_types.h"
  6. #include "core/hle/kernel/kernel.h"
  7. ////////////////////////////////////////////////////////////////////////////////////////////////////
  8. // FileSys namespace
  9. namespace FileSys {
  10. class FileBackend : NonCopyable {
  11. public:
  12. FileBackend() { }
  13. virtual ~FileBackend() { }
  14. /**
  15. * Open the file
  16. * @return true if the file opened correctly
  17. */
  18. virtual bool Open() = 0;
  19. /**
  20. * Read data from the file
  21. * @param offset Offset in bytes to start reading data from
  22. * @param length Length in bytes of data to read from file
  23. * @param buffer Buffer to read data into
  24. * @return Number of bytes read
  25. */
  26. virtual size_t Read(const u64 offset, const u32 length, u8* buffer) const = 0;
  27. /**
  28. * Write data to the file
  29. * @param offset Offset in bytes to start writing data to
  30. * @param length Length in bytes of data to write to file
  31. * @param flush The flush parameters (0 == do not flush)
  32. * @param buffer Buffer to read data from
  33. * @return Number of bytes written
  34. */
  35. virtual size_t Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const = 0;
  36. /**
  37. * Get the size of the file in bytes
  38. * @return Size of the file in bytes
  39. */
  40. virtual size_t GetSize() const = 0;
  41. /**
  42. * Set the size of the file in bytes
  43. * @param size New size of the file
  44. * @return true if successful
  45. */
  46. virtual bool SetSize(const u64 size) const = 0;
  47. /**
  48. * Close the file
  49. * @return true if the file closed correctly
  50. */
  51. virtual bool Close() const = 0;
  52. /**
  53. * Flushes the file
  54. */
  55. virtual void Flush() const = 0;
  56. };
  57. } // namespace FileSys