truncate and open(O_TRUNC) times.
Konstantin Belousov
kostikbel at gmail.com
Mon Jul 29 14:07:00 UTC 2013
On Mon, Jul 29, 2013 at 07:56:34PM +1000, Bruce Evans wrote:
> 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.
vaattr.va_vaflags could grow a flag to indicate that VOP_SETATTR()
should only change times when size was changed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-standards/attachments/20130729/734655a4/attachment.sig>
More information about the freebsd-standards
mailing list