From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B3EA10FF; Tue, 13 Feb 2024 00:18:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707783522; cv=none; b=QqgdLFRY5tW5HC2H77i9bAgsWUBMS78Wrd0SyWVJcfKbHHsc89C6EfePLw/D+p+s1lRUzrp8CBg+pDdOBHDwLYSsdR3P6YygXvnP63MbaiQ48iM+z3RQfv8qnMZyQB0GASlKRRwyXWpkQjcVtkyt7UEdUmQ3ai+tAcWMZOG4ENA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707783522; c=relaxed/simple; bh=4q8f+1EZ96FP3EZ+oGugQyTMVbkPPMDmROXjxrksiuk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ek2YJpra9a2NyoP2KVQGPWRXSXivupN5jV99ag96fwjLOWPkHkdjXc8unIt/wE29kcKQ7y/fBhIHm/X53KQFp+Y2J6WrcnEJV+sMJ4PYpamarX8py3L0aY4HWM04RyzL4BaRUglSPZrcp0/AbsxAsB7sa13tiVm6ecHu5Kb9Cis= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OJx5CvCI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OJx5CvCI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEEF0C433C7; Tue, 13 Feb 2024 00:18:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707783521; bh=4q8f+1EZ96FP3EZ+oGugQyTMVbkPPMDmROXjxrksiuk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OJx5CvCIJY282j6u4fIxsNh+hLVKi3+jOvXktJac3zg/r0eBAGd2i5N2yxGh+GReG hsiBa963XQQ1gYgsu3R/yi0mcDcZfnNcsNYcPNxUQgq7J7ncwcMuSByIcMmDeix7D3 npMNDh5bRb0gTVRW0xTMD4O3wLBnbAJF22JElUBBg41JeP638tD2cbhkTBrCPDGBoK Othyy0muUMgTi6M+rFaGn4+DF0D8EW63JN92NGiw1Blywe/lQFFO45MyN0M0gZbcCk eMeAdPvp8igaTUpwCOmEbSsSwL1uNSwvZXmi22IVAmirv331YxEiaDMjOJVs6NWxUA dA4CgiiiTo6yw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Konstantin Komarov , Sasha Levin , ntfs3@lists.linux.dev Subject: [PATCH AUTOSEL 6.7 02/58] fs/ntfs3: Modified fix directory element type detection Date: Mon, 12 Feb 2024 19:17:08 -0500 Message-ID: <20240213001837.668862-2-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240213001837.668862-1-sashal@kernel.org> References: <20240213001837.668862-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.7.4 Content-Transfer-Encoding: 8bit From: Konstantin Komarov [ 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 Signed-off-by: Sasha Levin --- 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 ec0566b322d5..22ede4da0450 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