From nobody Thu Nov 19 17:41:19 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.5 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794749207; b=xVnNiVEP2QOafZKNI6xdw34+VOYvOW2cRsPntYJAit7ZiTJLbV7QbeQKBXAruHTiNmpM DfJNJc1CUAzOvqBfiJtWv5hrTEGpS7XbzI0fYnpuGLPfGQlsJT0ErfJJthLEM+HKBLaMh 0JmKpCboYoCU/K22+Vj47jCuy8J8vjJGTc0TvPFyp6GX2BvgqyrgrJEVqHLa2q/ReDBx6 tu91SwZHSz1tpsOeAY/ad+mow27qjxm3J7wqH2X14whFPjD03C733sBPfcbs1VK1FdKfn USDl6sM1tfaRMEUf/sv6zJWSz7bgBxMfyitpTSB2NlS6lcAUX6gXQnl938Sp0728QAA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794749207; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=fJ54AZ8kyr59gug8UziG62hUVeqhH61HdqqjIRIFVek=; b=IUHRFlrguhkK4XsO8bj/u39Fc2zEM+89exA3L2Adl7kcv8DluDKH0+nppcu2ILbcQHOX 5Y0K3R/4RoXmE5MObfLr33aMwoaF9qmRTAqpXFlvnWll9Kqs82yBeX05FqqHFh+2Dh5QQ ve+zMfVlQZakPOnPlhMJA8Q/X5c5QbTBEKvWspw4C/7LAw6JnfOZxyGCu2el39j+SE6Gp Cv9hda5RzkWY7EN3bLNGEHRW2eGJH5IoOoixA3zuMgE8MKbeBIBGJsbdw9YDvsIK/HS81 gPfNhml8T7+Q52Vz7vMCCf7jVXi8KNG6fEta9O6wPimOU5P4A3d4eB1vyKkjZjeiBkQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=mTgfCIiO; arc=none smtp.remote-ip=220.197.31.5 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B057606A330 for ; Sun, 15 Nov 2026 13:26:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2B057606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=mTgfCIiO DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=fJ 54AZ8kyr59gug8UziG62hUVeqhH61HdqqjIRIFVek=; b=mTgfCIiOLIROMyqLDj iWAyq0yMRi3qsSNb4mV9uHlOiidL2Hos5fLVMiHv5kr/SjKAEeeBbA7za5uocibH kxyCF9Rrna4j9wZLHJhmUIs81dgweW3p1xaxRxvITicSe7HyBH6JRkj2PSFSBZ+1 hy704s5838NLejOzrSEwFEOkU= Received: from liubaolin-ThinkPad-E15-Gen-2 (unknown []) by gzga-smtp-mtada-g0-1 (Coremail) with SMTP id _____wD33yHzsvlqXCkHHw--.36757S3; Sun, 15 Nov 2026 21:26:14 +0800 (CST) From: Baolin Liu To: linkinjeon@kernel.org, hyc.lee@gmail.com Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, Dandan Wu , Baolin Liu Subject: [PATCH v4 01/12] ntfs: return zero after removing nonresident attributes Date: Sun, 15 Nov 2026 21:25:58 +0800 Message-ID: <20261115132609.209957-2-liubaolin12138@163.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20261115132609.209957-1-liubaolin12138@163.com> References: <20261115132609.209957-1-liubaolin12138@163.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD33yHzsvlqXCkHHw--.36757S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7uFy3WryrWrWkArWkGr1kGrg_yoW8Wry7pF Z2k34fK3y7Jw17Jws7t3ykXa4Fga18WF4jq345Gw12y3Z8tw4xt345tFy0gw1xKryDK3Wj qr4jgw47ury3ZaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jzOJnUUUUU= X-CM-SenderInfo: xolxutxrol0iasrtmqqrwthudrp/xtbC6RYDzWr5svZtOQAA3y Content-Type: text/plain; charset="utf-8" From: Dandan Wu ntfs_cluster_free() returns the number of freed clusters on success. ntfs_attr_rm() retains that positive value after removing the attribute records. ntfs_attr_remove() treats it as an error and skips invalidating the cached attribute inode. Store the cluster count in an s64 and propagate only negative errors, so successful removal returns zero and the caller invalidates the inode. Fixes: 495e90fa3348 ("ntfs: update attrib operations") Reviewed-by: Baolin Liu Signed-off-by: Dandan Wu --- New in v4. Tested 1536 injected creation failures with small/large inherited ACLs and 512-byte/4 KiB clusters. Free-cluster/free-MFT counts and offline reclamation checks passed. fs/ntfs/attrib.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c index 9266a3ea3b0f..a18d74a9f685 100644 --- a/fs/ntfs/attrib.c +++ b/fs/ntfs/attrib.c @@ -5515,6 +5515,7 @@ int ntfs_attr_rm(struct ntfs_inode *ni) /* Free cluster allocation. */ if (NInoNonResident(ni)) { struct ntfs_attr_search_ctx *ctx; + s64 freed; =20 err =3D ntfs_attr_map_whole_runlist(ni); if (err) @@ -5525,10 +5526,12 @@ int ntfs_attr_rm(struct ntfs_inode *ni) return -ENOMEM; } =20 - ret =3D ntfs_cluster_free(ni, 0, -1, ctx); - if (ret < 0) + freed =3D ntfs_cluster_free(ni, 0, -1, ctx); + if (freed < 0) { + ret =3D freed; ntfs_error(sb, "Failed to free cluster allocation. Leaving inconstant metadata.\n"); + } ntfs_attr_put_search_ctx(ctx); } From nobody Thu Nov 19 17:41:19 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=117.135.210.5 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794749203; b=2CXbstThHaQaJ32tGfN2eFQ/0jvxhTWgo1gp9FisK9o8C5BRVTDUtzqjWYr9+/UYIEx2 HKTxRRl3NqYnZ/oTFKkNSIcYSPJRAvBhd0x080yqeX7/+1BPN9xX1EM8t7zPmjc6qvGv2 I4isf3ns5hNSSgaHkt6Xra+KYUJS5M5D5r3hgPyNNyttLLLqpGPjL8aNF2bHMmmkxQkBB 1LlW8Xz9vRTpq0VPR1LvAEZVUp9SAdjyjaHw4lyubeCYR3t9Z3CXPxsAN4Mg/lMPaik3+ d3Gj0+9m0UCXne9VP11Jmh7aPqAVC0q7xKZBHjHHmqv/9cagxt7z3bx6YxF73RpfZaQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794749203; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=XXJaXzxHBixcD1q9auniGUIiTqL7+5xpVycMghx+12U=; b=xDWGRuUNgM6Ug2DlIXBfARf+Z/Mjg9BsB85IOLgOH8hYY8EljWsf5ZC/Jqtc54Cz8X5Z +mU0gxG0IynexDMStd6RlBtWs8U5lbNApQjDbPUUMBmU7PRvMjIR0EueX4naXLtJaOM+C r/zP4DeknOUsNpMOtnhs3hXWpsvqSrN4dH9q6GNAco/l56KgpiRkMjewagMmGV9BsF4FO h13QZQi5sYBIkx7HGO94ZmHyU2ttdSXSDlkIf8eL65RBOh2BVQrEVeNGkMYK5uEJzWdkc 0kUciKiBr/qycQERTV8MynTqsAZ8TctOYroOi5cFxAE6AmDE0dRIsID2RksbmAYJulw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=ncYlHkse; arc=none smtp.remote-ip=117.135.210.5 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93603606A338 for ; Sun, 15 Nov 2026 13:26:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 93603606A338 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=ncYlHkse DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=XX JaXzxHBixcD1q9auniGUIiTqL7+5xpVycMghx+12U=; b=ncYlHkse/xtlj5hXIc HDksTLqfaWjMA2yjE2huq5BcHyR2uHIjcNcFDb9hDgGRy1r7n/Nug9ZSM0r9gz6v /xI2CeT0o0CeP4bD4vmGnh605rFDWnNnS+muSzFyFQ8dF01tZTvAK5T+eSp1Ykgb lmSV4gUqAYCUlQVlj0CnaZ/6k= Received: from liubaolin-ThinkPad-E15-Gen-2 (unknown []) by gzga-smtp-mtada-g0-1 (Coremail) with SMTP id _____wD33yHzsvlqXCkHHw--.36757S4; Sun, 15 Nov 2026 21:26:14 +0800 (CST) From: Baolin Liu To: linkinjeon@kernel.org, hyc.lee@gmail.com Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, Dandan Wu , Baolin Liu Subject: [PATCH v4 02/12] ntfs: discard attribute inodes after failed initialization Date: Sun, 15 Nov 2026 21:25:59 +0800 Message-ID: <20261115132609.209957-3-liubaolin12138@163.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20261115132609.209957-1-liubaolin12138@163.com> References: <20261115132609.209957-1-liubaolin12138@163.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD33yHzsvlqXCkHHw--.36757S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7AFy7KFy5ArWrKFWrtw4DXFb_yoW8WrWUpF Z7Cry3KwnrAr47Kan3JF4UXa40934UCF4Utry8WrnrA3Z5G3ZFvFy0q340q3ZrtFWrKw4j qF1qg3y7XFW29rDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jDzVbUUUUU= X-CM-SenderInfo: xolxutxrol0iasrtmqqrwthudrp/xtbC6RYDzWr5svZtUgAA3Z Content-Type: text/plain; charset="utf-8" From: Dandan Wu When nonresident attribute initialization fails, ntfs_attr_add() removes the records but can leave the inode cached with its old runlist and base inode reference. After creation rollback frees the MFT record, reuse can find stale attribute state and fail even after space becomes available. After successful removal, clear the attribute inode's dirty state and link count and remove it from the inode hash before dropping its reference. Fixes: 495e90fa3348 ("ntfs: update attrib operations") Reviewed-by: Baolin Liu Signed-off-by: Dandan Wu --- New in v4. Tested repeated creation with a 3236-byte inherited ACL on full volumes with 512-byte/4 KiB clusters. After freeing space, regular-file, O_TMPFILE, directory and FIFO creation succeeded without stale EA state. fs/ntfs/attrib.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c index a18d74a9f685..a88dc62c6a4e 100644 --- a/fs/ntfs/attrib.c +++ b/fs/ntfs/attrib.c @@ -3039,8 +3039,13 @@ int ntfs_attr_add(struct ntfs_inode *ni, __le32 type, (val && (ntfs_inode_attr_pwrite(attr_vi, 0, size, val, false) !=3D size)= )) { err =3D -EIO; ntfs_error(sb, "Failed to initialize just added attribute"); - if (ntfs_attr_rm(attr_ni)) + if (ntfs_attr_rm(attr_ni)) { ntfs_error(sb, "Failed to remove just added attribute"); + } else { + NInoClearDirty(attr_ni); + clear_nlink(attr_vi); + remove_inode_hash(attr_vi); + } iput(attr_vi); goto err_out; } From nobody Thu Nov 19 17:41:19 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.5 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794749199; b=OpQ/NVMPedjGjMYv6izkuLVwfypt5RLdP+V1ODpOPRAFWyZgsfuKS5jDplQna4LFLkrA tyteq4FklTl0Q4tjvGZLxqlDUfEv9mnL7S7Qvx55Hs2z0RKZWhyczcr25UUNpU0Ec6eWH bKV3EogjdDeVDuuezZH8lLZL+UwflyKeRCCoVNfADhZMRKAeHnpdee3qVECCNMKXPcSQ8 C/bFa6AFq+7q7plpe+KpkujnTS612tQqVA/KZCPznMyqUBXCbJZaZ1UN0BbJZlwtLkIMl GPwfgxZ2FiuVuOMf4Y7KxprrW9rXhilKyRjmrU4StimupJK8nMAE2HAWX/yWUjOKDTw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794749199; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=r3FCEkbHpguBbj6tYBETaEBD/jS71Hm5EM8ENzIuC98=; b=V3HiCFVSKe5iHr8j9x0w4hBFCkl49+E4UuxKWtR01JYHnAyuaIL/Bq9LNLXfstZgBv4G wSpfcroXzOTZW0HDZdRmvk4CUD6hn99zSUffKHrNtvwYFQ2bLeX2/pwO1YaOW4R50YuSU JOV1cp7JSqMatmUUlxzOo3cWp6PXXPxhLRw0RPrJmknVSDLENZAGk/F/5VVlBHXuFhsm8 9FFc8k1YJPBbSmF28UGVeLEI+c6Ogr3FVgYGY9w616YGgMghBb7OEc9OWSRkPSyH5d6AP OKvfXh8avaxvIA7rNBHyKUxzIXKFUOHDYeT6hH7V8QUPMVk703PszABZZWDV1Nhl8TA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=RPHlaL0Y; arc=none smtp.remote-ip=220.197.31.5 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5837606A31A for ; Sun, 15 Nov 2026 13:26:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B5837606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=RPHlaL0Y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=r3 FCEkbHpguBbj6tYBETaEBD/jS71Hm5EM8ENzIuC98=; b=RPHlaL0YY2PUFY9rl4 LRATTk6ioWDBF1FjOnuFVllrDI6sFCwQGAwW4MAMEH3VucCNFftHKBT4MEquoT/x NZtIsTiokikgbJrkjOL/c22CulC1lwfU3YAGtJKWw/Jbrt6dFMs82kzElNw3wijy KsZErO1gXaqYHITJrATpw3HU4= Received: from liubaolin-ThinkPad-E15-Gen-2 (unknown []) by gzga-smtp-mtada-g0-1 (Coremail) with SMTP id _____wD33yHzsvlqXCkHHw--.36757S5; Sun, 15 Nov 2026 21:26:15 +0800 (CST) From: Baolin Liu To: linkinjeon@kernel.org, hyc.lee@gmail.com Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, Xuewen Wang , Baolin Liu Subject: [PATCH v4 03/12] ntfs: discard reparse attributes when creation fails Date: Sun, 15 Nov 2026 21:26:00 +0800 Message-ID: <20261115132609.209957-4-liubaolin12138@163.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20261115132609.209957-1-liubaolin12138@163.com> References: <20261115132609.209957-1-liubaolin12138@163.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD33yHzsvlqXCkHHw--.36757S5 X-Coremail-Antispam: 1Uf129KBjvJXoW7Aw1rKw1fJFW8uF4kArW3trb_yoW5JF18pa 93u3yIkwn7X34I9rnakr4F9r12g3ykWF4UGr4UJ3WSywn5Kw1Sva4kKr1j9Fs3ArWrKryq qF4UtrnrJFZ8uFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jdEfOUUUUU= X-CM-SenderInfo: xolxutxrol0iasrtmqqrwthudrp/xtbC6RcDzWr5svdtWwAA3Q Content-Type: text/plain; charset="utf-8" From: Xuewen Wang Creation rollback removes the reparse index entry but leaves the REPARSE_POINT attribute inode cached. The inode retains the old base inode and MFT sequence number after the MFT record is freed. When the record is reused, later index removal can use that stale sequence number and leave reparse index entries referring to freed records. Remove the attribute after deleting its index entry, and drop the returned inode reference after releasing the record locks. Fixes: af0db57d4293 ("ntfs: update inode operations") Reviewed-by: Baolin Liu Signed-off-by: Xuewen Wang --- New in v4. Injected FIFO creation failures after ACL and FILE_NAME setup with 512-byte/4 KiB clusters. Offline checks found no leftover reparse-index entries or allocated MFT records; space counts and retries passed. fs/ntfs/namei.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c index b46fe44b63b5..a84d7bc9bc28 100644 --- a/fs/ntfs/namei.c +++ b/fs/ntfs/namei.c @@ -429,6 +429,7 @@ static struct ntfs_inode *__ntfs_create(const struct mn= t_idmap *idmap, struct in struct mft_record *ni_mrec, *dni_mrec; struct super_block *sb =3D dir_ni->vol->sb; struct inode *rollback_data_vi =3D NULL, *rollback_sd_vi =3D NULL; + struct inode *rollback_rp_vi =3D NULL; __le64 parent_mft_ref; u64 child_mft_ref; __le16 ea_size; @@ -740,8 +741,13 @@ static struct ntfs_inode *__ntfs_create(const struct m= nt_idmap *idmap, struct in ntfs_error(sb, "Failed to roll back DATA attribute.\n"); } =20 - if (rollback_reparse) - ntfs_delete_reparse_index(ni); + if (rollback_reparse) { + if (ntfs_delete_reparse_index(ni) < 0) + ntfs_error(sb, "Failed to roll back reparse index entry."); + if (ntfs_attr_remove(ni, AT_REPARSE_POINT, AT_UNNAMED, 0, + &rollback_rp_vi)) + ntfs_error(sb, "Failed to roll back REPARSE_POINT attribute."); + } /* * Free extent MFT records (should not exist any with current * ntfs_create implementation, but for any case if something will be @@ -766,6 +772,8 @@ static struct ntfs_inode *__ntfs_create(const struct mn= t_idmap *idmap, struct in mutex_unlock(&dir_ni->mrec_lock); mutex_unlock(&ni->mrec_lock); =20 + if (rollback_rp_vi) + iput(rollback_rp_vi); if (rollback_data_vi) iput(rollback_data_vi); if (rollback_sd_vi) From nobody Thu Nov 19 17:41:19 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=117.135.210.4 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794749204; b=GU/UxM6LfiiXo6oBYH8MNpzD+rA5Y9576j91KGcDxN4+rPEuyRe3pSxYdxpsFmOf2d/f NQN1lVK2KY+nl8aW6LDCSNXdNxs4cxYg0kWzHsIV5DthhkOmfb5Ce/ZxlnlYtlZ1/I4rE Of8sQpSCHT2sGScvLoPpOy8YaMTBFh4T0lReO8xo/EQ3MiILU8LhoZf0TW8C3IIJkbEOy IsJKqZwVGRf4NzV6tpkh5MdWZQompOxXtvw1+CYQwEjsiDnrxct44+9HpMyRK0e5WTJe3 GN4JkP3y5ZOhFvI00iDRDZD2SKSumao+3dAhTU/RydBo2zACj/3/2faT+OAjdKcPiXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794749204; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=kKg/9kwKNY2ZO/UoqGeyH2Gnh0wgDsd0MkIzDgaumFs=; b=buKuHf79BRwnJ98pytVgRc5IN9pP+0TftoWmq9XywPK0Xj/Se4pgs+b7ozm926YqASVf mlJecyQWOPr32ymCcVeVdNzuSHXqfvgvi3cV6cB5Bylyhm5Yg5Fwe/U6BLF34fPBQuXpS v0ZMaYjpzigZBeflsjsYyHja7poVx6Ejj9R9T1wUnn9B0/M/hV7DRpMMPy+HH5+jqLysE dFU2jKzlK4PScuI08/aXEodtDNAtjQ9qR13AI8dnKtr3vSwilrW/jeskUACV3Pk1TGk8P VIwkHIduSMr6t7ctsLf2noOv7eT4XEyOh+sqkv7pnSJo1ufN88WpC5ya49gXRNG+yfA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=RSSp0hF1; arc=none smtp.remote-ip=117.135.210.4 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6B57606A32E for ; Sun, 15 Nov 2026 13:26:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B6B57606A32E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=RSSp0hF1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=kK g/9kwKNY2ZO/UoqGeyH2Gnh0wgDsd0MkIzDgaumFs=; b=RSSp0hF1JZl4i5nKta pNFwCj480A3FgFHp0JHV9gPCCxdvrRyf0ENPyPTb8vd8A0ZEYIEcTsK340KGiPD5 DIcI6xLSaL4lMwq9sgErp5IP7WeMROPy3xYzCFBoQbZ8+WgkrFuo4/9h1Nk58hex ntl4unMKExhHhIgcTSj6P1Db0= Received: from liubaolin-ThinkPad-E15-Gen-2 (unknown []) by gzga-smtp-mtada-g0-1 (Coremail) with SMTP id _____wD33yHzsvlqXCkHHw--.36757S6; Sun, 15 Nov 2026 21:26:15 +0800 (CST) From: Baolin Liu To: linkinjeon@kernel.org, hyc.lee@gmail.com Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, Xuewen Wang , Baolin Liu Subject: [PATCH v4 04/12] ntfs: remove remaining attribute lists on creation failure Date: Sun, 15 Nov 2026 21:26:01 +0800 Message-ID: <20261115132609.209957-5-liubaolin12138@163.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20261115132609.209957-1-liubaolin12138@163.com> References: <20261115132609.209957-1-liubaolin12138@163.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD33yHzsvlqXCkHHw--.36757S6 X-Coremail-Antispam: 1Uf129KBjvJXoW7Aw17ZF48CFW3GFyUWFyUKFg_yoW8tw4Dpa 1fuw47AwsrXw1IganakF40934IgrWkGrWUGr4UJ3WSya4kKw1S9asrKF1jkFs3JFZ5GrsF qr4DKr17JrWDuFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2FALUUUUU= X-CM-SenderInfo: xolxutxrol0iasrtmqqrwthudrp/xtbC6RcDzWr5svdtcAAA37 Content-Type: text/plain; charset="utf-8" From: Xuewen Wang Creation rollback can leave an ATTRIBUTE_LIST inode cached after freeing the base and extent MFT records. MFT reuse can find that stale inode; dropping it under another inode's record lock can trigger a lockdep warning. Remove any remaining ATTRIBUTE_LIST before freeing extent records to release its storage and invalidate the cached inode. Drop the returned reference after releasing the record locks. Fixes: af0db57d4293 ("ntfs: update inode operations") Reviewed-by: Baolin Liu Signed-off-by: Xuewen Wang --- New in v4. Tested rollback with large ACLs and long names forcing attribute lists and extent records. Offline reclamation checks, space counts and retries passed with 512-byte/4 KiB clusters. fs/ntfs/namei.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c index a84d7bc9bc28..abb3675757e9 100644 --- a/fs/ntfs/namei.c +++ b/fs/ntfs/namei.c @@ -429,7 +429,7 @@ static struct ntfs_inode *__ntfs_create(const struct mn= t_idmap *idmap, struct in struct mft_record *ni_mrec, *dni_mrec; struct super_block *sb =3D dir_ni->vol->sb; struct inode *rollback_data_vi =3D NULL, *rollback_sd_vi =3D NULL; - struct inode *rollback_rp_vi =3D NULL; + struct inode *rollback_rp_vi =3D NULL, *rollback_al_vi =3D NULL; __le64 parent_mft_ref; u64 child_mft_ref; __le16 ea_size; @@ -748,6 +748,10 @@ static struct ntfs_inode *__ntfs_create(const struct m= nt_idmap *idmap, struct in &rollback_rp_vi)) ntfs_error(sb, "Failed to roll back REPARSE_POINT attribute."); } + if (NInoAttrList(ni) && + ntfs_attr_remove(ni, AT_ATTRIBUTE_LIST, AT_UNNAMED, 0, + &rollback_al_vi)) + ntfs_error(sb, "Failed to roll back ATTRIBUTE_LIST attribute."); /* * Free extent MFT records (should not exist any with current * ntfs_create implementation, but for any case if something will be @@ -772,6 +776,8 @@ static struct ntfs_inode *__ntfs_create(const struct mn= t_idmap *idmap, struct in mutex_unlock(&dir_ni->mrec_lock); mutex_unlock(&ni->mrec_lock); =20 + if (rollback_al_vi) + iput(rollback_al_vi); if (rollback_rp_vi) iput(rollback_rp_vi); if (rollback_data_vi) From nobody Thu Nov 19 17:41:19 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.5 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794749199; b=mzlFfi7I2i+Lssb4yxfzroiy8R9wwmUoMvQMkfBgQLZ4mHrH2j9WQehh767fC7whTHAe tbbJHw6BawYpo3V+2hUYoNaCdLztTaEvqTjvmKq4GFGYpXJldP/DTBRCYtxZYzzFkjF7f 2JcrmBbO3/nNY0ESUqVdOLeWIGraXvxbEKcPB7NosFh/gyMKDnolq0cdG8O60lDM+q4zi s+EcqUEZ6nmFBY+3+myNTB/SgS3o30ofdzgVSCK9FTN6cNGDtgRZOeALZJj0MRN7eZ1kb XJrVRRoVJNnHyx1B6zc0baZZHHuvqPEjhpDJyXvms9ERjb+kyPnTvIi+wLm+8Yv/JSg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794749199; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=cr+vimpw5jt0758YqtYxZsFHqQP3QlFB5SQYksHXPPA=; b=hUt9IpMJWvkXiqPphjfxZIMlGeXHi7VDLwVVgFN0KK3jI6BLWwRAEYfXDJkxR2cBvBbO 10SWoZv+3E40rd9OURagvIwhKo7t5z9ZSzcmjE1C75sSn5zAsznvWXxsri3NLrwibJ0HF 1yJb6Dv24u2KS9EhgppYcWItmsnz5biYOZj/+2ZRr5tMIG3PI+5nD5YI1ejPcraKey/wU ASzewPRtZfumwfpKaMfm4WefmNVs4+B1SHbS24Df96HDZqkUp4hJZl8JxIcwxBHGRT9ws CY1M6yE01k6f9tDUP2fuA8pDe6aWjmWVVlWhk5Lg9s4aW9SKO98w4pjJNRI0D9ib4Rw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=m3v7hcnt; arc=none smtp.remote-ip=220.197.31.5 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B58C5606A31D for ; Sun, 15 Nov 2026 13:26:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B58C5606A31D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=m3v7hcnt DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=cr +vimpw5jt0758YqtYxZsFHqQP3QlFB5SQYksHXPPA=; b=m3v7hcntc3Dt9YPTbh JFOpRV7nEXxGiNhbruiT7wd3I5xVEEQB5R/g/iU1GGzHEVf18rBVwKEgqyayTBgU ZwSiZc2VOizKiA50w/UsGQtlHO76dAHRwMsUY6aoAI/IoWQ8TzxydM0Gx9xapwnV 5mzKPW3EuB/wGvjDw2SUvUXaE= Received: from liubaolin-ThinkPad-E15-Gen-2 (unknown []) by gzga-smtp-mtada-g0-1 (Coremail) with SMTP id _____wD33yHzsvlqXCkHHw--.36757S7; Sun, 15 Nov 2026 21:26:16 +0800 (CST) From: Baolin Liu To: linkinjeon@kernel.org, hyc.lee@gmail.com Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, Baolin Liu Subject: [PATCH v4 05/12] ntfs: initialize inherited ACLs after allocating the MFT record Date: Sun, 15 Nov 2026 21:26:02 +0800 Message-ID: <20261115132609.209957-6-liubaolin12138@163.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20261115132609.209957-1-liubaolin12138@163.com> References: <20261115132609.209957-1-liubaolin12138@163.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD33yHzsvlqXCkHHw--.36757S7 X-Coremail-Antispam: 1Uf129KBjvJXoW3Gr1xXF1UZF47XFy7XrWDJwb_yoW7CF1rpF s3urW7J39rXrySgFs3Kr4Y9r13K397ur4UGr47J3WSy3WFgw1a9a48KFy0kFn3trZ5G3sF qF4UKw47ArZ8u37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2FALUUUUU= X-CM-SenderInfo: xolxutxrol0iasrtmqqrwthudrp/xtbC6RgEzmr5svhthQAA3K Content-Type: text/plain; charset="utf-8" From: Baolin Liu ntfs_init_acl() can write EAs before __ntfs_create() allocates an MFT record, so inherited ACLs can disappear after inode eviction. Initialize ACLs after MFT allocation and standard attribute setup, releasing the record locks around the ACL helpers. Refresh the mode and use the post-ACL ctime for FILE_NAME and its index entry. Roll back EA and EA_INFORMATION on failure. Skip writeback while I_CREATING is set: failed creation clears I_NEW but retains I_CREATING after freeing the MFT record. Fixes: af0db57d4293 ("ntfs: update inode operations") Signed-off-by: Baolin Liu --- Changes since v3: add the I_CREATING guard and Fixes tag, and apply after the cleanup fixes. Drop Reviewed-by because the code changed. Tested cold-cache ACL inheritance and creation rollback. Forced writeback after I_NEW was cleared in failed named and anonymous creation; no access to the freed MFT record occurred, and subsequent creation passed remount. fs/ntfs/inode.c | 4 ++++ fs/ntfs/namei.c | 49 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c index 6a9f488e2775..885818f00b78 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c @@ -2955,6 +2955,10 @@ int __ntfs_write_inode(struct inode *vi, int sync) return 0; } =20 + /* Failed creations retain I_CREATING after discard_new_inode(). */ + if (inode_state_read_once(vi) & I_CREATING) + return 0; + /* igrab prevents vi from being evicted while mrec_lock is hold. */ if (igrab(vi) !=3D NULL) need_iput =3D true; diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c index abb3675757e9..05e2747bae54 100644 --- a/fs/ntfs/namei.c +++ b/fs/ntfs/namei.c @@ -422,6 +422,7 @@ static struct ntfs_inode *__ntfs_create(const struct mn= t_idmap *idmap, struct in struct ntfs_volume *vol =3D dir_ni->vol; struct ntfs_inode *ni; bool rollback_data =3D false, rollback_sd =3D false, rollback_reparse =3D= false; + bool rollback_ea =3D false; struct file_name_attr *fn =3D NULL; struct standard_information *si =3D NULL; int err =3D 0, fn_len, si_len; @@ -429,6 +430,7 @@ static struct ntfs_inode *__ntfs_create(const struct mn= t_idmap *idmap, struct in struct mft_record *ni_mrec, *dni_mrec; struct super_block *sb =3D dir_ni->vol->sb; struct inode *rollback_data_vi =3D NULL, *rollback_sd_vi =3D NULL; + struct inode *rollback_ea_vi =3D NULL, *rollback_eai_vi =3D NULL; struct inode *rollback_rp_vi =3D NULL, *rollback_al_vi =3D NULL; __le64 parent_mft_ref; u64 child_mft_ref; @@ -470,19 +472,6 @@ static struct ntfs_inode *__ntfs_create(const struct m= nt_idmap *idmap, struct in =20 mode =3D vi->i_mode; =20 -#ifdef CONFIG_NTFS_FS_POSIX_ACL - if (!S_ISLNK(mode) && (sb->s_flags & SB_POSIXACL)) { - err =3D ntfs_init_acl(idmap, vi, dir); - if (err) { - iput(vi); - return ERR_PTR(err); - } - } else -#endif - { - vi->i_flags |=3D S_NOSEC; - } - if (uid_valid(vol->uid)) vi->i_uid =3D vol->uid; =20 @@ -647,6 +636,24 @@ static struct ntfs_inode *__ntfs_create(const struct m= nt_idmap *idmap, struct in goto err_out; } =20 + /* ACL EAs need the allocated MFT record and initialized attributes. */ + rollback_ea =3D true; +#ifdef CONFIG_NTFS_FS_POSIX_ACL + if (!S_ISLNK(mode) && (sb->s_flags & SB_POSIXACL)) { + /* The ACL helpers acquire both the parent's and child's locks. */ + mutex_unlock(&dir_ni->mrec_lock); + mutex_unlock(&ni->mrec_lock); + err =3D ntfs_init_acl(idmap, vi, dir); + mutex_lock_nested(&ni->mrec_lock, NTFS_INODE_MUTEX_NORMAL); + mutex_lock_nested(&dir_ni->mrec_lock, NTFS_INODE_MUTEX_PARENT); + if (err) + goto err_out; + mode =3D vi->i_mode; + } +#endif + if (S_ISLNK(mode) || !(sb->s_flags & SB_POSIXACL)) + vi->i_flags |=3D S_NOSEC; + err =3D ntfs_ea_set_wsl_inode(vi, dev, &ea_size, NTFS_EA_UID | NTFS_EA_GID | NTFS_EA_MODE); if (err) @@ -680,7 +687,8 @@ static struct ntfs_inode *__ntfs_create(const struct mn= t_idmap *idmap, struct in if (NVolHideDotFiles(vol) && name_len > 0 && name[0] =3D=3D cpu_to_le16('= .')) fn->file_attributes |=3D FILE_ATTR_HIDDEN; fn->creation_time =3D fn->last_data_change_time =3D utc2ntfs(ni->i_crtime= ); - fn->last_mft_change_time =3D fn->last_access_time =3D fn->creation_time; + fn->last_mft_change_time =3D utc2ntfs(inode_get_ctime(vi)); + fn->last_access_time =3D fn->creation_time; memcpy(fn->file_name, name, name_len * sizeof(__le16)); =20 /* Add FILE_NAME attribute to inode. */ @@ -721,6 +729,15 @@ static struct ntfs_inode *__ntfs_create(const struct m= nt_idmap *idmap, struct in return ni; =20 err_out: + if (rollback_ea) { + if (ntfs_attr_exist(ni, AT_EA, AT_UNNAMED, 0) && + ntfs_attr_remove(ni, AT_EA, AT_UNNAMED, 0, &rollback_ea_vi)) + ntfs_error(sb, "Failed to roll back EA attribute."); + if (ntfs_attr_exist(ni, AT_EA_INFORMATION, AT_UNNAMED, 0) && + ntfs_attr_remove(ni, AT_EA_INFORMATION, AT_UNNAMED, 0, + &rollback_eai_vi)) + ntfs_error(sb, "Failed to roll back EA_INFORMATION attribute."); + } if (rollback_sd) { int rollback_err; =20 @@ -776,6 +793,10 @@ static struct ntfs_inode *__ntfs_create(const struct m= nt_idmap *idmap, struct in mutex_unlock(&dir_ni->mrec_lock); mutex_unlock(&ni->mrec_lock); =20 + if (rollback_ea_vi) + iput(rollback_ea_vi); + if (rollback_eai_vi) + iput(rollback_eai_vi); if (rollback_al_vi) iput(rollback_al_vi); if (rollback_rp_vi) From nobody Thu Nov 19 17:41:19 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.4 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794749238; b=D3NEt+ZnP87q/iStoQkJxc10mAopnPpylRtM5DVMZRXXcTTzScWkCGEOHtvuAvo8o9r9 s/ZV+j7SVgYme+oE3Umfu9EWuR/wIoU6BLjvkCE8EcJ5gycMrtc/zGdx6N5SmfkqdeBcY 9Np3iLcW4Jkf/cIk17AlXA638CXrY8NlYv4/kzAvUw7U3dfjtBiDRLA95lDJRKjtW20Wc qztC3T753rWv62sI/Ig7SeM+KU/nNMntPB0bGdYv4hr3j+29HOGlLmlSiatRIFMutcV9e FVYINJNGaI6V3efs2m+6Q6rcHLQwvvgENdJVAvKhFZNs2vIzmwAA0EE7S49CgdIeG0A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794749238; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=DX9VM9jkTgK560Jv3EZhZ53vVQdjW3sO2tpZaZM1PhE=; b=QFhcWla2JGVXd4rDKW1EfmTmyTd91bsRPsrf+QXIUAAeDJEx2qHFnxIE1I8ncd5vJYxu zlkzflcqj0ehg4KFTAzBXsDZYxZWEcW3VgZlcDQXklsVOx8LNFUazP2ialqhGF7fH1q/U /Lc5rccbChgx3J/kjy4f8v3lquF2ECiOIWjwRYofGntA3NdzLUwziDImJfpM16Ov9cjSs RZ3ey5DkjE+vWWNIxJZz76qQ51WfS0/xKlMySgIFOCNwX3auIGHFxG68pHNJSGVwF1cIP t0ES3pcf2iswD43LRtCoKeZgiwO34Dya5dDc/zMwAis/IrSBhQIC4vPwswSYzCisHQg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=IVS4TsRx; arc=none smtp.remote-ip=220.197.31.4 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FA6A606A31A for ; Sun, 15 Nov 2026 13:27:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5FA6A606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=IVS4TsRx DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=DX 9VM9jkTgK560Jv3EZhZ53vVQdjW3sO2tpZaZM1PhE=; b=IVS4TsRxdA9ZcV9mt4 ragq/3JNwXbuoHocfrQk4eGah1z6gIpCk0EIsPqkQLciu02UApSIF/o8pu+xwVi9 6B3u1X4stxakvmYsRvK7apNBA8BNP+4xHMfhgXd95LqyhXbh0HShr6EyTYWaDrPe 8+zn0XNatvSI/zQ97sjFT2KKo= Received: from liubaolin-ThinkPad-E15-Gen-2 (unknown []) by gzga-smtp-mtada-g0-1 (Coremail) with SMTP id _____wD33yHzsvlqXCkHHw--.36757S8; Sun, 15 Nov 2026 21:26:16 +0800 (CST) From: Baolin Liu To: linkinjeon@kernel.org, hyc.lee@gmail.com Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, Baolin Liu Subject: [PATCH v4 06/12] ntfs: read ACLs using their stored size Date: Sun, 15 Nov 2026 21:26:03 +0800 Message-ID: <20261115132609.209957-7-liubaolin12138@163.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20261115132609.209957-1-liubaolin12138@163.com> References: <20261115132609.209957-1-liubaolin12138@163.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD33yHzsvlqXCkHHw--.36757S8 X-Coremail-Antispam: 1Uf129KBjvJXoW7ZF1fuFW5Xw45Gr48Ar1UKFg_yoW8Cw1fpF sxJr1YgF4xXry2vF1vyr4DXry093WxKay5G34fKa1Ik3yYqrnI9Fy3tFy09a1ftF93Jwn0 qF15KrZIv347uwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2FALUUUUU= X-CM-SenderInfo: xolxutxrol0iasrtmqqrwthudrp/xtbC6RgEzmr5svhtmgAA3V Content-Type: text/plain; charset="utf-8" From: Baolin Liu The ACL setter accepts values larger than PATH_MAX, but ntfs_get_acl() uses a fixed PATH_MAX buffer. Valid ACLs larger than 4096 bytes cannot be read back after inode eviction. Inode-based ACL lookup also propagates this error to permission checks and default ACL inheritance. Query the EA length and allocate the required buffer with GFP_NOFS. Keep the record lock across the size query and read so a concurrent ACL replacement cannot change the required size in between. Fixes: fc053f05ca28 ("ntfs: add reparse and ea operations") Signed-off-by: Baolin Liu --- New in v4. Tested access/default ACLs of 4092, 4100 and 4836 bytes with 512-byte/4 KiB clusters. Inheritance, permissions, remount and reboot checks passed for regular files, O_TMPFILEs, directories and FIFOs. fs/ntfs/ea.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/fs/ntfs/ea.c b/fs/ntfs/ea.c index 68397b2a4e43..834f38ea4a00 100644 --- a/fs/ntfs/ea.c +++ b/fs/ntfs/ea.c @@ -1019,11 +1019,7 @@ struct posix_acl *ntfs_get_acl(const struct mnt_idma= p *idmap, struct dentry *den size_t name_len; struct posix_acl *acl; int err; - void *buf; - - buf =3D kmalloc(PATH_MAX, GFP_KERNEL); - if (!buf) - return ERR_PTR(-ENOMEM); + void *buf =3D NULL; =20 /* Possible values of 'type' was already checked above. */ if (type =3D=3D ACL_TYPE_ACCESS) { @@ -1035,7 +1031,14 @@ struct posix_acl *ntfs_get_acl(const struct mnt_idma= p *idmap, struct dentry *den } =20 mutex_lock(&ni->mrec_lock); - err =3D ntfs_get_ea(inode, name, name_len, buf, PATH_MAX); + err =3D ntfs_get_ea(inode, name, name_len, NULL, 0); + if (err > 0) { + buf =3D kmalloc(err, GFP_NOFS); + if (!buf) + err =3D -ENOMEM; + else + err =3D ntfs_get_ea(inode, name, name_len, buf, err); + } mutex_unlock(&ni->mrec_lock); =20 /* Translate extended attribute to acl. */ From nobody Thu Nov 19 17:41:19 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=117.135.210.3 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794749199; b=UDsP/LIsxirMaiqZtWyXDD30Nv0vPJL7Moi2e4/LtPn+3GFC4rimno4IP604/QOHt4J+ H6Wu39cJm7cxEPMEWy35jgbcTnBg5uvrpQ5iNpjuMONqMAtpV+EVbU3MRkhC/8CFbxdni EVIAk0HQjtPcY1oSqEQz2894GxAlb7Uxq8mECs8p6+jRrxUBQ3F8cgDdhJXRnwJGffOi6 8qyecNXfhEpLqfhaeh+i0uJJS1+SllgoCLXSfASrwMzecYPLs+IqJ19+F8V7pG6zbzzrV 9QDhrc7r5EB3GJRE786Gt16fuj81fK+ig7SjvA3g+E0h6vg0kNNJkwrwJzE7V/ABTtQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794749199; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=DxFqHk89+AUxsswFbtHbs6sZwleEydVjCKAy+YjPdgc=; b=I7lFuXJAVcMtzQ2KnRJWIvc10zqzsZWcAaM/P1qgcgDHtsdrrHa4Yf5F3HentCj5u+pY QgsHP1aHngNGRNE6/2yMtMEInrzYUx6j7O395dA+fs1pi57F6/oeVJk7nYPc7VoiPKJ1R 01a5Vuizi2hhvGd3lUHKAVVwE+W+nnQ/Y9KTSlMeWN2poIP1siCWmdZ3wNl/hQWlo2OLl 8rfjClJpUFDZhtSCVpwGKOQbqj64y4qHXPbIU3hffclwCNP7mGA5OjnDOSRuf3LF4rBwc oR3EOeeD3sqssgDG0iZywQyjSRipB9lhaEwUgw4PTf5simpTJ7NCRtbtgHL8ziIOwRA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=RGJq4BJd; arc=none smtp.remote-ip=117.135.210.3 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33A54606A329 for ; Sun, 15 Nov 2026 13:26:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 33A54606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=RGJq4BJd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Dx FqHk89+AUxsswFbtHbs6sZwleEydVjCKAy+YjPdgc=; b=RGJq4BJdQ3sWN3ehbj AAcb0TSLaLe2co11goFSE9YHc8K0oLObAiSUCbO8TzIsk7y0MR3GqDgRQhSZFg5L nvfnxaBXs04fL8tv5WE3fmyljA6QdqvXPxNMUrnwtsHO2Qu4RXXUb9AZ9r6QLUGC WtlB2HMh0CScNTMIQQRc9+UQM= Received: from liubaolin-ThinkPad-E15-Gen-2 (unknown []) by gzga-smtp-mtada-g0-1 (Coremail) with SMTP id _____wD33yHzsvlqXCkHHw--.36757S9; Sun, 15 Nov 2026 21:26:17 +0800 (CST) From: Baolin Liu To: linkinjeon@kernel.org, hyc.lee@gmail.com Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, Baolin Liu Subject: [PATCH v4 07/12] ntfs: load uncached ACLs through get_inode_acl Date: Sun, 15 Nov 2026 21:26:04 +0800 Message-ID: <20261115132609.209957-8-liubaolin12138@163.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20261115132609.209957-1-liubaolin12138@163.com> References: <20261115132609.209957-1-liubaolin12138@163.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD33yHzsvlqXCkHHw--.36757S9 X-Coremail-Antispam: 1Uf129KBjvJXoWxGFWkGr1UJryxurWkKFWDXFb_yoWrXFyxpF sxJw1rKa1xZrWSgwn2kr4DXw1F9ryxWa9Fg34rWw1Ska4Dtr13tFy8Ka1xuF95trWrGFnF gF15Kr4jvr15Wr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07Uio7NUUUUU= X-CM-SenderInfo: xolxutxrol0iasrtmqqrwthudrp/xtbC6RkEzmr5svltpAAA3r Content-Type: text/plain; charset="utf-8" From: Baolin Liu Permission checks and default ACL inheritance use get_inode_acl(), which cannot call NTFS's dentry-based get_acl callback. After inode eviction, these paths treat stored ACLs as absent unless an explicit xattr read has populated the cache. Use get_inode_acl for regular files, directories and special files, leaving ACL caching to the VFS. Return -ECHILD during RCU lookup so the VFS retries where the EA read can sleep. Fixes: 9c87959601e8 ("ntfs: update file operations") Signed-off-by: Baolin Liu --- New in v4. Tested cold-cache inheritance and permissions, O_TMPFILE publication, chmod, ACL replacement/removal, idmapped mounts and concurrent default ACL replacement/creation. Remount and reboot checks passed. fs/ntfs/ea.c | 10 ++++------ fs/ntfs/ea.h | 3 +-- fs/ntfs/file.c | 4 ++-- fs/ntfs/namei.c | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/fs/ntfs/ea.c b/fs/ntfs/ea.c index 834f38ea4a00..b745391b3f25 100644 --- a/fs/ntfs/ea.c +++ b/fs/ntfs/ea.c @@ -1010,10 +1010,8 @@ const struct xattr_handler * const ntfs_xattr_handle= rs[] =3D { // clang-format on =20 #ifdef CONFIG_NTFS_FS_POSIX_ACL -struct posix_acl *ntfs_get_acl(const struct mnt_idmap *idmap, struct dentr= y *dentry, - int type) +struct posix_acl *ntfs_get_acl(struct inode *inode, int type, bool rcu) { - struct inode *inode =3D d_inode(dentry); struct ntfs_inode *ni =3D NTFS_I(inode); const char *name; size_t name_len; @@ -1021,6 +1019,9 @@ struct posix_acl *ntfs_get_acl(const struct mnt_idmap= *idmap, struct dentry *den int err; void *buf =3D NULL; =20 + if (rcu) + return ERR_PTR(-ECHILD); + /* Possible values of 'type' was already checked above. */ if (type =3D=3D ACL_TYPE_ACCESS) { name =3D XATTR_NAME_POSIX_ACL_ACCESS; @@ -1049,9 +1050,6 @@ struct posix_acl *ntfs_get_acl(const struct mnt_idmap= *idmap, struct dentry *den else acl =3D ERR_PTR(err); =20 - if (!IS_ERR(acl)) - set_cached_acl(inode, type, acl); - kfree(buf); =20 return acl; diff --git a/fs/ntfs/ea.h b/fs/ntfs/ea.h index f200d49063e0..e9ea024f6a8e 100644 --- a/fs/ntfs/ea.h +++ b/fs/ntfs/ea.h @@ -28,8 +28,7 @@ int ntfs_ea_set_linuxflags(struct inode *inode, u32 linux= flags); ssize_t ntfs_listxattr(struct dentry *dentry, char *buffer, size_t size); =20 #ifdef CONFIG_NTFS_FS_POSIX_ACL -struct posix_acl *ntfs_get_acl(const struct mnt_idmap *idmap, struct dentr= y *dentry, - int type); +struct posix_acl *ntfs_get_acl(struct inode *inode, int type, bool rcu); int ntfs_set_acl(const struct mnt_idmap *idmap, struct dentry *dentry, struct posix_acl *acl, int type); int ntfs_init_acl(const struct mnt_idmap *idmap, struct inode *inode, diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c index 5ab0e3437d67..a52483d16c6e 100644 --- a/fs/ntfs/file.c +++ b/fs/ntfs/file.c @@ -1580,7 +1580,7 @@ const struct inode_operations ntfs_file_inode_ops =3D= { .fileattr_get =3D ntfs_fileattr_get, .fileattr_set =3D ntfs_fileattr_set, .listxattr =3D ntfs_listxattr, - .get_acl =3D ntfs_get_acl, + .get_inode_acl =3D ntfs_get_acl, .set_acl =3D ntfs_set_acl, .fiemap =3D ntfs_fiemap, }; @@ -1600,7 +1600,7 @@ const struct inode_operations ntfs_special_inode_oper= ations =3D { .listxattr =3D ntfs_listxattr, .fileattr_get =3D ntfs_fileattr_get, .fileattr_set =3D ntfs_fileattr_set, - .get_acl =3D ntfs_get_acl, + .get_inode_acl =3D ntfs_get_acl, .set_acl =3D ntfs_set_acl, }; =20 diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c index 05e2747bae54..d3c63b1c166f 100644 --- a/fs/ntfs/namei.c +++ b/fs/ntfs/namei.c @@ -1703,7 +1703,7 @@ const struct inode_operations ntfs_dir_inode_ops =3D { .mkdir =3D ntfs_mkdir, .rmdir =3D ntfs_rmdir, .rename =3D ntfs_rename, - .get_acl =3D ntfs_get_acl, + .get_inode_acl =3D ntfs_get_acl, .set_acl =3D ntfs_set_acl, .listxattr =3D ntfs_listxattr, .setattr =3D ntfs_setattr, From nobody Thu Nov 19 17:41:19 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.3 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794749260; b=iN+nRybnlIF5shZpgsmLKGCsR4Bqk0cIiDkSh9i7gh2y8rXcy6I5jdFnNGeGTwj5X0RN CZ9nt8Sq0r8PCwkbUFop9jzsWKct81LP2orF3NTJtzPsSQ9CCTOS60LaksdSA0IJeCen9 VYkuIhLLRL85vkrPuMi9QqW+MnmcBFvGwjlADc8HBHW/6IttBVJO+Eg/RG8vZ2Vpq5mU4 wXarrFbwgqN1zjXMPqd2QPCwgKEk0SmRKdD/Gx5gmcO1eV0adx13lvokQdZnaiVdxxL7n B4yysc2y69dsifc8BuVkJyRhkYQ5wQR0AMXeO8GPt1AF+hY9PNAxpMQseYL52cYoiKg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794749260; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=0YzvRYiv79bpbctDgzMqBgGUItuMaP+M3ARcws7Fb+s=; b=HJWajr5K3rlPu8tuBuKtpdueUny5iqVAJNISqacoY045pQ6OBZ4r3zxGz9+QFQky1Ypn 0UpG54BduSsdnVWh0ZnROZLwwdAI1J6YgAs1HG0ucULGJMIgrpR2lDPxQPlHBxQKRGUHj T2ADu9h/xqkorGoTUYhpUABuvyRP+wfPxhWt23mWD5cCmcU18XcEQvk6I7IN3p6VQ74s+ RsoKKekvuerVzgsXxqvT9a2uquS79NpBQNpaotTmZXiG0sxEs1IhQqMOdZ/DnoOlHS4nR rxQkC2sI9hHBtziulvC3qwBgnO6uKbI9Afz9urwu8PewfJH8mrJXpIz4cVwOXT+fDSg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=Ppt6upIw; arc=none smtp.remote-ip=220.197.31.3 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 422F2606A8B4 for ; Sun, 15 Nov 2026 13:27:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 422F2606A8B4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=Ppt6upIw DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=0Y zvRYiv79bpbctDgzMqBgGUItuMaP+M3ARcws7Fb+s=; b=Ppt6upIwMgVlkGkncK 9Y0vCWzByR49ZFVZsPC3P5cYnRLS8D90U/oricbUcHBwIrOfCYpPuWiZaiY80h0N km7YetQ9uDss6x8raM1xUjarsbFVxSadDOcTCZHMfXPOG7niSZcS4sWN7xfq67Q2 tFVcVs4GysWeqg7SzhISqnmiA= Received: from liubaolin-ThinkPad-E15-Gen-2 (unknown []) by gzga-smtp-mtada-g0-4 (Coremail) with SMTP id _____wDXP_A1s_lqfjtyIQ--.47831S2; Sun, 15 Nov 2026 21:27:18 +0800 (CST) From: Baolin Liu To: linkinjeon@kernel.org, hyc.lee@gmail.com Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, Xuewen Wang , Baolin Liu Subject: [PATCH v4 08/12] ntfs: preserve timestamps when creating hard links Date: Sun, 15 Nov 2026 21:26:05 +0800 Message-ID: <20261115132609.209957-9-liubaolin12138@163.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20261115132609.209957-1-liubaolin12138@163.com> References: <20261115132609.209957-1-liubaolin12138@163.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wDXP_A1s_lqfjtyIQ--.47831S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxAryUAr4xGryUKF4UZF4rAFb_yoWrWF4kpF W7Kw1DKr4xXrW7WFn2yF4q9rWSga4I9ay7JFWUKw12y3Z0qw18tF1Ivry2vF1rtrZ5Zr1a qa1rKr1UWw1UGwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j0yIUUUUUU= X-CM-SenderInfo: xolxutxrol0iasrtmqqrwthudrp/xtbC6hYT3Wr5szYKLwAA3B Content-Type: text/plain; charset="utf-8" From: Xuewen Wang ntfs_link() resets all timestamps on the source file and destination directory, overwriting file atime/mtime and directory atime. Update only source ctime and directory mtime/ctime. Use the same ctime for the new FILE_NAME, its index entry and the source inode, updating the inode only after the link succeeds. Mark both inodes dirty for writeback. Keep the rename caller's timestamp behavior unchanged. Fixes: af0db57d4293 ("ntfs: update inode operations") Reviewed-by: Hyunchul Lee Reviewed-by: Baolin Liu Signed-off-by: Xuewen Wang --- Changes since v3: add the Fixes tag; no code changes. generic/004 and generic/389 passed in QEMU. Offline checks confirmed matching ctime in STANDARD_INFORMATION, the new FILE_NAME and its index entry. File atime/mtime and directory atime were preserved. fs/ntfs/namei.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c index d3c63b1c166f..4d94e3012677 100644 --- a/fs/ntfs/namei.c +++ b/fs/ntfs/namei.c @@ -1258,6 +1258,7 @@ static int ntfs_rmdir(struct inode *dir, struct dentr= y *dentry) * @dir_ni: ntfs inode for directory in which new link should be placed * @name: unicode name of the new link * @name_len: length of the name in unicode characters + * @ctime: metadata change time for the new FILE_NAME * * Create a new hard link. This involves adding an entry to the directory * index and adding a new FILE_NAME attribute to the target inode. @@ -1265,7 +1266,7 @@ static int ntfs_rmdir(struct inode *dir, struct dentr= y *dentry) * Return 0 on success and -errno on error. */ static int __ntfs_link(struct ntfs_inode *ni, struct ntfs_inode *dir_ni, - __le16 *name, u8 name_len) + __le16 *name, u8 name_len, struct timespec64 ctime) { struct super_block *sb; struct inode *vi =3D VFS_I(ni); @@ -1327,7 +1328,7 @@ static int __ntfs_link(struct ntfs_inode *ni, struct = ntfs_inode *dir_ni, =20 fn->creation_time =3D utc2ntfs(ni->i_crtime); fn->last_data_change_time =3D utc2ntfs(inode_get_mtime(vi)); - fn->last_mft_change_time =3D utc2ntfs(inode_get_ctime(vi)); + fn->last_mft_change_time =3D utc2ntfs(ctime); fn->last_access_time =3D utc2ntfs(inode_get_atime(vi)); memcpy(fn->file_name, name, name_len * sizeof(__le16)); =20 @@ -1478,7 +1479,8 @@ static int ntfs_rename(const struct mnt_idmap *idmap,= struct inode *old_dir, goto err_out; } =20 - err =3D __ntfs_link(old_ni, new_dir_ni, uname_new, new_name_len); + err =3D __ntfs_link(old_ni, new_dir_ni, uname_new, new_name_len, + inode_get_ctime(old_inode)); if (err) goto err_out; =20 @@ -1644,6 +1646,7 @@ static int ntfs_link(struct dentry *old_dentry, struc= t inode *dir, int uname_len; int err; struct ntfs_inode *ni =3D NTFS_I(vi), *dir_ni =3D NTFS_I(dir); + struct timespec64 ctime; =20 if (NVolShutdown(vol)) return -EIO; @@ -1668,7 +1671,8 @@ static int ntfs_link(struct dentry *old_dentry, struc= t inode *dir, ihold(vi); mutex_lock_nested(&ni->mrec_lock, NTFS_INODE_MUTEX_NORMAL); mutex_lock_nested(&dir_ni->mrec_lock, NTFS_INODE_MUTEX_PARENT); - err =3D __ntfs_link(NTFS_I(vi), NTFS_I(dir), uname, uname_len); + ctime =3D current_time(vi); + err =3D __ntfs_link(ni, dir_ni, uname, uname_len, ctime); if (err) { mutex_unlock(&dir_ni->mrec_lock); mutex_unlock(&ni->mrec_lock); @@ -1678,12 +1682,13 @@ static int ntfs_link(struct dentry *old_dentry, str= uct inode *dir, } =20 inode_inc_iversion(dir); - simple_inode_init_ts(dir); + inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); + mark_inode_dirty(dir); =20 inode_inc_iversion(vi); - simple_inode_init_ts(vi); + inode_set_ctime_to_ts(vi, ctime); + mark_inode_dirty(vi); =20 - /* timestamp is already written, so mark_inode_dirty() is unneeded. */ d_instantiate(dentry, vi); mutex_unlock(&dir_ni->mrec_lock); mutex_unlock(&ni->mrec_lock); From nobody Thu Nov 19 17:41:19 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=117.135.210.2 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794749266; b=wQa/yjqpL2mUyu6W1Ksh/1++3JpDBKi4x+E7cxsDu7aLg08gYuCGZe4nElMjegIlWeQl Gddi/3jrd3xyQMgqsiegpkiq/m8l/TXnnsUF16YYTCPUFVrYfN0j1FyYmR+X+Y22UUqvY gjXn/PJNCAB9i8hNKgjW92zApm3dDWfj9hCaTaCwRVIsaKcWbiDlsLSOofMr+8R/2qJFI SkjhQ7f+untDM6VQxjHCh9Mx0+okrbVOBLs/suE0q9h28cYu9BIHzmwVR56Wqxtpvwpbz 3GRcd3GeZNdeiWCi4A+id1HK5eDb1nKcQsR2BXnAJJcaol2yPPSqbMPWRtV00WWbJXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794749266; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=RcSJMzTllFpoqlcqD030BZbd0w78HeFLQAwQPSIp/eM=; b=k5jqEhC3RG0MP9rf92SgexYPv3cU7jcQfk/JbGgZV52QFv4dR2pS0zxmSKDjLi1llEb+ 6O1wFYy4zRyRFoXmsNy6b41+fFaKTJMVSGktw6EkR4uxpXNu3aNJk6g32ANRNmy2CdgvV ++D8X+3e80kjeMqp5LyAH8U89zdkvoOWYv0pmGfitPpEp9VLiqIz8OukA7KMumHtYpUh9 m/VbejlKYSGUQ0YOHKbQ7o+kjckHTiBKXtOgLl0DkdMWZsyPfP+MN8OO6/m1ZJwsV3wst qq+EmJ/x76TjsxJ9XLn4wHKHlTQ8qL18G2IDo3Zz23FmNr3AuGHPAck2YM3jJgtaA2A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=J5y6xgZ0; arc=none smtp.remote-ip=117.135.210.2 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9713606A31A for ; Sun, 15 Nov 2026 13:27:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E9713606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=J5y6xgZ0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Rc SJMzTllFpoqlcqD030BZbd0w78HeFLQAwQPSIp/eM=; b=J5y6xgZ0Ulyr91S7HW Uu+AF6ALf+4oiMe2jJHxfbQzSiZMTdl31ATptpuU5PYuv3CoGMB6N3aWRzBw6OSS ffDHGP9qdP5ITVYnP31+kOdaYDnsVwQdPOrIiXYmc+9IJXHuvy4fkQq3FFqbE5xQ 6ii09kRw7KNVv4F0KIgdw4SSo= Received: from liubaolin-ThinkPad-E15-Gen-2 (unknown []) by gzga-smtp-mtada-g0-4 (Coremail) with SMTP id _____wDXP_A1s_lqfjtyIQ--.47831S3; Sun, 15 Nov 2026 21:27:19 +0800 (CST) From: Baolin Liu To: linkinjeon@kernel.org, hyc.lee@gmail.com Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, Xuewen Wang , Baolin Liu Subject: [PATCH v4 09/12] ntfs: initialize packed EA size when creating hard links Date: Sun, 15 Nov 2026 21:26:06 +0800 Message-ID: <20261115132609.209957-10-liubaolin12138@163.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20261115132609.209957-1-liubaolin12138@163.com> References: <20261115132609.209957-1-liubaolin12138@163.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wDXP_A1s_lqfjtyIQ--.47831S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ar4xtF1DAFyrKF1xGr1Utrb_yoW8ZrWUpF ZxGw1Fqa17XryagF9ayrZIva1fW397Ca1UGrs3Kr12k3ZYq3Z0ga4xKryUWrn3JFW8ua4Y qF4Yy3y7XryUZ3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jwAwsUUUUU= X-CM-SenderInfo: xolxutxrol0iasrtmqqrwthudrp/xtbC6hcT3Wr5szcKPAAA3S Content-Type: text/plain; charset="utf-8" From: Xuewen Wang 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. Fixes: af0db57d4293 ("ntfs: update inode operations") Suggested-by: Baolin Liu Reviewed-by: Hyunchul Lee Reviewed-by: Baolin Liu Signed-off-by: Xuewen Wang --- Changes since v3: add the Fixes tag; no code changes. EAs remained readable after publication, cache eviction, remount and reboot. Offline checks confirmed matching packed EA sizes in EA_INFORMATION, FILE_NAME and directory index entries. fs/ntfs/namei.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c index 4d94e3012677..3eb2d57bef1b 100644 --- a/fs/ntfs/namei.c +++ b/fs/ntfs/namei.c @@ -1332,6 +1332,24 @@ static int __ntfs_link(struct ntfs_inode *ni, struct= ntfs_inode *dir_ni, fn->last_access_time =3D utc2ntfs(inode_get_atime(vi)); memcpy(fn->file_name, name, name_len * sizeof(__le16)); =20 + if (NInoHasEA(ni) && !(ni->flags & FILE_ATTR_REPARSE_POINT)) { + struct ea_information *info; + s64 size; + + info =3D ntfs_attr_readall(ni, AT_EA_INFORMATION, AT_UNNAMED, 0, &size); + if (IS_ERR(info)) { + err =3D PTR_ERR(info); + goto err_out; + } + if (size !=3D sizeof(*info)) + err =3D -EUCLEAN; + else + fn->type.ea.packed_ea_size =3D info->ea_length; + kvfree(info); + if (err) + goto err_out; + } + /* Add FILE_NAME attribute to index. */ err =3D ntfs_index_add_filename(dir_ni, fn, MK_MREF(ni->mft_no, le16_to_cpu(ni_mrec->sequence_number))); From nobody Thu Nov 19 17:41:19 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.4 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794749255; b=W5DQCCtnyP06LXbsx5SOp9ELZaNu99mCHdQ7xPQqDU730ckeyTJjYm0Nze0gxz/fdjw7 LvB8CFExek/uqJ8Hu7h6X24eu/CZTvtbCBTX0qFlCyLohd7Jm1P3HlwyhW1ezdCZiynIH Id96el1vDbXz8Z8itASt0A+8NsTUSwNx7Jx9y3zxjJIOjqMUFauvWgOclgY0TE77fCANZ zpK1jvEUZ1GsvE6wGhUdpbGHUZvZmUItX+EnE/HklfmmpU8S81gxiu4kPuw1IhjmQ7CzS jkWrVQQL/tv8eIvsS6fPXcZ14bwBoKUUUdmSoiIM5CPcBZg3qW0r6kxgyZe3/pBvsRQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794749255; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=1jFE1IGMcuyCuZXQl2Is0ps1VLwkmCGSQjEBczV5rqA=; b=f0uXdNdqUExrCraNVo1VEeyUP6Dejax0eHxoo2uXZTVDYsrkkpshVVHB+EPBqTPalavw oCUtRrWTmfQ9AU58eFQyI25h5f0TVz4t/OGt9Y3C1fhbSvfVJ+j7CLfQIakD/l/L9W71E JcUMLJGkagPD+ntqvaqJYLarcAgymiW1jrHJGnsSf2vlSQtNNwSV/Dt1LgMu+iHbA7G/j 0nYK9lTP3DWWeYv1vJqMhpGxaVkIi0wHk2dmaTeNaNEkLCtkw5tFHSU+jPrQZiJ1pxl0G +AR6dooiHPT1ZdpQOayARJrgOHPouJ0fDZPvDh08fnBLd6RjsNsbTldHRqfMaydBEvA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=PVvisqBE; arc=none smtp.remote-ip=220.197.31.4 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F0C0606A31A for ; Sun, 15 Nov 2026 13:27:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1F0C0606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=PVvisqBE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=1j FE1IGMcuyCuZXQl2Is0ps1VLwkmCGSQjEBczV5rqA=; b=PVvisqBEAKPMfSdUHG jEbkgZojMl8o8FQa1bDrVQVEUu5dWaCWS3vpDSUuOtzrVRNdd25T+wKidvb8+6jN PrnRkPSQ18lKKOnaWnTBGX3InQw/aVf6fX0whL6AhoqR0uz0wjSQxr3oEfveNNfm +v2ErsBKw/J+y+F92ARcNP338= Received: from liubaolin-ThinkPad-E15-Gen-2 (unknown []) by gzga-smtp-mtada-g0-4 (Coremail) with SMTP id _____wDXP_A1s_lqfjtyIQ--.47831S4; Sun, 15 Nov 2026 21:27:19 +0800 (CST) From: Baolin Liu To: linkinjeon@kernel.org, hyc.lee@gmail.com Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, Xuewen Wang , Baolin Liu Subject: [PATCH v4 10/12] ntfs: write unlinked file attributes before dropping their cache Date: Sun, 15 Nov 2026 21:26:07 +0800 Message-ID: <20261115132609.209957-11-liubaolin12138@163.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20261115132609.209957-1-liubaolin12138@163.com> References: <20261115132609.209957-1-liubaolin12138@163.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wDXP_A1s_lqfjtyIQ--.47831S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxKF1ftr1UuFWDWrW8Jr4DXFb_yoW7Aw1fpF Z3CrZxtr4DXw12gws3ta1jq3WSq34xKr4UJry7Gr17A3ZYqr12gFWIk348tF1ftrWDWrWq qr4q9r4xuFWxXr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jDwIDUUUUU= X-CM-SenderInfo: xolxutxrol0iasrtmqqrwthudrp/xtbC6RcT3Wr5szd1XgAA3M Content-Type: text/plain; charset="utf-8" From: Xuewen Wang Zero-link internal attribute inodes are evicted at the final iput(), discarding dirty folios while the base file may still be open. Make writes and conversions synchronous when the attribute inode's own link count is zero, even after O_TMPFILE publication. Preserve the named stream writeback path. Write converted data before committing the nonresident layout so failures preserve the resident value. Propagate conversion I/O errors while still skipping busy candidates. Reviewed-by: Baolin Liu Signed-off-by: Xuewen Wang --- Changes since v3: check the attribute inode's own link count in both write paths. Adapt to the merged named-stream conversion fix, retaining NOWAIT and skipping busy candidates while propagating I/O errors. Tested publication/rewrite while fsync held a zero-link EA inode, SD/EA persistence with 512-byte/4 KiB/8 KiB clusters, and block-write EIO during EA conversion. The resident value and free space were preserved on EIO; retry and reboot passed. Locked fallback folios, conversion errors and uncached named-stream conversion also passed. fs/ntfs/attrib.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++-- fs/ntfs/inode.c | 8 +++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c index a88dc62c6a4e..af044ea895fc 100644 --- a/fs/ntfs/attrib.c +++ b/fs/ntfs/attrib.c @@ -16,6 +16,7 @@ * Copyright (c) 2010 Erik Larsson */ =20 +#include #include #include #include @@ -1961,6 +1962,40 @@ int ntfs_resident_attr_value_resize(struct mft_recor= d *m, struct attr_record *a, return 0; } =20 +/* Write the resident value to its new clusters before committing conversi= on. */ +static int ntfs_attr_write_conversion(struct ntfs_volume *vol, struct foli= o *folio, + const struct runlist_element *rl, u32 size) +{ + unsigned int offset =3D 0; + + size =3D round_up(size, vol->sector_size); + while (size) { + struct bio *bio; + unsigned int len; + int err; + + if (!rl->length || rl->lcn < 0) + return -EIO; + len =3D min_t(s64, size, ntfs_cluster_to_bytes(vol, rl->length)); + bio =3D bio_alloc(vol->sb->s_bdev, 1, REQ_OP_WRITE | REQ_SYNC, + GFP_NOIO); + bio->bi_iter.bi_sector =3D + ntfs_bytes_to_bio_sector(ntfs_cluster_to_bytes(vol, rl->lcn)); + if (!bio_add_folio(bio, folio, len, offset)) { + bio_put(bio); + return -EIO; + } + err =3D submit_bio_wait(bio); + bio_put(bio); + if (err) + return err; + offset +=3D len; + size -=3D len; + rl++; + } + return 0; +} + /* * ntfs_attr_make_non_resident - convert a resident to a non-resident attr= ibute * @ni: ntfs inode describing the attribute to convert @@ -2004,6 +2039,7 @@ static int __ntfs_attr_make_non_resident(struct ntfs_= inode *ni, const u32 data_s int mp_size, mp_ofs, name_ofs, arec_size, err, err2; u32 attr_size; u8 old_res_attr_flags; + bool sync; =20 if (NInoNonResident(ni)) { ntfs_warning(vol->sb, @@ -2028,6 +2064,8 @@ static int __ntfs_attr_make_non_resident(struct ntfs_= inode *ni, const u32 data_s base_ni =3D ni; else base_ni =3D ni->ext.base_ntfs_ino; + sync =3D NInoAttr(ni) && !vi->i_nlink && + !ntfs_inode_is_named_stream(ni); m =3D map_mft_record(base_ni); if (IS_ERR(m)) { err =3D PTR_ERR(m); @@ -2150,6 +2188,18 @@ static int __ntfs_attr_make_non_resident(struct ntfs= _inode *ni, const u32 data_s folio_mark_uptodate(folio); } =20 + /* + * A zero-link attribute inode can be evicted by the caller's iput(). + * Write its data before changing the record so an I/O failure leaves + * the resident value intact. Normal writeback would take mrec_lock, + * which callers may already hold. + */ + if (folio && sync) { + err =3D ntfs_attr_write_conversion(vol, folio, rl, attr_size); + if (err) + goto rl_err_out; + } + /* Backup the attribute flag. */ old_res_attr_flags =3D a->data.resident.flags; /* Resize the resident part of the attribute record. */ @@ -2238,7 +2288,8 @@ static int __ntfs_attr_make_non_resident(struct ntfs_= inode *ni, const u32 data_s unmap_mft_record(base_ni); up_write(&ni->runlist.lock); if (folio) { - iomap_dirty_folio(vi->i_mapping, folio); + if (!sync) + iomap_dirty_folio(vi->i_mapping, folio); folio_unlock(folio); folio_put(folio); } @@ -5040,8 +5091,11 @@ static int ntfs_resident_attr_resize(struct ntfs_ino= de *attr_ni, const s64 newsi continue; } =20 - if (__ntfs_attr_make_non_resident(NTFS_I(tvi), value_len, true)) { + err =3D __ntfs_attr_make_non_resident(NTFS_I(tvi), value_len, true); + if (err) { iput(tvi); + if (err !=3D -ENOSPC && err !=3D -EPERM && err !=3D -EAGAIN) + goto put_err_out; continue; } =20 diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c index 885818f00b78..4a4d7d36ad34 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c @@ -4090,6 +4090,14 @@ s64 ntfs_inode_attr_pwrite(struct inode *vi, s64 pos= , s64 count, u8 *buf, bool s =20 WARN_ON(!NInoAttr(ni)); =20 + /* + * A zero-link attribute inode is evicted at the final iput(), even + * if its base file has since been linked. Write its data before + * eviction can discard the dirty pages. + */ + if (!vi->i_nlink && !ntfs_inode_is_named_stream(ni)) + sync =3D true; + if (ntfs_inode_is_named_stream(ni)) { if (NInoEncrypted(ni)) return -EACCES; From nobody Thu Nov 19 17:41:19 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.5 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794749260; b=ylyPRwDDAMdRFDfuqCjqHyaTogVy/D2chByacfBxY72NSJMFeETDD0n25C/VJE6HGO8f 7gZkRWFEVmAao67q+BF9+VnqiN4duWPKk0RRGfyl7KlDCcCPOiZilfZ3aZFDSqkQMLGpP MbbWxX+1MrYRr+F1IRx9w7h0C91+gRUBTEl8QgvPugPqReBkIYlMwbhu6QcenugBp2fi8 FVIyqLW1Pt3ZU3V7lrngV6Edjk+YysRBP7syo5tPLEz9/VsHeB9wiTlx9cI/yKn4A47zt gGZ9DRHgGvJ6z85hepg0zbnU4KR/1HL3b/2mFQfAz/IsOV4/67Td9yo3kyYchnDwZUQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794749260; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=dOjv39u+QdaOW4a8RXiHMwV10o0QoRCOlOEkLTo3G54=; b=DEQDF/05eotk/Jh0mdT3G3CwLmdwmhCtk1t3HHDEs8Gk0BIKa+CkGOBProOIpSo3DmGI foStX+oyQUiVUX5uqDzmUMSkCRmPYrvebgX+LHSAIdoWQMKy/JZd0UPpZysHfRSQcvxdE 29OEAkIt7djazue8CoUu7pnleiLepue01o5KF75lNw5V2FkpJTeMSe5g9Nb9YEqpZkkZp PKekU2m4JZ+sl0xGxHGR3erRdNvHpQ4oxgiHBjMn8zKa282FdtYR8i9cFLonmr1RYDgjq v/5uZHQB2WL5bQd9tdcPe9BxCVFSuflMlsBsFD2E2SUNzGQNpm+ORRZHS9sIzbFhWuA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=IvNxdYLK; arc=none smtp.remote-ip=220.197.31.5 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5EB90606A8BF for ; Sun, 15 Nov 2026 13:27:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5EB90606A8BF Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=IvNxdYLK DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=dO jv39u+QdaOW4a8RXiHMwV10o0QoRCOlOEkLTo3G54=; b=IvNxdYLKEcvIzKAX94 UNggLy1P+sqB9J67hd3y1SXFePlIwbwD51zy8IyinePi3zsynvbJaDbgY6IPfGf7 vCV4s51SmGajY4JBp3fEtWCe2P3lgPpBhL3MNeyj1T1ktcXIQJvl6zMhcLxZrxnE l+7bmbYG0XVjYJCn7yRMUA7xM= Received: from liubaolin-ThinkPad-E15-Gen-2 (unknown []) by gzga-smtp-mtada-g0-4 (Coremail) with SMTP id _____wDXP_A1s_lqfjtyIQ--.47831S5; Sun, 15 Nov 2026 21:27:20 +0800 (CST) From: Baolin Liu To: linkinjeon@kernel.org, hyc.lee@gmail.com Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, Baolin Liu Subject: [PATCH v4 11/12] ntfs: flush internal attributes before unlinking a file Date: Sun, 15 Nov 2026 21:26:08 +0800 Message-ID: <20261115132609.209957-12-liubaolin12138@163.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20261115132609.209957-1-liubaolin12138@163.com> References: <20261115132609.209957-1-liubaolin12138@163.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wDXP_A1s_lqfjtyIQ--.47831S5 X-Coremail-Antispam: 1Uf129KBjvJXoWxtF45tFW3ZFWxXw4kuF4UArb_yoW7KF4DpF ZxKry3tw42qr9Fgrs3ta1UZ34Sva1I9ay7WrZxJ3WfAw1DXw12gFW0kryxWF1rtrWfXrWq qF4Uu3y7u3yUXrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jd_-PUUUUU= X-CM-SenderInfo: xolxutxrol0iasrtmqqrwthudrp/xtbC6hgU3mr5szgKYQAA3L Content-Type: text/plain; charset="utf-8" From: Baolin Liu Removing a file's last name clears internal attribute link counts and can discard dirty folios while the file is still open. A later fgetxattr() can return stale data; rename-overwrite has the same problem. Flush cached internal attributes before removing names. Release MFT locks for writeback, then reacquire and rescan to catch concurrent conversions. Return writeback errors before namespace changes. Preserve named-stream lifetime handling. Also make internal attribute writes and conversions synchronous once the base inode has no links, covering the interval before cleanup clears the attribute inode's own link count. Fixes: af0db57d4293 ("ntfs: update inode operations") Signed-off-by: Baolin Liu --- New in v4. Fixes the preexisting dirty-attribute loss on ordinary unlink also identified in the review. Reproduced stale EA reads after unlink and rename-overwrite before the fix. Tested EA preservation with 512-byte/4 KiB/8 KiB clusters, rmdir, directory replacement, hard links, post-unlink EA updates and reclamation. Injected EA block-write EIO returned before names or link counts changed; rewrite/retry passed. Concurrent EA reads/writes, fsync and unlink/rename passed with four CPUs, NTFS debug and lockdep. fs/ntfs/attrib.c | 2 +- fs/ntfs/inode.c | 6 +++-- fs/ntfs/namei.c | 67 +++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c index af044ea895fc..29eae1eb3d02 100644 --- a/fs/ntfs/attrib.c +++ b/fs/ntfs/attrib.c @@ -2064,7 +2064,7 @@ static int __ntfs_attr_make_non_resident(struct ntfs_= inode *ni, const u32 data_s base_ni =3D ni; else base_ni =3D ni->ext.base_ntfs_ino; - sync =3D NInoAttr(ni) && !vi->i_nlink && + sync =3D NInoAttr(ni) && (!vi->i_nlink || !VFS_I(base_ni)->i_nlink) && !ntfs_inode_is_named_stream(ni); m =3D map_mft_record(base_ni); if (IS_ERR(m)) { diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c index 4a4d7d36ad34..fb2f08265cc1 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c @@ -4093,9 +4093,11 @@ s64 ntfs_inode_attr_pwrite(struct inode *vi, s64 pos= , s64 count, u8 *buf, bool s /* * A zero-link attribute inode is evicted at the final iput(), even * if its base file has since been linked. Write its data before - * eviction can discard the dirty pages. + * eviction can discard the dirty pages. Also cover the interval after + * unlink clears the base inode's link count but before attribute cleanup. */ - if (!vi->i_nlink && !ntfs_inode_is_named_stream(ni)) + if ((!vi->i_nlink || !VFS_I(base_ni)->i_nlink) && + !ntfs_inode_is_named_stream(ni)) sync =3D true; =20 if (ntfs_inode_is_named_stream(ni)) { diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c index 3eb2d57bef1b..1b4d1e02e183 100644 --- a/fs/ntfs/namei.c +++ b/fs/ntfs/namei.c @@ -911,6 +911,58 @@ static int ntfs_test_inode_attr(struct inode *vi, void= *data) return 0; } =20 +static int ntfs_match_dirty_attr(struct inode *vi, u64 mft_no, void *data) +{ + struct ntfs_inode *ni =3D NTFS_I(vi); + int found =3D 0; + + if (ni->mft_no !=3D mft_no || !NInoAttr(ni) || + ntfs_inode_is_named_stream(ni)) + return 0; + + spin_lock(&vi->i_lock); + if (!(inode_state_read(vi) & (I_NEW | I_CREATING | I_FREEING | I_WILL_FRE= E)) && + (mapping_tagged(vi->i_mapping, PAGECACHE_TAG_DIRTY) || + mapping_tagged(vi->i_mapping, PAGECACHE_TAG_WRITEBACK))) { + __iget(vi); + found =3D 1; + } + spin_unlock(&vi->i_lock); + return found; +} + +/* + * Return with the target's mrec_lock held and its internal attributes cle= an. + * Rename also needs the source locked first. Drop both locks for writebac= k, + * then rescan under the locks to catch concurrent attribute conversions. + * Directory mrec_locks must not be held by the caller. + */ +static int ntfs_lock_unlink_inodes(struct ntfs_inode *ni, + struct ntfs_inode *source_ni) +{ + struct inode *attr_vi; + int err; + + for (;;) { + if (source_ni) + mutex_lock_nested(&source_ni->mrec_lock, NTFS_INODE_MUTEX_NORMAL); + mutex_lock_nested(&ni->mrec_lock, source_ni ? + NTFS_INODE_MUTEX_NORMAL_2 : NTFS_INODE_MUTEX_NORMAL); + attr_vi =3D find_inode_nowait(VFS_I(ni)->i_sb, ni->mft_no, + ntfs_match_dirty_attr, NULL); + if (!attr_vi) + return 0; + mutex_unlock(&ni->mrec_lock); + if (source_ni) + mutex_unlock(&source_ni->mrec_lock); + + err =3D filemap_write_and_wait(attr_vi->i_mapping); + iput(attr_vi); + if (err) + return err; + } +} + static void ntfs_cleanup_deleted_inode(struct ntfs_inode *ni) { struct inode *attr_vi; @@ -961,7 +1013,9 @@ static int ntfs_delete(struct ntfs_inode *ni, struct n= tfs_inode *dir_ni, ntfs_debug("Entering.\n"); =20 if (need_lock =3D=3D true) { - mutex_lock_nested(&ni->mrec_lock, NTFS_INODE_MUTEX_NORMAL); + err =3D ntfs_lock_unlink_inodes(ni, NULL); + if (err) + return err; mutex_lock_nested(&dir_ni->mrec_lock, NTFS_INODE_MUTEX_PARENT); } =20 @@ -1454,9 +1508,13 @@ static int ntfs_rename(const struct mnt_idmap *idmap= , struct inode *old_dir, =20 ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY); =20 - mutex_lock_nested(&old_ni->mrec_lock, NTFS_INODE_MUTEX_NORMAL); - if (new_ni) - mutex_lock_nested(&new_ni->mrec_lock, NTFS_INODE_MUTEX_NORMAL_2); + if (new_ni) { + err =3D ntfs_lock_unlink_inodes(new_ni, old_ni); + if (err) + goto out_names; + } else { + mutex_lock_nested(&old_ni->mrec_lock, NTFS_INODE_MUTEX_NORMAL); + } =20 if (old_dir =3D=3D new_dir) { mutex_lock_nested(&old_dir_ni->mrec_lock, NTFS_INODE_MUTEX_PARENT); @@ -1540,6 +1598,7 @@ static int ntfs_rename(const struct mnt_idmap *idmap,= struct inode *old_dir, mutex_unlock(&old_ni->mrec_lock); if (new_ni) ntfs_cleanup_deleted_inode(new_ni); +out_names: if (uname_new) kmem_cache_free(ntfs_name_cache, uname_new); if (uname_old) From nobody Thu Nov 19 17:41:19 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.3 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794749261; b=KOQYPg+LJObkIqE+El9G8orHfnwnqu4+PQ0geStVVCMYiWoAT0wP/4SkSVUNQUArblmz /gGdep+Tt7HoLZ59BwSrnvDjvngB3mygq9VyouQKEka6aynPHlIOwLUk8sT4CL8vroG6y thQ06FovAa9akE5wR9C9HbS0GP0+24H1jJH++Bcy769XeN1ERuYidIKVPVsA3vKCSXAtD nfkhO+kAdLmH6sfve3NzBozdl/cIzSYeNfyGVjz1NkW89hYhupqU09YxoubnfpzuYuUAh z6Qs7Hffkd30TEUHvT3Om+FihrOh/EUB+HK786U6oacBnW9PWlPmTMrek/FAGKC7Vmw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794749261; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=4tyCGDIewA+GiAVeQEatz7b2can7eSkfz9IJpWESZLk=; b=b72S2Q69QW4RIW7sxVzo/a0TA94Xh63Vw2J864S/g4HDSnACb0rY49eVOiZTN32lX1YY i8dsMlfMYopTytsebuJt+xSeZtrQfSwBUND3Bvb9QjWX66bEVSzdkHJNtNjGKtch/kn7v b0Tq2OnO/HcYsfdxd03AjqfdYQpyy5kKnTZ8Ld6SOcAofTeDm21NmsQazh7j2cTV/5gyx y9xdKsj1SHrSdo05NbQKIXFTCvywi0tb5HYdsb84Q8rFhzNAt01FYHrdVmGjLbthYTp22 RtaSi8DeNVu8VpyVfn83q2s/sKM/TifKzY+W/+aSl2uKZFbpMdEu+if+ga9kR+dpLZQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=QQMednry; arc=none smtp.remote-ip=220.197.31.3 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 592C8606A8BB for ; Sun, 15 Nov 2026 13:27:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 592C8606A8BB Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=QQMednry DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=4t yCGDIewA+GiAVeQEatz7b2can7eSkfz9IJpWESZLk=; b=QQMednryB+x5rXOyWY hgILGhS6/V6OxWXOp2msp1VJoEdxdug7612IiLkHdlQilxeG94qYBKfkP8tIgd5O ur5fXQVFLutNdH18XkK4+RfFm1mzh/y6kEYnXJ5noHCjMn8Yaf8ENep2oIGzE3dE Ny1irrgjgvVA02hCjdg6NjSEE= Received: from liubaolin-ThinkPad-E15-Gen-2 (unknown []) by gzga-smtp-mtada-g0-4 (Coremail) with SMTP id _____wDXP_A1s_lqfjtyIQ--.47831S6; Sun, 15 Nov 2026 21:27:20 +0800 (CST) From: Baolin Liu To: linkinjeon@kernel.org, hyc.lee@gmail.com Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, Baolin Liu Subject: [PATCH v4 12/12] ntfs: support O_TMPFILE Date: Sun, 15 Nov 2026 21:26:09 +0800 Message-ID: <20261115132609.209957-13-liubaolin12138@163.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20261115132609.209957-1-liubaolin12138@163.com> References: <20261115132609.209957-1-liubaolin12138@163.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wDXP_A1s_lqfjtyIQ--.47831S6 X-Coremail-Antispam: 1Uf129KBjvJXoW3AF43Gr4rJr4DurW5ZF1DKFg_yoWxJr18pF ZxWryxGw4xXry2g392ka1UZr4SgayxuF4UXrWxG3W3AFn8tw1FgF1ftFy3uF1ftrWrCrs0 qF4UK34UWr15ZwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07Uio7NUUUUU= X-CM-SenderInfo: xolxutxrol0iasrtmqqrwthudrp/xtbC6RgU3mr5szh1ewAA3t Content-Type: text/plain; charset="utf-8" From: Baolin Liu Create regular files without FILE_NAME or directory index entries, with zero on-disk links, and attach them using d_tmpfile(). Clear the in- memory link count before EA setup so attribute inodes cannot pin unpublished files in cache. Allow the first link only with I_LINKABLE, preserving existing deletion checks. Let the VFS enforce O_EXCL and clear I_LINKABLE after publication. Reuse zero-link eviction for cleanup. Document the interface and named-stream restrictions before publication. Reviewed-by: Hyunchul Lee Signed-off-by: Baolin Liu --- No code changes since v3; rebased on the preceding fixes. QEMU creation, publication, cleanup, O_EXCL, ACLs, permissions, idmapped mounts, streams, EAs, direct I/O, mmap and concurrency checks passed. Persistence, full-volume retries and injected rollback checks passed, as did generic/004 and generic/389. Documentation/filesystems/ntfs.rst | 15 +++++++++ fs/ntfs/namei.c | 54 ++++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/Documentation/filesystems/ntfs.rst b/Documentation/filesystems= /ntfs.rst index d5819da6ab53..635301117807 100644 --- a/Documentation/filesystems/ntfs.rst +++ b/Documentation/filesystems/ntfs.rst @@ -10,6 +10,7 @@ The Linux NTFS filesystem driver - Overview - Utilities support - Linux file attributes + - Temporary files - Supported mount options =20 =20 @@ -63,6 +64,20 @@ These Linux flags are enforced by Linux. Storing them in= an NTFS EA does not make Windows enforce immutable, append-only, nodump or noatime semanti= cs. =20 =20 +Temporary files +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The driver supports ``O_TMPFILE`` for regular files. The file has no +directory entry until it is linked with linkat(2); ``O_EXCL`` prevents +this publication. Ownership and mode follow normal file creation rules. +With ACLs enabled, the file's access ACL is derived from the creation +directory's default ACL. Unpublished files are reclaimed when their last +reference is released. + +Named stream ioctls cannot create or open streams on an unpublished +temporary file. They can be used after the file has been linked. + + Supported mount options =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c index 1b4d1e02e183..67f1d7eecf2b 100644 --- a/fs/ntfs/namei.c +++ b/fs/ntfs/namei.c @@ -490,9 +490,11 @@ static struct ntfs_inode *__ntfs_create(const struct m= nt_idmap *idmap, struct in simple_inode_init_ts(vi); ni->i_crtime =3D inode_get_ctime(vi); =20 - inode_set_mtime_to_ts(dir, ni->i_crtime); - inode_set_ctime_to_ts(dir, ni->i_crtime); - mark_inode_dirty(dir); + if (name) { + inode_set_mtime_to_ts(dir, ni->i_crtime); + inode_set_ctime_to_ts(dir, ni->i_crtime); + mark_inode_dirty(dir); + } =20 err =3D ntfs_mft_record_alloc(dir_ni->vol, mode, &ni, NULL, &ni_mrec, -1); @@ -514,6 +516,10 @@ static struct ntfs_inode *__ntfs_create(const struct m= nt_idmap *idmap, struct in inode_set_iversion(vi, 1); insert_inode_hash(vi); =20 + /* Attribute inodes must not pin an unpublished file in cache. */ + if (!name) + clear_nlink(vi); + mutex_lock_nested(&ni->mrec_lock, NTFS_INODE_MUTEX_NORMAL); mutex_lock_nested(&dir_ni->mrec_lock, NTFS_INODE_MUTEX_PARENT); if (NInoBeingDeleted(dir_ni)) { @@ -659,6 +665,12 @@ static struct ntfs_inode *__ntfs_create(const struct m= nt_idmap *idmap, struct in if (err) goto err_out; =20 + if (!name) { + ni_mrec->link_count =3D 0; + mark_mft_record_dirty(ni); + goto done; + } + /* Create FILE_NAME attribute. */ fn_len =3D sizeof(struct file_name_attr) + name_len * sizeof(__le16); fn =3D kzalloc(fn_len, GFP_NOFS); @@ -711,12 +723,13 @@ static struct ntfs_inode *__ntfs_create(const struct = mnt_idmap *idmap, struct in goto err_out; } =20 + ni->flags =3D fn->file_attributes | + (ni->flags & FILE_ATTRIBUTE_RECALL_ON_OPEN); +done: unmap_mft_record(ni); mutex_unlock(&dir_ni->mrec_lock); mutex_unlock(&ni->mrec_lock); =20 - ni->flags =3D fn->file_attributes | - (ni->flags & FILE_ATTRIBUTE_RECALL_ON_OPEN); /* Set the sequence number. */ vi->i_generation =3D ni->seq_no; set_nlink(vi, 1); @@ -793,6 +806,8 @@ static struct ntfs_inode *__ntfs_create(const struct mn= t_idmap *idmap, struct in mutex_unlock(&dir_ni->mrec_lock); mutex_unlock(&ni->mrec_lock); =20 + /* The MFT record has already been freed above. */ + set_nlink(vi, 1); if (rollback_ea_vi) iput(rollback_ea_vi); if (rollback_eai_vi) @@ -871,6 +886,31 @@ static int ntfs_create(const struct mnt_idmap *idmap, = struct inode *dir, return 0; } =20 +static int ntfs_tmpfile(const struct mnt_idmap *idmap, struct inode *dir, + struct file *file, umode_t mode) +{ + struct ntfs_volume *vol =3D NTFS_SB(dir->i_sb); + struct ntfs_inode *ni; + struct inode *inode; + int err; + + if (NVolShutdown(vol)) + return -EIO; + + err =3D ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY); + if (err) + return err; + + ni =3D __ntfs_create(idmap, dir, NULL, 0, mode, 0, NULL, 0); + if (IS_ERR(ni)) + return PTR_ERR(ni); + + inode =3D VFS_I(ni); + d_tmpfile(file, inode); + unlock_new_inode(inode); + return finish_open_simple(file, 0); +} + static int ntfs_check_unlinkable_dir(struct ntfs_attr_search_ctx *ctx, str= uct file_name_attr *fn) { int link_count; @@ -1340,7 +1380,8 @@ static int __ntfs_link(struct ntfs_inode *ni, struct = ntfs_inode *dir_ni, goto err_out; } =20 - if (le16_to_cpu(ni_mrec->link_count) =3D=3D 0) { + if (!ni_mrec->link_count && + !(inode_state_read_once(vi) & I_LINKABLE)) { err =3D -ENOENT; goto err_out; } @@ -1781,6 +1822,7 @@ static int ntfs_link(struct dentry *old_dentry, struc= t inode *dir, const struct inode_operations ntfs_dir_inode_ops =3D { .lookup =3D ntfs_lookup, /* VFS: Lookup directory. */ .create =3D ntfs_create, + .tmpfile =3D ntfs_tmpfile, .unlink =3D ntfs_unlink, .mkdir =3D ntfs_mkdir, .rmdir =3D ntfs_rmdir,