summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/file_sys/partition_filesystem.cpp29
-rw-r--r--src/core/file_sys/partition_filesystem.h10
-rw-r--r--src/core/file_sys/savedata_factory.cpp2
-rw-r--r--src/core/file_sys/savedata_factory.h2
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp2
-rw-r--r--src/core/hle/service/filesystem/filesystem.cpp6
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.cpp39
-rw-r--r--src/core/loader/nro.cpp2
-rw-r--r--src/core/loader/nso.cpp8
9 files changed, 47 insertions, 53 deletions
diff --git a/src/core/file_sys/partition_filesystem.cpp b/src/core/file_sys/partition_filesystem.cpp
index 15b1fb946..d4097a510 100644
--- a/src/core/file_sys/partition_filesystem.cpp
+++ b/src/core/file_sys/partition_filesystem.cpp
@@ -11,6 +11,11 @@
namespace FileSys {
+bool PartitionFilesystem::Header::HasValidMagicValue() const {
+ return magic == Common::MakeMagic('H', 'F', 'S', '0') ||
+ magic == Common::MakeMagic('P', 'F', 'S', '0');
+}
+
PartitionFilesystem::PartitionFilesystem(std::shared_ptr<VfsFile> file) {
// At least be as large as the header
if (file->GetSize() < sizeof(Header)) {
@@ -20,19 +25,17 @@ PartitionFilesystem::PartitionFilesystem(std::shared_ptr<VfsFile> file) {
// For cartridges, HFSs can get very large, so we need to calculate the size up to
// the actual content itself instead of just blindly reading in the entire file.
- Header pfs_header;
if (sizeof(Header) != file->ReadObject(&pfs_header)) {
status = Loader::ResultStatus::Error;
return;
}
- if (pfs_header.magic != Common::MakeMagic('H', 'F', 'S', '0') &&
- pfs_header.magic != Common::MakeMagic('P', 'F', 'S', '0')) {
+ if (!pfs_header.HasValidMagicValue()) {
status = Loader::ResultStatus::ErrorInvalidFormat;
return;
}
- bool is_hfs = pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0');
+ is_hfs = pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0');
size_t entry_size = is_hfs ? sizeof(HFSEntry) : sizeof(PFSEntry);
size_t metadata_size =
@@ -40,27 +43,13 @@ PartitionFilesystem::PartitionFilesystem(std::shared_ptr<VfsFile> file) {
// Actually read in now...
std::vector<u8> file_data = file->ReadBytes(metadata_size);
+ const size_t total_size = file_data.size();
- if (file_data.size() != metadata_size) {
- status = Loader::ResultStatus::Error;
- return;
- }
-
- size_t total_size = file_data.size();
- if (total_size < sizeof(Header)) {
+ if (total_size != metadata_size) {
status = Loader::ResultStatus::Error;
return;
}
- memcpy(&pfs_header, file_data.data(), sizeof(Header));
- if (pfs_header.magic != Common::MakeMagic('H', 'F', 'S', '0') &&
- pfs_header.magic != Common::MakeMagic('P', 'F', 'S', '0')) {
- status = Loader::ResultStatus::ErrorInvalidFormat;
- return;
- }
-
- is_hfs = pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0');
-
size_t entries_offset = sizeof(Header);
size_t strtab_offset = entries_offset + (pfs_header.num_entries * entry_size);
content_offset = strtab_offset + pfs_header.strtab_size;
diff --git a/src/core/file_sys/partition_filesystem.h b/src/core/file_sys/partition_filesystem.h
index 9656b40bf..7c7a75816 100644
--- a/src/core/file_sys/partition_filesystem.h
+++ b/src/core/file_sys/partition_filesystem.h
@@ -42,6 +42,8 @@ private:
u32_le num_entries;
u32_le strtab_size;
INSERT_PADDING_BYTES(0x4);
+
+ bool HasValidMagicValue() const;
};
static_assert(sizeof(Header) == 0x10, "PFS/HFS header structure size is wrong");
@@ -73,11 +75,11 @@ private:
#pragma pack(pop)
- Loader::ResultStatus status;
+ Loader::ResultStatus status{};
- Header pfs_header;
- bool is_hfs;
- size_t content_offset;
+ Header pfs_header{};
+ bool is_hfs = false;
+ size_t content_offset = 0;
std::vector<VirtualFile> pfs_files;
std::vector<VirtualDir> pfs_dirs;
diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp
index 6a53b2b10..dfdca83d6 100644
--- a/src/core/file_sys/savedata_factory.cpp
+++ b/src/core/file_sys/savedata_factory.cpp
@@ -11,7 +11,7 @@
namespace FileSys {
-std::string SaveDataDescriptor::DebugInfo() {
+std::string SaveDataDescriptor::DebugInfo() const {
return fmt::format("[type={:02X}, title_id={:016X}, user_id={:016X}{:016X}, save_id={:016X}]",
static_cast<u8>(type), title_id, user_id[1], user_id[0], save_id);
}
diff --git a/src/core/file_sys/savedata_factory.h b/src/core/file_sys/savedata_factory.h
index 53c69876f..e3a578c0f 100644
--- a/src/core/file_sys/savedata_factory.h
+++ b/src/core/file_sys/savedata_factory.h
@@ -37,7 +37,7 @@ struct SaveDataDescriptor {
u64_le zero_2;
u64_le zero_3;
- std::string DebugInfo();
+ std::string DebugInfo() const;
};
static_assert(sizeof(SaveDataDescriptor) == 0x40, "SaveDataDescriptor has incorrect size.");
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp
index b89c8c33d..911e6fbc1 100644
--- a/src/core/hle/kernel/hle_ipc.cpp
+++ b/src/core/hle/kernel/hle_ipc.cpp
@@ -302,7 +302,7 @@ size_t HLERequestContext::WriteBuffer(const void* buffer, size_t size, int buffe
}
size_t HLERequestContext::WriteBuffer(const std::vector<u8>& buffer, int buffer_index) const {
- return WriteBuffer(buffer.data(), buffer.size());
+ return WriteBuffer(buffer.data(), buffer.size(), buffer_index);
}
size_t HLERequestContext::GetReadBufferSize(int buffer_index) const {
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp
index a97d70a58..dffcdfbaf 100644
--- a/src/core/hle/service/filesystem/filesystem.cpp
+++ b/src/core/hle/service/filesystem/filesystem.cpp
@@ -2,7 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
-#pragma optimize("", off)
+#include <utility>
#include "common/assert.h"
#include "common/file_util.h"
@@ -25,14 +25,14 @@ constexpr u64 EMULATED_SD_REPORTED_SIZE = 32000000000;
static FileSys::VirtualDir GetDirectoryRelativeWrapped(FileSys::VirtualDir base,
const std::string& dir_name) {
- if (dir_name == "." || dir_name == "" || dir_name == "/" || dir_name == "\\")
+ if (dir_name.empty() || dir_name == "." || dir_name == "/" || dir_name == "\\")
return base;
return base->GetDirectoryRelative(dir_name);
}
VfsDirectoryServiceWrapper::VfsDirectoryServiceWrapper(FileSys::VirtualDir backing_)
- : backing(backing_) {}
+ : backing(std::move(backing_)) {}
std::string VfsDirectoryServiceWrapper::GetName() const {
return backing->GetName();
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp
index 1b003bd84..e7ffb6bd1 100644
--- a/src/core/hle/service/filesystem/fsp_srv.cpp
+++ b/src/core/hle/service/filesystem/fsp_srv.cpp
@@ -3,6 +3,14 @@
// Refer to the license.txt file included.
#include <cinttypes>
+#include <cstring>
+#include <iterator>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "common/assert.h"
+#include "common/common_types.h"
#include "common/logging/log.h"
#include "common/string_util.h"
#include "core/core.h"
@@ -26,7 +34,7 @@ enum class StorageId : u8 {
class IStorage final : public ServiceFramework<IStorage> {
public:
- IStorage(FileSys::VirtualFile backend_)
+ explicit IStorage(FileSys::VirtualFile backend_)
: ServiceFramework("IStorage"), backend(std::move(backend_)) {
static const FunctionInfo functions[] = {
{0, &IStorage::Read, "Read"}, {1, nullptr, "Write"}, {2, nullptr, "Flush"},
@@ -133,19 +141,19 @@ private:
return;
}
- std::vector<u8> data = ctx.ReadBuffer();
- std::vector<u8> actual_data(length);
+ const std::vector<u8> data = ctx.ReadBuffer();
ASSERT_MSG(
- data.size() <= length,
+ static_cast<s64>(data.size()) <= length,
"Attempting to write more data than requested (requested={:016X}, actual={:016X}).",
length, data.size());
- std::copy(data.begin(), data.end(), actual_data.begin());
// Write the data to the Storage backend
- auto written = backend->WriteBytes(data, offset);
+ const auto write_size =
+ static_cast<std::size_t>(std::distance(data.begin(), data.begin() + length));
+ const std::size_t written = backend->Write(data.data(), write_size, offset);
- ASSERT_MSG(written == length,
+ ASSERT_MSG(static_cast<s64>(written) == length,
"Could not write all bytes to file (requested={:016X}, actual={:016X}).", length,
written);
@@ -223,23 +231,20 @@ private:
LOG_DEBUG(Service_FS, "called, unk=0x{:X}", unk);
// Calculate how many entries we can fit in the output buffer
- u64 count_entries = ctx.GetWriteBufferSize() / sizeof(FileSys::Entry);
+ const u64 count_entries = ctx.GetWriteBufferSize() / sizeof(FileSys::Entry);
// Cap at total number of entries.
- u64 actual_entries = std::min(count_entries, entries.size() - next_entry_index);
+ const u64 actual_entries = std::min(count_entries, entries.size() - next_entry_index);
- // Read the data from the Directory backend
- std::vector<FileSys::Entry> entry_data(entries.begin() + next_entry_index,
- entries.begin() + next_entry_index + actual_entries);
+ // Determine data start and end
+ const auto* begin = reinterpret_cast<u8*>(entries.data() + next_entry_index);
+ const auto* end = reinterpret_cast<u8*>(entries.data() + next_entry_index + actual_entries);
+ const auto range_size = static_cast<std::size_t>(std::distance(begin, end));
next_entry_index += actual_entries;
- // Convert the data into a byte array
- std::vector<u8> output(entry_data.size() * sizeof(FileSys::Entry));
- std::memcpy(output.data(), entry_data.data(), output.size());
-
// Write the data to memory
- ctx.WriteBuffer(output);
+ ctx.WriteBuffer(begin, range_size);
IPC::ResponseBuilder rb{ctx, 4};
rb.Push(RESULT_SUCCESS);
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp
index a007d3e6e..465b827bb 100644
--- a/src/core/loader/nro.cpp
+++ b/src/core/loader/nro.cpp
@@ -82,7 +82,7 @@ bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) {
if (program_image.size() != PageAlignSize(nro_header.file_size))
return {};
- for (int i = 0; i < nro_header.segments.size(); ++i) {
+ for (std::size_t i = 0; i < nro_header.segments.size(); ++i) {
codeset->segments[i].addr = nro_header.segments[i].offset;
codeset->segments[i].offset = nro_header.segments[i].offset;
codeset->segments[i].size = PageAlignSize(nro_header.segments[i].size);
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp
index 2beb85fbf..f7752e0e3 100644
--- a/src/core/loader/nso.cpp
+++ b/src/core/loader/nso.cpp
@@ -66,8 +66,7 @@ FileType AppLoader_NSO::IdentifyType(const FileSys::VirtualFile& file) {
static std::vector<u8> DecompressSegment(const std::vector<u8>& compressed_data,
const NsoSegmentHeader& header) {
- std::vector<u8> uncompressed_data;
- uncompressed_data.resize(header.size);
+ std::vector<u8> uncompressed_data(header.size);
const int bytes_uncompressed = LZ4_decompress_safe(
reinterpret_cast<const char*>(compressed_data.data()),
reinterpret_cast<char*>(uncompressed_data.data()), compressed_data.size(), header.size);
@@ -80,8 +79,7 @@ static std::vector<u8> DecompressSegment(const std::vector<u8>& compressed_data,
static std::vector<u8> ReadSegment(FileUtil::IOFile& file, const NsoSegmentHeader& header,
size_t compressed_size) {
- std::vector<u8> compressed_data;
- compressed_data.resize(compressed_size);
+ std::vector<u8> compressed_data(compressed_size);
file.Seek(header.offset, SEEK_SET);
if (compressed_size != file.ReadBytes(compressed_data.data(), compressed_size)) {
@@ -113,7 +111,7 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base) {
// Build program image
Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create("");
std::vector<u8> program_image;
- for (int i = 0; i < nso_header.segments.size(); ++i) {
+ for (std::size_t i = 0; i < nso_header.segments.size(); ++i) {
const std::vector<u8> compressed_data =
file->ReadBytes(nso_header.segments_compressed_size[i], nso_header.segments[i].offset);
std::vector<u8> data = DecompressSegment(compressed_data, nso_header.segments[i]);