nr_cbs is derived from the page range and ignores i_size, while a compressed file is only allocated up to round_up(i_size, cb_size). The runlist walk for such a block reaches the LCN_ENOENT terminator and the read fails with -EIO. Every compressed file whose round_up(i_size, cb_size) is not a multiple of PAGE_SIZE fails to read its last page whenever PAGE_SIZE > cb_size. Fixes: 1e9ea7e04472 ("Revert "fs: Remove NTFS classic"") Cc: stable@vger.kernel.org Signed-off-by: Hyunchul Lee --- fs/ntfs/compress.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c index b3fb72761c6b..375c49949ce1 100644 --- a/fs/ntfs/compress.c +++ b/fs/ntfs/compress.c @@ -609,8 +609,15 @@ int ntfs_read_compressed_block(struct folio *folio) cb_end = cb + cb_size; rl = NULL; - for (vcn = start_vcn, start_vcn += cb_clusters; vcn < start_vcn; - vcn++) { + vcn = start_vcn; + start_vcn += cb_clusters; + /* + * A cb starting at or after EOF may be unallocated, so treat it + * as sparse rather than failing the runlist lookup below. + */ + if (ntfs_cluster_to_bytes(vol, vcn) >= i_size) + goto sparse_cb; + for (; vcn < start_vcn; vcn++) { bool is_retry = false; if (!rl) { @@ -669,6 +676,7 @@ int ntfs_read_compressed_block(struct folio *folio) cb_pos += vol->cluster_size; } +sparse_cb: /* Release the lock if we took it. */ if (rl) up_read(&ni->runlist.lock); -- 2.43.0