aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/file_sys/ivfc_archive.cpp
diff options
context:
space:
mode:
authorGravatar bunnei <bunneidev@gmail.com>2015-07-16 18:08:46 -0400
committerGravatar bunnei <bunneidev@gmail.com>2015-07-16 18:08:46 -0400
commit946f0ee2f4f5e150167ad90f86a425b50baec144 (patch)
tree47586aae7237dddc7278ef5e579cf82ad1b64e11 /src/core/file_sys/ivfc_archive.cpp
parent0ea2319f3c371dc5dd86fbfabfe5b54392d4b664 (diff)
parent62c2a262b2992ed5f56db098b2009ec1a20480bf (diff)
Merge pull request #918 from yuriks/romfs
Do not load entire RomFS to memory, read from the file as needed instead (rebased)
Diffstat (limited to 'src/core/file_sys/ivfc_archive.cpp')
-rw-r--r--src/core/file_sys/ivfc_archive.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/core/file_sys/ivfc_archive.cpp b/src/core/file_sys/ivfc_archive.cpp
index c88b39bc..e16aa149 100644
--- a/src/core/file_sys/ivfc_archive.cpp
+++ b/src/core/file_sys/ivfc_archive.cpp
@@ -16,15 +16,12 @@
namespace FileSys {
-IVFCArchive::IVFCArchive(std::shared_ptr<const std::vector<u8>> data) : data(data) {
-}
-
std::string IVFCArchive::GetName() const {
return "IVFC";
}
std::unique_ptr<FileBackend> IVFCArchive::OpenFile(const Path& path, const Mode mode) const {
- return Common::make_unique<IVFCFile>(data);
+ return Common::make_unique<IVFCFile>(romfs_file, data_offset, data_size);
}
bool IVFCArchive::DeleteFile(const Path& path) const {
@@ -64,19 +61,21 @@ std::unique_ptr<DirectoryBackend> IVFCArchive::OpenDirectory(const Path& path) c
////////////////////////////////////////////////////////////////////////////////////////////////////
-size_t IVFCFile::Read(const u64 offset, const u32 length, u8* buffer) const {
+size_t IVFCFile::Read(const u64 offset, const size_t length, u8* buffer) const {
LOG_TRACE(Service_FS, "called offset=%llu, length=%d", offset, length);
- memcpy(buffer, data->data() + offset, length);
- return length;
+ romfs_file->Seek(data_offset + offset, SEEK_SET);
+ size_t read_length = (size_t)std::min((u64)length, data_size - offset);
+
+ return romfs_file->ReadBytes(buffer, read_length);
}
-size_t IVFCFile::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const {
+size_t IVFCFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const {
LOG_ERROR(Service_FS, "Attempted to write to IVFC file");
return 0;
}
-size_t IVFCFile::GetSize() const {
- return sizeof(u8) * data->size();
+u64 IVFCFile::GetSize() const {
+ return data_size;
}
bool IVFCFile::SetSize(const u64 size) const {