From 1bdae0fe29f87daa81d2aba052a10a709b87485a Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 3 Nov 2019 18:54:03 -0500 Subject: common_func: Use std::array for INSERT_PADDING_* macros. - Zero initialization here is useful for determinism. --- src/core/file_sys/content_archive.cpp | 39 +++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'src/core/file_sys/content_archive.cpp') diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp index ea5c92f61..b8bbdd1ef 100644 --- a/src/core/file_sys/content_archive.cpp +++ b/src/core/file_sys/content_archive.cpp @@ -32,11 +32,28 @@ enum class NCASectionFilesystemType : u8 { ROMFS = 0x3, }; +struct IVFCLevel { + u64_le offset; + u64_le size; + u32_le block_size; + u32_le reserved; +}; +static_assert(sizeof(IVFCLevel) == 0x18, "IVFCLevel has incorrect size."); + +struct IVFCHeader { + u32_le magic; + u32_le magic_number; + INSERT_UNION_PADDING_BYTES(8); + std::array levels; + INSERT_UNION_PADDING_BYTES(64); +}; +static_assert(sizeof(IVFCHeader) == 0xE0, "IVFCHeader has incorrect size."); + struct NCASectionHeaderBlock { - INSERT_PADDING_BYTES(3); + INSERT_UNION_PADDING_BYTES(3); NCASectionFilesystemType filesystem_type; NCASectionCryptoType crypto_type; - INSERT_PADDING_BYTES(3); + INSERT_UNION_PADDING_BYTES(3); }; static_assert(sizeof(NCASectionHeaderBlock) == 0x8, "NCASectionHeaderBlock has incorrect size."); @@ -44,7 +61,7 @@ struct NCASectionRaw { NCASectionHeaderBlock header; std::array block_data; std::array section_ctr; - INSERT_PADDING_BYTES(0xB8); + INSERT_UNION_PADDING_BYTES(0xB8); }; static_assert(sizeof(NCASectionRaw) == 0x200, "NCASectionRaw has incorrect size."); @@ -52,19 +69,19 @@ struct PFS0Superblock { NCASectionHeaderBlock header_block; std::array hash; u32_le size; - INSERT_PADDING_BYTES(4); + INSERT_UNION_PADDING_BYTES(4); u64_le hash_table_offset; u64_le hash_table_size; u64_le pfs0_header_offset; u64_le pfs0_size; - INSERT_PADDING_BYTES(0x1B0); + INSERT_UNION_PADDING_BYTES(0x1B0); }; static_assert(sizeof(PFS0Superblock) == 0x200, "PFS0Superblock has incorrect size."); struct RomFSSuperblock { NCASectionHeaderBlock header_block; IVFCHeader ivfc; - INSERT_PADDING_BYTES(0x118); + INSERT_UNION_PADDING_BYTES(0x118); }; static_assert(sizeof(RomFSSuperblock) == 0x200, "RomFSSuperblock has incorrect size."); @@ -72,24 +89,24 @@ struct BKTRHeader { u64_le offset; u64_le size; u32_le magic; - INSERT_PADDING_BYTES(0x4); + INSERT_UNION_PADDING_BYTES(0x4); u32_le number_entries; - INSERT_PADDING_BYTES(0x4); + INSERT_UNION_PADDING_BYTES(0x4); }; static_assert(sizeof(BKTRHeader) == 0x20, "BKTRHeader has incorrect size."); struct BKTRSuperblock { NCASectionHeaderBlock header_block; IVFCHeader ivfc; - INSERT_PADDING_BYTES(0x18); + INSERT_UNION_PADDING_BYTES(0x18); BKTRHeader relocation; BKTRHeader subsection; - INSERT_PADDING_BYTES(0xC0); + INSERT_UNION_PADDING_BYTES(0xC0); }; static_assert(sizeof(BKTRSuperblock) == 0x200, "BKTRSuperblock has incorrect size."); union NCASectionHeader { - NCASectionRaw raw; + NCASectionRaw raw{}; PFS0Superblock pfs0; RomFSSuperblock romfs; BKTRSuperblock bktr; -- cgit v1.2.3