partition_filesystem.h 2.1 KB

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