summaryrefslogtreecommitdiffstats
path: root/src/core/file_sys
diff options
context:
space:
mode:
authorSubv <subv2112@gmail.com>2015-12-28 16:03:09 +0100
committerSubv <subv2112@gmail.com>2016-03-20 20:28:17 +0100
commit96f0e32f836b19edb3d14ce4f87a7aed1ac6a8e1 (patch)
tree9eed35100efe7714f7ef5a39ff2c3bbf897f3dae /src/core/file_sys
parentHLE/FS: Corrected the error codes for DeleteFile (diff)
downloadyuzu-96f0e32f836b19edb3d14ce4f87a7aed1ac6a8e1.tar
yuzu-96f0e32f836b19edb3d14ce4f87a7aed1ac6a8e1.tar.gz
yuzu-96f0e32f836b19edb3d14ce4f87a7aed1ac6a8e1.tar.bz2
yuzu-96f0e32f836b19edb3d14ce4f87a7aed1ac6a8e1.tar.lz
yuzu-96f0e32f836b19edb3d14ce4f87a7aed1ac6a8e1.tar.xz
yuzu-96f0e32f836b19edb3d14ce4f87a7aed1ac6a8e1.tar.zst
yuzu-96f0e32f836b19edb3d14ce4f87a7aed1ac6a8e1.zip
Diffstat (limited to 'src/core/file_sys')
-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
5 files changed, 24 insertions, 16 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() {
return file->IsOpen();
}
-size_t DiskFile::Read(const u64 offset, const size_t length, u8* buffer) const {
+ResultVal<size_t> DiskFile::Read(const u64 offset, const size_t length, u8* buffer) const {
+ if (!mode.read_flag && !mode.write_flag)
+ return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status);
+
file->Seek(offset, SEEK_SET);
- return file->ReadBytes(buffer, length);
+ return MakeResult<size_t>(file->ReadBytes(buffer, length));
}
-size_t DiskFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const {
+ResultVal<size_t> DiskFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const {
+ if (!mode.write_flag)
+ return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status);
+
file->Seek(offset, SEEK_SET);
size_t written = file->WriteBytes(buffer, length);
if (flush)
file->Flush();
- return written;
+ return MakeResult<size_t>(written);
}
u64 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:
DiskFile(const DiskArchive& archive, const Path& path, const Mode mode);
bool Open() override;
- size_t Read(u64 offset, size_t length, u8* buffer) const override;
- size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const override;
+ ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override;
+ ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) const override;
u64 GetSize() const override;
bool SetSize(u64 size) const override;
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 @@
#include <cstddef>
#include "common/common_types.h"
+#include "core/hle/result.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
// FileSys namespace
@@ -29,9 +30,9 @@ public:
* @param offset Offset in bytes to start reading data from
* @param length Length in bytes of data to read from file
* @param buffer Buffer to read data into
- * @return Number of bytes read
+ * @return Number of bytes read, or error code
*/
- virtual size_t Read(u64 offset, size_t length, u8* buffer) const = 0;
+ virtual ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const = 0;
/**
* Write data to the file
@@ -39,9 +40,9 @@ public:
* @param length Length in bytes of data to write to file
* @param flush The flush parameters (0 == do not flush)
* @param buffer Buffer to read data from
- * @return Number of bytes written
+ * @return Number of bytes written, or error code
*/
- virtual size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const = 0;
+ virtual ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) const = 0;
/**
* 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 {
////////////////////////////////////////////////////////////////////////////////////////////////////
-size_t IVFCFile::Read(const u64 offset, const size_t length, u8* buffer) const {
+ResultVal<size_t> IVFCFile::Read(const u64 offset, const size_t length, u8* buffer) const {
LOG_TRACE(Service_FS, "called offset=%llu, length=%zu", offset, length);
romfs_file->Seek(data_offset + offset, SEEK_SET);
size_t read_length = (size_t)std::min((u64)length, data_size - offset);
- return romfs_file->ReadBytes(buffer, read_length);
+ return MakeResult<size_t>(romfs_file->ReadBytes(buffer, read_length));
}
-size_t IVFCFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const {
+ResultVal<size_t> IVFCFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const {
LOG_ERROR(Service_FS, "Attempted to write to IVFC file");
- return 0;
+ // TODO(Subv): Find error code
+ return MakeResult<size_t>(0);
}
u64 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:
: romfs_file(file), data_offset(offset), data_size(size) {}
bool Open() override { return true; }
- size_t Read(u64 offset, size_t length, u8* buffer) const override;
- size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const override;
+ ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override;
+ ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) const override;
u64 GetSize() const override;
bool SetSize(u64 size) const override;
bool Close() const override { return false; }