[PATCH 05/11] ntfs: fix initialized size and page state after compressed writes

Namjae Jeon <[email protected]> Tue, 21 Jul 2026 18:54:25 +0900
Newsgroups dev.linux.lists.ntfs
Message-ID <[email protected]>
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.

Signed-off-by: Namjae Jeon <[email protected]>
---
 fs/ntfs/compress.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

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,
 			}
 		}
 
+		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);
-- 
2.34.1