[PATCH v6 05/37] ntfs: preserve synchronous buffered read errors

From: Xuewen Wang

Date: Wed Nov 18 2026 - 04:08:21 EST


From: Xuewen Wang <wangxuewen@xxxxxxxxxx>

iomap_read_folio() discards errors from the mapping callback. Returning
success from ntfs_read_folio() then makes the page-cache reader report EIO
instead of the original allocation or metadata lookup error.

Capture a negative mapping result through the iomap iterator's private
pointer and return it from read_folio. Keep asynchronous completion and
partial-read handling unchanged.

Reviewed-by: Baolin Liu <liubaolin@xxxxxxxxxx>
Signed-off-by: Xuewen Wang <wangxuewen@xxxxxxxxxx>
---
Changes in v6:
Extract buffered-read error propagation from v5 patch 9 and adapt it
to the current iomap callback interface.

Validation:
- Compiled and linked the NTFS module object with W=1 at this stage.
- No undefined references to ntfs_report_* or fserror_report_*.

fs/ntfs/aops.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/fs/ntfs/aops.c b/fs/ntfs/aops.c
index d0d1a8402bc4..d02d8dde833e 100644
--- a/fs/ntfs/aops.c
+++ b/fs/ntfs/aops.c
@@ -49,6 +49,18 @@ static const struct iomap_read_ops ntfs_iomap_bio_read_ops = {
.submit_read = ntfs_iomap_bio_submit_read,
};

+static int ntfs_read_folio_iomap_next(const struct iomap_iter *iter,
+ struct iomap *iomap, struct iomap *srcmap)
+{
+ int *error = iter->private;
+ int ret;
+
+ ret = ntfs_read_iomap_next(iter, iomap, srcmap);
+ if (ret < 0)
+ *error = ret;
+ return ret;
+}
+
/*
* ntfs_read_folio - Read data for a folio from the device
* @file: open file to which the folio @folio belongs or NULL
@@ -73,6 +85,7 @@ static int ntfs_read_folio(struct file *file, struct folio *folio)
.cur_folio = folio,
.ops = &ntfs_iomap_bio_read_ops,
};
+ int err = 0;

/*
* Only $DATA attributes can be encrypted and only unnamed $DATA
@@ -104,8 +117,9 @@ static int ntfs_read_folio(struct file *file, struct folio *folio)
return ntfs_read_compressed_block(folio);
}

- iomap_read_folio(ntfs_read_iomap_next, &ctx, NULL);
- return 0;
+ /* iomap_read_folio() otherwise discards synchronous mapping errors. */
+ iomap_read_folio(ntfs_read_folio_iomap_next, &ctx, &err);
+ return err;
}

/*
--
2.51.0