Re: [PATCH] windows: fix pread/pwrite
Vincent Fu <[email protected]>
| Newsgroups | org.kernel.vger.fio |
|---|---|
| Message-ID | <[email protected]> |
On 5/8/25 5:28 PM, Sitsofe Wheeler wrote: > Hi Vincent, > > On Thu, 8 May 2025 at 18:33, Vincent Fu <[email protected]> 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. > > Oof! Good catch! > > [...] > >>> lol, how broken is that... Does windows have any offset read/write >>> variants, or is lseek required? >> >> 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? > > Sadly (?) I'm not a Windows expert (even if I've occasionally played one) but > according to an answer on > https://stackoverflow.com/questions/3852758/equivalent-to-pread-pwrite-in-msvc > the only thing that can take an offset with the request is ReadFile/WriteFile > and this is done by passing an OVERLAPPED structure > (https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-overlapped > ) which in turn can specify an offset even for synchronous I/O (see > https://learn.microsoft.com/en-gb/windows/win32/api/fileapi/nf-fileapi-writefile?redirectedfrom=MSDN#synchronization-and-file-position > ). Unfortunately ReadFile/WriteFile only work with Windows handles but I think > you can get one from a file descriptor via _get_osfhandle (see > https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle?view=msvc-170). > > -- > Sitsofe Sitsofe, many thanks for taking a look. I think my patch is good enough for now but I'm pleased to know that someone who really caress about this may be able to eventually improve on it. Vincent