Common: Add alignment header

Gets rid of duplicated alignment code.
This commit is contained in:
Léo Lam
2016-11-27 11:56:22 +01:00
parent 7192789c11
commit 31ccfffd38
32 changed files with 146 additions and 119 deletions

View File

@ -14,11 +14,11 @@
#include <utility>
#include <vector>
#include "Common/Align.h"
#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/Logging/Log.h"
#include "Common/MathUtil.h"
#include "Common/MsgHandler.h"
#include "Common/NandPaths.h"
#include "Common/StringUtil.h"
@ -264,7 +264,7 @@ void CNANDContentLoader::InitializeContentEntries(const std::vector<u8>& tmd,
if (m_IsWAD)
{
u32 rounded_size = ROUND_UP(content.m_Size, 0x40);
u32 rounded_size = Common::AlignUp(content.m_Size, 0x40);
iv.fill(0);
std::copy(&tmd[entry_offset + 0x01E8], &tmd[entry_offset + 0x01E8 + 2], iv.begin());

View File

@ -10,12 +10,12 @@
#include <string>
#include <vector>
#include "Common/Align.h"
#include "Common/Assert.h"
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/Logging/Log.h"
#include "Common/MathUtil.h"
#include "DiscIO/Blob.h"
#include "DiscIO/Enums.h"
#include "DiscIO/FileMonitor.h"
@ -308,7 +308,7 @@ bool CVolumeDirectory::SetApploader(const std::string& _rApploader)
std::copy(data.begin(), data.end(), m_apploader.begin());
// 32byte aligned (plus 0x20 padding)
m_dol_address = ROUND_UP(APPLOADER_ADDRESS + m_apploader.size() + 0x20, 0x20ull);
m_dol_address = Common::AlignUp(APPLOADER_ADDRESS + m_apploader.size() + 0x20, 0x20ull);
return true;
}
else
@ -332,7 +332,7 @@ void CVolumeDirectory::SetDOL(const std::string& rDOL)
Write32((u32)(m_dol_address >> m_addressShift), 0x0420, &m_diskHeader);
// 32byte aligned (plus 0x20 padding)
m_fst_address = ROUND_UP(m_dol_address + m_DOL.size() + 0x20, 0x20ull);
m_fst_address = Common::AlignUp(m_dol_address + m_DOL.size() + 0x20, 0x20ull);
}
}
@ -353,7 +353,7 @@ void CVolumeDirectory::BuildFST()
m_fst_address = APPLOADER_ADDRESS + 0x2000;
// 4 byte aligned start of data on disk
m_dataStartAddress = ROUND_UP(m_fst_address + m_FSTData.size(), 0x8000ull);
m_dataStartAddress = Common::AlignUp(m_fst_address + m_FSTData.size(), 0x8000ull);
u64 curDataAddress = m_dataStartAddress;
u32 fstOffset = 0; // Offset within FST data
@ -470,7 +470,7 @@ void CVolumeDirectory::WriteEntry(const File::FSTEntry& entry, u32& fstOffset, u
m_virtualDisk.emplace(dataOffset, entry.physicalName);
// 4 byte aligned
dataOffset = ROUND_UP(dataOffset + std::max<u64>(entry.size, 1ull), 0x8000ull);
dataOffset = Common::AlignUp(dataOffset + std::max<u64>(entry.size, 1ull), 0x8000ull);
}
}

View File

@ -10,9 +10,9 @@
#include <utility>
#include <vector>
#include "Common/Align.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/MathUtil.h"
#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
#include "DiscIO/Blob.h"
@ -20,8 +20,6 @@
#include "DiscIO/Volume.h"
#include "DiscIO/VolumeWad.h"
#define ALIGN_40(x) ROUND_UP(Common::swap32(x), 0x40)
namespace DiscIO
{
CVolumeWAD::CVolumeWAD(std::unique_ptr<IBlobReader> reader)
@ -35,9 +33,13 @@ CVolumeWAD::CVolumeWAD(std::unique_ptr<IBlobReader> reader)
Read(0x14, 4, (u8*)&m_tmd_size);
Read(0x18, 4, (u8*)&m_data_size);
m_offset = ALIGN_40(m_hdr_size) + ALIGN_40(m_cert_size);
m_tmd_offset = ALIGN_40(m_hdr_size) + ALIGN_40(m_cert_size) + ALIGN_40(m_tick_size);
m_opening_bnr_offset = m_tmd_offset + ALIGN_40(m_tmd_size) + ALIGN_40(m_data_size);
m_offset = Common::AlignUp(Common::swap32(m_hdr_size), 0x40) +
Common::AlignUp(Common::swap32(m_cert_size), 0x40);
m_tmd_offset = Common::AlignUp(Common::swap32(m_hdr_size), 0x40) +
Common::AlignUp(Common::swap32(m_cert_size), 0x40) +
Common::AlignUp(Common::swap32(m_tick_size), 0x40);
m_opening_bnr_offset = m_tmd_offset + Common::AlignUp(Common::swap32(m_tmd_size), 0x40) +
Common::AlignUp(Common::swap32(m_data_size), 0x40);
}
CVolumeWAD::~CVolumeWAD()

View File

@ -9,6 +9,7 @@
#include <string>
#include <vector>
#include "Common/Align.h"
#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
@ -22,11 +23,6 @@ static const u64 WII_SECTOR_SIZE = 0x8000;
static const u64 WII_SECTOR_COUNT = 143432 * 2;
static const u64 WII_DISC_HEADER_SIZE = 256;
static inline u64 align(u64 value, u64 bounds)
{
return (value + (bounds - 1)) & (~(bounds - 1));
}
WbfsFileReader::WbfsFileReader(const std::string& filename)
: m_total_files(0), m_size(0), m_good(true)
{
@ -104,7 +100,7 @@ bool WbfsFileReader::ReadHeader()
m_blocks_per_disc =
(WII_SECTOR_COUNT * WII_SECTOR_SIZE + m_wbfs_sector_size - 1) / m_wbfs_sector_size;
m_disc_info_size =
align(WII_DISC_HEADER_SIZE + m_blocks_per_disc * sizeof(u16), m_hd_sector_size);
Common::AlignUp(WII_DISC_HEADER_SIZE + m_blocks_per_disc * sizeof(u16), m_hd_sector_size);
return m_header.disc_table[0] != 0;
}

View File

@ -6,11 +6,11 @@
#include <memory>
#include <string>
#include "Common/Align.h"
#include "Common/Assert.h"
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/Logging/Log.h"
#include "Common/MathUtil.h"
#include "DiscIO/Blob.h"
#include "DiscIO/WiiWad.h"
@ -87,15 +87,15 @@ bool WiiWAD::ParseWAD(IBlobReader& reader)
u32 offset = 0x40;
m_certificate_chain = CreateWADEntry(reader, certificate_chain_size, offset);
offset += ROUND_UP(certificate_chain_size, 0x40);
offset += Common::AlignUp(certificate_chain_size, 0x40);
m_ticket = CreateWADEntry(reader, ticket_size, offset);
offset += ROUND_UP(ticket_size, 0x40);
offset += Common::AlignUp(ticket_size, 0x40);
m_tmd = CreateWADEntry(reader, tmd_size, offset);
offset += ROUND_UP(tmd_size, 0x40);
offset += Common::AlignUp(tmd_size, 0x40);
m_data_app = CreateWADEntry(reader, data_app_size, offset);
offset += ROUND_UP(data_app_size, 0x40);
offset += Common::AlignUp(data_app_size, 0x40);
m_footer = CreateWADEntry(reader, footer_size, offset);
offset += ROUND_UP(footer_size, 0x40);
offset += Common::AlignUp(footer_size, 0x40);
return true;
}