Re: [PATCH] ntfs: use pagecache_isize_extended() on size extension

Hyunchul Lee <[email protected]> Fri, 17 Jul 2026 07:28:31 +0900
Newsgroups dev.linux.lists.ntfs,org.kernel.vger.linux-fsdevel
Message-ID <CANFS6bbPxFJw1vBD_16AfAGFONMPBh7Uk6roDBnuxZmo_tKP8w@mail.gmail.com>
2026=EB=85=84 7=EC=9B=94 16=EC=9D=BC (=EB=AA=A9) =EC=98=A4=EC=A0=84 11:47, =
Namjae Jeon <[email protected]>=EB=8B=98=EC=9D=B4 =EC=9E=91=EC=84=B1:
>
> When extending file size, call truncate_pagecache() first, then update
> i_size, and use pagecache_isize_extended() instead of manual
> iomap_zero_range(). This ensures the straddling folio is properly marked
> RO so page_mkwrite() is called and post-EOF area is zeroed.
>
> Signed-off-by: Namjae Jeon <[email protected]>

Looks good to me.

Reviewed-by: Hyunchul Lee <[email protected]>

> ---
>  fs/ntfs/file.c | 28 ++++++++++------------------
>  1 file changed, 10 insertions(+), 18 deletions(-)
>
> diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
> index 9061f8f77f7e..c8e49f83fd92 100644
> --- a/fs/ntfs/file.c
> +++ b/fs/ntfs/file.c
> @@ -268,23 +268,19 @@ static int ntfs_setattr_size(struct inode *vi, stru=
ct iattr *attr)
>                 return err;
>
>         inode_dio_wait(vi);
> -       truncate_setsize(vi, attr->ia_size);
> +       if (attr->ia_size > old_size) {
> +               truncate_pagecache(vi, old_size);
> +               i_size_write(vi, attr->ia_size);
> +               pagecache_isize_extended(vi, old_size, attr->ia_size);
> +       } else
> +               truncate_setsize(vi, attr->ia_size);
> +
>         err =3D ntfs_truncate_vfs(vi, attr->ia_size, old_size);
>         if (err) {
>                 i_size_write(vi, old_size);
>                 return err;
>         }
>
> -       if (NInoNonResident(ni) && attr->ia_size > old_size &&
> -           old_size % PAGE_SIZE !=3D 0) {
> -               loff_t len =3D min_t(loff_t,
> -                               round_up(old_size, PAGE_SIZE) - old_size,
> -                               attr->ia_size - old_size);
> -               err =3D iomap_zero_range(vi, old_size, len,
> -                               NULL, &ntfs_seek_iomap_ops,
> -                               &ntfs_iomap_folio_ops, NULL);
> -       }
> -
>         return err;
>  }
>
> @@ -1165,13 +1161,9 @@ static long ntfs_fallocate(struct file *file, int =
mode, loff_t offset, loff_t le
>                 filemap_invalidate_unlock(vi->i_mapping);
>         if (!err) {
>                 if (mode =3D=3D 0 && NInoNonResident(ni) &&
> -                   offset > old_size && old_size % PAGE_SIZE !=3D 0) {
> -                       loff_t len =3D min_t(loff_t,
> -                                          round_up(old_size, PAGE_SIZE) =
- old_size,
> -                                          offset - old_size);
> -                       err =3D iomap_zero_range(vi, old_size, len, NULL,
> -                                              &ntfs_seek_iomap_ops,
> -                                              &ntfs_iomap_folio_ops, NUL=
L);
> +                   offset > old_size) {
> +                       truncate_pagecache(vi, old_size);
> +                       pagecache_isize_extended(vi, old_size, offset);
>                 }
>                 NInoSetFileNameDirty(ni);
>                 inode_set_mtime_to_ts(vi, inode_set_ctime_current(vi));
> --
> 2.25.1
>


--=20
Thanks,
Hyunchul