From owner-freebsd-standards@FreeBSD.ORG Mon Jul 29 09:56:57 2013 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 04FA7D86 for ; Mon, 29 Jul 2013 09:56:57 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail110.syd.optusnet.com.au (mail110.syd.optusnet.com.au [211.29.132.97]) by mx1.freebsd.org (Postfix) with ESMTP id A47EB2AA5 for ; Mon, 29 Jul 2013 09:56:56 +0000 (UTC) Received: from c122-106-156-23.carlnfd1.nsw.optusnet.com.au (c122-106-156-23.carlnfd1.nsw.optusnet.com.au [122.106.156.23]) by mail110.syd.optusnet.com.au (Postfix) with ESMTPS id 71DB0780D6E; Mon, 29 Jul 2013 19:56:42 +1000 (EST) Date: Mon, 29 Jul 2013 19:56:34 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Chris Johns Subject: Re: truncate and open(O_TRUNC) times. In-Reply-To: <51F5813D.2030806@rtems.org> Message-ID: <20130729191944.M928@besplex.bde.org> References: <51F5813D.2030806@rtems.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=YYGEuWhf c=1 sm=1 tr=0 a=ebeQFi2P/qHVC0Yw9JDJ4g==:117 a=PO7r1zJSAAAA:8 a=CT-yo7tBpAMA:10 a=kj9zAlcOel0A:10 a=JzwRw_2MAAAA:8 a=X5dPMJUElLQA:10 a=DU0EyFXtAAAA:8 a=jSCJBBQonswEp5FjZWIA:9 a=CjuIK1q_8ugA:10 Cc: freebsd-standards@freebsd.org X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Jul 2013 09:56:57 -0000 On Mon, 29 Jul 2013, Chris Johns wrote: > In the RTEMS project we have some test code that appears to fail on FreeBSD. > You can find a stripped down version at > http://www.rtems.org/ftp/pub/rtems/people/chrisj/fstimes/truncate-time-test.c > > The code does .. > > fd = open (file01, O_CREAT | O_WRONLY, mode); > n = write (fd, databuf, len); > assert (n == len); > status = close (fd); > assert (status == 0); > > sleep(2); > > status = truncate (file01, len); > assert (status == 0); > > The length does not change and given the file does not change our > interpretation of the truncate call is the times should not change. POSIX is weirdly different for truncate(). It only requires truncate() to change the times if it changed the size (this is not weird, but unusual), while it requires ftruncate() to change the times if it succeeded. > > In the case of .. > > fd = open (file03, O_CREAT | O_WRONLY, mode); > status = close (fd); > assert (status == 0); > > sleep(2); > > fd = open (file03, O_TRUNC | O_WRONLY, mode); > status = close (fd); > assert (status == 0); > > the times do change as expected. POSIX requires open() with O_TRUNC to change the times if it succeeded (so it acts like ftruncate() on its descriptor). FreeBSD can't possibly do this as weirdly as POSIX specifies, since it uses the same VOP_SETATTR() API to set the size for ftruncate() and truncate(), and this API doesn't say who made the call. Most file systems seem to force the setting of the times if successful. E.g., ffs_truncate() does nothing much except set the times if the size didn't change. Bruce