summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Subv2015-12-28 10:03:09 -0500
committerGravatar Subv2016-03-20 14:28:17 -0500
commit96f0e32f836b19edb3d14ce4f87a7aed1ac6a8e1 (patch)
tree9eed35100efe7714f7ef5a39ff2c3bbf897f3dae /src/core
parentHLE/FS: Corrected the error codes for DeleteFile (diff)
downloadyuzu-96f0e32f836b19edb3d14ce4f87a7aed1ac6a8e1.tar.gz
yuzu-96f0e32f836b19edb3d14ce4f87a7aed1ac6a8e1.tar.xz
yuzu-96f0e32f836b19edb3d14ce4f87a7aed1ac6a8e1.zip
HLE/FS: Return the proper error codes on file Read/Write operations.
These operations are limited by the open flags specified while opening the file.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/file_sys/disk_archive.cpp14
-rw-r--r--src/core/file_sys/disk_archive.h4
-rw-r--r--src/core/file_sys/file_backend.h9
-rw-r--r--src/core/file_sys/ivfc_archive.cpp9
-rw-r--r--src/core/file_sys/ivfc_archive.h4
-rw-r--r--src/core/hle/result.h1
-rw-r--r--src/core/hle/service/fs/archive.cpp17
7 files changed, 40 insertions, 18 deletions
diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp
index 0c55a4863..2dca895fd 100644
--- a/src/core/file_sys/disk_archive.cpp
+++ b/src/core/file_sys/disk_archive.cpp
@@ -124,17 +124,23 @@ bool DiskFile::Open() {
124 return file->IsOpen(); 124 return file->IsOpen();
125} 125}
126 126
127size_t DiskFile::Read(const u64 offset, const size_t length, u8* buffer) const { 127ResultVal<size_t> DiskFile::Read(const u64 offset, const size_t length, u8* buffer) const {
128 if (!mode.read_flag && !mode.write_flag)
129 return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status);
130
128 file->Seek(offset, SEEK_SET); 131 file->Seek(offset, SEEK_SET);
129 return file->ReadBytes(buffer, length); 132 return MakeResult<size_t>(file->ReadBytes(buffer, length));
130} 133}
131 134
132size_t DiskFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const { 135ResultVal<size_t> DiskFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const {
136 if (!mode.write_flag)
137 return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status);
138
133 file->Seek(offset, SEEK_SET); 139 file->Seek(offset, SEEK_SET);
134 size_t written = file->WriteBytes(buffer, length); 140 size_t written = file->WriteBytes(buffer, length);
135 if (flush) 141 if (flush)
136 file->Flush(); 142 file->Flush();
137 return written; 143 return MakeResult<size_t>(written);
138} 144}
139 145
140u64 DiskFile::GetSize() const { 146u64 DiskFile::GetSize() const {
diff --git a/src/core/file_sys/disk_archive.h b/src/core/file_sys/disk_archive.h
index c0a3d3f7b..96d86ad21 100644
--- a/src/core/file_sys/disk_archive.h
+++ b/src/core/file_sys/disk_archive.h
@@ -55,8 +55,8 @@ 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(u64 offset, size_t length, u8* buffer) const override; 58 ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override;
59 size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const override; 59 ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) const override;
60 u64 GetSize() const override; 60 u64 GetSize() const override;
61 bool SetSize(u64 size) const override; 61 bool SetSize(u64 size) const override;
62 bool Close() const override; 62 bool Close() const override;
diff --git a/src/core/file_sys/file_backend.h b/src/core/file_sys/file_backend.h
index df7165df3..21864a73c 100644
--- a/src/core/file_sys/file_backend.h
+++ b/src/core/file_sys/file_backend.h
@@ -7,6 +7,7 @@
7#include <cstddef> 7#include <cstddef>
8 8
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "core/hle/result.h"
10 11
11//////////////////////////////////////////////////////////////////////////////////////////////////// 12////////////////////////////////////////////////////////////////////////////////////////////////////
12// FileSys namespace 13// FileSys namespace
@@ -29,9 +30,9 @@ public:
29 * @param offset Offset in bytes to start reading data from 30 * @param offset Offset in bytes to start reading data from
30 * @param length Length in bytes of data to read from file 31 * @param length Length in bytes of data to read from file
31 * @param buffer Buffer to read data into 32 * @param buffer Buffer to read data into
32 * @return Number of bytes read 33 * @return Number of bytes read, or error code
33 */ 34 */
34 virtual size_t Read(u64 offset, size_t length, u8* buffer) const = 0; 35 virtual ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const = 0;
35 36
36 /** 37 /**
37 * Write data to the file 38 * Write data to the file
@@ -39,9 +40,9 @@ public:
39 * @param length Length in bytes of data to write to file 40 * @param length Length in bytes of data to write to file
40 * @param flush The flush parameters (0 == do not flush) 41 * @param flush The flush parameters (0 == do not flush)
41 * @param buffer Buffer to read data from 42 * @param buffer Buffer to read data from
42 * @return Number of bytes written 43 * @return Number of bytes written, or error code
43 */ 44 */
44 virtual size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const = 0; 45 virtual ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) const = 0;
45 46
46 /** 47 /**
47 * Get the size of the file in bytes 48 * Get the size of the file in bytes
diff --git a/src/core/file_sys/ivfc_archive.cpp b/src/core/file_sys/ivfc_archive.cpp
index f2f96ef1a..e7b37e09d 100644
--- a/src/core/file_sys/ivfc_archive.cpp
+++ b/src/core/file_sys/ivfc_archive.cpp
@@ -68,17 +68,18 @@ u64 IVFCArchive::GetFreeBytes() const {
68 68
69//////////////////////////////////////////////////////////////////////////////////////////////////// 69////////////////////////////////////////////////////////////////////////////////////////////////////
70 70
71size_t IVFCFile::Read(const u64 offset, const size_t length, u8* buffer) const { 71ResultVal<size_t> IVFCFile::Read(const u64 offset, const size_t length, u8* buffer) const {
72 LOG_TRACE(Service_FS, "called offset=%llu, length=%zu", offset, length); 72 LOG_TRACE(Service_FS, "called offset=%llu, length=%zu", offset, length);
73 romfs_file->Seek(data_offset + offset, SEEK_SET); 73 romfs_file->Seek(data_offset + offset, SEEK_SET);
74 size_t read_length = (size_t)std::min((u64)length, data_size - offset); 74 size_t read_length = (size_t)std::min((u64)length, data_size - offset);
75 75
76 return romfs_file->ReadBytes(buffer, read_length); 76 return MakeResult<size_t>(romfs_file->ReadBytes(buffer, read_length));
77} 77}
78 78
79size_t IVFCFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const { 79ResultVal<size_t> IVFCFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const {
80 LOG_ERROR(Service_FS, "Attempted to write to IVFC file"); 80 LOG_ERROR(Service_FS, "Attempted to write to IVFC file");
81 return 0; 81 // TODO(Subv): Find error code
82 return MakeResult<size_t>(0);
82} 83}
83 84
84u64 IVFCFile::GetSize() const { 85u64 IVFCFile::GetSize() const {
diff --git a/src/core/file_sys/ivfc_archive.h b/src/core/file_sys/ivfc_archive.h
index 5d3a5b61e..acc7e60f5 100644
--- a/src/core/file_sys/ivfc_archive.h
+++ b/src/core/file_sys/ivfc_archive.h
@@ -56,8 +56,8 @@ public:
56 : romfs_file(file), data_offset(offset), data_size(size) {} 56 : romfs_file(file), data_offset(offset), data_size(size) {}
57 57
58 bool Open() override { return true; } 58 bool Open() override { return true; }
59 size_t Read(u64 offset, size_t length, u8* buffer) const override; 59 ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override;
60 size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const override; 60 ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) const override;
61 u64 GetSize() const override; 61 u64 GetSize() const override;
62 bool SetSize(u64 size) const override; 62 bool SetSize(u64 size) const override;
63 bool Close() const override { return false; } 63 bool Close() const override { return false; }
diff --git a/src/core/hle/result.h b/src/core/hle/result.h
index b9ee5f7d9..b68c0ff0d 100644
--- a/src/core/hle/result.h
+++ b/src/core/hle/result.h
@@ -21,6 +21,7 @@ enum class ErrorDescription : u32 {
21 WrongAddress = 53, 21 WrongAddress = 53,
22 FS_NotFound = 120, 22 FS_NotFound = 120,
23 FS_AlreadyExists = 190, 23 FS_AlreadyExists = 190,
24 FS_InvalidOpenFlags = 230,
24 FS_NotAFile = 250, 25 FS_NotAFile = 250,
25 FS_NotFormatted = 340, ///< This is used by the FS service when creating a SaveData archive 26 FS_NotFormatted = 340, ///< This is used by the FS service when creating a SaveData archive
26 InvalidSection = 1000, 27 InvalidSection = 1000,
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp
index cb98fa7aa..8c38c3ba4 100644
--- a/src/core/hle/service/fs/archive.cpp
+++ b/src/core/hle/service/fs/archive.cpp
@@ -103,7 +103,14 @@ ResultVal<bool> File::SyncRequest() {
103 u32 address = cmd_buff[5]; 103 u32 address = cmd_buff[5];
104 LOG_TRACE(Service_FS, "Read %s %s: offset=0x%llx length=%d address=0x%x", 104 LOG_TRACE(Service_FS, "Read %s %s: offset=0x%llx length=%d address=0x%x",
105 GetTypeName().c_str(), GetName().c_str(), offset, length, address); 105 GetTypeName().c_str(), GetName().c_str(), offset, length, address);
106 cmd_buff[2] = static_cast<u32>(backend->Read(offset, length, Memory::GetPointer(address))); 106 if (offset + length > backend->GetSize())
107 LOG_ERROR(Service_FS, "Reading from out of bounds offset=0x%llX length=0x%08X file_size=0x%llX", offset, length, backend->GetSize());
108 ResultVal<size_t> read = backend->Read(offset, length, Memory::GetPointer(address));
109 if (read.Failed()) {
110 cmd_buff[1] = read.Code().raw;
111 return read.Code();
112 }
113 cmd_buff[2] = static_cast<u32>(read.MoveFrom());
107 break; 114 break;
108 } 115 }
109 116
@@ -116,7 +123,13 @@ ResultVal<bool> File::SyncRequest() {
116 u32 address = cmd_buff[6]; 123 u32 address = cmd_buff[6];
117 LOG_TRACE(Service_FS, "Write %s %s: offset=0x%llx length=%d address=0x%x, flush=0x%x", 124 LOG_TRACE(Service_FS, "Write %s %s: offset=0x%llx length=%d address=0x%x, flush=0x%x",
118 GetTypeName().c_str(), GetName().c_str(), offset, length, address, flush); 125 GetTypeName().c_str(), GetName().c_str(), offset, length, address, flush);
119 cmd_buff[2] = static_cast<u32>(backend->Write(offset, length, flush != 0, Memory::GetPointer(address))); 126
127 ResultVal<size_t> written = backend->Write(offset, length, flush != 0, Memory::GetPointer(address));
128 if (written.Failed()) {
129 cmd_buff[1] = written.Code().raw;
130 return written.Code();
131 }
132 cmd_buff[2] = static_cast<u32>(written.MoveFrom());
120 break; 133 break;
121 } 134 }
122 135