Handle disk full more properly in sceIoWrite().

This commit is contained in:
Unknown W. Brackets 2014-11-02 10:53:17 -08:00
parent 24ce3d11ed
commit d4e8bd96af
5 changed files with 22 additions and 5 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -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);
}

View File

@ -44,7 +44,7 @@ struct AsyncIOEvent {
};
// TODO: Something better.
typedef size_t AsyncIOResult;
typedef s64 AsyncIOResult;
typedef ThreadEventQueue<NoBase, AsyncIOEvent, AsyncIOEventType, IO_EVENT_INVALID, IO_EVENT_SYNC, IO_EVENT_FINISH> IOThreadEventQueue;
class AsyncIOManager : public IOThreadEventQueue {

View File

@ -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);