mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhan Xusheng <zhanxusheng1024@gmail.com>
To: almaz.alexandrovich@paragon-software.com
Cc: ntfs3@lists.linux.dev, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, zhanxusheng@xiaomi.com
Subject: [PATCH 2/2] fs/ntfs3: zero new clusters that a write only partly covers
Date: Fri, 20 Nov 2026 21:36:04 +0800	[thread overview]
Message-ID: <20261120133604.427285-2-zhanxusheng1024@gmail.com> (raw)
In-Reply-To: <20261120133604.427285-1-zhanxusheng1024@gmail.com>

From: Zhan Xusheng <zhanxusheng@xiaomi.com>

When ntfs_iomap_begin() allocates clusters in a hole, the part of a new
cluster that the request does not write keeps the old disk contents,
and reads below the valid size return it.  The iomap conversion asked
attr_data_get_block() to zero such clusters only for writes through the
page cache, and commit 10d7c95af043 ("fs/ntfs3: add delayed-allocation
(delalloc) support") stopped asking for it at all.  Only the delalloc
path still zeroes them.

On a volume with 64K clusters, write 4K at 0 and at 960K into a sparse
file, then 4K at 512K: 61440 bytes of the file read back old disk
contents, both with O_DIRECT and with a buffered write on a volume
mounted without delalloc.

Zero the new clusters when the request does not cover them.

Fixes: 099ef9ab9203 ("fs/ntfs3: implement iomap-based file operations")
Fixes: 10d7c95af043 ("fs/ntfs3: add delayed-allocation (delalloc) support")
Cc: stable@vger.kernel.org
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
With 4K clusters a page covers a whole cluster, so only 64K clusters
show it in these tests.  With both patches, fsx with mmap on 4K and 64K
cluster volumes and on sparse and compressed files gives the same
results as before.

 fs/ntfs3/inode.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c
index 535a2b0804af..9c2ded9567f7 100644
--- a/fs/ntfs3/inode.c
+++ b/fs/ntfs3/inode.c
@@ -982,6 +982,10 @@ static int ntfs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
 	 */
 	no_da = flags == (IOMAP_DIRECT | IOMAP_WRITE) || srcmap == WB_NO_DA;
 
+	/* The request does not write all of a new cluster: zero it first. */
+	if (rw && ((offset | endbyte) & sbi->cluster_mask))
+		zero = true;
+
 	err = attr_data_get_block(ni, vcn, clen_max, &lcn, &clen,
 				  rw ? &new_clst : NULL, zero, &res, no_da);
 
-- 
2.43.0


      reply	other threads:[~2026-11-20 13:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 13:36 [PATCH 1/2] fs/ntfs3: allocate only the written range of a hole on writeback Zhan Xusheng
2026-11-20 13:36 ` Zhan Xusheng [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120133604.427285-2-zhanxusheng1024@gmail.com \
    --to=zhanxusheng1024@gmail.com \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=zhanxusheng@xiaomi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®