aboutsummaryrefslogtreecommitdiffhomepage
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/archive_romfs.cpp7
-rw-r--r--src/core/file_sys/archive_romfs.h6
-rw-r--r--src/core/file_sys/archive_savedatacheck.cpp11
-rw-r--r--src/core/file_sys/disk_archive.cpp8
-rw-r--r--src/core/file_sys/disk_archive.h8
-rw-r--r--src/core/file_sys/file_backend.h8
-rw-r--r--src/core/file_sys/ivfc_archive.cpp19
-rw-r--r--src/core/file_sys/ivfc_archive.h23
8 files changed, 47 insertions, 43 deletions
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
index c1e45dfe..696b51a9 100644
--- a/src/core/file_sys/archive_romfs.cpp
+++ b/src/core/file_sys/archive_romfs.cpp
@@ -17,16 +17,15 @@
namespace FileSys {
-ArchiveFactory_RomFS::ArchiveFactory_RomFS(const Loader::AppLoader& app_loader)
- : romfs_data(std::make_shared<std::vector<u8>>()) {
+ArchiveFactory_RomFS::ArchiveFactory_RomFS(Loader::AppLoader& app_loader) {
// Load the RomFS from the app
- if (Loader::ResultStatus::Success != app_loader.ReadRomFS(*romfs_data)) {
+ if (Loader::ResultStatus::Success != app_loader.ReadRomFS(romfs_file, data_offset, data_size)) {
LOG_ERROR(Service_FS, "Unable to read RomFS!");
}
}
ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_RomFS::Open(const Path& path) {
- auto archive = Common::make_unique<IVFCArchive>(romfs_data);
+ auto archive = Common::make_unique<IVFCArchive>(romfs_file, data_offset, data_size);
return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
}
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h
index c69ff91c..2bedfa9c 100644
--- a/src/core/file_sys/archive_romfs.h
+++ b/src/core/file_sys/archive_romfs.h
@@ -22,14 +22,16 @@ namespace FileSys {
/// File system interface to the RomFS archive
class ArchiveFactory_RomFS final : public ArchiveFactory {
public:
- ArchiveFactory_RomFS(const Loader::AppLoader& app_loader);
+ ArchiveFactory_RomFS(Loader::AppLoader& app_loader);
std::string GetName() const override { return "RomFS"; }
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override;
ResultCode Format(const Path& path) override;
private:
- std::shared_ptr<std::vector<u8>> romfs_data;
+ std::shared_ptr<FileUtil::IOFile> romfs_file;
+ u64 data_offset;
+ u64 data_size;
};
} // namespace FileSys
diff --git a/src/core/file_sys/archive_savedatacheck.cpp b/src/core/file_sys/archive_savedatacheck.cpp
index dec838ca..ea1dfe2c 100644
--- a/src/core/file_sys/archive_savedatacheck.cpp
+++ b/src/core/file_sys/archive_savedatacheck.cpp
@@ -37,17 +37,14 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveDataCheck::Open(co
auto vec = path.AsBinary();
const u32* data = reinterpret_cast<u32*>(vec.data());
std::string file_path = GetSaveDataCheckPath(mount_point, data[1], data[0]);
- FileUtil::IOFile file(file_path, "rb");
+ auto file = std::make_shared<FileUtil::IOFile>(file_path, "rb");
- if (!file.IsOpen()) {
+ if (!file->IsOpen()) {
return ResultCode(-1); // TODO(Subv): Find the right error code
}
- auto size = file.GetSize();
- auto raw_data = std::make_shared<std::vector<u8>>(size);
- file.ReadBytes(raw_data->data(), size);
- file.Close();
+ auto size = file->GetSize();
- auto archive = Common::make_unique<IVFCArchive>(std::move(raw_data));
+ auto archive = Common::make_unique<IVFCArchive>(file, 0, size);
return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
}
diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp
index 85151a31..1096fd34 100644
--- a/src/core/file_sys/disk_archive.cpp
+++ b/src/core/file_sys/disk_archive.cpp
@@ -105,12 +105,12 @@ bool DiskFile::Open() {
return true;
}
-size_t DiskFile::Read(const u64 offset, const u32 length, u8* buffer) const {
+size_t DiskFile::Read(const u64 offset, const size_t length, u8* buffer) const {
file->Seek(offset, SEEK_SET);
return file->ReadBytes(buffer, length);
}
-size_t DiskFile::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const {
+size_t DiskFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const {
file->Seek(offset, SEEK_SET);
size_t written = file->WriteBytes(buffer, length);
if (flush)
@@ -118,8 +118,8 @@ size_t DiskFile::Write(const u64 offset, const u32 length, const u32 flush, cons
return written;
}
-size_t DiskFile::GetSize() const {
- return static_cast<size_t>(file->GetSize());
+u64 DiskFile::GetSize() const {
+ return file->GetSize();
}
bool DiskFile::SetSize(const u64 size) const {
diff --git a/src/core/file_sys/disk_archive.h b/src/core/file_sys/disk_archive.h
index 5cfcddf6..c5da0750 100644
--- a/src/core/file_sys/disk_archive.h
+++ b/src/core/file_sys/disk_archive.h
@@ -55,10 +55,10 @@ public:
DiskFile(const DiskArchive& archive, const Path& path, const Mode mode);
bool Open() override;
- size_t Read(const u64 offset, const u32 length, u8* buffer) const override;
- size_t Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const override;
- size_t GetSize() const override;
- bool SetSize(const u64 size) const override;
+ size_t Read(u64 offset, size_t length, u8* buffer) const override;
+ size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const override;
+ u64 GetSize() const override;
+ bool SetSize(u64 size) const override;
bool Close() const override;
void Flush() const override {
diff --git a/src/core/file_sys/file_backend.h b/src/core/file_sys/file_backend.h
index f5f72c72..df7165df 100644
--- a/src/core/file_sys/file_backend.h
+++ b/src/core/file_sys/file_backend.h
@@ -31,7 +31,7 @@ public:
* @param buffer Buffer to read data into
* @return Number of bytes read
*/
- virtual size_t Read(const u64 offset, const u32 length, u8* buffer) const = 0;
+ virtual size_t Read(u64 offset, size_t length, u8* buffer) const = 0;
/**
* Write data to the file
@@ -41,20 +41,20 @@ public:
* @param buffer Buffer to read data from
* @return Number of bytes written
*/
- virtual size_t Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const = 0;
+ virtual size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const = 0;
/**
* Get the size of the file in bytes
* @return Size of the file in bytes
*/
- virtual size_t GetSize() const = 0;
+ virtual u64 GetSize() const = 0;
/**
* Set the size of the file in bytes
* @param size New size of the file
* @return true if successful
*/
- virtual bool SetSize(const u64 size) const = 0;
+ virtual bool SetSize(u64 size) const = 0;
/**
* Close the file
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 {
diff --git a/src/core/file_sys/ivfc_archive.h b/src/core/file_sys/ivfc_archive.h
index 1850b3b1..c15a6c4a 100644
--- a/src/core/file_sys/ivfc_archive.h
+++ b/src/core/file_sys/ivfc_archive.h
@@ -10,6 +10,7 @@
#include <vector>
#include "common/common_types.h"
+#include "common/file_util.h"
#include "core/file_sys/archive_backend.h"
#include "core/file_sys/directory_backend.h"
@@ -28,7 +29,8 @@ namespace FileSys {
*/
class IVFCArchive : public ArchiveBackend {
public:
- IVFCArchive(std::shared_ptr<const std::vector<u8>> data);
+ IVFCArchive(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size)
+ : romfs_file(file), data_offset(offset), data_size(size) {}
std::string GetName() const override;
@@ -42,23 +44,28 @@ public:
std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
protected:
- std::shared_ptr<const std::vector<u8>> data;
+ std::shared_ptr<FileUtil::IOFile> romfs_file;
+ u64 data_offset;
+ u64 data_size;
};
class IVFCFile : public FileBackend {
public:
- IVFCFile(std::shared_ptr<const std::vector<u8>> data) : data(data) {}
+ IVFCFile(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size)
+ : romfs_file(file), data_offset(offset), data_size(size) {}
bool Open() override { return true; }
- size_t Read(const u64 offset, const u32 length, u8* buffer) const override;
- size_t Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const override;
- size_t GetSize() const override;
- bool SetSize(const u64 size) const override;
+ size_t Read(u64 offset, size_t length, u8* buffer) const override;
+ size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const override;
+ u64 GetSize() const override;
+ bool SetSize(u64 size) const override;
bool Close() const override { return false; }
void Flush() const override { }
private:
- std::shared_ptr<const std::vector<u8>> data;
+ std::shared_ptr<FileUtil::IOFile> romfs_file;
+ u64 data_offset;
+ u64 data_size;
};
class IVFCDirectory : public DirectoryBackend {