diff --git a/fs/ntfs/iomap.c b/fs/ntfs/iomap.c index c812d7f19b36..b4475963e57a 100644 --- a/fs/ntfs/iomap.c +++ b/fs/ntfs/iomap.c @@ -394,7 +394,7 @@ static int ntfs_write_simple_iomap_begin_non_resident(struct inode *inode, loff_ loff_t vcn_ofs, rl_length; struct runlist_element *rl, *rlc; bool is_retry = false; - int err = 0; + int err = 0, map_err = 0; s64 vcn, lcn; s64 max_clu_count = ntfs_bytes_to_cluster(vol, round_up(length, vol->cluster_size)); @@ -429,12 +429,24 @@ static int ntfs_write_simple_iomap_begin_non_resident(struct inode *inode, loff_ if (lcn <= LCN_RL_NOT_MAPPED && is_retry == false) { is_retry = true; - if (!ntfs_map_runlist_nolock(ni, vcn, NULL)) { + map_err = ntfs_map_runlist_nolock(ni, vcn, NULL); + if (!map_err) { rl = ni->runlist.rl; goto remap_rl; } } + /* + * As in ntfs_attr_vcn_to_rl(): a runlist fragment that could not be + * mapped is not a hole. Treating it as one would put a delalloc + * extent over clusters that are allocated on disk but unknown to us. + */ + if (lcn == LCN_RL_NOT_MAPPED) { + up_write(&ni->runlist.lock); + mutex_unlock(&ni->mrec_lock); + return map_err == -ENOMEM ? -ENOMEM : -EIO; + } + max_clu_count = min(max_clu_count, rl->length - (vcn - rl->vcn)); if (max_clu_count == 0) { ntfs_error(inode->i_sb,