summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar archshift2014-08-20 22:03:31 -0700
committerGravatar archshift2014-08-22 15:45:10 -0700
commit4c4a01bf413eab37394e76683790cebe08d57922 (patch)
tree850d82660ff575580012161f2c1c47403ef20365 /src
parentMerge pull request #62 from archshift/revert-49-redundantloop (diff)
downloadyuzu-4c4a01bf413eab37394e76683790cebe08d57922.tar.gz
yuzu-4c4a01bf413eab37394e76683790cebe08d57922.tar.xz
yuzu-4c4a01bf413eab37394e76683790cebe08d57922.zip
Added FS functions to Archive and Archive_RomFS
Diffstat (limited to 'src')
-rw-r--r--src/core/file_sys/archive.h19
-rw-r--r--src/core/file_sys/archive_romfs.cpp27
-rw-r--r--src/core/file_sys/archive_romfs.h19
-rw-r--r--src/core/hle/kernel/archive.cpp34
4 files changed, 88 insertions, 11 deletions
diff --git a/src/core/file_sys/archive.h b/src/core/file_sys/archive.h
index ed2d83640..ac5630bea 100644
--- a/src/core/file_sys/archive.h
+++ b/src/core/file_sys/archive.h
@@ -37,18 +37,33 @@ public:
37 37
38 /** 38 /**
39 * Read data from the archive 39 * Read data from the archive
40 * @param offset Offset in bytes to start reading archive from 40 * @param offset Offset in bytes to start reading data from
41 * @param length Length in bytes to read data from archive 41 * @param length Length in bytes of data to read from archive
42 * @param buffer Buffer to read data into 42 * @param buffer Buffer to read data into
43 * @return Number of bytes read 43 * @return Number of bytes read
44 */ 44 */
45 virtual size_t Read(const u64 offset, const u32 length, u8* buffer) const = 0; 45 virtual size_t Read(const u64 offset, const u32 length, u8* buffer) const = 0;
46 46
47 /** 47 /**
48 * Write data to the archive
49 * @param offset Offset in bytes to start writing data to
50 * @param length Length in bytes of data to write to archive
51 * @param buffer Buffer to write data from
52 * @param flush The flush parameters (0 == do not flush)
53 * @return Number of bytes written
54 */
55 virtual size_t Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) = 0;
56
57 /**
48 * Get the size of the archive in bytes 58 * Get the size of the archive in bytes
49 * @return Size of the archive in bytes 59 * @return Size of the archive in bytes
50 */ 60 */
51 virtual size_t GetSize() const = 0; 61 virtual size_t GetSize() const = 0;
62
63 /**
64 * Set the size of the archive in bytes
65 */
66 virtual void SetSize(const u64 size) = 0;
52}; 67};
53 68
54} // namespace FileSys 69} // namespace FileSys
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
index fd84b9c8c..dc3fb1807 100644
--- a/src/core/file_sys/archive_romfs.cpp
+++ b/src/core/file_sys/archive_romfs.cpp
@@ -23,8 +23,8 @@ Archive_RomFS::~Archive_RomFS() {
23 23
24/** 24/**
25 * Read data from the archive 25 * Read data from the archive
26 * @param offset Offset in bytes to start reading archive from 26 * @param offset Offset in bytes to start reading data from
27 * @param length Length in bytes to read data from archive 27 * @param length Length in bytes of data to read from archive
28 * @param buffer Buffer to read data into 28 * @param buffer Buffer to read data into
29 * @return Number of bytes read 29 * @return Number of bytes read
30 */ 30 */
@@ -35,12 +35,31 @@ size_t Archive_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const
35} 35}
36 36
37/** 37/**
38 * Write data to the archive
39 * @param offset Offset in bytes to start writing data to
40 * @param length Length in bytes of data to write to archive
41 * @param buffer Buffer to write data from
42 * @param flush The flush parameters (0 == do not flush)
43 * @return Number of bytes written
44 */
45size_t Archive_RomFS::Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) {
46 ERROR_LOG(FILESYS, "Attempted to write to ROMFS.");
47 return 0;
48}
49
50/**
38 * Get the size of the archive in bytes 51 * Get the size of the archive in bytes
39 * @return Size of the archive in bytes 52 * @return Size of the archive in bytes
40 */ 53 */
41size_t Archive_RomFS::GetSize() const { 54size_t Archive_RomFS::GetSize() const {
42 ERROR_LOG(FILESYS, "(UNIMPLEMENTED)"); 55 return sizeof(u8) * raw_data.size();
43 return 0; 56}
57
58/**
59 * Set the size of the archive in bytes
60 */
61void Archive_RomFS::SetSize(const u64 size) {
62 ERROR_LOG(FILESYS, "Attempted to set the size of ROMFS");
44} 63}
45 64
46} // namespace FileSys 65} // namespace FileSys
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h
index 8a31190a9..e9ed6f77a 100644
--- a/src/core/file_sys/archive_romfs.h
+++ b/src/core/file_sys/archive_romfs.h
@@ -30,18 +30,33 @@ public:
30 30
31 /** 31 /**
32 * Read data from the archive 32 * Read data from the archive
33 * @param offset Offset in bytes to start reading archive from 33 * @param offset Offset in bytes to start reading data from
34 * @param length Length in bytes to read data from archive 34 * @param length Length in bytes of data to read from archive
35 * @param buffer Buffer to read data into 35 * @param buffer Buffer to read data into
36 * @return Number of bytes read 36 * @return Number of bytes read
37 */ 37 */
38 size_t Read(const u64 offset, const u32 length, u8* buffer) const override; 38 size_t Read(const u64 offset, const u32 length, u8* buffer) const override;
39 39
40 /** 40 /**
41 * Write data to the archive
42 * @param offset Offset in bytes to start writing data to
43 * @param length Length in bytes of data to write to archive
44 * @param buffer Buffer to write data from
45 * @param flush The flush parameters (0 == do not flush)
46 * @return Number of bytes written
47 */
48 size_t Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) override;
49
50 /**
41 * Get the size of the archive in bytes 51 * Get the size of the archive in bytes
42 * @return Size of the archive in bytes 52 * @return Size of the archive in bytes
43 */ 53 */
44 size_t GetSize() const override; 54 size_t GetSize() const override;
55
56 /**
57 * Set the size of the archive in bytes
58 */
59 void SetSize(const u64 size) override;
45 60
46private: 61private:
47 std::vector<u8> raw_data; 62 std::vector<u8> raw_data;
diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cpp
index 5079fcb84..1596367c3 100644
--- a/src/core/hle/kernel/archive.cpp
+++ b/src/core/hle/kernel/archive.cpp
@@ -3,6 +3,7 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "common/common_types.h" 5#include "common/common_types.h"
6#include "common/math_util.h"
6 7
7#include "core/file_sys/archive.h" 8#include "core/file_sys/archive.h"
8#include "core/hle/service/service.h" 9#include "core/hle/service/service.h"
@@ -48,23 +49,50 @@ public:
48 Result SyncRequest(bool* wait) { 49 Result SyncRequest(bool* wait) {
49 u32* cmd_buff = Service::GetCommandBuffer(); 50 u32* cmd_buff = Service::GetCommandBuffer();
50 FileCommand cmd = static_cast<FileCommand>(cmd_buff[0]); 51 FileCommand cmd = static_cast<FileCommand>(cmd_buff[0]);
52
51 switch (cmd) { 53 switch (cmd) {
52
53 // Read from archive... 54 // Read from archive...
54 case FileCommand::Read: 55 case FileCommand::Read:
55 { 56 {
56 u64 offset = cmd_buff[1] | ((u64) cmd_buff[2]) << 32; 57 u64 offset = cmd_buff[1] | ((u64)cmd_buff[2] << 32);
57 u32 length = cmd_buff[3]; 58 u32 length = cmd_buff[3];
58 u32 address = cmd_buff[5]; 59 u32 address = cmd_buff[5];
60
61 // Number of bytes read
59 cmd_buff[2] = backend->Read(offset, length, Memory::GetPointer(address)); 62 cmd_buff[2] = backend->Read(offset, length, Memory::GetPointer(address));
60 break; 63 break;
61 } 64 }
65 // Write to archive...
66 case FileCommand::Write:
67 {
68 u64 offset = cmd_buff[1] | ((u64)cmd_buff[2] << 32);
69 u32 length = cmd_buff[3];
70 u32 flush = cmd_buff[4];
71 u32 address = cmd_buff[6];
62 72
73 // Number of bytes written
74 cmd_buff[2] = backend->Write(offset, length, flush, Memory::GetPointer(address));
75 break;
76 }
77 case FileCommand::GetSize:
78 {
79 u64 filesize = (u64) backend->GetSize();
80 cmd_buff[2] = (u32) filesize; // Lower word
81 cmd_buff[3] = (u32) (filesize >> 32); // Upper word
82 break;
83 }
84 case FileCommand::SetSize:
85 {
86 backend->SetSize(cmd_buff[1] | ((u64)cmd_buff[2] << 32));
87 break;
88 }
63 // Unknown command... 89 // Unknown command...
64 default: 90 default:
91 {
65 ERROR_LOG(KERNEL, "Unknown command=0x%08X!", cmd); 92 ERROR_LOG(KERNEL, "Unknown command=0x%08X!", cmd);
66 return -1; 93 return -1;
67 } 94 }
95 }
68 cmd_buff[1] = 0; // No error 96 cmd_buff[1] = 0; // No error
69 return 0; 97 return 0;
70 } 98 }
@@ -140,7 +168,7 @@ Archive* CreateArchive(Handle& handle, FileSys::Archive* backend, const std::str
140 */ 168 */
141Handle CreateArchive(FileSys::Archive* backend, const std::string& name) { 169Handle CreateArchive(FileSys::Archive* backend, const std::string& name) {
142 Handle handle; 170 Handle handle;
143 Archive* archive = CreateArchive(handle, backend, name); 171 CreateArchive(handle, backend, name);
144 return handle; 172 return handle;
145} 173}
146 174