[VFS] Rewrote STFS to use memory mapping
- Replaced old-style buffer, buffer_length with std::span - Added STFS and SVOD specific Entry and File classes - Other smaller improvements
This commit is contained in:
committed by
Radosław Gliński
parent
e85c2392ba
commit
fe739208b6
@@ -157,8 +157,8 @@ bool KernelState::UpdateSpaData(vfs::Entry* spa_file_update) {
|
||||
std::vector<uint8_t> data(spa_file_update->size());
|
||||
|
||||
size_t read_bytes = 0;
|
||||
if (file->ReadSync(data.data(), spa_file_update->size(), 0, &read_bytes) !=
|
||||
X_STATUS_SUCCESS) {
|
||||
if (file->ReadSync(std::span<uint8_t>(data.data(), spa_file_update->size()),
|
||||
0, &read_bytes) != X_STATUS_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,8 @@ X_STATUS UserModule::LoadFromFile(const std::string_view path) {
|
||||
// Read entire file into memory.
|
||||
// Ugh.
|
||||
size_t bytes_read = 0;
|
||||
result = file->ReadSync(buffer.data(), buffer.size(), 0, &bytes_read);
|
||||
result = file->ReadSync(std::span<uint8_t>(buffer.data(), buffer.size()), 0,
|
||||
&bytes_read);
|
||||
if (XFAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#define XENIA_KERNEL_UTIL_XEX2_INFO_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "xenia/base/byte_order.h"
|
||||
|
||||
@@ -202,8 +202,9 @@ bool ProfileManager::LoadAccount(const uint64_t xuid) {
|
||||
file_data.resize(output_file->entry()->size());
|
||||
|
||||
size_t bytes_read = 0;
|
||||
output_file->ReadSync(file_data.data(), output_file->entry()->size(), 0,
|
||||
&bytes_read);
|
||||
output_file->ReadSync(
|
||||
std::span<uint8_t>(file_data.data(), output_file->entry()->size()), 0,
|
||||
&bytes_read);
|
||||
output_file->Destroy();
|
||||
|
||||
if (bytes_read < sizeof(X_XAMACCOUNTINFO)) {
|
||||
@@ -562,8 +563,9 @@ bool ProfileManager::UpdateAccount(const uint64_t xuid,
|
||||
EncryptAccountFile(account, encrypted_data.data());
|
||||
|
||||
size_t written_bytes = 0;
|
||||
output_file->WriteSync(encrypted_data.data(), encrypted_data.size(), 0,
|
||||
&written_bytes);
|
||||
output_file->WriteSync(
|
||||
std::span<uint8_t>(encrypted_data.data(), encrypted_data.size()), 0,
|
||||
&written_bytes);
|
||||
output_file->Destroy();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,8 @@ void UserProfile::LoadProfileIcon(XTileType tile_type) {
|
||||
|
||||
std::vector<uint8_t> data(file->entry()->size());
|
||||
size_t written_bytes = 0;
|
||||
file->ReadSync(data.data(), file->entry()->size(), 0, &written_bytes);
|
||||
file->ReadSync(std::span<uint8_t>(data.data(), file->entry()->size()), 0,
|
||||
&written_bytes);
|
||||
file->Destroy();
|
||||
|
||||
profile_images_.insert({tile_type, data});
|
||||
@@ -114,7 +115,8 @@ std::vector<uint8_t> UserProfile::LoadGpd(const uint32_t title_id) {
|
||||
std::vector<uint8_t> data(entry->size());
|
||||
|
||||
size_t read_size = 0;
|
||||
result = file->ReadSync(data.data(), entry->size(), 0, &read_size);
|
||||
result = file->ReadSync(std::span<uint8_t>(data.data(), entry->size()), 0,
|
||||
&read_size);
|
||||
if (result != X_STATUS_SUCCESS || read_size != entry->size()) {
|
||||
XELOGW(
|
||||
"User {} (XUID: {:016X}) cannot read profile GPD! Status: {:08X} read: "
|
||||
@@ -150,7 +152,8 @@ bool UserProfile::WriteGpd(const uint32_t title_id) {
|
||||
}
|
||||
|
||||
size_t written_bytes = 0;
|
||||
file->WriteSync(data.data(), data.size(), 0, &written_bytes);
|
||||
file->WriteSync(std::span<uint8_t>(data.data(), data.size()), 0,
|
||||
&written_bytes);
|
||||
file->Destroy();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -277,7 +277,9 @@ dword_result_t XexLoadImageHeaders_entry(pointer_t<X_ANSI_STRING> path,
|
||||
size_t bytes_read = 0;
|
||||
|
||||
X_STATUS result_status = vfs_file->ReadSync(
|
||||
reinterpret_cast<void*>(header.host_address()), 2048, 0, &bytes_read);
|
||||
std::span<uint8_t>(reinterpret_cast<uint8_t*>(header.host_address()),
|
||||
2048),
|
||||
0, &bytes_read);
|
||||
|
||||
if (result_status < 0) {
|
||||
vfs_file->Destroy();
|
||||
@@ -298,8 +300,10 @@ dword_result_t XexLoadImageHeaders_entry(pointer_t<X_ANSI_STRING> path,
|
||||
result_status = X_STATUS_SUCCESS;
|
||||
} else {
|
||||
result_status = vfs_file->ReadSync(
|
||||
reinterpret_cast<void*>(header.host_address() + 2048),
|
||||
header_size - 2048, 2048, &bytes_read);
|
||||
std::span<uint8_t>(
|
||||
reinterpret_cast<uint8_t*>(header.host_address() + 2048),
|
||||
header_size - 2048),
|
||||
2048, &bytes_read);
|
||||
if (result_status >= X_STATUS_SUCCESS) {
|
||||
result_status = X_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -143,12 +143,14 @@ X_STATUS XFile::Read(uint32_t buffer_guest_address, uint32_t buffer_length,
|
||||
result = X_STATUS_ACCESS_VIOLATION;
|
||||
} else {
|
||||
result = file_->ReadSync(
|
||||
buffer_physical_heap
|
||||
? memory()->TranslatePhysical(
|
||||
buffer_physical_heap->GetPhysicalAddress(
|
||||
buffer_guest_address))
|
||||
: memory()->TranslateVirtual(buffer_guest_address),
|
||||
buffer_length, size_t(byte_offset), &bytes_read);
|
||||
std::span<uint8_t>(
|
||||
buffer_physical_heap
|
||||
? memory()->TranslatePhysical(
|
||||
buffer_physical_heap->GetPhysicalAddress(
|
||||
buffer_guest_address))
|
||||
: memory()->TranslateVirtual(buffer_guest_address),
|
||||
buffer_length),
|
||||
size_t(byte_offset), &bytes_read);
|
||||
if (XSUCCEEDED(result)) {
|
||||
if (buffer_physical_heap) {
|
||||
buffer_physical_heap->TriggerCallbacks(
|
||||
@@ -245,9 +247,10 @@ X_STATUS XFile::Write(uint32_t buffer_guest_address, uint32_t buffer_length,
|
||||
}
|
||||
|
||||
size_t bytes_written = 0;
|
||||
X_STATUS result =
|
||||
file_->WriteSync(memory()->TranslateVirtual(buffer_guest_address),
|
||||
buffer_length, size_t(byte_offset), &bytes_written);
|
||||
X_STATUS result = file_->WriteSync(
|
||||
std::span<uint8_t>(memory()->TranslateVirtual(buffer_guest_address),
|
||||
buffer_length),
|
||||
size_t(byte_offset), &bytes_written);
|
||||
if (XSUCCEEDED(result)) {
|
||||
position_ += bytes_written;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user