From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 33813 invoked by alias); 19 Dec 2017 09:14:42 -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 33802 invoked by uid 89); 19 Dec 2017 09:14:42 -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=expectation 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; Tue, 19 Dec 2017 09:14:39 +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 0584172106C13 for ; Tue, 19 Dec 2017 10:14:31 +0100 (CET) Received: from calimero.vinschen.de (calimero.vinschen.de [192.168.129.6]) by aqua.hirmke.de (Postfix) with ESMTP id AF5A45E0498 for ; Tue, 19 Dec 2017 10:14:30 +0100 (CET) Received: by calimero.vinschen.de (Postfix, from userid 500) id 23790A805F1; Tue, 19 Dec 2017 10:14:31 +0100 (CET) Date: Tue, 19 Dec 2017 10:20:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: Wrong file position after writing 65537 bytes to block device Message-ID: <20171219091431.GF11285@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <20171218131035.GB11285@calimero.vinschen.de> <5a385ced.195b9d0a.d434.5400@mx.google.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="C94crkcyjafcjHxo" Content-Disposition: inline In-Reply-To: <5a385ced.195b9d0a.d434.5400@mx.google.com> User-Agent: Mutt/1.9.1 (2017-09-22) X-SW-Source: 2017-12/txt/msg00191.txt.bz2 --C94crkcyjafcjHxo Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 2014 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 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. > >=20 > > Looks like a patch is required. Stay tuned. >=20 > is it though? he says "write 65536 + 1 bytes", but as far as i can tell, = you > cant do that. quoting myself: >=20 > > Seeking, reading and writing must all be done in multiples of sector si= ze, in > > my case 512 bytes >=20 > http://web.archive.org/web/stackoverflow.com/questions/37228874/how-to-fw= rite-to-removable-volume >=20 > so it would make sense that the position becomes "65536 + 512" 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 is kept in the stdio buffer: fwrite(65537) -> write(65536) -> store 1 byte in FILE._buf ftell calls lseek which returns 65536. It adds the number of bytes still in the buffer, so it should return 65537. Further fwrite's seemlessly append to the bytes already written, as expected. ftell calling fflush and thus setting the current file position to the next sector boundary breaks this expectation. I pushed a patch yesterday and uploaded new developer snapshots to https://cygwin.com/snapshots/ Please test. Thanks, Corinna --=20 Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat --C94crkcyjafcjHxo Content-Type: application/pgp-signature; name="signature.asc" Content-length: 819 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJaONh2AAoJEPU2Bp2uRE+gjpUQAIuLQ8+G0uN4Ha5Ky1kOTrjC RVbEAUflICtbOGGukyK5zHFn0RZEXlcUv0q22m2D4buFZfve/+lQjmNe+ZexY9Tq qdO7eg0FM4KOWp62zuSejzM+ZbBUC0lBmuq9i5X+2Y1/U3Q4iTm+moNbuEygLYTf MqBANkvEtamTZghP+8UQnu4AOiJj8Dx6UyhWIdr6u6Yp79uvhe06M01SDJE3nVG8 R6uQQA4sjnYb8ARHwShM9319Cf5vy1S39ZcouWKNGG27LVtufDej8pwRlQgEZ37J JQsY3YVWOgHt9QFhzhBLqhwAYHTaqW9aqQjz++rhzOBZQixBL8T/4eya+eYCHOKS RM2wpr3e29+1OjJAqYrUoNvyNAmT5s1gH6CB5wE5CuCarTuofqAX7LDZ2LkW277q eNrkfKRsn7tW3YH79/PO/dVOHU0CEuOTi6XGSZEHzpu9a65bKGLcxU9SdPh7UgPf cCwTBRF8aVhYLhq535wWYmLBMgit/FRQqjmnFYAgOD2sljCAj1scnT75n9vOtDD/ aDC3Xfbn2aKjDYNnqfs7U+q0nVkJpYTFDOCdOAJXgncKvNH2j6cOXl07Qp5XC4s8 Jg+gTPryRrsEx2zw+82+xeRackIItOfZW5zIvt3ey72zc47iEwwTPnwL926jB8Rz JaPfpjH8m+hTcLtsjWJ8 =5qkl -----END PGP SIGNATURE----- --C94crkcyjafcjHxo--