From nobody Tue Jun 2 00:15:30 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4gTrvQ64ywz6gNDb for ; Tue, 02 Jun 2026 00:15:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gTrvQ2HgGz3tk1 for ; Tue, 02 Jun 2026 00:15:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1780359330; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hhpfHONCkdVUHh2vABPLhV0bTDx0TQOCOtm4YQP6Rzs=; b=EAqrjuz+D9wJu4o4b+0vb+n07rjD4zh4tJnqqHtgb58B4ZdLXsFavqLHR/pa/OFlnsIdEZ 2o4tzPSi3seKEjYzewXDHAWsE4ci+vt9v+yBbaUVdDm6Hal9Urdggvye7bItybfbtg+wW5 FtUYE0nV4V8YCJqzBV2/3LmDQTENBdPCp/g9WC0wdY1ufYrEomf+bOWquhZDEvHigGlWvI Uc/46QulU/pl6y+Gaew1HQKETzWBa01yRwTVMTf8a4jAEZ9/QaFoiGd3aQcMld5pXCsxtF iaAetqbbyrdP3wSOsJ61L3JUZ0k3/La2BB5Bb+lPxqUmJPbTzNdMB9jQBnp89Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1780359330; a=rsa-sha256; cv=none; b=UPG7dV6P2ExMnTjEinvlZ3TThuBT+74eIgHH07EecWwLgwhgEuf03Fc5b6PkyVpiv9w6LB al3Qfm2GdpB1EDaTWFmTJS0je2EMKNxDAaUV9dySMkAMhkgbZqBzTmaZm05vyaHVUXdiw/ oA4xw+iVDUUs8VrkfQtnUkWL2m6bgjdvof3fKgSvrO6Qm76QBTqRxFOq47MavnBkiksuC3 lvbMVIVxACjS1QdHmCgaCr+/UozCvE6Z1Nstw0dn8qyMg20Zg2d7+m+9+1w5ghvR4GhEeP tXiv3LRVgpWFUNMKC7g5lAO5Crtyj7eN5UDZk5QVl7ss+NMBJMmhbz0XO4j/nQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1780359330; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hhpfHONCkdVUHh2vABPLhV0bTDx0TQOCOtm4YQP6Rzs=; b=lkT0n8tUTbEVI8vIKc3o/jXLLDkffYCgRZSw08+aeI0Ly0dXbjnhhtfoe5/O4n/ZwcHvVZ xlSiOv6Ez2Aphdj+9czel22o51Bnv6k2k7kojKSq05UOjITs1YX8MXVmxXfjqvLJUn8uHc yj4BLm0HfYzk+95pWbMza7G+q43Xiswlw878b5lJdHyPTj4RBZH24/qZ5Q14haNCQ6TAlF sWxL0k9Lwtyx2x0zxZGbTjJrn5oClbQFr0l4i0CrvCmOZYsTb9S6xD1CEyHjy+ufkcdM53 WTeVqQNLZSp2YTJvtfIfejHxmHdjxq4EzgyQaMoJ9MEgJiZ/ZQHBRnR/zwjlAw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gTrvQ1NCbz114P for ; Tue, 02 Jun 2026 00:15:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1dd8f by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 02 Jun 2026 00:15:30 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kirk McKusick Subject: git: 553ef188f7ec - main - Avoid incorrect UFS1 timestamp corrections when system clock fails at boot. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mckusick X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 553ef188f7ecc23a384bd7ef1f3d5015fb8661da Auto-Submitted: auto-generated Date: Tue, 02 Jun 2026 00:15:30 +0000 Message-Id: <6a1e20a2.1dd8f.169e05f5@gitrepo.freebsd.org> The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=553ef188f7ecc23a384bd7ef1f3d5015fb8661da commit 553ef188f7ecc23a384bd7ef1f3d5015fb8661da Author: Kirk McKusick AuthorDate: 2026-06-01 23:48:21 +0000 Commit: Kirk McKusick CommitDate: 2026-06-01 23:48:21 +0000 Avoid incorrect UFS1 timestamp corrections when system clock fails at boot. Git 1111a44301da - main - Defer the January 19, 2038 date limit in UFS1 file systems to February 7, 2106 - did so by changing the UFS1 32-bit signed timestamps to unsigned. With this change, time stamps from before January 1, 1970 went from being negative numbers to large positive numbers implying times in the future. When such a time stamp is encountered when an inode is read into memory or when it is encountered by fsck, its timestamp is replaced with the kernel's current time. Andre Albsmeier reported that he had a machine reboot after a power failure and the battery that maintained its real-time clock had died. The result was that the system booted with the time set to five years earlier (absent a real-time clock value, the boot ROM used the time that the boot ROM had last been updated). The net result was that fsck reset the time stamps of all files newer than five years old to the five year old time. Andres's original request was for a flag in the file system superblock to say that there are no timestamps from before 1970 in the file system, so there shouldn't be anything to fix because of the signed to unsigned switch. But this assumes that no one every does an rsync or extracts a tar file or restores a dump that introduces an incorrect time stamp on their system. So this approach was not taken. This change compares the system's version of the current time to the last modification time in the file system superblock. If the current time is earlier than that time then use the last modification time in the superblock as the value for the current time. There should be no files in the file system with times newer than the last modification time in the superblock. The superblock time stamp is updated in the in-memory superblock every time any change is made to anything in the file system. The superblock is written to the disk every 30 seconds, so it may be off by up to 30 seconds plus the time it sits in the disk cache waiting to be written if the system has an unclean shutdown (such as a power failure). Thus, the worst case scenario with this change is that files written in the last 30 seconds plus disk cache delay time before the crash may have their times adjusted back by up to 30 seconds plus the disk cache delay time. Requested by: Andre Albsmeier Approved by: kib Reviewed by: kib, imp, Andre Albsmeier MFC-after: 1 week Differential Revision: https://reviews.freebsd.org/D57371 --- lib/libufs/inode.c | 17 +++++++++-------- sbin/fsck_ffs/inode.c | 3 ++- sys/ufs/ffs/ffs_vfsops.c | 7 ++++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/libufs/inode.c b/lib/libufs/inode.c index bc4d99c66203..a93e1b085342 100644 --- a/lib/libufs/inode.c +++ b/lib/libufs/inode.c @@ -57,7 +57,8 @@ getinode(struct uufsd *disk, union dinodep *dp, ino_t inum) ino_t min, max; caddr_t inoblock; struct fs *fs; - struct timespec now; + struct timespec time; + time_t now; ERROR(disk, NULL); @@ -70,10 +71,11 @@ getinode(struct uufsd *disk, union dinodep *dp, ino_t inum) min = disk->d_inomin; max = disk->d_inomax; - if (clock_gettime(CLOCK_REALTIME_FAST, &now) != 0) { - ERROR(disk, "cannot get current time of day"); - return (-1); - } + if (clock_gettime(CLOCK_REALTIME_FAST, &time) == 0 && + time.tv_sec > fs->fs_time) + now = time.tv_sec; + else + now = fs->fs_time; if (inum >= min && inum < max) goto gotit; bread(disk, fsbtodb(fs, ino_to_fsba(fs, inum)), inoblock, @@ -83,7 +85,7 @@ getinode(struct uufsd *disk, union dinodep *dp, ino_t inum) gotit: switch (disk->d_ufs) { case 1: disk->d_dp.dp1 = &((struct ufs1_dinode *)inoblock)[inum - min]; - if (ffs_oldfscompat_inode_read(fs, disk->d_dp, now.tv_sec)) + if (ffs_oldfscompat_inode_read(fs, disk->d_dp, now)) putinode(disk); if (dp != NULL) *dp = disk->d_dp; @@ -93,8 +95,7 @@ gotit: switch (disk->d_ufs) { if (dp != NULL) *dp = disk->d_dp; if (ffs_verify_dinode_ckhash(fs, disk->d_dp.dp2) == 0) { - if (ffs_oldfscompat_inode_read(fs, disk->d_dp, - now.tv_sec)) + if (ffs_oldfscompat_inode_read(fs, disk->d_dp, now)) putinode(disk); return (0); } diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c index b30e3aa5068b..f8e32bf4b157 100644 --- a/sbin/fsck_ffs/inode.c +++ b/sbin/fsck_ffs/inode.c @@ -647,7 +647,8 @@ setinodebuf(int cg, ino_t inosused) * If for some reason getting the time fails, we will use * the last time that the superblock was updated. */ - if (clock_gettime(CLOCK_REALTIME_FAST, &time) == 0) + if (clock_gettime(CLOCK_REALTIME_FAST, &time) == 0 && + time.tv_sec > sblock.fs_time) now = time.tv_sec; else now = sblock.fs_time; diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c index 8ac2075f8db8..11afa99bea76 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -189,8 +189,10 @@ ffs_load_inode(struct buf *bp, struct inode *ip, struct fs *fs, ino_t ino) { struct ufs1_dinode *dip1; struct ufs2_dinode *dip2; + time_t now; int error; + now = time_second > fs->fs_time ? time_second : fs->fs_time; if (I_IS_UFS1(ip)) { dip1 = ip->i_din1; *dip1 = @@ -203,7 +205,7 @@ ffs_load_inode(struct buf *bp, struct inode *ip, struct fs *fs, ino_t ino) ip->i_gen = dip1->di_gen; ip->i_uid = dip1->di_uid; ip->i_gid = dip1->di_gid; - if (ffs_oldfscompat_inode_read(fs, ip->i_dp, time_second) && + if (ffs_oldfscompat_inode_read(fs, ip->i_dp, now) && fs->fs_ronly == 0) UFS_INODE_SET_FLAG(ip, IN_MODIFIED); return (0); @@ -225,8 +227,7 @@ ffs_load_inode(struct buf *bp, struct inode *ip, struct fs *fs, ino_t ino) ip->i_gen = dip2->di_gen; ip->i_uid = dip2->di_uid; ip->i_gid = dip2->di_gid; - if (ffs_oldfscompat_inode_read(fs, ip->i_dp, time_second) && - fs->fs_ronly == 0) + if (ffs_oldfscompat_inode_read(fs, ip->i_dp, now) && fs->fs_ronly == 0) UFS_INODE_SET_FLAG(ip, IN_MODIFIED); return (0); }