|
@@ -282,6 +282,7 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg)
|
|
|
struct fstrim_range range;
|
|
|
u64 minlen = ULLONG_MAX;
|
|
|
u64 num_devices = 0;
|
|
|
+ u64 total_bytes = btrfs_super_total_bytes(&root->fs_info->super_copy);
|
|
|
int ret;
|
|
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
@@ -300,12 +301,15 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg)
|
|
|
}
|
|
|
}
|
|
|
rcu_read_unlock();
|
|
|
+
|
|
|
if (!num_devices)
|
|
|
return -EOPNOTSUPP;
|
|
|
-
|
|
|
if (copy_from_user(&range, arg, sizeof(range)))
|
|
|
return -EFAULT;
|
|
|
+ if (range.start > total_bytes)
|
|
|
+ return -EINVAL;
|
|
|
|
|
|
+ range.len = min(range.len, total_bytes - range.start);
|
|
|
range.minlen = max(range.minlen, minlen);
|
|
|
ret = btrfs_trim_fs(root, &range);
|
|
|
if (ret < 0)
|