Re: [PATCH] windows: fix pread/pwrite

Jens Axboe <[email protected]>
Newsgroups org.kernel.vger.fio
Message-ID <[email protected]>
On 5/8/25 11:31 AM, Vincent Fu wrote:
> On Thu, May 8, 2025 at 1:18?PM Jens Axboe <[email protected]> wrote:
>>
>> On 5/8/25 11:14 AM, Vincent Fu wrote:
>>> The pread and pwrite functions for Windows posix emulation never actually seek
>>> to the requested offset. Fix this so that the psync ioengine works correctly on
>>> Windows.
>>>
>>> Signed-off-by: Vincent Fu <[email protected]>
>>> ---
>>>  os/windows/posix.c | 10 ++++++++--
>>>  1 file changed, 8 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/os/windows/posix.c b/os/windows/posix.c
>>> index e3abf383..3e48c3ff 100644
>>> --- a/os/windows/posix.c
>>> +++ b/os/windows/posix.c
>>> @@ -830,18 +830,24 @@ ssize_t pwrite(int fildes, const void *buf, size_t nbyte,
>>>               off_t offset)
>>>  {
>>>       int64_t pos = _telli64(fildes);
>>> -     ssize_t len = _write(fildes, buf, nbyte);
>>> +     ssize_t len;
>>>
>>> +     _lseeki64(fildes, offset, SEEK_SET);
>>> +     len = _write(fildes, buf, nbyte);
>>>       _lseeki64(fildes, pos, SEEK_SET);
>>> +
>>>       return len;
>>>  }
>>>
>>>  ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset)
>>>  {
>>>       int64_t pos = _telli64(fildes);
>>> -     ssize_t len = read(fildes, buf, nbyte);
>>> +     ssize_t len;
>>>
>>> +     _lseeki64(fildes, offset, SEEK_SET);
>>> +     len = read(fildes, buf, nbyte);
>>>       _lseeki64(fildes, pos, SEEK_SET);
>>> +
>>>       return len;
>>>  }
>>
>> lol, how broken is that... Does windows have any offset read/write
>> variants, or is lseek required?
>>
>> --
>> Jens Axboe
>>
> 
> I could not find a better way to do this but I am hoping someone who
> knows more about Windows than I do can weigh in. Sitsofe?

It's probably not a big deal. I did a quick search and doesn't seem like
one exists for that.

-- 
Jens Axboe
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.