Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2772798rdb; Mon, 12 Feb 2024 16:49:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IELC6wihcMRTRWfFJSQmkb9pXW+5E9wCxZAFHtsprd8DfFL2YzLz1qn/gFnoE0Z9FBnOwMy X-Received: by 2002:a05:6808:220c:b0:3c0:2ff5:c568 with SMTP id bd12-20020a056808220c00b003c02ff5c568mr9560089oib.45.1707785397686; Mon, 12 Feb 2024 16:49:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707785397; cv=pass; d=google.com; s=arc-20160816; b=E8FNAq+iyjhoVu38kEgtXwLplWg9q21qRIHuhYR34boho7NZaaUN9ZjokJz7qn3Eea ZR6Cj3dNAciDt7WSlBG2JMe3Xuia9BL58LhqGY4qbTXuuw3FxJzRj0vOZzlMs4LUXfys F8J6RLHjrG1X/vOMKAF7kNrAImL6K7Ezb3K/o5Iz2V5l/Ijj433LQfzjcatl9d/nMGbx bSvq9iWCCgxnVY1VFIv4yp43cXWLlalwlXXW758uZyiVQ5KvBaCq54yUnhfM4bUu+p8O DFk4bNMvUoVZKNnRHgREcxqIOp8B3olhAnbRR3RJbUsDJeZ4j5r2/q4MncqCXsbxYdK2 bGRA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=ZfNRL+DYL6eyF1RCIZ1fyxdF80TWWX17Dn4BCXG0jOM=; fh=OWj0IULnsI2I/5vkCkSt6uog6wadob3m/WY4pRCbQ4Y=; b=ry0r2FgSsGd5lzWVqM2f77evang8EWZpGUzCZqWuU4CYEM/rnCboOhaM3e/hKhFxlG /SVoQhWdtetZmicwycUE1DPcuC7Z/JvZ00WVIOfVD0TLgRWZSXojDmVCt60Ckkls2Xj5 quMPnxAUZ6O/vmxcJUJnqyZ/ecPHFOIH/bbrRRNvjYoxCrTX0GFa/1noCSlBSai6x6D5 mqtO8ocdUu6HoAituZtE7//3VPwdM/l1uNkp8TPLzL3tW066G0Hrnnp+uKaO5nhTY43s vBNBBo4xh8f1J7jo/3i/3MMu1W/ALjdW9+PUo09LGbVG83okY024cEgc2q9ICmBbWZJV 4giA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jkEV7UgR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-62684-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62684-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCVj4o1TNB/oR8rFB5Uj2lyr8b6f1ZHYvi+rqLuoDKMxnnRPq2FxL6d5Wc7WbxvYkTRvWfFWkmGaAOC5DFpdWCktjJmeoPkzM3sy0qeLSg== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id t17-20020ac87611000000b0042c2e9340d2si1550893qtq.728.2024.02.12.16.49.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 16:49:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62684-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jkEV7UgR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-62684-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62684-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 7010C1C23992 for ; Tue, 13 Feb 2024 00:49:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4FA1F2230F; Tue, 13 Feb 2024 00:22:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jkEV7UgR" 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 7434D2207A; Tue, 13 Feb 2024 00:22:38 +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=1707783758; cv=none; b=DF1pt0znp4qoYf5V1Pv8PHrUDccxupX6GfvNeJ7+/vlHri+0pu996oFsqfGbGpIUIDztPtEvD8TC280k+2CK6SqPcKjiM2ZyEUKDPh7yC+QFQxhUUdTqsDICcm5ArPlSjpxoi1xMlKS5ESHSTyAFYO2FKlXGXy9tBE7Xv6xPN4Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707783758; c=relaxed/simple; bh=Cj6pQ9boaOw+HAqq3xcQolBE+yhny1YwI6Uzg4l7LBw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=MmwAmhfswwnKlyXbqdhIg2wLrDWna9P0AdpkKRO08CNzPJZtYOLNvHJv8WRvdtfU/829/L0FE/xEH/aENKNgdUmVhs2RMCYldTCr8COcKrvGMgiB7Wdr5bu/qFPGr+WjDRhLdVVJ4T3adup/itNfz+gjeLvA88/Eas+OrM+0qKk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jkEV7UgR; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52804C433F1; Tue, 13 Feb 2024 00:22:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707783758; bh=Cj6pQ9boaOw+HAqq3xcQolBE+yhny1YwI6Uzg4l7LBw=; h=From:To:Cc:Subject:Date:From; b=jkEV7UgRuOtuyfKu8Hmuxlchw4Ba7hSzwP55H6htH5nMebxLkzfOVwCbgQLkOH061 5c4SSUKMDvDiuMZ0FGQx9DSMLeZiTf1KKPyWL6Dt97l0sjc2w73XDNRdNe6dbSSY/4 zyg2g+sDYGLL1tbXZR3O9g2ZDAKF4kbRV45jsRkHztX7WX70iy8cW0HsWvbFjNXzkK W96umbqt1C+6oOf1WqEQTxyQVvAqC8nV7aysg6RpnSFC5UA+p7TuswY9QsHG9Orat0 H7mj2U37AVD9yh/paCIJKHHNiXzLKRpJKTJCa6gDFSTRILFTBJ3WJRbtfN0lFVDO+U ZTx5QYsatkziw== 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.1 01/28] fs/ntfs3: Modified fix directory element type detection Date: Mon, 12 Feb 2024 19:21:59 -0500 Message-ID: <20240213002235.671934-1-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 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.1.77 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 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