diff --git a/libraries/libstratosphere/include/stratosphere/fs/fsa/fs_ifile.hpp b/libraries/libstratosphere/include/stratosphere/fs/fsa/fs_ifile.hpp index 5466dfe80..422240110 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/fsa/fs_ifile.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/fsa/fs_ifile.hpp @@ -85,7 +85,7 @@ namespace ams::fs::fsa { protected: Result DryRead(size_t *out, s64 offset, size_t size, const fs::ReadOption &option, OpenMode open_mode) { /* Check that we can read. */ - R_UNLESS((open_mode & OpenMode_Read) != 0, fs::ResultInvalidOperationForOpenMode()); + R_UNLESS((open_mode & OpenMode_Read) != 0, fs::ResultReadNotPermitted()); /* Get the file size, and validate our offset. */ s64 file_size = 0; @@ -98,12 +98,31 @@ namespace ams::fs::fsa { Result DrySetSize(s64 size, fs::OpenMode open_mode) { /* Check that we can write. */ - R_UNLESS((open_mode & OpenMode_Write) != 0, fs::ResultInvalidOperationForOpenMode()); + R_UNLESS((open_mode & OpenMode_Write) != 0, fs::ResultWriteNotPermitted()); AMS_ASSERT(size >= 0); return ResultSuccess(); } + + Result DryWrite(bool *out_append, s64 offset, size_t size, const fs::WriteOption &option, fs::OpenMode open_mode) { + /* Check that we can write. */ + R_UNLESS((open_mode & OpenMode_Write) != 0, fs::ResultWriteNotPermitted()); + + /* Get the file size. */ + s64 file_size = 0; + R_TRY(this->GetSize(&file_size)); + + /* Determine if we need to append. */ + if (file_size < offset + static_cast(size)) { + R_UNLESS((open_mode & OpenMode_AllowAppend) != 0, fs::ResultFileExtensionWithoutOpenModeAllowAppend()); + *out_append = true; + } else { + *out_append = false; + } + + return ResultSuccess(); + } private: virtual Result ReadImpl(size_t *out, s64 offset, void *buffer, size_t size, const fs::ReadOption &option) = 0; virtual Result GetSizeImpl(s64 *out) = 0; diff --git a/libraries/libvapours/include/vapours/results/fs_results.hpp b/libraries/libvapours/include/vapours/results/fs_results.hpp index eb8bde043..c2985f2e1 100644 --- a/libraries/libvapours/include/vapours/results/fs_results.hpp +++ b/libraries/libvapours/include/vapours/results/fs_results.hpp @@ -240,6 +240,8 @@ namespace ams::fs { R_DEFINE_ERROR_RANGE(InvalidOperationForOpenMode, 6200, 6299); R_DEFINE_ERROR_RESULT(FileExtensionWithoutOpenModeAllowAppend, 6201); + R_DEFINE_ERROR_RESULT(ReadNotPermitted, 6202); + R_DEFINE_ERROR_RESULT(WriteNotPermitted, 6203); R_DEFINE_ERROR_RANGE(UnsupportedOperation, 6300, 6399); R_DEFINE_ERROR_RESULT(UnsupportedOperationInSubStorageA, 6302);