directory_backend.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <cstddef>
  6. #include "common/common_types.h"
  7. #include "core/hle/kernel/kernel.h"
  8. ////////////////////////////////////////////////////////////////////////////////////////////////////
  9. // FileSys namespace
  10. namespace FileSys {
  11. // Structure of a directory entry, from http://3dbrew.org/wiki/FSDir:Read#Entry_format
  12. const size_t FILENAME_LENGTH = 0x20C / 2;
  13. struct Entry {
  14. char16_t filename[FILENAME_LENGTH]; // Entry name (UTF-16, null-terminated)
  15. std::array<char, 9> short_name; // 8.3 file name ('longfilename' -> 'LONGFI~1', null-terminated)
  16. char unknown1; // unknown (observed values: 0x0A, 0x70, 0xFD)
  17. std::array<char, 4> extension; // 8.3 file extension (set to spaces for directories, null-terminated)
  18. char unknown2; // unknown (always 0x01)
  19. char unknown3; // unknown (0x00 or 0x08)
  20. char is_directory; // directory flag
  21. char is_hidden; // hidden flag
  22. char is_archive; // archive flag
  23. char is_read_only; // read-only flag
  24. u64 file_size; // file size (for files only)
  25. };
  26. static_assert(sizeof(Entry) == 0x228, "Directory Entry struct isn't exactly 0x228 bytes long!");
  27. static_assert(offsetof(Entry, short_name) == 0x20C, "Wrong offset for short_name in Entry.");
  28. static_assert(offsetof(Entry, extension) == 0x216, "Wrong offset for extension in Entry.");
  29. static_assert(offsetof(Entry, is_archive) == 0x21E, "Wrong offset for is_archive in Entry.");
  30. static_assert(offsetof(Entry, file_size) == 0x220, "Wrong offset for file_size in Entry.");
  31. class DirectoryBackend : NonCopyable {
  32. public:
  33. DirectoryBackend() { }
  34. virtual ~DirectoryBackend() { }
  35. /**
  36. * Open the directory
  37. * @return true if the directory opened correctly
  38. */
  39. virtual bool Open() = 0;
  40. /**
  41. * List files contained in the directory
  42. * @param count Number of entries to return at once in entries
  43. * @param entries Buffer to read data into
  44. * @return Number of entries listed
  45. */
  46. virtual u32 Read(const u32 count, Entry* entries) = 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