directory.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <cstddef>
  6. #include <iterator>
  7. #include <string_view>
  8. #include "common/common_funcs.h"
  9. #include "common/common_types.h"
  10. ////////////////////////////////////////////////////////////////////////////////////////////////////
  11. // FileSys namespace
  12. namespace FileSys {
  13. enum EntryType : u8 {
  14. Directory = 0,
  15. File = 1,
  16. };
  17. // Structure of a directory entry, from
  18. // http://switchbrew.org/index.php?title=Filesystem_services#DirectoryEntry
  19. struct Entry {
  20. Entry(std::string_view view, EntryType entry_type, u64 entry_size)
  21. : type{entry_type}, file_size{entry_size} {
  22. const std::size_t copy_size = view.copy(filename, std::size(filename) - 1);
  23. filename[copy_size] = '\0';
  24. }
  25. char filename[0x300];
  26. INSERT_PADDING_BYTES(4);
  27. EntryType type;
  28. INSERT_PADDING_BYTES(3);
  29. u64 file_size;
  30. };
  31. static_assert(sizeof(Entry) == 0x310, "Directory Entry struct isn't exactly 0x310 bytes long!");
  32. static_assert(offsetof(Entry, type) == 0x304, "Wrong offset for type in Entry.");
  33. static_assert(offsetof(Entry, file_size) == 0x308, "Wrong offset for file_size in Entry.");
  34. class DirectoryBackend : NonCopyable {
  35. public:
  36. DirectoryBackend() {}
  37. virtual ~DirectoryBackend() {}
  38. /**
  39. * List files contained in the directory
  40. * @param count Number of entries to return at once in entries
  41. * @param entries Buffer to read data into
  42. * @return Number of entries listed
  43. */
  44. virtual u64 Read(const u64 count, Entry* entries) = 0;
  45. /// Returns the number of entries still left to read.
  46. virtual u64 GetEntryCount() const = 0;
  47. /**
  48. * Close the directory
  49. * @return true if the directory closed correctly
  50. */
  51. virtual bool Close() const = 0;
  52. };
  53. } // namespace FileSys