mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Showta Ishizaki <zakinko@snowrabbit.org>
To: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Cc: ntfs3@lists.linux.dev, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Showta Ishizaki <zakinko@snowrabbit.org>
Subject: [PATCH] fs/ntfs3: keep the reparse tag of a long symlink in the parent
Date: Wed, 25 Nov 2026 23:18:20 +0900	[thread overview]
Message-ID: <20261125-ntfs3-02-v1@snowrabbit.org> (raw)

readdir() returns DT_REG for a symlink with a long target once the
symlink itself has been changed:

  # ln -s $(printf 'a%.0s' $(seq 200)) l
  # touch -h l

After a remount l is a symlink for lstat() and a regular file for
readdir().  ntfs3 keeps the reparse data of such a symlink non-resident,
and ni_update_parent() takes the tag only from resident data, so it
writes 0 over the tag in the parent.

Read the tag from disk when the data is non-resident.

I tried targets of 10, 100, 200, 500 and 1000 bytes.  Without the patch
touch -h made the last three DT_REG, and with it all five stay DT_LNK,
also after chown -h and a rename.

Signed-off-by: Showta Ishizaki <zakinko@snowrabbit.org>
---
 fs/ntfs3/frecord.c | 45 ++++++++++++++++++++++++++++++++++++---------
 1 file changed, 36 insertions(+), 9 deletions(-)

diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c
index 16ac847..14b9006 100644
--- a/fs/ntfs3/frecord.c
+++ b/fs/ntfs3/frecord.c
@@ -3039,6 +3039,36 @@ int ni_write_parents(struct ntfs_inode *ni, int sync)
 	return err;
 }
 
+/*
+ * ni_reparse_tag - Return the tag of the reparse point in @attr.
+ *
+ * The tag is the first field of the reparse data (MS-FSCC 2.1.2.2).
+ * ntfs_create_inode() keeps the reparse data of a long symlink
+ * non-resident, so it may have to be read from disk.  Returns 0 if it
+ * cannot be read.
+ */
+static __le32 ni_reparse_tag(struct ntfs_inode *ni, struct ATTRIB *attr)
+{
+	const struct REPARSE_POINT *rp;
+	struct runs_tree run;
+	__le32 tag;
+
+	if (!attr->non_res) {
+		rp = resident_data_ex(attr, sizeof(struct REPARSE_POINT));
+		return rp ? rp->ReparseTag : 0;
+	}
+
+	if (le64_to_cpu(attr->nres.data_size) < sizeof(tag))
+		return 0;
+
+	run_init(&run);
+	if (attr_load_runs_vcn(ni, ATTR_REPARSE, NULL, 0, &run, 0) ||
+	    ntfs_read_run_nb(ni->mi.sbi, &run, 0, &tag, sizeof(tag), NULL))
+		tag = 0;
+	run_close(&run);
+	return tag;
+}
+
 /*
  * ni_update_parent
  *
@@ -3098,15 +3128,12 @@ static bool ni_update_parent(struct ntfs_inode *ni, struct NTFS_DUP_INFO *dup,
 		attr = ni_find_attr(ni, NULL, NULL, ATTR_REPARSE, NULL, 0, NULL,
 				    NULL);
 
-		if (attr) {
-			const struct REPARSE_POINT *rp;
-
-			rp = resident_data_ex(attr,
-					      sizeof(struct REPARSE_POINT));
-			/* If ATTR_REPARSE exists 'rp' can't be NULL. */
-			if (rp)
-				dup->extend_data = rp->ReparseTag;
-		}
+		/*
+		 * Reading only resident data here used to leave extend_data 0
+		 * for a long symlink, and readdir then reported it as DT_REG.
+		 */
+		if (attr)
+			dup->extend_data = ni_reparse_tag(ni, attr);
 	} else if (ni->ni_flags & NI_FLAG_EA) {
 		attr = ni_find_attr(ni, attr, &le, ATTR_EA_INFO, NULL, 0, NULL,
 				    NULL);
-- 
2.54.0 (Apple Git-157)


                 reply	other threads:[~2026-11-25 14:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261125-ntfs3-02-v1@snowrabbit.org \
    --to=zakinko@snowrabbit.org \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    /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®