Re: Wrong file position after writing 65537 bytes to block device

2017-12-20 Thread Kaz Kylheku
On 18.12.2017 16:27, Steven Penny wrote: On Mon, 18 Dec 2017 14:10:35, Corinna Vinschen wrote: 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

Re: Wrong file position after writing 65537 bytes to block device

2017-12-19 Thread Ivan Kozik
On Tue, Dec 19, 2017 at 6:19 PM, Corinna Vinschen wrote: > On Dec 19 16:35, Ivan Kozik wrote: >> From what I observe on Linux, it supports writing at any offset to the >> block device because it does a read-modify-write behind the scenes, >> with accompanying nasty

Re: Wrong file position after writing 65537 bytes to block device

2017-12-19 Thread Corinna Vinschen
On Dec 19 16:35, Ivan Kozik wrote: > On Tue, Dec 19, 2017 at 4:13 PM, Eric Blake wrote: > > Can block devices report an unaligned offset to lseek()? If not, then when > > writing an unaligned value to a block device, don't we have to do a > > read-modify-write of the larger

Re: Wrong file position after writing 65537 bytes to block device

2017-12-19 Thread Ivan Kozik
On Tue, Dec 19, 2017 at 4:13 PM, Eric Blake wrote: > Can block devices report an unaligned offset to lseek()? If not, then when > writing an unaligned value to a block device, don't we have to do a > read-modify-write of the larger aligned cluster, and then put lseek() back >

Re: Wrong file position after writing 65537 bytes to block device

2017-12-19 Thread Eric Blake
On 12/19/2017 09:46 AM, Ivan Kozik wrote: Thanks, I can confirm that the 2017-12-18 snapshot fixed the test program I posted. What about the harder case where the program calls fflush, though? #include int main(int argc, char *argv[]) { FILE *f = fopen(argv[1], "w"); char x[65536 +

Re: Wrong file position after writing 65537 bytes to block device

2017-12-19 Thread Ivan Kozik
On Tue, Dec 19, 2017 at 9:14 AM, Corinna Vinschen wrote: > Neither glibc nor FreeBSD show this behaviour. Keep in mind that stdio > is designed for buffered I/O. What should happen, basically, is that a > multiple of the stdio buffersize is written and the remainder

Re: Wrong file position after writing 65537 bytes to block device

2017-12-19 Thread Corinna Vinschen
On Dec 18 16:27, Steven Penny wrote: > On Mon, 18 Dec 2017 14:10:35, Corinna Vinschen wrote: > > 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

Re: Wrong file position after writing 65537 bytes to block device

2017-12-18 Thread Steven Penny
On Mon, 18 Dec 2017 14:10:35, Corinna Vinschen wrote: 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

Re: Wrong file position after writing 65537 bytes to block device

2017-12-18 Thread Corinna Vinschen
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

Wrong file position after writing 65537 bytes to block device

2017-12-15 Thread Ivan Kozik
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