From: Viacheslav Dubeyko <slava@dubeyko.com>
To: glaubitz@physik.fu-berlin.de, frank.li@vivo.com
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
vdubeyko@coreweave.com, Viacheslav Dubeyko <slava@dubeyko.com>
Subject: [PATCH 0/3] hfs: fix timestamp wrapping and support timestamps after 2040
Date: Tue, 24 Nov 2026 14:53:27 -0800 [thread overview]
Message-ID: <20261124225330.3879708-1-slava@dubeyko.com> (raw)
HFS keeps timestamps in 32-bit unsigned on-disk fields as the number
of seconds since January 1, 1904 (local time). Such field can
represent the time range from January 1, 1904 till February 6, 2040.
The current HFS driver has the same timestamp wrapping issue as
the HFS+ driver had: it treats any on-disk timestamp under
HFS_UTC_OFFSET (January 1, 1970) as a time between 2040 and 2106,
and it calculates the on-disk value by means of adding the time
offset to the lower 32 bits of the timestamp. As a result, any
timestamp before January 1, 1970 is converted completely wrong.
This patchset is the HFS port of the HFS+ patchset "hfsplus: fix
timestamp wrapping and support timestamps after 2040". It fixes
the timestamp wrapping issue and extends the supported time range
beyond February 2040.
The first patch corrects the logic of __hfs_m_to_utime() and
__hfs_u_to_mtime(). The on-disk timestamp is interpreted as unsigned
number of seconds since January 1, 1904, out of range values are
clamped instead of wrapped, and hfs_fill_super() sets
sb->s_time_min, sb->s_time_max and sb->s_time_gran (shifted by
the local time zone offset). This patch restricts the supported time
range by February 6, 2040.
The second patch extends the supported time range. HFS has no
extended attributes on the volume. So, if the modification date
cannot be represented by the 32-bit on-disk field, then the maximal
value (0xFFFFFFFF) is stored into MdDat and the real value is kept
in the spare bytes of the same catalog record as big-endian 64-bit
number of seconds since January 1, 1904:
file record: FndrInfo.fdIconID and FndrInfo.fdUnused[0..5]
directory record: Resrv[0..7]
fsck_hfs does not check these bytes. It is Linux specific extension
of HFS on-disk layout. However, it is backward compatible: Mac OS
sees the clamped timestamp (February 6, 2040). If another
implementation updates MdDat, then the mark is removed and the stale
value of the spare bytes is ignored. The extended value is updated
together with MdDat in the same catalog record. So, no additional
locking or b-tree update is required. Only MdDat is extended because
HFS driver uses it for mtime, atime and ctime. The second patch
raises sb->s_time_max to HFS_EXT_MAX_TIMESTAMP_SECS.
The third patch adds the hfs_time KUnit test suite that checks
the date/time conversion logic and the extended timestamp support.
Tested on a KASAN and lockdep kernel: modification dates of files
and directories (1904, 1950, February 6, 2040 and one second later,
2050, 2106, 2200, records created with the clock set to 2055, and
timestamps moved back from the extended range) are preserved across
remount, a timestamp before 1904 is clamped, and fsck.hfs reports
the volume as OK. Without the patchset, the 1904, 1950, 2106 and 2200
timestamps are wrapped. The hfs_time and hfs_string KUnit suites
pass.
Viacheslav Dubeyko (3):
hfs: fix timestamp wrapped issue
hfs: store timestamps after February 2040 in spare catalog fields
hfs: add KUnit tests for date/time conversion
fs/hfs/Makefile | 2 +-
fs/hfs/catalog.c | 10 +-
fs/hfs/hfs_fs.h | 74 +++++++-
fs/hfs/hfs_time_test.c | 400 +++++++++++++++++++++++++++++++++++++++++
fs/hfs/inode.c | 88 ++++++++-
fs/hfs/super.c | 8 +
6 files changed, 567 insertions(+), 15 deletions(-)
create mode 100644 fs/hfs/hfs_time_test.c
base-commit: becaebec8e0f16edc0fd2426508e173f9d7bb5e9
--
2.53.0
next reply other threads:[~2026-11-24 22:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 22:53 Viacheslav Dubeyko [this message]
2026-11-24 22:53 ` [PATCH 1/3] hfs: fix timestamp wrapped issue Viacheslav Dubeyko
2026-11-24 22:53 ` [PATCH 2/3] hfs: store timestamps after February 2040 in spare catalog fields Viacheslav Dubeyko
2026-11-24 22:53 ` [PATCH 3/3] hfs: add KUnit tests for date/time conversion Viacheslav Dubeyko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261124225330.3879708-1-slava@dubeyko.com \
--to=slava@dubeyko.com \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vdubeyko@coreweave.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®