Issue #3483 has been reported by tuxillo.
----------------------------------------
Bug #3483: vfs: O_TRUNC of an empty file doesn't update its times on tmpfs,
HAMMER2 and HAMMER
http://bugs.dragonflybsd.org/issues/3483
* Author: tuxillo
* Status: New
* Priority: Normal
* Target version: 6.6
* Start date: 2026-11-26
----------------------------------------
As of master efcec8993c, opening an existing empty file with @O_TRUNC@, as
fopen(path, "wb") does, leaves its mtime and ctime unchanged on tmpfs, HAMMER2
and HAMMER. POSIX says open() with @O_TRUNC@ marks both for update when the
file exists, and UFS does it. Any user can see it with @: > f; sleep 2; : > f@
and stat.
vn_open() handles @O_TRUNC@ with a VOP_SETATTR of @va_size@ 0 and leaves the
times to the filesystem. tmpfs_truncate() returns early when the size doesn't
change, before it sets @TMPFS_NODE_CHANGED@ and @TMPFS_NODE_MODIFIED@.
hammer2_vop_setattr() and hammer_vop_setattr() only enter their resize code,
which sets the times, when the size differs. ffs_truncate() and ext2_truncate()
mark the times in that case.
ninja 1.13 takes each command's start time from the mtime of an empty
.ninja_lock that it rewrites with fopen("wb"). Since that mtime never moves, a
second or resumed ninja run thinks most of the tree is out of date: building
devel/electron42 in DPorts, it saw 32k of 42k edges dirty with 7.6k really
left. FreeBSD fixed tmpfs the same way in 860399eb86cc (PR 268528).
The attached patch marks the times on a same-size truncate of a regular file.
tmpfs sets both flags, HAMMER2 takes its resize path, and HAMMER sets mtime as
its other truncates do. HAMMER doesn't update ctime on any write or truncate; I
left that alone.
Tested in a QEMU guest on master d23da7dd7d (these filesystems haven't changed
since) with the attached truncmtime.c, which reopens a file with @O_TRUNC@
after 1.1 s. Before, an empty file kept its mtime and ctime on tmpfs, HAMMER
and HAMMER2, and UFS updated both. After, both change on tmpfs and HAMMER2, and
mtime on HAMMER. Shrinking, same-size and extending truncates still keep the
data right on all four. I didn't run ninja itself on the patched kernel.
---Files--------------------------------
truncmtime.c (2.15 KB)
0001-vfs-mark-mtime-on-open-O_TRUNC-of-a-file-that-is-alr.patch (3.99 KB)
--
You have received this notification because you have either subscribed to it,
or are involved in it.
To change your notification preferences, please click here:
http://bugs.dragonflybsd.org/my/account