Wrong file position after writing 65537 bytes to block device
Corinna Vinschen
corinna-cygwin@cygwin.com
Mon Dec 18 16:32:00 GMT 2017
On Dec 16 02:07, Ivan Kozik wrote:
> Hello,
>
> I have discovered that if you write 65536 + 1 bytes to a block device
> in cygwin, the file position can become 65536 + 512.
>
> With /dev/sdc as a throwaway USB block device:
>
> (cygwin_write.c is pasted below)
> # gcc -O2 -Wall -o cygwin_write cygwin_write.c
> # ./cygwin_write /dev/sdc
> 66048
>
> I am running 64-bit cygwin 2.9.0 on an updated Windows 8.1. I saw the
> same results with an 8TB drive and a 512MB USB stick.
In general, the writes on disk devices is sector-oriented. Howewver,
in this case ftell should have returned 65536. The problem here is
that the newlib implmentation of ftell/ftello performs an fflush
when called on a write stream since about 2008 to adjust for appending
streams. Given your example (thanks for the testcase!) this seems
pretty wrong. Looking further it turns out that neither glibc nor BSD
actually calls fflush in this case. There's only a special case for
appending streams, but this calls lseek, not fflush.
Looks like a patch is required. Stay tuned.
Thanks,
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20171218/020fe235/attachment.sig>
More information about the Cygwin
mailing list