Skip to contentSkip to conversation

hfsplus: fix timestamp wrapping and support timestamps after 2040

PATCH New Viacheslav Dubeyko 1 participant 4 messages Nov 20

Subsystems (3)
lore
Share & tools
lore

Viacheslav Dubeyko

author maintainer
#0 lore raw

v4 cover hfsplus: fix timestamp wrapping and support timestamps after 2040

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 and raises sb->s_time_max to HFSPLUS_MAX_TIMESTAMP_SECS. 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.

v4
- Rebased on the current hfs tree. The creation of catalog records has been reworked meanwhile (__hfsplus_create_cat() is shared by hfsplus_create_cat() and hfsplus_create_cat_uni()), so the creation date xattr is now saved in __hfsplus_create_cat().
- Set sb->s_time_max to HFSPLUS_MAX_TIMESTAMP_SECS in the second patch. v3 kept HFS_MAX_TIMESTAMP_SECS, so VFS clamped every timestamp to February 6, 2040 before it reached the driver.
- Mark is_create_date_identical() as noinline_for_stack. Both of its calls were inlined into hfsplus_lookup(), whose frame exceeded 1024 bytes with KASAN (-Wframe-larger-than=).
- Tested on a KASAN and lockdep kernel: mtime, atime and creation dates of files, directories and hard links (1950, February 6, 2040 and one second later, 2050, 2106, 2200) are preserved across remount and fsck.hfsplus reports the volume as OK; the hfsplus_time and hfsplus_unicode KUnit suites pass; xfstests generic/001, 002, 013, 020, 075, 112, 236 and 258 pass.

v3
File time_test.c has been renamed into hfsplus_time_test.c and file unicode_test.c has been renamed into hfsplus_unicode_test.c with the goal to exclude modules name conflict.
https://lore.kernel.org/all/[email protected]/

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                          | 108 +++++-
 fs/hfsplus/dir.c                              |  50 ++-
 fs/hfsplus/hfsplus_fs.h                       |  52 ++-
 fs/hfsplus/hfsplus_time_test.c                | 354 ++++++++++++++++++
 ...{unicode_test.c => hfsplus_unicode_test.c} |   0
 fs/hfsplus/inode.c                            | 299 ++++++++++++++-
 fs/hfsplus/super.c                            |   8 +
 fs/hfsplus/xattr.c                            | 202 ++++++++--
 fs/hfsplus/xattr.h                            |  32 +-
 include/linux/hfs_common.h                    |  13 +
 13 files changed, 1118 insertions(+), 100 deletions(-)
 create mode 100644 fs/hfsplus/hfsplus_time_test.c
 rename fs/hfsplus/{unicode_test.c => hfsplus_unicode_test.c} (100%)

base-commit: d4558e30b83d14f59e9cac85d9e83d662491de51

Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH v4 1/3 hfsplus: fix timestamp wrapped issue

The xfstests' test-case generic/258 fails to execute correctly:

FSTYP -- hfsplus
PLATFORM -- Linux/x86_64 hfsplus-testing-0001 6.15.0-rc4+ #8 SMP PREEMPT_DYNAMIC Thu May 1 16:43:22 PDT 2025 MKFS_OPTIONS -- /dev/loop51
MOUNT_OPTIONS -- /dev/loop51 /mnt/scratch

generic/258 [failed, exit status 1]- output mismatch (see xfstests-dev/results//generic/258.out.bad)

The main reason of the issue is the logic:

cpu_to_be32(lower_32_bits(ut) + HFSPLUS_UTC_OFFSET)

At first, we take the lower 32 bits of the value and, then, we add the time offset. However, if we have negative value (timestamp before January 1, 1970), then we make completely wrong calculation. The reverse conversion has the same issue because it treats any on-disk timestamp under HFSPLUS_UTC_OFFSET (January 1, 1970) as a time between 2040 and 2106.

This patch corrects the logic of __hfsp_mt2ut() and __hfsp_ut2mt(). Now, the on-disk timestamp is interpreted as unsigned number of seconds since January 1, 1904. As a result, the supported time range is from January 1, 1904 till February 6, 2040.

The HFS_UTC_OFFSET constant has been moved into include/linux/hfs_common.h and HFSPLUS_UTC_OFFSET has been removed. The HFS_MIN_TIMESTAMP_SECS and HFS_MAX_TIMESTAMP_SECS constants have been introduced in include/linux/hfs_common.h. The hfsplus_fill_super() logic defines sb->s_time_min, sb->s_time_max, and sb->s_time_gran. It means that VFS clamps the timestamps that are out of the supported range.

[1] https://github.com/hfs-linux-kernel/hfs-linux-kernel/issues/133

cc John Paul Adrian Glaubitz <[email protected]>
cc Yangtao Li <[email protected]>
---
 fs/hfs/hfs_fs.h            | 13 -------------
 fs/hfsplus/hfsplus_fs.h    | 17 +++++------------
 fs/hfsplus/super.c         |  4 ++++
 include/linux/hfs_common.h | 13 +++++++++++++
 4 files changed, 22 insertions(+), 25 deletions(-)
fs/hfs/hfs_fs.h +0 -13
index 2744508e01e6..2d56f8b1a5fa 100644
@@ -261,19 +261,6 @@ extern int hfs_mac2asc(struct super_block *sb,
 /* super.c */
 extern void hfs_mark_mdb_dirty(struct super_block *sb);
 
-/*
- * There are two time systems.  Both are based on seconds since
- * a particular time/date.
- *	Unix:	signed little-endian since 00:00 GMT, Jan. 1, 1970
- *	mac:	unsigned big-endian since 00:00 GMT, Jan. 1, 1904
- *
- * HFS implementations are highly inconsistent, this one matches the
- * traditional behavior of 64-bit Linux, giving the most useful
- * time range between 1970 and 2106, by treating any on-disk timestamp
- * under HFS_UTC_OFFSET (Jan 1 1970) as a time between 2040 and 2106.
- */
-#define HFS_UTC_OFFSET 2082844800U
-
 static inline time64_t __hfs_m_to_utime(__be32 mt)
 {
 	time64_t ut = (u32)(be32_to_cpu(mt) - HFS_UTC_OFFSET);
fs/hfsplus/hfsplus_fs.h +5 -12
index dd88053cc9b3..3df09414f7f3 100644
@@ -531,26 +531,19 @@ bool is_hfs_thread_record_type(u16 type)
 
 int hfsplus_brec_read_cat(struct hfs_find_data *fd, hfsplus_cat_entry *entry);
 
-/*
- * time helpers: convert between 1904-base and 1970-base timestamps
- *
- * HFS+ implementations are highly inconsistent, this one matches the
- * traditional behavior of 64-bit Linux, giving the most useful
- * time range between 1970 and 2106, by treating any on-disk timestamp
- * under HFSPLUS_UTC_OFFSET (Jan 1 1970) as a time between 2040 and 2106.
- */
-#define HFSPLUS_UTC_OFFSET 2082844800U
-
 static inline time64_t __hfsp_mt2ut(__be32 mt)
 {
-	time64_t ut = (u32)(be32_to_cpu(mt) - HFSPLUS_UTC_OFFSET);
+	time64_t ut = (time64_t)be32_to_cpu(mt) - HFS_UTC_OFFSET;
 
 	return ut;
 }
 
 static inline __be32 __hfsp_ut2mt(time64_t ut)
 {
-	return cpu_to_be32(lower_32_bits(ut) + HFSPLUS_UTC_OFFSET);
+	ut += HFS_UTC_OFFSET;
+
+	return cpu_to_be32(lower_32_bits(ut));
+
 }
 
 static inline enum hfsplus_btree_mutex_classes
fs/hfsplus/super.c +4 -0
index f3283e9b42c8..516885d91e51 100644
@@ -659,6 +659,10 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
 	if (!sbi->rsrc_clump_blocks)
 		sbi->rsrc_clump_blocks = 1;
 
+	sb->s_time_gran = NSEC_PER_SEC;
+	sb->s_time_min = HFS_MIN_TIMESTAMP_SECS;
+	sb->s_time_max = HFS_MAX_TIMESTAMP_SECS;
+
 	err = -EFBIG;
 	last_fs_block = sbi->total_blocks - 1;
 	last_fs_page = (last_fs_block << sbi->alloc_blksz_shift) >>
include/linux/hfs_common.h +13 -0
index 802d1590e4a3..eb119a1c565f 100644
@@ -687,4 +687,17 @@ typedef union {
 	struct hfsplus_attr_key attr;
 } __packed hfsplus_btree_key;
 
+/*
+ * There are two time systems.  Both are based on seconds since
+ * a particular time/date.
+ *	Unix:	signed little-endian since 00:00 GMT, Jan. 1, 1970
+ *	mac:	unsigned big-endian since 00:00 GMT, Jan. 1, 1904
+ */
+#define HFS_UTC_OFFSET 2082844800U
+
+/* January 1, 1904, 00:00:00 UTC */
+#define HFS_MIN_TIMESTAMP_SECS		-2082844800LL
+/* February 6, 2040, 06:28:15 UTC */
+#define HFS_MAX_TIMESTAMP_SECS		2212122495LL
+
 #endif /* _HFS_COMMON_H_ */
Signature · 1 line
2.53.0
author maintainer
#2 lore raw

PATCH v4 2/3 hfsplus: store timestamps after February 2040 in xattrs

In reply to Viacheslav Dubeyko

The timestamp wrapping issue has been fixed but it restricts the supported time range to the one that the 32-bit on-disk field can represent: from January 1, 1904 till February 6, 2040. Any timestamp after February 6, 2040 is clamped now.

Extend the supported time range by means of internal extended attributes. If a timestamp cannot be represented by the 32-bit on-disk field, then the maximal value (0xFFFFFFFF, HFSPLUS_EXT_TIMESTAMP_MARK) is stored into the catalog record and the real value is stored into the xattr of the catalog record 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

The HFSPLUS_XATTR_EXISTS flag of the catalog record is kept in sync with the presence of xattrs. As a result, sb->s_time_max is set to TIME64_MAX.

Read path: if the on-disk timestamp is equal to HFSPLUS_EXT_TIMESTAMP_MARK, then hfsplus_read_timestamp() takes the real value from the xattr. If the xattr is absent (for example, the record has been created by Mac OS X or the volume has no Attributes File), then HFS_MAX_TIMESTAMP_SECS is used.

Write path: hfsplus_cat_write_inode() stores the timestamps while the catalog tree is locked. It is the same lock ordering (catalog tree -> attributes tree) that __hfsplus_setxattr() uses. The hfsplus_set_attr_cnid() method has been introduced to create or replace the xattr of a given catalog record ID. The xattr is not rewritten if the timestamp has not been changed. The stale xattr is removed if the timestamp becomes representable by the on-disk field again. The per-inode HFSPLUS_I_{A,M,C}TIME_XATTR bits track which timestamps are stored in xattrs. A failure of the xattr operation is not
fatal: the timestamp is clamped by HFS_MAX_TIMESTAMP_SECS and the rest of the catalog record is saved anyway.

Creation date: hfsplus_create_cat() stores the creation date into the xattr if the record is created after February 2040. The hfsplus_inode_info keeps the on-disk value (create_date) and the real value (birthdate). The getattr() method reports birthdate as btime. A hard link record inherits the creation date of the hidden directory without changing the creation date of the linked inode. The is_create_date_identical() method compares the 64-bit creation dates in hfsplus_lookup() if the on-disk values are equal to HFSPLUS_EXT_TIMESTAMP_MARK.

Other changes:
(1) __hfsp_ut2mt() clamps the value into the supported range instead of wrapping it.
(2) hfsplus_create_attributes_file() stores the fork of Attributes File into the volume header right away. Otherwise, if Attributes File is created by hfsplus_cat_write_inode() in the middle of sync, the writeback can skip the dirty Attributes File inode and the volume header is committed without it.
(3) The internal linux_hfs.* xattrs are hidden from listxattr() and cannot be retrieved or changed by means of the osx.* namespace.
(4) The -ENODATA error code is treated as an absent xattr in the getxattr and remove logic.

cc John Paul Adrian Glaubitz <[email protected]>
cc Yangtao Li <[email protected]>
---
 fs/hfsplus/attributes.c |  85 +++++++++---
 fs/hfsplus/catalog.c    | 108 +++++++++++++--
 fs/hfsplus/dir.c        |  50 ++++++-
 fs/hfsplus/hfsplus_fs.h |  45 +++++-
 fs/hfsplus/inode.c      | 297 +++++++++++++++++++++++++++++++++++++---
 fs/hfsplus/super.c      |   6 +-
 fs/hfsplus/xattr.c      | 202 ++++++++++++++++++++++++---
 fs/hfsplus/xattr.h      |  32 ++++-
 8 files changed, 745 insertions(+), 80 deletions(-)
fs/hfsplus/attributes.c +69 -16
index 7c2e589d4553..51b18d780f2c 100644
@@ -206,7 +206,8 @@ int hfsplus_attr_exists(struct inode *inode, const char *name)
 }
 
 static
-int hfsplus_create_attr_nolock(struct inode *inode, const char *name,
+int hfsplus_create_attr_nolock(struct inode *inode, u32 cnid,
+				const char *name,
 				const void *value, size_t size,
 				struct hfs_find_data *fd,
 				hfsplus_attr_entry *entry_ptr)
@@ -215,12 +216,12 @@ int hfsplus_create_attr_nolock(struct inode *inode, const char *name,
 	int entry_size;
 	int err;
 
-	hfs_dbg("name %s, ino %llu\n",
-		name ? name : NULL, inode->i_ino);
+	hfs_dbg("name %s, ino %llu, cnid %u\n",
+		name ? name : NULL, inode->i_ino, cnid);
 
 	if (name) {
 		err = hfsplus_attr_build_key(sb, fd->search_key,
-						inode->i_ino, name);
+						cnid, name);
 		if (err)
 			return err;
 	} else
@@ -229,7 +230,7 @@ int hfsplus_create_attr_nolock(struct inode *inode, const char *name,
 	/* Mac OS X supports only inline data attributes. */
 	entry_size = hfsplus_attr_build_record(entry_ptr,
 					HFSPLUS_ATTR_INLINE_DATA,
-					inode->i_ino,
+					cnid,
 					value, size);
 	if (entry_size == HFSPLUS_INVALID_ATTR_RECORD) {
 		if (size > HFSPLUS_MAX_INLINE_DATA_SIZE)
@@ -289,8 +290,8 @@ int hfsplus_create_attr(struct inode *inode,
 	if (err)
 		goto failed_create_attr;
 
-	err = hfsplus_create_attr_nolock(inode, name, value, size,
-					 &fd, entry_ptr);
+	err = hfsplus_create_attr_nolock(inode, (u32)inode->i_ino, name,
+					 value, size, &fd, entry_ptr);
 	if (err)
 		goto failed_create_attr;
 
@@ -347,18 +348,19 @@ static int __hfsplus_delete_attr(struct inode *inode, u32 cnid,
 }
 
 static
-int hfsplus_delete_attr_nolock(struct inode *inode, const char *name,
+int hfsplus_delete_attr_nolock(struct inode *inode, u32 cnid,
+				const char *name,
 				struct hfs_find_data *fd)
 {
 	struct super_block *sb = inode->i_sb;
 	int err;
 
-	hfs_dbg("name %s, ino %llu\n",
-		name ? name : NULL, inode->i_ino);
+	hfs_dbg("name %s, ino %llu, cnid %u\n",
+		name ? name : NULL, inode->i_ino, cnid);
 
 	if (name) {
 		err = hfsplus_attr_build_key(sb, fd->search_key,
-						inode->i_ino, name);
+						cnid, name);
 		if (err)
 			return err;
 	} else {
@@ -373,7 +375,7 @@ int hfsplus_delete_attr_nolock(struct inode *inode, const char *name,
 	} else if (err)
 		return err;
 
-	err = __hfsplus_delete_attr(inode, inode->i_ino, fd);
+	err = __hfsplus_delete_attr(inode, cnid, fd);
 	if (err)
 		return err;
 
@@ -403,7 +405,7 @@ int hfsplus_delete_attr(struct inode *inode, const char *name)
 	if (err)
 		goto out;
 
-	err = hfsplus_delete_attr_nolock(inode, name, &fd);
+	err = hfsplus_delete_attr_nolock(inode, (u32)inode->i_ino, name, &fd);
 	if (err)
 		goto out;
 
@@ -481,12 +483,12 @@ int hfsplus_replace_attr(struct inode *inode,
 	if (err)
 		goto failed_replace_attr;
 
-	err = hfsplus_delete_attr_nolock(inode, name, &fd);
+	err = hfsplus_delete_attr_nolock(inode, (u32)inode->i_ino, name, &fd);
 	if (err)
 		goto failed_replace_attr;
 
-	err = hfsplus_create_attr_nolock(inode, name, value, size,
-					 &fd, entry_ptr);
+	err = hfsplus_create_attr_nolock(inode, (u32)inode->i_ino, name,
+					 value, size, &fd, entry_ptr);
 	if (err)
 		goto failed_replace_attr;
 
@@ -497,3 +499,54 @@ int hfsplus_replace_attr(struct inode *inode,
 	hfsplus_destroy_attr_entry(entry_ptr);
 	return err;
 }
+
+/*
+ * Create or replace the xattr @name of catalog record @cnid.
+ * The @inode is used only for access to the superblock and for
+ * marking the attributes tree as dirty. It is the caller's
+ * responsibility to set HFSPLUS_XATTR_EXISTS in the catalog record.
+ */
+int hfsplus_set_attr_cnid(struct inode *inode, u32 cnid,
+			  const char *name,
+			  const void *value, size_t size)
+{
+	struct super_block *sb = inode->i_sb;
+	struct hfs_find_data fd;
+	hfsplus_attr_entry *entry_ptr;
+	int err = 0;
+
+	hfs_dbg("name %s, ino %llu, cnid %u\n",
+		name ? name : NULL, inode->i_ino, cnid);
+
+	if (!HFSPLUS_SB(sb)->attr_tree) {
+		pr_err("attributes file doesn't exist\n");
+		return -EINVAL;
+	}
+
+	entry_ptr = hfsplus_alloc_attr_entry();
+	if (!entry_ptr)
+		return -ENOMEM;
+
+	err = hfs_find_init(HFSPLUS_SB(sb)->attr_tree, &fd);
+	if (err)
+		goto failed_init_set_attr;
+
+	/* Fail early and avoid ENOSPC during the btree operation */
+	err = hfs_bmap_reserve(fd.tree, fd.tree->depth + 1);
+	if (err)
+		goto failed_set_attr;
+
+	err = hfsplus_delete_attr_nolock(inode, cnid, name, &fd);
+	if (err && err != -ENOENT && err != -ENODATA)
+		goto failed_set_attr;
+
+	err = hfsplus_create_attr_nolock(inode, cnid, name,
+					 value, size, &fd, entry_ptr);
+
+failed_set_attr:
+	hfs_find_exit(&fd);
+
+failed_init_set_attr:
+	hfsplus_destroy_attr_entry(entry_ptr);
+	return err;
+}
fs/hfsplus/catalog.c +98 -10

154 lines not on this page · raw message

fs/hfsplus/dir.c +44 -6

62 lines not on this page · raw message

fs/hfsplus/hfsplus_fs.h +44 -1

91 lines not on this page · raw message

fs/hfsplus/inode.c +278 -19

348 lines not on this page · raw message

fs/hfsplus/super.c +5 -1
index 516885d91e51..50328fec1c94 100644
@@ -87,6 +87,7 @@ struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino)
 	mutex_init(&HFSPLUS_I(inode)->extents_lock);
 	HFSPLUS_I(inode)->rsrc_inode = NULL;
 	HFSPLUS_I(inode)->create_date = 0;
+	HFSPLUS_I(inode)->birthdate = 0;
 	HFSPLUS_I(inode)->linkid = 0;
 	HFSPLUS_I(inode)->flags = 0;
 	HFSPLUS_I(inode)->fs_blocks = 0;
@@ -661,7 +662,10 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
 
 	sb->s_time_gran = NSEC_PER_SEC;
 	sb->s_time_min = HFS_MIN_TIMESTAMP_SECS;
-	sb->s_time_max = HFS_MAX_TIMESTAMP_SECS;
+	/*
+	 * Timestamps after HFS_MAX_TIMESTAMP_SECS are stored in xattrs.
+	 */
+	sb->s_time_max = HFSPLUS_MAX_TIMESTAMP_SECS;
 
 	err = -EFBIG;
 	last_fs_block = sbi->total_blocks - 1;
fs/hfsplus/xattr.c +181 -21

284 lines not on this page · raw message

fs/hfsplus/xattr.h +26 -6
index 15cc55e41410..8f6283f85f13 100644
@@ -12,6 +12,24 @@
 
 #include <linux/xattr.h>
 
+/*
+ * Internal xattrs of Linux HFS+ driver. Timestamps beyond
+ * HFS_MAX_TIMESTAMP_SECS (February 2040) cannot be represented by
+ * 32-bit on-disk fields. Such timestamp is stored as the maximal value
+ * (HFSPLUS_EXT_TIMESTAMP_MARK) in the catalog record and the real value
+ * is kept in the xattr as big-endian 64-bit seconds since
+ * 00:00 GMT, Jan. 1, 1970.
+ */
+#define XATTR_LINUX_HFS_PREFIX "linux_hfs."
+#define XATTR_LINUX_HFS_PREFIX_LEN \
+	(sizeof(XATTR_LINUX_HFS_PREFIX) - 1)
+#define XATTR_LINUX_HFS_NAME_MAX	64
+#define XATTR_LINUX_CREATE_DATE_NAME "create_date_u64"
+#define XATTR_LINUX_CONTENT_MOD_DATE_NAME "content_mod_date_u64"
+#define XATTR_LINUX_ATTRIBUTE_MOD_DATE_NAME "attribute_mod_date_u64"
+#define XATTR_LINUX_ACCESS_DATE_NAME "access_date_u64"
+#define XATTR_LINUX_BACKUP_DATE_NAME "backup_date_u64"
+
 extern const struct xattr_handler hfsplus_xattr_osx_handler;
 extern const struct xattr_handler hfsplus_xattr_user_handler;
 extern const struct xattr_handler hfsplus_xattr_trusted_handler;
@@ -23,16 +41,18 @@ int __hfsplus_setxattr(struct inode *inode, const char *name,
 			const void *value, size_t size, int flags);
 
 int hfsplus_setxattr(struct inode *inode, const char *name,
-				   const void *value, size_t size, int flags,
-				   const char *prefix, size_t prefixlen);
-
-ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,
-			   void *value, size_t size);
-
+		     const void *value, size_t size, int flags,
+		     const char *prefix, size_t prefixlen);
 ssize_t hfsplus_getxattr(struct inode *inode, const char *name,
 			 void *value, size_t size,
 			 const char *prefix, size_t prefixlen);
 
+int hfsplus_get_timestamp_xattr(struct super_block *sb, u32 cnid,
+				const char *name, time64_t *ts);
+int hfsplus_set_timestamp_xattr(struct inode *inode, u32 cnid,
+				const char *name, time64_t ts);
+int hfsplus_remove_timestamp_xattr(struct inode *inode, const char *name);
+
 ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size);
 
 int hfsplus_init_security(struct inode *inode, struct inode *dir,
Signature · 1 line
2.53.0
author maintainer
#3 lore raw

PATCH v4 3/3 hfsplus: add KUnit tests for date/time conversion

In reply to Viacheslav Dubeyko

Add the hfsplus_time KUnit test suite that checks
the date/time conversion logic and the extended timestamp support:

(1) hfsplus_time_constants_test: the supported time range

    and HFSPLUS_EXT_TIMESTAMP_MARK value;
(2) hfsplus_mt2ut_test, hfsplus_ut2mt_test: conversion of
    the known dates (1904, 1970, 2000, 2026, 2038, 2040);
(3) hfsplus_ut2mt_before_1970_test: timestamps before
    January 1, 1970 (xfstests generic/258 issue);
(4) hfsplus_ut2mt_clamp_test: out-of-range timestamps are
    clamped instead of wrapped;
(5) hfsplus_time_roundtrip_test: representable timestamps
    survive the round trip;
(6) hfsplus_ut_needs_xattr_test, hfsplus_mt_is_ext_timestamp_test:
    the decision to keep the timestamp in xattr;

(7) hfsplus_read_timestamp_regular_test, hfsplus_read_timestamp_mark_no_xattr_test: reading of the regular on-disk timestamp and HFSPLUS_EXT_TIMESTAMP_MARK without xattr;
(8) hfsplus_timestamp_xattr_names_test: names of internal xattrs fit the name buffer.

The hfsplus_read_timestamp() is exported by means of EXPORT_SYMBOL_IF_KUNIT().

./tools/testing/kunit/kunit.py run --kunitconfig=fs/hfsplus/.kunitconfig

[PASSED] hfsplus_time_constants_test
[PASSED] hfsplus_mt2ut_test
[PASSED] hfsplus_ut2mt_test
[PASSED] hfsplus_ut2mt_before_1970_test
[PASSED] hfsplus_ut2mt_clamp_test
[PASSED] hfsplus_time_roundtrip_test
[PASSED] hfsplus_ut_needs_xattr_test
[PASSED] hfsplus_mt_is_ext_timestamp_test
[PASSED] hfsplus_read_timestamp_regular_test [PASSED] hfsplus_read_timestamp_mark_no_xattr_test [PASSED] hfsplus_timestamp_xattr_names_test ================== [PASSED] hfsplus_time ===================

cc John Paul Adrian Glaubitz <[email protected]>
cc Yangtao Li <[email protected]>
---
 fs/hfsplus/Makefile                           |   2 +-
 fs/hfsplus/hfsplus_time_test.c                | 354 ++++++++++++++++++
 ...{unicode_test.c => hfsplus_unicode_test.c} |   0
 fs/hfsplus/inode.c                            |   2 +
 4 files changed, 357 insertions(+), 1 deletion(-)
 create mode 100644 fs/hfsplus/hfsplus_time_test.c
 rename fs/hfsplus/{unicode_test.c => hfsplus_unicode_test.c} (100%)
fs/hfsplus/Makefile +1 -1
index f2a9ae697e81..7cb0a5ef9831 100644
@@ -10,4 +10,4 @@ hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o btre
 		attributes.o xattr.o xattr_user.o xattr_security.o xattr_trusted.o
 
 # KUnit tests
-obj-$(CONFIG_HFSPLUS_KUNIT_TEST) += unicode_test.o
+obj-$(CONFIG_HFSPLUS_KUNIT_TEST) += hfsplus_unicode_test.o hfsplus_time_test.o
fs/hfsplus/hfsplus_time_test.c new file +354 -0

354 lines not on this page · raw message

fs/hfsplus/hfsplus_unicode_test.c renamed from fs/hfsplus/unicode_test.c +0 -0
similarity index 100%
rename from fs/hfsplus/unicode_test.c
rename to fs/hfsplus/hfsplus_unicode_test.c
fs/hfsplus/inode.c +2 -0
index 8d0c10266e56..faed3e34856a 100644
@@ -18,6 +18,7 @@
 #include <linux/cred.h>
 #include <linux/uio.h>
 #include <linux/fileattr.h>
+#include <kunit/visibility.h>
 
 #include "hfsplus_fs.h"
 #include "hfsplus_raw.h"
@@ -638,6 +639,7 @@ int hfsplus_read_timestamp(struct super_block *sb, u32 cnid,
 
 	return 0;
 }
+EXPORT_SYMBOL_IF_KUNIT(hfsplus_read_timestamp);
 
 static int hfsplus_inode_read_timestamps(struct inode *inode,
 					 struct hfsplus_timestamps *timestamps)
Signature · 1 line
2.53.0