diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index 88a6fceaff..648c73d988 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -92,7 +92,7 @@ namespace size_t result = pspFileSystem.WriteFile(handle, data, dataSize); pspFileSystem.CloseFile(handle); - return result != 0; + return result == dataSize; } bool PSPMatch(std::string text, std::string regexp) diff --git a/Core/FileSystems/DirectoryFileSystem.cpp b/Core/FileSystems/DirectoryFileSystem.cpp index d77616a83e..499eed79c5 100644 --- a/Core/FileSystems/DirectoryFileSystem.cpp +++ b/Core/FileSystems/DirectoryFileSystem.cpp @@ -290,10 +290,19 @@ size_t DirectoryFileHandle::Read(u8* pointer, s64 size) size_t DirectoryFileHandle::Write(const u8* pointer, s64 size) { size_t bytesWritten = 0; + bool diskFull = false; + #ifdef _WIN32 - ::WriteFile(hFile, (LPVOID)pointer, (DWORD)size, (LPDWORD)&bytesWritten, 0); + BOOL success = ::WriteFile(hFile, (LPVOID)pointer, (DWORD)size, (LPDWORD)&bytesWritten, 0); + if (success == FALSE) { + DWORD err = GetLastError(); + diskFull = err == ERROR_DISK_FULL || err == ERROR_NOT_ENOUGH_QUOTA; + } #else bytesWritten = write(hFile, pointer, size); + if (bytesWritten == (size_t)-1) { + diskFull = errno == ENOSPC; + } #endif if (needsTrunc_ != -1) { off_t off = (off_t)Seek(0, FILEMOVE_CURRENT); @@ -301,6 +310,13 @@ size_t DirectoryFileHandle::Write(const u8* pointer, s64 size) needsTrunc_ = off; } } + + if (diskFull) { + // Sign extend on 64-bit. + ERROR_LOG(FILESYS, "Disk full"); + return (size_t)(s64)(s32)SCE_KERNEL_ERROR_ERRNO_DEVICE_NO_FREE_SPACE; + } + return bytesWritten; } diff --git a/Core/HW/AsyncIOManager.cpp b/Core/HW/AsyncIOManager.cpp index 89dfaf6481..c022f16404 100644 --- a/Core/HW/AsyncIOManager.cpp +++ b/Core/HW/AsyncIOManager.cpp @@ -96,7 +96,8 @@ void AsyncIOManager::Read(u32 handle, u8 *buf, size_t bytes) { } void AsyncIOManager::Write(u32 handle, u8 *buf, size_t bytes) { - size_t result = pspFileSystem.WriteFile(handle, buf, bytes); + // We want to sign extend this on 32-bit. + AsyncIOResult result = (ssize_t)pspFileSystem.WriteFile(handle, buf, bytes); EventResult(handle, result); } diff --git a/Core/HW/AsyncIOManager.h b/Core/HW/AsyncIOManager.h index 8fb96a16ee..76d6f5e7f9 100644 --- a/Core/HW/AsyncIOManager.h +++ b/Core/HW/AsyncIOManager.h @@ -44,7 +44,7 @@ struct AsyncIOEvent { }; // TODO: Something better. -typedef size_t AsyncIOResult; +typedef s64 AsyncIOResult; typedef ThreadEventQueue IOThreadEventQueue; class AsyncIOManager : public IOThreadEventQueue { diff --git a/UI/BackgroundAudio.cpp b/UI/BackgroundAudio.cpp index 8abe4ac9b1..5116b2c7b9 100644 --- a/UI/BackgroundAudio.cpp +++ b/UI/BackgroundAudio.cpp @@ -57,7 +57,7 @@ public: Nothing = temp >> 16; if (codec == PSP_CODEC_AT3) { - // The first two bytes are actually not useful part of the extradata. + // The first two bytes are actually not a useful part of the extradata. // We already read 16 bytes, so make sure there's enough left. if (file_.getCurrentChunkSize() >= 32) { file_.readData(at3_extradata, 16);