[PATCH v1 3/5] ntfs: initialize packed EA size when creating hard links

From: Baolin Liu

Date: Tue Oct 27 2026 - 05:41:26 EST


From: Xuewen Wang <wangxuewen@xxxxxxxxxx>

A new hard link has a zero packed EA size in its FILE_NAME even when
the source file already has extended attributes.

For files with EAs and no reparse point, read EA_INFORMATION and check
its attribute length before adding the name. Copy its ea_length into
the new FILE_NAME's packed_ea_size. Skip this assignment for reparse
points, where the same storage holds the reparse-point tag.

Suggested-by: Baolin Liu <liubaolin@xxxxxxxxxx>
Signed-off-by: Xuewen Wang <wangxuewen@xxxxxxxxxx>
---
Tested with the complete five-patch series in QEMU. Published an
O_TMPFILE after inheriting an access ACL and setting a 12000-byte EA.
Offline ntfsinfo inspection confirms that the FILE_NAME attribute in
the file's MFT record has the same packed EA length as EA_INFORMATION
(12134 bytes). The 12000-byte EA contents also match after cache eviction,
remount and a fresh boot.

fs/ntfs/namei.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c
index 4442e1d..b26fd9c 100644
--- a/fs/ntfs/namei.c
+++ b/fs/ntfs/namei.c
@@ -1316,6 +1316,24 @@ static int __ntfs_link(struct ntfs_inode *ni, struct ntfs_inode *dir_ni,
fn->last_access_time = utc2ntfs(inode_get_atime(vi));
memcpy(fn->file_name, name, name_len * sizeof(__le16));

+ if (NInoHasEA(ni) && !(ni->flags & FILE_ATTR_REPARSE_POINT)) {
+ struct ea_information *info;
+ s64 size;
+
+ info = ntfs_attr_readall(ni, AT_EA_INFORMATION, AT_UNNAMED, 0, &size);
+ if (IS_ERR(info)) {
+ err = PTR_ERR(info);
+ goto err_out;
+ }
+ if (size != sizeof(*info))
+ err = -EUCLEAN;
+ else
+ fn->type.ea.packed_ea_size = info->ea_length;
+ kvfree(info);
+ if (err)
+ goto err_out;
+ }
+
/* Add FILE_NAME attribute to index. */
err = ntfs_index_add_filename(dir_ni, fn, MK_MREF(ni->mft_no,
le16_to_cpu(ni_mrec->sequence_number)));