mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-07-17 22:22:21 +02:00
fs: add IFile::DryWrite, update results
This commit is contained in:
parent
f1494e650a
commit
4ee8d7fe75
@ -85,7 +85,7 @@ namespace ams::fs::fsa {
|
|||||||
protected:
|
protected:
|
||||||
Result DryRead(size_t *out, s64 offset, size_t size, const fs::ReadOption &option, OpenMode open_mode) {
|
Result DryRead(size_t *out, s64 offset, size_t size, const fs::ReadOption &option, OpenMode open_mode) {
|
||||||
/* Check that we can read. */
|
/* 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. */
|
/* Get the file size, and validate our offset. */
|
||||||
s64 file_size = 0;
|
s64 file_size = 0;
|
||||||
@ -98,12 +98,31 @@ namespace ams::fs::fsa {
|
|||||||
|
|
||||||
Result DrySetSize(s64 size, fs::OpenMode open_mode) {
|
Result DrySetSize(s64 size, fs::OpenMode open_mode) {
|
||||||
/* Check that we can write. */
|
/* 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);
|
AMS_ASSERT(size >= 0);
|
||||||
|
|
||||||
return ResultSuccess();
|
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<s64>(size)) {
|
||||||
|
R_UNLESS((open_mode & OpenMode_AllowAppend) != 0, fs::ResultFileExtensionWithoutOpenModeAllowAppend());
|
||||||
|
*out_append = true;
|
||||||
|
} else {
|
||||||
|
*out_append = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResultSuccess();
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
virtual Result ReadImpl(size_t *out, s64 offset, void *buffer, size_t size, const fs::ReadOption &option) = 0;
|
virtual Result ReadImpl(size_t *out, s64 offset, void *buffer, size_t size, const fs::ReadOption &option) = 0;
|
||||||
virtual Result GetSizeImpl(s64 *out) = 0;
|
virtual Result GetSizeImpl(s64 *out) = 0;
|
||||||
|
@ -240,6 +240,8 @@ namespace ams::fs {
|
|||||||
|
|
||||||
R_DEFINE_ERROR_RANGE(InvalidOperationForOpenMode, 6200, 6299);
|
R_DEFINE_ERROR_RANGE(InvalidOperationForOpenMode, 6200, 6299);
|
||||||
R_DEFINE_ERROR_RESULT(FileExtensionWithoutOpenModeAllowAppend, 6201);
|
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_RANGE(UnsupportedOperation, 6300, 6399);
|
||||||
R_DEFINE_ERROR_RESULT(UnsupportedOperationInSubStorageA, 6302);
|
R_DEFINE_ERROR_RESULT(UnsupportedOperationInSubStorageA, 6302);
|
||||||
|
Loading…
Reference in New Issue
Block a user