[Bug 272120] touch(1) -r modifies file's birthtime

From: <bugzilla-noreply_at_freebsd.org>
Date: Tue, 05 Mar 2024 00:16:25 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=272120

Mark Peek <mp@FreeBSD.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mp@FreeBSD.org

--- Comment #2 from Mark Peek <mp@FreeBSD.org> ---
I looked into this a little bit and here is what I discovered. Running "touch
-m" uses utimensat(2) and passes in just the modification date. This system
call then calls an internal setutimes()
https://github.com/freebsd/freebsd-src/blob/main/sys/kern/vfs_syscalls.c#L3211.

In 2002 this change was added:

   
https://github.com/freebsd/freebsd-src/commit/fb36a3d8472e3b7c446b5501635ec34eb1ebaa00

    Change utimes to set the file creation time (for filesystems that
    support creation times such as UFS2) to the value of the
    modification time if the value of the modification time is older
    than the current creation time. See utimes(2) for further details.

If a birthtime is not passed into setutimes() and the birthtime is younger than
the modification time, then the birthtime is set to the modification time. The
utimensat(2) man page documents this behavior.

This makes a little bit of sense given a modification time usually should not
be older than the birthtime of the file. But the utimes man page does talk
about the need for a new system call allowing for setting access, modification,
*and* birthtime so that might be an alternative.

Options:
1. Document this behavior in the touch(1) man page.
2. Add a new system call to allow setting all three times and modify touch(1)
to use it.

-- 
You are receiving this mail because:
You are the assignee for the bug.