From 397f5e54e0472b0f2e348dcdb648adfbeef8ba3a Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Sun, 6 Aug 2017 22:19:08 +0200 Subject: [PATCH] WFS: Implement READ_ABSOLUTE (merged with READ implementation). --- Source/Core/Core/IOS/WFS/WFSSRV.cpp | 25 +++++++++++++++++++------ Source/Core/Core/IOS/WFS/WFSSRV.h | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Source/Core/Core/IOS/WFS/WFSSRV.cpp b/Source/Core/Core/IOS/WFS/WFSSRV.cpp index a2601f3422..0a76d6e482 100644 --- a/Source/Core/Core/IOS/WFS/WFSSRV.cpp +++ b/Source/Core/Core/IOS/WFS/WFSSRV.cpp @@ -189,26 +189,39 @@ IPCCommandResult WFSSRV::IOCtl(const IOCtlRequest& request) } case IOCTL_WFS_READ: + case IOCTL_WFS_READ_ABSOLUTE: { u32 addr = Memory::Read_U32(request.buffer_in); + u32 position = Memory::Read_U32(request.buffer_in + 4); // Only for absolute. u16 fd = Memory::Read_U16(request.buffer_in + 0xC); u32 size = Memory::Read_U32(request.buffer_in + 8); + bool absolute = request.request == IOCTL_WFS_READ_ABSOLUTE; + FileDescriptor* fd_obj = FindFileDescriptor(fd); if (fd_obj == nullptr) { ERROR_LOG(IOS, "IOCTL_WFS_READ: invalid file descriptor %d", fd); - return_error_code = -1; // TODO(wfs): proper error code. + return_error_code = WFS_EBADFD; break; } - size_t read_bytes; - if (!fd_obj->file.ReadArray(Memory::GetPointer(addr), size, &read_bytes)) + u64 previous_position = fd_obj->file.Tell(); + if (absolute) { - return_error_code = -1; // TODO(wfs): proper error code. - break; + fd_obj->file.Seek(position, SEEK_SET); + } + size_t read_bytes; + fd_obj->file.ReadArray(Memory::GetPointer(addr), size, &read_bytes); + // TODO(wfs): Handle read errors. + if (absolute) + { + fd_obj->file.Seek(previous_position, SEEK_SET); + } + else + { + fd_obj->position += read_bytes; } - fd_obj->position += read_bytes; INFO_LOG(IOS, "IOCTL_WFS_READ: read %zd bytes from FD %d (%s)", read_bytes, fd, fd_obj->path.c_str()); diff --git a/Source/Core/Core/IOS/WFS/WFSSRV.h b/Source/Core/Core/IOS/WFS/WFSSRV.h index 72b051f87a..cba30037a1 100644 --- a/Source/Core/Core/IOS/WFS/WFSSRV.h +++ b/Source/Core/Core/IOS/WFS/WFSSRV.h @@ -67,6 +67,7 @@ private: IOCTL_WFS_WRITE = 0x22, IOCTL_WFS_ATTACH_DETACH = 0x2d, IOCTL_WFS_ATTACH_DETACH_2 = 0x2e, + IOCTL_WFS_READ_ABSOLUTE = 0x48, }; enum