[PATCH] Initialize IO_STATUS_BLOCK for pread, pwrite

Mark Geisert mark@maxrnd.com
Mon Dec 11 09:24:00 GMT 2017


Just closing out this email thread...

On Fri, 1 Dec 2017, Mark Geisert wrote:
> On Fri, 1 Dec 2017, Corinna Vinschen wrote:
>> On Dec  1 10:30, Corinna Vinschen wrote:
>>> On Dec  1 00:44, Mark Geisert wrote:
>>>> And then pwrite() creates its own handle (or reuses one (!)) to avoid
>>>> messing up the seek pointer of the fd passed in.
>>> 
>>> Wait.  Not "re-use", but "re-open".  If you're more familiar with POSIX
>>> terms, this is along the lines of the fdopen(3) call, just on the NT
>>> API level.  There's an equivalent Win32 function since Windows 2003
>>> called ReOpenFile.
>>> 
>>> In terms of pread/pwrite, the new handle shares the same settings with
>>> the original handle.  However, if you use cygwin_attach_handle_to_fd,
>>> there's a chance information got lost.  Nobody actually uses this call ;)
>>> 
>>> In terms of FILE_SYNCHRONOUS_IO_NONALERT, this is stored in
>>> fhandler_base::options, utilizing the get_options/set_options methods.
>>> I have a hunch that cygwin_attach_handle_to_fd fails to call set_options,
>>> thus options is 0 when you call pwrite, thus the new handle is opened
>>> without FILE_SYNCHRONOUS_IO_NONALERT and all the other option flags
>>> we use by default.
>> 
>> It's more than a hunch.  Of course the info gets lost since
>> none of the functions called by cygwin_attach_handle_to_fd calls
>> NtQueryInformationFile(FileModeInformation) to fetch the options.
>
> Bang.  There it is.  Let me fix the offending program to just use 
> Cygwin-supplied handles and make sure this bug of mine is squashed.  I'll 
> report back but it might be a few days.

Yes, this bug of mine that I was blaming pwrite() internals for, 
doesn't occur when using Cygwin-supplied file descriptors with Cygwin i/o 
calls.  Who new?

Sorry for the noise, but at least what I learned from this discussion is 
very helpful in figuring out what makes sense for a future async i/o 
facility in Cygwin.

I have some further comments but I'll take them to cygwin-developers.
This IO_STATUS_BLOCK patch is withdrawn ;-) .

..mark



More information about the Cygwin-patches mailing list