[PATCH 2/2] fs/ntfs3: zero new clusters that a write only partly covers
From: Zhan Xusheng
Date: Fri Nov 20 2026 - 08:36:21 EST
From: Zhan Xusheng <zhanxusheng@xxxxxxxxxx>
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@xxxxxxxxxxxxxxx
Signed-off-by: Zhan Xusheng <zhanxusheng@xxxxxxxxxx>
---
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