From owner-freebsd-standards@FreeBSD.ORG Mon Jul 29 14:07:00 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 BE49AFAD for ; Mon, 29 Jul 2013 14:07:00 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 5CB682873 for ; Mon, 29 Jul 2013 14:07:00 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.7/8.14.7) with ESMTP id r6TE6tWD014316; Mon, 29 Jul 2013 17:06:55 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.3 kib.kiev.ua r6TE6tWD014316 Received: (from kostik@localhost) by tom.home (8.14.7/8.14.7/Submit) id r6TE6spf014315; Mon, 29 Jul 2013 17:06:54 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 29 Jul 2013 17:06:54 +0300 From: Konstantin Belousov To: Bruce Evans Subject: Re: truncate and open(O_TRUNC) times. Message-ID: <20130729140654.GO4972@kib.kiev.ua> References: <51F5813D.2030806@rtems.org> <20130729191944.M928@besplex.bde.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Vxa5joy26gVGOrvU" Content-Disposition: inline In-Reply-To: <20130729191944.M928@besplex.bde.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home 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 14:07:00 -0000 --Vxa5joy26gVGOrvU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jul 29, 2013 at 07:56:34PM +1000, Bruce Evans wrote: > On Mon, 29 Jul 2013, Chris Johns wrote: >=20 > > In the RTEMS project we have some test code that appears to fail on Fre= eBSD.=20 > > You can find a stripped down version at=20 > > http://www.rtems.org/ftp/pub/rtems/people/chrisj/fstimes/truncate-time-= test.c > > > > The code does .. > > > > fd =3D open (file01, O_CREAT | O_WRONLY, mode); > > n =3D write (fd, databuf, len); > > assert (n =3D=3D len); > > status =3D close (fd); > > assert (status =3D=3D 0); > >=20 > > sleep(2); > > > > status =3D truncate (file01, len); > > assert (status =3D=3D 0); > > > > The length does not change and given the file does not change our=20 > > interpretation of the truncate call is the times should not change. >=20 > POSIX is weirdly different for truncate(). It only requires truncate() > to change the times if it changed the size (this is not weird, but unusua= l), > while it requires ftruncate() to change the times if it succeeded. >=20 > > > > In the case of .. > > > > fd =3D open (file03, O_CREAT | O_WRONLY, mode); > > status =3D close (fd); > > assert (status =3D=3D 0); > > > > sleep(2); > > > > fd =3D open (file03, O_TRUNC | O_WRONLY, mode); > > status =3D close (fd); > > assert (status =3D=3D 0); > > > > the times do change as expected. >=20 > POSIX requires open() with O_TRUNC to change the times if it succeeded > (so it acts like ftruncate() on its descriptor). >=20 > 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. vaattr.va_vaflags could grow a flag to indicate that VOP_SETATTR() should only change times when size was changed. --Vxa5joy26gVGOrvU Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (FreeBSD) iQIcBAEBAgAGBQJR9nb+AAoJEJDCuSvBvK1BoQcP/3Ez1aUsMNXppDbcnS/7loWO 3Er/qtKP85rvL1XRqW3tmK3Viwu298mvIj/iYP1wKU+eCWDruEX+3bfArLiZg8bV Yd1JH8DGf03v7OP+Gccpn48ZHuqOX7IqPLoOJcg028DfFl6VI0jU6YhWBjrn0IFe gCwmQ8EPnUoFtQu5VQItER9vg1jbjSJLnxLnedfBpucPlUmldzwpK7w9TVY4C0r+ 8sJf00942fwxYwlVgVUpC42CkbGkPepy95GwbQmnvp1em8RVru5lGUgfwBSeDON6 tGIFUkV2vwCNnhyBud3QzaXjVQhu/aOqTBZzMuuN+zKsknNmBcFq3aY4Q6gT510R FHoJhHaDVAwceyDASllCYRQH3px5O6jFbBRWO3UW3o9mCpkvFmGnjpHp4gSJfMv7 Ry3mjBN1IJCf5rLmoMkc23Hb8QseDjQHfAgKJXTGTYflhy9YBcOIGEurgYX2zJiu NqQI0fnLgpPYmQg+zKLoHKDUtI8ymtxlzd21z5EJrMRt37cuI40zb7Pc7mu35uCJ OUizRaWv2MC3HwL65zWG1vqaHj/xWZAW3V/OE8PGWl94TdrjM4/4mlD1ZiFXCI2w wvGM96SlV79OIX+9oFqF6mD3Ja8UsyyvLfoEJ+HSdeU6RMVcP0YyaQTIpYoeLMBb gNiZraXFeMLdbwdF8Bd5 =oMut -----END PGP SIGNATURE----- --Vxa5joy26gVGOrvU--