From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 107559 invoked by alias); 18 Dec 2017 13:10:41 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 107490 invoked by uid 89); 18 Dec 2017 13:10:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-100.3 required=5.0 tests=AWL,BAYES_00,GOOD_FROM_CORINNA_CYGWIN,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_BRBL_LASTEXT,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Ivan, kozik, Kozik, Stay X-HELO: drew.franken.de Received: from mail-n.franken.de (HELO drew.franken.de) (193.175.24.27) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 18 Dec 2017 13:10:38 +0000 Received: from aqua.hirmke.de (aquarius.franken.de [193.175.24.89]) (Authenticated sender: aquarius) by mail-n.franken.de (Postfix) with ESMTPSA id AF0D972106C24 for ; Mon, 18 Dec 2017 14:10:35 +0100 (CET) Received: from calimero.vinschen.de (calimero.vinschen.de [192.168.129.6]) by aqua.hirmke.de (Postfix) with ESMTP id 561275E01C7 for ; Mon, 18 Dec 2017 14:10:35 +0100 (CET) Received: by calimero.vinschen.de (Postfix, from userid 500) id B3CFFA8036A; Mon, 18 Dec 2017 14:10:35 +0100 (CET) Date: Mon, 18 Dec 2017 16:32:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: Wrong file position after writing 65537 bytes to block device Message-ID: <20171218131035.GB11285@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="mP3DRpeJDSE+ciuQ" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) X-SW-Source: 2017-12/txt/msg00169.txt.bz2 --mP3DRpeJDSE+ciuQ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 1235 On Dec 16 02:07, Ivan Kozik wrote: > Hello, >=20 > I have discovered that if you write 65536 + 1 bytes to a block device > in cygwin, the file position can become 65536 + 512. >=20 > With /dev/sdc as a throwaway USB block device: >=20 > (cygwin_write.c is pasted below) > # gcc -O2 -Wall -o cygwin_write cygwin_write.c > # ./cygwin_write /dev/sdc > 66048 >=20 > 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 --=20 Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat --mP3DRpeJDSE+ciuQ Content-Type: application/pgp-signature; name="signature.asc" Content-length: 819 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJaN75LAAoJEPU2Bp2uRE+gF3EQAIFF3CCRbb3k51088FvtRaNa 7fzWsqur6MZoFKMMge6hB2ze3phwZPcZWINQmzSIXKibJhLbQ/P3HLFCio5jg816 VDLq2BJqJLZAaWCN3MGdJRmW2j3noLrlVHDQ4EbyVxXkDe5uRbZSwwsyyV7EW4CQ rT7/MpnDixORLnEExcHcaYBmY8dwkJvSujmcsHuiK++q7Lwu/mnykhZPm3BbGBZ7 tD/lJ2yL+AyUwmjFsowJeHIIl7vxbEBK8No/tVSiwUJZwWG1X+AibPuSk3AVBHAJ 1ge9gWDygfwhjgHkuDI4nMh6gH1/yT0WWjROvhpDad1/KjBfTjr7XIehGSsF/cPC xN/kkmQXw3lfgxbjkjxReLT9PGKcBewtISKHhXvRyI8FiSH+mUlNPnaFEmcMEqY2 yH6PCVGsG8GjDvRM79AVXSHbwowPhAIHGKGvS8UDZg79DV26bnNXp+zHxn3iG/zo 5I88l/6f82Km0HmRsZRehxmbEeMob07Yr/LE0PsXbQTSYAJe8y2PYWwpeKbccVQM xEJZdmRDhERgAdUeR1HUPFi4Rz+kfCAtSlxLRE3LU29R4L5JjvTySgfDjliEUI+q qliFoG8REmECnMp95u89LLRZXmYCIV0/KJnbzHLE9xrd6GgObwTW+BZX2br3I23j 6Lu4pttsK+Vtp3gsTwOn =EEGV -----END PGP SIGNATURE----- --mP3DRpeJDSE+ciuQ--