fs/ntfs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
The minlen member of struct fstrim_range is a 64-bit byte count, but
ntfs_ioctl_fitrim() uses max_t(u32, ...) to compare it with the device's
discard granularity. This truncates the requested minimum length before
passing it to ntfs_trim_fs().
For example, a minimum length of 4 GiB is reduced to the discard
granularity, allowing smaller free extents to be discarded. The truncated
minimum length is also copied back to userspace.
Use max_t(u64, ...) to preserve the requested minimum length. The bitmap
scan already compares the aligned extent length against range->minlen
using 64-bit values.
Fixes: 9c87959601e8 ("ntfs: update file operations")
Signed-off-by: Xuewen Wang <wangxuewen@kylinos.cn>
Reviewed-by: Baolin Liu <liubaolin@kylinos.cn>
---
fs/ntfs/file.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index 8164326b7812..e315fed4d13b 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -866,7 +866,7 @@ static int ntfs_ioctl_fitrim(struct ntfs_volume *vol, unsigned long arg)
if (range.len < vol->cluster_size)
return -EINVAL;
- range.minlen = max_t(u32, range.minlen, bdev_discard_granularity(dev));
+ range.minlen = max_t(u64, range.minlen, bdev_discard_granularity(dev));
err = ntfs_trim_fs(vol, &range);
if (err < 0)
--
2.25.1
On Sun, Sep 20, 2026 at 3:32 PM Xuewen Wang <wangxuewen@kylinos.cn> wrote:
>
> The minlen member of struct fstrim_range is a 64-bit byte count, but
> ntfs_ioctl_fitrim() uses max_t(u32, ...) to compare it with the device's
> discard granularity. This truncates the requested minimum length before
> passing it to ntfs_trim_fs().
>
> For example, a minimum length of 4 GiB is reduced to the discard
> granularity, allowing smaller free extents to be discarded. The truncated
> minimum length is also copied back to userspace.
>
> Use max_t(u64, ...) to preserve the requested minimum length. The bitmap
> scan already compares the aligned extent length against range->minlen
> using 64-bit values.
>
> Fixes: 9c87959601e8 ("ntfs: update file operations")
> Signed-off-by: Xuewen Wang <wangxuewen@kylinos.cn>
> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn>
Applied it to #ntfs-next.
Thanks.
2026년 9월 20일 (일) 오후 3:32, Xuewen Wang <wangxuewen@kylinos.cn>님이 작성:
>
> The minlen member of struct fstrim_range is a 64-bit byte count, but
> ntfs_ioctl_fitrim() uses max_t(u32, ...) to compare it with the device's
> discard granularity. This truncates the requested minimum length before
> passing it to ntfs_trim_fs().
>
> For example, a minimum length of 4 GiB is reduced to the discard
> granularity, allowing smaller free extents to be discarded. The truncated
> minimum length is also copied back to userspace.
>
> Use max_t(u64, ...) to preserve the requested minimum length. The bitmap
> scan already compares the aligned extent length against range->minlen
> using 64-bit values.
>
> Fixes: 9c87959601e8 ("ntfs: update file operations")
> Signed-off-by: Xuewen Wang <wangxuewen@kylinos.cn>
> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn>
Looks good to me.
Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com>
> ---
> fs/ntfs/file.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
> index 8164326b7812..e315fed4d13b 100644
> --- a/fs/ntfs/file.c
> +++ b/fs/ntfs/file.c
> @@ -866,7 +866,7 @@ static int ntfs_ioctl_fitrim(struct ntfs_volume *vol, unsigned long arg)
> if (range.len < vol->cluster_size)
> return -EINVAL;
>
> - range.minlen = max_t(u32, range.minlen, bdev_discard_granularity(dev));
> + range.minlen = max_t(u64, range.minlen, bdev_discard_granularity(dev));
>
> err = ntfs_trim_fs(vol, &range);
> if (err < 0)
> --
> 2.25.1
>
--
Thanks,
Hyunchul
© 2016 - 2026 Red Hat, Inc.