2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-04-16 12:29:15 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include "common/common_funcs.h"
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "common/swap.h"
|
2024-01-16 06:23:01 +01:00
|
|
|
#include "core/file_sys/vfs/vfs.h"
|
2018-04-16 12:29:15 +02:00
|
|
|
|
|
|
|
namespace Loader {
|
2018-08-12 06:56:22 +02:00
|
|
|
enum class ResultStatus : u16;
|
2018-04-16 12:29:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace FileSys {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper which implements an interface to parse PFS/HFS filesystems.
|
|
|
|
* Data can either be loaded from a file path or data with an offset into it.
|
|
|
|
*/
|
2018-07-19 03:07:11 +02:00
|
|
|
class PartitionFilesystem : public ReadOnlyVfsDirectory {
|
2018-04-16 12:29:15 +02:00
|
|
|
public:
|
2020-08-23 20:20:37 +02:00
|
|
|
explicit PartitionFilesystem(VirtualFile file);
|
2018-09-20 01:19:05 +02:00
|
|
|
~PartitionFilesystem() override;
|
|
|
|
|
2018-07-19 03:07:11 +02:00
|
|
|
Loader::ResultStatus GetStatus() const;
|
2018-04-16 12:29:15 +02:00
|
|
|
|
2019-09-23 03:44:36 +02:00
|
|
|
std::map<std::string, u64> GetFileOffsets() const;
|
|
|
|
std::map<std::string, u64> GetFileSizes() const;
|
|
|
|
|
2020-08-23 20:20:37 +02:00
|
|
|
std::vector<VirtualFile> GetFiles() const override;
|
|
|
|
std::vector<VirtualDir> GetSubdirectories() const override;
|
2018-07-19 03:07:11 +02:00
|
|
|
std::string GetName() const override;
|
2020-08-23 20:20:37 +02:00
|
|
|
VirtualDir GetParentDirectory() const override;
|
2018-07-19 03:07:11 +02:00
|
|
|
void PrintDebugInfo() const;
|
2018-04-16 12:29:15 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct Header {
|
2018-06-21 17:16:23 +02:00
|
|
|
u32_le magic;
|
2018-04-16 12:29:15 +02:00
|
|
|
u32_le num_entries;
|
|
|
|
u32_le strtab_size;
|
|
|
|
INSERT_PADDING_BYTES(0x4);
|
2018-07-19 05:25:07 +02:00
|
|
|
|
|
|
|
bool HasValidMagicValue() const;
|
2018-04-16 12:29:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static_assert(sizeof(Header) == 0x10, "PFS/HFS header structure size is wrong");
|
|
|
|
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
struct FSEntry {
|
|
|
|
u64_le offset;
|
|
|
|
u64_le size;
|
|
|
|
u32_le strtab_offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
static_assert(sizeof(FSEntry) == 0x14, "FS entry structure size is wrong");
|
|
|
|
|
|
|
|
struct PFSEntry {
|
|
|
|
FSEntry fs_entry;
|
|
|
|
INSERT_PADDING_BYTES(0x4);
|
|
|
|
};
|
|
|
|
|
|
|
|
static_assert(sizeof(PFSEntry) == 0x18, "PFS entry structure size is wrong");
|
|
|
|
|
|
|
|
struct HFSEntry {
|
|
|
|
FSEntry fs_entry;
|
|
|
|
u32_le hash_region_size;
|
|
|
|
INSERT_PADDING_BYTES(0x8);
|
|
|
|
std::array<char, 0x20> hash;
|
|
|
|
};
|
|
|
|
|
|
|
|
static_assert(sizeof(HFSEntry) == 0x40, "HFS entry structure size is wrong");
|
|
|
|
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
2018-07-19 05:25:07 +02:00
|
|
|
Loader::ResultStatus status{};
|
2018-04-16 12:29:15 +02:00
|
|
|
|
2018-07-19 05:25:07 +02:00
|
|
|
Header pfs_header{};
|
|
|
|
bool is_hfs = false;
|
2018-09-15 15:21:06 +02:00
|
|
|
std::size_t content_offset = 0;
|
2018-04-16 12:29:15 +02:00
|
|
|
|
2019-09-23 03:44:36 +02:00
|
|
|
std::map<std::string, u64> offsets;
|
|
|
|
std::map<std::string, u64> sizes;
|
|
|
|
|
2018-07-19 03:07:11 +02:00
|
|
|
std::vector<VirtualFile> pfs_files;
|
2018-04-16 12:29:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace FileSys
|