Skip to contentSkip to conversation

hfsplus: fix generic/020 xfstests failure

PATCH New Viacheslav Dubeyko 1 participant 1 message Dec 24, 2025

Subsystems (2)
lore
Share & tools
lore

Viacheslav Dubeyko

author maintainer
#0 lore raw

PATCH 1/1 hfsplus: fix generic/020 xfstests failure

The xfstests' test-case generic/020 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/020 _check_generic_filesystem: filesystem on /dev/loop50 is inconsistent (see xfstests-dev/results//generic/020.full for details)

*** add lots of attributes
*** check
*** MAX_ATTRS attribute(s)
+/mnt/test/attribute_12286: Numerical result out of range
*** -1 attribute(s)
*** remove lots of attributes
...
(Run 'diff -u /xfstests-dev/tests/generic/020.out /xfstests-dev/results//generic/020.out.bad' to see the entire diff)

The generic/020 creates more than 100 xattrs and gives its the names user.attribute_<number> (for example, user.attribute_101). As the next step, listxattr() is called with the goal to check the correctness of xattrs creation. However, it was issue in hfsplus_listxattr() logic. This method re-uses
the fd.key->attr.key_name.unicode and strbuf buffers in the loop without re-initialization. As a result, part of the previous name could still remain in the buffers. For example, user.attribute_101 could be processed before user.attribute_54. The issue resulted in formation the name user.attribute_541 instead of user.attribute_54. This patch adds initialization of fd.key->attr.key_name.unicode and strbuf buffers before calling hfs_brec_goto() method that prepare next name in the buffer.

HFS+ logic supports only inline xattrs. Such extended attributes can store values not bigger than 3802 bytes [1]. This limitation requires correction of generic/020 logic. Finally, generic/020 can be executed without any issue:

sudo ./check generic/020

FSTYP         -- hfsplus
PLATFORM      -- Linux/x86_64 hfsplus-testing-0001 6.19.0-rc1+ #44 SMP PREEMPT_DYNAMIC Mon Dec 22 15:39:00 PST 2025
MKFS_OPTIONS  -- /dev/loop51

MOUNT_OPTIONS -- /dev/loop51 /mnt/scratch

generic/020 31s ... 38s
Ran: generic/020
Passed all 1 tests

[1] https://elixir.bootlin.com/linux/v6.19-rc2/source/include/linux/hfs_common.h#L626

cc John Paul Adrian Glaubitz <[email protected]>
cc Yangtao Li <[email protected]>
---
 fs/hfsplus/attributes.c | 14 +++++++--
 fs/hfsplus/xattr.c      | 70 ++++++++++++++++++++++++++++++++++-------
 2 files changed, 70 insertions(+), 14 deletions(-)
fs/hfsplus/attributes.c +11 -3
index ba26980cc503..74b0ca9c4f17 100644
@@ -117,8 +117,10 @@ static int hfsplus_attr_build_record(hfsplus_attr_entry *entry, int record_type,
 		entry->inline_data.record_type = cpu_to_be32(record_type);
 		if (size <= HFSPLUS_MAX_INLINE_DATA_SIZE)
 			len = size;
-		else
+		else {
+			hfs_dbg("value size %zu is too big\n", size);
 			return HFSPLUS_INVALID_ATTR_RECORD;
+		}
 		entry->inline_data.length = cpu_to_be16(len);
 		memcpy(entry->inline_data.raw_bytes, value, len);
 		/*
@@ -238,7 +240,11 @@ int hfsplus_create_attr(struct inode *inode,
 					inode->i_ino,
 					value, size);
 	if (entry_size == HFSPLUS_INVALID_ATTR_RECORD) {
-		err = -EINVAL;
+		if (size > HFSPLUS_MAX_INLINE_DATA_SIZE)
+			err = -E2BIG;
+		else
+			err = -EINVAL;
+		hfs_dbg("unable to store value: err %d\n", err);
 		goto failed_create_attr;
 	}
 
@@ -250,8 +256,10 @@ int hfsplus_create_attr(struct inode *inode,
 	}
 
 	err = hfs_brec_insert(&fd, entry_ptr, entry_size);
-	if (err)
+	if (err) {
+		hfs_dbg("unable to store value: err %d\n", err);
 		goto failed_create_attr;
+	}
 
 	hfsplus_mark_inode_dirty(inode, HFSPLUS_I_ATTR_DIRTY);
 
fs/hfsplus/xattr.c +59 -11

173 lines not on this page · raw message

Signature · 1 line
2.43.0