Date: Mon, 29 Jul 2013 17:06:54 +0300 From: Konstantin Belousov <kostikbel@gmail.com> To: Bruce Evans <brde@optusnet.com.au> Cc: freebsd-standards@freebsd.org Subject: Re: truncate and open(O_TRUNC) times. Message-ID: <20130729140654.GO4972@kib.kiev.ua> In-Reply-To: <20130729191944.M928@besplex.bde.org> References: <51F5813D.2030806@rtems.org> <20130729191944.M928@besplex.bde.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130729140654.GO4972>