From b54559689a00eb50308fb768e05fbb5036c7b1b0 Mon Sep 17 00:00:00 2001 From: Namjae Jeon Date: Tue, 21 Jul 2026 11:58:08 +0900 Subject: [PATCH] ntfs: fix initialized size and page state after compressed writes The write iterator now expands attributes before calling ntfs_compress_write(), so compressed writes must not expand the attribute themselves. However, the compressed path still needs to reject zero-byte iterator copies, advance initialized_size after successful I/O, and invalidate modified folios after a failed compression-unit write. Reject no-progress copies, persist the new initialized size on success, and clear folio uptodate state when the synchronous write fails. Reviewed-by: Hyunchul Lee Signed-off-by: Namjae Jeon --- fs/ntfs/compress.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c index 5b5cd494e5d8..a993cba3b961 100644 --- a/fs/ntfs/compress.c +++ b/fs/ntfs/compress.c @@ -1549,13 +1549,26 @@ int ntfs_compress_write(struct ntfs_inode *ni, loff_t pos, size_t count, } } - err = ntfs_write_cb(ni, pos, pages, pages_per_cb, page_offset); + if (!copied) { + err = -EFAULT; + goto release_pages; + } + err = ntfs_write_cb(ni, pos, pages, pages_per_cb, page_offset); + if (!err && pos + copied > ni->initialized_size) { + mutex_lock(&ni->mrec_lock); + err = ntfs_attr_set_initialized_size(ni, pos + copied); + mutex_unlock(&ni->mrec_lock); + } + +release_pages: for (i = 0; i < pages_per_cb; i++) { folio = page_folio(pages[i]); - if (i < ip) { + if (!err) { folio_clear_dirty(folio); folio_mark_uptodate(folio); + } else { + folio_clear_uptodate(folio); } folio_unlock(folio); folio_put(folio);