diff --git a/src/core/file_sys/archive.h b/src/core/file_sys/archive.h index ed2d83640..c96475f20 100644 --- a/src/core/file_sys/archive.h +++ b/src/core/file_sys/archive.h @@ -44,6 +44,15 @@ public: */ virtual size_t Read(const u64 offset, const u32 length, u8* buffer) const = 0; + /** + * Write data to the archive + * @param offset Offset in bytes to start writing archive to + * @param length Length in bytes to write data to archive + * @param buffer Buffer to write data from + * @return Number of bytes written + */ + virtual size_t Write(const u64 offset, const u32 length, u8* buffer) = 0; + /** * Get the size of the archive in bytes * @return Size of the archive in bytes diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp index fd84b9c8c..9dc7d340d 100644 --- a/src/core/file_sys/archive_romfs.cpp +++ b/src/core/file_sys/archive_romfs.cpp @@ -34,6 +34,21 @@ size_t Archive_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const return length; } +/** + * Write data to the archive + * @param offset Offset in bytes to start writing archive to + * @param length Length in bytes to write data to archive + * @param buffer Buffer to write data from + * @return Number of bytes written + */ +size_t Archive_RomFS::Write(const u64 offset, const u32 length, u8* buffer) { + DEBUG_LOG(FILESYS, "called offset=%d, length=%d", offset, length); + + raw_data.reserve(offset + length); + raw_data.insert(raw_data.begin() + offset, buffer, buffer + length); + return length; +} + /** * Get the size of the archive in bytes * @return Size of the archive in bytes diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h index 8a31190a9..a1aed6a17 100644 --- a/src/core/file_sys/archive_romfs.h +++ b/src/core/file_sys/archive_romfs.h @@ -37,6 +37,15 @@ public: */ size_t Read(const u64 offset, const u32 length, u8* buffer) const override; + /** + * Write data to the archive + * @param offset Offset in bytes to start writing archive to + * @param length Length in bytes to write data to archive + * @param buffer Buffer to write data from + * @return Number of bytes written + */ + size_t Write(const u64 offset, const u32 length, u8* buffer) override; + /** * Get the size of the archive in bytes * @return Size of the archive in bytes diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cpp index 5079fcb84..3a678ef0e 100644 --- a/src/core/hle/kernel/archive.cpp +++ b/src/core/hle/kernel/archive.cpp @@ -48,8 +48,8 @@ public: Result SyncRequest(bool* wait) { u32* cmd_buff = Service::GetCommandBuffer(); FileCommand cmd = static_cast(cmd_buff[0]); + switch (cmd) { - // Read from archive... case FileCommand::Read: { @@ -59,12 +59,22 @@ public: cmd_buff[2] = backend->Read(offset, length, Memory::GetPointer(address)); break; } - + // Write to archive... + case FileCommand::Write: + { + u64 offset = cmd_buff[1] | ((u64) cmd_buff[2]) << 32; + u32 length = cmd_buff[3]; + u32 address = cmd_buff[5]; + cmd_buff[2] = backend->Write(offset, length, Memory::GetPointer(address)); + break; + } // Unknown command... default: + { ERROR_LOG(KERNEL, "Unknown command=0x%08X!", cmd); return -1; } + } cmd_buff[1] = 0; // No error return 0; }