partition_filesystem.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <array>
  6. #include <string>
  7. #include <vector>
  8. #include "common/common_funcs.h"
  9. #include "common/common_types.h"
  10. #include "common/swap.h"
  11. #include "core/file_sys/vfs.h"
  12. namespace Loader {
  13. enum class ResultStatus : u16;
  14. }
  15. namespace FileSys {
  16. /**
  17. * Helper which implements an interface to parse PFS/HFS filesystems.
  18. * Data can either be loaded from a file path or data with an offset into it.
  19. */
  20. class PartitionFilesystem : public ReadOnlyVfsDirectory {
  21. public:
  22. explicit PartitionFilesystem(std::shared_ptr<VfsFile> file);
  23. Loader::ResultStatus GetStatus() const;
  24. std::vector<std::shared_ptr<VfsFile>> GetFiles() const override;
  25. std::vector<std::shared_ptr<VfsDirectory>> GetSubdirectories() const override;
  26. std::string GetName() const override;
  27. std::shared_ptr<VfsDirectory> GetParentDirectory() const override;
  28. void PrintDebugInfo() const;
  29. protected:
  30. bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override;
  31. private:
  32. struct Header {
  33. u32_le magic;
  34. u32_le num_entries;
  35. u32_le strtab_size;
  36. INSERT_PADDING_BYTES(0x4);
  37. bool HasValidMagicValue() const;
  38. };
  39. static_assert(sizeof(Header) == 0x10, "PFS/HFS header structure size is wrong");
  40. #pragma pack(push, 1)
  41. struct FSEntry {
  42. u64_le offset;
  43. u64_le size;
  44. u32_le strtab_offset;
  45. };
  46. static_assert(sizeof(FSEntry) == 0x14, "FS entry structure size is wrong");
  47. struct PFSEntry {
  48. FSEntry fs_entry;
  49. INSERT_PADDING_BYTES(0x4);
  50. };
  51. static_assert(sizeof(PFSEntry) == 0x18, "PFS entry structure size is wrong");
  52. struct HFSEntry {
  53. FSEntry fs_entry;
  54. u32_le hash_region_size;
  55. INSERT_PADDING_BYTES(0x8);
  56. std::array<char, 0x20> hash;
  57. };
  58. static_assert(sizeof(HFSEntry) == 0x40, "HFS entry structure size is wrong");
  59. #pragma pack(pop)
  60. Loader::ResultStatus status{};
  61. Header pfs_header{};
  62. bool is_hfs = false;
  63. size_t content_offset = 0;
  64. std::vector<VirtualFile> pfs_files;
  65. std::vector<VirtualDir> pfs_dirs;
  66. };
  67. } // namespace FileSys