diff options
| author | 2018-09-27 09:58:56 -0400 | |
|---|---|---|
| committer | 2018-09-27 09:58:56 -0400 | |
| commit | 8731ac87fae09632e466eee8b7d4c9d5cd3d5511 (patch) | |
| tree | 97ea7300be2fb03cc033f006f35e3b8bac84a006 | |
| parent | Merge pull request #1399 from lioncash/sched (diff) | |
| parent | fsmitm_romfsbuild: std::move std::vector instances in Build() (diff) | |
| download | yuzu-8731ac87fae09632e466eee8b7d4c9d5cd3d5511.tar.gz yuzu-8731ac87fae09632e466eee8b7d4c9d5cd3d5511.tar.xz yuzu-8731ac87fae09632e466eee8b7d4c9d5cd3d5511.zip | |
Merge pull request #1404 from lioncash/vfs
fsmitm_romfsbuild: Minor changes
Diffstat (limited to '')
| -rw-r--r-- | src/core/file_sys/fsmitm_romfsbuild.cpp | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/core/file_sys/fsmitm_romfsbuild.cpp b/src/core/file_sys/fsmitm_romfsbuild.cpp index 07b074817..2a913ce82 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,14 +338,14 @@ 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; |
| 346 | 345 | ||
| 347 | std::vector<u8> header_data(sizeof(RomFSHeader)); | 346 | std::vector<u8> header_data(sizeof(RomFSHeader)); |
| 348 | std::memcpy(header_data.data(), &header, header_data.size()); | 347 | std::memcpy(header_data.data(), &header, header_data.size()); |
| 349 | out.emplace(0, std::make_shared<VectorVfsFile>(header_data)); | 348 | out.emplace(0, std::make_shared<VectorVfsFile>(std::move(header_data))); |
| 350 | 349 | ||
| 351 | std::vector<u8> metadata(file_hash_table_size + file_table_size + dir_hash_table_size + | 350 | std::vector<u8> metadata(file_hash_table_size + file_table_size + dir_hash_table_size + |
| 352 | dir_table_size); | 351 | dir_table_size); |
| @@ -359,7 +358,7 @@ std::map<u64, VirtualFile> RomFSBuildContext::Build() { | |||
| 359 | file_hash_table.size() * sizeof(u32)); | 358 | file_hash_table.size() * sizeof(u32)); |
| 360 | index += file_hash_table.size() * sizeof(u32); | 359 | index += file_hash_table.size() * sizeof(u32); |
| 361 | std::memcpy(metadata.data() + index, file_table.data(), file_table.size()); | 360 | std::memcpy(metadata.data() + index, file_table.data(), file_table.size()); |
| 362 | out.emplace(header.dir_hash_table_ofs, std::make_shared<VectorVfsFile>(metadata)); | 361 | out.emplace(header.dir_hash_table_ofs, std::make_shared<VectorVfsFile>(std::move(metadata))); |
| 363 | 362 | ||
| 364 | return out; | 363 | return out; |
| 365 | } | 364 | } |