diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/file_sys/fsmitm_romfsbuild.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/core/file_sys/fsmitm_romfsbuild.cpp b/src/core/file_sys/fsmitm_romfsbuild.cpp index 07b074817..3a17864db 100644 --- a/src/core/file_sys/fsmitm_romfsbuild.cpp +++ b/src/core/file_sys/fsmitm_romfsbuild.cpp | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | #include <cstring> | 25 | #include <cstring> |
| 26 | #include "common/alignment.h" | ||
| 26 | #include "common/assert.h" | 27 | #include "common/assert.h" |
| 27 | #include "core/file_sys/fsmitm_romfsbuild.h" | 28 | #include "core/file_sys/fsmitm_romfsbuild.h" |
| 28 | #include "core/file_sys/vfs.h" | 29 | #include "core/file_sys/vfs.h" |
| @@ -182,7 +183,7 @@ bool RomFSBuildContext::AddDirectory(std::shared_ptr<RomFSBuildDirectoryContext> | |||
| 182 | // Add a new directory. | 183 | // Add a new directory. |
| 183 | num_dirs++; | 184 | num_dirs++; |
| 184 | dir_table_size += | 185 | dir_table_size += |
| 185 | sizeof(RomFSDirectoryEntry) + ((dir_ctx->path_len - dir_ctx->cur_path_ofs + 3) & ~3); | 186 | sizeof(RomFSDirectoryEntry) + Common::AlignUp(dir_ctx->path_len - dir_ctx->cur_path_ofs, 4); |
| 186 | dir_ctx->parent = parent_dir_ctx; | 187 | dir_ctx->parent = parent_dir_ctx; |
| 187 | directories.emplace(dir_ctx->path, dir_ctx); | 188 | directories.emplace(dir_ctx->path, dir_ctx); |
| 188 | 189 | ||
| @@ -200,7 +201,7 @@ bool RomFSBuildContext::AddFile(std::shared_ptr<RomFSBuildDirectoryContext> pare | |||
| 200 | // Add a new file. | 201 | // Add a new file. |
| 201 | num_files++; | 202 | num_files++; |
| 202 | file_table_size += | 203 | file_table_size += |
| 203 | sizeof(RomFSFileEntry) + ((file_ctx->path_len - file_ctx->cur_path_ofs + 3) & ~3); | 204 | sizeof(RomFSFileEntry) + Common::AlignUp(file_ctx->path_len - file_ctx->cur_path_ofs, 4); |
| 204 | file_ctx->parent = parent_dir_ctx; | 205 | file_ctx->parent = parent_dir_ctx; |
| 205 | files.emplace(file_ctx->path, file_ctx); | 206 | files.emplace(file_ctx->path, file_ctx); |
| 206 | 207 | ||
| @@ -241,12 +242,12 @@ std::map<u64, VirtualFile> RomFSBuildContext::Build() { | |||
| 241 | std::shared_ptr<RomFSBuildFileContext> prev_file = nullptr; | 242 | std::shared_ptr<RomFSBuildFileContext> prev_file = nullptr; |
| 242 | for (const auto& it : files) { | 243 | for (const auto& it : files) { |
| 243 | cur_file = it.second; | 244 | cur_file = it.second; |
| 244 | file_partition_size = (file_partition_size + 0xFULL) & ~0xFULL; | 245 | file_partition_size = Common::AlignUp(file_partition_size, 16); |
| 245 | cur_file->offset = file_partition_size; | 246 | cur_file->offset = file_partition_size; |
| 246 | file_partition_size += cur_file->size; | 247 | file_partition_size += cur_file->size; |
| 247 | cur_file->entry_offset = entry_offset; | 248 | cur_file->entry_offset = entry_offset; |
| 248 | entry_offset += | 249 | entry_offset += sizeof(RomFSFileEntry) + |
| 249 | sizeof(RomFSFileEntry) + ((cur_file->path_len - cur_file->cur_path_ofs + 3) & ~3); | 250 | Common::AlignUp(cur_file->path_len - cur_file->cur_path_ofs, 4); |
| 250 | prev_file = cur_file; | 251 | prev_file = cur_file; |
| 251 | } | 252 | } |
| 252 | // Assign deferred parent/sibling ownership. | 253 | // Assign deferred parent/sibling ownership. |
| @@ -263,8 +264,8 @@ std::map<u64, VirtualFile> RomFSBuildContext::Build() { | |||
| 263 | for (const auto& it : directories) { | 264 | for (const auto& it : directories) { |
| 264 | cur_dir = it.second; | 265 | cur_dir = it.second; |
| 265 | cur_dir->entry_offset = entry_offset; | 266 | cur_dir->entry_offset = entry_offset; |
| 266 | entry_offset += | 267 | entry_offset += sizeof(RomFSDirectoryEntry) + |
| 267 | sizeof(RomFSDirectoryEntry) + ((cur_dir->path_len - cur_dir->cur_path_ofs + 3) & ~3); | 268 | Common::AlignUp(cur_dir->path_len - cur_dir->cur_path_ofs, 4); |
| 268 | } | 269 | } |
| 269 | // Assign deferred parent/sibling ownership. | 270 | // Assign deferred parent/sibling ownership. |
| 270 | for (auto it = directories.rbegin(); it->second != root; ++it) { | 271 | for (auto it = directories.rbegin(); it->second != root; ++it) { |
| @@ -297,7 +298,7 @@ std::map<u64, VirtualFile> RomFSBuildContext::Build() { | |||
| 297 | out.emplace(cur_file->offset + ROMFS_FILEPARTITION_OFS, cur_file->source); | 298 | out.emplace(cur_file->offset + ROMFS_FILEPARTITION_OFS, cur_file->source); |
| 298 | std::memcpy(file_table.data() + cur_file->entry_offset, &cur_entry, sizeof(RomFSFileEntry)); | 299 | std::memcpy(file_table.data() + cur_file->entry_offset, &cur_entry, sizeof(RomFSFileEntry)); |
| 299 | std::memset(file_table.data() + cur_file->entry_offset + sizeof(RomFSFileEntry), 0, | 300 | std::memset(file_table.data() + cur_file->entry_offset + sizeof(RomFSFileEntry), 0, |
| 300 | (cur_entry.name_size + 3) & ~3); | 301 | Common::AlignUp(cur_entry.name_size, 4)); |
| 301 | std::memcpy(file_table.data() + cur_file->entry_offset + sizeof(RomFSFileEntry), | 302 | std::memcpy(file_table.data() + cur_file->entry_offset + sizeof(RomFSFileEntry), |
| 302 | cur_file->path.data() + cur_file->cur_path_ofs, name_size); | 303 | cur_file->path.data() + cur_file->cur_path_ofs, name_size); |
| 303 | } | 304 | } |
| @@ -324,10 +325,8 @@ std::map<u64, VirtualFile> RomFSBuildContext::Build() { | |||
| 324 | 325 | ||
| 325 | std::memcpy(dir_table.data() + cur_dir->entry_offset, &cur_entry, | 326 | std::memcpy(dir_table.data() + cur_dir->entry_offset, &cur_entry, |
| 326 | sizeof(RomFSDirectoryEntry)); | 327 | sizeof(RomFSDirectoryEntry)); |
| 327 | std::memcpy(dir_table.data() + cur_dir->entry_offset, &cur_entry, | ||
| 328 | sizeof(RomFSDirectoryEntry)); | ||
| 329 | std::memset(dir_table.data() + cur_dir->entry_offset + sizeof(RomFSDirectoryEntry), 0, | 328 | std::memset(dir_table.data() + cur_dir->entry_offset + sizeof(RomFSDirectoryEntry), 0, |
| 330 | (cur_entry.name_size + 3) & ~3); | 329 | Common::AlignUp(cur_entry.name_size, 4)); |
| 331 | std::memcpy(dir_table.data() + cur_dir->entry_offset + sizeof(RomFSDirectoryEntry), | 330 | std::memcpy(dir_table.data() + cur_dir->entry_offset + sizeof(RomFSDirectoryEntry), |
| 332 | cur_dir->path.data() + cur_dir->cur_path_ofs, name_size); | 331 | cur_dir->path.data() + cur_dir->cur_path_ofs, name_size); |
| 333 | } | 332 | } |
| @@ -339,7 +338,7 @@ std::map<u64, VirtualFile> RomFSBuildContext::Build() { | |||
| 339 | header.dir_hash_table_size = dir_hash_table_size; | 338 | header.dir_hash_table_size = dir_hash_table_size; |
| 340 | header.dir_table_size = dir_table_size; | 339 | header.dir_table_size = dir_table_size; |
| 341 | header.file_partition_ofs = ROMFS_FILEPARTITION_OFS; | 340 | header.file_partition_ofs = ROMFS_FILEPARTITION_OFS; |
| 342 | header.dir_hash_table_ofs = (header.file_partition_ofs + file_partition_size + 3ULL) & ~3ULL; | 341 | header.dir_hash_table_ofs = Common::AlignUp(header.file_partition_ofs + file_partition_size, 4); |
| 343 | header.dir_table_ofs = header.dir_hash_table_ofs + header.dir_hash_table_size; | 342 | header.dir_table_ofs = header.dir_hash_table_ofs + header.dir_hash_table_size; |
| 344 | header.file_hash_table_ofs = header.dir_table_ofs + header.dir_table_size; | 343 | header.file_hash_table_ofs = header.dir_table_ofs + header.dir_table_size; |
| 345 | header.file_table_ofs = header.file_hash_table_ofs + header.file_hash_table_size; | 344 | header.file_table_ofs = header.file_hash_table_ofs + header.file_hash_table_size; |