public inbox for ntfs3@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 5.15 01/22] fs/ntfs3: Modified fix directory element type detection
@ 2024-02-13  0:23 Sasha Levin
  2024-02-13  0:23 ` [PATCH AUTOSEL 5.15 02/22] fs/ntfs3: Improve ntfs_dir_count Sasha Levin
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Sasha Levin @ 2024-02-13  0:23 UTC (permalink / raw)
  To: linux-kernel, stable; +Cc: Konstantin Komarov, Sasha Levin, ntfs3

From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>

[ Upstream commit 22457c047ed971f2f2e33be593ddfabd9639a409 ]

Unfortunately reparse attribute is used for many purposes (several dozens).
It is not possible here to know is this name symlink or not.
To get exactly the type of name we should to open inode (read mft).
getattr for opened file (fstat) correctly returns symlink.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/ntfs3/dir.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/fs/ntfs3/dir.c b/fs/ntfs3/dir.c
index d4d9f4ffb6d9..c2fb76bb28f4 100644
--- a/fs/ntfs3/dir.c
+++ b/fs/ntfs3/dir.c
@@ -309,11 +309,31 @@ static inline int ntfs_filldir(struct ntfs_sb_info *sbi, struct ntfs_inode *ni,
 		return 0;
 	}
 
-	/* NTFS: symlinks are "dir + reparse" or "file + reparse" */
-	if (fname->dup.fa & FILE_ATTRIBUTE_REPARSE_POINT)
-		dt_type = DT_LNK;
-	else
-		dt_type = (fname->dup.fa & FILE_ATTRIBUTE_DIRECTORY) ? DT_DIR : DT_REG;
+	/*
+	 * NTFS: symlinks are "dir + reparse" or "file + reparse"
+	 * Unfortunately reparse attribute is used for many purposes (several dozens).
+	 * It is not possible here to know is this name symlink or not.
+	 * To get exactly the type of name we should to open inode (read mft).
+	 * getattr for opened file (fstat) correctly returns symlink.
+	 */
+	dt_type = (fname->dup.fa & FILE_ATTRIBUTE_DIRECTORY) ? DT_DIR : DT_REG;
+
+	/*
+	 * It is not reliable to detect the type of name using duplicated information
+	 * stored in parent directory.
+	 * The only correct way to get the type of name - read MFT record and find ATTR_STD.
+	 * The code below is not good idea.
+	 * It does additional locks/reads just to get the type of name.
+	 * Should we use additional mount option to enable branch below?
+	 */
+	if ((fname->dup.fa & FILE_ATTRIBUTE_REPARSE_POINT) &&
+	    ino != ni->mi.rno) {
+		struct inode *inode = ntfs_iget5(sbi->sb, &e->ref, NULL);
+		if (!IS_ERR_OR_NULL(inode)) {
+			dt_type = fs_umode_to_dtype(inode->i_mode);
+			iput(inode);
+		}
+	}
 
 	return !dir_emit(ctx, (s8 *)name, name_len, ino, dt_type);
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-02-13  0:23 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-13  0:23 [PATCH AUTOSEL 5.15 01/22] fs/ntfs3: Modified fix directory element type detection Sasha Levin
2024-02-13  0:23 ` [PATCH AUTOSEL 5.15 02/22] fs/ntfs3: Improve ntfs_dir_count Sasha Levin
2024-02-13  0:23 ` [PATCH AUTOSEL 5.15 03/22] fs/ntfs3: Correct hard links updating when dealing with DOS names Sasha Levin
2024-02-13  0:23 ` [PATCH AUTOSEL 5.15 04/22] fs/ntfs3: Print warning while fixing hard links count Sasha Levin
2024-02-13  0:23 ` [PATCH AUTOSEL 5.15 05/22] fs/ntfs3: Fix detected field-spanning write (size 8) of single field "le->name" Sasha Levin
2024-02-13  0:23 ` [PATCH AUTOSEL 5.15 06/22] fs/ntfs3: Add NULL ptr dereference checking at the end of attr_allocate_frame() Sasha Levin
2024-02-13  0:23 ` [PATCH AUTOSEL 5.15 07/22] fs/ntfs3: Disable ATTR_LIST_ENTRY size check Sasha Levin
2024-02-13  0:23 ` [PATCH AUTOSEL 5.15 08/22] fs/ntfs3: use non-movable memory for ntfs3 MFT buffer cache Sasha Levin
2024-02-13  0:23 ` [PATCH AUTOSEL 5.15 09/22] fs/ntfs3: Prevent generic message "attempt to access beyond end of device" Sasha Levin
2024-02-13  0:23 ` [PATCH AUTOSEL 5.15 10/22] fs/ntfs3: Correct function is_rst_area_valid Sasha Levin
2024-02-13  0:23 ` [PATCH AUTOSEL 5.15 11/22] fs/ntfs3: Update inode->i_size after success write into compressed file Sasha Levin
2024-02-13  0:23 ` [PATCH AUTOSEL 5.15 12/22] fs/ntfs3: Fix oob in ntfs_listxattr Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox