Web lists-archives.com

Wrong file position after writing 65537 bytes to block device


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

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.

Best regards,



#include <stdio.h>

int main(int argc, char *argv[]) {
    FILE *f = fopen(argv[1], "w");
    char x[65536 + 1];
    fwrite(x, 1, 65536 + 1, f);
    printf("%ld", ftell(f));
    return 0;

Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple