partition_filesystem.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. ~PartitionFilesystem() override;
  24. Loader::ResultStatus GetStatus() const;
  25. std::map<std::string, u64> GetFileOffsets() const;
  26. std::map<std::string, u64> GetFileSizes() const;
  27. std::vector<std::shared_ptr<VfsFile>> GetFiles() const override;
  28. std::vector<std::shared_ptr<VfsDirectory>> GetSubdirectories() const override;
  29. std::string GetName() const override;
  30. std::shared_ptr<VfsDirectory> GetParentDirectory() const override;
  31. void PrintDebugInfo() const;
  32. private:
  33. struct Header {
  34. u32_le magic;
  35. u32_le num_entries;
  36. u32_le strtab_size;
  37. INSERT_PADDING_BYTES(0x4);
  38. bool HasValidMagicValue() const;
  39. };
  40. static_assert(sizeof(Header) == 0x10, "PFS/HFS header structure size is wrong");
  41. #pragma pack(push, 1)
  42. struct FSEntry {
  43. u64_le offset;
  44. u64_le size;
  45. u32_le strtab_offset;
  46. };
  47. static_assert(sizeof(FSEntry) == 0x14, "FS entry structure size is wrong");
  48. struct PFSEntry {
  49. FSEntry fs_entry;
  50. INSERT_PADDING_BYTES(0x4);
  51. };
  52. static_assert(sizeof(PFSEntry) == 0x18, "PFS entry structure size is wrong");
  53. struct HFSEntry {
  54. FSEntry fs_entry;
  55. u32_le hash_region_size;
  56. INSERT_PADDING_BYTES(0x8);
  57. std::array<char, 0x20> hash;
  58. };
  59. static_assert(sizeof(HFSEntry) == 0x40, "HFS entry structure size is wrong");
  60. #pragma pack(pop)
  61. Loader::ResultStatus status{};
  62. Header pfs_header{};
  63. bool is_hfs = false;
  64. std::size_t content_offset = 0;
  65. std::map<std::string, u64> offsets;
  66. std::map<std::string, u64> sizes;
  67. std::vector<VirtualFile> pfs_files;
  68. };
  69. } // namespace FileSys