diff options
| author | 2015-07-16 18:08:46 -0400 | |
|---|---|---|
| committer | 2015-07-16 18:08:46 -0400 | |
| commit | 946f0ee2f4f5e150167ad90f86a425b50baec144 (patch) | |
| tree | 47586aae7237dddc7278ef5e579cf82ad1b64e11 /src/core/file_sys | |
| parent | Merge pull request #931 from neobrain/move_default_attr_handler (diff) | |
| parent | Loader: Fix variable type and remove unused variable (diff) | |
| download | yuzu-946f0ee2f4f5e150167ad90f86a425b50baec144.tar.gz yuzu-946f0ee2f4f5e150167ad90f86a425b50baec144.tar.xz yuzu-946f0ee2f4f5e150167ad90f86a425b50baec144.zip | |
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')
| -rw-r--r-- | src/core/file_sys/archive_romfs.cpp | 7 | ||||
| -rw-r--r-- | src/core/file_sys/archive_romfs.h | 6 | ||||
| -rw-r--r-- | src/core/file_sys/archive_savedatacheck.cpp | 11 | ||||
| -rw-r--r-- | src/core/file_sys/disk_archive.cpp | 8 | ||||
| -rw-r--r-- | src/core/file_sys/disk_archive.h | 8 | ||||
| -rw-r--r-- | src/core/file_sys/file_backend.h | 8 | ||||
| -rw-r--r-- | src/core/file_sys/ivfc_archive.cpp | 19 | ||||
| -rw-r--r-- | src/core/file_sys/ivfc_archive.h | 23 |
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 c1e45dfeb..696b51a94 100644 --- a/src/core/file_sys/archive_romfs.cpp +++ b/src/core/file_sys/archive_romfs.cpp | |||
| @@ -17,16 +17,15 @@ | |||
| 17 | 17 | ||
| 18 | namespace FileSys { | 18 | namespace FileSys { |
| 19 | 19 | ||
| 20 | ArchiveFactory_RomFS::ArchiveFactory_RomFS(const Loader::AppLoader& app_loader) | 20 | ArchiveFactory_RomFS::ArchiveFactory_RomFS(Loader::AppLoader& app_loader) { |
| 21 | : romfs_data(std::make_shared<std::vector<u8>>()) { | ||
| 22 | // Load the RomFS from the app | 21 | // Load the RomFS from the app |
| 23 | if (Loader::ResultStatus::Success != app_loader.ReadRomFS(*romfs_data)) { | 22 | if (Loader::ResultStatus::Success != app_loader.ReadRomFS(romfs_file, data_offset, data_size)) { |
| 24 | LOG_ERROR(Service_FS, "Unable to read RomFS!"); | 23 | LOG_ERROR(Service_FS, "Unable to read RomFS!"); |
| 25 | } | 24 | } |
| 26 | } | 25 | } |
| 27 | 26 | ||
| 28 | ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_RomFS::Open(const Path& path) { | 27 | ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_RomFS::Open(const Path& path) { |
| 29 | auto archive = Common::make_unique<IVFCArchive>(romfs_data); | 28 | auto archive = Common::make_unique<IVFCArchive>(romfs_file, data_offset, data_size); |
| 30 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); | 29 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); |
| 31 | } | 30 | } |
| 32 | 31 | ||
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h index c69ff91c3..2bedfa9c6 100644 --- a/src/core/file_sys/archive_romfs.h +++ b/src/core/file_sys/archive_romfs.h | |||
| @@ -22,14 +22,16 @@ namespace FileSys { | |||
| 22 | /// File system interface to the RomFS archive | 22 | /// File system interface to the RomFS archive |
| 23 | class ArchiveFactory_RomFS final : public ArchiveFactory { | 23 | class ArchiveFactory_RomFS final : public ArchiveFactory { |
| 24 | public: | 24 | public: |
| 25 | ArchiveFactory_RomFS(const Loader::AppLoader& app_loader); | 25 | ArchiveFactory_RomFS(Loader::AppLoader& app_loader); |
| 26 | 26 | ||
| 27 | std::string GetName() const override { return "RomFS"; } | 27 | std::string GetName() const override { return "RomFS"; } |
| 28 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; | 28 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; |
| 29 | ResultCode Format(const Path& path) override; | 29 | ResultCode Format(const Path& path) override; |
| 30 | 30 | ||
| 31 | private: | 31 | private: |
| 32 | std::shared_ptr<std::vector<u8>> romfs_data; | 32 | std::shared_ptr<FileUtil::IOFile> romfs_file; |
| 33 | u64 data_offset; | ||
| 34 | u64 data_size; | ||
| 33 | }; | 35 | }; |
| 34 | 36 | ||
| 35 | } // namespace FileSys | 37 | } // namespace FileSys |
diff --git a/src/core/file_sys/archive_savedatacheck.cpp b/src/core/file_sys/archive_savedatacheck.cpp index dec838cae..ea1dfe2c7 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 | |||
| 37 | auto vec = path.AsBinary(); | 37 | auto vec = path.AsBinary(); |
| 38 | const u32* data = reinterpret_cast<u32*>(vec.data()); | 38 | const u32* data = reinterpret_cast<u32*>(vec.data()); |
| 39 | std::string file_path = GetSaveDataCheckPath(mount_point, data[1], data[0]); | 39 | std::string file_path = GetSaveDataCheckPath(mount_point, data[1], data[0]); |
| 40 | FileUtil::IOFile file(file_path, "rb"); | 40 | auto file = std::make_shared<FileUtil::IOFile>(file_path, "rb"); |
| 41 | 41 | ||
| 42 | if (!file.IsOpen()) { | 42 | if (!file->IsOpen()) { |
| 43 | return ResultCode(-1); // TODO(Subv): Find the right error code | 43 | return ResultCode(-1); // TODO(Subv): Find the right error code |
| 44 | } | 44 | } |
| 45 | auto size = file.GetSize(); | 45 | auto size = file->GetSize(); |
| 46 | auto raw_data = std::make_shared<std::vector<u8>>(size); | ||
| 47 | file.ReadBytes(raw_data->data(), size); | ||
| 48 | file.Close(); | ||
| 49 | 46 | ||
| 50 | auto archive = Common::make_unique<IVFCArchive>(std::move(raw_data)); | 47 | auto archive = Common::make_unique<IVFCArchive>(file, 0, size); |
| 51 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); | 48 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); |
| 52 | } | 49 | } |
| 53 | 50 | ||
diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp index 85151a311..1096fd34d 100644 --- a/src/core/file_sys/disk_archive.cpp +++ b/src/core/file_sys/disk_archive.cpp | |||
| @@ -105,12 +105,12 @@ bool DiskFile::Open() { | |||
| 105 | return true; | 105 | return true; |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | size_t DiskFile::Read(const u64 offset, const u32 length, u8* buffer) const { | 108 | size_t DiskFile::Read(const u64 offset, const size_t length, u8* buffer) const { |
| 109 | file->Seek(offset, SEEK_SET); | 109 | file->Seek(offset, SEEK_SET); |
| 110 | return file->ReadBytes(buffer, length); | 110 | return file->ReadBytes(buffer, length); |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | size_t DiskFile::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const { | 113 | size_t DiskFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const { |
| 114 | file->Seek(offset, SEEK_SET); | 114 | file->Seek(offset, SEEK_SET); |
| 115 | size_t written = file->WriteBytes(buffer, length); | 115 | size_t written = file->WriteBytes(buffer, length); |
| 116 | if (flush) | 116 | if (flush) |
| @@ -118,8 +118,8 @@ size_t DiskFile::Write(const u64 offset, const u32 length, const u32 flush, cons | |||
| 118 | return written; | 118 | return written; |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | size_t DiskFile::GetSize() const { | 121 | u64 DiskFile::GetSize() const { |
| 122 | return static_cast<size_t>(file->GetSize()); | 122 | return file->GetSize(); |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | bool DiskFile::SetSize(const u64 size) const { | 125 | 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 5cfcddf6c..c5da07508 100644 --- a/src/core/file_sys/disk_archive.h +++ b/src/core/file_sys/disk_archive.h | |||
| @@ -55,10 +55,10 @@ public: | |||
| 55 | DiskFile(const DiskArchive& archive, const Path& path, const Mode mode); | 55 | DiskFile(const DiskArchive& archive, const Path& path, const Mode mode); |
| 56 | 56 | ||
| 57 | bool Open() override; | 57 | bool Open() override; |
| 58 | size_t Read(const u64 offset, const u32 length, u8* buffer) const override; | 58 | size_t Read(u64 offset, size_t length, u8* buffer) const override; |
| 59 | size_t Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const override; | 59 | size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const override; |
| 60 | size_t GetSize() const override; | 60 | u64 GetSize() const override; |
| 61 | bool SetSize(const u64 size) const override; | 61 | bool SetSize(u64 size) const override; |
| 62 | bool Close() const override; | 62 | bool Close() const override; |
| 63 | 63 | ||
| 64 | void Flush() const override { | 64 | void Flush() const override { |
diff --git a/src/core/file_sys/file_backend.h b/src/core/file_sys/file_backend.h index f5f72c722..df7165df3 100644 --- a/src/core/file_sys/file_backend.h +++ b/src/core/file_sys/file_backend.h | |||
| @@ -31,7 +31,7 @@ public: | |||
| 31 | * @param buffer Buffer to read data into | 31 | * @param buffer Buffer to read data into |
| 32 | * @return Number of bytes read | 32 | * @return Number of bytes read |
| 33 | */ | 33 | */ |
| 34 | virtual size_t Read(const u64 offset, const u32 length, u8* buffer) const = 0; | 34 | virtual size_t Read(u64 offset, size_t length, u8* buffer) const = 0; |
| 35 | 35 | ||
| 36 | /** | 36 | /** |
| 37 | * Write data to the file | 37 | * Write data to the file |
| @@ -41,20 +41,20 @@ public: | |||
| 41 | * @param buffer Buffer to read data from | 41 | * @param buffer Buffer to read data from |
| 42 | * @return Number of bytes written | 42 | * @return Number of bytes written |
| 43 | */ | 43 | */ |
| 44 | virtual size_t Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const = 0; | 44 | virtual size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const = 0; |
| 45 | 45 | ||
| 46 | /** | 46 | /** |
| 47 | * Get the size of the file in bytes | 47 | * Get the size of the file in bytes |
| 48 | * @return Size of the file in bytes | 48 | * @return Size of the file in bytes |
| 49 | */ | 49 | */ |
| 50 | virtual size_t GetSize() const = 0; | 50 | virtual u64 GetSize() const = 0; |
| 51 | 51 | ||
| 52 | /** | 52 | /** |
| 53 | * Set the size of the file in bytes | 53 | * Set the size of the file in bytes |
| 54 | * @param size New size of the file | 54 | * @param size New size of the file |
| 55 | * @return true if successful | 55 | * @return true if successful |
| 56 | */ | 56 | */ |
| 57 | virtual bool SetSize(const u64 size) const = 0; | 57 | virtual bool SetSize(u64 size) const = 0; |
| 58 | 58 | ||
| 59 | /** | 59 | /** |
| 60 | * Close the file | 60 | * Close the file |
diff --git a/src/core/file_sys/ivfc_archive.cpp b/src/core/file_sys/ivfc_archive.cpp index c88b39bcd..e16aa1491 100644 --- a/src/core/file_sys/ivfc_archive.cpp +++ b/src/core/file_sys/ivfc_archive.cpp | |||
| @@ -16,15 +16,12 @@ | |||
| 16 | 16 | ||
| 17 | namespace FileSys { | 17 | namespace FileSys { |
| 18 | 18 | ||
| 19 | IVFCArchive::IVFCArchive(std::shared_ptr<const std::vector<u8>> data) : data(data) { | ||
| 20 | } | ||
| 21 | |||
| 22 | std::string IVFCArchive::GetName() const { | 19 | std::string IVFCArchive::GetName() const { |
| 23 | return "IVFC"; | 20 | return "IVFC"; |
| 24 | } | 21 | } |
| 25 | 22 | ||
| 26 | std::unique_ptr<FileBackend> IVFCArchive::OpenFile(const Path& path, const Mode mode) const { | 23 | std::unique_ptr<FileBackend> IVFCArchive::OpenFile(const Path& path, const Mode mode) const { |
| 27 | return Common::make_unique<IVFCFile>(data); | 24 | return Common::make_unique<IVFCFile>(romfs_file, data_offset, data_size); |
| 28 | } | 25 | } |
| 29 | 26 | ||
| 30 | bool IVFCArchive::DeleteFile(const Path& path) const { | 27 | bool IVFCArchive::DeleteFile(const Path& path) const { |
| @@ -64,19 +61,21 @@ std::unique_ptr<DirectoryBackend> IVFCArchive::OpenDirectory(const Path& path) c | |||
| 64 | 61 | ||
| 65 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 62 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 66 | 63 | ||
| 67 | size_t IVFCFile::Read(const u64 offset, const u32 length, u8* buffer) const { | 64 | size_t IVFCFile::Read(const u64 offset, const size_t length, u8* buffer) const { |
| 68 | LOG_TRACE(Service_FS, "called offset=%llu, length=%d", offset, length); | 65 | LOG_TRACE(Service_FS, "called offset=%llu, length=%d", offset, length); |
| 69 | memcpy(buffer, data->data() + offset, length); | 66 | romfs_file->Seek(data_offset + offset, SEEK_SET); |
| 70 | return length; | 67 | size_t read_length = (size_t)std::min((u64)length, data_size - offset); |
| 68 | |||
| 69 | return romfs_file->ReadBytes(buffer, read_length); | ||
| 71 | } | 70 | } |
| 72 | 71 | ||
| 73 | size_t IVFCFile::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const { | 72 | size_t IVFCFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const { |
| 74 | LOG_ERROR(Service_FS, "Attempted to write to IVFC file"); | 73 | LOG_ERROR(Service_FS, "Attempted to write to IVFC file"); |
| 75 | return 0; | 74 | return 0; |
| 76 | } | 75 | } |
| 77 | 76 | ||
| 78 | size_t IVFCFile::GetSize() const { | 77 | u64 IVFCFile::GetSize() const { |
| 79 | return sizeof(u8) * data->size(); | 78 | return data_size; |
| 80 | } | 79 | } |
| 81 | 80 | ||
| 82 | bool IVFCFile::SetSize(const u64 size) const { | 81 | 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 1850b3b17..c15a6c4ae 100644 --- a/src/core/file_sys/ivfc_archive.h +++ b/src/core/file_sys/ivfc_archive.h | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include <vector> | 10 | #include <vector> |
| 11 | 11 | ||
| 12 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 13 | #include "common/file_util.h" | ||
| 13 | 14 | ||
| 14 | #include "core/file_sys/archive_backend.h" | 15 | #include "core/file_sys/archive_backend.h" |
| 15 | #include "core/file_sys/directory_backend.h" | 16 | #include "core/file_sys/directory_backend.h" |
| @@ -28,7 +29,8 @@ namespace FileSys { | |||
| 28 | */ | 29 | */ |
| 29 | class IVFCArchive : public ArchiveBackend { | 30 | class IVFCArchive : public ArchiveBackend { |
| 30 | public: | 31 | public: |
| 31 | IVFCArchive(std::shared_ptr<const std::vector<u8>> data); | 32 | IVFCArchive(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size) |
| 33 | : romfs_file(file), data_offset(offset), data_size(size) {} | ||
| 32 | 34 | ||
| 33 | std::string GetName() const override; | 35 | std::string GetName() const override; |
| 34 | 36 | ||
| @@ -42,23 +44,28 @@ public: | |||
| 42 | std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; | 44 | std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; |
| 43 | 45 | ||
| 44 | protected: | 46 | protected: |
| 45 | std::shared_ptr<const std::vector<u8>> data; | 47 | std::shared_ptr<FileUtil::IOFile> romfs_file; |
| 48 | u64 data_offset; | ||
| 49 | u64 data_size; | ||
| 46 | }; | 50 | }; |
| 47 | 51 | ||
| 48 | class IVFCFile : public FileBackend { | 52 | class IVFCFile : public FileBackend { |
| 49 | public: | 53 | public: |
| 50 | IVFCFile(std::shared_ptr<const std::vector<u8>> data) : data(data) {} | 54 | IVFCFile(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size) |
| 55 | : romfs_file(file), data_offset(offset), data_size(size) {} | ||
| 51 | 56 | ||
| 52 | bool Open() override { return true; } | 57 | bool Open() override { return true; } |
| 53 | size_t Read(const u64 offset, const u32 length, u8* buffer) const override; | 58 | size_t Read(u64 offset, size_t length, u8* buffer) const override; |
| 54 | size_t Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const override; | 59 | size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const override; |
| 55 | size_t GetSize() const override; | 60 | u64 GetSize() const override; |
| 56 | bool SetSize(const u64 size) const override; | 61 | bool SetSize(u64 size) const override; |
| 57 | bool Close() const override { return false; } | 62 | bool Close() const override { return false; } |
| 58 | void Flush() const override { } | 63 | void Flush() const override { } |
| 59 | 64 | ||
| 60 | private: | 65 | private: |
| 61 | std::shared_ptr<const std::vector<u8>> data; | 66 | std::shared_ptr<FileUtil::IOFile> romfs_file; |
| 67 | u64 data_offset; | ||
| 68 | u64 data_size; | ||
| 62 | }; | 69 | }; |
| 63 | 70 | ||
| 64 | class IVFCDirectory : public DirectoryBackend { | 71 | class IVFCDirectory : public DirectoryBackend { |