X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:subject:to:references:from:message-id:date
	:mime-version:in-reply-to:content-type
	:content-transfer-encoding; q=dns; s=default; b=jWv2C8LVxvVgvD8Z
	iUlceHssBnTHX7DIlLojMdElXmy4gmxzsCN+45OdwNw76v7xylcJ2T1yzCNnuRkz
	UFeIPPX/vcx44B6LRQ4u042WlulYonWF0ogdL+V8xgCBqcPn69REC75CNUh5a/4N
	/mRMy1C0+mUbxxLXixSpq0tR624=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:subject:to:references:from:message-id:date
	:mime-version:in-reply-to:content-type
	:content-transfer-encoding; s=default; bh=SOtqpb6sK+AcMS0iAZ5bOr
	uOXbs=; b=YPKF8Bb1odtljDRulUcY+QmbWvFhQs3RPl82RGEKtK7QwwHkZkltDy
	lXjzI6hLpZlB2/kyaQYO6gQQpaZvoyV2s5SthNLVY6YYh+0r9VZ1V+Vl+o/ViU4x
	3xorBPQugm+EEUuj+LZp2qLi5T2B7+nmahNCZ4nn/aRLWaeuIsh1Q=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=principal, caveat, H*M:10af
X-HELO: mx1.redhat.com
Subject: Re: Wrong file position after writing 65537 bytes to block device
To: cygwin@cygwin.com
References: <20171218131035.GB11285@calimero.vinschen.de> <5a385ced.195b9d0a.d434.5400@mx.google.com> <20171219091431.GF11285@calimero.vinschen.de> <CAKyntiLyTBGcAx3iwhq7dX0wqiE3S685kwmhMg+U2A3huXVzUQ@mail.gmail.com>
From: Eric Blake <eblake@redhat.com>
Message-ID: <9f29d418-10af-1dc7-2636-89cae1eb16f4@redhat.com>
Date: Tue, 19 Dec 2017 10:13:17 -0600
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0
MIME-Version: 1.0
In-Reply-To: <CAKyntiLyTBGcAx3iwhq7dX0wqiE3S685kwmhMg+U2A3huXVzUQ@mail.gmail.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-IsSubscribed: yes

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 <stdio.h>
> 
> int main(int argc, char *argv[]) {
>      FILE *f = fopen(argv[1], "w");
>      char x[65536 + 1];
>      fwrite(x, 1, 65536 + 1, f);
>      fflush(f);
>      printf("%ld", ftell(f));

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 to the unaligned boundary, and have extra magic in ftell() to track 
that we are at an unaligned position within the block device?  But that 
sounds like a lot of nasty overhead; and that it would be better to make 
sure that block devices can report unaligned lseek() locations (caveat: 
I haven't tested what Linux does in that regards).

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

--
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

