summaryrefslogtreecommitdiff
path: root/src/core/file_sys
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2014-12-15 06:41:02 -0200
committerGravatar Yuri Kunde Schlesner2014-12-16 01:08:44 -0200
commit83e6e4ffec9ca67fbca5536bb0ed7b4876ade0db (patch)
tree0e8b9aebaaebd6651e27b444964e95ef4c14d699 /src/core/file_sys
parentService.FS: Rename FileSys::File to FileBackend (diff)
downloadyuzu-83e6e4ffec9ca67fbca5536bb0ed7b4876ade0db.tar.gz
yuzu-83e6e4ffec9ca67fbca5536bb0ed7b4876ade0db.tar.xz
yuzu-83e6e4ffec9ca67fbca5536bb0ed7b4876ade0db.zip
FS.Archive: Clean up treatment of archives and their handles
- Refactor FS::Archive internals to make Archive creation and lifetime management clearer. - Remove the "Archive as a File" hack. - Implement 64-bit Archive handles.
Diffstat (limited to 'src/core/file_sys')
-rw-r--r--src/core/file_sys/archive_backend.h30
-rw-r--r--src/core/file_sys/archive_romfs.cpp50
-rw-r--r--src/core/file_sys/archive_romfs.h33
-rw-r--r--src/core/file_sys/archive_sdmc.cpp41
-rw-r--r--src/core/file_sys/archive_sdmc.h30
-rw-r--r--src/core/file_sys/file_romfs.cpp19
-rw-r--r--src/core/file_sys/file_romfs.h8
7 files changed, 21 insertions, 190 deletions
diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h
index 8d7a6a057..18c314884 100644
--- a/src/core/file_sys/archive_backend.h
+++ b/src/core/file_sys/archive_backend.h
@@ -220,36 +220,6 @@ public:
220 * @return Opened directory, or nullptr 220 * @return Opened directory, or nullptr
221 */ 221 */
222 virtual std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const = 0; 222 virtual std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const = 0;
223
224 /**
225 * Read data from the archive
226 * @param offset Offset in bytes to start reading data from
227 * @param length Length in bytes of data to read from archive
228 * @param buffer Buffer to read data into
229 * @return Number of bytes read
230 */
231 virtual size_t Read(const u64 offset, const u32 length, u8* buffer) const = 0;
232
233 /**
234 * Write data to the archive
235 * @param offset Offset in bytes to start writing data to
236 * @param length Length in bytes of data to write to archive
237 * @param buffer Buffer to write data from
238 * @param flush The flush parameters (0 == do not flush)
239 * @return Number of bytes written
240 */
241 virtual size_t Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) = 0;
242
243 /**
244 * Get the size of the archive in bytes
245 * @return Size of the archive in bytes
246 */
247 virtual size_t GetSize() const = 0;
248
249 /**
250 * Set the size of the archive in bytes
251 */
252 virtual void SetSize(const u64 size) = 0;
253}; 223};
254 224
255} // namespace FileSys 225} // namespace FileSys
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
index c515e0dd9..0709b62a1 100644
--- a/src/core/file_sys/archive_romfs.cpp
+++ b/src/core/file_sys/archive_romfs.cpp
@@ -2,6 +2,8 @@
2// Licensed under GPLv2 2// Licensed under GPLv2
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <memory>
6
5#include "common/common_types.h" 7#include "common/common_types.h"
6 8
7#include "core/file_sys/archive_romfs.h" 9#include "core/file_sys/archive_romfs.h"
@@ -20,9 +22,6 @@ Archive_RomFS::Archive_RomFS(const Loader::AppLoader& app_loader) {
20 } 22 }
21} 23}
22 24
23Archive_RomFS::~Archive_RomFS() {
24}
25
26/** 25/**
27 * Open a file specified by its path, using the specified mode 26 * Open a file specified by its path, using the specified mode
28 * @param path Path relative to the archive 27 * @param path Path relative to the archive
@@ -30,7 +29,7 @@ Archive_RomFS::~Archive_RomFS() {
30 * @return Opened file, or nullptr 29 * @return Opened file, or nullptr
31 */ 30 */
32std::unique_ptr<FileBackend> Archive_RomFS::OpenFile(const Path& path, const Mode mode) const { 31std::unique_ptr<FileBackend> Archive_RomFS::OpenFile(const Path& path, const Mode mode) const {
33 return std::unique_ptr<FileBackend>(new File_RomFS); 32 return std::make_unique<File_RomFS>(this);
34} 33}
35 34
36/** 35/**
@@ -79,48 +78,7 @@ bool Archive_RomFS::RenameDirectory(const FileSys::Path& src_path, const FileSys
79 * @return Opened directory, or nullptr 78 * @return Opened directory, or nullptr
80 */ 79 */
81std::unique_ptr<DirectoryBackend> Archive_RomFS::OpenDirectory(const Path& path) const { 80std::unique_ptr<DirectoryBackend> Archive_RomFS::OpenDirectory(const Path& path) const {
82 return std::unique_ptr<DirectoryBackend>(new Directory_RomFS); 81 return std::make_unique<Directory_RomFS>();
83}
84
85/**
86 * Read data from the archive
87 * @param offset Offset in bytes to start reading data from
88 * @param length Length in bytes of data to read from archive
89 * @param buffer Buffer to read data into
90 * @return Number of bytes read
91 */
92size_t Archive_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const {
93 LOG_TRACE(Service_FS, "called offset=%llu, length=%d", offset, length);
94 memcpy(buffer, &raw_data[(u32)offset], length);
95 return length;
96}
97
98/**
99 * Write data to the archive
100 * @param offset Offset in bytes to start writing data to
101 * @param length Length in bytes of data to write to archive
102 * @param buffer Buffer to write data from
103 * @param flush The flush parameters (0 == do not flush)
104 * @return Number of bytes written
105 */
106size_t Archive_RomFS::Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) {
107 LOG_WARNING(Service_FS, "Attempted to write to ROMFS.");
108 return 0;
109}
110
111/**
112 * Get the size of the archive in bytes
113 * @return Size of the archive in bytes
114 */
115size_t Archive_RomFS::GetSize() const {
116 return sizeof(u8) * raw_data.size();
117}
118
119/**
120 * Set the size of the archive in bytes
121 */
122void Archive_RomFS::SetSize(const u64 size) {
123 LOG_WARNING(Service_FS, "Attempted to set the size of ROMFS");
124} 82}
125 83
126} // namespace FileSys 84} // namespace FileSys
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h
index 0390821bf..5b1ee6332 100644
--- a/src/core/file_sys/archive_romfs.h
+++ b/src/core/file_sys/archive_romfs.h
@@ -20,7 +20,6 @@ namespace FileSys {
20class Archive_RomFS final : public ArchiveBackend { 20class Archive_RomFS final : public ArchiveBackend {
21public: 21public:
22 Archive_RomFS(const Loader::AppLoader& app_loader); 22 Archive_RomFS(const Loader::AppLoader& app_loader);
23 ~Archive_RomFS() override;
24 23
25 std::string GetName() const override { return "RomFS"; } 24 std::string GetName() const override { return "RomFS"; }
26 25
@@ -76,37 +75,9 @@ public:
76 */ 75 */
77 std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; 76 std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
78 77
79 /**
80 * Read data from the archive
81 * @param offset Offset in bytes to start reading data from
82 * @param length Length in bytes of data to read from archive
83 * @param buffer Buffer to read data into
84 * @return Number of bytes read
85 */
86 size_t Read(const u64 offset, const u32 length, u8* buffer) const override;
87
88 /**
89 * Write data to the archive
90 * @param offset Offset in bytes to start writing data to
91 * @param length Length in bytes of data to write to archive
92 * @param buffer Buffer to write data from
93 * @param flush The flush parameters (0 == do not flush)
94 * @return Number of bytes written
95 */
96 size_t Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) override;
97
98 /**
99 * Get the size of the archive in bytes
100 * @return Size of the archive in bytes
101 */
102 size_t GetSize() const override;
103
104 /**
105 * Set the size of the archive in bytes
106 */
107 void SetSize(const u64 size) override;
108
109private: 78private:
79 friend class File_RomFS;
80
110 std::vector<u8> raw_data; 81 std::vector<u8> raw_data;
111}; 82};
112 83
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp
index 43252b98b..9d58668e0 100644
--- a/src/core/file_sys/archive_sdmc.cpp
+++ b/src/core/file_sys/archive_sdmc.cpp
@@ -106,47 +106,6 @@ std::unique_ptr<DirectoryBackend> Archive_SDMC::OpenDirectory(const Path& path)
106} 106}
107 107
108/** 108/**
109 * Read data from the archive
110 * @param offset Offset in bytes to start reading archive from
111 * @param length Length in bytes to read data from archive
112 * @param buffer Buffer to read data into
113 * @return Number of bytes read
114 */
115size_t Archive_SDMC::Read(const u64 offset, const u32 length, u8* buffer) const {
116 LOG_ERROR(Service_FS, "(UNIMPLEMENTED)");
117 return -1;
118}
119
120/**
121 * Write data to the archive
122 * @param offset Offset in bytes to start writing data to
123 * @param length Length in bytes of data to write to archive
124 * @param buffer Buffer to write data from
125 * @param flush The flush parameters (0 == do not flush)
126 * @return Number of bytes written
127 */
128size_t Archive_SDMC::Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) {
129 LOG_ERROR(Service_FS, "(UNIMPLEMENTED)");
130 return -1;
131}
132
133/**
134 * Get the size of the archive in bytes
135 * @return Size of the archive in bytes
136 */
137size_t Archive_SDMC::GetSize() const {
138 LOG_ERROR(Service_FS, "(UNIMPLEMENTED)");
139 return 0;
140}
141
142/**
143 * Set the size of the archive in bytes
144 */
145void Archive_SDMC::SetSize(const u64 size) {
146 LOG_ERROR(Service_FS, "(UNIMPLEMENTED)");
147}
148
149/**
150 * Getter for the path used for this Archive 109 * Getter for the path used for this Archive
151 * @return Mount point of that passthrough archive 110 * @return Mount point of that passthrough archive
152 */ 111 */
diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h
index 5920051f7..059045245 100644
--- a/src/core/file_sys/archive_sdmc.h
+++ b/src/core/file_sys/archive_sdmc.h
@@ -81,36 +81,6 @@ public:
81 std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; 81 std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
82 82
83 /** 83 /**
84 * Read data from the archive
85 * @param offset Offset in bytes to start reading archive from
86 * @param length Length in bytes to read data from archive
87 * @param buffer Buffer to read data into
88 * @return Number of bytes read
89 */
90 size_t Read(const u64 offset, const u32 length, u8* buffer) const override;
91
92 /**
93 * Write data to the archive
94 * @param offset Offset in bytes to start writing data to
95 * @param length Length in bytes of data to write to archive
96 * @param buffer Buffer to write data from
97 * @param flush The flush parameters (0 == do not flush)
98 * @return Number of bytes written
99 */
100 size_t Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) override;
101
102 /**
103 * Get the size of the archive in bytes
104 * @return Size of the archive in bytes
105 */
106 size_t GetSize() const override;
107
108 /**
109 * Set the size of the archive in bytes
110 */
111 void SetSize(const u64 size) override;
112
113 /**
114 * Getter for the path used for this Archive 84 * Getter for the path used for this Archive
115 * @return Mount point of that passthrough archive 85 * @return Mount point of that passthrough archive
116 */ 86 */
diff --git a/src/core/file_sys/file_romfs.cpp b/src/core/file_sys/file_romfs.cpp
index b55708df4..5f38c2704 100644
--- a/src/core/file_sys/file_romfs.cpp
+++ b/src/core/file_sys/file_romfs.cpp
@@ -5,24 +5,19 @@
5#include "common/common_types.h" 5#include "common/common_types.h"
6 6
7#include "core/file_sys/file_romfs.h" 7#include "core/file_sys/file_romfs.h"
8#include "core/file_sys/archive_romfs.h"
8 9
9//////////////////////////////////////////////////////////////////////////////////////////////////// 10////////////////////////////////////////////////////////////////////////////////////////////////////
10// FileSys namespace 11// FileSys namespace
11 12
12namespace FileSys { 13namespace FileSys {
13 14
14File_RomFS::File_RomFS() {
15}
16
17File_RomFS::~File_RomFS() {
18}
19
20/** 15/**
21 * Open the file 16 * Open the file
22 * @return true if the file opened correctly 17 * @return true if the file opened correctly
23 */ 18 */
24bool File_RomFS::Open() { 19bool File_RomFS::Open() {
25 return false; 20 return true;
26} 21}
27 22
28/** 23/**
@@ -33,7 +28,9 @@ bool File_RomFS::Open() {
33 * @return Number of bytes read 28 * @return Number of bytes read
34 */ 29 */
35size_t File_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const { 30size_t File_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const {
36 return -1; 31 LOG_TRACE(Service_FS, "called offset=%llu, length=%d", offset, length);
32 memcpy(buffer, &archive->raw_data[(u32)offset], length);
33 return length;
37} 34}
38 35
39/** 36/**
@@ -45,7 +42,8 @@ size_t File_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const {
45 * @return Number of bytes written 42 * @return Number of bytes written
46 */ 43 */
47size_t File_RomFS::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const { 44size_t File_RomFS::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const {
48 return -1; 45 LOG_WARNING(Service_FS, "Attempted to write to ROMFS.");
46 return 0;
49} 47}
50 48
51/** 49/**
@@ -53,7 +51,7 @@ size_t File_RomFS::Write(const u64 offset, const u32 length, const u32 flush, co
53 * @return Size of the file in bytes 51 * @return Size of the file in bytes
54 */ 52 */
55size_t File_RomFS::GetSize() const { 53size_t File_RomFS::GetSize() const {
56 return -1; 54 return sizeof(u8) * archive->raw_data.size();
57} 55}
58 56
59/** 57/**
@@ -62,6 +60,7 @@ size_t File_RomFS::GetSize() const {
62 * @return true if successful 60 * @return true if successful
63 */ 61 */
64bool File_RomFS::SetSize(const u64 size) const { 62bool File_RomFS::SetSize(const u64 size) const {
63 LOG_WARNING(Service_FS, "Attempted to set the size of ROMFS");
65 return false; 64 return false;
66} 65}
67 66
diff --git a/src/core/file_sys/file_romfs.h b/src/core/file_sys/file_romfs.h
index 4ddaafe21..09fa2e7e3 100644
--- a/src/core/file_sys/file_romfs.h
+++ b/src/core/file_sys/file_romfs.h
@@ -14,10 +14,11 @@
14 14
15namespace FileSys { 15namespace FileSys {
16 16
17class Archive_RomFS;
18
17class File_RomFS final : public FileBackend { 19class File_RomFS final : public FileBackend {
18public: 20public:
19 File_RomFS(); 21 File_RomFS(const Archive_RomFS* archive) : archive(archive) {}
20 ~File_RomFS() override;
21 22
22 /** 23 /**
23 * Open the file 24 * Open the file
@@ -62,6 +63,9 @@ public:
62 * @return true if the file closed correctly 63 * @return true if the file closed correctly
63 */ 64 */
64 bool Close() const override; 65 bool Close() const override;
66
67private:
68 const Archive_RomFS* archive;
65}; 69};
66 70
67} // namespace FileSys 71} // namespace FileSys