diff --git a/Source/Core/Core/IOS/WFS/WFSSRV.cpp b/Source/Core/Core/IOS/WFS/WFSSRV.cpp index 6ff55a8e66..a2601f3422 100644 --- a/Source/Core/Core/IOS/WFS/WFSSRV.cpp +++ b/Source/Core/Core/IOS/WFS/WFSSRV.cpp @@ -4,6 +4,7 @@ #include "Core/IOS/WFS/WFSSRV.h" +#include #include #include @@ -157,6 +158,28 @@ IPCCommandResult WFSSRV::IOCtl(const IOCtlRequest& request) break; } + case IOCTL_WFS_GET_SIZE: + { + u16 fd = Memory::Read_U16(request.buffer_in); + FileDescriptor* fd_obj = FindFileDescriptor(fd); + if (fd_obj == nullptr) + { + ERROR_LOG(IOS, "IOCTL_WFS_GET_SIZE: invalid file descriptor %d", fd); + return_error_code = WFS_EBADFD; + break; + } + + u64 size = fd_obj->file.GetSize(); + u32 truncated_size = static_cast(size); + INFO_LOG(IOS, "IOCTL_WFS_GET_SIZE(%d) -> %d", fd, truncated_size); + if (size != truncated_size) + { + ERROR_LOG(IOS, "IOCTL_WFS_GET_SIZE: file %d too large (%" PRIu64 ")", fd, size); + } + Memory::Write_U32(truncated_size, request.buffer_out); + break; + } + case IOCTL_WFS_CLOSE: { u16 fd = Memory::Read_U16(request.buffer_in + 0x4); diff --git a/Source/Core/Core/IOS/WFS/WFSSRV.h b/Source/Core/Core/IOS/WFS/WFSSRV.h index 889bfc25fd..72b051f87a 100644 --- a/Source/Core/Core/IOS/WFS/WFSSRV.h +++ b/Source/Core/Core/IOS/WFS/WFSSRV.h @@ -61,6 +61,7 @@ private: IOCTL_WFS_DELETE = 0x15, IOCTL_WFS_GET_ATTRIBUTES = 0x17, IOCTL_WFS_OPEN = 0x1A, + IOCTL_WFS_GET_SIZE = 0x1B, IOCTL_WFS_CLOSE = 0x1E, IOCTL_WFS_READ = 0x20, IOCTL_WFS_WRITE = 0x22, @@ -70,6 +71,7 @@ private: enum { + WFS_EBADFD = -10026, // Invalid file descriptor. WFS_EEMPTY = -10028, // Directory is empty of iteration completed. };