summaryrefslogtreecommitdiff
path: root/src/core/file_sys
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/file_sys')
-rw-r--r--src/core/file_sys/card_image.cpp15
-rw-r--r--src/core/file_sys/content_archive.cpp6
-rw-r--r--src/core/file_sys/directory.h2
-rw-r--r--src/core/file_sys/nca_metadata.cpp4
-rw-r--r--src/core/file_sys/nca_patch.cpp34
-rw-r--r--src/core/file_sys/nca_patch.h12
-rw-r--r--src/core/file_sys/partition_filesystem.cpp10
-rw-r--r--src/core/file_sys/partition_filesystem.h2
-rw-r--r--src/core/file_sys/patch_manager.cpp4
-rw-r--r--src/core/file_sys/program_metadata.cpp2
-rw-r--r--src/core/file_sys/registered_cache.cpp10
-rw-r--r--src/core/file_sys/romfs.cpp11
-rw-r--r--src/core/file_sys/vfs.cpp22
-rw-r--r--src/core/file_sys/vfs.h32
-rw-r--r--src/core/file_sys/vfs_concat.cpp10
-rw-r--r--src/core/file_sys/vfs_concat.h8
-rw-r--r--src/core/file_sys/vfs_offset.cpp24
-rw-r--r--src/core/file_sys/vfs_offset.h26
-rw-r--r--src/core/file_sys/vfs_real.cpp8
-rw-r--r--src/core/file_sys/vfs_real.h8
-rw-r--r--src/core/file_sys/xts_archive.cpp8
21 files changed, 130 insertions, 128 deletions
diff --git a/src/core/file_sys/card_image.cpp b/src/core/file_sys/card_image.cpp
index 8218893b2..edfc1bbd4 100644
--- a/src/core/file_sys/card_image.cpp
+++ b/src/core/file_sys/card_image.cpp
@@ -41,13 +41,14 @@ XCI::XCI(VirtualFile file_) : file(std::move(file_)), partitions(0x4) {
41 41
42 for (XCIPartition partition : 42 for (XCIPartition partition :
43 {XCIPartition::Update, XCIPartition::Normal, XCIPartition::Secure, XCIPartition::Logo}) { 43 {XCIPartition::Update, XCIPartition::Normal, XCIPartition::Secure, XCIPartition::Logo}) {
44 auto raw = main_hfs.GetFile(partition_names[static_cast<size_t>(partition)]); 44 auto raw = main_hfs.GetFile(partition_names[static_cast<std::size_t>(partition)]);
45 if (raw != nullptr) 45 if (raw != nullptr)
46 partitions[static_cast<size_t>(partition)] = std::make_shared<PartitionFilesystem>(raw); 46 partitions[static_cast<std::size_t>(partition)] =
47 std::make_shared<PartitionFilesystem>(raw);
47 } 48 }
48 49
49 secure_partition = std::make_shared<NSP>( 50 secure_partition = std::make_shared<NSP>(
50 main_hfs.GetFile(partition_names[static_cast<size_t>(XCIPartition::Secure)])); 51 main_hfs.GetFile(partition_names[static_cast<std::size_t>(XCIPartition::Secure)]));
51 52
52 const auto secure_ncas = secure_partition->GetNCAsCollapsed(); 53 const auto secure_ncas = secure_partition->GetNCAsCollapsed();
53 std::copy(secure_ncas.begin(), secure_ncas.end(), std::back_inserter(ncas)); 54 std::copy(secure_ncas.begin(), secure_ncas.end(), std::back_inserter(ncas));
@@ -92,7 +93,7 @@ Loader::ResultStatus XCI::GetProgramNCAStatus() const {
92} 93}
93 94
94VirtualDir XCI::GetPartition(XCIPartition partition) const { 95VirtualDir XCI::GetPartition(XCIPartition partition) const {
95 return partitions[static_cast<size_t>(partition)]; 96 return partitions[static_cast<std::size_t>(partition)];
96} 97}
97 98
98std::shared_ptr<NSP> XCI::GetSecurePartitionNSP() const { 99std::shared_ptr<NSP> XCI::GetSecurePartitionNSP() const {
@@ -168,11 +169,11 @@ bool XCI::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) {
168} 169}
169 170
170Loader::ResultStatus XCI::AddNCAFromPartition(XCIPartition part) { 171Loader::ResultStatus XCI::AddNCAFromPartition(XCIPartition part) {
171 if (partitions[static_cast<size_t>(part)] == nullptr) { 172 if (partitions[static_cast<std::size_t>(part)] == nullptr) {
172 return Loader::ResultStatus::ErrorXCIMissingPartition; 173 return Loader::ResultStatus::ErrorXCIMissingPartition;
173 } 174 }
174 175
175 for (const VirtualFile& file : partitions[static_cast<size_t>(part)]->GetFiles()) { 176 for (const VirtualFile& file : partitions[static_cast<std::size_t>(part)]->GetFiles()) {
176 if (file->GetExtension() != "nca") 177 if (file->GetExtension() != "nca")
177 continue; 178 continue;
178 auto nca = std::make_shared<NCA>(file); 179 auto nca = std::make_shared<NCA>(file);
@@ -187,7 +188,7 @@ Loader::ResultStatus XCI::AddNCAFromPartition(XCIPartition part) {
187 } else { 188 } else {
188 const u16 error_id = static_cast<u16>(nca->GetStatus()); 189 const u16 error_id = static_cast<u16>(nca->GetStatus());
189 LOG_CRITICAL(Loader, "Could not load NCA {}/{}, failed with error code {:04X} ({})", 190 LOG_CRITICAL(Loader, "Could not load NCA {}/{}, failed with error code {:04X} ({})",
190 partition_names[static_cast<size_t>(part)], nca->GetName(), error_id, 191 partition_names[static_cast<std::size_t>(part)], nca->GetName(), error_id,
191 nca->GetStatus()); 192 nca->GetStatus());
192 } 193 }
193 } 194 }
diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp
index 79bfb6fec..45fc0b574 100644
--- a/src/core/file_sys/content_archive.cpp
+++ b/src/core/file_sys/content_archive.cpp
@@ -298,11 +298,11 @@ NCA::NCA(VirtualFile file_, VirtualFile bktr_base_romfs_, u64 bktr_base_ivfc_off
298 auto section = sections[i]; 298 auto section = sections[i];
299 299
300 if (section.raw.header.filesystem_type == NCASectionFilesystemType::ROMFS) { 300 if (section.raw.header.filesystem_type == NCASectionFilesystemType::ROMFS) {
301 const size_t base_offset = 301 const std::size_t base_offset =
302 header.section_tables[i].media_offset * MEDIA_OFFSET_MULTIPLIER; 302 header.section_tables[i].media_offset * MEDIA_OFFSET_MULTIPLIER;
303 ivfc_offset = section.romfs.ivfc.levels[IVFC_MAX_LEVEL - 1].offset; 303 ivfc_offset = section.romfs.ivfc.levels[IVFC_MAX_LEVEL - 1].offset;
304 const size_t romfs_offset = base_offset + ivfc_offset; 304 const std::size_t romfs_offset = base_offset + ivfc_offset;
305 const size_t romfs_size = section.romfs.ivfc.levels[IVFC_MAX_LEVEL - 1].size; 305 const std::size_t romfs_size = section.romfs.ivfc.levels[IVFC_MAX_LEVEL - 1].size;
306 auto raw = std::make_shared<OffsetVfsFile>(file, romfs_size, romfs_offset); 306 auto raw = std::make_shared<OffsetVfsFile>(file, romfs_size, romfs_offset);
307 auto dec = Decrypt(section, raw, romfs_offset); 307 auto dec = Decrypt(section, raw, romfs_offset);
308 308
diff --git a/src/core/file_sys/directory.h b/src/core/file_sys/directory.h
index 3759e743a..12bb90ec8 100644
--- a/src/core/file_sys/directory.h
+++ b/src/core/file_sys/directory.h
@@ -25,7 +25,7 @@ enum EntryType : u8 {
25struct Entry { 25struct Entry {
26 Entry(std::string_view view, EntryType entry_type, u64 entry_size) 26 Entry(std::string_view view, EntryType entry_type, u64 entry_size)
27 : type{entry_type}, file_size{entry_size} { 27 : type{entry_type}, file_size{entry_size} {
28 const size_t copy_size = view.copy(filename, std::size(filename) - 1); 28 const std::size_t copy_size = view.copy(filename, std::size(filename) - 1);
29 filename[copy_size] = '\0'; 29 filename[copy_size] = '\0';
30 } 30 }
31 31
diff --git a/src/core/file_sys/nca_metadata.cpp b/src/core/file_sys/nca_metadata.cpp
index cdfbc5aaf..479916b69 100644
--- a/src/core/file_sys/nca_metadata.cpp
+++ b/src/core/file_sys/nca_metadata.cpp
@@ -11,11 +11,11 @@
11namespace FileSys { 11namespace FileSys {
12 12
13bool operator>=(TitleType lhs, TitleType rhs) { 13bool operator>=(TitleType lhs, TitleType rhs) {
14 return static_cast<size_t>(lhs) >= static_cast<size_t>(rhs); 14 return static_cast<std::size_t>(lhs) >= static_cast<std::size_t>(rhs);
15} 15}
16 16
17bool operator<=(TitleType lhs, TitleType rhs) { 17bool operator<=(TitleType lhs, TitleType rhs) {
18 return static_cast<size_t>(lhs) <= static_cast<size_t>(rhs); 18 return static_cast<std::size_t>(lhs) <= static_cast<std::size_t>(rhs);
19} 19}
20 20
21CNMT::CNMT(VirtualFile file) { 21CNMT::CNMT(VirtualFile file) {
diff --git a/src/core/file_sys/nca_patch.cpp b/src/core/file_sys/nca_patch.cpp
index 6fc5bd7d8..0090cc6c4 100644
--- a/src/core/file_sys/nca_patch.cpp
+++ b/src/core/file_sys/nca_patch.cpp
@@ -22,11 +22,11 @@ BKTR::BKTR(VirtualFile base_romfs_, VirtualFile bktr_romfs_, RelocationBlock rel
22 base_romfs(std::move(base_romfs_)), bktr_romfs(std::move(bktr_romfs_)), 22 base_romfs(std::move(base_romfs_)), bktr_romfs(std::move(bktr_romfs_)),
23 encrypted(is_encrypted_), key(key_), base_offset(base_offset_), ivfc_offset(ivfc_offset_), 23 encrypted(is_encrypted_), key(key_), base_offset(base_offset_), ivfc_offset(ivfc_offset_),
24 section_ctr(section_ctr_) { 24 section_ctr(section_ctr_) {
25 for (size_t i = 0; i < relocation.number_buckets - 1; ++i) { 25 for (std::size_t i = 0; i < relocation.number_buckets - 1; ++i) {
26 relocation_buckets[i].entries.push_back({relocation.base_offsets[i + 1], 0, 0}); 26 relocation_buckets[i].entries.push_back({relocation.base_offsets[i + 1], 0, 0});
27 } 27 }
28 28
29 for (size_t i = 0; i < subsection.number_buckets - 1; ++i) { 29 for (std::size_t i = 0; i < subsection.number_buckets - 1; ++i) {
30 subsection_buckets[i].entries.push_back({subsection_buckets[i + 1].entries[0].address_patch, 30 subsection_buckets[i].entries.push_back({subsection_buckets[i + 1].entries[0].address_patch,
31 {0}, 31 {0},
32 subsection_buckets[i + 1].entries[0].ctr}); 32 subsection_buckets[i + 1].entries[0].ctr});
@@ -37,7 +37,7 @@ BKTR::BKTR(VirtualFile base_romfs_, VirtualFile bktr_romfs_, RelocationBlock rel
37 37
38BKTR::~BKTR() = default; 38BKTR::~BKTR() = default;
39 39
40size_t BKTR::Read(u8* data, size_t length, size_t offset) const { 40std::size_t BKTR::Read(u8* data, std::size_t length, std::size_t offset) const {
41 // Read out of bounds. 41 // Read out of bounds.
42 if (offset >= relocation.size) 42 if (offset >= relocation.size)
43 return 0; 43 return 0;
@@ -69,14 +69,14 @@ size_t BKTR::Read(u8* data, size_t length, size_t offset) const {
69 std::vector<u8> iv(16); 69 std::vector<u8> iv(16);
70 auto subsection_ctr = subsection.ctr; 70 auto subsection_ctr = subsection.ctr;
71 auto offset_iv = section_offset + base_offset; 71 auto offset_iv = section_offset + base_offset;
72 for (size_t i = 0; i < section_ctr.size(); ++i) 72 for (std::size_t i = 0; i < section_ctr.size(); ++i)
73 iv[i] = section_ctr[0x8 - i - 1]; 73 iv[i] = section_ctr[0x8 - i - 1];
74 offset_iv >>= 4; 74 offset_iv >>= 4;
75 for (size_t i = 0; i < sizeof(u64); ++i) { 75 for (std::size_t i = 0; i < sizeof(u64); ++i) {
76 iv[0xF - i] = static_cast<u8>(offset_iv & 0xFF); 76 iv[0xF - i] = static_cast<u8>(offset_iv & 0xFF);
77 offset_iv >>= 8; 77 offset_iv >>= 8;
78 } 78 }
79 for (size_t i = 0; i < sizeof(u32); ++i) { 79 for (std::size_t i = 0; i < sizeof(u32); ++i) {
80 iv[0x7 - i] = static_cast<u8>(subsection_ctr & 0xFF); 80 iv[0x7 - i] = static_cast<u8>(subsection_ctr & 0xFF);
81 subsection_ctr >>= 8; 81 subsection_ctr >>= 8;
82 } 82 }
@@ -110,8 +110,8 @@ size_t BKTR::Read(u8* data, size_t length, size_t offset) const {
110} 110}
111 111
112template <bool Subsection, typename BlockType, typename BucketType> 112template <bool Subsection, typename BlockType, typename BucketType>
113std::pair<size_t, size_t> BKTR::SearchBucketEntry(u64 offset, BlockType block, 113std::pair<std::size_t, std::size_t> BKTR::SearchBucketEntry(u64 offset, BlockType block,
114 BucketType buckets) const { 114 BucketType buckets) const {
115 if constexpr (Subsection) { 115 if constexpr (Subsection) {
116 const auto last_bucket = buckets[block.number_buckets - 1]; 116 const auto last_bucket = buckets[block.number_buckets - 1];
117 if (offset >= last_bucket.entries[last_bucket.number_entries].address_patch) 117 if (offset >= last_bucket.entries[last_bucket.number_entries].address_patch)
@@ -120,18 +120,18 @@ std::pair<size_t, size_t> BKTR::SearchBucketEntry(u64 offset, BlockType block,
120 ASSERT_MSG(offset <= block.size, "Offset is out of bounds in BKTR relocation block."); 120 ASSERT_MSG(offset <= block.size, "Offset is out of bounds in BKTR relocation block.");
121 } 121 }
122 122
123 size_t bucket_id = std::count_if(block.base_offsets.begin() + 1, 123 std::size_t bucket_id = std::count_if(
124 block.base_offsets.begin() + block.number_buckets, 124 block.base_offsets.begin() + 1, block.base_offsets.begin() + block.number_buckets,
125 [&offset](u64 base_offset) { return base_offset <= offset; }); 125 [&offset](u64 base_offset) { return base_offset <= offset; });
126 126
127 const auto bucket = buckets[bucket_id]; 127 const auto bucket = buckets[bucket_id];
128 128
129 if (bucket.number_entries == 1) 129 if (bucket.number_entries == 1)
130 return {bucket_id, 0}; 130 return {bucket_id, 0};
131 131
132 size_t low = 0; 132 std::size_t low = 0;
133 size_t mid = 0; 133 std::size_t mid = 0;
134 size_t high = bucket.number_entries - 1; 134 std::size_t high = bucket.number_entries - 1;
135 while (low <= high) { 135 while (low <= high) {
136 mid = (low + high) / 2; 136 mid = (low + high) / 2;
137 if (bucket.entries[mid].address_patch > offset) { 137 if (bucket.entries[mid].address_patch > offset) {
@@ -179,11 +179,11 @@ std::string BKTR::GetName() const {
179 return base_romfs->GetName(); 179 return base_romfs->GetName();
180} 180}
181 181
182size_t BKTR::GetSize() const { 182std::size_t BKTR::GetSize() const {
183 return relocation.size; 183 return relocation.size;
184} 184}
185 185
186bool BKTR::Resize(size_t new_size) { 186bool BKTR::Resize(std::size_t new_size) {
187 return false; 187 return false;
188} 188}
189 189
@@ -199,7 +199,7 @@ bool BKTR::IsReadable() const {
199 return true; 199 return true;
200} 200}
201 201
202size_t BKTR::Write(const u8* data, size_t length, size_t offset) { 202std::size_t BKTR::Write(const u8* data, std::size_t length, std::size_t offset) {
203 return 0; 203 return 0;
204} 204}
205 205
diff --git a/src/core/file_sys/nca_patch.h b/src/core/file_sys/nca_patch.h
index 381f3504f..8e64e8378 100644
--- a/src/core/file_sys/nca_patch.h
+++ b/src/core/file_sys/nca_patch.h
@@ -98,13 +98,13 @@ public:
98 Core::Crypto::Key128 key, u64 base_offset, u64 ivfc_offset, std::array<u8, 8> section_ctr); 98 Core::Crypto::Key128 key, u64 base_offset, u64 ivfc_offset, std::array<u8, 8> section_ctr);
99 ~BKTR() override; 99 ~BKTR() override;
100 100
101 size_t Read(u8* data, size_t length, size_t offset) const override; 101 std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override;
102 102
103 std::string GetName() const override; 103 std::string GetName() const override;
104 104
105 size_t GetSize() const override; 105 std::size_t GetSize() const override;
106 106
107 bool Resize(size_t new_size) override; 107 bool Resize(std::size_t new_size) override;
108 108
109 std::shared_ptr<VfsDirectory> GetContainingDirectory() const override; 109 std::shared_ptr<VfsDirectory> GetContainingDirectory() const override;
110 110
@@ -112,14 +112,14 @@ public:
112 112
113 bool IsReadable() const override; 113 bool IsReadable() const override;
114 114
115 size_t Write(const u8* data, size_t length, size_t offset) override; 115 std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override;
116 116
117 bool Rename(std::string_view name) override; 117 bool Rename(std::string_view name) override;
118 118
119private: 119private:
120 template <bool Subsection, typename BlockType, typename BucketType> 120 template <bool Subsection, typename BlockType, typename BucketType>
121 std::pair<size_t, size_t> SearchBucketEntry(u64 offset, BlockType block, 121 std::pair<std::size_t, std::size_t> SearchBucketEntry(u64 offset, BlockType block,
122 BucketType buckets) const; 122 BucketType buckets) const;
123 123
124 RelocationEntry GetRelocationEntry(u64 offset) const; 124 RelocationEntry GetRelocationEntry(u64 offset) const;
125 RelocationEntry GetNextRelocationEntry(u64 offset) const; 125 RelocationEntry GetNextRelocationEntry(u64 offset) const;
diff --git a/src/core/file_sys/partition_filesystem.cpp b/src/core/file_sys/partition_filesystem.cpp
index c377edc9c..f5b3b0175 100644
--- a/src/core/file_sys/partition_filesystem.cpp
+++ b/src/core/file_sys/partition_filesystem.cpp
@@ -42,21 +42,21 @@ PartitionFilesystem::PartitionFilesystem(std::shared_ptr<VfsFile> file) {
42 42
43 is_hfs = pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0'); 43 is_hfs = pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0');
44 44
45 size_t entry_size = is_hfs ? sizeof(HFSEntry) : sizeof(PFSEntry); 45 std::size_t entry_size = is_hfs ? sizeof(HFSEntry) : sizeof(PFSEntry);
46 size_t metadata_size = 46 std::size_t metadata_size =
47 sizeof(Header) + (pfs_header.num_entries * entry_size) + pfs_header.strtab_size; 47 sizeof(Header) + (pfs_header.num_entries * entry_size) + pfs_header.strtab_size;
48 48
49 // Actually read in now... 49 // Actually read in now...
50 std::vector<u8> file_data = file->ReadBytes(metadata_size); 50 std::vector<u8> file_data = file->ReadBytes(metadata_size);
51 const size_t total_size = file_data.size(); 51 const std::size_t total_size = file_data.size();
52 52
53 if (total_size != metadata_size) { 53 if (total_size != metadata_size) {
54 status = Loader::ResultStatus::ErrorIncorrectPFSFileSize; 54 status = Loader::ResultStatus::ErrorIncorrectPFSFileSize;
55 return; 55 return;
56 } 56 }
57 57
58 size_t entries_offset = sizeof(Header); 58 std::size_t entries_offset = sizeof(Header);
59 size_t strtab_offset = entries_offset + (pfs_header.num_entries * entry_size); 59 std::size_t strtab_offset = entries_offset + (pfs_header.num_entries * entry_size);
60 content_offset = strtab_offset + pfs_header.strtab_size; 60 content_offset = strtab_offset + pfs_header.strtab_size;
61 for (u16 i = 0; i < pfs_header.num_entries; i++) { 61 for (u16 i = 0; i < pfs_header.num_entries; i++) {
62 FSEntry entry; 62 FSEntry entry;
diff --git a/src/core/file_sys/partition_filesystem.h b/src/core/file_sys/partition_filesystem.h
index be7bc32a8..e80d2456b 100644
--- a/src/core/file_sys/partition_filesystem.h
+++ b/src/core/file_sys/partition_filesystem.h
@@ -79,7 +79,7 @@ private:
79 79
80 Header pfs_header{}; 80 Header pfs_header{};
81 bool is_hfs = false; 81 bool is_hfs = false;
82 size_t content_offset = 0; 82 std::size_t content_offset = 0;
83 83
84 std::vector<VirtualFile> pfs_files; 84 std::vector<VirtualFile> pfs_files;
85 std::vector<VirtualDir> pfs_dirs; 85 std::vector<VirtualDir> pfs_dirs;
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp
index 6cecab336..b37b4c68b 100644
--- a/src/core/file_sys/patch_manager.cpp
+++ b/src/core/file_sys/patch_manager.cpp
@@ -21,7 +21,7 @@ constexpr u64 SINGLE_BYTE_MODULUS = 0x100;
21std::string FormatTitleVersion(u32 version, TitleVersionFormat format) { 21std::string FormatTitleVersion(u32 version, TitleVersionFormat format) {
22 std::array<u8, sizeof(u32)> bytes{}; 22 std::array<u8, sizeof(u32)> bytes{};
23 bytes[0] = version % SINGLE_BYTE_MODULUS; 23 bytes[0] = version % SINGLE_BYTE_MODULUS;
24 for (size_t i = 1; i < bytes.size(); ++i) { 24 for (std::size_t i = 1; i < bytes.size(); ++i) {
25 version /= SINGLE_BYTE_MODULUS; 25 version /= SINGLE_BYTE_MODULUS;
26 bytes[i] = version % SINGLE_BYTE_MODULUS; 26 bytes[i] = version % SINGLE_BYTE_MODULUS;
27 } 27 }
@@ -36,7 +36,7 @@ constexpr std::array<const char*, 1> PATCH_TYPE_NAMES{
36}; 36};
37 37
38std::string FormatPatchTypeName(PatchType type) { 38std::string FormatPatchTypeName(PatchType type) {
39 return PATCH_TYPE_NAMES.at(static_cast<size_t>(type)); 39 return PATCH_TYPE_NAMES.at(static_cast<std::size_t>(type));
40} 40}
41 41
42PatchManager::PatchManager(u64 title_id) : title_id(title_id) {} 42PatchManager::PatchManager(u64 title_id) : title_id(title_id) {}
diff --git a/src/core/file_sys/program_metadata.cpp b/src/core/file_sys/program_metadata.cpp
index ccb685526..9d19aaa6d 100644
--- a/src/core/file_sys/program_metadata.cpp
+++ b/src/core/file_sys/program_metadata.cpp
@@ -13,7 +13,7 @@
13namespace FileSys { 13namespace FileSys {
14 14
15Loader::ResultStatus ProgramMetadata::Load(VirtualFile file) { 15Loader::ResultStatus ProgramMetadata::Load(VirtualFile file) {
16 size_t total_size = static_cast<size_t>(file->GetSize()); 16 std::size_t total_size = static_cast<std::size_t>(file->GetSize());
17 if (total_size < sizeof(Header)) 17 if (total_size < sizeof(Header))
18 return Loader::ResultStatus::ErrorBadNPDMHeader; 18 return Loader::ResultStatus::ErrorBadNPDMHeader;
19 19
diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp
index 7361a67be..dad7ae10b 100644
--- a/src/core/file_sys/registered_cache.cpp
+++ b/src/core/file_sys/registered_cache.cpp
@@ -62,11 +62,11 @@ static std::string GetCNMTName(TitleType type, u64 title_id) {
62 "" ///< Currently unknown 'DeltaTitle' 62 "" ///< Currently unknown 'DeltaTitle'
63 }; 63 };
64 64
65 auto index = static_cast<size_t>(type); 65 auto index = static_cast<std::size_t>(type);
66 // If the index is after the jump in TitleType, subtract it out. 66 // If the index is after the jump in TitleType, subtract it out.
67 if (index >= static_cast<size_t>(TitleType::Application)) { 67 if (index >= static_cast<std::size_t>(TitleType::Application)) {
68 index -= static_cast<size_t>(TitleType::Application) - 68 index -= static_cast<std::size_t>(TitleType::Application) -
69 static_cast<size_t>(TitleType::FirmwarePackageB); 69 static_cast<std::size_t>(TitleType::FirmwarePackageB);
70 } 70 }
71 return fmt::format("{}_{:016x}.cnmt", TITLE_TYPE_NAMES[index], title_id); 71 return fmt::format("{}_{:016x}.cnmt", TITLE_TYPE_NAMES[index], title_id);
72} 72}
@@ -105,7 +105,7 @@ VirtualFile RegisteredCache::OpenFileOrDirectoryConcat(const VirtualDir& dir,
105 } else { 105 } else {
106 std::vector<VirtualFile> concat; 106 std::vector<VirtualFile> concat;
107 // Since the files are a two-digit hex number, max is FF. 107 // Since the files are a two-digit hex number, max is FF.
108 for (size_t i = 0; i < 0x100; ++i) { 108 for (std::size_t i = 0; i < 0x100; ++i) {
109 auto next = nca_dir->GetFile(fmt::format("{:02X}", i)); 109 auto next = nca_dir->GetFile(fmt::format("{:02X}", i));
110 if (next != nullptr) { 110 if (next != nullptr) {
111 concat.push_back(std::move(next)); 111 concat.push_back(std::move(next));
diff --git a/src/core/file_sys/romfs.cpp b/src/core/file_sys/romfs.cpp
index e490c8ace..9f6e41cdf 100644
--- a/src/core/file_sys/romfs.cpp
+++ b/src/core/file_sys/romfs.cpp
@@ -49,7 +49,7 @@ struct FileEntry {
49static_assert(sizeof(FileEntry) == 0x20, "FileEntry has incorrect size."); 49static_assert(sizeof(FileEntry) == 0x20, "FileEntry has incorrect size.");
50 50
51template <typename Entry> 51template <typename Entry>
52static std::pair<Entry, std::string> GetEntry(const VirtualFile& file, size_t offset) { 52static std::pair<Entry, std::string> GetEntry(const VirtualFile& file, std::size_t offset) {
53 Entry entry{}; 53 Entry entry{};
54 if (file->ReadObject(&entry, offset) != sizeof(Entry)) 54 if (file->ReadObject(&entry, offset) != sizeof(Entry))
55 return {}; 55 return {};
@@ -59,8 +59,8 @@ static std::pair<Entry, std::string> GetEntry(const VirtualFile& file, size_t of
59 return {entry, string}; 59 return {entry, string};
60} 60}
61 61
62void ProcessFile(VirtualFile file, size_t file_offset, size_t data_offset, u32 this_file_offset, 62void ProcessFile(VirtualFile file, std::size_t file_offset, std::size_t data_offset,
63 std::shared_ptr<VectorVfsDirectory> parent) { 63 u32 this_file_offset, std::shared_ptr<VectorVfsDirectory> parent) {
64 while (true) { 64 while (true) {
65 auto entry = GetEntry<FileEntry>(file, file_offset + this_file_offset); 65 auto entry = GetEntry<FileEntry>(file, file_offset + this_file_offset);
66 66
@@ -74,8 +74,9 @@ void ProcessFile(VirtualFile file, size_t file_offset, size_t data_offset, u32 t
74 } 74 }
75} 75}
76 76
77void ProcessDirectory(VirtualFile file, size_t dir_offset, size_t file_offset, size_t data_offset, 77void ProcessDirectory(VirtualFile file, std::size_t dir_offset, std::size_t file_offset,
78 u32 this_dir_offset, std::shared_ptr<VectorVfsDirectory> parent) { 78 std::size_t data_offset, u32 this_dir_offset,
79 std::shared_ptr<VectorVfsDirectory> parent) {
79 while (true) { 80 while (true) {
80 auto entry = GetEntry<DirectoryEntry>(file, dir_offset + this_dir_offset); 81 auto entry = GetEntry<DirectoryEntry>(file, dir_offset + this_dir_offset);
81 auto current = std::make_shared<VectorVfsDirectory>( 82 auto current = std::make_shared<VectorVfsDirectory>(
diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs.cpp
index 146c839f4..d7b52abfd 100644
--- a/src/core/file_sys/vfs.cpp
+++ b/src/core/file_sys/vfs.cpp
@@ -167,18 +167,18 @@ std::string VfsFile::GetExtension() const {
167 167
168VfsDirectory::~VfsDirectory() = default; 168VfsDirectory::~VfsDirectory() = default;
169 169
170boost::optional<u8> VfsFile::ReadByte(size_t offset) const { 170boost::optional<u8> VfsFile::ReadByte(std::size_t offset) const {
171 u8 out{}; 171 u8 out{};
172 size_t size = Read(&out, 1, offset); 172 std::size_t size = Read(&out, 1, offset);
173 if (size == 1) 173 if (size == 1)
174 return out; 174 return out;
175 175
176 return boost::none; 176 return boost::none;
177} 177}
178 178
179std::vector<u8> VfsFile::ReadBytes(size_t size, size_t offset) const { 179std::vector<u8> VfsFile::ReadBytes(std::size_t size, std::size_t offset) const {
180 std::vector<u8> out(size); 180 std::vector<u8> out(size);
181 size_t read_size = Read(out.data(), size, offset); 181 std::size_t read_size = Read(out.data(), size, offset);
182 out.resize(read_size); 182 out.resize(read_size);
183 return out; 183 return out;
184} 184}
@@ -187,11 +187,11 @@ std::vector<u8> VfsFile::ReadAllBytes() const {
187 return ReadBytes(GetSize()); 187 return ReadBytes(GetSize());
188} 188}
189 189
190bool VfsFile::WriteByte(u8 data, size_t offset) { 190bool VfsFile::WriteByte(u8 data, std::size_t offset) {
191 return Write(&data, 1, offset) == 1; 191 return Write(&data, 1, offset) == 1;
192} 192}
193 193
194size_t VfsFile::WriteBytes(const std::vector<u8>& data, size_t offset) { 194std::size_t VfsFile::WriteBytes(const std::vector<u8>& data, std::size_t offset) {
195 return Write(data.data(), data.size(), offset); 195 return Write(data.data(), data.size(), offset);
196} 196}
197 197
@@ -215,7 +215,7 @@ std::shared_ptr<VfsFile> VfsDirectory::GetFileRelative(std::string_view path) co
215 } 215 }
216 216
217 auto dir = GetSubdirectory(vec[0]); 217 auto dir = GetSubdirectory(vec[0]);
218 for (size_t component = 1; component < vec.size() - 1; ++component) { 218 for (std::size_t component = 1; component < vec.size() - 1; ++component) {
219 if (dir == nullptr) { 219 if (dir == nullptr) {
220 return nullptr; 220 return nullptr;
221 } 221 }
@@ -249,7 +249,7 @@ std::shared_ptr<VfsDirectory> VfsDirectory::GetDirectoryRelative(std::string_vie
249 } 249 }
250 250
251 auto dir = GetSubdirectory(vec[0]); 251 auto dir = GetSubdirectory(vec[0]);
252 for (size_t component = 1; component < vec.size(); ++component) { 252 for (std::size_t component = 1; component < vec.size(); ++component) {
253 if (dir == nullptr) { 253 if (dir == nullptr) {
254 return nullptr; 254 return nullptr;
255 } 255 }
@@ -286,7 +286,7 @@ bool VfsDirectory::IsRoot() const {
286 return GetParentDirectory() == nullptr; 286 return GetParentDirectory() == nullptr;
287} 287}
288 288
289size_t VfsDirectory::GetSize() const { 289std::size_t VfsDirectory::GetSize() const {
290 const auto& files = GetFiles(); 290 const auto& files = GetFiles();
291 const auto sum_sizes = [](const auto& range) { 291 const auto sum_sizes = [](const auto& range) {
292 return std::accumulate(range.begin(), range.end(), 0ULL, 292 return std::accumulate(range.begin(), range.end(), 0ULL,
@@ -434,13 +434,13 @@ bool ReadOnlyVfsDirectory::Rename(std::string_view name) {
434 return false; 434 return false;
435} 435}
436 436
437bool DeepEquals(const VirtualFile& file1, const VirtualFile& file2, size_t block_size) { 437bool DeepEquals(const VirtualFile& file1, const VirtualFile& file2, std::size_t block_size) {
438 if (file1->GetSize() != file2->GetSize()) 438 if (file1->GetSize() != file2->GetSize())
439 return false; 439 return false;
440 440
441 std::vector<u8> f1_v(block_size); 441 std::vector<u8> f1_v(block_size);
442 std::vector<u8> f2_v(block_size); 442 std::vector<u8> f2_v(block_size);
443 for (size_t i = 0; i < file1->GetSize(); i += block_size) { 443 for (std::size_t i = 0; i < file1->GetSize(); i += block_size) {
444 auto f1_vs = file1->Read(f1_v.data(), block_size, i); 444 auto f1_vs = file1->Read(f1_v.data(), block_size, i);
445 auto f2_vs = file2->Read(f2_v.data(), block_size, i); 445 auto f2_vs = file2->Read(f2_v.data(), block_size, i);
446 446
diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h
index 5142a3e86..74489b452 100644
--- a/src/core/file_sys/vfs.h
+++ b/src/core/file_sys/vfs.h
@@ -92,9 +92,9 @@ public:
92 // Retrieves the extension of the file name. 92 // Retrieves the extension of the file name.
93 virtual std::string GetExtension() const; 93 virtual std::string GetExtension() const;
94 // Retrieves the size of the file. 94 // Retrieves the size of the file.
95 virtual size_t GetSize() const = 0; 95 virtual std::size_t GetSize() const = 0;
96 // Resizes the file to new_size. Returns whether or not the operation was successful. 96 // Resizes the file to new_size. Returns whether or not the operation was successful.
97 virtual bool Resize(size_t new_size) = 0; 97 virtual bool Resize(std::size_t new_size) = 0;
98 // Gets a pointer to the directory containing this file, returning nullptr if there is none. 98 // Gets a pointer to the directory containing this file, returning nullptr if there is none.
99 virtual std::shared_ptr<VfsDirectory> GetContainingDirectory() const = 0; 99 virtual std::shared_ptr<VfsDirectory> GetContainingDirectory() const = 0;
100 100
@@ -105,15 +105,15 @@ public:
105 105
106 // The primary method of reading from the file. Reads length bytes into data starting at offset 106 // The primary method of reading from the file. Reads length bytes into data starting at offset
107 // into file. Returns number of bytes successfully read. 107 // into file. Returns number of bytes successfully read.
108 virtual size_t Read(u8* data, size_t length, size_t offset = 0) const = 0; 108 virtual std::size_t Read(u8* data, std::size_t length, std::size_t offset = 0) const = 0;
109 // The primary method of writing to the file. Writes length bytes from data starting at offset 109 // The primary method of writing to the file. Writes length bytes from data starting at offset
110 // into file. Returns number of bytes successfully written. 110 // into file. Returns number of bytes successfully written.
111 virtual size_t Write(const u8* data, size_t length, size_t offset = 0) = 0; 111 virtual std::size_t Write(const u8* data, std::size_t length, std::size_t offset = 0) = 0;
112 112
113 // Reads exactly one byte at the offset provided, returning boost::none on error. 113 // Reads exactly one byte at the offset provided, returning boost::none on error.
114 virtual boost::optional<u8> ReadByte(size_t offset = 0) const; 114 virtual boost::optional<u8> ReadByte(std::size_t offset = 0) const;
115 // Reads size bytes starting at offset in file into a vector. 115 // Reads size bytes starting at offset in file into a vector.
116 virtual std::vector<u8> ReadBytes(size_t size, size_t offset = 0) const; 116 virtual std::vector<u8> ReadBytes(std::size_t size, std::size_t offset = 0) const;
117 // Reads all the bytes from the file into a vector. Equivalent to 'file->Read(file->GetSize(), 117 // Reads all the bytes from the file into a vector. Equivalent to 'file->Read(file->GetSize(),
118 // 0)' 118 // 0)'
119 virtual std::vector<u8> ReadAllBytes() const; 119 virtual std::vector<u8> ReadAllBytes() const;
@@ -121,7 +121,7 @@ public:
121 // Reads an array of type T, size number_elements starting at offset. 121 // Reads an array of type T, size number_elements starting at offset.
122 // Returns the number of bytes (sizeof(T)*number_elements) read successfully. 122 // Returns the number of bytes (sizeof(T)*number_elements) read successfully.
123 template <typename T> 123 template <typename T>
124 size_t ReadArray(T* data, size_t number_elements, size_t offset = 0) const { 124 std::size_t ReadArray(T* data, std::size_t number_elements, std::size_t offset = 0) const {
125 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); 125 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable.");
126 126
127 return Read(reinterpret_cast<u8*>(data), number_elements * sizeof(T), offset); 127 return Read(reinterpret_cast<u8*>(data), number_elements * sizeof(T), offset);
@@ -130,7 +130,7 @@ public:
130 // Reads size bytes into the memory starting at data starting at offset into the file. 130 // Reads size bytes into the memory starting at data starting at offset into the file.
131 // Returns the number of bytes read successfully. 131 // Returns the number of bytes read successfully.
132 template <typename T> 132 template <typename T>
133 size_t ReadBytes(T* data, size_t size, size_t offset = 0) const { 133 std::size_t ReadBytes(T* data, std::size_t size, std::size_t offset = 0) const {
134 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); 134 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable.");
135 return Read(reinterpret_cast<u8*>(data), size, offset); 135 return Read(reinterpret_cast<u8*>(data), size, offset);
136 } 136 }
@@ -138,22 +138,22 @@ public:
138 // Reads one object of type T starting at offset in file. 138 // Reads one object of type T starting at offset in file.
139 // Returns the number of bytes read successfully (sizeof(T)). 139 // Returns the number of bytes read successfully (sizeof(T)).
140 template <typename T> 140 template <typename T>
141 size_t ReadObject(T* data, size_t offset = 0) const { 141 std::size_t ReadObject(T* data, std::size_t offset = 0) const {
142 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); 142 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable.");
143 return Read(reinterpret_cast<u8*>(data), sizeof(T), offset); 143 return Read(reinterpret_cast<u8*>(data), sizeof(T), offset);
144 } 144 }
145 145
146 // Writes exactly one byte to offset in file and retuns whether or not the byte was written 146 // Writes exactly one byte to offset in file and retuns whether or not the byte was written
147 // successfully. 147 // successfully.
148 virtual bool WriteByte(u8 data, size_t offset = 0); 148 virtual bool WriteByte(u8 data, std::size_t offset = 0);
149 // Writes a vector of bytes to offset in file and returns the number of bytes successfully 149 // Writes a vector of bytes to offset in file and returns the number of bytes successfully
150 // written. 150 // written.
151 virtual size_t WriteBytes(const std::vector<u8>& data, size_t offset = 0); 151 virtual std::size_t WriteBytes(const std::vector<u8>& data, std::size_t offset = 0);
152 152
153 // Writes an array of type T, size number_elements to offset in file. 153 // Writes an array of type T, size number_elements to offset in file.
154 // Returns the number of bytes (sizeof(T)*number_elements) written successfully. 154 // Returns the number of bytes (sizeof(T)*number_elements) written successfully.
155 template <typename T> 155 template <typename T>
156 size_t WriteArray(const T* data, size_t number_elements, size_t offset = 0) { 156 std::size_t WriteArray(const T* data, std::size_t number_elements, std::size_t offset = 0) {
157 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); 157 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable.");
158 return Write(data, number_elements * sizeof(T), offset); 158 return Write(data, number_elements * sizeof(T), offset);
159 } 159 }
@@ -161,7 +161,7 @@ public:
161 // Writes size bytes starting at memory location data to offset in file. 161 // Writes size bytes starting at memory location data to offset in file.
162 // Returns the number of bytes written successfully. 162 // Returns the number of bytes written successfully.
163 template <typename T> 163 template <typename T>
164 size_t WriteBytes(const T* data, size_t size, size_t offset = 0) { 164 std::size_t WriteBytes(const T* data, std::size_t size, std::size_t offset = 0) {
165 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); 165 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable.");
166 return Write(reinterpret_cast<const u8*>(data), size, offset); 166 return Write(reinterpret_cast<const u8*>(data), size, offset);
167 } 167 }
@@ -169,7 +169,7 @@ public:
169 // Writes one object of type T to offset in file. 169 // Writes one object of type T to offset in file.
170 // Returns the number of bytes written successfully (sizeof(T)). 170 // Returns the number of bytes written successfully (sizeof(T)).
171 template <typename T> 171 template <typename T>
172 size_t WriteObject(const T& data, size_t offset = 0) { 172 std::size_t WriteObject(const T& data, std::size_t offset = 0) {
173 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); 173 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable.");
174 return Write(&data, sizeof(T), offset); 174 return Write(&data, sizeof(T), offset);
175 } 175 }
@@ -221,7 +221,7 @@ public:
221 // Returns the name of the directory. 221 // Returns the name of the directory.
222 virtual std::string GetName() const = 0; 222 virtual std::string GetName() const = 0;
223 // Returns the total size of all files and subdirectories in this directory. 223 // Returns the total size of all files and subdirectories in this directory.
224 virtual size_t GetSize() const; 224 virtual std::size_t GetSize() const;
225 // Returns the parent directory of this directory. Returns nullptr if this directory is root or 225 // Returns the parent directory of this directory. Returns nullptr if this directory is root or
226 // has no parent. 226 // has no parent.
227 virtual std::shared_ptr<VfsDirectory> GetParentDirectory() const = 0; 227 virtual std::shared_ptr<VfsDirectory> GetParentDirectory() const = 0;
@@ -311,7 +311,7 @@ public:
311}; 311};
312 312
313// Compare the two files, byte-for-byte, in increments specificed by block_size 313// Compare the two files, byte-for-byte, in increments specificed by block_size
314bool DeepEquals(const VirtualFile& file1, const VirtualFile& file2, size_t block_size = 0x200); 314bool DeepEquals(const VirtualFile& file1, const VirtualFile& file2, std::size_t block_size = 0x200);
315 315
316// A method that copies the raw data between two different implementations of VirtualFile. If you 316// A method that copies the raw data between two different implementations of VirtualFile. If you
317// are using the same implementation, it is probably better to use the Copy method in the parent 317// are using the same implementation, it is probably better to use the Copy method in the parent
diff --git a/src/core/file_sys/vfs_concat.cpp b/src/core/file_sys/vfs_concat.cpp
index e6bf586a3..25a980cbb 100644
--- a/src/core/file_sys/vfs_concat.cpp
+++ b/src/core/file_sys/vfs_concat.cpp
@@ -20,7 +20,7 @@ VirtualFile ConcatenateFiles(std::vector<VirtualFile> files, std::string name) {
20 20
21ConcatenatedVfsFile::ConcatenatedVfsFile(std::vector<VirtualFile> files_, std::string name) 21ConcatenatedVfsFile::ConcatenatedVfsFile(std::vector<VirtualFile> files_, std::string name)
22 : name(std::move(name)) { 22 : name(std::move(name)) {
23 size_t next_offset = 0; 23 std::size_t next_offset = 0;
24 for (const auto& file : files_) { 24 for (const auto& file : files_) {
25 files[next_offset] = file; 25 files[next_offset] = file;
26 next_offset += file->GetSize(); 26 next_offset += file->GetSize();
@@ -35,13 +35,13 @@ std::string ConcatenatedVfsFile::GetName() const {
35 return files.begin()->second->GetName(); 35 return files.begin()->second->GetName();
36} 36}
37 37
38size_t ConcatenatedVfsFile::GetSize() const { 38std::size_t ConcatenatedVfsFile::GetSize() const {
39 if (files.empty()) 39 if (files.empty())
40 return 0; 40 return 0;
41 return files.rbegin()->first + files.rbegin()->second->GetSize(); 41 return files.rbegin()->first + files.rbegin()->second->GetSize();
42} 42}
43 43
44bool ConcatenatedVfsFile::Resize(size_t new_size) { 44bool ConcatenatedVfsFile::Resize(std::size_t new_size) {
45 return false; 45 return false;
46} 46}
47 47
@@ -59,7 +59,7 @@ bool ConcatenatedVfsFile::IsReadable() const {
59 return true; 59 return true;
60} 60}
61 61
62size_t ConcatenatedVfsFile::Read(u8* data, size_t length, size_t offset) const { 62std::size_t ConcatenatedVfsFile::Read(u8* data, std::size_t length, std::size_t offset) const {
63 auto entry = files.end(); 63 auto entry = files.end();
64 for (auto iter = files.begin(); iter != files.end(); ++iter) { 64 for (auto iter = files.begin(); iter != files.end(); ++iter) {
65 if (iter->first > offset) { 65 if (iter->first > offset) {
@@ -84,7 +84,7 @@ size_t ConcatenatedVfsFile::Read(u8* data, size_t length, size_t offset) const {
84 return entry->second->Read(data, length, offset - entry->first); 84 return entry->second->Read(data, length, offset - entry->first);
85} 85}
86 86
87size_t ConcatenatedVfsFile::Write(const u8* data, size_t length, size_t offset) { 87std::size_t ConcatenatedVfsFile::Write(const u8* data, std::size_t length, std::size_t offset) {
88 return 0; 88 return 0;
89} 89}
90 90
diff --git a/src/core/file_sys/vfs_concat.h b/src/core/file_sys/vfs_concat.h
index 686d32515..31775db7e 100644
--- a/src/core/file_sys/vfs_concat.h
+++ b/src/core/file_sys/vfs_concat.h
@@ -23,13 +23,13 @@ class ConcatenatedVfsFile : public VfsFile {
23 23
24public: 24public:
25 std::string GetName() const override; 25 std::string GetName() const override;
26 size_t GetSize() const override; 26 std::size_t GetSize() const override;
27 bool Resize(size_t new_size) override; 27 bool Resize(std::size_t new_size) override;
28 std::shared_ptr<VfsDirectory> GetContainingDirectory() const override; 28 std::shared_ptr<VfsDirectory> GetContainingDirectory() const override;
29 bool IsWritable() const override; 29 bool IsWritable() const override;
30 bool IsReadable() const override; 30 bool IsReadable() const override;
31 size_t Read(u8* data, size_t length, size_t offset) const override; 31 std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override;
32 size_t Write(const u8* data, size_t length, size_t offset) override; 32 std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override;
33 bool Rename(std::string_view name) override; 33 bool Rename(std::string_view name) override;
34 34
35private: 35private:
diff --git a/src/core/file_sys/vfs_offset.cpp b/src/core/file_sys/vfs_offset.cpp
index 847cde2f5..f5ed291ea 100644
--- a/src/core/file_sys/vfs_offset.cpp
+++ b/src/core/file_sys/vfs_offset.cpp
@@ -9,7 +9,7 @@
9 9
10namespace FileSys { 10namespace FileSys {
11 11
12OffsetVfsFile::OffsetVfsFile(std::shared_ptr<VfsFile> file_, size_t size_, size_t offset_, 12OffsetVfsFile::OffsetVfsFile(std::shared_ptr<VfsFile> file_, std::size_t size_, std::size_t offset_,
13 std::string name_, VirtualDir parent_) 13 std::string name_, VirtualDir parent_)
14 : file(file_), offset(offset_), size(size_), name(std::move(name_)), 14 : file(file_), offset(offset_), size(size_), name(std::move(name_)),
15 parent(parent_ == nullptr ? file->GetContainingDirectory() : std::move(parent_)) {} 15 parent(parent_ == nullptr ? file->GetContainingDirectory() : std::move(parent_)) {}
@@ -18,11 +18,11 @@ std::string OffsetVfsFile::GetName() const {
18 return name.empty() ? file->GetName() : name; 18 return name.empty() ? file->GetName() : name;
19} 19}
20 20
21size_t OffsetVfsFile::GetSize() const { 21std::size_t OffsetVfsFile::GetSize() const {
22 return size; 22 return size;
23} 23}
24 24
25bool OffsetVfsFile::Resize(size_t new_size) { 25bool OffsetVfsFile::Resize(std::size_t new_size) {
26 if (offset + new_size < file->GetSize()) { 26 if (offset + new_size < file->GetSize()) {
27 size = new_size; 27 size = new_size;
28 } else { 28 } else {
@@ -47,22 +47,22 @@ bool OffsetVfsFile::IsReadable() const {
47 return file->IsReadable(); 47 return file->IsReadable();
48} 48}
49 49
50size_t OffsetVfsFile::Read(u8* data, size_t length, size_t r_offset) const { 50std::size_t OffsetVfsFile::Read(u8* data, std::size_t length, std::size_t r_offset) const {
51 return file->Read(data, TrimToFit(length, r_offset), offset + r_offset); 51 return file->Read(data, TrimToFit(length, r_offset), offset + r_offset);
52} 52}
53 53
54size_t OffsetVfsFile::Write(const u8* data, size_t length, size_t r_offset) { 54std::size_t OffsetVfsFile::Write(const u8* data, std::size_t length, std::size_t r_offset) {
55 return file->Write(data, TrimToFit(length, r_offset), offset + r_offset); 55 return file->Write(data, TrimToFit(length, r_offset), offset + r_offset);
56} 56}
57 57
58boost::optional<u8> OffsetVfsFile::ReadByte(size_t r_offset) const { 58boost::optional<u8> OffsetVfsFile::ReadByte(std::size_t r_offset) const {
59 if (r_offset < size) 59 if (r_offset < size)
60 return file->ReadByte(offset + r_offset); 60 return file->ReadByte(offset + r_offset);
61 61
62 return boost::none; 62 return boost::none;
63} 63}
64 64
65std::vector<u8> OffsetVfsFile::ReadBytes(size_t r_size, size_t r_offset) const { 65std::vector<u8> OffsetVfsFile::ReadBytes(std::size_t r_size, std::size_t r_offset) const {
66 return file->ReadBytes(TrimToFit(r_size, r_offset), offset + r_offset); 66 return file->ReadBytes(TrimToFit(r_size, r_offset), offset + r_offset);
67} 67}
68 68
@@ -70,14 +70,14 @@ std::vector<u8> OffsetVfsFile::ReadAllBytes() const {
70 return file->ReadBytes(size, offset); 70 return file->ReadBytes(size, offset);
71} 71}
72 72
73bool OffsetVfsFile::WriteByte(u8 data, size_t r_offset) { 73bool OffsetVfsFile::WriteByte(u8 data, std::size_t r_offset) {
74 if (r_offset < size) 74 if (r_offset < size)
75 return file->WriteByte(data, offset + r_offset); 75 return file->WriteByte(data, offset + r_offset);
76 76
77 return false; 77 return false;
78} 78}
79 79
80size_t OffsetVfsFile::WriteBytes(const std::vector<u8>& data, size_t r_offset) { 80std::size_t OffsetVfsFile::WriteBytes(const std::vector<u8>& data, std::size_t r_offset) {
81 return file->Write(data.data(), TrimToFit(data.size(), r_offset), offset + r_offset); 81 return file->Write(data.data(), TrimToFit(data.size(), r_offset), offset + r_offset);
82} 82}
83 83
@@ -85,12 +85,12 @@ bool OffsetVfsFile::Rename(std::string_view name) {
85 return file->Rename(name); 85 return file->Rename(name);
86} 86}
87 87
88size_t OffsetVfsFile::GetOffset() const { 88std::size_t OffsetVfsFile::GetOffset() const {
89 return offset; 89 return offset;
90} 90}
91 91
92size_t OffsetVfsFile::TrimToFit(size_t r_size, size_t r_offset) const { 92std::size_t OffsetVfsFile::TrimToFit(std::size_t r_size, std::size_t r_offset) const {
93 return std::clamp(r_size, size_t{0}, size - r_offset); 93 return std::clamp(r_size, std::size_t{0}, size - r_offset);
94} 94}
95 95
96} // namespace FileSys 96} // namespace FileSys
diff --git a/src/core/file_sys/vfs_offset.h b/src/core/file_sys/vfs_offset.h
index cb92d1570..34cb180b3 100644
--- a/src/core/file_sys/vfs_offset.h
+++ b/src/core/file_sys/vfs_offset.h
@@ -17,33 +17,33 @@ namespace FileSys {
17// the size of this wrapper. 17// the size of this wrapper.
18class OffsetVfsFile : public VfsFile { 18class OffsetVfsFile : public VfsFile {
19public: 19public:
20 OffsetVfsFile(std::shared_ptr<VfsFile> file, size_t size, size_t offset = 0, 20 OffsetVfsFile(std::shared_ptr<VfsFile> file, std::size_t size, std::size_t offset = 0,
21 std::string new_name = "", VirtualDir new_parent = nullptr); 21 std::string new_name = "", VirtualDir new_parent = nullptr);
22 22
23 std::string GetName() const override; 23 std::string GetName() const override;
24 size_t GetSize() const override; 24 std::size_t GetSize() const override;
25 bool Resize(size_t new_size) override; 25 bool Resize(std::size_t new_size) override;
26 std::shared_ptr<VfsDirectory> GetContainingDirectory() const override; 26 std::shared_ptr<VfsDirectory> GetContainingDirectory() const override;
27 bool IsWritable() const override; 27 bool IsWritable() const override;
28 bool IsReadable() const override; 28 bool IsReadable() const override;
29 size_t Read(u8* data, size_t length, size_t offset) const override; 29 std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override;
30 size_t Write(const u8* data, size_t length, size_t offset) override; 30 std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override;
31 boost::optional<u8> ReadByte(size_t offset) const override; 31 boost::optional<u8> ReadByte(std::size_t offset) const override;
32 std::vector<u8> ReadBytes(size_t size, size_t offset) const override; 32 std::vector<u8> ReadBytes(std::size_t size, std::size_t offset) const override;
33 std::vector<u8> ReadAllBytes() const override; 33 std::vector<u8> ReadAllBytes() const override;
34 bool WriteByte(u8 data, size_t offset) override; 34 bool WriteByte(u8 data, std::size_t offset) override;
35 size_t WriteBytes(const std::vector<u8>& data, size_t offset) override; 35 std::size_t WriteBytes(const std::vector<u8>& data, std::size_t offset) override;
36 36
37 bool Rename(std::string_view name) override; 37 bool Rename(std::string_view name) override;
38 38
39 size_t GetOffset() const; 39 std::size_t GetOffset() const;
40 40
41private: 41private:
42 size_t TrimToFit(size_t r_size, size_t r_offset) const; 42 std::size_t TrimToFit(std::size_t r_size, std::size_t r_offset) const;
43 43
44 std::shared_ptr<VfsFile> file; 44 std::shared_ptr<VfsFile> file;
45 size_t offset; 45 std::size_t offset;
46 size_t size; 46 std::size_t size;
47 std::string name; 47 std::string name;
48 VirtualDir parent; 48 VirtualDir parent;
49}; 49};
diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp
index 89b101145..5e242e20f 100644
--- a/src/core/file_sys/vfs_real.cpp
+++ b/src/core/file_sys/vfs_real.cpp
@@ -227,11 +227,11 @@ std::string RealVfsFile::GetName() const {
227 return path_components.back(); 227 return path_components.back();
228} 228}
229 229
230size_t RealVfsFile::GetSize() const { 230std::size_t RealVfsFile::GetSize() const {
231 return backing->GetSize(); 231 return backing->GetSize();
232} 232}
233 233
234bool RealVfsFile::Resize(size_t new_size) { 234bool RealVfsFile::Resize(std::size_t new_size) {
235 return backing->Resize(new_size); 235 return backing->Resize(new_size);
236} 236}
237 237
@@ -247,13 +247,13 @@ bool RealVfsFile::IsReadable() const {
247 return (perms & Mode::ReadWrite) != 0; 247 return (perms & Mode::ReadWrite) != 0;
248} 248}
249 249
250size_t RealVfsFile::Read(u8* data, size_t length, size_t offset) const { 250std::size_t RealVfsFile::Read(u8* data, std::size_t length, std::size_t offset) const {
251 if (!backing->Seek(offset, SEEK_SET)) 251 if (!backing->Seek(offset, SEEK_SET))
252 return 0; 252 return 0;
253 return backing->ReadBytes(data, length); 253 return backing->ReadBytes(data, length);
254} 254}
255 255
256size_t RealVfsFile::Write(const u8* data, size_t length, size_t offset) { 256std::size_t RealVfsFile::Write(const u8* data, std::size_t length, std::size_t offset) {
257 if (!backing->Seek(offset, SEEK_SET)) 257 if (!backing->Seek(offset, SEEK_SET))
258 return 0; 258 return 0;
259 return backing->WriteBytes(data, length); 259 return backing->WriteBytes(data, length);
diff --git a/src/core/file_sys/vfs_real.h b/src/core/file_sys/vfs_real.h
index 7db86691f..681c43e82 100644
--- a/src/core/file_sys/vfs_real.h
+++ b/src/core/file_sys/vfs_real.h
@@ -48,13 +48,13 @@ public:
48 ~RealVfsFile() override; 48 ~RealVfsFile() override;
49 49
50 std::string GetName() const override; 50 std::string GetName() const override;
51 size_t GetSize() const override; 51 std::size_t GetSize() const override;
52 bool Resize(size_t new_size) override; 52 bool Resize(std::size_t new_size) override;
53 std::shared_ptr<VfsDirectory> GetContainingDirectory() const override; 53 std::shared_ptr<VfsDirectory> GetContainingDirectory() const override;
54 bool IsWritable() const override; 54 bool IsWritable() const override;
55 bool IsReadable() const override; 55 bool IsReadable() const override;
56 size_t Read(u8* data, size_t length, size_t offset) const override; 56 std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override;
57 size_t Write(const u8* data, size_t length, size_t offset) override; 57 std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override;
58 bool Rename(std::string_view name) override; 58 bool Rename(std::string_view name) override;
59 59
60private: 60private:
diff --git a/src/core/file_sys/xts_archive.cpp b/src/core/file_sys/xts_archive.cpp
index 4dbc25c55..0173f71c1 100644
--- a/src/core/file_sys/xts_archive.cpp
+++ b/src/core/file_sys/xts_archive.cpp
@@ -25,8 +25,8 @@ namespace FileSys {
25constexpr u64 NAX_HEADER_PADDING_SIZE = 0x4000; 25constexpr u64 NAX_HEADER_PADDING_SIZE = 0x4000;
26 26
27template <typename SourceData, typename SourceKey, typename Destination> 27template <typename SourceData, typename SourceKey, typename Destination>
28static bool CalculateHMAC256(Destination* out, const SourceKey* key, size_t key_length, 28static bool CalculateHMAC256(Destination* out, const SourceKey* key, std::size_t key_length,
29 const SourceData* data, size_t data_length) { 29 const SourceData* data, std::size_t data_length) {
30 mbedtls_md_context_t context; 30 mbedtls_md_context_t context;
31 mbedtls_md_init(&context); 31 mbedtls_md_init(&context);
32 32
@@ -91,7 +91,7 @@ Loader::ResultStatus NAX::Parse(std::string_view path) {
91 91
92 const auto enc_keys = header->key_area; 92 const auto enc_keys = header->key_area;
93 93
94 size_t i = 0; 94 std::size_t i = 0;
95 for (; i < sd_keys.size(); ++i) { 95 for (; i < sd_keys.size(); ++i) {
96 std::array<Core::Crypto::Key128, 2> nax_keys{}; 96 std::array<Core::Crypto::Key128, 2> nax_keys{};
97 if (!CalculateHMAC256(nax_keys.data(), sd_keys[i].data(), 0x10, std::string(path).c_str(), 97 if (!CalculateHMAC256(nax_keys.data(), sd_keys[i].data(), 0x10, std::string(path).c_str(),
@@ -99,7 +99,7 @@ Loader::ResultStatus NAX::Parse(std::string_view path) {
99 return Loader::ResultStatus::ErrorNAXKeyHMACFailed; 99 return Loader::ResultStatus::ErrorNAXKeyHMACFailed;
100 } 100 }
101 101
102 for (size_t j = 0; j < nax_keys.size(); ++j) { 102 for (std::size_t j = 0; j < nax_keys.size(); ++j) {
103 Core::Crypto::AESCipher<Core::Crypto::Key128> cipher(nax_keys[j], 103 Core::Crypto::AESCipher<Core::Crypto::Key128> cipher(nax_keys[j],
104 Core::Crypto::Mode::ECB); 104 Core::Crypto::Mode::ECB);
105 cipher.Transcode(enc_keys[j].data(), 0x10, header->key_area[j].data(), 105 cipher.Transcode(enc_keys[j].data(), 0x10, header->key_area[j].data(),