From 381a5c053f76a7d85d811ebf37a5943f6a57579e Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 28 Dec 2015 09:38:10 -0500 Subject: HLE/FS: FS::CreateFile takes an u64 for the file size. --- src/core/file_sys/disk_archive.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/file_sys/disk_archive.cpp') diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp index a51416774..614c2e2a0 100644 --- a/src/core/file_sys/disk_archive.cpp +++ b/src/core/file_sys/disk_archive.cpp @@ -37,7 +37,7 @@ bool DiskArchive::DeleteDirectory(const Path& path) const { return FileUtil::DeleteDir(mount_point + path.AsString()); } -ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u32 size) const { +ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u64 size) const { std::string full_path = mount_point + path.AsString(); if (FileUtil::Exists(full_path)) -- cgit v1.2.3 From b350f192bbfe61a212e00ea70d4dcd7d3e90b60a Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 28 Dec 2015 09:55:38 -0500 Subject: HLE/FS: Corrected the error codes for CreateFile --- src/core/file_sys/disk_archive.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/core/file_sys/disk_archive.cpp') diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp index 614c2e2a0..5c68e944f 100644 --- a/src/core/file_sys/disk_archive.cpp +++ b/src/core/file_sys/disk_archive.cpp @@ -40,8 +40,11 @@ bool DiskArchive::DeleteDirectory(const Path& path) const { ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u64 size) const { std::string full_path = mount_point + path.AsString(); + if (FileUtil::IsDirectory(full_path)) + return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); + if (FileUtil::Exists(full_path)) - return ResultCode(ErrorDescription::AlreadyExists, ErrorModule::FS, ErrorSummary::NothingHappened, ErrorLevel::Info); + return ResultCode(ErrorDescription::FS_AlreadyExists, ErrorModule::FS, ErrorSummary::NothingHappened, ErrorLevel::Status); if (size == 0) { FileUtil::CreateEmptyFile(full_path); -- cgit v1.2.3 From 09b0564c75c3da41eaf15dcb847831c11f4c27b9 Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 28 Dec 2015 09:59:27 -0500 Subject: HLE/FS: Corrected the error codes for DeleteFile --- src/core/file_sys/disk_archive.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/core/file_sys/disk_archive.cpp') diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp index 5c68e944f..0c55a4863 100644 --- a/src/core/file_sys/disk_archive.cpp +++ b/src/core/file_sys/disk_archive.cpp @@ -25,8 +25,19 @@ std::unique_ptr DiskArchive::OpenFile(const Path& path, const Mode return std::move(file); } -bool DiskArchive::DeleteFile(const Path& path) const { - return FileUtil::Delete(mount_point + path.AsString()); +ResultCode DiskArchive::DeleteFile(const Path& path) const { + std::string file_path = mount_point + path.AsString(); + + if (FileUtil::IsDirectory(file_path)) + return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); + + if (!FileUtil::Exists(file_path)) + return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Status); + + if (FileUtil::Delete(file_path)) + return RESULT_SUCCESS; + + return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); } bool DiskArchive::RenameFile(const Path& src_path, const Path& dest_path) const { -- cgit v1.2.3 From 96f0e32f836b19edb3d14ce4f87a7aed1ac6a8e1 Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 28 Dec 2015 10:03:09 -0500 Subject: 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. --- src/core/file_sys/disk_archive.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/core/file_sys/disk_archive.cpp') 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 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(file->ReadBytes(buffer, length)); } -size_t DiskFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const { +ResultVal 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(written); } u64 DiskFile::GetSize() const { -- cgit v1.2.3 From 95b34f8081e26cfe75d63a853d1626fdd5b636e6 Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 28 Dec 2015 10:17:06 -0500 Subject: HLE/FS: Return the proper error codes when opening files. --- src/core/file_sys/disk_archive.cpp | 44 +++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'src/core/file_sys/disk_archive.cpp') diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp index 2dca895fd..8e4ea01c5 100644 --- a/src/core/file_sys/disk_archive.cpp +++ b/src/core/file_sys/disk_archive.cpp @@ -17,12 +17,13 @@ namespace FileSys { -std::unique_ptr DiskArchive::OpenFile(const Path& path, const Mode mode) const { +ResultVal> DiskArchive::OpenFile(const Path& path, const Mode mode) const { LOG_DEBUG(Service_FS, "called path=%s mode=%01X", path.DebugStr().c_str(), mode.hex); auto file = Common::make_unique(*this, path, mode); - if (!file->Open()) - return nullptr; - return std::move(file); + ResultCode result = file->Open(); + if (result.IsError()) + return result; + return MakeResult>(std::move(file)); } ResultCode DiskArchive::DeleteFile(const Path& path) const { @@ -103,25 +104,38 @@ DiskFile::DiskFile(const DiskArchive& archive, const Path& path, const Mode mode this->mode.hex = mode.hex; } -bool DiskFile::Open() { - if (!mode.create_flag && !FileUtil::Exists(path)) { - LOG_ERROR(Service_FS, "Non-existing file %s can't be open without mode create.", path.c_str()); - return false; +ResultCode DiskFile::Open() { + if (FileUtil::IsDirectory(path)) + return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); + + // Specifying only the Create flag is invalid + if (mode.create_flag && !mode.read_flag && !mode.write_flag) { + return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); } - std::string mode_string; - if (mode.create_flag) - mode_string = "w+"; - else if (mode.write_flag) - mode_string = "r+"; // Files opened with Write access can be read from + if (!FileUtil::Exists(path)) { + if (!mode.create_flag) { + LOG_ERROR(Service_FS, "Non-existing file %s can't be open without mode create.", path.c_str()); + return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Status); + } else { + // Create the file + FileUtil::CreateEmptyFile(path); + } + } + + std::string mode_string = ""; + if (mode.write_flag) + mode_string += "r+"; // Files opened with Write access can be read from else if (mode.read_flag) - mode_string = "r"; + mode_string += "r"; // Open the file in binary mode, to avoid problems with CR/LF on Windows systems mode_string += "b"; file = Common::make_unique(path, mode_string.c_str()); - return file->IsOpen(); + if (file->IsOpen()) + return RESULT_SUCCESS; + return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Status); } ResultVal DiskFile::Read(const u64 offset, const size_t length, u8* buffer) const { -- cgit v1.2.3