From owner-freebsd-standards@FreeBSD.ORG Mon Jul 29 20:50:19 2013 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id D999565F for ; Mon, 29 Jul 2013 20:50:19 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (unknown [IPv6:2001:610:1108:5012::107]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A15BB2010 for ; Mon, 29 Jul 2013 20:50:19 +0000 (UTC) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id 772BF1203CA; Mon, 29 Jul 2013 22:50:02 +0200 (CEST) Received: by snail.stack.nl (Postfix, from userid 1677) id 4B16928494; Mon, 29 Jul 2013 22:50:02 +0200 (CEST) Date: Mon, 29 Jul 2013 22:50:02 +0200 From: Jilles Tjoelker To: Chris Johns Subject: Re: truncate and open(O_TRUNC) times. Message-ID: <20130729205002.GA72031@stack.nl> References: <51F5813D.2030806@rtems.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <51F5813D.2030806@rtems.org> User-Agent: Mutt/1.5.21 (2010-09-15) 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 20:50:19 -0000 On Mon, Jul 29, 2013 at 06:38:21AM +1000, 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. > 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. Although POSIX indeed makes an exception for truncate() (ftruncate() and open(O_TRUNC) update the times whenever successful), this inconsistency has been reported as a bug to the Austin Group and this has been accepted. The report http://austingroupbugs.net/view.php?id=489 is specifically about truncate() and asks to change its specification to update the times whenever successful; http://austingroupbugs.net/view.php?id=485 changes all metadata-changing operations to update the times whenever successful, even when the new value is equal to the old value, except chown() where both uid and gid are -1 and futimens()/utimensat() where both times have UTIME_OMIT. In those special cases, the implementation may or may not update the times. Some browsing around on man.freebsd.org shows inconsistent descriptions in the man pages as well. Usually, ftruncate() and truncate() are described in the same man page and there is no mention of any difference in the way they affect timestamps. FreeBSD's truncate() already behaves as proposed in the Austin Group bugs; I think it is best to keep it that way. -- Jilles Tjoelker