[PATCH v2 0/3] hfsplus: fix timestamp wrapping and support timestamps after 2040
From: Viacheslav Dubeyko
Date: Fri Oct 09 2026 - 17:31:55 EST
HFS+ keeps timestamps in 32-bit unsigned on-disk fields as the number
of seconds since January 1, 1904. Such field can represent the time
range from January 1, 1904 till February 6, 2040.
The current HFS+ driver treats any on-disk timestamp under
HFSPLUS_UTC_OFFSET (January 1, 1970) as a time between 2040 and 2106.
Also, 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 and
xfstests' generic/258 fails.
This patchset fixes the timestamp wrapping issue and extends
the supported time range beyond February 2040.
The first patch corrects the logic of __hfsp_mt2ut() and
__hfsp_ut2mt(). The on-disk timestamp is interpreted as unsigned
number of seconds since January 1, 1904. HFS_UTC_OFFSET,
HFS_MIN_TIMESTAMP_SECS and HFS_MAX_TIMESTAMP_SECS are defined in
include/linux/hfs_common.h, and hfsplus_fill_super() sets
sb->s_time_min, sb->s_time_max and sb->s_time_gran. This patch fixes
generic/258 but it restricts the supported time range by
February 6, 2040.
The second patch stores the timestamps after February 2040 into
internal extended attributes. Such timestamp is stored as the maximal
on-disk value (0xFFFFFFFF) in the catalog record and the real value
is kept in the xattr as big-endian 64-bit number of seconds since
January 1, 1970:
linux_hfs.create_date_u64
linux_hfs.content_mod_date_u64
linux_hfs.attribute_mod_date_u64
linux_hfs.access_date_u64
It is Linux specific extension of HFS+ on-disk layout. However,
it is backward compatible: Mac OS X sees the clamped timestamp
(February 6, 2040) and an extended attribute. If the xattr is absent
(for example, the record has been created by Mac OS X), then
the driver reads the maximal on-disk value as February 6, 2040.
The internal xattrs are hidden from listxattr() and they cannot be
changed by user. The creation date is supported by the same logic,
including the hard link records. Also, the second patch fixes
the issue when the Attributes File, created in the middle of sync
operation, is not recorded into the volume header.
The third patch adds the hfsplus_time KUnit test suite that checks
the date/time conversion logic and the extended timestamp support.
Viacheslav Dubeyko (3):
hfsplus: fix timestamp wrapped issue
hfsplus: store timestamps after February 2040 in xattrs
hfsplus: add KUnit tests for date/time conversion
fs/hfs/hfs_fs.h | 13 --
fs/hfsplus/Makefile | 2 +-
fs/hfsplus/attributes.c | 85 +++++++--
fs/hfsplus/catalog.c | 110 ++++++++++--
fs/hfsplus/dir.c | 49 ++++-
fs/hfsplus/hfsplus_fs.h | 52 +++++-
fs/hfsplus/inode.c | 299 +++++++++++++++++++++++++++++--
fs/hfsplus/super.c | 8 +
fs/hfsplus/time_test.c | 354 +++++++++++++++++++++++++++++++++++++
fs/hfsplus/xattr.c | 202 ++++++++++++++++++---
fs/hfsplus/xattr.h | 32 +++-
include/linux/hfs_common.h | 13 ++
12 files changed, 1118 insertions(+), 101 deletions(-)
create mode 100644 fs/hfsplus/time_test.c
--
2.43.0